@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -27,1971 +27,1971 @@ discard block |
||
| 27 | 27 | class Transactions_Admin_Page extends EE_Admin_Page |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var EE_Transaction |
|
| 32 | - */ |
|
| 33 | - private $_transaction; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var EE_Session |
|
| 37 | - */ |
|
| 38 | - private $_session; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var array $_txn_status |
|
| 42 | - */ |
|
| 43 | - private static $_txn_status; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var array $_pay_status |
|
| 47 | - */ |
|
| 48 | - private static $_pay_status; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var array $_existing_reg_payment_REG_IDs |
|
| 52 | - */ |
|
| 53 | - protected $_existing_reg_payment_REG_IDs = null; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @Constructor |
|
| 58 | - * @access public |
|
| 59 | - * |
|
| 60 | - * @param bool $routing |
|
| 61 | - * |
|
| 62 | - * @return Transactions_Admin_Page |
|
| 63 | - */ |
|
| 64 | - public function __construct($routing = true) |
|
| 65 | - { |
|
| 66 | - parent::__construct($routing); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * _init_page_props |
|
| 72 | - * @return void |
|
| 73 | - */ |
|
| 74 | - protected function _init_page_props() |
|
| 75 | - { |
|
| 76 | - $this->page_slug = TXN_PG_SLUG; |
|
| 77 | - $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 78 | - $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 79 | - $this->_admin_base_path = TXN_ADMIN; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * _ajax_hooks |
|
| 85 | - * @return void |
|
| 86 | - */ |
|
| 87 | - protected function _ajax_hooks() |
|
| 88 | - { |
|
| 89 | - add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 90 | - add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 91 | - add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * _define_page_props |
|
| 97 | - * @return void |
|
| 98 | - */ |
|
| 99 | - protected function _define_page_props() |
|
| 100 | - { |
|
| 101 | - $this->_admin_page_title = $this->page_label; |
|
| 102 | - $this->_labels = array( |
|
| 103 | - 'buttons' => array( |
|
| 104 | - 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 105 | - 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 106 | - 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 107 | - ) |
|
| 108 | - ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * grab url requests and route them |
|
| 114 | - * @access private |
|
| 115 | - * @return void |
|
| 116 | - */ |
|
| 117 | - public function _set_page_routes() |
|
| 118 | - { |
|
| 119 | - |
|
| 120 | - $this->_set_transaction_status_array(); |
|
| 121 | - |
|
| 122 | - $txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0; |
|
| 123 | - |
|
| 124 | - $this->_page_routes = array( |
|
| 125 | - |
|
| 126 | - 'default' => array( |
|
| 127 | - 'func' => '_transactions_overview_list_table', |
|
| 128 | - 'capability' => 'ee_read_transactions' |
|
| 129 | - ), |
|
| 130 | - |
|
| 131 | - 'view_transaction' => array( |
|
| 132 | - 'func' => '_transaction_details', |
|
| 133 | - 'capability' => 'ee_read_transaction', |
|
| 134 | - 'obj_id' => $txn_id |
|
| 135 | - ), |
|
| 136 | - |
|
| 137 | - 'send_payment_reminder' => array( |
|
| 138 | - 'func' => '_send_payment_reminder', |
|
| 139 | - 'noheader' => true, |
|
| 140 | - 'capability' => 'ee_send_message' |
|
| 141 | - ), |
|
| 142 | - |
|
| 143 | - 'espresso_apply_payment' => array( |
|
| 144 | - 'func' => 'apply_payments_or_refunds', |
|
| 145 | - 'noheader' => true, |
|
| 146 | - 'capability' => 'ee_edit_payments' |
|
| 147 | - ), |
|
| 148 | - |
|
| 149 | - 'espresso_apply_refund' => array( |
|
| 150 | - 'func' => 'apply_payments_or_refunds', |
|
| 151 | - 'noheader' => true, |
|
| 152 | - 'capability' => 'ee_edit_payments' |
|
| 153 | - ), |
|
| 154 | - |
|
| 155 | - 'espresso_delete_payment' => array( |
|
| 156 | - 'func' => 'delete_payment', |
|
| 157 | - 'noheader' => true, |
|
| 158 | - 'capability' => 'ee_delete_payments' |
|
| 159 | - ), |
|
| 160 | - |
|
| 161 | - ); |
|
| 162 | - |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - protected function _set_page_config() |
|
| 167 | - { |
|
| 168 | - $this->_page_config = array( |
|
| 169 | - 'default' => array( |
|
| 170 | - 'nav' => array( |
|
| 171 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 172 | - 'order' => 10 |
|
| 173 | - ), |
|
| 174 | - 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 175 | - 'help_tabs' => array( |
|
| 176 | - 'transactions_overview_help_tab' => array( |
|
| 177 | - 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 178 | - 'filename' => 'transactions_overview' |
|
| 179 | - ), |
|
| 180 | - 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 181 | - 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 182 | - 'filename' => 'transactions_overview_table_column_headings' |
|
| 183 | - ), |
|
| 184 | - 'transactions_overview_views_filters_help_tab' => array( |
|
| 185 | - 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 186 | - 'filename' => 'transactions_overview_views_filters_search' |
|
| 187 | - ), |
|
| 188 | - ), |
|
| 189 | - 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 190 | - /** |
|
| 191 | - * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 192 | - * may change in a later iteration so want to keep the code for then. |
|
| 193 | - */ |
|
| 194 | - //'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 195 | - 'require_nonce' => false |
|
| 196 | - ), |
|
| 197 | - 'view_transaction' => array( |
|
| 198 | - 'nav' => array( |
|
| 199 | - 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 200 | - 'order' => 5, |
|
| 201 | - 'url' => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), |
|
| 202 | - $this->_current_page_view_url) : $this->_admin_base_url, |
|
| 203 | - 'persistent' => false |
|
| 204 | - ), |
|
| 205 | - 'help_tabs' => array( |
|
| 206 | - 'transactions_view_transaction_help_tab' => array( |
|
| 207 | - 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 208 | - 'filename' => 'transactions_view_transaction' |
|
| 209 | - ), |
|
| 210 | - 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 211 | - 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 212 | - 'filename' => 'transactions_view_transaction_transaction_details_table' |
|
| 213 | - ), |
|
| 214 | - 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 215 | - 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 216 | - 'filename' => 'transactions_view_transaction_attendees_registered' |
|
| 217 | - ), |
|
| 218 | - 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 219 | - 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 220 | - 'filename' => 'transactions_view_transaction_primary_registrant_billing_information' |
|
| 221 | - ), |
|
| 222 | - ), |
|
| 223 | - 'qtips' => array('Transaction_Details_Tips'), |
|
| 224 | - 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 225 | - 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 226 | - |
|
| 227 | - 'require_nonce' => false |
|
| 228 | - ) |
|
| 229 | - ); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * The below methods aren't used by this class currently |
|
| 235 | - */ |
|
| 236 | - protected function _add_screen_options() |
|
| 237 | - { |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - protected function _add_feature_pointers() |
|
| 241 | - { |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - public function admin_init() |
|
| 245 | - { |
|
| 246 | - // IF a registration was JUST added via the admin... |
|
| 247 | - if ( |
|
| 248 | - isset( |
|
| 249 | - $this->_req_data['redirect_from'], |
|
| 250 | - $this->_req_data['EVT_ID'], |
|
| 251 | - $this->_req_data['event_name'] |
|
| 252 | - ) |
|
| 253 | - ) { |
|
| 254 | - // then set a cookie so that we can block any attempts to use |
|
| 255 | - // the back button as a way to enter another registration. |
|
| 256 | - setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'); |
|
| 257 | - // and update the global |
|
| 258 | - $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 259 | - } |
|
| 260 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 261 | - 'event_espresso'); |
|
| 262 | - EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__('An error occurred! Please refresh the page and try again.', |
|
| 263 | - 'event_espresso'); |
|
| 264 | - EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 265 | - EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 266 | - EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 267 | - EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__('This transaction has been overpaid ! Payments Total', |
|
| 268 | - 'event_espresso'); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - public function admin_notices() |
|
| 272 | - { |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - public function admin_footer_scripts() |
|
| 276 | - { |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * _set_transaction_status_array |
|
| 282 | - * sets list of transaction statuses |
|
| 283 | - * |
|
| 284 | - * @access private |
|
| 285 | - * @return void |
|
| 286 | - */ |
|
| 287 | - private function _set_transaction_status_array() |
|
| 288 | - { |
|
| 289 | - self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * get_transaction_status_array |
|
| 295 | - * return the transaction status array for wp_list_table |
|
| 296 | - * |
|
| 297 | - * @access public |
|
| 298 | - * @return array |
|
| 299 | - */ |
|
| 300 | - public function get_transaction_status_array() |
|
| 301 | - { |
|
| 302 | - return self::$_txn_status; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * get list of payment statuses |
|
| 308 | - * |
|
| 309 | - * @access private |
|
| 310 | - * @return void |
|
| 311 | - */ |
|
| 312 | - private function _get_payment_status_array() |
|
| 313 | - { |
|
| 314 | - self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 315 | - $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 316 | - |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * _add_screen_options_default |
|
| 322 | - * |
|
| 323 | - * @access protected |
|
| 324 | - * @return void |
|
| 325 | - */ |
|
| 326 | - protected function _add_screen_options_default() |
|
| 327 | - { |
|
| 328 | - $this->_per_page_screen_option(); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * load_scripts_styles |
|
| 334 | - * |
|
| 335 | - * @access public |
|
| 336 | - * @return void |
|
| 337 | - */ |
|
| 338 | - public function load_scripts_styles() |
|
| 339 | - { |
|
| 340 | - //enqueue style |
|
| 341 | - wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), |
|
| 342 | - EVENT_ESPRESSO_VERSION); |
|
| 343 | - wp_enqueue_style('espresso_txn'); |
|
| 344 | - //scripts |
|
| 345 | - wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
| 346 | - 'ee_admin_js', |
|
| 347 | - 'ee-datepicker', |
|
| 348 | - 'jquery-ui-datepicker', |
|
| 349 | - 'jquery-ui-draggable', |
|
| 350 | - 'ee-dialog', |
|
| 351 | - 'ee-accounting', |
|
| 352 | - 'ee-serialize-full-array' |
|
| 353 | - ), EVENT_ESPRESSO_VERSION, true); |
|
| 354 | - wp_enqueue_script('espresso_txn'); |
|
| 355 | - |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * load_scripts_styles_view_transaction |
|
| 361 | - * |
|
| 362 | - * @access public |
|
| 363 | - * @return void |
|
| 364 | - */ |
|
| 365 | - public function load_scripts_styles_view_transaction() |
|
| 366 | - { |
|
| 367 | - //styles |
|
| 368 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * load_scripts_styles_default |
|
| 374 | - * |
|
| 375 | - * @access public |
|
| 376 | - * @return void |
|
| 377 | - */ |
|
| 378 | - public function load_scripts_styles_default() |
|
| 379 | - { |
|
| 380 | - //styles |
|
| 381 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * _set_list_table_views_default |
|
| 387 | - * |
|
| 388 | - * @access protected |
|
| 389 | - * @return void |
|
| 390 | - */ |
|
| 391 | - protected function _set_list_table_views_default() |
|
| 392 | - { |
|
| 393 | - $this->_views = array( |
|
| 394 | - 'all' => array( |
|
| 395 | - 'slug' => 'all', |
|
| 396 | - 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 397 | - 'count' => 0 |
|
| 398 | - ), |
|
| 399 | - 'abandoned' => array( |
|
| 400 | - 'slug' => 'abandoned', |
|
| 401 | - 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 402 | - 'count' => 0 |
|
| 403 | - ), |
|
| 404 | - 'failed' => array( |
|
| 405 | - 'slug' => 'failed', |
|
| 406 | - 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 407 | - 'count' => 0 |
|
| 408 | - ) |
|
| 409 | - ); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * _set_transaction_object |
|
| 415 | - * This sets the _transaction property for the transaction details screen |
|
| 416 | - * |
|
| 417 | - * @access private |
|
| 418 | - * @return void |
|
| 419 | - */ |
|
| 420 | - private function _set_transaction_object() |
|
| 421 | - { |
|
| 422 | - if (is_object($this->_transaction)) { |
|
| 423 | - return; |
|
| 424 | - } //get out we've already set the object |
|
| 425 | - |
|
| 426 | - $TXN = EEM_Transaction::instance(); |
|
| 427 | - |
|
| 428 | - $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 429 | - |
|
| 430 | - //get transaction object |
|
| 431 | - $this->_transaction = $TXN->get_one_by_ID($TXN_ID); |
|
| 432 | - $this->_session = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null; |
|
| 433 | - $this->_transaction->verify_abandoned_transaction_status(); |
|
| 434 | - |
|
| 435 | - if (empty($this->_transaction)) { |
|
| 436 | - $error_msg = esc_html__('An error occurred and the details for Transaction ID #', |
|
| 437 | - 'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso'); |
|
| 438 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * _transaction_legend_items |
|
| 445 | - * |
|
| 446 | - * @access protected |
|
| 447 | - * @return array |
|
| 448 | - */ |
|
| 449 | - protected function _transaction_legend_items() |
|
| 450 | - { |
|
| 451 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 452 | - $items = array(); |
|
| 453 | - |
|
| 454 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 455 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 456 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 457 | - $items['view_related_messages'] = array( |
|
| 458 | - 'class' => $related_for_icon['css_class'], |
|
| 459 | - 'desc' => $related_for_icon['label'], |
|
| 460 | - ); |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - $items = apply_filters( |
|
| 465 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 466 | - array_merge($items, |
|
| 467 | - array( |
|
| 468 | - 'view_details' => array( |
|
| 469 | - 'class' => 'dashicons dashicons-cart', |
|
| 470 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso') |
|
| 471 | - ), |
|
| 472 | - 'view_invoice' => array( |
|
| 473 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 474 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso') |
|
| 475 | - ), |
|
| 476 | - 'view_receipt' => array( |
|
| 477 | - 'class' => 'dashicons dashicons-media-default', |
|
| 478 | - 'desc' => esc_html__('View Transaction Receipt', 'event_espresso') |
|
| 479 | - ), |
|
| 480 | - 'view_registration' => array( |
|
| 481 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 482 | - 'desc' => esc_html__('View Registration Details', 'event_espresso') |
|
| 483 | - ) |
|
| 484 | - ) |
|
| 485 | - ) |
|
| 486 | - ); |
|
| 487 | - |
|
| 488 | - if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 489 | - 'espresso_transactions_send_payment_reminder') |
|
| 490 | - ) { |
|
| 491 | - if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
| 492 | - $items['send_payment_reminder'] = array( |
|
| 493 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 494 | - 'desc' => esc_html__('Send Payment Reminder', 'event_espresso') |
|
| 495 | - ); |
|
| 496 | - } else { |
|
| 497 | - $items['blank*'] = array( |
|
| 498 | - 'class' => '', |
|
| 499 | - 'desc' => '' |
|
| 500 | - ); |
|
| 501 | - } |
|
| 502 | - } else { |
|
| 503 | - $items['blank*'] = array( |
|
| 504 | - 'class' => '', |
|
| 505 | - 'desc' => '' |
|
| 506 | - ); |
|
| 507 | - } |
|
| 508 | - $more_items = apply_filters( |
|
| 509 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 510 | - array( |
|
| 511 | - 'overpaid' => array( |
|
| 512 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 513 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence') |
|
| 514 | - ), |
|
| 515 | - 'complete' => array( |
|
| 516 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 517 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence') |
|
| 518 | - ), |
|
| 519 | - 'incomplete' => array( |
|
| 520 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 521 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence') |
|
| 522 | - ), |
|
| 523 | - 'abandoned' => array( |
|
| 524 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 525 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence') |
|
| 526 | - ), |
|
| 527 | - 'failed' => array( |
|
| 528 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 529 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence') |
|
| 530 | - ) |
|
| 531 | - ) |
|
| 532 | - ); |
|
| 533 | - |
|
| 534 | - return array_merge($items, $more_items); |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * _transactions_overview_list_table |
|
| 540 | - * |
|
| 541 | - * @access protected |
|
| 542 | - * @return void |
|
| 543 | - */ |
|
| 544 | - protected function _transactions_overview_list_table() |
|
| 545 | - { |
|
| 546 | - $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 547 | - $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null; |
|
| 548 | - $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s', |
|
| 549 | - 'event_espresso'), '<h3>', |
|
| 550 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
| 551 | - EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event', |
|
| 552 | - 'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : ''; |
|
| 553 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 554 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * _transaction_details |
|
| 560 | - * generates HTML for the View Transaction Details Admin page |
|
| 561 | - * |
|
| 562 | - * @access protected |
|
| 563 | - * @return void |
|
| 564 | - */ |
|
| 565 | - protected function _transaction_details() |
|
| 566 | - { |
|
| 567 | - do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 568 | - |
|
| 569 | - $this->_set_transaction_status_array(); |
|
| 570 | - |
|
| 571 | - $this->_template_args = array(); |
|
| 572 | - $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 573 | - |
|
| 574 | - $this->_set_transaction_object(); |
|
| 575 | - |
|
| 576 | - $primary_registration = $this->_transaction->primary_registration(); |
|
| 577 | - $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null; |
|
| 578 | - |
|
| 579 | - $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 580 | - $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 581 | - |
|
| 582 | - $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 583 | - $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 584 | - |
|
| 585 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
| 586 | - $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 587 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 588 | - |
|
| 589 | - $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
| 590 | - $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
| 591 | - |
|
| 592 | - if ( |
|
| 593 | - $attendee instanceof EE_Attendee |
|
| 594 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 595 | - 'ee_send_message', |
|
| 596 | - 'espresso_transactions_send_payment_reminder' |
|
| 597 | - ) |
|
| 598 | - ) { |
|
| 599 | - $this->_template_args['send_payment_reminder_button'] = |
|
| 600 | - EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 601 | - && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code |
|
| 602 | - && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code |
|
| 603 | - ? EEH_Template::get_button_or_link( |
|
| 604 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 605 | - array( |
|
| 606 | - 'action' => 'send_payment_reminder', |
|
| 607 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 608 | - 'redirect_to' => 'view_transaction' |
|
| 609 | - ), |
|
| 610 | - TXN_ADMIN_URL |
|
| 611 | - ), |
|
| 612 | - __(' Send Payment Reminder', 'event_espresso'), |
|
| 613 | - 'button secondary-button right', |
|
| 614 | - 'dashicons dashicons-email-alt' |
|
| 615 | - ) |
|
| 616 | - : ''; |
|
| 617 | - } else { |
|
| 618 | - $this->_template_args['send_payment_reminder_button'] = ''; |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
| 622 | - $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true); |
|
| 623 | - if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 624 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; |
|
| 625 | - } else { |
|
| 626 | - $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; |
|
| 627 | - } |
|
| 628 | - $this->_template_args['amount_due_class'] = ''; |
|
| 629 | - |
|
| 630 | - if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
| 631 | - // paid in full |
|
| 632 | - $this->_template_args['amount_due'] = false; |
|
| 633 | - } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
| 634 | - // overpaid |
|
| 635 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 636 | - } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) { |
|
| 637 | - // monies owing |
|
| 638 | - $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 639 | - } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) { |
|
| 640 | - // no payments made yet |
|
| 641 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 642 | - } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
| 643 | - // free event |
|
| 644 | - $this->_template_args['amount_due'] = false; |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - $payment_method = $this->_transaction->payment_method(); |
|
| 648 | - |
|
| 649 | - $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 650 | - ? $payment_method->admin_name() |
|
| 651 | - : esc_html__('Unknown', 'event_espresso'); |
|
| 652 | - |
|
| 653 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 654 | - // link back to overview |
|
| 655 | - $this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER']) |
|
| 656 | - ? $_SERVER['HTTP_REFERER'] |
|
| 657 | - : TXN_ADMIN_URL; |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - // next link |
|
| 661 | - $next_txn = $this->_transaction->next( |
|
| 662 | - null, |
|
| 663 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 664 | - 'TXN_ID' |
|
| 665 | - ); |
|
| 666 | - $this->_template_args['next_transaction'] = $next_txn |
|
| 667 | - ? $this->_next_link( |
|
| 668 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 669 | - array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 670 | - TXN_ADMIN_URL |
|
| 671 | - ), |
|
| 672 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 673 | - ) |
|
| 674 | - : ''; |
|
| 675 | - // previous link |
|
| 676 | - $previous_txn = $this->_transaction->previous( |
|
| 677 | - null, |
|
| 678 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 679 | - 'TXN_ID' |
|
| 680 | - ); |
|
| 681 | - $this->_template_args['previous_transaction'] = $previous_txn |
|
| 682 | - ? $this->_previous_link( |
|
| 683 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 684 | - array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 685 | - TXN_ADMIN_URL |
|
| 686 | - ), |
|
| 687 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 688 | - ) |
|
| 689 | - : ''; |
|
| 690 | - |
|
| 691 | - // were we just redirected here after adding a new registration ??? |
|
| 692 | - if ( |
|
| 693 | - isset( |
|
| 694 | - $this->_req_data['redirect_from'], |
|
| 695 | - $this->_req_data['EVT_ID'], |
|
| 696 | - $this->_req_data['event_name'] |
|
| 697 | - ) |
|
| 698 | - ) { |
|
| 699 | - if ( |
|
| 700 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 701 | - 'ee_edit_registrations', |
|
| 702 | - 'espresso_registrations_new_registration', |
|
| 703 | - $this->_req_data['EVT_ID'] |
|
| 704 | - ) |
|
| 705 | - ) { |
|
| 706 | - $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 707 | - $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 708 | - array( |
|
| 709 | - 'page' => 'espresso_registrations', |
|
| 710 | - 'action' => 'new_registration', |
|
| 711 | - 'return' => 'default', |
|
| 712 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 713 | - 'event_id' => $this->_req_data['EVT_ID'], |
|
| 714 | - ), |
|
| 715 | - REG_ADMIN_URL |
|
| 716 | - ); |
|
| 717 | - $this->_admin_page_title .= '">'; |
|
| 718 | - |
|
| 719 | - $this->_admin_page_title .= sprintf( |
|
| 720 | - esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 721 | - htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 722 | - ); |
|
| 723 | - $this->_admin_page_title .= '</a>'; |
|
| 724 | - } |
|
| 725 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 726 | - } |
|
| 727 | - // grab messages at the last second |
|
| 728 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 729 | - // path to template |
|
| 730 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 731 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
|
| 732 | - $this->_template_args, true); |
|
| 733 | - |
|
| 734 | - // the details template wrapper |
|
| 735 | - $this->display_admin_page_with_sidebar(); |
|
| 736 | - |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * _transaction_details_metaboxes |
|
| 742 | - * |
|
| 743 | - * @access protected |
|
| 744 | - * @return void |
|
| 745 | - */ |
|
| 746 | - protected function _transaction_details_metaboxes() |
|
| 747 | - { |
|
| 748 | - |
|
| 749 | - $this->_set_transaction_object(); |
|
| 750 | - |
|
| 751 | - add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'), |
|
| 752 | - array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high'); |
|
| 753 | - add_meta_box( |
|
| 754 | - 'edit-txn-attendees-mbox', |
|
| 755 | - esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 756 | - array($this, 'txn_attendees_meta_box'), |
|
| 757 | - $this->_wp_page_slug, |
|
| 758 | - 'normal', |
|
| 759 | - 'high', |
|
| 760 | - array('TXN_ID' => $this->_transaction->ID()) |
|
| 761 | - ); |
|
| 762 | - add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'), |
|
| 763 | - array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
| 764 | - add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'), |
|
| 765 | - array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
| 766 | - |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * txn_details_meta_box |
|
| 772 | - * generates HTML for the Transaction main meta box |
|
| 773 | - * |
|
| 774 | - * @access public |
|
| 775 | - * @return void |
|
| 776 | - */ |
|
| 777 | - public function txn_details_meta_box() |
|
| 778 | - { |
|
| 779 | - |
|
| 780 | - $this->_set_transaction_object(); |
|
| 781 | - $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 782 | - $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null; |
|
| 783 | - |
|
| 784 | - //get line table |
|
| 785 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 786 | - $Line_Item_Display = new EE_Line_Item_Display('admin_table', |
|
| 787 | - 'EE_Admin_Table_Line_Item_Display_Strategy'); |
|
| 788 | - $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item()); |
|
| 789 | - $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration')->get('REG_code'); |
|
| 790 | - |
|
| 791 | - // process taxes |
|
| 792 | - $taxes = $this->_transaction->get_many_related('Line_Item', |
|
| 793 | - array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 794 | - $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 795 | - |
|
| 796 | - $this->_template_args['grand_total'] = EEH_Template::format_currency($this->_transaction->get('TXN_total'), |
|
| 797 | - false, false); |
|
| 798 | - $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
| 799 | - $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
| 30 | + /** |
|
| 31 | + * @var EE_Transaction |
|
| 32 | + */ |
|
| 33 | + private $_transaction; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var EE_Session |
|
| 37 | + */ |
|
| 38 | + private $_session; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var array $_txn_status |
|
| 42 | + */ |
|
| 43 | + private static $_txn_status; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var array $_pay_status |
|
| 47 | + */ |
|
| 48 | + private static $_pay_status; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var array $_existing_reg_payment_REG_IDs |
|
| 52 | + */ |
|
| 53 | + protected $_existing_reg_payment_REG_IDs = null; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @Constructor |
|
| 58 | + * @access public |
|
| 59 | + * |
|
| 60 | + * @param bool $routing |
|
| 61 | + * |
|
| 62 | + * @return Transactions_Admin_Page |
|
| 63 | + */ |
|
| 64 | + public function __construct($routing = true) |
|
| 65 | + { |
|
| 66 | + parent::__construct($routing); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * _init_page_props |
|
| 72 | + * @return void |
|
| 73 | + */ |
|
| 74 | + protected function _init_page_props() |
|
| 75 | + { |
|
| 76 | + $this->page_slug = TXN_PG_SLUG; |
|
| 77 | + $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 78 | + $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 79 | + $this->_admin_base_path = TXN_ADMIN; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * _ajax_hooks |
|
| 85 | + * @return void |
|
| 86 | + */ |
|
| 87 | + protected function _ajax_hooks() |
|
| 88 | + { |
|
| 89 | + add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 90 | + add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 91 | + add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * _define_page_props |
|
| 97 | + * @return void |
|
| 98 | + */ |
|
| 99 | + protected function _define_page_props() |
|
| 100 | + { |
|
| 101 | + $this->_admin_page_title = $this->page_label; |
|
| 102 | + $this->_labels = array( |
|
| 103 | + 'buttons' => array( |
|
| 104 | + 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 105 | + 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 106 | + 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 107 | + ) |
|
| 108 | + ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * grab url requests and route them |
|
| 114 | + * @access private |
|
| 115 | + * @return void |
|
| 116 | + */ |
|
| 117 | + public function _set_page_routes() |
|
| 118 | + { |
|
| 119 | + |
|
| 120 | + $this->_set_transaction_status_array(); |
|
| 121 | + |
|
| 122 | + $txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0; |
|
| 123 | + |
|
| 124 | + $this->_page_routes = array( |
|
| 125 | + |
|
| 126 | + 'default' => array( |
|
| 127 | + 'func' => '_transactions_overview_list_table', |
|
| 128 | + 'capability' => 'ee_read_transactions' |
|
| 129 | + ), |
|
| 130 | + |
|
| 131 | + 'view_transaction' => array( |
|
| 132 | + 'func' => '_transaction_details', |
|
| 133 | + 'capability' => 'ee_read_transaction', |
|
| 134 | + 'obj_id' => $txn_id |
|
| 135 | + ), |
|
| 136 | + |
|
| 137 | + 'send_payment_reminder' => array( |
|
| 138 | + 'func' => '_send_payment_reminder', |
|
| 139 | + 'noheader' => true, |
|
| 140 | + 'capability' => 'ee_send_message' |
|
| 141 | + ), |
|
| 142 | + |
|
| 143 | + 'espresso_apply_payment' => array( |
|
| 144 | + 'func' => 'apply_payments_or_refunds', |
|
| 145 | + 'noheader' => true, |
|
| 146 | + 'capability' => 'ee_edit_payments' |
|
| 147 | + ), |
|
| 148 | + |
|
| 149 | + 'espresso_apply_refund' => array( |
|
| 150 | + 'func' => 'apply_payments_or_refunds', |
|
| 151 | + 'noheader' => true, |
|
| 152 | + 'capability' => 'ee_edit_payments' |
|
| 153 | + ), |
|
| 154 | + |
|
| 155 | + 'espresso_delete_payment' => array( |
|
| 156 | + 'func' => 'delete_payment', |
|
| 157 | + 'noheader' => true, |
|
| 158 | + 'capability' => 'ee_delete_payments' |
|
| 159 | + ), |
|
| 160 | + |
|
| 161 | + ); |
|
| 162 | + |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + protected function _set_page_config() |
|
| 167 | + { |
|
| 168 | + $this->_page_config = array( |
|
| 169 | + 'default' => array( |
|
| 170 | + 'nav' => array( |
|
| 171 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 172 | + 'order' => 10 |
|
| 173 | + ), |
|
| 174 | + 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 175 | + 'help_tabs' => array( |
|
| 176 | + 'transactions_overview_help_tab' => array( |
|
| 177 | + 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 178 | + 'filename' => 'transactions_overview' |
|
| 179 | + ), |
|
| 180 | + 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 181 | + 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 182 | + 'filename' => 'transactions_overview_table_column_headings' |
|
| 183 | + ), |
|
| 184 | + 'transactions_overview_views_filters_help_tab' => array( |
|
| 185 | + 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 186 | + 'filename' => 'transactions_overview_views_filters_search' |
|
| 187 | + ), |
|
| 188 | + ), |
|
| 189 | + 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 190 | + /** |
|
| 191 | + * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 192 | + * may change in a later iteration so want to keep the code for then. |
|
| 193 | + */ |
|
| 194 | + //'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 195 | + 'require_nonce' => false |
|
| 196 | + ), |
|
| 197 | + 'view_transaction' => array( |
|
| 198 | + 'nav' => array( |
|
| 199 | + 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 200 | + 'order' => 5, |
|
| 201 | + 'url' => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), |
|
| 202 | + $this->_current_page_view_url) : $this->_admin_base_url, |
|
| 203 | + 'persistent' => false |
|
| 204 | + ), |
|
| 205 | + 'help_tabs' => array( |
|
| 206 | + 'transactions_view_transaction_help_tab' => array( |
|
| 207 | + 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 208 | + 'filename' => 'transactions_view_transaction' |
|
| 209 | + ), |
|
| 210 | + 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 211 | + 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 212 | + 'filename' => 'transactions_view_transaction_transaction_details_table' |
|
| 213 | + ), |
|
| 214 | + 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 215 | + 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 216 | + 'filename' => 'transactions_view_transaction_attendees_registered' |
|
| 217 | + ), |
|
| 218 | + 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 219 | + 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 220 | + 'filename' => 'transactions_view_transaction_primary_registrant_billing_information' |
|
| 221 | + ), |
|
| 222 | + ), |
|
| 223 | + 'qtips' => array('Transaction_Details_Tips'), |
|
| 224 | + 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 225 | + 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 226 | + |
|
| 227 | + 'require_nonce' => false |
|
| 228 | + ) |
|
| 229 | + ); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * The below methods aren't used by this class currently |
|
| 235 | + */ |
|
| 236 | + protected function _add_screen_options() |
|
| 237 | + { |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + protected function _add_feature_pointers() |
|
| 241 | + { |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + public function admin_init() |
|
| 245 | + { |
|
| 246 | + // IF a registration was JUST added via the admin... |
|
| 247 | + if ( |
|
| 248 | + isset( |
|
| 249 | + $this->_req_data['redirect_from'], |
|
| 250 | + $this->_req_data['EVT_ID'], |
|
| 251 | + $this->_req_data['event_name'] |
|
| 252 | + ) |
|
| 253 | + ) { |
|
| 254 | + // then set a cookie so that we can block any attempts to use |
|
| 255 | + // the back button as a way to enter another registration. |
|
| 256 | + setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'); |
|
| 257 | + // and update the global |
|
| 258 | + $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 259 | + } |
|
| 260 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 261 | + 'event_espresso'); |
|
| 262 | + EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__('An error occurred! Please refresh the page and try again.', |
|
| 263 | + 'event_espresso'); |
|
| 264 | + EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 265 | + EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 266 | + EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 267 | + EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__('This transaction has been overpaid ! Payments Total', |
|
| 268 | + 'event_espresso'); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + public function admin_notices() |
|
| 272 | + { |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + public function admin_footer_scripts() |
|
| 276 | + { |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * _set_transaction_status_array |
|
| 282 | + * sets list of transaction statuses |
|
| 283 | + * |
|
| 284 | + * @access private |
|
| 285 | + * @return void |
|
| 286 | + */ |
|
| 287 | + private function _set_transaction_status_array() |
|
| 288 | + { |
|
| 289 | + self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * get_transaction_status_array |
|
| 295 | + * return the transaction status array for wp_list_table |
|
| 296 | + * |
|
| 297 | + * @access public |
|
| 298 | + * @return array |
|
| 299 | + */ |
|
| 300 | + public function get_transaction_status_array() |
|
| 301 | + { |
|
| 302 | + return self::$_txn_status; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * get list of payment statuses |
|
| 308 | + * |
|
| 309 | + * @access private |
|
| 310 | + * @return void |
|
| 311 | + */ |
|
| 312 | + private function _get_payment_status_array() |
|
| 313 | + { |
|
| 314 | + self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 315 | + $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 316 | + |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * _add_screen_options_default |
|
| 322 | + * |
|
| 323 | + * @access protected |
|
| 324 | + * @return void |
|
| 325 | + */ |
|
| 326 | + protected function _add_screen_options_default() |
|
| 327 | + { |
|
| 328 | + $this->_per_page_screen_option(); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * load_scripts_styles |
|
| 334 | + * |
|
| 335 | + * @access public |
|
| 336 | + * @return void |
|
| 337 | + */ |
|
| 338 | + public function load_scripts_styles() |
|
| 339 | + { |
|
| 340 | + //enqueue style |
|
| 341 | + wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), |
|
| 342 | + EVENT_ESPRESSO_VERSION); |
|
| 343 | + wp_enqueue_style('espresso_txn'); |
|
| 344 | + //scripts |
|
| 345 | + wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
| 346 | + 'ee_admin_js', |
|
| 347 | + 'ee-datepicker', |
|
| 348 | + 'jquery-ui-datepicker', |
|
| 349 | + 'jquery-ui-draggable', |
|
| 350 | + 'ee-dialog', |
|
| 351 | + 'ee-accounting', |
|
| 352 | + 'ee-serialize-full-array' |
|
| 353 | + ), EVENT_ESPRESSO_VERSION, true); |
|
| 354 | + wp_enqueue_script('espresso_txn'); |
|
| 355 | + |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * load_scripts_styles_view_transaction |
|
| 361 | + * |
|
| 362 | + * @access public |
|
| 363 | + * @return void |
|
| 364 | + */ |
|
| 365 | + public function load_scripts_styles_view_transaction() |
|
| 366 | + { |
|
| 367 | + //styles |
|
| 368 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * load_scripts_styles_default |
|
| 374 | + * |
|
| 375 | + * @access public |
|
| 376 | + * @return void |
|
| 377 | + */ |
|
| 378 | + public function load_scripts_styles_default() |
|
| 379 | + { |
|
| 380 | + //styles |
|
| 381 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * _set_list_table_views_default |
|
| 387 | + * |
|
| 388 | + * @access protected |
|
| 389 | + * @return void |
|
| 390 | + */ |
|
| 391 | + protected function _set_list_table_views_default() |
|
| 392 | + { |
|
| 393 | + $this->_views = array( |
|
| 394 | + 'all' => array( |
|
| 395 | + 'slug' => 'all', |
|
| 396 | + 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 397 | + 'count' => 0 |
|
| 398 | + ), |
|
| 399 | + 'abandoned' => array( |
|
| 400 | + 'slug' => 'abandoned', |
|
| 401 | + 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 402 | + 'count' => 0 |
|
| 403 | + ), |
|
| 404 | + 'failed' => array( |
|
| 405 | + 'slug' => 'failed', |
|
| 406 | + 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 407 | + 'count' => 0 |
|
| 408 | + ) |
|
| 409 | + ); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * _set_transaction_object |
|
| 415 | + * This sets the _transaction property for the transaction details screen |
|
| 416 | + * |
|
| 417 | + * @access private |
|
| 418 | + * @return void |
|
| 419 | + */ |
|
| 420 | + private function _set_transaction_object() |
|
| 421 | + { |
|
| 422 | + if (is_object($this->_transaction)) { |
|
| 423 | + return; |
|
| 424 | + } //get out we've already set the object |
|
| 425 | + |
|
| 426 | + $TXN = EEM_Transaction::instance(); |
|
| 427 | + |
|
| 428 | + $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 429 | + |
|
| 430 | + //get transaction object |
|
| 431 | + $this->_transaction = $TXN->get_one_by_ID($TXN_ID); |
|
| 432 | + $this->_session = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null; |
|
| 433 | + $this->_transaction->verify_abandoned_transaction_status(); |
|
| 434 | + |
|
| 435 | + if (empty($this->_transaction)) { |
|
| 436 | + $error_msg = esc_html__('An error occurred and the details for Transaction ID #', |
|
| 437 | + 'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso'); |
|
| 438 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * _transaction_legend_items |
|
| 445 | + * |
|
| 446 | + * @access protected |
|
| 447 | + * @return array |
|
| 448 | + */ |
|
| 449 | + protected function _transaction_legend_items() |
|
| 450 | + { |
|
| 451 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 452 | + $items = array(); |
|
| 453 | + |
|
| 454 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 455 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 456 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 457 | + $items['view_related_messages'] = array( |
|
| 458 | + 'class' => $related_for_icon['css_class'], |
|
| 459 | + 'desc' => $related_for_icon['label'], |
|
| 460 | + ); |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + $items = apply_filters( |
|
| 465 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 466 | + array_merge($items, |
|
| 467 | + array( |
|
| 468 | + 'view_details' => array( |
|
| 469 | + 'class' => 'dashicons dashicons-cart', |
|
| 470 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso') |
|
| 471 | + ), |
|
| 472 | + 'view_invoice' => array( |
|
| 473 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 474 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso') |
|
| 475 | + ), |
|
| 476 | + 'view_receipt' => array( |
|
| 477 | + 'class' => 'dashicons dashicons-media-default', |
|
| 478 | + 'desc' => esc_html__('View Transaction Receipt', 'event_espresso') |
|
| 479 | + ), |
|
| 480 | + 'view_registration' => array( |
|
| 481 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 482 | + 'desc' => esc_html__('View Registration Details', 'event_espresso') |
|
| 483 | + ) |
|
| 484 | + ) |
|
| 485 | + ) |
|
| 486 | + ); |
|
| 487 | + |
|
| 488 | + if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 489 | + 'espresso_transactions_send_payment_reminder') |
|
| 490 | + ) { |
|
| 491 | + if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
| 492 | + $items['send_payment_reminder'] = array( |
|
| 493 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 494 | + 'desc' => esc_html__('Send Payment Reminder', 'event_espresso') |
|
| 495 | + ); |
|
| 496 | + } else { |
|
| 497 | + $items['blank*'] = array( |
|
| 498 | + 'class' => '', |
|
| 499 | + 'desc' => '' |
|
| 500 | + ); |
|
| 501 | + } |
|
| 502 | + } else { |
|
| 503 | + $items['blank*'] = array( |
|
| 504 | + 'class' => '', |
|
| 505 | + 'desc' => '' |
|
| 506 | + ); |
|
| 507 | + } |
|
| 508 | + $more_items = apply_filters( |
|
| 509 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 510 | + array( |
|
| 511 | + 'overpaid' => array( |
|
| 512 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 513 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence') |
|
| 514 | + ), |
|
| 515 | + 'complete' => array( |
|
| 516 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 517 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence') |
|
| 518 | + ), |
|
| 519 | + 'incomplete' => array( |
|
| 520 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 521 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence') |
|
| 522 | + ), |
|
| 523 | + 'abandoned' => array( |
|
| 524 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 525 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence') |
|
| 526 | + ), |
|
| 527 | + 'failed' => array( |
|
| 528 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 529 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence') |
|
| 530 | + ) |
|
| 531 | + ) |
|
| 532 | + ); |
|
| 533 | + |
|
| 534 | + return array_merge($items, $more_items); |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * _transactions_overview_list_table |
|
| 540 | + * |
|
| 541 | + * @access protected |
|
| 542 | + * @return void |
|
| 543 | + */ |
|
| 544 | + protected function _transactions_overview_list_table() |
|
| 545 | + { |
|
| 546 | + $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 547 | + $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null; |
|
| 548 | + $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s', |
|
| 549 | + 'event_espresso'), '<h3>', |
|
| 550 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
| 551 | + EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event', |
|
| 552 | + 'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : ''; |
|
| 553 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 554 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * _transaction_details |
|
| 560 | + * generates HTML for the View Transaction Details Admin page |
|
| 561 | + * |
|
| 562 | + * @access protected |
|
| 563 | + * @return void |
|
| 564 | + */ |
|
| 565 | + protected function _transaction_details() |
|
| 566 | + { |
|
| 567 | + do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 568 | + |
|
| 569 | + $this->_set_transaction_status_array(); |
|
| 570 | + |
|
| 571 | + $this->_template_args = array(); |
|
| 572 | + $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 573 | + |
|
| 574 | + $this->_set_transaction_object(); |
|
| 575 | + |
|
| 576 | + $primary_registration = $this->_transaction->primary_registration(); |
|
| 577 | + $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null; |
|
| 578 | + |
|
| 579 | + $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 580 | + $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 581 | + |
|
| 582 | + $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 583 | + $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 584 | + |
|
| 585 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
| 586 | + $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 587 | + $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 588 | + |
|
| 589 | + $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
| 590 | + $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
| 591 | + |
|
| 592 | + if ( |
|
| 593 | + $attendee instanceof EE_Attendee |
|
| 594 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 595 | + 'ee_send_message', |
|
| 596 | + 'espresso_transactions_send_payment_reminder' |
|
| 597 | + ) |
|
| 598 | + ) { |
|
| 599 | + $this->_template_args['send_payment_reminder_button'] = |
|
| 600 | + EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 601 | + && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code |
|
| 602 | + && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code |
|
| 603 | + ? EEH_Template::get_button_or_link( |
|
| 604 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 605 | + array( |
|
| 606 | + 'action' => 'send_payment_reminder', |
|
| 607 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 608 | + 'redirect_to' => 'view_transaction' |
|
| 609 | + ), |
|
| 610 | + TXN_ADMIN_URL |
|
| 611 | + ), |
|
| 612 | + __(' Send Payment Reminder', 'event_espresso'), |
|
| 613 | + 'button secondary-button right', |
|
| 614 | + 'dashicons dashicons-email-alt' |
|
| 615 | + ) |
|
| 616 | + : ''; |
|
| 617 | + } else { |
|
| 618 | + $this->_template_args['send_payment_reminder_button'] = ''; |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
| 622 | + $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true); |
|
| 623 | + if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 624 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; |
|
| 625 | + } else { |
|
| 626 | + $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; |
|
| 627 | + } |
|
| 628 | + $this->_template_args['amount_due_class'] = ''; |
|
| 629 | + |
|
| 630 | + if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
| 631 | + // paid in full |
|
| 632 | + $this->_template_args['amount_due'] = false; |
|
| 633 | + } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
| 634 | + // overpaid |
|
| 635 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 636 | + } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) { |
|
| 637 | + // monies owing |
|
| 638 | + $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 639 | + } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) { |
|
| 640 | + // no payments made yet |
|
| 641 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 642 | + } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
| 643 | + // free event |
|
| 644 | + $this->_template_args['amount_due'] = false; |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + $payment_method = $this->_transaction->payment_method(); |
|
| 648 | + |
|
| 649 | + $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 650 | + ? $payment_method->admin_name() |
|
| 651 | + : esc_html__('Unknown', 'event_espresso'); |
|
| 652 | + |
|
| 653 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 654 | + // link back to overview |
|
| 655 | + $this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER']) |
|
| 656 | + ? $_SERVER['HTTP_REFERER'] |
|
| 657 | + : TXN_ADMIN_URL; |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + // next link |
|
| 661 | + $next_txn = $this->_transaction->next( |
|
| 662 | + null, |
|
| 663 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 664 | + 'TXN_ID' |
|
| 665 | + ); |
|
| 666 | + $this->_template_args['next_transaction'] = $next_txn |
|
| 667 | + ? $this->_next_link( |
|
| 668 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 669 | + array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 670 | + TXN_ADMIN_URL |
|
| 671 | + ), |
|
| 672 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 673 | + ) |
|
| 674 | + : ''; |
|
| 675 | + // previous link |
|
| 676 | + $previous_txn = $this->_transaction->previous( |
|
| 677 | + null, |
|
| 678 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 679 | + 'TXN_ID' |
|
| 680 | + ); |
|
| 681 | + $this->_template_args['previous_transaction'] = $previous_txn |
|
| 682 | + ? $this->_previous_link( |
|
| 683 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 684 | + array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 685 | + TXN_ADMIN_URL |
|
| 686 | + ), |
|
| 687 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 688 | + ) |
|
| 689 | + : ''; |
|
| 690 | + |
|
| 691 | + // were we just redirected here after adding a new registration ??? |
|
| 692 | + if ( |
|
| 693 | + isset( |
|
| 694 | + $this->_req_data['redirect_from'], |
|
| 695 | + $this->_req_data['EVT_ID'], |
|
| 696 | + $this->_req_data['event_name'] |
|
| 697 | + ) |
|
| 698 | + ) { |
|
| 699 | + if ( |
|
| 700 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 701 | + 'ee_edit_registrations', |
|
| 702 | + 'espresso_registrations_new_registration', |
|
| 703 | + $this->_req_data['EVT_ID'] |
|
| 704 | + ) |
|
| 705 | + ) { |
|
| 706 | + $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 707 | + $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 708 | + array( |
|
| 709 | + 'page' => 'espresso_registrations', |
|
| 710 | + 'action' => 'new_registration', |
|
| 711 | + 'return' => 'default', |
|
| 712 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 713 | + 'event_id' => $this->_req_data['EVT_ID'], |
|
| 714 | + ), |
|
| 715 | + REG_ADMIN_URL |
|
| 716 | + ); |
|
| 717 | + $this->_admin_page_title .= '">'; |
|
| 718 | + |
|
| 719 | + $this->_admin_page_title .= sprintf( |
|
| 720 | + esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 721 | + htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 722 | + ); |
|
| 723 | + $this->_admin_page_title .= '</a>'; |
|
| 724 | + } |
|
| 725 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 726 | + } |
|
| 727 | + // grab messages at the last second |
|
| 728 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 729 | + // path to template |
|
| 730 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 731 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
|
| 732 | + $this->_template_args, true); |
|
| 733 | + |
|
| 734 | + // the details template wrapper |
|
| 735 | + $this->display_admin_page_with_sidebar(); |
|
| 736 | + |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * _transaction_details_metaboxes |
|
| 742 | + * |
|
| 743 | + * @access protected |
|
| 744 | + * @return void |
|
| 745 | + */ |
|
| 746 | + protected function _transaction_details_metaboxes() |
|
| 747 | + { |
|
| 748 | + |
|
| 749 | + $this->_set_transaction_object(); |
|
| 750 | + |
|
| 751 | + add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'), |
|
| 752 | + array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high'); |
|
| 753 | + add_meta_box( |
|
| 754 | + 'edit-txn-attendees-mbox', |
|
| 755 | + esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 756 | + array($this, 'txn_attendees_meta_box'), |
|
| 757 | + $this->_wp_page_slug, |
|
| 758 | + 'normal', |
|
| 759 | + 'high', |
|
| 760 | + array('TXN_ID' => $this->_transaction->ID()) |
|
| 761 | + ); |
|
| 762 | + add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'), |
|
| 763 | + array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
| 764 | + add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'), |
|
| 765 | + array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
| 766 | + |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * txn_details_meta_box |
|
| 772 | + * generates HTML for the Transaction main meta box |
|
| 773 | + * |
|
| 774 | + * @access public |
|
| 775 | + * @return void |
|
| 776 | + */ |
|
| 777 | + public function txn_details_meta_box() |
|
| 778 | + { |
|
| 779 | + |
|
| 780 | + $this->_set_transaction_object(); |
|
| 781 | + $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 782 | + $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null; |
|
| 783 | + |
|
| 784 | + //get line table |
|
| 785 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 786 | + $Line_Item_Display = new EE_Line_Item_Display('admin_table', |
|
| 787 | + 'EE_Admin_Table_Line_Item_Display_Strategy'); |
|
| 788 | + $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item()); |
|
| 789 | + $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration')->get('REG_code'); |
|
| 790 | + |
|
| 791 | + // process taxes |
|
| 792 | + $taxes = $this->_transaction->get_many_related('Line_Item', |
|
| 793 | + array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 794 | + $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 795 | + |
|
| 796 | + $this->_template_args['grand_total'] = EEH_Template::format_currency($this->_transaction->get('TXN_total'), |
|
| 797 | + false, false); |
|
| 798 | + $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
| 799 | + $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
| 800 | 800 | |
| 801 | 801 | // $txn_status_class = 'status-' . $this->_transaction->get('STS_ID'); |
| 802 | 802 | |
| 803 | - // process payment details |
|
| 804 | - $payments = $this->_transaction->get_many_related('Payment'); |
|
| 805 | - if ( ! empty($payments)) { |
|
| 806 | - $this->_template_args['payments'] = $payments; |
|
| 807 | - $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 808 | - } else { |
|
| 809 | - $this->_template_args['payments'] = false; |
|
| 810 | - $this->_template_args['existing_reg_payments'] = array(); |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 814 | - $this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'), |
|
| 815 | - TXN_ADMIN_URL); |
|
| 816 | - |
|
| 817 | - if (isset($txn_details['invoice_number'])) { |
|
| 818 | - $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 819 | - $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number', |
|
| 820 | - 'event_espresso'); |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session'); |
|
| 824 | - $this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session', |
|
| 825 | - 'event_espresso'); |
|
| 826 | - |
|
| 827 | - $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : ''; |
|
| 828 | - $this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP', |
|
| 829 | - 'event_espresso'); |
|
| 830 | - |
|
| 831 | - $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : ''; |
|
| 832 | - $this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent', |
|
| 833 | - 'event_espresso'); |
|
| 834 | - |
|
| 835 | - $reg_steps = '<ul>'; |
|
| 836 | - foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 837 | - if ($reg_step_status === true) { |
|
| 838 | - $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 839 | - ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 840 | - } else if (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 841 | - $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( |
|
| 842 | - esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 843 | - ucwords(str_replace('_', ' ', $reg_step)), |
|
| 844 | - date(get_option('date_format') . ' ' . get_option('time_format'), |
|
| 845 | - ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))) |
|
| 846 | - ) . '</li>'; |
|
| 847 | - } else { |
|
| 848 | - $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated', |
|
| 849 | - 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 850 | - } |
|
| 851 | - } |
|
| 852 | - $reg_steps .= '</ul>'; |
|
| 853 | - $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 854 | - $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress', |
|
| 855 | - 'event_espresso'); |
|
| 856 | - |
|
| 857 | - |
|
| 858 | - $this->_get_registrations_to_apply_payment_to(); |
|
| 859 | - $this->_get_payment_methods($payments); |
|
| 860 | - $this->_get_payment_status_array(); |
|
| 861 | - $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
|
| 862 | - |
|
| 863 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 864 | - 'action' => 'edit_transaction', |
|
| 865 | - 'process' => 'transaction' |
|
| 866 | - ), TXN_ADMIN_URL); |
|
| 867 | - $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 868 | - 'page' => 'espresso_transactions', |
|
| 869 | - 'action' => 'espresso_apply_payment' |
|
| 870 | - ), WP_AJAX_URL); |
|
| 871 | - $this->_template_args['delete_payment_form_url'] = add_query_arg(array( |
|
| 872 | - 'page' => 'espresso_transactions', |
|
| 873 | - 'action' => 'espresso_delete_payment' |
|
| 874 | - ), WP_AJAX_URL); |
|
| 875 | - |
|
| 876 | - // 'espresso_delete_payment_nonce' |
|
| 877 | - |
|
| 878 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 879 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 880 | - |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - |
|
| 884 | - /** |
|
| 885 | - * _get_registration_payment_IDs |
|
| 886 | - * |
|
| 887 | - * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 888 | - * |
|
| 889 | - * @access protected |
|
| 890 | - * |
|
| 891 | - * @param EE_Payment[] $payments |
|
| 892 | - * |
|
| 893 | - * @return array |
|
| 894 | - */ |
|
| 895 | - protected function _get_registration_payment_IDs($payments = array()) |
|
| 896 | - { |
|
| 897 | - $existing_reg_payments = array(); |
|
| 898 | - // get all reg payments for these payments |
|
| 899 | - $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
| 900 | - array( |
|
| 901 | - 'PAY_ID' => array( |
|
| 902 | - 'IN', |
|
| 903 | - array_keys($payments) |
|
| 904 | - ) |
|
| 905 | - ) |
|
| 906 | - )); |
|
| 907 | - if ( ! empty($reg_payments)) { |
|
| 908 | - foreach ($payments as $payment) { |
|
| 909 | - if ( ! $payment instanceof EE_Payment) { |
|
| 910 | - continue; |
|
| 911 | - } else if ( ! isset($existing_reg_payments[$payment->ID()])) { |
|
| 912 | - $existing_reg_payments[$payment->ID()] = array(); |
|
| 913 | - } |
|
| 914 | - foreach ($reg_payments as $reg_payment) { |
|
| 915 | - if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) { |
|
| 916 | - $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
| 917 | - } |
|
| 918 | - } |
|
| 919 | - } |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - return $existing_reg_payments; |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * _get_registrations_to_apply_payment_to |
|
| 928 | - * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 929 | - * which allows the admin to only apply the payment to the specific registrations |
|
| 930 | - * |
|
| 931 | - * @access protected |
|
| 932 | - * @return void |
|
| 933 | - * @throws \EE_Error |
|
| 934 | - */ |
|
| 935 | - protected function _get_registrations_to_apply_payment_to() |
|
| 936 | - { |
|
| 937 | - // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 938 | - $query_params = array( |
|
| 939 | - array( |
|
| 940 | - 'STS_ID' => array( |
|
| 941 | - 'IN', |
|
| 942 | - array( |
|
| 943 | - EEM_Registration::status_id_approved, |
|
| 944 | - EEM_Registration::status_id_pending_payment, |
|
| 945 | - EEM_Registration::status_id_not_approved, |
|
| 946 | - ) |
|
| 947 | - ) |
|
| 948 | - ) |
|
| 949 | - ); |
|
| 950 | - $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 951 | - '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 952 | - ); |
|
| 953 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 954 | - $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 955 | - $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 956 | - EEH_HTML::tr( |
|
| 957 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 958 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 959 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 960 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 961 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 962 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 963 | - EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 964 | - ) |
|
| 965 | - ); |
|
| 966 | - $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 967 | - // get registrations for TXN |
|
| 968 | - $registrations = $this->_transaction->registrations($query_params); |
|
| 969 | - foreach ($registrations as $registration) { |
|
| 970 | - if ($registration instanceof EE_Registration) { |
|
| 971 | - $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 972 | - ? $registration->attendee()->full_name() |
|
| 973 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 974 | - $owing = $registration->final_price() - $registration->paid(); |
|
| 975 | - $taxable = $registration->ticket()->taxable() |
|
| 976 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 977 | - : ''; |
|
| 978 | - $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
|
| 979 | - ? ' checked="checked"' |
|
| 980 | - : ''; |
|
| 981 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 982 | - $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 983 | - EEH_HTML::td($registration->ID()) . |
|
| 984 | - EEH_HTML::td($attendee_name) . |
|
| 985 | - EEH_HTML::td( |
|
| 986 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 987 | - ) . |
|
| 988 | - EEH_HTML::td($registration->event_name()) . |
|
| 989 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 990 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 991 | - EEH_HTML::td( |
|
| 992 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 993 | - . '" name="txn_admin_payment[registrations]"' |
|
| 994 | - . $checked . $disabled . '>', |
|
| 995 | - '', 'jst-cntr' |
|
| 996 | - ), |
|
| 997 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 998 | - ); |
|
| 999 | - } |
|
| 1000 | - } |
|
| 1001 | - $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1002 | - $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1003 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1004 | - $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1005 | - esc_html__( |
|
| 1006 | - 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
| 1007 | - 'event_espresso' |
|
| 1008 | - ), |
|
| 1009 | - '', 'clear description' |
|
| 1010 | - ); |
|
| 1011 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1012 | - $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1013 | - } |
|
| 1014 | - |
|
| 1015 | - |
|
| 1016 | - /** |
|
| 1017 | - * _get_reg_status_selection |
|
| 1018 | - * |
|
| 1019 | - * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1020 | - * instead of events. |
|
| 1021 | - * @access protected |
|
| 1022 | - * @return void |
|
| 1023 | - */ |
|
| 1024 | - protected function _get_reg_status_selection() |
|
| 1025 | - { |
|
| 1026 | - //first get all possible statuses |
|
| 1027 | - $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1028 | - //let's add a "don't change" option. |
|
| 1029 | - $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1030 | - $status_array = array_merge($status_array, $statuses); |
|
| 1031 | - $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]', |
|
| 1032 | - $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status'); |
|
| 1033 | - $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]', |
|
| 1034 | - $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status'); |
|
| 1035 | - |
|
| 1036 | - } |
|
| 1037 | - |
|
| 1038 | - |
|
| 1039 | - /** |
|
| 1040 | - * _get_payment_methods |
|
| 1041 | - * Gets all the payment methods available generally, or the ones that are already |
|
| 1042 | - * selected on these payments (in case their payment methods are no longer active). |
|
| 1043 | - * Has the side-effect of updating the template args' payment_methods item |
|
| 1044 | - * @access private |
|
| 1045 | - * |
|
| 1046 | - * @param EE_Payment[] to show on this page |
|
| 1047 | - * |
|
| 1048 | - * @return void |
|
| 1049 | - */ |
|
| 1050 | - private function _get_payment_methods($payments = array()) |
|
| 1051 | - { |
|
| 1052 | - $payment_methods_of_payments = array(); |
|
| 1053 | - foreach ($payments as $payment) { |
|
| 1054 | - if ($payment instanceof EE_Payment) { |
|
| 1055 | - $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
| 1056 | - } |
|
| 1057 | - } |
|
| 1058 | - if ($payment_methods_of_payments) { |
|
| 1059 | - $query_args = array( |
|
| 1060 | - array( |
|
| 1061 | - 'OR*payment_method_for_payment' => array( |
|
| 1062 | - 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1063 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%') |
|
| 1064 | - ) |
|
| 1065 | - ) |
|
| 1066 | - ); |
|
| 1067 | - } else { |
|
| 1068 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1069 | - } |
|
| 1070 | - $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - |
|
| 1074 | - /** |
|
| 1075 | - * txn_attendees_meta_box |
|
| 1076 | - * generates HTML for the Attendees Transaction main meta box |
|
| 1077 | - * |
|
| 1078 | - * @access public |
|
| 1079 | - * |
|
| 1080 | - * @param WP_Post $post |
|
| 1081 | - * @param array $metabox |
|
| 1082 | - * |
|
| 1083 | - * @return void |
|
| 1084 | - */ |
|
| 1085 | - public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1086 | - { |
|
| 1087 | - |
|
| 1088 | - extract($metabox['args']); |
|
| 1089 | - $this->_template_args['post'] = $post; |
|
| 1090 | - $this->_template_args['event_attendees'] = array(); |
|
| 1091 | - // process items in cart |
|
| 1092 | - $line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item'))); |
|
| 1093 | - if ( ! empty($line_items)) { |
|
| 1094 | - foreach ($line_items as $item) { |
|
| 1095 | - if ($item instanceof EE_Line_Item) { |
|
| 1096 | - switch ($item->OBJ_type()) { |
|
| 1097 | - |
|
| 1098 | - case 'Event' : |
|
| 1099 | - break; |
|
| 1100 | - |
|
| 1101 | - case 'Ticket' : |
|
| 1102 | - $ticket = $item->ticket(); |
|
| 1103 | - //right now we're only handling tickets here. Cause its expected that only tickets will have attendees right? |
|
| 1104 | - if ( ! $ticket instanceof EE_Ticket) { |
|
| 1105 | - continue; |
|
| 1106 | - } |
|
| 1107 | - try { |
|
| 1108 | - $event_name = $ticket->get_event_name(); |
|
| 1109 | - } catch (Exception $e) { |
|
| 1110 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1111 | - $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1112 | - } |
|
| 1113 | - $event_name .= ' - ' . $item->get('LIN_name'); |
|
| 1114 | - $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
| 1115 | - // now get all of the registrations for this transaction that use this ticket |
|
| 1116 | - $registrations = $ticket->get_many_related('Registration', |
|
| 1117 | - array(array('TXN_ID' => $this->_transaction->ID()))); |
|
| 1118 | - foreach ($registrations as $registration) { |
|
| 1119 | - if ( ! $registration instanceof EE_Registration) { |
|
| 1120 | - continue; |
|
| 1121 | - } |
|
| 1122 | - $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] = $registration->status_ID(); |
|
| 1123 | - $this->_template_args['event_attendees'][$registration->ID()]['att_num'] = $registration->count(); |
|
| 1124 | - $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name; |
|
| 1125 | - $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] = $ticket_price; |
|
| 1126 | - // attendee info |
|
| 1127 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 1128 | - if ($attendee instanceof EE_Attendee) { |
|
| 1129 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); |
|
| 1130 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); |
|
| 1131 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event', |
|
| 1132 | - 'event_espresso') . '">' . $attendee->email() . '</a>'; |
|
| 1133 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] = EEH_Address::format($attendee, |
|
| 1134 | - 'inline', false, false); |
|
| 1135 | - } else { |
|
| 1136 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
| 1137 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
| 1138 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
| 1139 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
| 1140 | - } |
|
| 1141 | - } |
|
| 1142 | - break; |
|
| 1143 | - |
|
| 1144 | - } |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 1149 | - 'action' => 'edit_transaction', |
|
| 1150 | - 'process' => 'attendees' |
|
| 1151 | - ), TXN_ADMIN_URL); |
|
| 1152 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1153 | - $this->_template_args, true); |
|
| 1154 | - |
|
| 1155 | - } else { |
|
| 1156 | - echo sprintf( |
|
| 1157 | - esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1158 | - 'event_espresso'), |
|
| 1159 | - '<p class="important-notice">', |
|
| 1160 | - '</p>' |
|
| 1161 | - ); |
|
| 1162 | - } |
|
| 1163 | - } |
|
| 1164 | - |
|
| 1165 | - |
|
| 1166 | - /** |
|
| 1167 | - * txn_registrant_side_meta_box |
|
| 1168 | - * generates HTML for the Edit Transaction side meta box |
|
| 1169 | - * |
|
| 1170 | - * @access public |
|
| 1171 | - * @throws \EE_Error |
|
| 1172 | - * @return void |
|
| 1173 | - */ |
|
| 1174 | - public function txn_registrant_side_meta_box() |
|
| 1175 | - { |
|
| 1176 | - $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null; |
|
| 1177 | - if ( ! $primary_att instanceof EE_Attendee) { |
|
| 1178 | - $this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1179 | - 'event_espresso'); |
|
| 1180 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1181 | - } |
|
| 1182 | - $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1183 | - $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1184 | - $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1185 | - $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1186 | - $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1187 | - $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1188 | - 'action' => 'edit_attendee', |
|
| 1189 | - 'post' => $primary_att->ID() |
|
| 1190 | - ), REG_ADMIN_URL); |
|
| 1191 | - // get formatted address for registrant |
|
| 1192 | - $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1193 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1194 | - $this->_template_args, true); |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - |
|
| 1198 | - /** |
|
| 1199 | - * txn_billing_info_side_meta_box |
|
| 1200 | - * generates HTML for the Edit Transaction side meta box |
|
| 1201 | - * |
|
| 1202 | - * @access public |
|
| 1203 | - * @return void |
|
| 1204 | - */ |
|
| 1205 | - public function txn_billing_info_side_meta_box() |
|
| 1206 | - { |
|
| 1207 | - |
|
| 1208 | - $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1209 | - $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1210 | - array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1211 | - TXN_ADMIN_URL |
|
| 1212 | - ); |
|
| 1213 | - |
|
| 1214 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1215 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - |
|
| 1219 | - /** |
|
| 1220 | - * apply_payments_or_refunds |
|
| 1221 | - * registers a payment or refund made towards a transaction |
|
| 1222 | - * |
|
| 1223 | - * @access public |
|
| 1224 | - * @return void |
|
| 1225 | - */ |
|
| 1226 | - public function apply_payments_or_refunds() |
|
| 1227 | - { |
|
| 1228 | - $json_response_data = array('return_data' => false); |
|
| 1229 | - $valid_data = $this->_validate_payment_request_data(); |
|
| 1230 | - if ( ! empty($valid_data)) { |
|
| 1231 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1232 | - //save the new payment |
|
| 1233 | - $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1234 | - // get the TXN for this payment |
|
| 1235 | - $transaction = $payment->transaction(); |
|
| 1236 | - // verify transaction |
|
| 1237 | - if ($transaction instanceof EE_Transaction) { |
|
| 1238 | - // calculate_total_payments_and_update_status |
|
| 1239 | - $this->_process_transaction_payments($transaction); |
|
| 1240 | - $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1241 | - $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1242 | - // apply payment to registrations (if applicable) |
|
| 1243 | - if ( ! empty($REG_IDs)) { |
|
| 1244 | - $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1245 | - $this->_maybe_send_notifications(); |
|
| 1246 | - // now process status changes for the same registrations |
|
| 1247 | - $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1248 | - } |
|
| 1249 | - $this->_maybe_send_notifications($payment); |
|
| 1250 | - //prepare to render page |
|
| 1251 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1252 | - do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction, |
|
| 1253 | - $payment); |
|
| 1254 | - } else { |
|
| 1255 | - EE_Error::add_error( |
|
| 1256 | - esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'), |
|
| 1257 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1258 | - ); |
|
| 1259 | - } |
|
| 1260 | - } else { |
|
| 1261 | - EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.', |
|
| 1262 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 1266 | - $this->_template_args = array( |
|
| 1267 | - 'data' => $json_response_data, |
|
| 1268 | - 'error' => $notices['errors'], |
|
| 1269 | - 'success' => $notices['success'] |
|
| 1270 | - ); |
|
| 1271 | - $this->_return_json(); |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - |
|
| 1275 | - /** |
|
| 1276 | - * _validate_payment_request_data |
|
| 1277 | - * |
|
| 1278 | - * @return array |
|
| 1279 | - */ |
|
| 1280 | - protected function _validate_payment_request_data() |
|
| 1281 | - { |
|
| 1282 | - if ( ! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1283 | - return false; |
|
| 1284 | - } |
|
| 1285 | - $payment_form = $this->_generate_payment_form_section(); |
|
| 1286 | - try { |
|
| 1287 | - if ($payment_form->was_submitted()) { |
|
| 1288 | - $payment_form->receive_form_submission(); |
|
| 1289 | - if ( ! $payment_form->is_valid()) { |
|
| 1290 | - $submission_error_messages = array(); |
|
| 1291 | - foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1292 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1293 | - $submission_error_messages[] = sprintf( |
|
| 1294 | - _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1295 | - $validation_error->get_form_section()->html_label_text(), |
|
| 1296 | - $validation_error->getMessage() |
|
| 1297 | - ); |
|
| 1298 | - } |
|
| 1299 | - } |
|
| 1300 | - EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
| 1301 | - |
|
| 1302 | - return array(); |
|
| 1303 | - } |
|
| 1304 | - } |
|
| 1305 | - } catch (EE_Error $e) { |
|
| 1306 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1307 | - |
|
| 1308 | - return array(); |
|
| 1309 | - } |
|
| 1310 | - |
|
| 1311 | - return $payment_form->valid_data(); |
|
| 1312 | - } |
|
| 1313 | - |
|
| 1314 | - |
|
| 1315 | - /** |
|
| 1316 | - * _generate_payment_form_section |
|
| 1317 | - * |
|
| 1318 | - * @return EE_Form_Section_Proper |
|
| 1319 | - */ |
|
| 1320 | - protected function _generate_payment_form_section() |
|
| 1321 | - { |
|
| 1322 | - return new EE_Form_Section_Proper( |
|
| 1323 | - array( |
|
| 1324 | - 'name' => 'txn_admin_payment', |
|
| 1325 | - 'subsections' => array( |
|
| 1326 | - 'PAY_ID' => new EE_Text_Input( |
|
| 1327 | - array( |
|
| 1328 | - 'default' => 0, |
|
| 1329 | - 'required' => false, |
|
| 1330 | - 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1331 | - 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1332 | - ) |
|
| 1333 | - ), |
|
| 1334 | - 'TXN_ID' => new EE_Text_Input( |
|
| 1335 | - array( |
|
| 1336 | - 'default' => 0, |
|
| 1337 | - 'required' => true, |
|
| 1338 | - 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1339 | - 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1340 | - ) |
|
| 1341 | - ), |
|
| 1342 | - 'type' => new EE_Text_Input( |
|
| 1343 | - array( |
|
| 1344 | - 'default' => 1, |
|
| 1345 | - 'required' => true, |
|
| 1346 | - 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1347 | - 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1348 | - ) |
|
| 1349 | - ), |
|
| 1350 | - 'amount' => new EE_Text_Input( |
|
| 1351 | - array( |
|
| 1352 | - 'default' => 0, |
|
| 1353 | - 'required' => true, |
|
| 1354 | - 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1355 | - 'validation_strategies' => array(new EE_Float_Normalization()) |
|
| 1356 | - ) |
|
| 1357 | - ), |
|
| 1358 | - 'status' => new EE_Text_Input( |
|
| 1359 | - array( |
|
| 1360 | - 'default' => EEM_Payment::status_id_approved, |
|
| 1361 | - 'required' => true, |
|
| 1362 | - 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1363 | - ) |
|
| 1364 | - ), |
|
| 1365 | - 'PMD_ID' => new EE_Text_Input( |
|
| 1366 | - array( |
|
| 1367 | - 'default' => 2, |
|
| 1368 | - 'required' => true, |
|
| 1369 | - 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1370 | - 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1371 | - ) |
|
| 1372 | - ), |
|
| 1373 | - 'date' => new EE_Text_Input( |
|
| 1374 | - array( |
|
| 1375 | - 'default' => time(), |
|
| 1376 | - 'required' => true, |
|
| 1377 | - 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1378 | - ) |
|
| 1379 | - ), |
|
| 1380 | - 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1381 | - array( |
|
| 1382 | - 'default' => '', |
|
| 1383 | - 'required' => false, |
|
| 1384 | - 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1385 | - 'validation_strategies' => array( |
|
| 1386 | - new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1387 | - 100), |
|
| 1388 | - ) |
|
| 1389 | - ) |
|
| 1390 | - ), |
|
| 1391 | - 'po_number' => new EE_Text_Input( |
|
| 1392 | - array( |
|
| 1393 | - 'default' => '', |
|
| 1394 | - 'required' => false, |
|
| 1395 | - 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1396 | - 'validation_strategies' => array( |
|
| 1397 | - new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1398 | - 100), |
|
| 1399 | - ) |
|
| 1400 | - ) |
|
| 1401 | - ), |
|
| 1402 | - 'accounting' => new EE_Text_Input( |
|
| 1403 | - array( |
|
| 1404 | - 'default' => '', |
|
| 1405 | - 'required' => false, |
|
| 1406 | - 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1407 | - 'validation_strategies' => array( |
|
| 1408 | - new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1409 | - 100), |
|
| 1410 | - ) |
|
| 1411 | - ) |
|
| 1412 | - ), |
|
| 1413 | - ) |
|
| 1414 | - ) |
|
| 1415 | - ); |
|
| 1416 | - } |
|
| 1417 | - |
|
| 1418 | - |
|
| 1419 | - /** |
|
| 1420 | - * _create_payment_from_request_data |
|
| 1421 | - * |
|
| 1422 | - * @param array $valid_data |
|
| 1423 | - * |
|
| 1424 | - * @return EE_Payment |
|
| 1425 | - */ |
|
| 1426 | - protected function _create_payment_from_request_data($valid_data) |
|
| 1427 | - { |
|
| 1428 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1429 | - // get payment amount |
|
| 1430 | - $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1431 | - // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1432 | - // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1433 | - $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1434 | - // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1435 | - $date = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a', |
|
| 1436 | - current_time('timestamp')); |
|
| 1437 | - $payment = EE_Payment::new_instance( |
|
| 1438 | - array( |
|
| 1439 | - 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1440 | - 'STS_ID' => $valid_data['status'], |
|
| 1441 | - 'PAY_timestamp' => $date, |
|
| 1442 | - 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1443 | - 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1444 | - 'PAY_amount' => $amount, |
|
| 1445 | - 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1446 | - 'PAY_po_number' => $valid_data['po_number'], |
|
| 1447 | - 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1448 | - 'PAY_details' => $valid_data, |
|
| 1449 | - 'PAY_ID' => $PAY_ID |
|
| 1450 | - ), |
|
| 1451 | - '', |
|
| 1452 | - array('Y-m-d', 'g:i a') |
|
| 1453 | - ); |
|
| 1454 | - |
|
| 1455 | - if ( ! $payment->save()) { |
|
| 1456 | - EE_Error::add_error( |
|
| 1457 | - sprintf( |
|
| 1458 | - esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1459 | - $payment->ID() |
|
| 1460 | - ), |
|
| 1461 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1462 | - ); |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - return $payment; |
|
| 1466 | - } |
|
| 1467 | - |
|
| 1468 | - |
|
| 1469 | - /** |
|
| 1470 | - * _process_transaction_payments |
|
| 1471 | - * |
|
| 1472 | - * @param \EE_Transaction $transaction |
|
| 1473 | - * |
|
| 1474 | - * @return array |
|
| 1475 | - */ |
|
| 1476 | - protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1477 | - { |
|
| 1478 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1479 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1480 | - //update the transaction with this payment |
|
| 1481 | - if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1482 | - EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'), |
|
| 1483 | - __FILE__, __FUNCTION__, __LINE__); |
|
| 1484 | - } else { |
|
| 1485 | - EE_Error::add_error( |
|
| 1486 | - esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1487 | - 'event_espresso') |
|
| 1488 | - , __FILE__, __FUNCTION__, __LINE__ |
|
| 1489 | - ); |
|
| 1490 | - } |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - |
|
| 1494 | - /** |
|
| 1495 | - * _get_REG_IDs_to_apply_payment_to |
|
| 1496 | - * |
|
| 1497 | - * returns a list of registration IDs that the payment will apply to |
|
| 1498 | - * |
|
| 1499 | - * @param \EE_Payment $payment |
|
| 1500 | - * |
|
| 1501 | - * @return array |
|
| 1502 | - */ |
|
| 1503 | - protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1504 | - { |
|
| 1505 | - $REG_IDs = array(); |
|
| 1506 | - // grab array of IDs for specific registrations to apply changes to |
|
| 1507 | - if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1508 | - $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
| 1509 | - } |
|
| 1510 | - //nothing specified ? then get all reg IDs |
|
| 1511 | - if (empty($REG_IDs)) { |
|
| 1512 | - $registrations = $payment->transaction()->registrations(); |
|
| 1513 | - $REG_IDs = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1514 | - } |
|
| 1515 | - |
|
| 1516 | - // ensure that REG_IDs are integers and NOT strings |
|
| 1517 | - return array_map('intval', $REG_IDs); |
|
| 1518 | - } |
|
| 1519 | - |
|
| 1520 | - |
|
| 1521 | - /** |
|
| 1522 | - * @return array |
|
| 1523 | - */ |
|
| 1524 | - public function existing_reg_payment_REG_IDs() |
|
| 1525 | - { |
|
| 1526 | - return $this->_existing_reg_payment_REG_IDs; |
|
| 1527 | - } |
|
| 1528 | - |
|
| 1529 | - |
|
| 1530 | - /** |
|
| 1531 | - * @param array $existing_reg_payment_REG_IDs |
|
| 1532 | - */ |
|
| 1533 | - public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1534 | - { |
|
| 1535 | - $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1536 | - } |
|
| 1537 | - |
|
| 1538 | - |
|
| 1539 | - /** |
|
| 1540 | - * _get_existing_reg_payment_REG_IDs |
|
| 1541 | - * |
|
| 1542 | - * returns a list of registration IDs that the payment is currently related to |
|
| 1543 | - * as recorded in the database |
|
| 1544 | - * |
|
| 1545 | - * @param \EE_Payment $payment |
|
| 1546 | - * |
|
| 1547 | - * @return array |
|
| 1548 | - */ |
|
| 1549 | - protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 1550 | - { |
|
| 1551 | - if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 1552 | - // let's get any existing reg payment records for this payment |
|
| 1553 | - $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 1554 | - // but we only want the REG IDs, so grab the array keys |
|
| 1555 | - $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array(); |
|
| 1556 | - $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 1557 | - } |
|
| 1558 | - |
|
| 1559 | - return $this->existing_reg_payment_REG_IDs(); |
|
| 1560 | - } |
|
| 1561 | - |
|
| 1562 | - |
|
| 1563 | - /** |
|
| 1564 | - * _remove_existing_registration_payments |
|
| 1565 | - * |
|
| 1566 | - * this calculates the difference between existing relations |
|
| 1567 | - * to the supplied payment and the new list registration IDs, |
|
| 1568 | - * removes any related registrations that no longer apply, |
|
| 1569 | - * and then updates the registration paid fields |
|
| 1570 | - * |
|
| 1571 | - * @param \EE_Payment $payment |
|
| 1572 | - * @param int $PAY_ID |
|
| 1573 | - * |
|
| 1574 | - * @return bool; |
|
| 1575 | - */ |
|
| 1576 | - protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 1577 | - { |
|
| 1578 | - // newly created payments will have nothing recorded for $PAY_ID |
|
| 1579 | - if ($PAY_ID == 0) { |
|
| 1580 | - return false; |
|
| 1581 | - } |
|
| 1582 | - $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1583 | - if (empty($existing_reg_payment_REG_IDs)) { |
|
| 1584 | - return false; |
|
| 1585 | - } |
|
| 1586 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1587 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1588 | - |
|
| 1589 | - return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 1590 | - $payment, |
|
| 1591 | - array( |
|
| 1592 | - array( |
|
| 1593 | - 'PAY_ID' => $payment->ID(), |
|
| 1594 | - 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 1595 | - ) |
|
| 1596 | - ) |
|
| 1597 | - ); |
|
| 1598 | - } |
|
| 1599 | - |
|
| 1600 | - |
|
| 1601 | - /** |
|
| 1602 | - * _update_registration_payments |
|
| 1603 | - * |
|
| 1604 | - * this applies the payments to the selected registrations |
|
| 1605 | - * but only if they have not already been paid for |
|
| 1606 | - * |
|
| 1607 | - * @param EE_Transaction $transaction |
|
| 1608 | - * @param \EE_Payment $payment |
|
| 1609 | - * @param array $REG_IDs |
|
| 1610 | - * |
|
| 1611 | - * @return bool |
|
| 1612 | - */ |
|
| 1613 | - protected function _update_registration_payments( |
|
| 1614 | - EE_Transaction $transaction, |
|
| 1615 | - EE_Payment $payment, |
|
| 1616 | - $REG_IDs = array() |
|
| 1617 | - ) { |
|
| 1618 | - // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 1619 | - // so let's do that using our set of REG_IDs from the form |
|
| 1620 | - $registration_query_where_params = array( |
|
| 1621 | - 'REG_ID' => array('IN', $REG_IDs) |
|
| 1622 | - ); |
|
| 1623 | - // but add in some conditions regarding payment, |
|
| 1624 | - // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 1625 | - // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 1626 | - if ( ! $payment->is_a_refund()) { |
|
| 1627 | - $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 1628 | - $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 1629 | - } |
|
| 1630 | - //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ ); |
|
| 1631 | - $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 1632 | - if ( ! empty($registrations)) { |
|
| 1633 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 1634 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 1635 | - $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 1636 | - } |
|
| 1637 | - } |
|
| 1638 | - |
|
| 1639 | - |
|
| 1640 | - /** |
|
| 1641 | - * _process_registration_status_change |
|
| 1642 | - * |
|
| 1643 | - * This processes requested registration status changes for all the registrations |
|
| 1644 | - * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 1645 | - * |
|
| 1646 | - * @param EE_Transaction $transaction |
|
| 1647 | - * @param array $REG_IDs |
|
| 1648 | - * |
|
| 1649 | - * @return bool |
|
| 1650 | - */ |
|
| 1651 | - protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 1652 | - { |
|
| 1653 | - // first if there is no change in status then we get out. |
|
| 1654 | - if ( |
|
| 1655 | - ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 1656 | - || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN' |
|
| 1657 | - ) { |
|
| 1658 | - //no error message, no change requested, just nothing to do man. |
|
| 1659 | - return false; |
|
| 1660 | - } |
|
| 1661 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1662 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1663 | - |
|
| 1664 | - // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 1665 | - return $transaction_processor->manually_update_registration_statuses( |
|
| 1666 | - $transaction, |
|
| 1667 | - sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 1668 | - array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 1669 | - ); |
|
| 1670 | - } |
|
| 1671 | - |
|
| 1672 | - |
|
| 1673 | - /** |
|
| 1674 | - * _build_payment_json_response |
|
| 1675 | - * |
|
| 1676 | - * @access public |
|
| 1677 | - * |
|
| 1678 | - * @param \EE_Payment $payment |
|
| 1679 | - * @param array $REG_IDs |
|
| 1680 | - * @param bool | null $delete_txn_reg_status_change |
|
| 1681 | - * |
|
| 1682 | - * @return array |
|
| 1683 | - */ |
|
| 1684 | - protected function _build_payment_json_response( |
|
| 1685 | - EE_Payment $payment, |
|
| 1686 | - $REG_IDs = array(), |
|
| 1687 | - $delete_txn_reg_status_change = null |
|
| 1688 | - ) { |
|
| 1689 | - // was the payment deleted ? |
|
| 1690 | - if (is_bool($delete_txn_reg_status_change)) { |
|
| 1691 | - return array( |
|
| 1692 | - 'PAY_ID' => $payment->ID(), |
|
| 1693 | - 'amount' => $payment->amount(), |
|
| 1694 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 1695 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 1696 | - 'pay_status' => $payment->STS_ID(), |
|
| 1697 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 1698 | - 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 1699 | - ); |
|
| 1700 | - } else { |
|
| 1701 | - $this->_get_payment_status_array(); |
|
| 1702 | - |
|
| 1703 | - return array( |
|
| 1704 | - 'amount' => $payment->amount(), |
|
| 1705 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 1706 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 1707 | - 'pay_status' => $payment->STS_ID(), |
|
| 1708 | - 'PAY_ID' => $payment->ID(), |
|
| 1709 | - 'STS_ID' => $payment->STS_ID(), |
|
| 1710 | - 'status' => self::$_pay_status[$payment->STS_ID()], |
|
| 1711 | - 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 1712 | - 'method' => strtoupper($payment->source()), |
|
| 1713 | - 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 1714 | - 'gateway' => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown", |
|
| 1715 | - 'event_espresso'), |
|
| 1716 | - 'gateway_response' => $payment->gateway_response(), |
|
| 1717 | - 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 1718 | - 'po_number' => $payment->po_number(), |
|
| 1719 | - 'extra_accntng' => $payment->extra_accntng(), |
|
| 1720 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 1721 | - ); |
|
| 1722 | - } |
|
| 1723 | - } |
|
| 1724 | - |
|
| 1725 | - |
|
| 1726 | - /** |
|
| 1727 | - * delete_payment |
|
| 1728 | - * delete a payment or refund made towards a transaction |
|
| 1729 | - * |
|
| 1730 | - * @access public |
|
| 1731 | - * @return void |
|
| 1732 | - */ |
|
| 1733 | - public function delete_payment() |
|
| 1734 | - { |
|
| 1735 | - $json_response_data = array('return_data' => false); |
|
| 1736 | - $PAY_ID = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0; |
|
| 1737 | - if ($PAY_ID) { |
|
| 1738 | - $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false; |
|
| 1739 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 1740 | - if ($payment instanceof EE_Payment) { |
|
| 1741 | - $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1742 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1743 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1744 | - if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 1745 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs, |
|
| 1746 | - $delete_txn_reg_status_change); |
|
| 1747 | - if ($delete_txn_reg_status_change) { |
|
| 1748 | - $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 1749 | - //MAKE sure we also add the delete_txn_req_status_change to the |
|
| 1750 | - //$_REQUEST global because that's how messages will be looking for it. |
|
| 1751 | - $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 1752 | - $this->_maybe_send_notifications(); |
|
| 1753 | - $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 1754 | - } |
|
| 1755 | - } |
|
| 1756 | - } else { |
|
| 1757 | - EE_Error::add_error( |
|
| 1758 | - esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 1759 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1760 | - ); |
|
| 1761 | - } |
|
| 1762 | - } else { |
|
| 1763 | - EE_Error::add_error( |
|
| 1764 | - esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 1765 | - 'event_espresso'), |
|
| 1766 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1767 | - ); |
|
| 1768 | - } |
|
| 1769 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 1770 | - $this->_template_args = array( |
|
| 1771 | - 'data' => $json_response_data, |
|
| 1772 | - 'success' => $notices['success'], |
|
| 1773 | - 'error' => $notices['errors'], |
|
| 1774 | - 'attention' => $notices['attention'] |
|
| 1775 | - ); |
|
| 1776 | - $this->_return_json(); |
|
| 1777 | - } |
|
| 1778 | - |
|
| 1779 | - |
|
| 1780 | - /** |
|
| 1781 | - * _registration_payment_data_array |
|
| 1782 | - * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 1783 | - * |
|
| 1784 | - * @access protected |
|
| 1785 | - * |
|
| 1786 | - * @param array $REG_IDs |
|
| 1787 | - * |
|
| 1788 | - * @return array |
|
| 1789 | - */ |
|
| 1790 | - protected function _registration_payment_data_array($REG_IDs) |
|
| 1791 | - { |
|
| 1792 | - $registration_payment_data = array(); |
|
| 1793 | - //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 1794 | - if ( ! empty($REG_IDs)) { |
|
| 1795 | - $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 1796 | - foreach ($registrations as $registration) { |
|
| 1797 | - if ($registration instanceof EE_Registration) { |
|
| 1798 | - $registration_payment_data[$registration->ID()] = array( |
|
| 1799 | - 'paid' => $registration->pretty_paid(), |
|
| 1800 | - 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 1801 | - ); |
|
| 1802 | - } |
|
| 1803 | - } |
|
| 1804 | - } |
|
| 1805 | - |
|
| 1806 | - return $registration_payment_data; |
|
| 1807 | - } |
|
| 1808 | - |
|
| 1809 | - |
|
| 1810 | - /** |
|
| 1811 | - * _maybe_send_notifications |
|
| 1812 | - * |
|
| 1813 | - * determines whether or not the admin has indicated that notifications should be sent. |
|
| 1814 | - * If so, will toggle a filter switch for delivering registration notices. |
|
| 1815 | - * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 1816 | - * |
|
| 1817 | - * @access protected |
|
| 1818 | - * |
|
| 1819 | - * @param \EE_Payment | null $payment |
|
| 1820 | - */ |
|
| 1821 | - protected function _maybe_send_notifications($payment = null) |
|
| 1822 | - { |
|
| 1823 | - switch ($payment instanceof EE_Payment) { |
|
| 1824 | - // payment notifications |
|
| 1825 | - case true : |
|
| 1826 | - if ( |
|
| 1827 | - isset( |
|
| 1828 | - $this->_req_data['txn_payments'], |
|
| 1829 | - $this->_req_data['txn_payments']['send_notifications'] |
|
| 1830 | - ) && |
|
| 1831 | - filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 1832 | - ) { |
|
| 1833 | - $this->_process_payment_notification($payment); |
|
| 1834 | - } |
|
| 1835 | - break; |
|
| 1836 | - // registration notifications |
|
| 1837 | - case false : |
|
| 1838 | - if ( |
|
| 1839 | - isset( |
|
| 1840 | - $this->_req_data['txn_reg_status_change'], |
|
| 1841 | - $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
| 1842 | - ) && |
|
| 1843 | - filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 1844 | - ) { |
|
| 1845 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 1846 | - } |
|
| 1847 | - break; |
|
| 1848 | - } |
|
| 1849 | - } |
|
| 1850 | - |
|
| 1851 | - |
|
| 1852 | - /** |
|
| 1853 | - * _send_payment_reminder |
|
| 1854 | - * generates HTML for the View Transaction Details Admin page |
|
| 1855 | - * |
|
| 1856 | - * @access protected |
|
| 1857 | - * @return void |
|
| 1858 | - */ |
|
| 1859 | - protected function _send_payment_reminder() |
|
| 1860 | - { |
|
| 1861 | - $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 1862 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 1863 | - $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 1864 | - 'action' => $this->_req_data['redirect_to'], |
|
| 1865 | - 'TXN_ID' => $this->_req_data['TXN_ID'] |
|
| 1866 | - ) : array(); |
|
| 1867 | - do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 1868 | - $transaction); |
|
| 1869 | - $this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'), |
|
| 1870 | - esc_html__('sent', 'event_espresso'), $query_args, true); |
|
| 1871 | - } |
|
| 1872 | - |
|
| 1873 | - |
|
| 1874 | - /** |
|
| 1875 | - * get_transactions |
|
| 1876 | - * get transactions for given parameters (used by list table) |
|
| 1877 | - * |
|
| 1878 | - * @param int $perpage how many transactions displayed per page |
|
| 1879 | - * @param boolean $count return the count or objects |
|
| 1880 | - * @param string $view |
|
| 1881 | - * |
|
| 1882 | - * @return mixed int = count || array of transaction objects |
|
| 1883 | - */ |
|
| 1884 | - public function get_transactions($perpage, $count = false, $view = '') |
|
| 1885 | - { |
|
| 1886 | - |
|
| 1887 | - $TXN = EEM_Transaction::instance(); |
|
| 1888 | - |
|
| 1889 | - $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y', |
|
| 1890 | - strtotime('-10 year')); |
|
| 1891 | - $end_date = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y'); |
|
| 1892 | - |
|
| 1893 | - //make sure our timestamps start and end right at the boundaries for each day |
|
| 1894 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 1895 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 1896 | - |
|
| 1897 | - |
|
| 1898 | - //convert to timestamps |
|
| 1899 | - $start_date = strtotime($start_date); |
|
| 1900 | - $end_date = strtotime($end_date); |
|
| 1901 | - |
|
| 1902 | - //makes sure start date is the lowest value and vice versa |
|
| 1903 | - $start_date = min($start_date, $end_date); |
|
| 1904 | - $end_date = max($start_date, $end_date); |
|
| 1905 | - |
|
| 1906 | - //convert to correct format for query |
|
| 1907 | - $start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
| 1908 | - date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s'); |
|
| 1909 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
| 1910 | - date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s'); |
|
| 1911 | - |
|
| 1912 | - |
|
| 1913 | - //set orderby |
|
| 1914 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 1915 | - |
|
| 1916 | - switch ($this->_req_data['orderby']) { |
|
| 1917 | - case 'TXN_ID': |
|
| 1918 | - $orderby = 'TXN_ID'; |
|
| 1919 | - break; |
|
| 1920 | - case 'ATT_fname': |
|
| 1921 | - $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 1922 | - break; |
|
| 1923 | - case 'event_name': |
|
| 1924 | - $orderby = 'Registration.Event.EVT_name'; |
|
| 1925 | - break; |
|
| 1926 | - default: //'TXN_timestamp' |
|
| 1927 | - $orderby = 'TXN_timestamp'; |
|
| 1928 | - } |
|
| 1929 | - |
|
| 1930 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC'; |
|
| 1931 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1932 | - $per_page = isset($perpage) && ! empty($perpage) ? $perpage : 10; |
|
| 1933 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 1934 | - |
|
| 1935 | - $offset = ($current_page - 1) * $per_page; |
|
| 1936 | - $limit = array($offset, $per_page); |
|
| 1937 | - |
|
| 1938 | - $_where = array( |
|
| 1939 | - 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 1940 | - 'Registration.REG_count' => 1 |
|
| 1941 | - ); |
|
| 1942 | - |
|
| 1943 | - if (isset($this->_req_data['EVT_ID'])) { |
|
| 1944 | - $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 1945 | - } |
|
| 1946 | - |
|
| 1947 | - if (isset($this->_req_data['s'])) { |
|
| 1948 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1949 | - $_where['OR'] = array( |
|
| 1950 | - 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 1951 | - 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1952 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1953 | - 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1954 | - 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1955 | - 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1956 | - 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1957 | - 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1958 | - 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1959 | - 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1960 | - 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1961 | - 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 1962 | - 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 1963 | - 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 1964 | - 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 1965 | - 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1966 | - 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1967 | - 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 1968 | - 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 1969 | - 'TXN_session_data' => array('LIKE', $search_string), |
|
| 1970 | - 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string) |
|
| 1971 | - ); |
|
| 1972 | - } |
|
| 1973 | - |
|
| 1974 | - //failed transactions |
|
| 1975 | - $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false; |
|
| 1976 | - $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false; |
|
| 1977 | - |
|
| 1978 | - if ($failed) { |
|
| 1979 | - $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 1980 | - } else if ($abandoned) { |
|
| 1981 | - $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 1982 | - } else { |
|
| 1983 | - $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 1984 | - $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 1985 | - } |
|
| 1986 | - |
|
| 1987 | - $query_params = array($_where, 'order_by' => array($orderby => $sort), 'limit' => $limit); |
|
| 1988 | - |
|
| 1989 | - $transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params); |
|
| 1990 | - |
|
| 1991 | - |
|
| 1992 | - return $transactions; |
|
| 1993 | - |
|
| 1994 | - } |
|
| 803 | + // process payment details |
|
| 804 | + $payments = $this->_transaction->get_many_related('Payment'); |
|
| 805 | + if ( ! empty($payments)) { |
|
| 806 | + $this->_template_args['payments'] = $payments; |
|
| 807 | + $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 808 | + } else { |
|
| 809 | + $this->_template_args['payments'] = false; |
|
| 810 | + $this->_template_args['existing_reg_payments'] = array(); |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 814 | + $this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'), |
|
| 815 | + TXN_ADMIN_URL); |
|
| 816 | + |
|
| 817 | + if (isset($txn_details['invoice_number'])) { |
|
| 818 | + $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 819 | + $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number', |
|
| 820 | + 'event_espresso'); |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session'); |
|
| 824 | + $this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session', |
|
| 825 | + 'event_espresso'); |
|
| 826 | + |
|
| 827 | + $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : ''; |
|
| 828 | + $this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP', |
|
| 829 | + 'event_espresso'); |
|
| 830 | + |
|
| 831 | + $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : ''; |
|
| 832 | + $this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent', |
|
| 833 | + 'event_espresso'); |
|
| 834 | + |
|
| 835 | + $reg_steps = '<ul>'; |
|
| 836 | + foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 837 | + if ($reg_step_status === true) { |
|
| 838 | + $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 839 | + ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 840 | + } else if (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 841 | + $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( |
|
| 842 | + esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 843 | + ucwords(str_replace('_', ' ', $reg_step)), |
|
| 844 | + date(get_option('date_format') . ' ' . get_option('time_format'), |
|
| 845 | + ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))) |
|
| 846 | + ) . '</li>'; |
|
| 847 | + } else { |
|
| 848 | + $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated', |
|
| 849 | + 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 850 | + } |
|
| 851 | + } |
|
| 852 | + $reg_steps .= '</ul>'; |
|
| 853 | + $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 854 | + $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress', |
|
| 855 | + 'event_espresso'); |
|
| 856 | + |
|
| 857 | + |
|
| 858 | + $this->_get_registrations_to_apply_payment_to(); |
|
| 859 | + $this->_get_payment_methods($payments); |
|
| 860 | + $this->_get_payment_status_array(); |
|
| 861 | + $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
|
| 862 | + |
|
| 863 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 864 | + 'action' => 'edit_transaction', |
|
| 865 | + 'process' => 'transaction' |
|
| 866 | + ), TXN_ADMIN_URL); |
|
| 867 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 868 | + 'page' => 'espresso_transactions', |
|
| 869 | + 'action' => 'espresso_apply_payment' |
|
| 870 | + ), WP_AJAX_URL); |
|
| 871 | + $this->_template_args['delete_payment_form_url'] = add_query_arg(array( |
|
| 872 | + 'page' => 'espresso_transactions', |
|
| 873 | + 'action' => 'espresso_delete_payment' |
|
| 874 | + ), WP_AJAX_URL); |
|
| 875 | + |
|
| 876 | + // 'espresso_delete_payment_nonce' |
|
| 877 | + |
|
| 878 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 879 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 880 | + |
|
| 881 | + } |
|
| 882 | + |
|
| 883 | + |
|
| 884 | + /** |
|
| 885 | + * _get_registration_payment_IDs |
|
| 886 | + * |
|
| 887 | + * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 888 | + * |
|
| 889 | + * @access protected |
|
| 890 | + * |
|
| 891 | + * @param EE_Payment[] $payments |
|
| 892 | + * |
|
| 893 | + * @return array |
|
| 894 | + */ |
|
| 895 | + protected function _get_registration_payment_IDs($payments = array()) |
|
| 896 | + { |
|
| 897 | + $existing_reg_payments = array(); |
|
| 898 | + // get all reg payments for these payments |
|
| 899 | + $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
| 900 | + array( |
|
| 901 | + 'PAY_ID' => array( |
|
| 902 | + 'IN', |
|
| 903 | + array_keys($payments) |
|
| 904 | + ) |
|
| 905 | + ) |
|
| 906 | + )); |
|
| 907 | + if ( ! empty($reg_payments)) { |
|
| 908 | + foreach ($payments as $payment) { |
|
| 909 | + if ( ! $payment instanceof EE_Payment) { |
|
| 910 | + continue; |
|
| 911 | + } else if ( ! isset($existing_reg_payments[$payment->ID()])) { |
|
| 912 | + $existing_reg_payments[$payment->ID()] = array(); |
|
| 913 | + } |
|
| 914 | + foreach ($reg_payments as $reg_payment) { |
|
| 915 | + if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) { |
|
| 916 | + $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
| 917 | + } |
|
| 918 | + } |
|
| 919 | + } |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + return $existing_reg_payments; |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * _get_registrations_to_apply_payment_to |
|
| 928 | + * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 929 | + * which allows the admin to only apply the payment to the specific registrations |
|
| 930 | + * |
|
| 931 | + * @access protected |
|
| 932 | + * @return void |
|
| 933 | + * @throws \EE_Error |
|
| 934 | + */ |
|
| 935 | + protected function _get_registrations_to_apply_payment_to() |
|
| 936 | + { |
|
| 937 | + // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 938 | + $query_params = array( |
|
| 939 | + array( |
|
| 940 | + 'STS_ID' => array( |
|
| 941 | + 'IN', |
|
| 942 | + array( |
|
| 943 | + EEM_Registration::status_id_approved, |
|
| 944 | + EEM_Registration::status_id_pending_payment, |
|
| 945 | + EEM_Registration::status_id_not_approved, |
|
| 946 | + ) |
|
| 947 | + ) |
|
| 948 | + ) |
|
| 949 | + ); |
|
| 950 | + $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 951 | + '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 952 | + ); |
|
| 953 | + $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 954 | + $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 955 | + $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 956 | + EEH_HTML::tr( |
|
| 957 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 958 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 959 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 960 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 961 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 962 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 963 | + EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 964 | + ) |
|
| 965 | + ); |
|
| 966 | + $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 967 | + // get registrations for TXN |
|
| 968 | + $registrations = $this->_transaction->registrations($query_params); |
|
| 969 | + foreach ($registrations as $registration) { |
|
| 970 | + if ($registration instanceof EE_Registration) { |
|
| 971 | + $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 972 | + ? $registration->attendee()->full_name() |
|
| 973 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 974 | + $owing = $registration->final_price() - $registration->paid(); |
|
| 975 | + $taxable = $registration->ticket()->taxable() |
|
| 976 | + ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 977 | + : ''; |
|
| 978 | + $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
|
| 979 | + ? ' checked="checked"' |
|
| 980 | + : ''; |
|
| 981 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 982 | + $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 983 | + EEH_HTML::td($registration->ID()) . |
|
| 984 | + EEH_HTML::td($attendee_name) . |
|
| 985 | + EEH_HTML::td( |
|
| 986 | + $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 987 | + ) . |
|
| 988 | + EEH_HTML::td($registration->event_name()) . |
|
| 989 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 990 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 991 | + EEH_HTML::td( |
|
| 992 | + '<input type="checkbox" value="' . $registration->ID() |
|
| 993 | + . '" name="txn_admin_payment[registrations]"' |
|
| 994 | + . $checked . $disabled . '>', |
|
| 995 | + '', 'jst-cntr' |
|
| 996 | + ), |
|
| 997 | + 'apply-payment-registration-row-' . $registration->ID() |
|
| 998 | + ); |
|
| 999 | + } |
|
| 1000 | + } |
|
| 1001 | + $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1002 | + $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1003 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1004 | + $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1005 | + esc_html__( |
|
| 1006 | + 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
| 1007 | + 'event_espresso' |
|
| 1008 | + ), |
|
| 1009 | + '', 'clear description' |
|
| 1010 | + ); |
|
| 1011 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1012 | + $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1013 | + } |
|
| 1014 | + |
|
| 1015 | + |
|
| 1016 | + /** |
|
| 1017 | + * _get_reg_status_selection |
|
| 1018 | + * |
|
| 1019 | + * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1020 | + * instead of events. |
|
| 1021 | + * @access protected |
|
| 1022 | + * @return void |
|
| 1023 | + */ |
|
| 1024 | + protected function _get_reg_status_selection() |
|
| 1025 | + { |
|
| 1026 | + //first get all possible statuses |
|
| 1027 | + $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1028 | + //let's add a "don't change" option. |
|
| 1029 | + $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1030 | + $status_array = array_merge($status_array, $statuses); |
|
| 1031 | + $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]', |
|
| 1032 | + $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status'); |
|
| 1033 | + $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]', |
|
| 1034 | + $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status'); |
|
| 1035 | + |
|
| 1036 | + } |
|
| 1037 | + |
|
| 1038 | + |
|
| 1039 | + /** |
|
| 1040 | + * _get_payment_methods |
|
| 1041 | + * Gets all the payment methods available generally, or the ones that are already |
|
| 1042 | + * selected on these payments (in case their payment methods are no longer active). |
|
| 1043 | + * Has the side-effect of updating the template args' payment_methods item |
|
| 1044 | + * @access private |
|
| 1045 | + * |
|
| 1046 | + * @param EE_Payment[] to show on this page |
|
| 1047 | + * |
|
| 1048 | + * @return void |
|
| 1049 | + */ |
|
| 1050 | + private function _get_payment_methods($payments = array()) |
|
| 1051 | + { |
|
| 1052 | + $payment_methods_of_payments = array(); |
|
| 1053 | + foreach ($payments as $payment) { |
|
| 1054 | + if ($payment instanceof EE_Payment) { |
|
| 1055 | + $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
| 1056 | + } |
|
| 1057 | + } |
|
| 1058 | + if ($payment_methods_of_payments) { |
|
| 1059 | + $query_args = array( |
|
| 1060 | + array( |
|
| 1061 | + 'OR*payment_method_for_payment' => array( |
|
| 1062 | + 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1063 | + 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%') |
|
| 1064 | + ) |
|
| 1065 | + ) |
|
| 1066 | + ); |
|
| 1067 | + } else { |
|
| 1068 | + $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1069 | + } |
|
| 1070 | + $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + |
|
| 1074 | + /** |
|
| 1075 | + * txn_attendees_meta_box |
|
| 1076 | + * generates HTML for the Attendees Transaction main meta box |
|
| 1077 | + * |
|
| 1078 | + * @access public |
|
| 1079 | + * |
|
| 1080 | + * @param WP_Post $post |
|
| 1081 | + * @param array $metabox |
|
| 1082 | + * |
|
| 1083 | + * @return void |
|
| 1084 | + */ |
|
| 1085 | + public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1086 | + { |
|
| 1087 | + |
|
| 1088 | + extract($metabox['args']); |
|
| 1089 | + $this->_template_args['post'] = $post; |
|
| 1090 | + $this->_template_args['event_attendees'] = array(); |
|
| 1091 | + // process items in cart |
|
| 1092 | + $line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item'))); |
|
| 1093 | + if ( ! empty($line_items)) { |
|
| 1094 | + foreach ($line_items as $item) { |
|
| 1095 | + if ($item instanceof EE_Line_Item) { |
|
| 1096 | + switch ($item->OBJ_type()) { |
|
| 1097 | + |
|
| 1098 | + case 'Event' : |
|
| 1099 | + break; |
|
| 1100 | + |
|
| 1101 | + case 'Ticket' : |
|
| 1102 | + $ticket = $item->ticket(); |
|
| 1103 | + //right now we're only handling tickets here. Cause its expected that only tickets will have attendees right? |
|
| 1104 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 1105 | + continue; |
|
| 1106 | + } |
|
| 1107 | + try { |
|
| 1108 | + $event_name = $ticket->get_event_name(); |
|
| 1109 | + } catch (Exception $e) { |
|
| 1110 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1111 | + $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1112 | + } |
|
| 1113 | + $event_name .= ' - ' . $item->get('LIN_name'); |
|
| 1114 | + $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
| 1115 | + // now get all of the registrations for this transaction that use this ticket |
|
| 1116 | + $registrations = $ticket->get_many_related('Registration', |
|
| 1117 | + array(array('TXN_ID' => $this->_transaction->ID()))); |
|
| 1118 | + foreach ($registrations as $registration) { |
|
| 1119 | + if ( ! $registration instanceof EE_Registration) { |
|
| 1120 | + continue; |
|
| 1121 | + } |
|
| 1122 | + $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] = $registration->status_ID(); |
|
| 1123 | + $this->_template_args['event_attendees'][$registration->ID()]['att_num'] = $registration->count(); |
|
| 1124 | + $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name; |
|
| 1125 | + $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] = $ticket_price; |
|
| 1126 | + // attendee info |
|
| 1127 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 1128 | + if ($attendee instanceof EE_Attendee) { |
|
| 1129 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); |
|
| 1130 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); |
|
| 1131 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event', |
|
| 1132 | + 'event_espresso') . '">' . $attendee->email() . '</a>'; |
|
| 1133 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = EEH_Address::format($attendee, |
|
| 1134 | + 'inline', false, false); |
|
| 1135 | + } else { |
|
| 1136 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
| 1137 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
| 1138 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
| 1139 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
| 1140 | + } |
|
| 1141 | + } |
|
| 1142 | + break; |
|
| 1143 | + |
|
| 1144 | + } |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 1149 | + 'action' => 'edit_transaction', |
|
| 1150 | + 'process' => 'attendees' |
|
| 1151 | + ), TXN_ADMIN_URL); |
|
| 1152 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1153 | + $this->_template_args, true); |
|
| 1154 | + |
|
| 1155 | + } else { |
|
| 1156 | + echo sprintf( |
|
| 1157 | + esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1158 | + 'event_espresso'), |
|
| 1159 | + '<p class="important-notice">', |
|
| 1160 | + '</p>' |
|
| 1161 | + ); |
|
| 1162 | + } |
|
| 1163 | + } |
|
| 1164 | + |
|
| 1165 | + |
|
| 1166 | + /** |
|
| 1167 | + * txn_registrant_side_meta_box |
|
| 1168 | + * generates HTML for the Edit Transaction side meta box |
|
| 1169 | + * |
|
| 1170 | + * @access public |
|
| 1171 | + * @throws \EE_Error |
|
| 1172 | + * @return void |
|
| 1173 | + */ |
|
| 1174 | + public function txn_registrant_side_meta_box() |
|
| 1175 | + { |
|
| 1176 | + $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null; |
|
| 1177 | + if ( ! $primary_att instanceof EE_Attendee) { |
|
| 1178 | + $this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1179 | + 'event_espresso'); |
|
| 1180 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1181 | + } |
|
| 1182 | + $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1183 | + $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1184 | + $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1185 | + $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1186 | + $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1187 | + $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1188 | + 'action' => 'edit_attendee', |
|
| 1189 | + 'post' => $primary_att->ID() |
|
| 1190 | + ), REG_ADMIN_URL); |
|
| 1191 | + // get formatted address for registrant |
|
| 1192 | + $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1193 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1194 | + $this->_template_args, true); |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + |
|
| 1198 | + /** |
|
| 1199 | + * txn_billing_info_side_meta_box |
|
| 1200 | + * generates HTML for the Edit Transaction side meta box |
|
| 1201 | + * |
|
| 1202 | + * @access public |
|
| 1203 | + * @return void |
|
| 1204 | + */ |
|
| 1205 | + public function txn_billing_info_side_meta_box() |
|
| 1206 | + { |
|
| 1207 | + |
|
| 1208 | + $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1209 | + $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1210 | + array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1211 | + TXN_ADMIN_URL |
|
| 1212 | + ); |
|
| 1213 | + |
|
| 1214 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1215 | + echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + |
|
| 1219 | + /** |
|
| 1220 | + * apply_payments_or_refunds |
|
| 1221 | + * registers a payment or refund made towards a transaction |
|
| 1222 | + * |
|
| 1223 | + * @access public |
|
| 1224 | + * @return void |
|
| 1225 | + */ |
|
| 1226 | + public function apply_payments_or_refunds() |
|
| 1227 | + { |
|
| 1228 | + $json_response_data = array('return_data' => false); |
|
| 1229 | + $valid_data = $this->_validate_payment_request_data(); |
|
| 1230 | + if ( ! empty($valid_data)) { |
|
| 1231 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1232 | + //save the new payment |
|
| 1233 | + $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1234 | + // get the TXN for this payment |
|
| 1235 | + $transaction = $payment->transaction(); |
|
| 1236 | + // verify transaction |
|
| 1237 | + if ($transaction instanceof EE_Transaction) { |
|
| 1238 | + // calculate_total_payments_and_update_status |
|
| 1239 | + $this->_process_transaction_payments($transaction); |
|
| 1240 | + $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1241 | + $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1242 | + // apply payment to registrations (if applicable) |
|
| 1243 | + if ( ! empty($REG_IDs)) { |
|
| 1244 | + $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1245 | + $this->_maybe_send_notifications(); |
|
| 1246 | + // now process status changes for the same registrations |
|
| 1247 | + $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1248 | + } |
|
| 1249 | + $this->_maybe_send_notifications($payment); |
|
| 1250 | + //prepare to render page |
|
| 1251 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1252 | + do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction, |
|
| 1253 | + $payment); |
|
| 1254 | + } else { |
|
| 1255 | + EE_Error::add_error( |
|
| 1256 | + esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'), |
|
| 1257 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1258 | + ); |
|
| 1259 | + } |
|
| 1260 | + } else { |
|
| 1261 | + EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.', |
|
| 1262 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 1266 | + $this->_template_args = array( |
|
| 1267 | + 'data' => $json_response_data, |
|
| 1268 | + 'error' => $notices['errors'], |
|
| 1269 | + 'success' => $notices['success'] |
|
| 1270 | + ); |
|
| 1271 | + $this->_return_json(); |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + |
|
| 1275 | + /** |
|
| 1276 | + * _validate_payment_request_data |
|
| 1277 | + * |
|
| 1278 | + * @return array |
|
| 1279 | + */ |
|
| 1280 | + protected function _validate_payment_request_data() |
|
| 1281 | + { |
|
| 1282 | + if ( ! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1283 | + return false; |
|
| 1284 | + } |
|
| 1285 | + $payment_form = $this->_generate_payment_form_section(); |
|
| 1286 | + try { |
|
| 1287 | + if ($payment_form->was_submitted()) { |
|
| 1288 | + $payment_form->receive_form_submission(); |
|
| 1289 | + if ( ! $payment_form->is_valid()) { |
|
| 1290 | + $submission_error_messages = array(); |
|
| 1291 | + foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1292 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1293 | + $submission_error_messages[] = sprintf( |
|
| 1294 | + _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1295 | + $validation_error->get_form_section()->html_label_text(), |
|
| 1296 | + $validation_error->getMessage() |
|
| 1297 | + ); |
|
| 1298 | + } |
|
| 1299 | + } |
|
| 1300 | + EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
| 1301 | + |
|
| 1302 | + return array(); |
|
| 1303 | + } |
|
| 1304 | + } |
|
| 1305 | + } catch (EE_Error $e) { |
|
| 1306 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1307 | + |
|
| 1308 | + return array(); |
|
| 1309 | + } |
|
| 1310 | + |
|
| 1311 | + return $payment_form->valid_data(); |
|
| 1312 | + } |
|
| 1313 | + |
|
| 1314 | + |
|
| 1315 | + /** |
|
| 1316 | + * _generate_payment_form_section |
|
| 1317 | + * |
|
| 1318 | + * @return EE_Form_Section_Proper |
|
| 1319 | + */ |
|
| 1320 | + protected function _generate_payment_form_section() |
|
| 1321 | + { |
|
| 1322 | + return new EE_Form_Section_Proper( |
|
| 1323 | + array( |
|
| 1324 | + 'name' => 'txn_admin_payment', |
|
| 1325 | + 'subsections' => array( |
|
| 1326 | + 'PAY_ID' => new EE_Text_Input( |
|
| 1327 | + array( |
|
| 1328 | + 'default' => 0, |
|
| 1329 | + 'required' => false, |
|
| 1330 | + 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1331 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1332 | + ) |
|
| 1333 | + ), |
|
| 1334 | + 'TXN_ID' => new EE_Text_Input( |
|
| 1335 | + array( |
|
| 1336 | + 'default' => 0, |
|
| 1337 | + 'required' => true, |
|
| 1338 | + 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1339 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1340 | + ) |
|
| 1341 | + ), |
|
| 1342 | + 'type' => new EE_Text_Input( |
|
| 1343 | + array( |
|
| 1344 | + 'default' => 1, |
|
| 1345 | + 'required' => true, |
|
| 1346 | + 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1347 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1348 | + ) |
|
| 1349 | + ), |
|
| 1350 | + 'amount' => new EE_Text_Input( |
|
| 1351 | + array( |
|
| 1352 | + 'default' => 0, |
|
| 1353 | + 'required' => true, |
|
| 1354 | + 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1355 | + 'validation_strategies' => array(new EE_Float_Normalization()) |
|
| 1356 | + ) |
|
| 1357 | + ), |
|
| 1358 | + 'status' => new EE_Text_Input( |
|
| 1359 | + array( |
|
| 1360 | + 'default' => EEM_Payment::status_id_approved, |
|
| 1361 | + 'required' => true, |
|
| 1362 | + 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1363 | + ) |
|
| 1364 | + ), |
|
| 1365 | + 'PMD_ID' => new EE_Text_Input( |
|
| 1366 | + array( |
|
| 1367 | + 'default' => 2, |
|
| 1368 | + 'required' => true, |
|
| 1369 | + 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1370 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1371 | + ) |
|
| 1372 | + ), |
|
| 1373 | + 'date' => new EE_Text_Input( |
|
| 1374 | + array( |
|
| 1375 | + 'default' => time(), |
|
| 1376 | + 'required' => true, |
|
| 1377 | + 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1378 | + ) |
|
| 1379 | + ), |
|
| 1380 | + 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1381 | + array( |
|
| 1382 | + 'default' => '', |
|
| 1383 | + 'required' => false, |
|
| 1384 | + 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1385 | + 'validation_strategies' => array( |
|
| 1386 | + new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1387 | + 100), |
|
| 1388 | + ) |
|
| 1389 | + ) |
|
| 1390 | + ), |
|
| 1391 | + 'po_number' => new EE_Text_Input( |
|
| 1392 | + array( |
|
| 1393 | + 'default' => '', |
|
| 1394 | + 'required' => false, |
|
| 1395 | + 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1396 | + 'validation_strategies' => array( |
|
| 1397 | + new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1398 | + 100), |
|
| 1399 | + ) |
|
| 1400 | + ) |
|
| 1401 | + ), |
|
| 1402 | + 'accounting' => new EE_Text_Input( |
|
| 1403 | + array( |
|
| 1404 | + 'default' => '', |
|
| 1405 | + 'required' => false, |
|
| 1406 | + 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1407 | + 'validation_strategies' => array( |
|
| 1408 | + new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1409 | + 100), |
|
| 1410 | + ) |
|
| 1411 | + ) |
|
| 1412 | + ), |
|
| 1413 | + ) |
|
| 1414 | + ) |
|
| 1415 | + ); |
|
| 1416 | + } |
|
| 1417 | + |
|
| 1418 | + |
|
| 1419 | + /** |
|
| 1420 | + * _create_payment_from_request_data |
|
| 1421 | + * |
|
| 1422 | + * @param array $valid_data |
|
| 1423 | + * |
|
| 1424 | + * @return EE_Payment |
|
| 1425 | + */ |
|
| 1426 | + protected function _create_payment_from_request_data($valid_data) |
|
| 1427 | + { |
|
| 1428 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1429 | + // get payment amount |
|
| 1430 | + $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1431 | + // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1432 | + // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1433 | + $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1434 | + // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1435 | + $date = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a', |
|
| 1436 | + current_time('timestamp')); |
|
| 1437 | + $payment = EE_Payment::new_instance( |
|
| 1438 | + array( |
|
| 1439 | + 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1440 | + 'STS_ID' => $valid_data['status'], |
|
| 1441 | + 'PAY_timestamp' => $date, |
|
| 1442 | + 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1443 | + 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1444 | + 'PAY_amount' => $amount, |
|
| 1445 | + 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1446 | + 'PAY_po_number' => $valid_data['po_number'], |
|
| 1447 | + 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1448 | + 'PAY_details' => $valid_data, |
|
| 1449 | + 'PAY_ID' => $PAY_ID |
|
| 1450 | + ), |
|
| 1451 | + '', |
|
| 1452 | + array('Y-m-d', 'g:i a') |
|
| 1453 | + ); |
|
| 1454 | + |
|
| 1455 | + if ( ! $payment->save()) { |
|
| 1456 | + EE_Error::add_error( |
|
| 1457 | + sprintf( |
|
| 1458 | + esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1459 | + $payment->ID() |
|
| 1460 | + ), |
|
| 1461 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1462 | + ); |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + return $payment; |
|
| 1466 | + } |
|
| 1467 | + |
|
| 1468 | + |
|
| 1469 | + /** |
|
| 1470 | + * _process_transaction_payments |
|
| 1471 | + * |
|
| 1472 | + * @param \EE_Transaction $transaction |
|
| 1473 | + * |
|
| 1474 | + * @return array |
|
| 1475 | + */ |
|
| 1476 | + protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1477 | + { |
|
| 1478 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1479 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1480 | + //update the transaction with this payment |
|
| 1481 | + if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1482 | + EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'), |
|
| 1483 | + __FILE__, __FUNCTION__, __LINE__); |
|
| 1484 | + } else { |
|
| 1485 | + EE_Error::add_error( |
|
| 1486 | + esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1487 | + 'event_espresso') |
|
| 1488 | + , __FILE__, __FUNCTION__, __LINE__ |
|
| 1489 | + ); |
|
| 1490 | + } |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + |
|
| 1494 | + /** |
|
| 1495 | + * _get_REG_IDs_to_apply_payment_to |
|
| 1496 | + * |
|
| 1497 | + * returns a list of registration IDs that the payment will apply to |
|
| 1498 | + * |
|
| 1499 | + * @param \EE_Payment $payment |
|
| 1500 | + * |
|
| 1501 | + * @return array |
|
| 1502 | + */ |
|
| 1503 | + protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1504 | + { |
|
| 1505 | + $REG_IDs = array(); |
|
| 1506 | + // grab array of IDs for specific registrations to apply changes to |
|
| 1507 | + if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1508 | + $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
| 1509 | + } |
|
| 1510 | + //nothing specified ? then get all reg IDs |
|
| 1511 | + if (empty($REG_IDs)) { |
|
| 1512 | + $registrations = $payment->transaction()->registrations(); |
|
| 1513 | + $REG_IDs = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1514 | + } |
|
| 1515 | + |
|
| 1516 | + // ensure that REG_IDs are integers and NOT strings |
|
| 1517 | + return array_map('intval', $REG_IDs); |
|
| 1518 | + } |
|
| 1519 | + |
|
| 1520 | + |
|
| 1521 | + /** |
|
| 1522 | + * @return array |
|
| 1523 | + */ |
|
| 1524 | + public function existing_reg_payment_REG_IDs() |
|
| 1525 | + { |
|
| 1526 | + return $this->_existing_reg_payment_REG_IDs; |
|
| 1527 | + } |
|
| 1528 | + |
|
| 1529 | + |
|
| 1530 | + /** |
|
| 1531 | + * @param array $existing_reg_payment_REG_IDs |
|
| 1532 | + */ |
|
| 1533 | + public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1534 | + { |
|
| 1535 | + $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1536 | + } |
|
| 1537 | + |
|
| 1538 | + |
|
| 1539 | + /** |
|
| 1540 | + * _get_existing_reg_payment_REG_IDs |
|
| 1541 | + * |
|
| 1542 | + * returns a list of registration IDs that the payment is currently related to |
|
| 1543 | + * as recorded in the database |
|
| 1544 | + * |
|
| 1545 | + * @param \EE_Payment $payment |
|
| 1546 | + * |
|
| 1547 | + * @return array |
|
| 1548 | + */ |
|
| 1549 | + protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 1550 | + { |
|
| 1551 | + if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 1552 | + // let's get any existing reg payment records for this payment |
|
| 1553 | + $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 1554 | + // but we only want the REG IDs, so grab the array keys |
|
| 1555 | + $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array(); |
|
| 1556 | + $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 1557 | + } |
|
| 1558 | + |
|
| 1559 | + return $this->existing_reg_payment_REG_IDs(); |
|
| 1560 | + } |
|
| 1561 | + |
|
| 1562 | + |
|
| 1563 | + /** |
|
| 1564 | + * _remove_existing_registration_payments |
|
| 1565 | + * |
|
| 1566 | + * this calculates the difference between existing relations |
|
| 1567 | + * to the supplied payment and the new list registration IDs, |
|
| 1568 | + * removes any related registrations that no longer apply, |
|
| 1569 | + * and then updates the registration paid fields |
|
| 1570 | + * |
|
| 1571 | + * @param \EE_Payment $payment |
|
| 1572 | + * @param int $PAY_ID |
|
| 1573 | + * |
|
| 1574 | + * @return bool; |
|
| 1575 | + */ |
|
| 1576 | + protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 1577 | + { |
|
| 1578 | + // newly created payments will have nothing recorded for $PAY_ID |
|
| 1579 | + if ($PAY_ID == 0) { |
|
| 1580 | + return false; |
|
| 1581 | + } |
|
| 1582 | + $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1583 | + if (empty($existing_reg_payment_REG_IDs)) { |
|
| 1584 | + return false; |
|
| 1585 | + } |
|
| 1586 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1587 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1588 | + |
|
| 1589 | + return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 1590 | + $payment, |
|
| 1591 | + array( |
|
| 1592 | + array( |
|
| 1593 | + 'PAY_ID' => $payment->ID(), |
|
| 1594 | + 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 1595 | + ) |
|
| 1596 | + ) |
|
| 1597 | + ); |
|
| 1598 | + } |
|
| 1599 | + |
|
| 1600 | + |
|
| 1601 | + /** |
|
| 1602 | + * _update_registration_payments |
|
| 1603 | + * |
|
| 1604 | + * this applies the payments to the selected registrations |
|
| 1605 | + * but only if they have not already been paid for |
|
| 1606 | + * |
|
| 1607 | + * @param EE_Transaction $transaction |
|
| 1608 | + * @param \EE_Payment $payment |
|
| 1609 | + * @param array $REG_IDs |
|
| 1610 | + * |
|
| 1611 | + * @return bool |
|
| 1612 | + */ |
|
| 1613 | + protected function _update_registration_payments( |
|
| 1614 | + EE_Transaction $transaction, |
|
| 1615 | + EE_Payment $payment, |
|
| 1616 | + $REG_IDs = array() |
|
| 1617 | + ) { |
|
| 1618 | + // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 1619 | + // so let's do that using our set of REG_IDs from the form |
|
| 1620 | + $registration_query_where_params = array( |
|
| 1621 | + 'REG_ID' => array('IN', $REG_IDs) |
|
| 1622 | + ); |
|
| 1623 | + // but add in some conditions regarding payment, |
|
| 1624 | + // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 1625 | + // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 1626 | + if ( ! $payment->is_a_refund()) { |
|
| 1627 | + $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 1628 | + $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 1629 | + } |
|
| 1630 | + //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ ); |
|
| 1631 | + $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 1632 | + if ( ! empty($registrations)) { |
|
| 1633 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 1634 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 1635 | + $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 1636 | + } |
|
| 1637 | + } |
|
| 1638 | + |
|
| 1639 | + |
|
| 1640 | + /** |
|
| 1641 | + * _process_registration_status_change |
|
| 1642 | + * |
|
| 1643 | + * This processes requested registration status changes for all the registrations |
|
| 1644 | + * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 1645 | + * |
|
| 1646 | + * @param EE_Transaction $transaction |
|
| 1647 | + * @param array $REG_IDs |
|
| 1648 | + * |
|
| 1649 | + * @return bool |
|
| 1650 | + */ |
|
| 1651 | + protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 1652 | + { |
|
| 1653 | + // first if there is no change in status then we get out. |
|
| 1654 | + if ( |
|
| 1655 | + ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 1656 | + || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN' |
|
| 1657 | + ) { |
|
| 1658 | + //no error message, no change requested, just nothing to do man. |
|
| 1659 | + return false; |
|
| 1660 | + } |
|
| 1661 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1662 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1663 | + |
|
| 1664 | + // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 1665 | + return $transaction_processor->manually_update_registration_statuses( |
|
| 1666 | + $transaction, |
|
| 1667 | + sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 1668 | + array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 1669 | + ); |
|
| 1670 | + } |
|
| 1671 | + |
|
| 1672 | + |
|
| 1673 | + /** |
|
| 1674 | + * _build_payment_json_response |
|
| 1675 | + * |
|
| 1676 | + * @access public |
|
| 1677 | + * |
|
| 1678 | + * @param \EE_Payment $payment |
|
| 1679 | + * @param array $REG_IDs |
|
| 1680 | + * @param bool | null $delete_txn_reg_status_change |
|
| 1681 | + * |
|
| 1682 | + * @return array |
|
| 1683 | + */ |
|
| 1684 | + protected function _build_payment_json_response( |
|
| 1685 | + EE_Payment $payment, |
|
| 1686 | + $REG_IDs = array(), |
|
| 1687 | + $delete_txn_reg_status_change = null |
|
| 1688 | + ) { |
|
| 1689 | + // was the payment deleted ? |
|
| 1690 | + if (is_bool($delete_txn_reg_status_change)) { |
|
| 1691 | + return array( |
|
| 1692 | + 'PAY_ID' => $payment->ID(), |
|
| 1693 | + 'amount' => $payment->amount(), |
|
| 1694 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 1695 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 1696 | + 'pay_status' => $payment->STS_ID(), |
|
| 1697 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 1698 | + 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 1699 | + ); |
|
| 1700 | + } else { |
|
| 1701 | + $this->_get_payment_status_array(); |
|
| 1702 | + |
|
| 1703 | + return array( |
|
| 1704 | + 'amount' => $payment->amount(), |
|
| 1705 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 1706 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 1707 | + 'pay_status' => $payment->STS_ID(), |
|
| 1708 | + 'PAY_ID' => $payment->ID(), |
|
| 1709 | + 'STS_ID' => $payment->STS_ID(), |
|
| 1710 | + 'status' => self::$_pay_status[$payment->STS_ID()], |
|
| 1711 | + 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 1712 | + 'method' => strtoupper($payment->source()), |
|
| 1713 | + 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 1714 | + 'gateway' => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown", |
|
| 1715 | + 'event_espresso'), |
|
| 1716 | + 'gateway_response' => $payment->gateway_response(), |
|
| 1717 | + 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 1718 | + 'po_number' => $payment->po_number(), |
|
| 1719 | + 'extra_accntng' => $payment->extra_accntng(), |
|
| 1720 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 1721 | + ); |
|
| 1722 | + } |
|
| 1723 | + } |
|
| 1724 | + |
|
| 1725 | + |
|
| 1726 | + /** |
|
| 1727 | + * delete_payment |
|
| 1728 | + * delete a payment or refund made towards a transaction |
|
| 1729 | + * |
|
| 1730 | + * @access public |
|
| 1731 | + * @return void |
|
| 1732 | + */ |
|
| 1733 | + public function delete_payment() |
|
| 1734 | + { |
|
| 1735 | + $json_response_data = array('return_data' => false); |
|
| 1736 | + $PAY_ID = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0; |
|
| 1737 | + if ($PAY_ID) { |
|
| 1738 | + $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false; |
|
| 1739 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 1740 | + if ($payment instanceof EE_Payment) { |
|
| 1741 | + $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1742 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1743 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1744 | + if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 1745 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs, |
|
| 1746 | + $delete_txn_reg_status_change); |
|
| 1747 | + if ($delete_txn_reg_status_change) { |
|
| 1748 | + $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 1749 | + //MAKE sure we also add the delete_txn_req_status_change to the |
|
| 1750 | + //$_REQUEST global because that's how messages will be looking for it. |
|
| 1751 | + $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 1752 | + $this->_maybe_send_notifications(); |
|
| 1753 | + $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 1754 | + } |
|
| 1755 | + } |
|
| 1756 | + } else { |
|
| 1757 | + EE_Error::add_error( |
|
| 1758 | + esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 1759 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1760 | + ); |
|
| 1761 | + } |
|
| 1762 | + } else { |
|
| 1763 | + EE_Error::add_error( |
|
| 1764 | + esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 1765 | + 'event_espresso'), |
|
| 1766 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1767 | + ); |
|
| 1768 | + } |
|
| 1769 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 1770 | + $this->_template_args = array( |
|
| 1771 | + 'data' => $json_response_data, |
|
| 1772 | + 'success' => $notices['success'], |
|
| 1773 | + 'error' => $notices['errors'], |
|
| 1774 | + 'attention' => $notices['attention'] |
|
| 1775 | + ); |
|
| 1776 | + $this->_return_json(); |
|
| 1777 | + } |
|
| 1778 | + |
|
| 1779 | + |
|
| 1780 | + /** |
|
| 1781 | + * _registration_payment_data_array |
|
| 1782 | + * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 1783 | + * |
|
| 1784 | + * @access protected |
|
| 1785 | + * |
|
| 1786 | + * @param array $REG_IDs |
|
| 1787 | + * |
|
| 1788 | + * @return array |
|
| 1789 | + */ |
|
| 1790 | + protected function _registration_payment_data_array($REG_IDs) |
|
| 1791 | + { |
|
| 1792 | + $registration_payment_data = array(); |
|
| 1793 | + //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 1794 | + if ( ! empty($REG_IDs)) { |
|
| 1795 | + $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 1796 | + foreach ($registrations as $registration) { |
|
| 1797 | + if ($registration instanceof EE_Registration) { |
|
| 1798 | + $registration_payment_data[$registration->ID()] = array( |
|
| 1799 | + 'paid' => $registration->pretty_paid(), |
|
| 1800 | + 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 1801 | + ); |
|
| 1802 | + } |
|
| 1803 | + } |
|
| 1804 | + } |
|
| 1805 | + |
|
| 1806 | + return $registration_payment_data; |
|
| 1807 | + } |
|
| 1808 | + |
|
| 1809 | + |
|
| 1810 | + /** |
|
| 1811 | + * _maybe_send_notifications |
|
| 1812 | + * |
|
| 1813 | + * determines whether or not the admin has indicated that notifications should be sent. |
|
| 1814 | + * If so, will toggle a filter switch for delivering registration notices. |
|
| 1815 | + * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 1816 | + * |
|
| 1817 | + * @access protected |
|
| 1818 | + * |
|
| 1819 | + * @param \EE_Payment | null $payment |
|
| 1820 | + */ |
|
| 1821 | + protected function _maybe_send_notifications($payment = null) |
|
| 1822 | + { |
|
| 1823 | + switch ($payment instanceof EE_Payment) { |
|
| 1824 | + // payment notifications |
|
| 1825 | + case true : |
|
| 1826 | + if ( |
|
| 1827 | + isset( |
|
| 1828 | + $this->_req_data['txn_payments'], |
|
| 1829 | + $this->_req_data['txn_payments']['send_notifications'] |
|
| 1830 | + ) && |
|
| 1831 | + filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 1832 | + ) { |
|
| 1833 | + $this->_process_payment_notification($payment); |
|
| 1834 | + } |
|
| 1835 | + break; |
|
| 1836 | + // registration notifications |
|
| 1837 | + case false : |
|
| 1838 | + if ( |
|
| 1839 | + isset( |
|
| 1840 | + $this->_req_data['txn_reg_status_change'], |
|
| 1841 | + $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
| 1842 | + ) && |
|
| 1843 | + filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 1844 | + ) { |
|
| 1845 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 1846 | + } |
|
| 1847 | + break; |
|
| 1848 | + } |
|
| 1849 | + } |
|
| 1850 | + |
|
| 1851 | + |
|
| 1852 | + /** |
|
| 1853 | + * _send_payment_reminder |
|
| 1854 | + * generates HTML for the View Transaction Details Admin page |
|
| 1855 | + * |
|
| 1856 | + * @access protected |
|
| 1857 | + * @return void |
|
| 1858 | + */ |
|
| 1859 | + protected function _send_payment_reminder() |
|
| 1860 | + { |
|
| 1861 | + $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 1862 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 1863 | + $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 1864 | + 'action' => $this->_req_data['redirect_to'], |
|
| 1865 | + 'TXN_ID' => $this->_req_data['TXN_ID'] |
|
| 1866 | + ) : array(); |
|
| 1867 | + do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 1868 | + $transaction); |
|
| 1869 | + $this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'), |
|
| 1870 | + esc_html__('sent', 'event_espresso'), $query_args, true); |
|
| 1871 | + } |
|
| 1872 | + |
|
| 1873 | + |
|
| 1874 | + /** |
|
| 1875 | + * get_transactions |
|
| 1876 | + * get transactions for given parameters (used by list table) |
|
| 1877 | + * |
|
| 1878 | + * @param int $perpage how many transactions displayed per page |
|
| 1879 | + * @param boolean $count return the count or objects |
|
| 1880 | + * @param string $view |
|
| 1881 | + * |
|
| 1882 | + * @return mixed int = count || array of transaction objects |
|
| 1883 | + */ |
|
| 1884 | + public function get_transactions($perpage, $count = false, $view = '') |
|
| 1885 | + { |
|
| 1886 | + |
|
| 1887 | + $TXN = EEM_Transaction::instance(); |
|
| 1888 | + |
|
| 1889 | + $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y', |
|
| 1890 | + strtotime('-10 year')); |
|
| 1891 | + $end_date = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y'); |
|
| 1892 | + |
|
| 1893 | + //make sure our timestamps start and end right at the boundaries for each day |
|
| 1894 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 1895 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 1896 | + |
|
| 1897 | + |
|
| 1898 | + //convert to timestamps |
|
| 1899 | + $start_date = strtotime($start_date); |
|
| 1900 | + $end_date = strtotime($end_date); |
|
| 1901 | + |
|
| 1902 | + //makes sure start date is the lowest value and vice versa |
|
| 1903 | + $start_date = min($start_date, $end_date); |
|
| 1904 | + $end_date = max($start_date, $end_date); |
|
| 1905 | + |
|
| 1906 | + //convert to correct format for query |
|
| 1907 | + $start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
| 1908 | + date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s'); |
|
| 1909 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
| 1910 | + date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s'); |
|
| 1911 | + |
|
| 1912 | + |
|
| 1913 | + //set orderby |
|
| 1914 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 1915 | + |
|
| 1916 | + switch ($this->_req_data['orderby']) { |
|
| 1917 | + case 'TXN_ID': |
|
| 1918 | + $orderby = 'TXN_ID'; |
|
| 1919 | + break; |
|
| 1920 | + case 'ATT_fname': |
|
| 1921 | + $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 1922 | + break; |
|
| 1923 | + case 'event_name': |
|
| 1924 | + $orderby = 'Registration.Event.EVT_name'; |
|
| 1925 | + break; |
|
| 1926 | + default: //'TXN_timestamp' |
|
| 1927 | + $orderby = 'TXN_timestamp'; |
|
| 1928 | + } |
|
| 1929 | + |
|
| 1930 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC'; |
|
| 1931 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1932 | + $per_page = isset($perpage) && ! empty($perpage) ? $perpage : 10; |
|
| 1933 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 1934 | + |
|
| 1935 | + $offset = ($current_page - 1) * $per_page; |
|
| 1936 | + $limit = array($offset, $per_page); |
|
| 1937 | + |
|
| 1938 | + $_where = array( |
|
| 1939 | + 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 1940 | + 'Registration.REG_count' => 1 |
|
| 1941 | + ); |
|
| 1942 | + |
|
| 1943 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 1944 | + $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 1945 | + } |
|
| 1946 | + |
|
| 1947 | + if (isset($this->_req_data['s'])) { |
|
| 1948 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1949 | + $_where['OR'] = array( |
|
| 1950 | + 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 1951 | + 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1952 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1953 | + 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1954 | + 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1955 | + 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1956 | + 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1957 | + 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1958 | + 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1959 | + 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1960 | + 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1961 | + 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 1962 | + 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 1963 | + 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 1964 | + 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 1965 | + 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1966 | + 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1967 | + 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 1968 | + 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 1969 | + 'TXN_session_data' => array('LIKE', $search_string), |
|
| 1970 | + 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string) |
|
| 1971 | + ); |
|
| 1972 | + } |
|
| 1973 | + |
|
| 1974 | + //failed transactions |
|
| 1975 | + $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false; |
|
| 1976 | + $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false; |
|
| 1977 | + |
|
| 1978 | + if ($failed) { |
|
| 1979 | + $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 1980 | + } else if ($abandoned) { |
|
| 1981 | + $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 1982 | + } else { |
|
| 1983 | + $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 1984 | + $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 1985 | + } |
|
| 1986 | + |
|
| 1987 | + $query_params = array($_where, 'order_by' => array($orderby => $sort), 'limit' => $limit); |
|
| 1988 | + |
|
| 1989 | + $transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params); |
|
| 1990 | + |
|
| 1991 | + |
|
| 1992 | + return $transactions; |
|
| 1993 | + |
|
| 1994 | + } |
|
| 1995 | 1995 | |
| 1996 | 1996 | |
| 1997 | 1997 | } |
@@ -338,11 +338,11 @@ discard block |
||
| 338 | 338 | public function load_scripts_styles() |
| 339 | 339 | { |
| 340 | 340 | //enqueue style |
| 341 | - wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), |
|
| 341 | + wp_register_style('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.css', array(), |
|
| 342 | 342 | EVENT_ESPRESSO_VERSION); |
| 343 | 343 | wp_enqueue_style('espresso_txn'); |
| 344 | 344 | //scripts |
| 345 | - wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
| 345 | + wp_register_script('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.js', array( |
|
| 346 | 346 | 'ee_admin_js', |
| 347 | 347 | 'ee-datepicker', |
| 348 | 348 | 'jquery-ui-datepicker', |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | |
| 435 | 435 | if (empty($this->_transaction)) { |
| 436 | 436 | $error_msg = esc_html__('An error occurred and the details for Transaction ID #', |
| 437 | - 'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso'); |
|
| 437 | + 'event_espresso').$TXN_ID.esc_html__(' could not be retrieved.', 'event_espresso'); |
|
| 438 | 438 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
| 439 | 439 | } |
| 440 | 440 | } |
@@ -509,23 +509,23 @@ discard block |
||
| 509 | 509 | 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
| 510 | 510 | array( |
| 511 | 511 | 'overpaid' => array( |
| 512 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 512 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code, |
|
| 513 | 513 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence') |
| 514 | 514 | ), |
| 515 | 515 | 'complete' => array( |
| 516 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 516 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code, |
|
| 517 | 517 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence') |
| 518 | 518 | ), |
| 519 | 519 | 'incomplete' => array( |
| 520 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 520 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code, |
|
| 521 | 521 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence') |
| 522 | 522 | ), |
| 523 | 523 | 'abandoned' => array( |
| 524 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 524 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code, |
|
| 525 | 525 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence') |
| 526 | 526 | ), |
| 527 | 527 | 'failed' => array( |
| 528 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 528 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code, |
|
| 529 | 529 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence') |
| 530 | 530 | ) |
| 531 | 531 | ) |
@@ -547,10 +547,10 @@ discard block |
||
| 547 | 547 | $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null; |
| 548 | 548 | $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s', |
| 549 | 549 | 'event_espresso'), '<h3>', |
| 550 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
| 551 | - EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event', |
|
| 552 | - 'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : ''; |
|
| 553 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 550 | + '<a href="'.EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
| 551 | + EVENTS_ADMIN_URL).'" title="'.esc_attr__('Click to Edit event', |
|
| 552 | + 'event_espresso').'">'.$event->get('EVT_name').'</a>', '</h3>') : ''; |
|
| 553 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 554 | 554 | $this->display_admin_list_table_page_with_no_sidebar(); |
| 555 | 555 | } |
| 556 | 556 | |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | |
| 585 | 585 | $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
| 586 | 586 | $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
| 587 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 587 | + $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->get('STS_ID'); |
|
| 588 | 588 | |
| 589 | 589 | $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
| 590 | 590 | $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
@@ -621,9 +621,9 @@ discard block |
||
| 621 | 621 | $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
| 622 | 622 | $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true); |
| 623 | 623 | if (EE_Registry::instance()->CFG->currency->sign_b4) { |
| 624 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; |
|
| 624 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign.$this->_template_args['amount_due']; |
|
| 625 | 625 | } else { |
| 626 | - $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; |
|
| 626 | + $this->_template_args['amount_due'] = $this->_template_args['amount_due'].EE_Registry::instance()->CFG->currency->sign; |
|
| 627 | 627 | } |
| 628 | 628 | $this->_template_args['amount_due_class'] = ''; |
| 629 | 629 | |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | |
| 659 | 659 | |
| 660 | 660 | // next link |
| 661 | - $next_txn = $this->_transaction->next( |
|
| 661 | + $next_txn = $this->_transaction->next( |
|
| 662 | 662 | null, |
| 663 | 663 | array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
| 664 | 664 | 'TXN_ID' |
@@ -673,7 +673,7 @@ discard block |
||
| 673 | 673 | ) |
| 674 | 674 | : ''; |
| 675 | 675 | // previous link |
| 676 | - $previous_txn = $this->_transaction->previous( |
|
| 676 | + $previous_txn = $this->_transaction->previous( |
|
| 677 | 677 | null, |
| 678 | 678 | array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
| 679 | 679 | 'TXN_ID' |
@@ -727,7 +727,7 @@ discard block |
||
| 727 | 727 | // grab messages at the last second |
| 728 | 728 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 729 | 729 | // path to template |
| 730 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 730 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php'; |
|
| 731 | 731 | $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
| 732 | 732 | $this->_template_args, true); |
| 733 | 733 | |
@@ -835,18 +835,18 @@ discard block |
||
| 835 | 835 | $reg_steps = '<ul>'; |
| 836 | 836 | foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
| 837 | 837 | if ($reg_step_status === true) { |
| 838 | - $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 839 | - ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 838 | + $reg_steps .= '<li style="color:#70cc50">'.sprintf(esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 839 | + ucwords(str_replace('_', ' ', $reg_step))).'</li>'; |
|
| 840 | 840 | } else if (is_numeric($reg_step_status) && $reg_step_status !== false) { |
| 841 | - $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( |
|
| 841 | + $reg_steps .= '<li style="color:#2EA2CC">'.sprintf( |
|
| 842 | 842 | esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
| 843 | 843 | ucwords(str_replace('_', ' ', $reg_step)), |
| 844 | - date(get_option('date_format') . ' ' . get_option('time_format'), |
|
| 844 | + date(get_option('date_format').' '.get_option('time_format'), |
|
| 845 | 845 | ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))) |
| 846 | - ) . '</li>'; |
|
| 846 | + ).'</li>'; |
|
| 847 | 847 | } else { |
| 848 | - $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated', |
|
| 849 | - 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 848 | + $reg_steps .= '<li style="color:#E76700">'.sprintf(esc_html__('%1$s : Never Initiated', |
|
| 849 | + 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))).'</li>'; |
|
| 850 | 850 | } |
| 851 | 851 | } |
| 852 | 852 | $reg_steps .= '</ul>'; |
@@ -860,11 +860,11 @@ discard block |
||
| 860 | 860 | $this->_get_payment_status_array(); |
| 861 | 861 | $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
| 862 | 862 | |
| 863 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 863 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 864 | 864 | 'action' => 'edit_transaction', |
| 865 | 865 | 'process' => 'transaction' |
| 866 | 866 | ), TXN_ADMIN_URL); |
| 867 | - $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 867 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 868 | 868 | 'page' => 'espresso_transactions', |
| 869 | 869 | 'action' => 'espresso_apply_payment' |
| 870 | 870 | ), WP_AJAX_URL); |
@@ -875,7 +875,7 @@ discard block |
||
| 875 | 875 | |
| 876 | 876 | // 'espresso_delete_payment_nonce' |
| 877 | 877 | |
| 878 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 878 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 879 | 879 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 880 | 880 | |
| 881 | 881 | } |
@@ -935,7 +935,7 @@ discard block |
||
| 935 | 935 | protected function _get_registrations_to_apply_payment_to() |
| 936 | 936 | { |
| 937 | 937 | // we want any registration with an active status (ie: not deleted or cancelled) |
| 938 | - $query_params = array( |
|
| 938 | + $query_params = array( |
|
| 939 | 939 | array( |
| 940 | 940 | 'STS_ID' => array( |
| 941 | 941 | 'IN', |
@@ -947,19 +947,19 @@ discard block |
||
| 947 | 947 | ) |
| 948 | 948 | ) |
| 949 | 949 | ); |
| 950 | - $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 950 | + $registrations_to_apply_payment_to = EEH_HTML::br().EEH_HTML::div( |
|
| 951 | 951 | '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;' |
| 952 | 952 | ); |
| 953 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 953 | + $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 954 | 954 | $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
| 955 | 955 | $registrations_to_apply_payment_to .= EEH_HTML::thead( |
| 956 | 956 | EEH_HTML::tr( |
| 957 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 958 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 959 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 960 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 961 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 962 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 957 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')). |
|
| 958 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')). |
|
| 959 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')). |
|
| 960 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')). |
|
| 961 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
| 962 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr'). |
|
| 963 | 963 | EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
| 964 | 964 | ) |
| 965 | 965 | ); |
@@ -973,28 +973,28 @@ discard block |
||
| 973 | 973 | : esc_html__('Unknown Attendee', 'event_espresso'); |
| 974 | 974 | $owing = $registration->final_price() - $registration->paid(); |
| 975 | 975 | $taxable = $registration->ticket()->taxable() |
| 976 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 976 | + ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>' |
|
| 977 | 977 | : ''; |
| 978 | 978 | $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
| 979 | 979 | ? ' checked="checked"' |
| 980 | 980 | : ''; |
| 981 | 981 | $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
| 982 | 982 | $registrations_to_apply_payment_to .= EEH_HTML::tr( |
| 983 | - EEH_HTML::td($registration->ID()) . |
|
| 984 | - EEH_HTML::td($attendee_name) . |
|
| 983 | + EEH_HTML::td($registration->ID()). |
|
| 984 | + EEH_HTML::td($attendee_name). |
|
| 985 | 985 | EEH_HTML::td( |
| 986 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 987 | - ) . |
|
| 988 | - EEH_HTML::td($registration->event_name()) . |
|
| 989 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 990 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 986 | + $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable |
|
| 987 | + ). |
|
| 988 | + EEH_HTML::td($registration->event_name()). |
|
| 989 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
| 990 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr'). |
|
| 991 | 991 | EEH_HTML::td( |
| 992 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 992 | + '<input type="checkbox" value="'.$registration->ID() |
|
| 993 | 993 | . '" name="txn_admin_payment[registrations]"' |
| 994 | - . $checked . $disabled . '>', |
|
| 994 | + . $checked.$disabled.'>', |
|
| 995 | 995 | '', 'jst-cntr' |
| 996 | 996 | ), |
| 997 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 997 | + 'apply-payment-registration-row-'.$registration->ID() |
|
| 998 | 998 | ); |
| 999 | 999 | } |
| 1000 | 1000 | } |
@@ -1060,12 +1060,12 @@ discard block |
||
| 1060 | 1060 | array( |
| 1061 | 1061 | 'OR*payment_method_for_payment' => array( |
| 1062 | 1062 | 'PMD_ID' => array('IN', $payment_methods_of_payments), |
| 1063 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%') |
|
| 1063 | + 'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%') |
|
| 1064 | 1064 | ) |
| 1065 | 1065 | ) |
| 1066 | 1066 | ); |
| 1067 | 1067 | } else { |
| 1068 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1068 | + $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'))); |
|
| 1069 | 1069 | } |
| 1070 | 1070 | $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
| 1071 | 1071 | } |
@@ -1110,7 +1110,7 @@ discard block |
||
| 1110 | 1110 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
| 1111 | 1111 | $event_name = esc_html__('Unknown Event', 'event_espresso'); |
| 1112 | 1112 | } |
| 1113 | - $event_name .= ' - ' . $item->get('LIN_name'); |
|
| 1113 | + $event_name .= ' - '.$item->get('LIN_name'); |
|
| 1114 | 1114 | $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
| 1115 | 1115 | // now get all of the registrations for this transaction that use this ticket |
| 1116 | 1116 | $registrations = $ticket->get_many_related('Registration', |
@@ -1128,8 +1128,8 @@ discard block |
||
| 1128 | 1128 | if ($attendee instanceof EE_Attendee) { |
| 1129 | 1129 | $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); |
| 1130 | 1130 | $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); |
| 1131 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event', |
|
| 1132 | - 'event_espresso') . '">' . $attendee->email() . '</a>'; |
|
| 1131 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:'.$attendee->email().'?subject='.$event_name.esc_html__(' Event', |
|
| 1132 | + 'event_espresso').'">'.$attendee->email().'</a>'; |
|
| 1133 | 1133 | $this->_template_args['event_attendees'][$registration->ID()]['address'] = EEH_Address::format($attendee, |
| 1134 | 1134 | 'inline', false, false); |
| 1135 | 1135 | } else { |
@@ -1149,7 +1149,7 @@ discard block |
||
| 1149 | 1149 | 'action' => 'edit_transaction', |
| 1150 | 1150 | 'process' => 'attendees' |
| 1151 | 1151 | ), TXN_ADMIN_URL); |
| 1152 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1152 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1153 | 1153 | $this->_template_args, true); |
| 1154 | 1154 | |
| 1155 | 1155 | } else { |
@@ -1190,7 +1190,7 @@ discard block |
||
| 1190 | 1190 | ), REG_ADMIN_URL); |
| 1191 | 1191 | // get formatted address for registrant |
| 1192 | 1192 | $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
| 1193 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1193 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1194 | 1194 | $this->_template_args, true); |
| 1195 | 1195 | } |
| 1196 | 1196 | |
@@ -1211,8 +1211,8 @@ discard block |
||
| 1211 | 1211 | TXN_ADMIN_URL |
| 1212 | 1212 | ); |
| 1213 | 1213 | |
| 1214 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1215 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
| 1214 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1215 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); /**/ |
|
| 1216 | 1216 | } |
| 1217 | 1217 | |
| 1218 | 1218 | |
@@ -1505,7 +1505,7 @@ discard block |
||
| 1505 | 1505 | $REG_IDs = array(); |
| 1506 | 1506 | // grab array of IDs for specific registrations to apply changes to |
| 1507 | 1507 | if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
| 1508 | - $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
| 1508 | + $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
| 1509 | 1509 | } |
| 1510 | 1510 | //nothing specified ? then get all reg IDs |
| 1511 | 1511 | if (empty($REG_IDs)) { |
@@ -1891,8 +1891,8 @@ discard block |
||
| 1891 | 1891 | $end_date = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y'); |
| 1892 | 1892 | |
| 1893 | 1893 | //make sure our timestamps start and end right at the boundaries for each day |
| 1894 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 1895 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 1894 | + $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00'; |
|
| 1895 | + $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59'; |
|
| 1896 | 1896 | |
| 1897 | 1897 | |
| 1898 | 1898 | //convert to timestamps |
@@ -1945,7 +1945,7 @@ discard block |
||
| 1945 | 1945 | } |
| 1946 | 1946 | |
| 1947 | 1947 | if (isset($this->_req_data['s'])) { |
| 1948 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1948 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
| 1949 | 1949 | $_where['OR'] = array( |
| 1950 | 1950 | 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
| 1951 | 1951 | 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /** |
| 5 | 5 | * Event Espresso |
@@ -28,2114 +28,2114 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | |
| 30 | 30 | |
| 31 | - //set in _init_page_props() |
|
| 32 | - public $page_slug; |
|
| 31 | + //set in _init_page_props() |
|
| 32 | + public $page_slug; |
|
| 33 | 33 | |
| 34 | - public $page_label; |
|
| 34 | + public $page_label; |
|
| 35 | 35 | |
| 36 | - public $page_folder; |
|
| 36 | + public $page_folder; |
|
| 37 | 37 | |
| 38 | - //set in define_page_props() |
|
| 39 | - protected $_admin_base_url; |
|
| 38 | + //set in define_page_props() |
|
| 39 | + protected $_admin_base_url; |
|
| 40 | 40 | |
| 41 | - protected $_admin_base_path; |
|
| 41 | + protected $_admin_base_path; |
|
| 42 | 42 | |
| 43 | - protected $_admin_page_title; |
|
| 43 | + protected $_admin_page_title; |
|
| 44 | 44 | |
| 45 | - protected $_labels; |
|
| 45 | + protected $_labels; |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | - //set early within EE_Admin_Init |
|
| 49 | - protected $_wp_page_slug; |
|
| 48 | + //set early within EE_Admin_Init |
|
| 49 | + protected $_wp_page_slug; |
|
| 50 | 50 | |
| 51 | - //navtabs |
|
| 52 | - protected $_nav_tabs; |
|
| 51 | + //navtabs |
|
| 52 | + protected $_nav_tabs; |
|
| 53 | 53 | |
| 54 | - protected $_default_nav_tab_name; |
|
| 54 | + protected $_default_nav_tab_name; |
|
| 55 | 55 | |
| 56 | - //helptourstops |
|
| 57 | - protected $_help_tour = array(); |
|
| 56 | + //helptourstops |
|
| 57 | + protected $_help_tour = array(); |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - //template variables (used by templates) |
|
| 61 | - protected $_template_path; |
|
| 60 | + //template variables (used by templates) |
|
| 61 | + protected $_template_path; |
|
| 62 | 62 | |
| 63 | - protected $_column_template_path; |
|
| 63 | + protected $_column_template_path; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @var array $_template_args |
|
| 67 | - */ |
|
| 68 | - protected $_template_args = array(); |
|
| 65 | + /** |
|
| 66 | + * @var array $_template_args |
|
| 67 | + */ |
|
| 68 | + protected $_template_args = array(); |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * this will hold the list table object for a given view. |
|
| 72 | - * |
|
| 73 | - * @var EE_Admin_List_Table $_list_table_object |
|
| 74 | - */ |
|
| 75 | - protected $_list_table_object; |
|
| 70 | + /** |
|
| 71 | + * this will hold the list table object for a given view. |
|
| 72 | + * |
|
| 73 | + * @var EE_Admin_List_Table $_list_table_object |
|
| 74 | + */ |
|
| 75 | + protected $_list_table_object; |
|
| 76 | 76 | |
| 77 | - //bools |
|
| 78 | - protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states. |
|
| 77 | + //bools |
|
| 78 | + protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states. |
|
| 79 | 79 | |
| 80 | - protected $_routing; |
|
| 80 | + protected $_routing; |
|
| 81 | 81 | |
| 82 | - //list table args |
|
| 83 | - protected $_view; |
|
| 82 | + //list table args |
|
| 83 | + protected $_view; |
|
| 84 | 84 | |
| 85 | - protected $_views; |
|
| 85 | + protected $_views; |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | - //action => method pairs used for routing incoming requests |
|
| 89 | - protected $_page_routes; |
|
| 88 | + //action => method pairs used for routing incoming requests |
|
| 89 | + protected $_page_routes; |
|
| 90 | 90 | |
| 91 | - protected $_page_config; |
|
| 91 | + protected $_page_config; |
|
| 92 | 92 | |
| 93 | - //the current page route and route config |
|
| 94 | - protected $_route; |
|
| 93 | + //the current page route and route config |
|
| 94 | + protected $_route; |
|
| 95 | 95 | |
| 96 | - protected $_route_config; |
|
| 96 | + protected $_route_config; |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 100 | - * actions. |
|
| 101 | - * |
|
| 102 | - * @since 4.6.x |
|
| 103 | - * @var array. |
|
| 104 | - */ |
|
| 105 | - protected $_default_route_query_args; |
|
| 98 | + /** |
|
| 99 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 100 | + * actions. |
|
| 101 | + * |
|
| 102 | + * @since 4.6.x |
|
| 103 | + * @var array. |
|
| 104 | + */ |
|
| 105 | + protected $_default_route_query_args; |
|
| 106 | 106 | |
| 107 | - //set via request page and action args. |
|
| 108 | - protected $_current_page; |
|
| 107 | + //set via request page and action args. |
|
| 108 | + protected $_current_page; |
|
| 109 | 109 | |
| 110 | - protected $_current_view; |
|
| 110 | + protected $_current_view; |
|
| 111 | 111 | |
| 112 | - protected $_current_page_view_url; |
|
| 112 | + protected $_current_page_view_url; |
|
| 113 | 113 | |
| 114 | - //sanitized request action (and nonce) |
|
| 115 | - /** |
|
| 116 | - * @var string $_req_action |
|
| 117 | - */ |
|
| 118 | - protected $_req_action; |
|
| 114 | + //sanitized request action (and nonce) |
|
| 115 | + /** |
|
| 116 | + * @var string $_req_action |
|
| 117 | + */ |
|
| 118 | + protected $_req_action; |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * @var string $_req_nonce |
|
| 122 | - */ |
|
| 123 | - protected $_req_nonce; |
|
| 120 | + /** |
|
| 121 | + * @var string $_req_nonce |
|
| 122 | + */ |
|
| 123 | + protected $_req_nonce; |
|
| 124 | 124 | |
| 125 | - //search related |
|
| 126 | - protected $_search_btn_label; |
|
| 125 | + //search related |
|
| 126 | + protected $_search_btn_label; |
|
| 127 | 127 | |
| 128 | - protected $_search_box_callback; |
|
| 128 | + protected $_search_box_callback; |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * WP Current Screen object |
|
| 132 | - * |
|
| 133 | - * @var WP_Screen |
|
| 134 | - */ |
|
| 135 | - protected $_current_screen; |
|
| 130 | + /** |
|
| 131 | + * WP Current Screen object |
|
| 132 | + * |
|
| 133 | + * @var WP_Screen |
|
| 134 | + */ |
|
| 135 | + protected $_current_screen; |
|
| 136 | 136 | |
| 137 | - //for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 138 | - protected $_hook_obj; |
|
| 137 | + //for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 138 | + protected $_hook_obj; |
|
| 139 | 139 | |
| 140 | - //for holding incoming request data |
|
| 141 | - protected $_req_data; |
|
| 140 | + //for holding incoming request data |
|
| 141 | + protected $_req_data; |
|
| 142 | 142 | |
| 143 | - // yes / no array for admin form fields |
|
| 144 | - protected $_yes_no_values = array(); |
|
| 145 | - |
|
| 146 | - //some default things shared by all child classes |
|
| 147 | - protected $_default_espresso_metaboxes; |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * EE_Registry Object |
|
| 151 | - * |
|
| 152 | - * @var EE_Registry |
|
| 153 | - * @access protected |
|
| 154 | - */ |
|
| 155 | - protected $EE = null; |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 161 | - * |
|
| 162 | - * @var boolean |
|
| 163 | - */ |
|
| 164 | - protected $_is_caf = false; |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @Constructor |
|
| 170 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 171 | - * @access public |
|
| 172 | - */ |
|
| 173 | - public function __construct($routing = true) |
|
| 174 | - { |
|
| 175 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 176 | - $this->_is_caf = true; |
|
| 177 | - } |
|
| 178 | - $this->_yes_no_values = array( |
|
| 179 | - array('id' => true, 'text' => __('Yes', 'event_espresso')), |
|
| 180 | - array('id' => false, 'text' => __('No', 'event_espresso')), |
|
| 181 | - ); |
|
| 182 | - //set the _req_data property. |
|
| 183 | - $this->_req_data = array_merge($_GET, $_POST); |
|
| 184 | - //routing enabled? |
|
| 185 | - $this->_routing = $routing; |
|
| 186 | - //set initial page props (child method) |
|
| 187 | - $this->_init_page_props(); |
|
| 188 | - //set global defaults |
|
| 189 | - $this->_set_defaults(); |
|
| 190 | - //set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 191 | - $this->_global_ajax_hooks(); |
|
| 192 | - $this->_ajax_hooks(); |
|
| 193 | - //other_page_hooks have to be early too. |
|
| 194 | - $this->_do_other_page_hooks(); |
|
| 195 | - //This just allows us to have extending classes do something specific |
|
| 196 | - // before the parent constructor runs _page_setup(). |
|
| 197 | - if (method_exists($this, '_before_page_setup')) { |
|
| 198 | - $this->_before_page_setup(); |
|
| 199 | - } |
|
| 200 | - //set up page dependencies |
|
| 201 | - $this->_page_setup(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * _init_page_props |
|
| 208 | - * Child classes use to set at least the following properties: |
|
| 209 | - * $page_slug. |
|
| 210 | - * $page_label. |
|
| 211 | - * |
|
| 212 | - * @abstract |
|
| 213 | - * @access protected |
|
| 214 | - * @return void |
|
| 215 | - */ |
|
| 216 | - abstract protected function _init_page_props(); |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * _ajax_hooks |
|
| 222 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 223 | - * Note: within the ajax callback methods. |
|
| 224 | - * |
|
| 225 | - * @abstract |
|
| 226 | - * @access protected |
|
| 227 | - * @return void |
|
| 228 | - */ |
|
| 229 | - abstract protected function _ajax_hooks(); |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * _define_page_props |
|
| 235 | - * child classes define page properties in here. Must include at least: |
|
| 236 | - * $_admin_base_url = base_url for all admin pages |
|
| 237 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 238 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 239 | - * array( |
|
| 240 | - * 'buttons' => array( |
|
| 241 | - * 'add' => __('label for add new button'), |
|
| 242 | - * 'edit' => __('label for edit button'), |
|
| 243 | - * 'delete' => __('label for delete button') |
|
| 244 | - * ) |
|
| 245 | - * ) |
|
| 246 | - * |
|
| 247 | - * @abstract |
|
| 248 | - * @access protected |
|
| 249 | - * @return void |
|
| 250 | - */ |
|
| 251 | - abstract protected function _define_page_props(); |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * _set_page_routes |
|
| 257 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also have a 'default' |
|
| 258 | - * route. Here's the format |
|
| 259 | - * $this->_page_routes = array( |
|
| 260 | - * 'default' => array( |
|
| 261 | - * 'func' => '_default_method_handling_route', |
|
| 262 | - * 'args' => array('array','of','args'), |
|
| 263 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing) |
|
| 264 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after. The string you enter here should match the defined route reference for a headers sent route. |
|
| 265 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access this route. |
|
| 266 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks). |
|
| 267 | - * ), |
|
| 268 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method. |
|
| 269 | - * ) |
|
| 270 | - * ) |
|
| 271 | - * |
|
| 272 | - * @abstract |
|
| 273 | - * @access protected |
|
| 274 | - * @return void |
|
| 275 | - */ |
|
| 276 | - abstract protected function _set_page_routes(); |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * _set_page_config |
|
| 282 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page. |
|
| 283 | - * Format: |
|
| 284 | - * $this->_page_config = array( |
|
| 285 | - * 'default' => array( |
|
| 286 | - * 'labels' => array( |
|
| 287 | - * 'buttons' => array( |
|
| 288 | - * 'add' => __('label for adding item'), |
|
| 289 | - * 'edit' => __('label for editing item'), |
|
| 290 | - * 'delete' => __('label for deleting item') |
|
| 291 | - * ), |
|
| 292 | - * 'publishbox' => __('Localized Title for Publish metabox', 'event_espresso') |
|
| 293 | - * ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method |
|
| 294 | - * 'nav' => array( |
|
| 295 | - * 'label' => __('Label for Tab', 'event_espresso'). |
|
| 296 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 297 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 298 | - * 'order' => 10, //required to indicate tab position. |
|
| 299 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter. |
|
| 300 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 301 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages. |
|
| 302 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added later. We just use |
|
| 303 | - * this flag to make sure the necessary js gets enqueued on page load. |
|
| 304 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 305 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The array indicates the max number of columns (4) and the default number of columns on page load (2). There is an option |
|
| 306 | - * in the "screen_options" dropdown that is setup so users can pick what columns they want to display. |
|
| 307 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 308 | - * 'tab_id' => array( |
|
| 309 | - * 'title' => 'tab_title', |
|
| 310 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content. The fallback if it isn't present is to try a the callback. Filename should match a file in the admin |
|
| 311 | - * folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 312 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class |
|
| 313 | - * ), |
|
| 314 | - * 'tab2_id' => array( |
|
| 315 | - * 'title' => 'tab2 title', |
|
| 316 | - * 'filename' => 'file_name_2' |
|
| 317 | - * 'callback' => 'callback_method_for_content', |
|
| 318 | - * ), |
|
| 319 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 320 | - * 'help_tour' => array( |
|
| 321 | - * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 322 | - * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 323 | - * ), |
|
| 324 | - * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present). To remove the requirement for a nonce check when this route is visited just set |
|
| 325 | - * 'require_nonce' to FALSE |
|
| 326 | - * ) |
|
| 327 | - * ) |
|
| 328 | - * |
|
| 329 | - * @abstract |
|
| 330 | - * @access protected |
|
| 331 | - * @return void |
|
| 332 | - */ |
|
| 333 | - abstract protected function _set_page_config(); |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** end sample help_tour methods **/ |
|
| 340 | - /** |
|
| 341 | - * _add_screen_options |
|
| 342 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 343 | - * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view. |
|
| 344 | - * |
|
| 345 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 346 | - * see also WP_Screen object documents... |
|
| 347 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 348 | - * @abstract |
|
| 349 | - * @access protected |
|
| 350 | - * @return void |
|
| 351 | - */ |
|
| 352 | - abstract protected function _add_screen_options(); |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * _add_feature_pointers |
|
| 358 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 359 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view. |
|
| 360 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 361 | - * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see: |
|
| 362 | - * |
|
| 363 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 364 | - * @abstract |
|
| 365 | - * @access protected |
|
| 366 | - * @return void |
|
| 367 | - */ |
|
| 368 | - abstract protected function _add_feature_pointers(); |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * load_scripts_styles |
|
| 374 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific scripts/styles |
|
| 375 | - * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 376 | - * |
|
| 377 | - * @abstract |
|
| 378 | - * @access public |
|
| 379 | - * @return void |
|
| 380 | - */ |
|
| 381 | - abstract public function load_scripts_styles(); |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * admin_init |
|
| 387 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to all pages/views loaded by child class. |
|
| 388 | - * |
|
| 389 | - * @abstract |
|
| 390 | - * @access public |
|
| 391 | - * @return void |
|
| 392 | - */ |
|
| 393 | - abstract public function admin_init(); |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * admin_notices |
|
| 399 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class. |
|
| 400 | - * |
|
| 401 | - * @abstract |
|
| 402 | - * @access public |
|
| 403 | - * @return void |
|
| 404 | - */ |
|
| 405 | - abstract public function admin_notices(); |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * admin_footer_scripts |
|
| 411 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class. |
|
| 412 | - * |
|
| 413 | - * @access public |
|
| 414 | - * @return void |
|
| 415 | - */ |
|
| 416 | - abstract public function admin_footer_scripts(); |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * admin_footer |
|
| 422 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class. |
|
| 423 | - * |
|
| 424 | - * @access public |
|
| 425 | - * @return void |
|
| 426 | - */ |
|
| 427 | - public function admin_footer() |
|
| 428 | - { |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * _global_ajax_hooks |
|
| 435 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 436 | - * Note: within the ajax callback methods. |
|
| 437 | - * |
|
| 438 | - * @abstract |
|
| 439 | - * @access protected |
|
| 440 | - * @return void |
|
| 441 | - */ |
|
| 442 | - protected function _global_ajax_hooks() |
|
| 443 | - { |
|
| 444 | - //for lazy loading of metabox content |
|
| 445 | - add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - public function ajax_metabox_content() |
|
| 451 | - { |
|
| 452 | - $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 453 | - $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 454 | - self::cached_rss_display($contentid, $url); |
|
| 455 | - wp_die(); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * _page_setup |
|
| 462 | - * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested doesn't match the object. |
|
| 463 | - * |
|
| 464 | - * @final |
|
| 465 | - * @access protected |
|
| 466 | - * @return void |
|
| 467 | - */ |
|
| 468 | - final protected function _page_setup() |
|
| 469 | - { |
|
| 470 | - //requires? |
|
| 471 | - //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can. But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 472 | - add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 473 | - //next verify if we need to load anything... |
|
| 474 | - $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 475 | - $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this)))); |
|
| 476 | - global $ee_menu_slugs; |
|
| 477 | - $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 478 | - if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) { |
|
| 479 | - return; |
|
| 480 | - } |
|
| 481 | - // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
| 482 | - if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) { |
|
| 483 | - $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action']; |
|
| 484 | - } |
|
| 485 | - // then set blank or -1 action values to 'default' |
|
| 486 | - $this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default'; |
|
| 487 | - //if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 488 | - $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
|
| 489 | - //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 490 | - $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
|
| 491 | - $this->_current_view = $this->_req_action; |
|
| 492 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 493 | - $this->_define_page_props(); |
|
| 494 | - $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url); |
|
| 495 | - //default things |
|
| 496 | - $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box'); |
|
| 497 | - //set page configs |
|
| 498 | - $this->_set_page_routes(); |
|
| 499 | - $this->_set_page_config(); |
|
| 500 | - //let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 501 | - if (isset($this->_req_data['wp_referer'])) { |
|
| 502 | - $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 503 | - } |
|
| 504 | - //for caffeinated and other extended functionality. If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays |
|
| 505 | - if (method_exists($this, '_extend_page_config')) { |
|
| 506 | - $this->_extend_page_config(); |
|
| 507 | - } |
|
| 508 | - //for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays. |
|
| 509 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 510 | - $this->_extend_page_config_for_cpt(); |
|
| 511 | - } |
|
| 512 | - //filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 513 | - $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this); |
|
| 514 | - $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this); |
|
| 515 | - //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 516 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 517 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2); |
|
| 518 | - } |
|
| 519 | - //next route only if routing enabled |
|
| 520 | - if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 521 | - $this->_verify_routes(); |
|
| 522 | - //next let's just check user_access and kill if no access |
|
| 523 | - $this->check_user_access(); |
|
| 524 | - if ($this->_is_UI_request) { |
|
| 525 | - //admin_init stuff - global, all views for this page class, specific view |
|
| 526 | - add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 527 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 528 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 529 | - } |
|
| 530 | - } else { |
|
| 531 | - //hijack regular WP loading and route admin request immediately |
|
| 532 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 533 | - $this->route_admin_request(); |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - |
|
| 540 | - /** |
|
| 541 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 542 | - * |
|
| 543 | - * @access private |
|
| 544 | - * @return void |
|
| 545 | - */ |
|
| 546 | - private function _do_other_page_hooks() |
|
| 547 | - { |
|
| 548 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 549 | - foreach ($registered_pages as $page) { |
|
| 550 | - //now let's setup the file name and class that should be present |
|
| 551 | - $classname = str_replace('.class.php', '', $page); |
|
| 552 | - //autoloaders should take care of loading file |
|
| 553 | - if ( ! class_exists($classname)) { |
|
| 554 | - $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page); |
|
| 555 | - $error_msg[] = $error_msg[0] |
|
| 556 | - . "\r\n" |
|
| 557 | - . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 558 | - 'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>'); |
|
| 559 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 560 | - } |
|
| 561 | - $a = new ReflectionClass($classname); |
|
| 562 | - //notice we are passing the instance of this class to the hook object. |
|
| 563 | - $hookobj[] = $a->newInstance($this); |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - public function load_page_dependencies() |
|
| 570 | - { |
|
| 571 | - try { |
|
| 572 | - $this->_load_page_dependencies(); |
|
| 573 | - } catch (EE_Error $e) { |
|
| 574 | - $e->get_error(); |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * load_page_dependencies |
|
| 582 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 583 | - * |
|
| 584 | - * @access public |
|
| 585 | - * @return void |
|
| 586 | - */ |
|
| 587 | - protected function _load_page_dependencies() |
|
| 588 | - { |
|
| 589 | - //let's set the current_screen and screen options to override what WP set |
|
| 590 | - $this->_current_screen = get_current_screen(); |
|
| 591 | - //load admin_notices - global, page class, and view specific |
|
| 592 | - add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 593 | - add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 594 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 595 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 596 | - } |
|
| 597 | - //load network admin_notices - global, page class, and view specific |
|
| 598 | - add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 599 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 600 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 601 | - } |
|
| 602 | - //this will save any per_page screen options if they are present |
|
| 603 | - $this->_set_per_page_screen_options(); |
|
| 604 | - //setup list table properties |
|
| 605 | - $this->_set_list_table(); |
|
| 606 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 607 | - $this->_add_registered_meta_boxes(); |
|
| 608 | - $this->_add_screen_columns(); |
|
| 609 | - //add screen options - global, page child class, and view specific |
|
| 610 | - $this->_add_global_screen_options(); |
|
| 611 | - $this->_add_screen_options(); |
|
| 612 | - if (method_exists($this, '_add_screen_options_' . $this->_current_view)) { |
|
| 613 | - call_user_func(array($this, '_add_screen_options_' . $this->_current_view)); |
|
| 614 | - } |
|
| 615 | - //add help tab(s) and tours- set via page_config and qtips. |
|
| 616 | - $this->_add_help_tour(); |
|
| 617 | - $this->_add_help_tabs(); |
|
| 618 | - $this->_add_qtips(); |
|
| 619 | - //add feature_pointers - global, page child class, and view specific |
|
| 620 | - $this->_add_feature_pointers(); |
|
| 621 | - $this->_add_global_feature_pointers(); |
|
| 622 | - if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) { |
|
| 623 | - call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view)); |
|
| 624 | - } |
|
| 625 | - //enqueue scripts/styles - global, page class, and view specific |
|
| 626 | - add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 627 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 628 | - if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) { |
|
| 629 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15); |
|
| 630 | - } |
|
| 631 | - add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 632 | - //admin_print_footer_scripts - global, page child class, and view specific. NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. In most cases that's doing_it_wrong(). But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these |
|
| 633 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 634 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 635 | - if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) { |
|
| 636 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101); |
|
| 637 | - } |
|
| 638 | - //admin footer scripts |
|
| 639 | - add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 640 | - add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 641 | - if (method_exists($this, 'admin_footer_' . $this->_current_view)) { |
|
| 642 | - add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101); |
|
| 643 | - } |
|
| 644 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 645 | - //targeted hook |
|
| 646 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * _set_defaults |
|
| 653 | - * This sets some global defaults for class properties. |
|
| 654 | - */ |
|
| 655 | - private function _set_defaults() |
|
| 656 | - { |
|
| 657 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 658 | - $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array(); |
|
| 659 | - $this->default_nav_tab_name = 'overview'; |
|
| 660 | - //init template args |
|
| 661 | - $this->_template_args = array( |
|
| 662 | - 'admin_page_header' => '', |
|
| 663 | - 'admin_page_content' => '', |
|
| 664 | - 'post_body_content' => '', |
|
| 665 | - 'before_list_table' => '', |
|
| 666 | - 'after_list_table' => '', |
|
| 667 | - ); |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - |
|
| 672 | - /** |
|
| 673 | - * route_admin_request |
|
| 674 | - * |
|
| 675 | - * @see _route_admin_request() |
|
| 676 | - * @access public |
|
| 677 | - * @return void|exception error |
|
| 678 | - */ |
|
| 679 | - public function route_admin_request() |
|
| 680 | - { |
|
| 681 | - try { |
|
| 682 | - $this->_route_admin_request(); |
|
| 683 | - } catch (EE_Error $e) { |
|
| 684 | - $e->get_error(); |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - |
|
| 690 | - public function set_wp_page_slug($wp_page_slug) |
|
| 691 | - { |
|
| 692 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 693 | - //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 694 | - if (is_network_admin()) { |
|
| 695 | - $this->_wp_page_slug .= '-network'; |
|
| 696 | - } |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * _verify_routes |
|
| 703 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so we know if we need to drop out. |
|
| 704 | - * |
|
| 705 | - * @access protected |
|
| 706 | - * @return void |
|
| 707 | - */ |
|
| 708 | - protected function _verify_routes() |
|
| 709 | - { |
|
| 710 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 711 | - if ( ! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 712 | - return false; |
|
| 713 | - } |
|
| 714 | - $this->_route = false; |
|
| 715 | - $func = false; |
|
| 716 | - $args = array(); |
|
| 717 | - // check that the page_routes array is not empty |
|
| 718 | - if (empty($this->_page_routes)) { |
|
| 719 | - // user error msg |
|
| 720 | - $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 721 | - // developer error msg |
|
| 722 | - $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso'); |
|
| 723 | - throw new EE_Error($error_msg); |
|
| 724 | - } |
|
| 725 | - // and that the requested page route exists |
|
| 726 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 727 | - $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 728 | - $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array(); |
|
| 729 | - } else { |
|
| 730 | - // user error msg |
|
| 731 | - $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 732 | - // developer error msg |
|
| 733 | - $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action); |
|
| 734 | - throw new EE_Error($error_msg); |
|
| 735 | - } |
|
| 736 | - // and that a default route exists |
|
| 737 | - if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 738 | - // user error msg |
|
| 739 | - $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 740 | - // developer error msg |
|
| 741 | - $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso'); |
|
| 742 | - throw new EE_Error($error_msg); |
|
| 743 | - } |
|
| 744 | - //first lets' catch if the UI request has EVER been set. |
|
| 745 | - if ($this->_is_UI_request === null) { |
|
| 746 | - //lets set if this is a UI request or not. |
|
| 747 | - $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false; |
|
| 748 | - //wait a minute... we might have a noheader in the route array |
|
| 749 | - $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 750 | - } |
|
| 751 | - $this->_set_current_labels(); |
|
| 752 | - } |
|
| 753 | - |
|
| 754 | - |
|
| 755 | - |
|
| 756 | - /** |
|
| 757 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 758 | - * |
|
| 759 | - * @param string $route the route name we're verifying |
|
| 760 | - * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 761 | - */ |
|
| 762 | - protected function _verify_route($route) |
|
| 763 | - { |
|
| 764 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 765 | - return true; |
|
| 766 | - } else { |
|
| 767 | - // user error msg |
|
| 768 | - $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 769 | - // developer error msg |
|
| 770 | - $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route); |
|
| 771 | - throw new EE_Error($error_msg); |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * perform nonce verification |
|
| 779 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!) |
|
| 780 | - * |
|
| 781 | - * @param string $nonce The nonce sent |
|
| 782 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 783 | - * @return mixed (bool|die) |
|
| 784 | - */ |
|
| 785 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
| 786 | - { |
|
| 787 | - // verify nonce against expected value |
|
| 788 | - if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 789 | - // these are not the droids you are looking for !!! |
|
| 790 | - $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>'); |
|
| 791 | - if (WP_DEBUG) { |
|
| 792 | - $msg .= "\n " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__); |
|
| 793 | - } |
|
| 794 | - if ( ! defined('DOING_AJAX')) { |
|
| 795 | - wp_die($msg); |
|
| 796 | - } else { |
|
| 797 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 798 | - $this->_return_json(); |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - |
|
| 804 | - |
|
| 805 | - /** |
|
| 806 | - * _route_admin_request() |
|
| 807 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 808 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 809 | - * in the page routes and then will try to load the corresponding method. |
|
| 810 | - * |
|
| 811 | - * @access protected |
|
| 812 | - * @return void |
|
| 813 | - * @throws \EE_Error |
|
| 814 | - */ |
|
| 815 | - protected function _route_admin_request() |
|
| 816 | - { |
|
| 817 | - if ( ! $this->_is_UI_request) { |
|
| 818 | - $this->_verify_routes(); |
|
| 819 | - } |
|
| 820 | - $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 821 | - ? $this->_route_config['require_nonce'] |
|
| 822 | - : true; |
|
| 823 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 824 | - // set nonce from post data |
|
| 825 | - $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 826 | - ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 827 | - : ''; |
|
| 828 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 829 | - } |
|
| 830 | - //set the nav_tabs array but ONLY if this is UI_request |
|
| 831 | - if ($this->_is_UI_request) { |
|
| 832 | - $this->_set_nav_tabs(); |
|
| 833 | - } |
|
| 834 | - // grab callback function |
|
| 835 | - $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 836 | - // check if callback has args |
|
| 837 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 838 | - $error_msg = ''; |
|
| 839 | - // action right before calling route |
|
| 840 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 841 | - if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 842 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 843 | - } |
|
| 844 | - // right before calling the route, let's remove _wp_http_referer from the |
|
| 845 | - // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 846 | - $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI'])); |
|
| 847 | - if ( ! empty($func)) { |
|
| 848 | - if (is_array($func)) { |
|
| 849 | - list($class, $method) = $func; |
|
| 850 | - } else if (strpos($func, '::') !== false) { |
|
| 851 | - list($class, $method) = explode('::', $func); |
|
| 852 | - } else { |
|
| 853 | - $class = $this; |
|
| 854 | - $method = $func; |
|
| 855 | - } |
|
| 856 | - if ( ! (is_object($class) && $class === $this)) { |
|
| 857 | - // send along this admin page object for access by addons. |
|
| 858 | - $args['admin_page_object'] = $this; |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - if ( |
|
| 862 | - //is it a method on a class that doesn't work? |
|
| 863 | - ( |
|
| 864 | - ( |
|
| 865 | - method_exists($class, $method) |
|
| 866 | - && call_user_func_array(array($class, $method), $args) === false |
|
| 867 | - ) |
|
| 868 | - && ( |
|
| 869 | - //is it a standalone function that doesn't work? |
|
| 870 | - function_exists($method) |
|
| 871 | - && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false |
|
| 872 | - ) |
|
| 873 | - ) |
|
| 874 | - || ( |
|
| 875 | - //is it neither a class method NOR a standalone function? |
|
| 876 | - ! method_exists($class, $method) |
|
| 877 | - && ! function_exists($method) |
|
| 878 | - ) |
|
| 879 | - ) { |
|
| 880 | - // user error msg |
|
| 881 | - $error_msg = __('An error occurred. The requested page route could not be found.', 'event_espresso'); |
|
| 882 | - // developer error msg |
|
| 883 | - $error_msg .= '||'; |
|
| 884 | - $error_msg .= sprintf( |
|
| 885 | - __( |
|
| 886 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 887 | - 'event_espresso' |
|
| 888 | - ), |
|
| 889 | - $method |
|
| 890 | - ); |
|
| 891 | - } |
|
| 892 | - if ( ! empty($error_msg)) { |
|
| 893 | - throw new EE_Error($error_msg); |
|
| 894 | - } |
|
| 895 | - } |
|
| 896 | - //if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route. |
|
| 897 | - //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 898 | - if ($this->_is_UI_request === false |
|
| 899 | - && is_array($this->_route) |
|
| 900 | - && ! empty($this->_route['headers_sent_route']) |
|
| 901 | - ) { |
|
| 902 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 903 | - } |
|
| 904 | - } |
|
| 905 | - |
|
| 906 | - |
|
| 907 | - |
|
| 908 | - /** |
|
| 909 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 910 | - * route redirects to a headers route in its route config. |
|
| 911 | - * |
|
| 912 | - * @since 4.3.0 |
|
| 913 | - * @param string $new_route New (non header) route to redirect to. |
|
| 914 | - * @return void |
|
| 915 | - */ |
|
| 916 | - protected function _reset_routing_properties($new_route) |
|
| 917 | - { |
|
| 918 | - $this->_is_UI_request = true; |
|
| 919 | - //now we set the current route to whatever the headers_sent_route is set at |
|
| 920 | - $this->_req_data['action'] = $new_route; |
|
| 921 | - //rerun page setup |
|
| 922 | - $this->_page_setup(); |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - |
|
| 926 | - |
|
| 927 | - /** |
|
| 928 | - * _add_query_arg |
|
| 929 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 930 | - *(internally just uses EEH_URL's function with the same name) |
|
| 931 | - * |
|
| 932 | - * @access public |
|
| 933 | - * @param array $args |
|
| 934 | - * @param string $url |
|
| 935 | - * @param bool $sticky if true, then the existing Request params will be appended to the generated |
|
| 936 | - * url in an associative array indexed by the key 'wp_referer'; |
|
| 937 | - * Example usage: |
|
| 938 | - * If the current page is: |
|
| 939 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 940 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 941 | - * &_wpnonce=5467821 |
|
| 942 | - * and you call: |
|
| 943 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 944 | - * array( |
|
| 945 | - * 'action' => 'resend_something', |
|
| 946 | - * 'page=>espresso_registrations' |
|
| 947 | - * ), |
|
| 948 | - * $some_url, |
|
| 949 | - * true |
|
| 950 | - * ); |
|
| 951 | - * It will produce a url in this structure: |
|
| 952 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 953 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 954 | - * month_range]=March%202015 |
|
| 955 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 956 | - * @return string |
|
| 957 | - */ |
|
| 958 | - public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false) |
|
| 959 | - { |
|
| 960 | - //if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 961 | - if ($sticky) { |
|
| 962 | - $request = $_REQUEST; |
|
| 963 | - unset($request['_wp_http_referer']); |
|
| 964 | - unset($request['wp_referer']); |
|
| 965 | - foreach ($request as $key => $value) { |
|
| 966 | - //do not add nonces |
|
| 967 | - if (strpos($key, 'nonce') !== false) { |
|
| 968 | - continue; |
|
| 969 | - } |
|
| 970 | - $args['wp_referer[' . $key . ']'] = $value; |
|
| 971 | - } |
|
| 972 | - } |
|
| 973 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - /** |
|
| 979 | - * This returns a generated link that will load the related help tab. |
|
| 980 | - * |
|
| 981 | - * @param string $help_tab_id the id for the connected help tab |
|
| 982 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 983 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 984 | - * @uses EEH_Template::get_help_tab_link() |
|
| 985 | - * @return string generated link |
|
| 986 | - */ |
|
| 987 | - protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false) |
|
| 988 | - { |
|
| 989 | - return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text); |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - |
|
| 993 | - |
|
| 994 | - /** |
|
| 995 | - * _add_help_tabs |
|
| 996 | - * Note child classes define their help tabs within the page_config array. |
|
| 997 | - * |
|
| 998 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 999 | - * @access protected |
|
| 1000 | - * @return void |
|
| 1001 | - */ |
|
| 1002 | - protected function _add_help_tabs() |
|
| 1003 | - { |
|
| 1004 | - $tour_buttons = ''; |
|
| 1005 | - if (isset($this->_page_config[$this->_req_action])) { |
|
| 1006 | - $config = $this->_page_config[$this->_req_action]; |
|
| 1007 | - //is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1008 | - if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1009 | - $tb = array(); |
|
| 1010 | - $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1011 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1012 | - //if this is the end tour then we don't need to setup a button |
|
| 1013 | - if ($tour instanceof EE_Help_Tour_final_stop) { |
|
| 1014 | - continue; |
|
| 1015 | - } |
|
| 1016 | - $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>'; |
|
| 1017 | - } |
|
| 1018 | - $tour_buttons .= implode('<br />', $tb); |
|
| 1019 | - $tour_buttons .= '</div></div>'; |
|
| 1020 | - } |
|
| 1021 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1022 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1023 | - //check that the callback given is valid |
|
| 1024 | - if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1025 | - throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1026 | - 'event_espresso'), $config['help_sidebar'], get_class($this))); |
|
| 1027 | - } |
|
| 1028 | - $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar']))); |
|
| 1029 | - $content .= $tour_buttons; //add help tour buttons. |
|
| 1030 | - //do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1031 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1032 | - } |
|
| 1033 | - //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar. |
|
| 1034 | - if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1035 | - $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1036 | - } |
|
| 1037 | - //handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1038 | - if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1039 | - $_ht['id'] = $this->page_slug; |
|
| 1040 | - $_ht['title'] = __('Help Tours', 'event_espresso'); |
|
| 1041 | - $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>'; |
|
| 1042 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1043 | - }/**/ |
|
| 1044 | - if ( ! isset($config['help_tabs'])) { |
|
| 1045 | - return; |
|
| 1046 | - } //no help tabs for this route |
|
| 1047 | - foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1048 | - //we're here so there ARE help tabs! |
|
| 1049 | - //make sure we've got what we need |
|
| 1050 | - if ( ! isset($cfg['title'])) { |
|
| 1051 | - throw new EE_Error(__('The _page_config array is not set up properly for help tabs. It is missing a title', 'event_espresso')); |
|
| 1052 | - } |
|
| 1053 | - if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1054 | - throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1055 | - 'event_espresso')); |
|
| 1056 | - } |
|
| 1057 | - //first priority goes to content. |
|
| 1058 | - if ( ! empty($cfg['content'])) { |
|
| 1059 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1060 | - //second priority goes to filename |
|
| 1061 | - } else if ( ! empty($cfg['filename'])) { |
|
| 1062 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1063 | - //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1064 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path; |
|
| 1065 | - //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1066 | - if ( ! is_readable($file_path) && ! isset($cfg['callback'])) { |
|
| 1067 | - EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1068 | - 'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__); |
|
| 1069 | - return; |
|
| 1070 | - } |
|
| 1071 | - $template_args['admin_page_obj'] = $this; |
|
| 1072 | - $content = EEH_Template::display_template($file_path, $template_args, true); |
|
| 1073 | - } else { |
|
| 1074 | - $content = ''; |
|
| 1075 | - } |
|
| 1076 | - //check if callback is valid |
|
| 1077 | - if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) { |
|
| 1078 | - EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1079 | - 'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__); |
|
| 1080 | - return; |
|
| 1081 | - } |
|
| 1082 | - //setup config array for help tab method |
|
| 1083 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1084 | - $_ht = array( |
|
| 1085 | - 'id' => $id, |
|
| 1086 | - 'title' => $cfg['title'], |
|
| 1087 | - 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1088 | - 'content' => $content, |
|
| 1089 | - ); |
|
| 1090 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1091 | - } |
|
| 1092 | - } |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - |
|
| 1096 | - |
|
| 1097 | - /** |
|
| 1098 | - * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is an array with properties for setting up usage of the joyride plugin |
|
| 1099 | - * |
|
| 1100 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1101 | - * @see instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments |
|
| 1102 | - * @access protected |
|
| 1103 | - * @return void |
|
| 1104 | - */ |
|
| 1105 | - protected function _add_help_tour() |
|
| 1106 | - { |
|
| 1107 | - $tours = array(); |
|
| 1108 | - $this->_help_tour = array(); |
|
| 1109 | - //exit early if help tours are turned off globally |
|
| 1110 | - if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) { |
|
| 1111 | - return; |
|
| 1112 | - } |
|
| 1113 | - //loop through _page_config to find any help_tour defined |
|
| 1114 | - foreach ($this->_page_config as $route => $config) { |
|
| 1115 | - //we're only going to set things up for this route |
|
| 1116 | - if ($route !== $this->_req_action) { |
|
| 1117 | - continue; |
|
| 1118 | - } |
|
| 1119 | - if (isset($config['help_tour'])) { |
|
| 1120 | - foreach ($config['help_tour'] as $tour) { |
|
| 1121 | - $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1122 | - //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent |
|
| 1123 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path; |
|
| 1124 | - //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1125 | - if ( ! is_readable($file_path)) { |
|
| 1126 | - EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'), |
|
| 1127 | - $file_path, $tour), __FILE__, __FUNCTION__, __LINE__); |
|
| 1128 | - return; |
|
| 1129 | - } |
|
| 1130 | - require_once $file_path; |
|
| 1131 | - if ( ! class_exists($tour)) { |
|
| 1132 | - $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour); |
|
| 1133 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1134 | - 'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this)); |
|
| 1135 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 1136 | - } |
|
| 1137 | - $a = new ReflectionClass($tour); |
|
| 1138 | - $tour_obj = $a->newInstance($this->_is_caf); |
|
| 1139 | - $tours[] = $tour_obj; |
|
| 1140 | - $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1141 | - } |
|
| 1142 | - //let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1143 | - $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1144 | - $tours[] = $end_stop_tour; |
|
| 1145 | - $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1146 | - } |
|
| 1147 | - } |
|
| 1148 | - if ( ! empty($tours)) { |
|
| 1149 | - $this->_help_tour['tours'] = $tours; |
|
| 1150 | - } |
|
| 1151 | - //thats it! Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically. |
|
| 1152 | - } |
|
| 1153 | - |
|
| 1154 | - |
|
| 1155 | - |
|
| 1156 | - /** |
|
| 1157 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1158 | - * |
|
| 1159 | - * @access protected |
|
| 1160 | - * @return void |
|
| 1161 | - */ |
|
| 1162 | - protected function _add_qtips() |
|
| 1163 | - { |
|
| 1164 | - if (isset($this->_route_config['qtips'])) { |
|
| 1165 | - $qtips = (array)$this->_route_config['qtips']; |
|
| 1166 | - //load qtip loader |
|
| 1167 | - $path = array( |
|
| 1168 | - $this->_get_dir() . '/qtips/', |
|
| 1169 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1170 | - ); |
|
| 1171 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1172 | - } |
|
| 1173 | - } |
|
| 1174 | - |
|
| 1175 | - |
|
| 1176 | - |
|
| 1177 | - /** |
|
| 1178 | - * _set_nav_tabs |
|
| 1179 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly. |
|
| 1180 | - * |
|
| 1181 | - * @access protected |
|
| 1182 | - * @return void |
|
| 1183 | - */ |
|
| 1184 | - protected function _set_nav_tabs() |
|
| 1185 | - { |
|
| 1186 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1187 | - $i = 0; |
|
| 1188 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1189 | - if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) { |
|
| 1190 | - continue; |
|
| 1191 | - } //no nav tab for this config |
|
| 1192 | - //check for persistent flag |
|
| 1193 | - if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) { |
|
| 1194 | - continue; |
|
| 1195 | - } //nav tab is only to appear when route requested. |
|
| 1196 | - if ( ! $this->check_user_access($slug, true)) { |
|
| 1197 | - continue; |
|
| 1198 | - } //no nav tab becasue current user does not have access. |
|
| 1199 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1200 | - $this->_nav_tabs[$slug] = array( |
|
| 1201 | - 'url' => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url), |
|
| 1202 | - 'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)), |
|
| 1203 | - 'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1204 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1205 | - ); |
|
| 1206 | - $i++; |
|
| 1207 | - } |
|
| 1208 | - //if $this->_nav_tabs is empty then lets set the default |
|
| 1209 | - if (empty($this->_nav_tabs)) { |
|
| 1210 | - $this->_nav_tabs[$this->default_nav_tab_name] = array( |
|
| 1211 | - 'url' => $this->admin_base_url, |
|
| 1212 | - 'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)), |
|
| 1213 | - 'css_class' => 'nav-tab-active', |
|
| 1214 | - 'order' => 10, |
|
| 1215 | - ); |
|
| 1216 | - } |
|
| 1217 | - //now let's sort the tabs according to order |
|
| 1218 | - usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - |
|
| 1222 | - |
|
| 1223 | - /** |
|
| 1224 | - * _set_current_labels |
|
| 1225 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array |
|
| 1226 | - * |
|
| 1227 | - * @access private |
|
| 1228 | - * @return void |
|
| 1229 | - */ |
|
| 1230 | - private function _set_current_labels() |
|
| 1231 | - { |
|
| 1232 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1233 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1234 | - if (is_array($text)) { |
|
| 1235 | - foreach ($text as $sublabel => $subtext) { |
|
| 1236 | - $this->_labels[$label][$sublabel] = $subtext; |
|
| 1237 | - } |
|
| 1238 | - } else { |
|
| 1239 | - $this->_labels[$label] = $text; |
|
| 1240 | - } |
|
| 1241 | - } |
|
| 1242 | - } |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - |
|
| 1246 | - |
|
| 1247 | - /** |
|
| 1248 | - * verifies user access for this admin page |
|
| 1249 | - * |
|
| 1250 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1251 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just return false if verify fail. |
|
| 1252 | - * @return BOOL|wp_die() |
|
| 1253 | - */ |
|
| 1254 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1255 | - { |
|
| 1256 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1257 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1258 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1259 | - ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1260 | - if (empty($capability) && empty($route_to_check)) { |
|
| 1261 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability']; |
|
| 1262 | - } else { |
|
| 1263 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1264 | - } |
|
| 1265 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1266 | - if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) { |
|
| 1267 | - if ($verify_only) { |
|
| 1268 | - return false; |
|
| 1269 | - } else { |
|
| 1270 | - if ( is_user_logged_in() ) { |
|
| 1271 | - wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1272 | - } else { |
|
| 1273 | - return false; |
|
| 1274 | - } |
|
| 1275 | - } |
|
| 1276 | - } |
|
| 1277 | - return true; |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - |
|
| 1281 | - |
|
| 1282 | - /** |
|
| 1283 | - * admin_init_global |
|
| 1284 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1285 | - * This method executes for ALL EE Admin pages. |
|
| 1286 | - * |
|
| 1287 | - * @access public |
|
| 1288 | - * @return void |
|
| 1289 | - */ |
|
| 1290 | - public function admin_init_global() |
|
| 1291 | - { |
|
| 1292 | - } |
|
| 1293 | - |
|
| 1294 | - |
|
| 1295 | - |
|
| 1296 | - /** |
|
| 1297 | - * wp_loaded_global |
|
| 1298 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an EE_Admin page and will execute on every EE Admin Page load |
|
| 1299 | - * |
|
| 1300 | - * @access public |
|
| 1301 | - * @return void |
|
| 1302 | - */ |
|
| 1303 | - public function wp_loaded() |
|
| 1304 | - { |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * admin_notices |
|
| 1311 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages. |
|
| 1312 | - * |
|
| 1313 | - * @access public |
|
| 1314 | - * @return void |
|
| 1315 | - */ |
|
| 1316 | - public function admin_notices_global() |
|
| 1317 | - { |
|
| 1318 | - $this->_display_no_javascript_warning(); |
|
| 1319 | - $this->_display_espresso_notices(); |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - |
|
| 1323 | - |
|
| 1324 | - public function network_admin_notices_global() |
|
| 1325 | - { |
|
| 1326 | - $this->_display_no_javascript_warning(); |
|
| 1327 | - $this->_display_espresso_notices(); |
|
| 1328 | - } |
|
| 1329 | - |
|
| 1330 | - |
|
| 1331 | - |
|
| 1332 | - /** |
|
| 1333 | - * admin_footer_scripts_global |
|
| 1334 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages. |
|
| 1335 | - * |
|
| 1336 | - * @access public |
|
| 1337 | - * @return void |
|
| 1338 | - */ |
|
| 1339 | - public function admin_footer_scripts_global() |
|
| 1340 | - { |
|
| 1341 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1342 | - $this->_add_admin_page_overlay(); |
|
| 1343 | - //if metaboxes are present we need to add the nonce field |
|
| 1344 | - if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) { |
|
| 1345 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1346 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1347 | - } |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - |
|
| 1351 | - |
|
| 1352 | - /** |
|
| 1353 | - * admin_footer_global |
|
| 1354 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages. |
|
| 1355 | - * |
|
| 1356 | - * @access public |
|
| 1357 | - * @return void |
|
| 1358 | - */ |
|
| 1359 | - public function admin_footer_global() |
|
| 1360 | - { |
|
| 1361 | - //dialog container for dialog helper |
|
| 1362 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1363 | - $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1364 | - $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1365 | - $d_cont .= '</div>'; |
|
| 1366 | - echo $d_cont; |
|
| 1367 | - //help tour stuff? |
|
| 1368 | - if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1369 | - echo implode('<br />', $this->_help_tour[$this->_req_action]); |
|
| 1370 | - } |
|
| 1371 | - //current set timezone for timezone js |
|
| 1372 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - |
|
| 1376 | - |
|
| 1377 | - /** |
|
| 1378 | - * This function sees if there is a method for help popup content existing for the given route. If there is then we'll use the retrieved array to output the content using the template. |
|
| 1379 | - * For child classes: |
|
| 1380 | - * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for |
|
| 1381 | - * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content for the |
|
| 1382 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1383 | - * 'help_trigger_id' => array( |
|
| 1384 | - * 'title' => __('localized title for popup', 'event_espresso'), |
|
| 1385 | - * 'content' => __('localized content for popup', 'event_espresso') |
|
| 1386 | - * ) |
|
| 1387 | - * ); |
|
| 1388 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1389 | - * |
|
| 1390 | - * @access protected |
|
| 1391 | - * @return string content |
|
| 1392 | - */ |
|
| 1393 | - protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1394 | - { |
|
| 1395 | - $content = ''; |
|
| 1396 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1397 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php'; |
|
| 1398 | - //loop through the array and setup content |
|
| 1399 | - foreach ($help_array as $trigger => $help) { |
|
| 1400 | - //make sure the array is setup properly |
|
| 1401 | - if ( ! isset($help['title']) || ! isset($help['content'])) { |
|
| 1402 | - throw new EE_Error(__('Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1403 | - 'event_espresso')); |
|
| 1404 | - } |
|
| 1405 | - //we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1406 | - $template_args = array( |
|
| 1407 | - 'help_popup_id' => $trigger, |
|
| 1408 | - 'help_popup_title' => $help['title'], |
|
| 1409 | - 'help_popup_content' => $help['content'], |
|
| 1410 | - ); |
|
| 1411 | - $content .= EEH_Template::display_template($template_path, $template_args, true); |
|
| 1412 | - } |
|
| 1413 | - if ($display) { |
|
| 1414 | - echo $content; |
|
| 1415 | - } else { |
|
| 1416 | - return $content; |
|
| 1417 | - } |
|
| 1418 | - } |
|
| 1419 | - |
|
| 1420 | - |
|
| 1421 | - |
|
| 1422 | - /** |
|
| 1423 | - * All this does is retrive the help content array if set by the EE_Admin_Page child |
|
| 1424 | - * |
|
| 1425 | - * @access private |
|
| 1426 | - * @return array properly formatted array for help popup content |
|
| 1427 | - */ |
|
| 1428 | - private function _get_help_content() |
|
| 1429 | - { |
|
| 1430 | - //what is the method we're looking for? |
|
| 1431 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1432 | - //if method doesn't exist let's get out. |
|
| 1433 | - if ( ! method_exists($this, $method_name)) { |
|
| 1434 | - return array(); |
|
| 1435 | - } |
|
| 1436 | - //k we're good to go let's retrieve the help array |
|
| 1437 | - $help_array = call_user_func(array($this, $method_name)); |
|
| 1438 | - //make sure we've got an array! |
|
| 1439 | - if ( ! is_array($help_array)) { |
|
| 1440 | - throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso')); |
|
| 1441 | - } |
|
| 1442 | - return $help_array; |
|
| 1443 | - } |
|
| 1444 | - |
|
| 1445 | - |
|
| 1446 | - |
|
| 1447 | - /** |
|
| 1448 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1449 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1450 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1451 | - * |
|
| 1452 | - * @access protected |
|
| 1453 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1454 | - * @param boolean $display if false then we return the trigger string |
|
| 1455 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1456 | - * @return string |
|
| 1457 | - */ |
|
| 1458 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1459 | - { |
|
| 1460 | - if (defined('DOING_AJAX')) { |
|
| 1461 | - return; |
|
| 1462 | - } |
|
| 1463 | - //let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1464 | - $help_array = $this->_get_help_content(); |
|
| 1465 | - $help_content = ''; |
|
| 1466 | - if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1467 | - $help_array[$trigger_id] = array( |
|
| 1468 | - 'title' => __('Missing Content', 'event_espresso'), |
|
| 1469 | - 'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1470 | - 'event_espresso'), |
|
| 1471 | - ); |
|
| 1472 | - $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1473 | - } |
|
| 1474 | - //let's setup the trigger |
|
| 1475 | - $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1476 | - $content = $content . $help_content; |
|
| 1477 | - if ($display) { |
|
| 1478 | - echo $content; |
|
| 1479 | - } else { |
|
| 1480 | - return $content; |
|
| 1481 | - } |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - |
|
| 1485 | - |
|
| 1486 | - /** |
|
| 1487 | - * _add_global_screen_options |
|
| 1488 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1489 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1490 | - * |
|
| 1491 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1492 | - * see also WP_Screen object documents... |
|
| 1493 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1494 | - * @abstract |
|
| 1495 | - * @access private |
|
| 1496 | - * @return void |
|
| 1497 | - */ |
|
| 1498 | - private function _add_global_screen_options() |
|
| 1499 | - { |
|
| 1500 | - } |
|
| 1501 | - |
|
| 1502 | - |
|
| 1503 | - |
|
| 1504 | - /** |
|
| 1505 | - * _add_global_feature_pointers |
|
| 1506 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1507 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1508 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1509 | - * |
|
| 1510 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see: |
|
| 1511 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1512 | - * @abstract |
|
| 1513 | - * @access protected |
|
| 1514 | - * @return void |
|
| 1515 | - */ |
|
| 1516 | - private function _add_global_feature_pointers() |
|
| 1517 | - { |
|
| 1518 | - } |
|
| 1519 | - |
|
| 1520 | - |
|
| 1521 | - |
|
| 1522 | - /** |
|
| 1523 | - * load_global_scripts_styles |
|
| 1524 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1525 | - * |
|
| 1526 | - * @return void |
|
| 1527 | - */ |
|
| 1528 | - public function load_global_scripts_styles() |
|
| 1529 | - { |
|
| 1530 | - /** STYLES **/ |
|
| 1531 | - // add debugging styles |
|
| 1532 | - if (WP_DEBUG) { |
|
| 1533 | - add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1534 | - } |
|
| 1535 | - // register all styles |
|
| 1536 | - wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1537 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1538 | - //helpers styles |
|
| 1539 | - wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1540 | - /** SCRIPTS **/ |
|
| 1541 | - //register all scripts |
|
| 1542 | - wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1543 | - wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
| 1544 | - wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true); |
|
| 1545 | - add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1546 | - //script for sorting tables |
|
| 1547 | - wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1548 | - //script for parsing uri's |
|
| 1549 | - wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1550 | - //and parsing associative serialized form elements |
|
| 1551 | - wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1552 | - //helpers scripts |
|
| 1553 | - wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1554 | - wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1555 | - wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 1556 | - wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true); |
|
| 1557 | - //google charts |
|
| 1558 | - wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false); |
|
| 1559 | - // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1560 | - wp_enqueue_style('ee-admin-css'); |
|
| 1561 | - wp_enqueue_script('ee_admin_js'); |
|
| 1562 | - wp_enqueue_script('ee-accounting'); |
|
| 1563 | - wp_enqueue_script('jquery-validate'); |
|
| 1564 | - //taking care of metaboxes |
|
| 1565 | - if ( |
|
| 1566 | - empty($this->_cpt_route) |
|
| 1567 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1568 | - ) { |
|
| 1569 | - wp_enqueue_script('dashboard'); |
|
| 1570 | - } |
|
| 1571 | - // LOCALIZED DATA |
|
| 1572 | - //localize script for ajax lazy loading |
|
| 1573 | - $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content')); |
|
| 1574 | - wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 1575 | - /** |
|
| 1576 | - * help tour stuff |
|
| 1577 | - */ |
|
| 1578 | - if ( ! empty($this->_help_tour)) { |
|
| 1579 | - //register the js for kicking things off |
|
| 1580 | - wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true); |
|
| 1581 | - //setup tours for the js tour object |
|
| 1582 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1583 | - $tours[] = array( |
|
| 1584 | - 'id' => $tour->get_slug(), |
|
| 1585 | - 'options' => $tour->get_options(), |
|
| 1586 | - ); |
|
| 1587 | - } |
|
| 1588 | - wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 1589 | - //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 1590 | - } |
|
| 1591 | - } |
|
| 1592 | - |
|
| 1593 | - |
|
| 1594 | - |
|
| 1595 | - /** |
|
| 1596 | - * admin_footer_scripts_eei18n_js_strings |
|
| 1597 | - * |
|
| 1598 | - * @access public |
|
| 1599 | - * @return void |
|
| 1600 | - */ |
|
| 1601 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 1602 | - { |
|
| 1603 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1604 | - EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso'); |
|
| 1605 | - EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso'); |
|
| 1606 | - EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso'); |
|
| 1607 | - EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso'); |
|
| 1608 | - EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso'); |
|
| 1609 | - EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso'); |
|
| 1610 | - EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso'); |
|
| 1611 | - EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso'); |
|
| 1612 | - EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso'); |
|
| 1613 | - EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso'); |
|
| 1614 | - EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso'); |
|
| 1615 | - EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso'); |
|
| 1616 | - EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso'); |
|
| 1617 | - EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso'); |
|
| 1618 | - EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso'); |
|
| 1619 | - EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso'); |
|
| 1620 | - EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso'); |
|
| 1621 | - EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso'); |
|
| 1622 | - EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso'); |
|
| 1623 | - EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso'); |
|
| 1624 | - EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso'); |
|
| 1625 | - EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso'); |
|
| 1626 | - EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso'); |
|
| 1627 | - EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso'); |
|
| 1628 | - EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso'); |
|
| 1629 | - EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso'); |
|
| 1630 | - EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso'); |
|
| 1631 | - EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso'); |
|
| 1632 | - EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso'); |
|
| 1633 | - EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso'); |
|
| 1634 | - EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso'); |
|
| 1635 | - EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso'); |
|
| 1636 | - EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso'); |
|
| 1637 | - EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso'); |
|
| 1638 | - EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso'); |
|
| 1639 | - EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso'); |
|
| 1640 | - EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso'); |
|
| 1641 | - EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso'); |
|
| 1642 | - EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso'); |
|
| 1643 | - } |
|
| 1644 | - |
|
| 1645 | - |
|
| 1646 | - |
|
| 1647 | - /** |
|
| 1648 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 1649 | - * |
|
| 1650 | - * @access public |
|
| 1651 | - * @return void |
|
| 1652 | - */ |
|
| 1653 | - public function add_xdebug_style() |
|
| 1654 | - { |
|
| 1655 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 1656 | - } |
|
| 1657 | - |
|
| 1658 | - |
|
| 1659 | - /************************/ |
|
| 1660 | - /** LIST TABLE METHODS **/ |
|
| 1661 | - /************************/ |
|
| 1662 | - /** |
|
| 1663 | - * this sets up the list table if the current view requires it. |
|
| 1664 | - * |
|
| 1665 | - * @access protected |
|
| 1666 | - * @return void |
|
| 1667 | - */ |
|
| 1668 | - protected function _set_list_table() |
|
| 1669 | - { |
|
| 1670 | - //first is this a list_table view? |
|
| 1671 | - if ( ! isset($this->_route_config['list_table'])) { |
|
| 1672 | - return; |
|
| 1673 | - } //not a list_table view so get out. |
|
| 1674 | - //list table functions are per view specific (because some admin pages might have more than one listtable!) |
|
| 1675 | - if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) { |
|
| 1676 | - //user error msg |
|
| 1677 | - $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso'); |
|
| 1678 | - //developer error msg |
|
| 1679 | - $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'), |
|
| 1680 | - $this->_req_action, '_set_list_table_views_' . $this->_req_action); |
|
| 1681 | - throw new EE_Error($error_msg); |
|
| 1682 | - } |
|
| 1683 | - //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 1684 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views); |
|
| 1685 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1686 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 1687 | - $this->_set_list_table_view(); |
|
| 1688 | - $this->_set_list_table_object(); |
|
| 1689 | - } |
|
| 1690 | - |
|
| 1691 | - |
|
| 1692 | - |
|
| 1693 | - /** |
|
| 1694 | - * set current view for List Table |
|
| 1695 | - * |
|
| 1696 | - * @access public |
|
| 1697 | - * @return array |
|
| 1698 | - */ |
|
| 1699 | - protected function _set_list_table_view() |
|
| 1700 | - { |
|
| 1701 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1702 | - // looking at active items or dumpster diving ? |
|
| 1703 | - if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 1704 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 1705 | - } else { |
|
| 1706 | - $this->_view = sanitize_key($this->_req_data['status']); |
|
| 1707 | - } |
|
| 1708 | - } |
|
| 1709 | - |
|
| 1710 | - |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * _set_list_table_object |
|
| 1714 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 1715 | - * |
|
| 1716 | - * @throws \EE_Error |
|
| 1717 | - */ |
|
| 1718 | - protected function _set_list_table_object() |
|
| 1719 | - { |
|
| 1720 | - if (isset($this->_route_config['list_table'])) { |
|
| 1721 | - if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 1722 | - throw new EE_Error( |
|
| 1723 | - sprintf( |
|
| 1724 | - __( |
|
| 1725 | - 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 1726 | - 'event_espresso' |
|
| 1727 | - ), |
|
| 1728 | - $this->_route_config['list_table'], |
|
| 1729 | - get_class($this) |
|
| 1730 | - ) |
|
| 1731 | - ); |
|
| 1732 | - } |
|
| 1733 | - $list_table = $this->_route_config['list_table']; |
|
| 1734 | - $this->_list_table_object = new $list_table($this); |
|
| 1735 | - } |
|
| 1736 | - } |
|
| 1737 | - |
|
| 1738 | - |
|
| 1739 | - |
|
| 1740 | - /** |
|
| 1741 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 1742 | - * |
|
| 1743 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 1744 | - * urls. The array should be indexed by the view it is being |
|
| 1745 | - * added to. |
|
| 1746 | - * @return array |
|
| 1747 | - */ |
|
| 1748 | - public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 1749 | - { |
|
| 1750 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1751 | - if (empty($this->_views)) { |
|
| 1752 | - $this->_views = array(); |
|
| 1753 | - } |
|
| 1754 | - // cycle thru views |
|
| 1755 | - foreach ($this->_views as $key => $view) { |
|
| 1756 | - $query_args = array(); |
|
| 1757 | - // check for current view |
|
| 1758 | - $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : ''; |
|
| 1759 | - $query_args['action'] = $this->_req_action; |
|
| 1760 | - $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 1761 | - $query_args['status'] = $view['slug']; |
|
| 1762 | - //merge any other arguments sent in. |
|
| 1763 | - if (isset($extra_query_args[$view['slug']])) { |
|
| 1764 | - $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 1765 | - } |
|
| 1766 | - $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1767 | - } |
|
| 1768 | - return $this->_views; |
|
| 1769 | - } |
|
| 1770 | - |
|
| 1771 | - |
|
| 1772 | - |
|
| 1773 | - /** |
|
| 1774 | - * _entries_per_page_dropdown |
|
| 1775 | - * generates a drop down box for selecting the number of visiable rows in an admin page list table |
|
| 1776 | - * |
|
| 1777 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it. |
|
| 1778 | - * @access protected |
|
| 1779 | - * @param int $max_entries total number of rows in the table |
|
| 1780 | - * @return string |
|
| 1781 | - */ |
|
| 1782 | - protected function _entries_per_page_dropdown($max_entries = false) |
|
| 1783 | - { |
|
| 1784 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1785 | - $values = array(10, 25, 50, 100); |
|
| 1786 | - $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 1787 | - if ($max_entries) { |
|
| 1788 | - $values[] = $max_entries; |
|
| 1789 | - sort($values); |
|
| 1790 | - } |
|
| 1791 | - $entries_per_page_dropdown = ' |
|
| 143 | + // yes / no array for admin form fields |
|
| 144 | + protected $_yes_no_values = array(); |
|
| 145 | + |
|
| 146 | + //some default things shared by all child classes |
|
| 147 | + protected $_default_espresso_metaboxes; |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * EE_Registry Object |
|
| 151 | + * |
|
| 152 | + * @var EE_Registry |
|
| 153 | + * @access protected |
|
| 154 | + */ |
|
| 155 | + protected $EE = null; |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 161 | + * |
|
| 162 | + * @var boolean |
|
| 163 | + */ |
|
| 164 | + protected $_is_caf = false; |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @Constructor |
|
| 170 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 171 | + * @access public |
|
| 172 | + */ |
|
| 173 | + public function __construct($routing = true) |
|
| 174 | + { |
|
| 175 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 176 | + $this->_is_caf = true; |
|
| 177 | + } |
|
| 178 | + $this->_yes_no_values = array( |
|
| 179 | + array('id' => true, 'text' => __('Yes', 'event_espresso')), |
|
| 180 | + array('id' => false, 'text' => __('No', 'event_espresso')), |
|
| 181 | + ); |
|
| 182 | + //set the _req_data property. |
|
| 183 | + $this->_req_data = array_merge($_GET, $_POST); |
|
| 184 | + //routing enabled? |
|
| 185 | + $this->_routing = $routing; |
|
| 186 | + //set initial page props (child method) |
|
| 187 | + $this->_init_page_props(); |
|
| 188 | + //set global defaults |
|
| 189 | + $this->_set_defaults(); |
|
| 190 | + //set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 191 | + $this->_global_ajax_hooks(); |
|
| 192 | + $this->_ajax_hooks(); |
|
| 193 | + //other_page_hooks have to be early too. |
|
| 194 | + $this->_do_other_page_hooks(); |
|
| 195 | + //This just allows us to have extending classes do something specific |
|
| 196 | + // before the parent constructor runs _page_setup(). |
|
| 197 | + if (method_exists($this, '_before_page_setup')) { |
|
| 198 | + $this->_before_page_setup(); |
|
| 199 | + } |
|
| 200 | + //set up page dependencies |
|
| 201 | + $this->_page_setup(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * _init_page_props |
|
| 208 | + * Child classes use to set at least the following properties: |
|
| 209 | + * $page_slug. |
|
| 210 | + * $page_label. |
|
| 211 | + * |
|
| 212 | + * @abstract |
|
| 213 | + * @access protected |
|
| 214 | + * @return void |
|
| 215 | + */ |
|
| 216 | + abstract protected function _init_page_props(); |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * _ajax_hooks |
|
| 222 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 223 | + * Note: within the ajax callback methods. |
|
| 224 | + * |
|
| 225 | + * @abstract |
|
| 226 | + * @access protected |
|
| 227 | + * @return void |
|
| 228 | + */ |
|
| 229 | + abstract protected function _ajax_hooks(); |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * _define_page_props |
|
| 235 | + * child classes define page properties in here. Must include at least: |
|
| 236 | + * $_admin_base_url = base_url for all admin pages |
|
| 237 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 238 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 239 | + * array( |
|
| 240 | + * 'buttons' => array( |
|
| 241 | + * 'add' => __('label for add new button'), |
|
| 242 | + * 'edit' => __('label for edit button'), |
|
| 243 | + * 'delete' => __('label for delete button') |
|
| 244 | + * ) |
|
| 245 | + * ) |
|
| 246 | + * |
|
| 247 | + * @abstract |
|
| 248 | + * @access protected |
|
| 249 | + * @return void |
|
| 250 | + */ |
|
| 251 | + abstract protected function _define_page_props(); |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * _set_page_routes |
|
| 257 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also have a 'default' |
|
| 258 | + * route. Here's the format |
|
| 259 | + * $this->_page_routes = array( |
|
| 260 | + * 'default' => array( |
|
| 261 | + * 'func' => '_default_method_handling_route', |
|
| 262 | + * 'args' => array('array','of','args'), |
|
| 263 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing) |
|
| 264 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after. The string you enter here should match the defined route reference for a headers sent route. |
|
| 265 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access this route. |
|
| 266 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks). |
|
| 267 | + * ), |
|
| 268 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method. |
|
| 269 | + * ) |
|
| 270 | + * ) |
|
| 271 | + * |
|
| 272 | + * @abstract |
|
| 273 | + * @access protected |
|
| 274 | + * @return void |
|
| 275 | + */ |
|
| 276 | + abstract protected function _set_page_routes(); |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * _set_page_config |
|
| 282 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page. |
|
| 283 | + * Format: |
|
| 284 | + * $this->_page_config = array( |
|
| 285 | + * 'default' => array( |
|
| 286 | + * 'labels' => array( |
|
| 287 | + * 'buttons' => array( |
|
| 288 | + * 'add' => __('label for adding item'), |
|
| 289 | + * 'edit' => __('label for editing item'), |
|
| 290 | + * 'delete' => __('label for deleting item') |
|
| 291 | + * ), |
|
| 292 | + * 'publishbox' => __('Localized Title for Publish metabox', 'event_espresso') |
|
| 293 | + * ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method |
|
| 294 | + * 'nav' => array( |
|
| 295 | + * 'label' => __('Label for Tab', 'event_espresso'). |
|
| 296 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 297 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 298 | + * 'order' => 10, //required to indicate tab position. |
|
| 299 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter. |
|
| 300 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 301 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages. |
|
| 302 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added later. We just use |
|
| 303 | + * this flag to make sure the necessary js gets enqueued on page load. |
|
| 304 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 305 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The array indicates the max number of columns (4) and the default number of columns on page load (2). There is an option |
|
| 306 | + * in the "screen_options" dropdown that is setup so users can pick what columns they want to display. |
|
| 307 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 308 | + * 'tab_id' => array( |
|
| 309 | + * 'title' => 'tab_title', |
|
| 310 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content. The fallback if it isn't present is to try a the callback. Filename should match a file in the admin |
|
| 311 | + * folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 312 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class |
|
| 313 | + * ), |
|
| 314 | + * 'tab2_id' => array( |
|
| 315 | + * 'title' => 'tab2 title', |
|
| 316 | + * 'filename' => 'file_name_2' |
|
| 317 | + * 'callback' => 'callback_method_for_content', |
|
| 318 | + * ), |
|
| 319 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 320 | + * 'help_tour' => array( |
|
| 321 | + * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 322 | + * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 323 | + * ), |
|
| 324 | + * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present). To remove the requirement for a nonce check when this route is visited just set |
|
| 325 | + * 'require_nonce' to FALSE |
|
| 326 | + * ) |
|
| 327 | + * ) |
|
| 328 | + * |
|
| 329 | + * @abstract |
|
| 330 | + * @access protected |
|
| 331 | + * @return void |
|
| 332 | + */ |
|
| 333 | + abstract protected function _set_page_config(); |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** end sample help_tour methods **/ |
|
| 340 | + /** |
|
| 341 | + * _add_screen_options |
|
| 342 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 343 | + * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view. |
|
| 344 | + * |
|
| 345 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 346 | + * see also WP_Screen object documents... |
|
| 347 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 348 | + * @abstract |
|
| 349 | + * @access protected |
|
| 350 | + * @return void |
|
| 351 | + */ |
|
| 352 | + abstract protected function _add_screen_options(); |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * _add_feature_pointers |
|
| 358 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 359 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view. |
|
| 360 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 361 | + * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see: |
|
| 362 | + * |
|
| 363 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 364 | + * @abstract |
|
| 365 | + * @access protected |
|
| 366 | + * @return void |
|
| 367 | + */ |
|
| 368 | + abstract protected function _add_feature_pointers(); |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * load_scripts_styles |
|
| 374 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific scripts/styles |
|
| 375 | + * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 376 | + * |
|
| 377 | + * @abstract |
|
| 378 | + * @access public |
|
| 379 | + * @return void |
|
| 380 | + */ |
|
| 381 | + abstract public function load_scripts_styles(); |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * admin_init |
|
| 387 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to all pages/views loaded by child class. |
|
| 388 | + * |
|
| 389 | + * @abstract |
|
| 390 | + * @access public |
|
| 391 | + * @return void |
|
| 392 | + */ |
|
| 393 | + abstract public function admin_init(); |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * admin_notices |
|
| 399 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class. |
|
| 400 | + * |
|
| 401 | + * @abstract |
|
| 402 | + * @access public |
|
| 403 | + * @return void |
|
| 404 | + */ |
|
| 405 | + abstract public function admin_notices(); |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * admin_footer_scripts |
|
| 411 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class. |
|
| 412 | + * |
|
| 413 | + * @access public |
|
| 414 | + * @return void |
|
| 415 | + */ |
|
| 416 | + abstract public function admin_footer_scripts(); |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * admin_footer |
|
| 422 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class. |
|
| 423 | + * |
|
| 424 | + * @access public |
|
| 425 | + * @return void |
|
| 426 | + */ |
|
| 427 | + public function admin_footer() |
|
| 428 | + { |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * _global_ajax_hooks |
|
| 435 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 436 | + * Note: within the ajax callback methods. |
|
| 437 | + * |
|
| 438 | + * @abstract |
|
| 439 | + * @access protected |
|
| 440 | + * @return void |
|
| 441 | + */ |
|
| 442 | + protected function _global_ajax_hooks() |
|
| 443 | + { |
|
| 444 | + //for lazy loading of metabox content |
|
| 445 | + add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + public function ajax_metabox_content() |
|
| 451 | + { |
|
| 452 | + $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 453 | + $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 454 | + self::cached_rss_display($contentid, $url); |
|
| 455 | + wp_die(); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * _page_setup |
|
| 462 | + * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested doesn't match the object. |
|
| 463 | + * |
|
| 464 | + * @final |
|
| 465 | + * @access protected |
|
| 466 | + * @return void |
|
| 467 | + */ |
|
| 468 | + final protected function _page_setup() |
|
| 469 | + { |
|
| 470 | + //requires? |
|
| 471 | + //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can. But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 472 | + add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 473 | + //next verify if we need to load anything... |
|
| 474 | + $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 475 | + $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this)))); |
|
| 476 | + global $ee_menu_slugs; |
|
| 477 | + $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 478 | + if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) { |
|
| 479 | + return; |
|
| 480 | + } |
|
| 481 | + // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
| 482 | + if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) { |
|
| 483 | + $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action']; |
|
| 484 | + } |
|
| 485 | + // then set blank or -1 action values to 'default' |
|
| 486 | + $this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default'; |
|
| 487 | + //if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 488 | + $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
|
| 489 | + //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 490 | + $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
|
| 491 | + $this->_current_view = $this->_req_action; |
|
| 492 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 493 | + $this->_define_page_props(); |
|
| 494 | + $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url); |
|
| 495 | + //default things |
|
| 496 | + $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box'); |
|
| 497 | + //set page configs |
|
| 498 | + $this->_set_page_routes(); |
|
| 499 | + $this->_set_page_config(); |
|
| 500 | + //let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 501 | + if (isset($this->_req_data['wp_referer'])) { |
|
| 502 | + $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 503 | + } |
|
| 504 | + //for caffeinated and other extended functionality. If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays |
|
| 505 | + if (method_exists($this, '_extend_page_config')) { |
|
| 506 | + $this->_extend_page_config(); |
|
| 507 | + } |
|
| 508 | + //for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays. |
|
| 509 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 510 | + $this->_extend_page_config_for_cpt(); |
|
| 511 | + } |
|
| 512 | + //filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 513 | + $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this); |
|
| 514 | + $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this); |
|
| 515 | + //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 516 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 517 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2); |
|
| 518 | + } |
|
| 519 | + //next route only if routing enabled |
|
| 520 | + if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 521 | + $this->_verify_routes(); |
|
| 522 | + //next let's just check user_access and kill if no access |
|
| 523 | + $this->check_user_access(); |
|
| 524 | + if ($this->_is_UI_request) { |
|
| 525 | + //admin_init stuff - global, all views for this page class, specific view |
|
| 526 | + add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 527 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 528 | + add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 529 | + } |
|
| 530 | + } else { |
|
| 531 | + //hijack regular WP loading and route admin request immediately |
|
| 532 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 533 | + $this->route_admin_request(); |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + |
|
| 540 | + /** |
|
| 541 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 542 | + * |
|
| 543 | + * @access private |
|
| 544 | + * @return void |
|
| 545 | + */ |
|
| 546 | + private function _do_other_page_hooks() |
|
| 547 | + { |
|
| 548 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 549 | + foreach ($registered_pages as $page) { |
|
| 550 | + //now let's setup the file name and class that should be present |
|
| 551 | + $classname = str_replace('.class.php', '', $page); |
|
| 552 | + //autoloaders should take care of loading file |
|
| 553 | + if ( ! class_exists($classname)) { |
|
| 554 | + $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page); |
|
| 555 | + $error_msg[] = $error_msg[0] |
|
| 556 | + . "\r\n" |
|
| 557 | + . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 558 | + 'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>'); |
|
| 559 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 560 | + } |
|
| 561 | + $a = new ReflectionClass($classname); |
|
| 562 | + //notice we are passing the instance of this class to the hook object. |
|
| 563 | + $hookobj[] = $a->newInstance($this); |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + public function load_page_dependencies() |
|
| 570 | + { |
|
| 571 | + try { |
|
| 572 | + $this->_load_page_dependencies(); |
|
| 573 | + } catch (EE_Error $e) { |
|
| 574 | + $e->get_error(); |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * load_page_dependencies |
|
| 582 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 583 | + * |
|
| 584 | + * @access public |
|
| 585 | + * @return void |
|
| 586 | + */ |
|
| 587 | + protected function _load_page_dependencies() |
|
| 588 | + { |
|
| 589 | + //let's set the current_screen and screen options to override what WP set |
|
| 590 | + $this->_current_screen = get_current_screen(); |
|
| 591 | + //load admin_notices - global, page class, and view specific |
|
| 592 | + add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 593 | + add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 594 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 595 | + add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 596 | + } |
|
| 597 | + //load network admin_notices - global, page class, and view specific |
|
| 598 | + add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 599 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 600 | + add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 601 | + } |
|
| 602 | + //this will save any per_page screen options if they are present |
|
| 603 | + $this->_set_per_page_screen_options(); |
|
| 604 | + //setup list table properties |
|
| 605 | + $this->_set_list_table(); |
|
| 606 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 607 | + $this->_add_registered_meta_boxes(); |
|
| 608 | + $this->_add_screen_columns(); |
|
| 609 | + //add screen options - global, page child class, and view specific |
|
| 610 | + $this->_add_global_screen_options(); |
|
| 611 | + $this->_add_screen_options(); |
|
| 612 | + if (method_exists($this, '_add_screen_options_' . $this->_current_view)) { |
|
| 613 | + call_user_func(array($this, '_add_screen_options_' . $this->_current_view)); |
|
| 614 | + } |
|
| 615 | + //add help tab(s) and tours- set via page_config and qtips. |
|
| 616 | + $this->_add_help_tour(); |
|
| 617 | + $this->_add_help_tabs(); |
|
| 618 | + $this->_add_qtips(); |
|
| 619 | + //add feature_pointers - global, page child class, and view specific |
|
| 620 | + $this->_add_feature_pointers(); |
|
| 621 | + $this->_add_global_feature_pointers(); |
|
| 622 | + if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) { |
|
| 623 | + call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view)); |
|
| 624 | + } |
|
| 625 | + //enqueue scripts/styles - global, page class, and view specific |
|
| 626 | + add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 627 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 628 | + if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) { |
|
| 629 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15); |
|
| 630 | + } |
|
| 631 | + add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 632 | + //admin_print_footer_scripts - global, page child class, and view specific. NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. In most cases that's doing_it_wrong(). But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these |
|
| 633 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 634 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 635 | + if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) { |
|
| 636 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101); |
|
| 637 | + } |
|
| 638 | + //admin footer scripts |
|
| 639 | + add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 640 | + add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 641 | + if (method_exists($this, 'admin_footer_' . $this->_current_view)) { |
|
| 642 | + add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101); |
|
| 643 | + } |
|
| 644 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 645 | + //targeted hook |
|
| 646 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action); |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * _set_defaults |
|
| 653 | + * This sets some global defaults for class properties. |
|
| 654 | + */ |
|
| 655 | + private function _set_defaults() |
|
| 656 | + { |
|
| 657 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 658 | + $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array(); |
|
| 659 | + $this->default_nav_tab_name = 'overview'; |
|
| 660 | + //init template args |
|
| 661 | + $this->_template_args = array( |
|
| 662 | + 'admin_page_header' => '', |
|
| 663 | + 'admin_page_content' => '', |
|
| 664 | + 'post_body_content' => '', |
|
| 665 | + 'before_list_table' => '', |
|
| 666 | + 'after_list_table' => '', |
|
| 667 | + ); |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + |
|
| 672 | + /** |
|
| 673 | + * route_admin_request |
|
| 674 | + * |
|
| 675 | + * @see _route_admin_request() |
|
| 676 | + * @access public |
|
| 677 | + * @return void|exception error |
|
| 678 | + */ |
|
| 679 | + public function route_admin_request() |
|
| 680 | + { |
|
| 681 | + try { |
|
| 682 | + $this->_route_admin_request(); |
|
| 683 | + } catch (EE_Error $e) { |
|
| 684 | + $e->get_error(); |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + |
|
| 690 | + public function set_wp_page_slug($wp_page_slug) |
|
| 691 | + { |
|
| 692 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 693 | + //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 694 | + if (is_network_admin()) { |
|
| 695 | + $this->_wp_page_slug .= '-network'; |
|
| 696 | + } |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * _verify_routes |
|
| 703 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so we know if we need to drop out. |
|
| 704 | + * |
|
| 705 | + * @access protected |
|
| 706 | + * @return void |
|
| 707 | + */ |
|
| 708 | + protected function _verify_routes() |
|
| 709 | + { |
|
| 710 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 711 | + if ( ! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 712 | + return false; |
|
| 713 | + } |
|
| 714 | + $this->_route = false; |
|
| 715 | + $func = false; |
|
| 716 | + $args = array(); |
|
| 717 | + // check that the page_routes array is not empty |
|
| 718 | + if (empty($this->_page_routes)) { |
|
| 719 | + // user error msg |
|
| 720 | + $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 721 | + // developer error msg |
|
| 722 | + $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso'); |
|
| 723 | + throw new EE_Error($error_msg); |
|
| 724 | + } |
|
| 725 | + // and that the requested page route exists |
|
| 726 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 727 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 728 | + $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array(); |
|
| 729 | + } else { |
|
| 730 | + // user error msg |
|
| 731 | + $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 732 | + // developer error msg |
|
| 733 | + $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action); |
|
| 734 | + throw new EE_Error($error_msg); |
|
| 735 | + } |
|
| 736 | + // and that a default route exists |
|
| 737 | + if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 738 | + // user error msg |
|
| 739 | + $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 740 | + // developer error msg |
|
| 741 | + $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso'); |
|
| 742 | + throw new EE_Error($error_msg); |
|
| 743 | + } |
|
| 744 | + //first lets' catch if the UI request has EVER been set. |
|
| 745 | + if ($this->_is_UI_request === null) { |
|
| 746 | + //lets set if this is a UI request or not. |
|
| 747 | + $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false; |
|
| 748 | + //wait a minute... we might have a noheader in the route array |
|
| 749 | + $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 750 | + } |
|
| 751 | + $this->_set_current_labels(); |
|
| 752 | + } |
|
| 753 | + |
|
| 754 | + |
|
| 755 | + |
|
| 756 | + /** |
|
| 757 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 758 | + * |
|
| 759 | + * @param string $route the route name we're verifying |
|
| 760 | + * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 761 | + */ |
|
| 762 | + protected function _verify_route($route) |
|
| 763 | + { |
|
| 764 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 765 | + return true; |
|
| 766 | + } else { |
|
| 767 | + // user error msg |
|
| 768 | + $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 769 | + // developer error msg |
|
| 770 | + $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route); |
|
| 771 | + throw new EE_Error($error_msg); |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * perform nonce verification |
|
| 779 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!) |
|
| 780 | + * |
|
| 781 | + * @param string $nonce The nonce sent |
|
| 782 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 783 | + * @return mixed (bool|die) |
|
| 784 | + */ |
|
| 785 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
| 786 | + { |
|
| 787 | + // verify nonce against expected value |
|
| 788 | + if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 789 | + // these are not the droids you are looking for !!! |
|
| 790 | + $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>'); |
|
| 791 | + if (WP_DEBUG) { |
|
| 792 | + $msg .= "\n " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__); |
|
| 793 | + } |
|
| 794 | + if ( ! defined('DOING_AJAX')) { |
|
| 795 | + wp_die($msg); |
|
| 796 | + } else { |
|
| 797 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 798 | + $this->_return_json(); |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + |
|
| 804 | + |
|
| 805 | + /** |
|
| 806 | + * _route_admin_request() |
|
| 807 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 808 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 809 | + * in the page routes and then will try to load the corresponding method. |
|
| 810 | + * |
|
| 811 | + * @access protected |
|
| 812 | + * @return void |
|
| 813 | + * @throws \EE_Error |
|
| 814 | + */ |
|
| 815 | + protected function _route_admin_request() |
|
| 816 | + { |
|
| 817 | + if ( ! $this->_is_UI_request) { |
|
| 818 | + $this->_verify_routes(); |
|
| 819 | + } |
|
| 820 | + $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 821 | + ? $this->_route_config['require_nonce'] |
|
| 822 | + : true; |
|
| 823 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 824 | + // set nonce from post data |
|
| 825 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 826 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 827 | + : ''; |
|
| 828 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 829 | + } |
|
| 830 | + //set the nav_tabs array but ONLY if this is UI_request |
|
| 831 | + if ($this->_is_UI_request) { |
|
| 832 | + $this->_set_nav_tabs(); |
|
| 833 | + } |
|
| 834 | + // grab callback function |
|
| 835 | + $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 836 | + // check if callback has args |
|
| 837 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 838 | + $error_msg = ''; |
|
| 839 | + // action right before calling route |
|
| 840 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 841 | + if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 842 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 843 | + } |
|
| 844 | + // right before calling the route, let's remove _wp_http_referer from the |
|
| 845 | + // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 846 | + $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI'])); |
|
| 847 | + if ( ! empty($func)) { |
|
| 848 | + if (is_array($func)) { |
|
| 849 | + list($class, $method) = $func; |
|
| 850 | + } else if (strpos($func, '::') !== false) { |
|
| 851 | + list($class, $method) = explode('::', $func); |
|
| 852 | + } else { |
|
| 853 | + $class = $this; |
|
| 854 | + $method = $func; |
|
| 855 | + } |
|
| 856 | + if ( ! (is_object($class) && $class === $this)) { |
|
| 857 | + // send along this admin page object for access by addons. |
|
| 858 | + $args['admin_page_object'] = $this; |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + if ( |
|
| 862 | + //is it a method on a class that doesn't work? |
|
| 863 | + ( |
|
| 864 | + ( |
|
| 865 | + method_exists($class, $method) |
|
| 866 | + && call_user_func_array(array($class, $method), $args) === false |
|
| 867 | + ) |
|
| 868 | + && ( |
|
| 869 | + //is it a standalone function that doesn't work? |
|
| 870 | + function_exists($method) |
|
| 871 | + && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false |
|
| 872 | + ) |
|
| 873 | + ) |
|
| 874 | + || ( |
|
| 875 | + //is it neither a class method NOR a standalone function? |
|
| 876 | + ! method_exists($class, $method) |
|
| 877 | + && ! function_exists($method) |
|
| 878 | + ) |
|
| 879 | + ) { |
|
| 880 | + // user error msg |
|
| 881 | + $error_msg = __('An error occurred. The requested page route could not be found.', 'event_espresso'); |
|
| 882 | + // developer error msg |
|
| 883 | + $error_msg .= '||'; |
|
| 884 | + $error_msg .= sprintf( |
|
| 885 | + __( |
|
| 886 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 887 | + 'event_espresso' |
|
| 888 | + ), |
|
| 889 | + $method |
|
| 890 | + ); |
|
| 891 | + } |
|
| 892 | + if ( ! empty($error_msg)) { |
|
| 893 | + throw new EE_Error($error_msg); |
|
| 894 | + } |
|
| 895 | + } |
|
| 896 | + //if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route. |
|
| 897 | + //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 898 | + if ($this->_is_UI_request === false |
|
| 899 | + && is_array($this->_route) |
|
| 900 | + && ! empty($this->_route['headers_sent_route']) |
|
| 901 | + ) { |
|
| 902 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 903 | + } |
|
| 904 | + } |
|
| 905 | + |
|
| 906 | + |
|
| 907 | + |
|
| 908 | + /** |
|
| 909 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 910 | + * route redirects to a headers route in its route config. |
|
| 911 | + * |
|
| 912 | + * @since 4.3.0 |
|
| 913 | + * @param string $new_route New (non header) route to redirect to. |
|
| 914 | + * @return void |
|
| 915 | + */ |
|
| 916 | + protected function _reset_routing_properties($new_route) |
|
| 917 | + { |
|
| 918 | + $this->_is_UI_request = true; |
|
| 919 | + //now we set the current route to whatever the headers_sent_route is set at |
|
| 920 | + $this->_req_data['action'] = $new_route; |
|
| 921 | + //rerun page setup |
|
| 922 | + $this->_page_setup(); |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + |
|
| 926 | + |
|
| 927 | + /** |
|
| 928 | + * _add_query_arg |
|
| 929 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 930 | + *(internally just uses EEH_URL's function with the same name) |
|
| 931 | + * |
|
| 932 | + * @access public |
|
| 933 | + * @param array $args |
|
| 934 | + * @param string $url |
|
| 935 | + * @param bool $sticky if true, then the existing Request params will be appended to the generated |
|
| 936 | + * url in an associative array indexed by the key 'wp_referer'; |
|
| 937 | + * Example usage: |
|
| 938 | + * If the current page is: |
|
| 939 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 940 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 941 | + * &_wpnonce=5467821 |
|
| 942 | + * and you call: |
|
| 943 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 944 | + * array( |
|
| 945 | + * 'action' => 'resend_something', |
|
| 946 | + * 'page=>espresso_registrations' |
|
| 947 | + * ), |
|
| 948 | + * $some_url, |
|
| 949 | + * true |
|
| 950 | + * ); |
|
| 951 | + * It will produce a url in this structure: |
|
| 952 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 953 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 954 | + * month_range]=March%202015 |
|
| 955 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 956 | + * @return string |
|
| 957 | + */ |
|
| 958 | + public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false) |
|
| 959 | + { |
|
| 960 | + //if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 961 | + if ($sticky) { |
|
| 962 | + $request = $_REQUEST; |
|
| 963 | + unset($request['_wp_http_referer']); |
|
| 964 | + unset($request['wp_referer']); |
|
| 965 | + foreach ($request as $key => $value) { |
|
| 966 | + //do not add nonces |
|
| 967 | + if (strpos($key, 'nonce') !== false) { |
|
| 968 | + continue; |
|
| 969 | + } |
|
| 970 | + $args['wp_referer[' . $key . ']'] = $value; |
|
| 971 | + } |
|
| 972 | + } |
|
| 973 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + /** |
|
| 979 | + * This returns a generated link that will load the related help tab. |
|
| 980 | + * |
|
| 981 | + * @param string $help_tab_id the id for the connected help tab |
|
| 982 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 983 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 984 | + * @uses EEH_Template::get_help_tab_link() |
|
| 985 | + * @return string generated link |
|
| 986 | + */ |
|
| 987 | + protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false) |
|
| 988 | + { |
|
| 989 | + return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text); |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + |
|
| 993 | + |
|
| 994 | + /** |
|
| 995 | + * _add_help_tabs |
|
| 996 | + * Note child classes define their help tabs within the page_config array. |
|
| 997 | + * |
|
| 998 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 999 | + * @access protected |
|
| 1000 | + * @return void |
|
| 1001 | + */ |
|
| 1002 | + protected function _add_help_tabs() |
|
| 1003 | + { |
|
| 1004 | + $tour_buttons = ''; |
|
| 1005 | + if (isset($this->_page_config[$this->_req_action])) { |
|
| 1006 | + $config = $this->_page_config[$this->_req_action]; |
|
| 1007 | + //is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1008 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1009 | + $tb = array(); |
|
| 1010 | + $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1011 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1012 | + //if this is the end tour then we don't need to setup a button |
|
| 1013 | + if ($tour instanceof EE_Help_Tour_final_stop) { |
|
| 1014 | + continue; |
|
| 1015 | + } |
|
| 1016 | + $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>'; |
|
| 1017 | + } |
|
| 1018 | + $tour_buttons .= implode('<br />', $tb); |
|
| 1019 | + $tour_buttons .= '</div></div>'; |
|
| 1020 | + } |
|
| 1021 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1022 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1023 | + //check that the callback given is valid |
|
| 1024 | + if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1025 | + throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1026 | + 'event_espresso'), $config['help_sidebar'], get_class($this))); |
|
| 1027 | + } |
|
| 1028 | + $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar']))); |
|
| 1029 | + $content .= $tour_buttons; //add help tour buttons. |
|
| 1030 | + //do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1031 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1032 | + } |
|
| 1033 | + //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar. |
|
| 1034 | + if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1035 | + $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1036 | + } |
|
| 1037 | + //handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1038 | + if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1039 | + $_ht['id'] = $this->page_slug; |
|
| 1040 | + $_ht['title'] = __('Help Tours', 'event_espresso'); |
|
| 1041 | + $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>'; |
|
| 1042 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1043 | + }/**/ |
|
| 1044 | + if ( ! isset($config['help_tabs'])) { |
|
| 1045 | + return; |
|
| 1046 | + } //no help tabs for this route |
|
| 1047 | + foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1048 | + //we're here so there ARE help tabs! |
|
| 1049 | + //make sure we've got what we need |
|
| 1050 | + if ( ! isset($cfg['title'])) { |
|
| 1051 | + throw new EE_Error(__('The _page_config array is not set up properly for help tabs. It is missing a title', 'event_espresso')); |
|
| 1052 | + } |
|
| 1053 | + if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1054 | + throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1055 | + 'event_espresso')); |
|
| 1056 | + } |
|
| 1057 | + //first priority goes to content. |
|
| 1058 | + if ( ! empty($cfg['content'])) { |
|
| 1059 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1060 | + //second priority goes to filename |
|
| 1061 | + } else if ( ! empty($cfg['filename'])) { |
|
| 1062 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1063 | + //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1064 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path; |
|
| 1065 | + //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1066 | + if ( ! is_readable($file_path) && ! isset($cfg['callback'])) { |
|
| 1067 | + EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1068 | + 'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__); |
|
| 1069 | + return; |
|
| 1070 | + } |
|
| 1071 | + $template_args['admin_page_obj'] = $this; |
|
| 1072 | + $content = EEH_Template::display_template($file_path, $template_args, true); |
|
| 1073 | + } else { |
|
| 1074 | + $content = ''; |
|
| 1075 | + } |
|
| 1076 | + //check if callback is valid |
|
| 1077 | + if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) { |
|
| 1078 | + EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1079 | + 'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__); |
|
| 1080 | + return; |
|
| 1081 | + } |
|
| 1082 | + //setup config array for help tab method |
|
| 1083 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1084 | + $_ht = array( |
|
| 1085 | + 'id' => $id, |
|
| 1086 | + 'title' => $cfg['title'], |
|
| 1087 | + 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1088 | + 'content' => $content, |
|
| 1089 | + ); |
|
| 1090 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1091 | + } |
|
| 1092 | + } |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + |
|
| 1096 | + |
|
| 1097 | + /** |
|
| 1098 | + * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is an array with properties for setting up usage of the joyride plugin |
|
| 1099 | + * |
|
| 1100 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1101 | + * @see instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments |
|
| 1102 | + * @access protected |
|
| 1103 | + * @return void |
|
| 1104 | + */ |
|
| 1105 | + protected function _add_help_tour() |
|
| 1106 | + { |
|
| 1107 | + $tours = array(); |
|
| 1108 | + $this->_help_tour = array(); |
|
| 1109 | + //exit early if help tours are turned off globally |
|
| 1110 | + if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) { |
|
| 1111 | + return; |
|
| 1112 | + } |
|
| 1113 | + //loop through _page_config to find any help_tour defined |
|
| 1114 | + foreach ($this->_page_config as $route => $config) { |
|
| 1115 | + //we're only going to set things up for this route |
|
| 1116 | + if ($route !== $this->_req_action) { |
|
| 1117 | + continue; |
|
| 1118 | + } |
|
| 1119 | + if (isset($config['help_tour'])) { |
|
| 1120 | + foreach ($config['help_tour'] as $tour) { |
|
| 1121 | + $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1122 | + //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent |
|
| 1123 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path; |
|
| 1124 | + //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1125 | + if ( ! is_readable($file_path)) { |
|
| 1126 | + EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'), |
|
| 1127 | + $file_path, $tour), __FILE__, __FUNCTION__, __LINE__); |
|
| 1128 | + return; |
|
| 1129 | + } |
|
| 1130 | + require_once $file_path; |
|
| 1131 | + if ( ! class_exists($tour)) { |
|
| 1132 | + $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour); |
|
| 1133 | + $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1134 | + 'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this)); |
|
| 1135 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 1136 | + } |
|
| 1137 | + $a = new ReflectionClass($tour); |
|
| 1138 | + $tour_obj = $a->newInstance($this->_is_caf); |
|
| 1139 | + $tours[] = $tour_obj; |
|
| 1140 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1141 | + } |
|
| 1142 | + //let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1143 | + $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1144 | + $tours[] = $end_stop_tour; |
|
| 1145 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1146 | + } |
|
| 1147 | + } |
|
| 1148 | + if ( ! empty($tours)) { |
|
| 1149 | + $this->_help_tour['tours'] = $tours; |
|
| 1150 | + } |
|
| 1151 | + //thats it! Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically. |
|
| 1152 | + } |
|
| 1153 | + |
|
| 1154 | + |
|
| 1155 | + |
|
| 1156 | + /** |
|
| 1157 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1158 | + * |
|
| 1159 | + * @access protected |
|
| 1160 | + * @return void |
|
| 1161 | + */ |
|
| 1162 | + protected function _add_qtips() |
|
| 1163 | + { |
|
| 1164 | + if (isset($this->_route_config['qtips'])) { |
|
| 1165 | + $qtips = (array)$this->_route_config['qtips']; |
|
| 1166 | + //load qtip loader |
|
| 1167 | + $path = array( |
|
| 1168 | + $this->_get_dir() . '/qtips/', |
|
| 1169 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1170 | + ); |
|
| 1171 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1172 | + } |
|
| 1173 | + } |
|
| 1174 | + |
|
| 1175 | + |
|
| 1176 | + |
|
| 1177 | + /** |
|
| 1178 | + * _set_nav_tabs |
|
| 1179 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly. |
|
| 1180 | + * |
|
| 1181 | + * @access protected |
|
| 1182 | + * @return void |
|
| 1183 | + */ |
|
| 1184 | + protected function _set_nav_tabs() |
|
| 1185 | + { |
|
| 1186 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1187 | + $i = 0; |
|
| 1188 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1189 | + if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) { |
|
| 1190 | + continue; |
|
| 1191 | + } //no nav tab for this config |
|
| 1192 | + //check for persistent flag |
|
| 1193 | + if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) { |
|
| 1194 | + continue; |
|
| 1195 | + } //nav tab is only to appear when route requested. |
|
| 1196 | + if ( ! $this->check_user_access($slug, true)) { |
|
| 1197 | + continue; |
|
| 1198 | + } //no nav tab becasue current user does not have access. |
|
| 1199 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1200 | + $this->_nav_tabs[$slug] = array( |
|
| 1201 | + 'url' => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url), |
|
| 1202 | + 'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)), |
|
| 1203 | + 'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1204 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1205 | + ); |
|
| 1206 | + $i++; |
|
| 1207 | + } |
|
| 1208 | + //if $this->_nav_tabs is empty then lets set the default |
|
| 1209 | + if (empty($this->_nav_tabs)) { |
|
| 1210 | + $this->_nav_tabs[$this->default_nav_tab_name] = array( |
|
| 1211 | + 'url' => $this->admin_base_url, |
|
| 1212 | + 'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)), |
|
| 1213 | + 'css_class' => 'nav-tab-active', |
|
| 1214 | + 'order' => 10, |
|
| 1215 | + ); |
|
| 1216 | + } |
|
| 1217 | + //now let's sort the tabs according to order |
|
| 1218 | + usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + |
|
| 1222 | + |
|
| 1223 | + /** |
|
| 1224 | + * _set_current_labels |
|
| 1225 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array |
|
| 1226 | + * |
|
| 1227 | + * @access private |
|
| 1228 | + * @return void |
|
| 1229 | + */ |
|
| 1230 | + private function _set_current_labels() |
|
| 1231 | + { |
|
| 1232 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1233 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1234 | + if (is_array($text)) { |
|
| 1235 | + foreach ($text as $sublabel => $subtext) { |
|
| 1236 | + $this->_labels[$label][$sublabel] = $subtext; |
|
| 1237 | + } |
|
| 1238 | + } else { |
|
| 1239 | + $this->_labels[$label] = $text; |
|
| 1240 | + } |
|
| 1241 | + } |
|
| 1242 | + } |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + |
|
| 1246 | + |
|
| 1247 | + /** |
|
| 1248 | + * verifies user access for this admin page |
|
| 1249 | + * |
|
| 1250 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1251 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just return false if verify fail. |
|
| 1252 | + * @return BOOL|wp_die() |
|
| 1253 | + */ |
|
| 1254 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1255 | + { |
|
| 1256 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1257 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1258 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1259 | + ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1260 | + if (empty($capability) && empty($route_to_check)) { |
|
| 1261 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability']; |
|
| 1262 | + } else { |
|
| 1263 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1264 | + } |
|
| 1265 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1266 | + if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) { |
|
| 1267 | + if ($verify_only) { |
|
| 1268 | + return false; |
|
| 1269 | + } else { |
|
| 1270 | + if ( is_user_logged_in() ) { |
|
| 1271 | + wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1272 | + } else { |
|
| 1273 | + return false; |
|
| 1274 | + } |
|
| 1275 | + } |
|
| 1276 | + } |
|
| 1277 | + return true; |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + |
|
| 1281 | + |
|
| 1282 | + /** |
|
| 1283 | + * admin_init_global |
|
| 1284 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1285 | + * This method executes for ALL EE Admin pages. |
|
| 1286 | + * |
|
| 1287 | + * @access public |
|
| 1288 | + * @return void |
|
| 1289 | + */ |
|
| 1290 | + public function admin_init_global() |
|
| 1291 | + { |
|
| 1292 | + } |
|
| 1293 | + |
|
| 1294 | + |
|
| 1295 | + |
|
| 1296 | + /** |
|
| 1297 | + * wp_loaded_global |
|
| 1298 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an EE_Admin page and will execute on every EE Admin Page load |
|
| 1299 | + * |
|
| 1300 | + * @access public |
|
| 1301 | + * @return void |
|
| 1302 | + */ |
|
| 1303 | + public function wp_loaded() |
|
| 1304 | + { |
|
| 1305 | + } |
|
| 1306 | + |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * admin_notices |
|
| 1311 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages. |
|
| 1312 | + * |
|
| 1313 | + * @access public |
|
| 1314 | + * @return void |
|
| 1315 | + */ |
|
| 1316 | + public function admin_notices_global() |
|
| 1317 | + { |
|
| 1318 | + $this->_display_no_javascript_warning(); |
|
| 1319 | + $this->_display_espresso_notices(); |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + |
|
| 1323 | + |
|
| 1324 | + public function network_admin_notices_global() |
|
| 1325 | + { |
|
| 1326 | + $this->_display_no_javascript_warning(); |
|
| 1327 | + $this->_display_espresso_notices(); |
|
| 1328 | + } |
|
| 1329 | + |
|
| 1330 | + |
|
| 1331 | + |
|
| 1332 | + /** |
|
| 1333 | + * admin_footer_scripts_global |
|
| 1334 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages. |
|
| 1335 | + * |
|
| 1336 | + * @access public |
|
| 1337 | + * @return void |
|
| 1338 | + */ |
|
| 1339 | + public function admin_footer_scripts_global() |
|
| 1340 | + { |
|
| 1341 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1342 | + $this->_add_admin_page_overlay(); |
|
| 1343 | + //if metaboxes are present we need to add the nonce field |
|
| 1344 | + if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) { |
|
| 1345 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1346 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1347 | + } |
|
| 1348 | + } |
|
| 1349 | + |
|
| 1350 | + |
|
| 1351 | + |
|
| 1352 | + /** |
|
| 1353 | + * admin_footer_global |
|
| 1354 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages. |
|
| 1355 | + * |
|
| 1356 | + * @access public |
|
| 1357 | + * @return void |
|
| 1358 | + */ |
|
| 1359 | + public function admin_footer_global() |
|
| 1360 | + { |
|
| 1361 | + //dialog container for dialog helper |
|
| 1362 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1363 | + $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1364 | + $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1365 | + $d_cont .= '</div>'; |
|
| 1366 | + echo $d_cont; |
|
| 1367 | + //help tour stuff? |
|
| 1368 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1369 | + echo implode('<br />', $this->_help_tour[$this->_req_action]); |
|
| 1370 | + } |
|
| 1371 | + //current set timezone for timezone js |
|
| 1372 | + echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1373 | + } |
|
| 1374 | + |
|
| 1375 | + |
|
| 1376 | + |
|
| 1377 | + /** |
|
| 1378 | + * This function sees if there is a method for help popup content existing for the given route. If there is then we'll use the retrieved array to output the content using the template. |
|
| 1379 | + * For child classes: |
|
| 1380 | + * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for |
|
| 1381 | + * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content for the |
|
| 1382 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1383 | + * 'help_trigger_id' => array( |
|
| 1384 | + * 'title' => __('localized title for popup', 'event_espresso'), |
|
| 1385 | + * 'content' => __('localized content for popup', 'event_espresso') |
|
| 1386 | + * ) |
|
| 1387 | + * ); |
|
| 1388 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1389 | + * |
|
| 1390 | + * @access protected |
|
| 1391 | + * @return string content |
|
| 1392 | + */ |
|
| 1393 | + protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1394 | + { |
|
| 1395 | + $content = ''; |
|
| 1396 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1397 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php'; |
|
| 1398 | + //loop through the array and setup content |
|
| 1399 | + foreach ($help_array as $trigger => $help) { |
|
| 1400 | + //make sure the array is setup properly |
|
| 1401 | + if ( ! isset($help['title']) || ! isset($help['content'])) { |
|
| 1402 | + throw new EE_Error(__('Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1403 | + 'event_espresso')); |
|
| 1404 | + } |
|
| 1405 | + //we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1406 | + $template_args = array( |
|
| 1407 | + 'help_popup_id' => $trigger, |
|
| 1408 | + 'help_popup_title' => $help['title'], |
|
| 1409 | + 'help_popup_content' => $help['content'], |
|
| 1410 | + ); |
|
| 1411 | + $content .= EEH_Template::display_template($template_path, $template_args, true); |
|
| 1412 | + } |
|
| 1413 | + if ($display) { |
|
| 1414 | + echo $content; |
|
| 1415 | + } else { |
|
| 1416 | + return $content; |
|
| 1417 | + } |
|
| 1418 | + } |
|
| 1419 | + |
|
| 1420 | + |
|
| 1421 | + |
|
| 1422 | + /** |
|
| 1423 | + * All this does is retrive the help content array if set by the EE_Admin_Page child |
|
| 1424 | + * |
|
| 1425 | + * @access private |
|
| 1426 | + * @return array properly formatted array for help popup content |
|
| 1427 | + */ |
|
| 1428 | + private function _get_help_content() |
|
| 1429 | + { |
|
| 1430 | + //what is the method we're looking for? |
|
| 1431 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1432 | + //if method doesn't exist let's get out. |
|
| 1433 | + if ( ! method_exists($this, $method_name)) { |
|
| 1434 | + return array(); |
|
| 1435 | + } |
|
| 1436 | + //k we're good to go let's retrieve the help array |
|
| 1437 | + $help_array = call_user_func(array($this, $method_name)); |
|
| 1438 | + //make sure we've got an array! |
|
| 1439 | + if ( ! is_array($help_array)) { |
|
| 1440 | + throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso')); |
|
| 1441 | + } |
|
| 1442 | + return $help_array; |
|
| 1443 | + } |
|
| 1444 | + |
|
| 1445 | + |
|
| 1446 | + |
|
| 1447 | + /** |
|
| 1448 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1449 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1450 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1451 | + * |
|
| 1452 | + * @access protected |
|
| 1453 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1454 | + * @param boolean $display if false then we return the trigger string |
|
| 1455 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1456 | + * @return string |
|
| 1457 | + */ |
|
| 1458 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1459 | + { |
|
| 1460 | + if (defined('DOING_AJAX')) { |
|
| 1461 | + return; |
|
| 1462 | + } |
|
| 1463 | + //let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1464 | + $help_array = $this->_get_help_content(); |
|
| 1465 | + $help_content = ''; |
|
| 1466 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1467 | + $help_array[$trigger_id] = array( |
|
| 1468 | + 'title' => __('Missing Content', 'event_espresso'), |
|
| 1469 | + 'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1470 | + 'event_espresso'), |
|
| 1471 | + ); |
|
| 1472 | + $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1473 | + } |
|
| 1474 | + //let's setup the trigger |
|
| 1475 | + $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1476 | + $content = $content . $help_content; |
|
| 1477 | + if ($display) { |
|
| 1478 | + echo $content; |
|
| 1479 | + } else { |
|
| 1480 | + return $content; |
|
| 1481 | + } |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + |
|
| 1485 | + |
|
| 1486 | + /** |
|
| 1487 | + * _add_global_screen_options |
|
| 1488 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1489 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1490 | + * |
|
| 1491 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1492 | + * see also WP_Screen object documents... |
|
| 1493 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1494 | + * @abstract |
|
| 1495 | + * @access private |
|
| 1496 | + * @return void |
|
| 1497 | + */ |
|
| 1498 | + private function _add_global_screen_options() |
|
| 1499 | + { |
|
| 1500 | + } |
|
| 1501 | + |
|
| 1502 | + |
|
| 1503 | + |
|
| 1504 | + /** |
|
| 1505 | + * _add_global_feature_pointers |
|
| 1506 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1507 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1508 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1509 | + * |
|
| 1510 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see: |
|
| 1511 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1512 | + * @abstract |
|
| 1513 | + * @access protected |
|
| 1514 | + * @return void |
|
| 1515 | + */ |
|
| 1516 | + private function _add_global_feature_pointers() |
|
| 1517 | + { |
|
| 1518 | + } |
|
| 1519 | + |
|
| 1520 | + |
|
| 1521 | + |
|
| 1522 | + /** |
|
| 1523 | + * load_global_scripts_styles |
|
| 1524 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1525 | + * |
|
| 1526 | + * @return void |
|
| 1527 | + */ |
|
| 1528 | + public function load_global_scripts_styles() |
|
| 1529 | + { |
|
| 1530 | + /** STYLES **/ |
|
| 1531 | + // add debugging styles |
|
| 1532 | + if (WP_DEBUG) { |
|
| 1533 | + add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1534 | + } |
|
| 1535 | + // register all styles |
|
| 1536 | + wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1537 | + wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1538 | + //helpers styles |
|
| 1539 | + wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1540 | + /** SCRIPTS **/ |
|
| 1541 | + //register all scripts |
|
| 1542 | + wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1543 | + wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
| 1544 | + wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true); |
|
| 1545 | + add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1546 | + //script for sorting tables |
|
| 1547 | + wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1548 | + //script for parsing uri's |
|
| 1549 | + wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1550 | + //and parsing associative serialized form elements |
|
| 1551 | + wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1552 | + //helpers scripts |
|
| 1553 | + wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1554 | + wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1555 | + wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 1556 | + wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true); |
|
| 1557 | + //google charts |
|
| 1558 | + wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false); |
|
| 1559 | + // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1560 | + wp_enqueue_style('ee-admin-css'); |
|
| 1561 | + wp_enqueue_script('ee_admin_js'); |
|
| 1562 | + wp_enqueue_script('ee-accounting'); |
|
| 1563 | + wp_enqueue_script('jquery-validate'); |
|
| 1564 | + //taking care of metaboxes |
|
| 1565 | + if ( |
|
| 1566 | + empty($this->_cpt_route) |
|
| 1567 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1568 | + ) { |
|
| 1569 | + wp_enqueue_script('dashboard'); |
|
| 1570 | + } |
|
| 1571 | + // LOCALIZED DATA |
|
| 1572 | + //localize script for ajax lazy loading |
|
| 1573 | + $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content')); |
|
| 1574 | + wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 1575 | + /** |
|
| 1576 | + * help tour stuff |
|
| 1577 | + */ |
|
| 1578 | + if ( ! empty($this->_help_tour)) { |
|
| 1579 | + //register the js for kicking things off |
|
| 1580 | + wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true); |
|
| 1581 | + //setup tours for the js tour object |
|
| 1582 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1583 | + $tours[] = array( |
|
| 1584 | + 'id' => $tour->get_slug(), |
|
| 1585 | + 'options' => $tour->get_options(), |
|
| 1586 | + ); |
|
| 1587 | + } |
|
| 1588 | + wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 1589 | + //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 1590 | + } |
|
| 1591 | + } |
|
| 1592 | + |
|
| 1593 | + |
|
| 1594 | + |
|
| 1595 | + /** |
|
| 1596 | + * admin_footer_scripts_eei18n_js_strings |
|
| 1597 | + * |
|
| 1598 | + * @access public |
|
| 1599 | + * @return void |
|
| 1600 | + */ |
|
| 1601 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 1602 | + { |
|
| 1603 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1604 | + EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso'); |
|
| 1605 | + EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso'); |
|
| 1606 | + EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso'); |
|
| 1607 | + EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso'); |
|
| 1608 | + EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso'); |
|
| 1609 | + EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso'); |
|
| 1610 | + EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso'); |
|
| 1611 | + EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso'); |
|
| 1612 | + EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso'); |
|
| 1613 | + EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso'); |
|
| 1614 | + EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso'); |
|
| 1615 | + EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso'); |
|
| 1616 | + EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso'); |
|
| 1617 | + EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso'); |
|
| 1618 | + EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso'); |
|
| 1619 | + EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso'); |
|
| 1620 | + EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso'); |
|
| 1621 | + EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso'); |
|
| 1622 | + EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso'); |
|
| 1623 | + EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso'); |
|
| 1624 | + EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso'); |
|
| 1625 | + EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso'); |
|
| 1626 | + EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso'); |
|
| 1627 | + EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso'); |
|
| 1628 | + EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso'); |
|
| 1629 | + EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso'); |
|
| 1630 | + EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso'); |
|
| 1631 | + EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso'); |
|
| 1632 | + EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso'); |
|
| 1633 | + EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso'); |
|
| 1634 | + EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso'); |
|
| 1635 | + EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso'); |
|
| 1636 | + EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso'); |
|
| 1637 | + EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso'); |
|
| 1638 | + EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso'); |
|
| 1639 | + EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso'); |
|
| 1640 | + EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso'); |
|
| 1641 | + EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso'); |
|
| 1642 | + EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso'); |
|
| 1643 | + } |
|
| 1644 | + |
|
| 1645 | + |
|
| 1646 | + |
|
| 1647 | + /** |
|
| 1648 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 1649 | + * |
|
| 1650 | + * @access public |
|
| 1651 | + * @return void |
|
| 1652 | + */ |
|
| 1653 | + public function add_xdebug_style() |
|
| 1654 | + { |
|
| 1655 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 1656 | + } |
|
| 1657 | + |
|
| 1658 | + |
|
| 1659 | + /************************/ |
|
| 1660 | + /** LIST TABLE METHODS **/ |
|
| 1661 | + /************************/ |
|
| 1662 | + /** |
|
| 1663 | + * this sets up the list table if the current view requires it. |
|
| 1664 | + * |
|
| 1665 | + * @access protected |
|
| 1666 | + * @return void |
|
| 1667 | + */ |
|
| 1668 | + protected function _set_list_table() |
|
| 1669 | + { |
|
| 1670 | + //first is this a list_table view? |
|
| 1671 | + if ( ! isset($this->_route_config['list_table'])) { |
|
| 1672 | + return; |
|
| 1673 | + } //not a list_table view so get out. |
|
| 1674 | + //list table functions are per view specific (because some admin pages might have more than one listtable!) |
|
| 1675 | + if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) { |
|
| 1676 | + //user error msg |
|
| 1677 | + $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso'); |
|
| 1678 | + //developer error msg |
|
| 1679 | + $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'), |
|
| 1680 | + $this->_req_action, '_set_list_table_views_' . $this->_req_action); |
|
| 1681 | + throw new EE_Error($error_msg); |
|
| 1682 | + } |
|
| 1683 | + //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 1684 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views); |
|
| 1685 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1686 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 1687 | + $this->_set_list_table_view(); |
|
| 1688 | + $this->_set_list_table_object(); |
|
| 1689 | + } |
|
| 1690 | + |
|
| 1691 | + |
|
| 1692 | + |
|
| 1693 | + /** |
|
| 1694 | + * set current view for List Table |
|
| 1695 | + * |
|
| 1696 | + * @access public |
|
| 1697 | + * @return array |
|
| 1698 | + */ |
|
| 1699 | + protected function _set_list_table_view() |
|
| 1700 | + { |
|
| 1701 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1702 | + // looking at active items or dumpster diving ? |
|
| 1703 | + if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 1704 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 1705 | + } else { |
|
| 1706 | + $this->_view = sanitize_key($this->_req_data['status']); |
|
| 1707 | + } |
|
| 1708 | + } |
|
| 1709 | + |
|
| 1710 | + |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * _set_list_table_object |
|
| 1714 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 1715 | + * |
|
| 1716 | + * @throws \EE_Error |
|
| 1717 | + */ |
|
| 1718 | + protected function _set_list_table_object() |
|
| 1719 | + { |
|
| 1720 | + if (isset($this->_route_config['list_table'])) { |
|
| 1721 | + if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 1722 | + throw new EE_Error( |
|
| 1723 | + sprintf( |
|
| 1724 | + __( |
|
| 1725 | + 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 1726 | + 'event_espresso' |
|
| 1727 | + ), |
|
| 1728 | + $this->_route_config['list_table'], |
|
| 1729 | + get_class($this) |
|
| 1730 | + ) |
|
| 1731 | + ); |
|
| 1732 | + } |
|
| 1733 | + $list_table = $this->_route_config['list_table']; |
|
| 1734 | + $this->_list_table_object = new $list_table($this); |
|
| 1735 | + } |
|
| 1736 | + } |
|
| 1737 | + |
|
| 1738 | + |
|
| 1739 | + |
|
| 1740 | + /** |
|
| 1741 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 1742 | + * |
|
| 1743 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 1744 | + * urls. The array should be indexed by the view it is being |
|
| 1745 | + * added to. |
|
| 1746 | + * @return array |
|
| 1747 | + */ |
|
| 1748 | + public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 1749 | + { |
|
| 1750 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1751 | + if (empty($this->_views)) { |
|
| 1752 | + $this->_views = array(); |
|
| 1753 | + } |
|
| 1754 | + // cycle thru views |
|
| 1755 | + foreach ($this->_views as $key => $view) { |
|
| 1756 | + $query_args = array(); |
|
| 1757 | + // check for current view |
|
| 1758 | + $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : ''; |
|
| 1759 | + $query_args['action'] = $this->_req_action; |
|
| 1760 | + $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 1761 | + $query_args['status'] = $view['slug']; |
|
| 1762 | + //merge any other arguments sent in. |
|
| 1763 | + if (isset($extra_query_args[$view['slug']])) { |
|
| 1764 | + $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 1765 | + } |
|
| 1766 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1767 | + } |
|
| 1768 | + return $this->_views; |
|
| 1769 | + } |
|
| 1770 | + |
|
| 1771 | + |
|
| 1772 | + |
|
| 1773 | + /** |
|
| 1774 | + * _entries_per_page_dropdown |
|
| 1775 | + * generates a drop down box for selecting the number of visiable rows in an admin page list table |
|
| 1776 | + * |
|
| 1777 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it. |
|
| 1778 | + * @access protected |
|
| 1779 | + * @param int $max_entries total number of rows in the table |
|
| 1780 | + * @return string |
|
| 1781 | + */ |
|
| 1782 | + protected function _entries_per_page_dropdown($max_entries = false) |
|
| 1783 | + { |
|
| 1784 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1785 | + $values = array(10, 25, 50, 100); |
|
| 1786 | + $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 1787 | + if ($max_entries) { |
|
| 1788 | + $values[] = $max_entries; |
|
| 1789 | + sort($values); |
|
| 1790 | + } |
|
| 1791 | + $entries_per_page_dropdown = ' |
|
| 1792 | 1792 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 1793 | 1793 | <label class="hide-if-no-js"> |
| 1794 | 1794 | Show |
| 1795 | 1795 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 1796 | - foreach ($values as $value) { |
|
| 1797 | - if ($value < $max_entries) { |
|
| 1798 | - $selected = $value == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1799 | - $entries_per_page_dropdown .= ' |
|
| 1796 | + foreach ($values as $value) { |
|
| 1797 | + if ($value < $max_entries) { |
|
| 1798 | + $selected = $value == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1799 | + $entries_per_page_dropdown .= ' |
|
| 1800 | 1800 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 1801 | - } |
|
| 1802 | - } |
|
| 1803 | - $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1804 | - $entries_per_page_dropdown .= ' |
|
| 1801 | + } |
|
| 1802 | + } |
|
| 1803 | + $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1804 | + $entries_per_page_dropdown .= ' |
|
| 1805 | 1805 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 1806 | - $entries_per_page_dropdown .= ' |
|
| 1806 | + $entries_per_page_dropdown .= ' |
|
| 1807 | 1807 | </select> |
| 1808 | 1808 | entries |
| 1809 | 1809 | </label> |
| 1810 | 1810 | <input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" > |
| 1811 | 1811 | </div> |
| 1812 | 1812 | '; |
| 1813 | - return $entries_per_page_dropdown; |
|
| 1814 | - } |
|
| 1815 | - |
|
| 1816 | - |
|
| 1817 | - |
|
| 1818 | - /** |
|
| 1819 | - * _set_search_attributes |
|
| 1820 | - * |
|
| 1821 | - * @access protected |
|
| 1822 | - * @return void |
|
| 1823 | - */ |
|
| 1824 | - public function _set_search_attributes() |
|
| 1825 | - { |
|
| 1826 | - $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label); |
|
| 1827 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 1828 | - } |
|
| 1829 | - |
|
| 1830 | - /*** END LIST TABLE METHODS **/ |
|
| 1831 | - /*****************************/ |
|
| 1832 | - /** |
|
| 1833 | - * _add_registered_metaboxes |
|
| 1834 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 1835 | - * |
|
| 1836 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 1837 | - * @access private |
|
| 1838 | - * @return void |
|
| 1839 | - */ |
|
| 1840 | - private function _add_registered_meta_boxes() |
|
| 1841 | - { |
|
| 1842 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1843 | - //we only add meta boxes if the page_route calls for it |
|
| 1844 | - if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 1845 | - && is_array( |
|
| 1846 | - $this->_route_config['metaboxes'] |
|
| 1847 | - ) |
|
| 1848 | - ) { |
|
| 1849 | - // this simply loops through the callbacks provided |
|
| 1850 | - // and checks if there is a corresponding callback registered by the child |
|
| 1851 | - // if there is then we go ahead and process the metabox loader. |
|
| 1852 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 1853 | - // first check for Closures |
|
| 1854 | - if ($metabox_callback instanceof Closure) { |
|
| 1855 | - $result = $metabox_callback(); |
|
| 1856 | - } else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 1857 | - $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 1858 | - } else { |
|
| 1859 | - $result = call_user_func(array($this, &$metabox_callback)); |
|
| 1860 | - } |
|
| 1861 | - if ($result === false) { |
|
| 1862 | - // user error msg |
|
| 1863 | - $error_msg = __('An error occurred. The requested metabox could not be found.', 'event_espresso'); |
|
| 1864 | - // developer error msg |
|
| 1865 | - $error_msg .= '||' . sprintf( |
|
| 1866 | - __( |
|
| 1867 | - 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 1868 | - 'event_espresso' |
|
| 1869 | - ), |
|
| 1870 | - $metabox_callback |
|
| 1871 | - ); |
|
| 1872 | - throw new EE_Error($error_msg); |
|
| 1873 | - } |
|
| 1874 | - } |
|
| 1875 | - } |
|
| 1876 | - } |
|
| 1877 | - |
|
| 1878 | - |
|
| 1879 | - |
|
| 1880 | - /** |
|
| 1881 | - * _add_screen_columns |
|
| 1882 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page. |
|
| 1883 | - * |
|
| 1884 | - * @access private |
|
| 1885 | - * @return void |
|
| 1886 | - */ |
|
| 1887 | - private function _add_screen_columns() |
|
| 1888 | - { |
|
| 1889 | - if ( |
|
| 1890 | - is_array($this->_route_config) |
|
| 1891 | - && isset($this->_route_config['columns']) |
|
| 1892 | - && is_array($this->_route_config['columns']) |
|
| 1893 | - && count($this->_route_config['columns']) === 2 |
|
| 1894 | - ) { |
|
| 1895 | - add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1])); |
|
| 1896 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 1897 | - $screen_id = $this->_current_screen->id; |
|
| 1898 | - $screen_columns = (int)get_user_option("screen_layout_$screen_id"); |
|
| 1899 | - $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1]; |
|
| 1900 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 1901 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 1902 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 1903 | - $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 1904 | - //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 1905 | - $this->_route_config['has_metaboxes'] = true; |
|
| 1906 | - } |
|
| 1907 | - } |
|
| 1908 | - |
|
| 1909 | - |
|
| 1910 | - |
|
| 1911 | - /**********************************/ |
|
| 1912 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 1913 | - /** |
|
| 1914 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply referencing the callback in the _page_config array property. This way you can be very specific about what pages these get |
|
| 1915 | - * loaded on. |
|
| 1916 | - */ |
|
| 1917 | - private function _espresso_news_post_box() |
|
| 1918 | - { |
|
| 1919 | - $news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso')); |
|
| 1920 | - add_meta_box('espresso_news_post_box', $news_box_title, array( |
|
| 1921 | - $this, |
|
| 1922 | - 'espresso_news_post_box', |
|
| 1923 | - ), $this->_wp_page_slug, 'side'); |
|
| 1924 | - } |
|
| 1925 | - |
|
| 1926 | - |
|
| 1927 | - |
|
| 1928 | - /** |
|
| 1929 | - * Code for setting up espresso ratings request metabox. |
|
| 1930 | - */ |
|
| 1931 | - protected function _espresso_ratings_request() |
|
| 1932 | - { |
|
| 1933 | - if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 1934 | - return ''; |
|
| 1935 | - } |
|
| 1936 | - $ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso')); |
|
| 1937 | - add_meta_box('espresso_ratings_request', $ratings_box_title, array( |
|
| 1938 | - $this, |
|
| 1939 | - 'espresso_ratings_request', |
|
| 1940 | - ), $this->_wp_page_slug, 'side'); |
|
| 1941 | - } |
|
| 1942 | - |
|
| 1943 | - |
|
| 1944 | - |
|
| 1945 | - /** |
|
| 1946 | - * Code for setting up espresso ratings request metabox content. |
|
| 1947 | - */ |
|
| 1948 | - public function espresso_ratings_request() |
|
| 1949 | - { |
|
| 1950 | - $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'; |
|
| 1951 | - EEH_Template::display_template($template_path, array()); |
|
| 1952 | - } |
|
| 1953 | - |
|
| 1954 | - |
|
| 1955 | - |
|
| 1956 | - public static function cached_rss_display($rss_id, $url) |
|
| 1957 | - { |
|
| 1958 | - $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading…') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>'; |
|
| 1959 | - $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX); |
|
| 1960 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 1961 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 1962 | - $post = '</div>' . "\n"; |
|
| 1963 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 1964 | - if (false != ($output = get_transient($cache_key))) { |
|
| 1965 | - echo $pre . $output . $post; |
|
| 1966 | - return true; |
|
| 1967 | - } |
|
| 1968 | - if ( ! $doing_ajax) { |
|
| 1969 | - echo $pre . $loading . $post; |
|
| 1970 | - return false; |
|
| 1971 | - } |
|
| 1972 | - ob_start(); |
|
| 1973 | - wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 1974 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 1975 | - return true; |
|
| 1976 | - } |
|
| 1977 | - |
|
| 1978 | - |
|
| 1979 | - |
|
| 1980 | - public function espresso_news_post_box() |
|
| 1981 | - { |
|
| 1982 | - ?> |
|
| 1813 | + return $entries_per_page_dropdown; |
|
| 1814 | + } |
|
| 1815 | + |
|
| 1816 | + |
|
| 1817 | + |
|
| 1818 | + /** |
|
| 1819 | + * _set_search_attributes |
|
| 1820 | + * |
|
| 1821 | + * @access protected |
|
| 1822 | + * @return void |
|
| 1823 | + */ |
|
| 1824 | + public function _set_search_attributes() |
|
| 1825 | + { |
|
| 1826 | + $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label); |
|
| 1827 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 1828 | + } |
|
| 1829 | + |
|
| 1830 | + /*** END LIST TABLE METHODS **/ |
|
| 1831 | + /*****************************/ |
|
| 1832 | + /** |
|
| 1833 | + * _add_registered_metaboxes |
|
| 1834 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 1835 | + * |
|
| 1836 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 1837 | + * @access private |
|
| 1838 | + * @return void |
|
| 1839 | + */ |
|
| 1840 | + private function _add_registered_meta_boxes() |
|
| 1841 | + { |
|
| 1842 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1843 | + //we only add meta boxes if the page_route calls for it |
|
| 1844 | + if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 1845 | + && is_array( |
|
| 1846 | + $this->_route_config['metaboxes'] |
|
| 1847 | + ) |
|
| 1848 | + ) { |
|
| 1849 | + // this simply loops through the callbacks provided |
|
| 1850 | + // and checks if there is a corresponding callback registered by the child |
|
| 1851 | + // if there is then we go ahead and process the metabox loader. |
|
| 1852 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 1853 | + // first check for Closures |
|
| 1854 | + if ($metabox_callback instanceof Closure) { |
|
| 1855 | + $result = $metabox_callback(); |
|
| 1856 | + } else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 1857 | + $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 1858 | + } else { |
|
| 1859 | + $result = call_user_func(array($this, &$metabox_callback)); |
|
| 1860 | + } |
|
| 1861 | + if ($result === false) { |
|
| 1862 | + // user error msg |
|
| 1863 | + $error_msg = __('An error occurred. The requested metabox could not be found.', 'event_espresso'); |
|
| 1864 | + // developer error msg |
|
| 1865 | + $error_msg .= '||' . sprintf( |
|
| 1866 | + __( |
|
| 1867 | + 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 1868 | + 'event_espresso' |
|
| 1869 | + ), |
|
| 1870 | + $metabox_callback |
|
| 1871 | + ); |
|
| 1872 | + throw new EE_Error($error_msg); |
|
| 1873 | + } |
|
| 1874 | + } |
|
| 1875 | + } |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + |
|
| 1879 | + |
|
| 1880 | + /** |
|
| 1881 | + * _add_screen_columns |
|
| 1882 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page. |
|
| 1883 | + * |
|
| 1884 | + * @access private |
|
| 1885 | + * @return void |
|
| 1886 | + */ |
|
| 1887 | + private function _add_screen_columns() |
|
| 1888 | + { |
|
| 1889 | + if ( |
|
| 1890 | + is_array($this->_route_config) |
|
| 1891 | + && isset($this->_route_config['columns']) |
|
| 1892 | + && is_array($this->_route_config['columns']) |
|
| 1893 | + && count($this->_route_config['columns']) === 2 |
|
| 1894 | + ) { |
|
| 1895 | + add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1])); |
|
| 1896 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 1897 | + $screen_id = $this->_current_screen->id; |
|
| 1898 | + $screen_columns = (int)get_user_option("screen_layout_$screen_id"); |
|
| 1899 | + $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1]; |
|
| 1900 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 1901 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 1902 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 1903 | + $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 1904 | + //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 1905 | + $this->_route_config['has_metaboxes'] = true; |
|
| 1906 | + } |
|
| 1907 | + } |
|
| 1908 | + |
|
| 1909 | + |
|
| 1910 | + |
|
| 1911 | + /**********************************/ |
|
| 1912 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 1913 | + /** |
|
| 1914 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply referencing the callback in the _page_config array property. This way you can be very specific about what pages these get |
|
| 1915 | + * loaded on. |
|
| 1916 | + */ |
|
| 1917 | + private function _espresso_news_post_box() |
|
| 1918 | + { |
|
| 1919 | + $news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso')); |
|
| 1920 | + add_meta_box('espresso_news_post_box', $news_box_title, array( |
|
| 1921 | + $this, |
|
| 1922 | + 'espresso_news_post_box', |
|
| 1923 | + ), $this->_wp_page_slug, 'side'); |
|
| 1924 | + } |
|
| 1925 | + |
|
| 1926 | + |
|
| 1927 | + |
|
| 1928 | + /** |
|
| 1929 | + * Code for setting up espresso ratings request metabox. |
|
| 1930 | + */ |
|
| 1931 | + protected function _espresso_ratings_request() |
|
| 1932 | + { |
|
| 1933 | + if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 1934 | + return ''; |
|
| 1935 | + } |
|
| 1936 | + $ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso')); |
|
| 1937 | + add_meta_box('espresso_ratings_request', $ratings_box_title, array( |
|
| 1938 | + $this, |
|
| 1939 | + 'espresso_ratings_request', |
|
| 1940 | + ), $this->_wp_page_slug, 'side'); |
|
| 1941 | + } |
|
| 1942 | + |
|
| 1943 | + |
|
| 1944 | + |
|
| 1945 | + /** |
|
| 1946 | + * Code for setting up espresso ratings request metabox content. |
|
| 1947 | + */ |
|
| 1948 | + public function espresso_ratings_request() |
|
| 1949 | + { |
|
| 1950 | + $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'; |
|
| 1951 | + EEH_Template::display_template($template_path, array()); |
|
| 1952 | + } |
|
| 1953 | + |
|
| 1954 | + |
|
| 1955 | + |
|
| 1956 | + public static function cached_rss_display($rss_id, $url) |
|
| 1957 | + { |
|
| 1958 | + $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading…') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>'; |
|
| 1959 | + $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX); |
|
| 1960 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 1961 | + $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 1962 | + $post = '</div>' . "\n"; |
|
| 1963 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 1964 | + if (false != ($output = get_transient($cache_key))) { |
|
| 1965 | + echo $pre . $output . $post; |
|
| 1966 | + return true; |
|
| 1967 | + } |
|
| 1968 | + if ( ! $doing_ajax) { |
|
| 1969 | + echo $pre . $loading . $post; |
|
| 1970 | + return false; |
|
| 1971 | + } |
|
| 1972 | + ob_start(); |
|
| 1973 | + wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 1974 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 1975 | + return true; |
|
| 1976 | + } |
|
| 1977 | + |
|
| 1978 | + |
|
| 1979 | + |
|
| 1980 | + public function espresso_news_post_box() |
|
| 1981 | + { |
|
| 1982 | + ?> |
|
| 1983 | 1983 | <div class="padding"> |
| 1984 | 1984 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 1985 | 1985 | <?php |
| 1986 | - // Get RSS Feed(s) |
|
| 1987 | - $feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/'); |
|
| 1988 | - $url = urlencode($feed_url); |
|
| 1989 | - self::cached_rss_display('espresso_news_post_box_content', $url); |
|
| 1990 | - ?> |
|
| 1986 | + // Get RSS Feed(s) |
|
| 1987 | + $feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/'); |
|
| 1988 | + $url = urlencode($feed_url); |
|
| 1989 | + self::cached_rss_display('espresso_news_post_box_content', $url); |
|
| 1990 | + ?> |
|
| 1991 | 1991 | </div> |
| 1992 | 1992 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 1993 | 1993 | </div> |
| 1994 | 1994 | <?php |
| 1995 | - } |
|
| 1996 | - |
|
| 1997 | - |
|
| 1998 | - |
|
| 1999 | - private function _espresso_links_post_box() |
|
| 2000 | - { |
|
| 2001 | - //Hiding until we actually have content to put in here... |
|
| 2002 | - //add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2003 | - } |
|
| 2004 | - |
|
| 2005 | - |
|
| 2006 | - |
|
| 2007 | - public function espresso_links_post_box() |
|
| 2008 | - { |
|
| 2009 | - //Hiding until we actually have content to put in here... |
|
| 2010 | - //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'; |
|
| 2011 | - //EEH_Template::display_template( $templatepath ); |
|
| 2012 | - } |
|
| 2013 | - |
|
| 2014 | - |
|
| 2015 | - |
|
| 2016 | - protected function _espresso_sponsors_post_box() |
|
| 2017 | - { |
|
| 2018 | - $show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true); |
|
| 2019 | - if ($show_sponsors) { |
|
| 2020 | - add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2021 | - } |
|
| 2022 | - } |
|
| 2023 | - |
|
| 2024 | - |
|
| 2025 | - |
|
| 2026 | - public function espresso_sponsors_post_box() |
|
| 2027 | - { |
|
| 2028 | - $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'; |
|
| 2029 | - EEH_Template::display_template($templatepath); |
|
| 2030 | - } |
|
| 2031 | - |
|
| 2032 | - |
|
| 2033 | - |
|
| 2034 | - private function _publish_post_box() |
|
| 2035 | - { |
|
| 2036 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2037 | - //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label. Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2038 | - if ( ! empty($this->_labels['publishbox'])) { |
|
| 2039 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox']; |
|
| 2040 | - } else { |
|
| 2041 | - $box_label = __('Publish', 'event_espresso'); |
|
| 2042 | - } |
|
| 2043 | - $box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this); |
|
| 2044 | - add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high'); |
|
| 2045 | - } |
|
| 2046 | - |
|
| 2047 | - |
|
| 2048 | - |
|
| 2049 | - public function editor_overview() |
|
| 2050 | - { |
|
| 2051 | - //if we have extra content set let's add it in if not make sure its empty |
|
| 2052 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
|
| 2053 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php'; |
|
| 2054 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2055 | - } |
|
| 2056 | - |
|
| 2057 | - |
|
| 2058 | - /** end of globally available metaboxes section **/ |
|
| 2059 | - /*************************************************/ |
|
| 2060 | - /** |
|
| 2061 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2062 | - * protected method. |
|
| 2063 | - * |
|
| 2064 | - * @see $this->_set_publish_post_box_vars for param details |
|
| 2065 | - * @since 4.6.0 |
|
| 2066 | - */ |
|
| 2067 | - public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true) |
|
| 2068 | - { |
|
| 2069 | - $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns); |
|
| 2070 | - } |
|
| 2071 | - |
|
| 2072 | - |
|
| 2073 | - |
|
| 2074 | - /** |
|
| 2075 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2076 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2077 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2078 | - * values for the name and id arguments. |
|
| 2079 | - * |
|
| 2080 | - * @todo Add in validation for name/id arguments. |
|
| 2081 | - * @param string $name key used for the action ID (i.e. event_id) |
|
| 2082 | - * @param int $id id attached to the item published |
|
| 2083 | - * @param string $delete page route callback for the delete action |
|
| 2084 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2085 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button |
|
| 2086 | - * @throws \EE_Error |
|
| 2087 | - */ |
|
| 2088 | - protected function _set_publish_post_box_vars( |
|
| 2089 | - $name = '', |
|
| 2090 | - $id = 0, |
|
| 2091 | - $delete = '', |
|
| 2092 | - $save_close_redirect_URL = '', |
|
| 2093 | - $both_btns = true |
|
| 2094 | - ) { |
|
| 2095 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2096 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url; |
|
| 2097 | - // create the Save & Close and Save buttons |
|
| 2098 | - $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2099 | - //if we have extra content set let's add it in if not make sure its empty |
|
| 2100 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
|
| 2101 | - if ($delete && ! empty($id)) { |
|
| 2102 | - //make sure we have a default if just true is sent. |
|
| 2103 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2104 | - $delete_link_args = array($name => $id); |
|
| 2105 | - $delete = $this->get_action_link_or_button( |
|
| 2106 | - $delete, |
|
| 2107 | - $delete, |
|
| 2108 | - $delete_link_args, |
|
| 2109 | - 'submitdelete deletion', |
|
| 2110 | - '', |
|
| 2111 | - false |
|
| 2112 | - ); |
|
| 2113 | - } |
|
| 2114 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2115 | - if ( ! empty($name) && ! empty($id)) { |
|
| 2116 | - $hidden_field_arr[$name] = array( |
|
| 2117 | - 'type' => 'hidden', |
|
| 2118 | - 'value' => $id, |
|
| 2119 | - ); |
|
| 2120 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2121 | - } else { |
|
| 2122 | - $hf = ''; |
|
| 2123 | - } |
|
| 2124 | - // add hidden field |
|
| 2125 | - $this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf; |
|
| 2126 | - } |
|
| 2127 | - |
|
| 2128 | - |
|
| 2129 | - |
|
| 2130 | - /** |
|
| 2131 | - * displays an error message to ppl who have javascript disabled |
|
| 2132 | - * |
|
| 2133 | - * @access private |
|
| 2134 | - * @return string |
|
| 2135 | - */ |
|
| 2136 | - private function _display_no_javascript_warning() |
|
| 2137 | - { |
|
| 2138 | - ?> |
|
| 1995 | + } |
|
| 1996 | + |
|
| 1997 | + |
|
| 1998 | + |
|
| 1999 | + private function _espresso_links_post_box() |
|
| 2000 | + { |
|
| 2001 | + //Hiding until we actually have content to put in here... |
|
| 2002 | + //add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2003 | + } |
|
| 2004 | + |
|
| 2005 | + |
|
| 2006 | + |
|
| 2007 | + public function espresso_links_post_box() |
|
| 2008 | + { |
|
| 2009 | + //Hiding until we actually have content to put in here... |
|
| 2010 | + //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'; |
|
| 2011 | + //EEH_Template::display_template( $templatepath ); |
|
| 2012 | + } |
|
| 2013 | + |
|
| 2014 | + |
|
| 2015 | + |
|
| 2016 | + protected function _espresso_sponsors_post_box() |
|
| 2017 | + { |
|
| 2018 | + $show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true); |
|
| 2019 | + if ($show_sponsors) { |
|
| 2020 | + add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2021 | + } |
|
| 2022 | + } |
|
| 2023 | + |
|
| 2024 | + |
|
| 2025 | + |
|
| 2026 | + public function espresso_sponsors_post_box() |
|
| 2027 | + { |
|
| 2028 | + $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'; |
|
| 2029 | + EEH_Template::display_template($templatepath); |
|
| 2030 | + } |
|
| 2031 | + |
|
| 2032 | + |
|
| 2033 | + |
|
| 2034 | + private function _publish_post_box() |
|
| 2035 | + { |
|
| 2036 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2037 | + //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label. Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2038 | + if ( ! empty($this->_labels['publishbox'])) { |
|
| 2039 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox']; |
|
| 2040 | + } else { |
|
| 2041 | + $box_label = __('Publish', 'event_espresso'); |
|
| 2042 | + } |
|
| 2043 | + $box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this); |
|
| 2044 | + add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high'); |
|
| 2045 | + } |
|
| 2046 | + |
|
| 2047 | + |
|
| 2048 | + |
|
| 2049 | + public function editor_overview() |
|
| 2050 | + { |
|
| 2051 | + //if we have extra content set let's add it in if not make sure its empty |
|
| 2052 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
|
| 2053 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php'; |
|
| 2054 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2055 | + } |
|
| 2056 | + |
|
| 2057 | + |
|
| 2058 | + /** end of globally available metaboxes section **/ |
|
| 2059 | + /*************************************************/ |
|
| 2060 | + /** |
|
| 2061 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2062 | + * protected method. |
|
| 2063 | + * |
|
| 2064 | + * @see $this->_set_publish_post_box_vars for param details |
|
| 2065 | + * @since 4.6.0 |
|
| 2066 | + */ |
|
| 2067 | + public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true) |
|
| 2068 | + { |
|
| 2069 | + $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns); |
|
| 2070 | + } |
|
| 2071 | + |
|
| 2072 | + |
|
| 2073 | + |
|
| 2074 | + /** |
|
| 2075 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2076 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2077 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2078 | + * values for the name and id arguments. |
|
| 2079 | + * |
|
| 2080 | + * @todo Add in validation for name/id arguments. |
|
| 2081 | + * @param string $name key used for the action ID (i.e. event_id) |
|
| 2082 | + * @param int $id id attached to the item published |
|
| 2083 | + * @param string $delete page route callback for the delete action |
|
| 2084 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2085 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button |
|
| 2086 | + * @throws \EE_Error |
|
| 2087 | + */ |
|
| 2088 | + protected function _set_publish_post_box_vars( |
|
| 2089 | + $name = '', |
|
| 2090 | + $id = 0, |
|
| 2091 | + $delete = '', |
|
| 2092 | + $save_close_redirect_URL = '', |
|
| 2093 | + $both_btns = true |
|
| 2094 | + ) { |
|
| 2095 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2096 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url; |
|
| 2097 | + // create the Save & Close and Save buttons |
|
| 2098 | + $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2099 | + //if we have extra content set let's add it in if not make sure its empty |
|
| 2100 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
|
| 2101 | + if ($delete && ! empty($id)) { |
|
| 2102 | + //make sure we have a default if just true is sent. |
|
| 2103 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2104 | + $delete_link_args = array($name => $id); |
|
| 2105 | + $delete = $this->get_action_link_or_button( |
|
| 2106 | + $delete, |
|
| 2107 | + $delete, |
|
| 2108 | + $delete_link_args, |
|
| 2109 | + 'submitdelete deletion', |
|
| 2110 | + '', |
|
| 2111 | + false |
|
| 2112 | + ); |
|
| 2113 | + } |
|
| 2114 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2115 | + if ( ! empty($name) && ! empty($id)) { |
|
| 2116 | + $hidden_field_arr[$name] = array( |
|
| 2117 | + 'type' => 'hidden', |
|
| 2118 | + 'value' => $id, |
|
| 2119 | + ); |
|
| 2120 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2121 | + } else { |
|
| 2122 | + $hf = ''; |
|
| 2123 | + } |
|
| 2124 | + // add hidden field |
|
| 2125 | + $this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf; |
|
| 2126 | + } |
|
| 2127 | + |
|
| 2128 | + |
|
| 2129 | + |
|
| 2130 | + /** |
|
| 2131 | + * displays an error message to ppl who have javascript disabled |
|
| 2132 | + * |
|
| 2133 | + * @access private |
|
| 2134 | + * @return string |
|
| 2135 | + */ |
|
| 2136 | + private function _display_no_javascript_warning() |
|
| 2137 | + { |
|
| 2138 | + ?> |
|
| 2139 | 2139 | <noscript> |
| 2140 | 2140 | <div id="no-js-message" class="error"> |
| 2141 | 2141 | <p style="font-size:1.3em;"> |
@@ -2145,1267 +2145,1267 @@ discard block |
||
| 2145 | 2145 | </div> |
| 2146 | 2146 | </noscript> |
| 2147 | 2147 | <?php |
| 2148 | - } |
|
| 2148 | + } |
|
| 2149 | 2149 | |
| 2150 | 2150 | |
| 2151 | 2151 | |
| 2152 | - /** |
|
| 2153 | - * displays espresso success and/or error notices |
|
| 2154 | - * |
|
| 2155 | - * @access private |
|
| 2156 | - * @return string |
|
| 2157 | - */ |
|
| 2158 | - private function _display_espresso_notices() |
|
| 2159 | - { |
|
| 2160 | - $notices = $this->_get_transient(true); |
|
| 2161 | - echo stripslashes($notices); |
|
| 2162 | - } |
|
| 2152 | + /** |
|
| 2153 | + * displays espresso success and/or error notices |
|
| 2154 | + * |
|
| 2155 | + * @access private |
|
| 2156 | + * @return string |
|
| 2157 | + */ |
|
| 2158 | + private function _display_espresso_notices() |
|
| 2159 | + { |
|
| 2160 | + $notices = $this->_get_transient(true); |
|
| 2161 | + echo stripslashes($notices); |
|
| 2162 | + } |
|
| 2163 | 2163 | |
| 2164 | 2164 | |
| 2165 | 2165 | |
| 2166 | - /** |
|
| 2167 | - * spinny things pacify the masses |
|
| 2168 | - * |
|
| 2169 | - * @access private |
|
| 2170 | - * @return string |
|
| 2171 | - */ |
|
| 2172 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2173 | - { |
|
| 2174 | - ?> |
|
| 2166 | + /** |
|
| 2167 | + * spinny things pacify the masses |
|
| 2168 | + * |
|
| 2169 | + * @access private |
|
| 2170 | + * @return string |
|
| 2171 | + */ |
|
| 2172 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2173 | + { |
|
| 2174 | + ?> |
|
| 2175 | 2175 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2176 | 2176 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e('loading...', 'event_espresso'); ?></span> |
| 2177 | 2177 | </div> |
| 2178 | 2178 | <?php |
| 2179 | - } |
|
| 2179 | + } |
|
| 2180 | 2180 | |
| 2181 | 2181 | |
| 2182 | 2182 | |
| 2183 | - /** |
|
| 2184 | - * add admin page overlay for modal boxes |
|
| 2185 | - * |
|
| 2186 | - * @access private |
|
| 2187 | - * @return string |
|
| 2188 | - */ |
|
| 2189 | - protected function _add_admin_page_overlay() |
|
| 2190 | - { |
|
| 2191 | - ?> |
|
| 2183 | + /** |
|
| 2184 | + * add admin page overlay for modal boxes |
|
| 2185 | + * |
|
| 2186 | + * @access private |
|
| 2187 | + * @return string |
|
| 2188 | + */ |
|
| 2189 | + protected function _add_admin_page_overlay() |
|
| 2190 | + { |
|
| 2191 | + ?> |
|
| 2192 | 2192 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2193 | 2193 | <?php |
| 2194 | - } |
|
| 2195 | - |
|
| 2196 | - |
|
| 2197 | - |
|
| 2198 | - /** |
|
| 2199 | - * facade for add_meta_box |
|
| 2200 | - * |
|
| 2201 | - * @param string $action where the metabox get's displayed |
|
| 2202 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2203 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here. |
|
| 2204 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2205 | - * @param string $column what metabox column |
|
| 2206 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2207 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box. |
|
| 2208 | - */ |
|
| 2209 | - public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true) |
|
| 2210 | - { |
|
| 2211 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2212 | - //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2213 | - if (empty($callback_args) && $create_func) { |
|
| 2214 | - $callback_args = array( |
|
| 2215 | - 'template_path' => $this->_template_path, |
|
| 2216 | - 'template_args' => $this->_template_args, |
|
| 2217 | - ); |
|
| 2218 | - } |
|
| 2219 | - //if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2220 | - $call_back_func = $create_func ? create_function('$post, $metabox', |
|
| 2221 | - 'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback; |
|
| 2222 | - add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args); |
|
| 2223 | - } |
|
| 2224 | - |
|
| 2225 | - |
|
| 2226 | - |
|
| 2227 | - /** |
|
| 2228 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2229 | - * |
|
| 2230 | - * @return [type] [description] |
|
| 2231 | - */ |
|
| 2232 | - public function display_admin_page_with_metabox_columns() |
|
| 2233 | - { |
|
| 2234 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2235 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true); |
|
| 2236 | - //the final wrapper |
|
| 2237 | - $this->admin_page_wrapper(); |
|
| 2238 | - } |
|
| 2239 | - |
|
| 2240 | - |
|
| 2241 | - |
|
| 2242 | - /** |
|
| 2243 | - * generates HTML wrapper for an admin details page |
|
| 2244 | - * |
|
| 2245 | - * @access public |
|
| 2246 | - * @return void |
|
| 2247 | - */ |
|
| 2248 | - public function display_admin_page_with_sidebar() |
|
| 2249 | - { |
|
| 2250 | - $this->_display_admin_page(true); |
|
| 2251 | - } |
|
| 2252 | - |
|
| 2253 | - |
|
| 2254 | - |
|
| 2255 | - /** |
|
| 2256 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2257 | - * |
|
| 2258 | - * @access public |
|
| 2259 | - * @return void |
|
| 2260 | - */ |
|
| 2261 | - public function display_admin_page_with_no_sidebar() |
|
| 2262 | - { |
|
| 2263 | - $this->_display_admin_page(); |
|
| 2264 | - } |
|
| 2265 | - |
|
| 2266 | - |
|
| 2267 | - |
|
| 2268 | - /** |
|
| 2269 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2270 | - * |
|
| 2271 | - * @access public |
|
| 2272 | - * @return void |
|
| 2273 | - */ |
|
| 2274 | - public function display_about_admin_page() |
|
| 2275 | - { |
|
| 2276 | - $this->_display_admin_page(false, true); |
|
| 2277 | - } |
|
| 2278 | - |
|
| 2279 | - |
|
| 2280 | - |
|
| 2281 | - /** |
|
| 2282 | - * display_admin_page |
|
| 2283 | - * contains the code for actually displaying an admin page |
|
| 2284 | - * |
|
| 2285 | - * @access private |
|
| 2286 | - * @param boolean $sidebar true with sidebar, false without |
|
| 2287 | - * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2288 | - * @return void |
|
| 2289 | - */ |
|
| 2290 | - private function _display_admin_page($sidebar = false, $about = false) |
|
| 2291 | - { |
|
| 2292 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2293 | - //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2294 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2295 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2296 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2297 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2298 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2299 | - ? 'poststuff' |
|
| 2300 | - : 'espresso-default-admin'; |
|
| 2301 | - $template_path = $sidebar |
|
| 2302 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2303 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2304 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2305 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2306 | - } |
|
| 2307 | - $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
|
| 2308 | - $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : ''; |
|
| 2309 | - $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''; |
|
| 2310 | - $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''; |
|
| 2311 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2312 | - // the final template wrapper |
|
| 2313 | - $this->admin_page_wrapper($about); |
|
| 2314 | - } |
|
| 2315 | - |
|
| 2316 | - |
|
| 2317 | - |
|
| 2318 | - /** |
|
| 2319 | - * This is used to display caf preview pages. |
|
| 2320 | - * |
|
| 2321 | - * @since 4.3.2 |
|
| 2322 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2323 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2324 | - * @return void |
|
| 2325 | - * @throws \EE_Error |
|
| 2326 | - */ |
|
| 2327 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2328 | - { |
|
| 2329 | - //let's generate a default preview action button if there isn't one already present. |
|
| 2330 | - $this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso'); |
|
| 2331 | - $buy_now_url = add_query_arg( |
|
| 2332 | - array( |
|
| 2333 | - 'ee_ver' => 'ee4', |
|
| 2334 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2335 | - 'utm_medium' => 'link', |
|
| 2336 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2337 | - 'utm_content' => 'buy_now_button', |
|
| 2338 | - ), |
|
| 2339 | - 'http://eventespresso.com/pricing/' |
|
| 2340 | - ); |
|
| 2341 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2342 | - ? $this->get_action_link_or_button( |
|
| 2343 | - '', |
|
| 2344 | - 'buy_now', |
|
| 2345 | - array(), |
|
| 2346 | - 'button-primary button-large', |
|
| 2347 | - $buy_now_url, |
|
| 2348 | - true |
|
| 2349 | - ) |
|
| 2350 | - : $this->_template_args['preview_action_button']; |
|
| 2351 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php'; |
|
| 2352 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2353 | - $template_path, |
|
| 2354 | - $this->_template_args, |
|
| 2355 | - true |
|
| 2356 | - ); |
|
| 2357 | - $this->_display_admin_page($display_sidebar); |
|
| 2358 | - } |
|
| 2359 | - |
|
| 2360 | - |
|
| 2361 | - |
|
| 2362 | - /** |
|
| 2363 | - * display_admin_list_table_page_with_sidebar |
|
| 2364 | - * generates HTML wrapper for an admin_page with list_table |
|
| 2365 | - * |
|
| 2366 | - * @access public |
|
| 2367 | - * @return void |
|
| 2368 | - */ |
|
| 2369 | - public function display_admin_list_table_page_with_sidebar() |
|
| 2370 | - { |
|
| 2371 | - $this->_display_admin_list_table_page(true); |
|
| 2372 | - } |
|
| 2373 | - |
|
| 2374 | - |
|
| 2375 | - |
|
| 2376 | - /** |
|
| 2377 | - * display_admin_list_table_page_with_no_sidebar |
|
| 2378 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2379 | - * |
|
| 2380 | - * @access public |
|
| 2381 | - * @return void |
|
| 2382 | - */ |
|
| 2383 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 2384 | - { |
|
| 2385 | - $this->_display_admin_list_table_page(); |
|
| 2386 | - } |
|
| 2387 | - |
|
| 2388 | - |
|
| 2389 | - |
|
| 2390 | - /** |
|
| 2391 | - * generates html wrapper for an admin_list_table page |
|
| 2392 | - * |
|
| 2393 | - * @access private |
|
| 2394 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2395 | - * @return void |
|
| 2396 | - */ |
|
| 2397 | - private function _display_admin_list_table_page($sidebar = false) |
|
| 2398 | - { |
|
| 2399 | - //setup search attributes |
|
| 2400 | - $this->_set_search_attributes(); |
|
| 2401 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2402 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2403 | - $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 2404 | - ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 2405 | - : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 2406 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2407 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 2408 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2409 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2410 | - if ( ! empty($ajax_sorting_callback)) { |
|
| 2411 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2412 | - $ajax_sorting_callback . '_nonce', |
|
| 2413 | - $ajax_sorting_callback . '_nonce', |
|
| 2414 | - false, |
|
| 2415 | - false |
|
| 2416 | - ); |
|
| 2417 | - // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
|
| 2418 | - // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
|
| 2419 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />'; |
|
| 2420 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />'; |
|
| 2421 | - } else { |
|
| 2422 | - $sortable_list_table_form_fields = ''; |
|
| 2423 | - } |
|
| 2424 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2425 | - $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : ''; |
|
| 2426 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2427 | - $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
|
| 2428 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2429 | - //display message about search results? |
|
| 2430 | - $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 2431 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 2432 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 2433 | - trim($this->_req_data['s'], '%') |
|
| 2434 | - ) . '</p>' |
|
| 2435 | - : ''; |
|
| 2436 | - // filter before_list_table template arg |
|
| 2437 | - $this->_template_args['before_list_table'] = apply_filters( |
|
| 2438 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2439 | - $this->_template_args['before_list_table'], |
|
| 2440 | - $this->page_slug, |
|
| 2441 | - $this->_req_data, |
|
| 2442 | - $this->_req_action |
|
| 2443 | - ); |
|
| 2444 | - // convert to array and filter again |
|
| 2445 | - // arrays are easier to inject new items in a specific location, |
|
| 2446 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 2447 | - $this->_template_args['before_list_table'] = implode( |
|
| 2448 | - " \n", |
|
| 2449 | - (array) apply_filters( |
|
| 2450 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 2451 | - (array) $this->_template_args['before_list_table'], |
|
| 2452 | - $this->page_slug, |
|
| 2453 | - $this->_req_data, |
|
| 2454 | - $this->_req_action |
|
| 2455 | - ) |
|
| 2456 | - ); |
|
| 2457 | - // filter after_list_table template arg |
|
| 2458 | - $this->_template_args['after_list_table'] = apply_filters( |
|
| 2459 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 2460 | - $this->_template_args['after_list_table'], |
|
| 2461 | - $this->page_slug, |
|
| 2462 | - $this->_req_data, |
|
| 2463 | - $this->_req_action |
|
| 2464 | - ); |
|
| 2465 | - // convert to array and filter again |
|
| 2466 | - // arrays are easier to inject new items in a specific location, |
|
| 2467 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 2468 | - $this->_template_args['after_list_table'] = implode( |
|
| 2469 | - " \n", |
|
| 2470 | - (array) apply_filters( |
|
| 2471 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 2472 | - (array) $this->_template_args['after_list_table'], |
|
| 2473 | - $this->page_slug, |
|
| 2474 | - $this->_req_data, |
|
| 2475 | - $this->_req_action |
|
| 2476 | - ) |
|
| 2477 | - ); |
|
| 2478 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2479 | - $template_path, |
|
| 2480 | - $this->_template_args, |
|
| 2481 | - true |
|
| 2482 | - ); |
|
| 2483 | - // the final template wrapper |
|
| 2484 | - if ($sidebar) { |
|
| 2485 | - $this->display_admin_page_with_sidebar(); |
|
| 2486 | - } else { |
|
| 2487 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2488 | - } |
|
| 2489 | - } |
|
| 2490 | - |
|
| 2491 | - |
|
| 2492 | - |
|
| 2493 | - /** |
|
| 2494 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend. |
|
| 2495 | - * $items are expected in an array in the following format: |
|
| 2496 | - * $legend_items = array( |
|
| 2497 | - * 'item_id' => array( |
|
| 2498 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 2499 | - * 'desc' => __('localized description of item'); |
|
| 2500 | - * ) |
|
| 2501 | - * ); |
|
| 2502 | - * |
|
| 2503 | - * @param array $items see above for format of array |
|
| 2504 | - * @return string html string of legend |
|
| 2505 | - */ |
|
| 2506 | - protected function _display_legend($items) |
|
| 2507 | - { |
|
| 2508 | - $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this); |
|
| 2509 | - $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php'; |
|
| 2510 | - return EEH_Template::display_template($legend_template, $this->_template_args, true); |
|
| 2511 | - } |
|
| 2512 | - |
|
| 2513 | - |
|
| 2514 | - |
|
| 2515 | - /** |
|
| 2516 | - * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 2517 | - * |
|
| 2518 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed. |
|
| 2519 | - * The returned json object is created from an array in the following format: |
|
| 2520 | - * array( |
|
| 2521 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 2522 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 2523 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 2524 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 2525 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any |
|
| 2526 | - * specific template args that might be included in here) |
|
| 2527 | - * ) |
|
| 2528 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 2529 | - * @return void |
|
| 2530 | - */ |
|
| 2531 | - protected function _return_json($sticky_notices = false) |
|
| 2532 | - { |
|
| 2533 | - //make sure any EE_Error notices have been handled. |
|
| 2534 | - $this->_process_notices(array(), true, $sticky_notices); |
|
| 2535 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 2536 | - unset($this->_template_args['data']); |
|
| 2537 | - $json = array( |
|
| 2538 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 2539 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 2540 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 2541 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 2542 | - 'notices' => EE_Error::get_notices(), |
|
| 2543 | - 'content' => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '', |
|
| 2544 | - 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 2545 | - 'isEEajax' => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 2546 | - ); |
|
| 2547 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 2548 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 2549 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 2550 | - } |
|
| 2551 | - echo wp_json_encode($json); |
|
| 2552 | - |
|
| 2553 | - exit(); |
|
| 2554 | - } |
|
| 2555 | - |
|
| 2556 | - |
|
| 2557 | - |
|
| 2558 | - /** |
|
| 2559 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 2560 | - * |
|
| 2561 | - * @return void |
|
| 2562 | - * @throws EE_Error |
|
| 2563 | - */ |
|
| 2564 | - public function return_json() |
|
| 2565 | - { |
|
| 2566 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2567 | - $this->_return_json(); |
|
| 2568 | - } else { |
|
| 2569 | - throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__)); |
|
| 2570 | - } |
|
| 2571 | - } |
|
| 2572 | - |
|
| 2573 | - |
|
| 2574 | - |
|
| 2575 | - /** |
|
| 2576 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 2577 | - * |
|
| 2578 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 2579 | - * @access public |
|
| 2580 | - */ |
|
| 2581 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 2582 | - { |
|
| 2583 | - $this->_hook_obj = $hook_obj; |
|
| 2584 | - } |
|
| 2585 | - |
|
| 2586 | - |
|
| 2587 | - |
|
| 2588 | - /** |
|
| 2589 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 2590 | - * |
|
| 2591 | - * @access public |
|
| 2592 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
| 2593 | - * @return void |
|
| 2594 | - */ |
|
| 2595 | - public function admin_page_wrapper($about = false) |
|
| 2596 | - { |
|
| 2597 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2598 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 2599 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 2600 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 2601 | - $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2602 | - isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''); |
|
| 2603 | - $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2604 | - isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''); |
|
| 2605 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 2606 | - // load settings page wrapper template |
|
| 2607 | - $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php'; |
|
| 2608 | - //about page? |
|
| 2609 | - $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path; |
|
| 2610 | - if (defined('DOING_AJAX')) { |
|
| 2611 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2612 | - $this->_return_json(); |
|
| 2613 | - } else { |
|
| 2614 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 2615 | - } |
|
| 2616 | - } |
|
| 2617 | - |
|
| 2618 | - |
|
| 2619 | - |
|
| 2620 | - /** |
|
| 2621 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 2622 | - * |
|
| 2623 | - * @return string html |
|
| 2624 | - */ |
|
| 2625 | - protected function _get_main_nav_tabs() |
|
| 2626 | - { |
|
| 2627 | - //let's generate the html using the EEH_Tabbed_Content helper. We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array) |
|
| 2628 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 2629 | - } |
|
| 2630 | - |
|
| 2631 | - |
|
| 2632 | - |
|
| 2633 | - /** |
|
| 2634 | - * sort nav tabs |
|
| 2635 | - * |
|
| 2636 | - * @access public |
|
| 2637 | - * @param $a |
|
| 2638 | - * @param $b |
|
| 2639 | - * @return int |
|
| 2640 | - */ |
|
| 2641 | - private function _sort_nav_tabs($a, $b) |
|
| 2642 | - { |
|
| 2643 | - if ($a['order'] == $b['order']) { |
|
| 2644 | - return 0; |
|
| 2645 | - } |
|
| 2646 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 2647 | - } |
|
| 2648 | - |
|
| 2649 | - |
|
| 2650 | - |
|
| 2651 | - /** |
|
| 2652 | - * generates HTML for the forms used on admin pages |
|
| 2653 | - * |
|
| 2654 | - * @access protected |
|
| 2655 | - * @param array $input_vars - array of input field details |
|
| 2656 | - * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to use) |
|
| 2657 | - * @return string |
|
| 2658 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 2659 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 2660 | - */ |
|
| 2661 | - protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 2662 | - { |
|
| 2663 | - $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 2664 | - return $content; |
|
| 2665 | - } |
|
| 2666 | - |
|
| 2667 | - |
|
| 2668 | - |
|
| 2669 | - /** |
|
| 2670 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 2671 | - * |
|
| 2672 | - * @access protected |
|
| 2673 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & Close" button. |
|
| 2674 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close') |
|
| 2675 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button). We can also use this to just dump default actions by submitting some other value. |
|
| 2676 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling). |
|
| 2677 | - */ |
|
| 2678 | - protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 2679 | - { |
|
| 2680 | - //make sure $text and $actions are in an array |
|
| 2681 | - $text = (array)$text; |
|
| 2682 | - $actions = (array)$actions; |
|
| 2683 | - $referrer_url = empty($referrer) ? '' : $referrer; |
|
| 2684 | - $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />' |
|
| 2685 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />'; |
|
| 2686 | - $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso')); |
|
| 2687 | - $default_names = array('save', 'save_and_close'); |
|
| 2688 | - //add in a hidden index for the current page (so save and close redirects properly) |
|
| 2689 | - $this->_template_args['save_buttons'] = $referrer_url; |
|
| 2690 | - foreach ($button_text as $key => $button) { |
|
| 2691 | - $ref = $default_names[$key]; |
|
| 2692 | - $id = $this->_current_view . '_' . $ref; |
|
| 2693 | - $name = ! empty($actions) ? $actions[$key] : $ref; |
|
| 2694 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />'; |
|
| 2695 | - if ( ! $both) { |
|
| 2696 | - break; |
|
| 2697 | - } |
|
| 2698 | - } |
|
| 2699 | - } |
|
| 2700 | - |
|
| 2701 | - |
|
| 2702 | - |
|
| 2703 | - /** |
|
| 2704 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 2705 | - * |
|
| 2706 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 2707 | - * @since 4.6.0 |
|
| 2708 | - * @param string $route |
|
| 2709 | - * @param array $additional_hidden_fields |
|
| 2710 | - */ |
|
| 2711 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 2712 | - { |
|
| 2713 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 2714 | - } |
|
| 2715 | - |
|
| 2716 | - |
|
| 2717 | - |
|
| 2718 | - /** |
|
| 2719 | - * set form open and close tags on add/edit pages. |
|
| 2720 | - * |
|
| 2721 | - * @access protected |
|
| 2722 | - * @param string $route the route you want the form to direct to |
|
| 2723 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 2724 | - * @return void |
|
| 2725 | - */ |
|
| 2726 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 2727 | - { |
|
| 2728 | - if (empty($route)) { |
|
| 2729 | - $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso'); |
|
| 2730 | - $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__); |
|
| 2731 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2732 | - } |
|
| 2733 | - // open form |
|
| 2734 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >'; |
|
| 2735 | - // add nonce |
|
| 2736 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 2737 | - // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
|
| 2738 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 2739 | - // add REQUIRED form action |
|
| 2740 | - $hidden_fields = array( |
|
| 2741 | - 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 2742 | - ); |
|
| 2743 | - // merge arrays |
|
| 2744 | - $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields; |
|
| 2745 | - // generate form fields |
|
| 2746 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 2747 | - // add fields to form |
|
| 2748 | - foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 2749 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 2750 | - } |
|
| 2751 | - // close form |
|
| 2752 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 2753 | - } |
|
| 2754 | - |
|
| 2755 | - |
|
| 2756 | - |
|
| 2757 | - /** |
|
| 2758 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 2759 | - * discovered it would be useful for external code to have access. |
|
| 2760 | - * |
|
| 2761 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 2762 | - * @since 4.5.0 |
|
| 2763 | - */ |
|
| 2764 | - public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false) |
|
| 2765 | - { |
|
| 2766 | - $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite); |
|
| 2767 | - } |
|
| 2768 | - |
|
| 2769 | - |
|
| 2770 | - |
|
| 2771 | - /** |
|
| 2772 | - * _redirect_after_action |
|
| 2773 | - * |
|
| 2774 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
| 2775 | - * @param string $what - what the action was performed on |
|
| 2776 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 2777 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin action is completed |
|
| 2778 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show. |
|
| 2779 | - * @access protected |
|
| 2780 | - * @return void |
|
| 2781 | - */ |
|
| 2782 | - protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false) |
|
| 2783 | - { |
|
| 2784 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2785 | - //class name for actions/filters. |
|
| 2786 | - $classname = get_class($this); |
|
| 2787 | - //set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url |
|
| 2788 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 2789 | - $notices = EE_Error::get_notices(false); |
|
| 2790 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 2791 | - if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 2792 | - EE_Error::overwrite_success(); |
|
| 2793 | - } |
|
| 2794 | - if ( ! empty($what) && ! empty($action_desc)) { |
|
| 2795 | - // how many records affected ? more than one record ? or just one ? |
|
| 2796 | - if ($success > 1 && empty($notices['errors'])) { |
|
| 2797 | - // set plural msg |
|
| 2798 | - EE_Error::add_success( |
|
| 2799 | - sprintf( |
|
| 2800 | - __('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 2801 | - $what, |
|
| 2802 | - $action_desc |
|
| 2803 | - ), |
|
| 2804 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2805 | - ); |
|
| 2806 | - } else if ($success == 1 && empty($notices['errors'])) { |
|
| 2807 | - // set singular msg |
|
| 2808 | - EE_Error::add_success( |
|
| 2809 | - sprintf( |
|
| 2810 | - __('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 2811 | - $what, |
|
| 2812 | - $action_desc |
|
| 2813 | - ), |
|
| 2814 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2815 | - ); |
|
| 2816 | - } |
|
| 2817 | - } |
|
| 2818 | - // check that $query_args isn't something crazy |
|
| 2819 | - if ( ! is_array($query_args)) { |
|
| 2820 | - $query_args = array(); |
|
| 2821 | - } |
|
| 2822 | - /** |
|
| 2823 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 2824 | - * redirections on save and close actions |
|
| 2825 | - * |
|
| 2826 | - * @since 4.2.0 |
|
| 2827 | - * @param array $query_args The original query_args array coming into the |
|
| 2828 | - * method. |
|
| 2829 | - */ |
|
| 2830 | - do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args); |
|
| 2831 | - //calculate where we're going (if we have a "save and close" button pushed) |
|
| 2832 | - if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) { |
|
| 2833 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 2834 | - $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 2835 | - // regenerate query args array from referrer URL |
|
| 2836 | - parse_str($parsed_url['query'], $query_args); |
|
| 2837 | - // correct page and action will be in the query args now |
|
| 2838 | - $redirect_url = admin_url('admin.php'); |
|
| 2839 | - } |
|
| 2840 | - //merge any default query_args set in _default_route_query_args property |
|
| 2841 | - if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 2842 | - $args_to_merge = array(); |
|
| 2843 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 2844 | - //is there a wp_referer array in our _default_route_query_args property? |
|
| 2845 | - if ($query_param == 'wp_referer') { |
|
| 2846 | - $query_value = (array)$query_value; |
|
| 2847 | - foreach ($query_value as $reference => $value) { |
|
| 2848 | - if (strpos($reference, 'nonce') !== false) { |
|
| 2849 | - continue; |
|
| 2850 | - } |
|
| 2851 | - //finally we will override any arguments in the referer with |
|
| 2852 | - //what might be set on the _default_route_query_args array. |
|
| 2853 | - if (isset($this->_default_route_query_args[$reference])) { |
|
| 2854 | - $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 2855 | - } else { |
|
| 2856 | - $args_to_merge[$reference] = urlencode($value); |
|
| 2857 | - } |
|
| 2858 | - } |
|
| 2859 | - continue; |
|
| 2860 | - } |
|
| 2861 | - $args_to_merge[$query_param] = $query_value; |
|
| 2862 | - } |
|
| 2863 | - //now let's merge these arguments but override with what was specifically sent in to the |
|
| 2864 | - //redirect. |
|
| 2865 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 2866 | - } |
|
| 2867 | - $this->_process_notices($query_args); |
|
| 2868 | - // generate redirect url |
|
| 2869 | - // if redirecting to anything other than the main page, add a nonce |
|
| 2870 | - if (isset($query_args['action'])) { |
|
| 2871 | - // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 2872 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2873 | - } |
|
| 2874 | - //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that). |
|
| 2875 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 2876 | - $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args); |
|
| 2877 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 2878 | - if (defined('DOING_AJAX')) { |
|
| 2879 | - $default_data = array( |
|
| 2880 | - 'close' => true, |
|
| 2881 | - 'redirect_url' => $redirect_url, |
|
| 2882 | - 'where' => 'main', |
|
| 2883 | - 'what' => 'append', |
|
| 2884 | - ); |
|
| 2885 | - $this->_template_args['success'] = $success; |
|
| 2886 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data; |
|
| 2887 | - $this->_return_json(); |
|
| 2888 | - } |
|
| 2889 | - wp_safe_redirect($redirect_url); |
|
| 2890 | - exit(); |
|
| 2891 | - } |
|
| 2892 | - |
|
| 2893 | - |
|
| 2894 | - |
|
| 2895 | - /** |
|
| 2896 | - * process any notices before redirecting (or returning ajax request) |
|
| 2897 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 2898 | - * |
|
| 2899 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 2900 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet. |
|
| 2901 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice. |
|
| 2902 | - * @return void |
|
| 2903 | - */ |
|
| 2904 | - protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 2905 | - { |
|
| 2906 | - //first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 2907 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2908 | - $notices = EE_Error::get_notices(false); |
|
| 2909 | - if (empty($this->_template_args['success'])) { |
|
| 2910 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 2911 | - } |
|
| 2912 | - if (empty($this->_template_args['errors'])) { |
|
| 2913 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 2914 | - } |
|
| 2915 | - if (empty($this->_template_args['attention'])) { |
|
| 2916 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 2917 | - } |
|
| 2918 | - } |
|
| 2919 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 2920 | - //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 2921 | - if ( ! defined('DOING_AJAX') || $sticky_notices) { |
|
| 2922 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 2923 | - $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify); |
|
| 2924 | - } |
|
| 2925 | - } |
|
| 2926 | - |
|
| 2927 | - |
|
| 2928 | - |
|
| 2929 | - /** |
|
| 2930 | - * get_action_link_or_button |
|
| 2931 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 2932 | - * |
|
| 2933 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 2934 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) property. |
|
| 2935 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 2936 | - * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 2937 | - * @param string $base_url If this is not provided |
|
| 2938 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 2939 | - * Otherwise this value will be used. |
|
| 2940 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 2941 | - * @return string |
|
| 2942 | - * @throws \EE_Error |
|
| 2943 | - */ |
|
| 2944 | - public function get_action_link_or_button( |
|
| 2945 | - $action, |
|
| 2946 | - $type = 'add', |
|
| 2947 | - $extra_request = array(), |
|
| 2948 | - $class = 'button-primary', |
|
| 2949 | - $base_url = '', |
|
| 2950 | - $exclude_nonce = false |
|
| 2951 | - ) { |
|
| 2952 | - //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 2953 | - if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 2954 | - throw new EE_Error( |
|
| 2955 | - sprintf( |
|
| 2956 | - __( |
|
| 2957 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 2958 | - 'event_espresso' |
|
| 2959 | - ), |
|
| 2960 | - $action |
|
| 2961 | - ) |
|
| 2962 | - ); |
|
| 2963 | - } |
|
| 2964 | - if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 2965 | - throw new EE_Error( |
|
| 2966 | - sprintf( |
|
| 2967 | - __( |
|
| 2968 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 2969 | - 'event_espresso' |
|
| 2970 | - ), |
|
| 2971 | - $type |
|
| 2972 | - ) |
|
| 2973 | - ); |
|
| 2974 | - } |
|
| 2975 | - //finally check user access for this button. |
|
| 2976 | - $has_access = $this->check_user_access($action, true); |
|
| 2977 | - if ( ! $has_access) { |
|
| 2978 | - return ''; |
|
| 2979 | - } |
|
| 2980 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 2981 | - $query_args = array( |
|
| 2982 | - 'action' => $action, |
|
| 2983 | - ); |
|
| 2984 | - //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 2985 | - if ( ! empty($extra_request)) { |
|
| 2986 | - $query_args = array_merge($extra_request, $query_args); |
|
| 2987 | - } |
|
| 2988 | - $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 2989 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 2990 | - } |
|
| 2991 | - |
|
| 2992 | - |
|
| 2993 | - |
|
| 2994 | - /** |
|
| 2995 | - * _per_page_screen_option |
|
| 2996 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 2997 | - * |
|
| 2998 | - * @return void |
|
| 2999 | - */ |
|
| 3000 | - protected function _per_page_screen_option() |
|
| 3001 | - { |
|
| 3002 | - $option = 'per_page'; |
|
| 3003 | - $args = array( |
|
| 3004 | - 'label' => $this->_admin_page_title, |
|
| 3005 | - 'default' => 10, |
|
| 3006 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3007 | - ); |
|
| 3008 | - //ONLY add the screen option if the user has access to it. |
|
| 3009 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 3010 | - add_screen_option($option, $args); |
|
| 3011 | - } |
|
| 3012 | - } |
|
| 3013 | - |
|
| 3014 | - |
|
| 3015 | - |
|
| 3016 | - /** |
|
| 3017 | - * set_per_page_screen_option |
|
| 3018 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3019 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu. |
|
| 3020 | - * |
|
| 3021 | - * @access private |
|
| 3022 | - * @return void |
|
| 3023 | - */ |
|
| 3024 | - private function _set_per_page_screen_options() |
|
| 3025 | - { |
|
| 3026 | - if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3027 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3028 | - if ( ! $user = wp_get_current_user()) { |
|
| 3029 | - return; |
|
| 3030 | - } |
|
| 3031 | - $option = $_POST['wp_screen_options']['option']; |
|
| 3032 | - $value = $_POST['wp_screen_options']['value']; |
|
| 3033 | - if ($option != sanitize_key($option)) { |
|
| 3034 | - return; |
|
| 3035 | - } |
|
| 3036 | - $map_option = $option; |
|
| 3037 | - $option = str_replace('-', '_', $option); |
|
| 3038 | - switch ($map_option) { |
|
| 3039 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3040 | - $value = (int)$value; |
|
| 3041 | - if ($value < 1 || $value > 999) { |
|
| 3042 | - return; |
|
| 3043 | - } |
|
| 3044 | - break; |
|
| 3045 | - default: |
|
| 3046 | - $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value); |
|
| 3047 | - if (false === $value) { |
|
| 3048 | - return; |
|
| 3049 | - } |
|
| 3050 | - break; |
|
| 3051 | - } |
|
| 3052 | - update_user_meta($user->ID, $option, $value); |
|
| 3053 | - wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3054 | - exit; |
|
| 3055 | - } |
|
| 3056 | - } |
|
| 3057 | - |
|
| 3058 | - |
|
| 3059 | - |
|
| 3060 | - /** |
|
| 3061 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3062 | - * |
|
| 3063 | - * @param array $data array that will be assigned to template args. |
|
| 3064 | - */ |
|
| 3065 | - public function set_template_args($data) |
|
| 3066 | - { |
|
| 3067 | - $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3068 | - } |
|
| 3069 | - |
|
| 3070 | - |
|
| 3071 | - |
|
| 3072 | - /** |
|
| 3073 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3074 | - * |
|
| 3075 | - * @access protected |
|
| 3076 | - * @param string $route the route that should receive the transient |
|
| 3077 | - * @param array $data the data that gets sent |
|
| 3078 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a normal route transient. |
|
| 3079 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used when we are adding a transient before page_routes have been defined. |
|
| 3080 | - * @return void |
|
| 3081 | - */ |
|
| 3082 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3083 | - { |
|
| 3084 | - $user_id = get_current_user_id(); |
|
| 3085 | - if ( ! $skip_route_verify) { |
|
| 3086 | - $this->_verify_route($route); |
|
| 3087 | - } |
|
| 3088 | - //now let's set the string for what kind of transient we're setting |
|
| 3089 | - $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3090 | - $data = $notices ? array('notices' => $data) : $data; |
|
| 3091 | - //is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3092 | - $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
|
| 3093 | - if ($existing) { |
|
| 3094 | - $data = array_merge((array)$data, (array)$existing); |
|
| 3095 | - } |
|
| 3096 | - if (is_multisite() && is_network_admin()) { |
|
| 3097 | - set_site_transient($transient, $data, 8); |
|
| 3098 | - } else { |
|
| 3099 | - set_transient($transient, $data, 8); |
|
| 3100 | - } |
|
| 3101 | - } |
|
| 3102 | - |
|
| 3103 | - |
|
| 3104 | - |
|
| 3105 | - /** |
|
| 3106 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3107 | - * |
|
| 3108 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3109 | - * @return mixed data |
|
| 3110 | - */ |
|
| 3111 | - protected function _get_transient($notices = false, $route = false) |
|
| 3112 | - { |
|
| 3113 | - $user_id = get_current_user_id(); |
|
| 3114 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3115 | - $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3116 | - $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
|
| 3117 | - //delete transient after retrieval (just in case it hasn't expired); |
|
| 3118 | - if (is_multisite() && is_network_admin()) { |
|
| 3119 | - delete_site_transient($transient); |
|
| 3120 | - } else { |
|
| 3121 | - delete_transient($transient); |
|
| 3122 | - } |
|
| 3123 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3124 | - } |
|
| 3125 | - |
|
| 3126 | - |
|
| 3127 | - |
|
| 3128 | - /** |
|
| 3129 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later. |
|
| 3130 | - * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.) |
|
| 3131 | - * |
|
| 3132 | - * @return void |
|
| 3133 | - */ |
|
| 3134 | - protected function _transient_garbage_collection() |
|
| 3135 | - { |
|
| 3136 | - global $wpdb; |
|
| 3137 | - //retrieve all existing transients |
|
| 3138 | - $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3139 | - if ($results = $wpdb->get_results($query)) { |
|
| 3140 | - foreach ($results as $result) { |
|
| 3141 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3142 | - get_transient($transient); |
|
| 3143 | - if (is_multisite() && is_network_admin()) { |
|
| 3144 | - get_site_transient($transient); |
|
| 3145 | - } |
|
| 3146 | - } |
|
| 3147 | - } |
|
| 3148 | - } |
|
| 3149 | - |
|
| 3150 | - |
|
| 3151 | - |
|
| 3152 | - /** |
|
| 3153 | - * get_view |
|
| 3154 | - * |
|
| 3155 | - * @access public |
|
| 3156 | - * @return string content of _view property |
|
| 3157 | - */ |
|
| 3158 | - public function get_view() |
|
| 3159 | - { |
|
| 3160 | - return $this->_view; |
|
| 3161 | - } |
|
| 3162 | - |
|
| 3163 | - |
|
| 3164 | - |
|
| 3165 | - /** |
|
| 3166 | - * getter for the protected $_views property |
|
| 3167 | - * |
|
| 3168 | - * @return array |
|
| 3169 | - */ |
|
| 3170 | - public function get_views() |
|
| 3171 | - { |
|
| 3172 | - return $this->_views; |
|
| 3173 | - } |
|
| 3174 | - |
|
| 3175 | - |
|
| 3176 | - |
|
| 3177 | - /** |
|
| 3178 | - * get_current_page |
|
| 3179 | - * |
|
| 3180 | - * @access public |
|
| 3181 | - * @return string _current_page property value |
|
| 3182 | - */ |
|
| 3183 | - public function get_current_page() |
|
| 3184 | - { |
|
| 3185 | - return $this->_current_page; |
|
| 3186 | - } |
|
| 3187 | - |
|
| 3188 | - |
|
| 3189 | - |
|
| 3190 | - /** |
|
| 3191 | - * get_current_view |
|
| 3192 | - * |
|
| 3193 | - * @access public |
|
| 3194 | - * @return string _current_view property value |
|
| 3195 | - */ |
|
| 3196 | - public function get_current_view() |
|
| 3197 | - { |
|
| 3198 | - return $this->_current_view; |
|
| 3199 | - } |
|
| 3200 | - |
|
| 3201 | - |
|
| 3202 | - |
|
| 3203 | - /** |
|
| 3204 | - * get_current_screen |
|
| 3205 | - * |
|
| 3206 | - * @access public |
|
| 3207 | - * @return object The current WP_Screen object |
|
| 3208 | - */ |
|
| 3209 | - public function get_current_screen() |
|
| 3210 | - { |
|
| 3211 | - return $this->_current_screen; |
|
| 3212 | - } |
|
| 3213 | - |
|
| 3214 | - |
|
| 3215 | - |
|
| 3216 | - /** |
|
| 3217 | - * get_current_page_view_url |
|
| 3218 | - * |
|
| 3219 | - * @access public |
|
| 3220 | - * @return string This returns the url for the current_page_view. |
|
| 3221 | - */ |
|
| 3222 | - public function get_current_page_view_url() |
|
| 3223 | - { |
|
| 3224 | - return $this->_current_page_view_url; |
|
| 3225 | - } |
|
| 3226 | - |
|
| 3227 | - |
|
| 3228 | - |
|
| 3229 | - /** |
|
| 3230 | - * just returns the _req_data property |
|
| 3231 | - * |
|
| 3232 | - * @return array |
|
| 3233 | - */ |
|
| 3234 | - public function get_request_data() |
|
| 3235 | - { |
|
| 3236 | - return $this->_req_data; |
|
| 3237 | - } |
|
| 3238 | - |
|
| 3239 | - |
|
| 3240 | - |
|
| 3241 | - /** |
|
| 3242 | - * returns the _req_data protected property |
|
| 3243 | - * |
|
| 3244 | - * @return string |
|
| 3245 | - */ |
|
| 3246 | - public function get_req_action() |
|
| 3247 | - { |
|
| 3248 | - return $this->_req_action; |
|
| 3249 | - } |
|
| 3250 | - |
|
| 3251 | - |
|
| 3252 | - |
|
| 3253 | - /** |
|
| 3254 | - * @return bool value of $_is_caf property |
|
| 3255 | - */ |
|
| 3256 | - public function is_caf() |
|
| 3257 | - { |
|
| 3258 | - return $this->_is_caf; |
|
| 3259 | - } |
|
| 3260 | - |
|
| 3261 | - |
|
| 3262 | - |
|
| 3263 | - /** |
|
| 3264 | - * @return mixed |
|
| 3265 | - */ |
|
| 3266 | - public function default_espresso_metaboxes() |
|
| 3267 | - { |
|
| 3268 | - return $this->_default_espresso_metaboxes; |
|
| 3269 | - } |
|
| 3270 | - |
|
| 3271 | - |
|
| 3272 | - |
|
| 3273 | - /** |
|
| 3274 | - * @return mixed |
|
| 3275 | - */ |
|
| 3276 | - public function admin_base_url() |
|
| 3277 | - { |
|
| 3278 | - return $this->_admin_base_url; |
|
| 3279 | - } |
|
| 3280 | - |
|
| 3281 | - |
|
| 3282 | - |
|
| 3283 | - /** |
|
| 3284 | - * @return mixed |
|
| 3285 | - */ |
|
| 3286 | - public function wp_page_slug() |
|
| 3287 | - { |
|
| 3288 | - return $this->_wp_page_slug; |
|
| 3289 | - } |
|
| 3290 | - |
|
| 3291 | - |
|
| 3292 | - |
|
| 3293 | - /** |
|
| 3294 | - * updates espresso configuration settings |
|
| 3295 | - * |
|
| 3296 | - * @access protected |
|
| 3297 | - * @param string $tab |
|
| 3298 | - * @param EE_Config_Base|EE_Config $config |
|
| 3299 | - * @param string $file file where error occurred |
|
| 3300 | - * @param string $func function where error occurred |
|
| 3301 | - * @param string $line line no where error occurred |
|
| 3302 | - * @return boolean |
|
| 3303 | - */ |
|
| 3304 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 3305 | - { |
|
| 3306 | - //remove any options that are NOT going to be saved with the config settings. |
|
| 3307 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 3308 | - $config->core->ee_ueip_has_notified = true; |
|
| 3309 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 3310 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 3311 | - update_option('ee_ueip_has_notified', true); |
|
| 3312 | - } |
|
| 3313 | - // and save it (note we're also doing the network save here) |
|
| 3314 | - $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 3315 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 3316 | - if ($config_saved && $net_saved) { |
|
| 3317 | - EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 3318 | - return true; |
|
| 3319 | - } else { |
|
| 3320 | - EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 3321 | - return false; |
|
| 3322 | - } |
|
| 3323 | - } |
|
| 3324 | - |
|
| 3325 | - |
|
| 3326 | - |
|
| 3327 | - /** |
|
| 3328 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 3329 | - * |
|
| 3330 | - * @return array |
|
| 3331 | - */ |
|
| 3332 | - public function get_yes_no_values() |
|
| 3333 | - { |
|
| 3334 | - return $this->_yes_no_values; |
|
| 3335 | - } |
|
| 3336 | - |
|
| 3337 | - |
|
| 3338 | - |
|
| 3339 | - protected function _get_dir() |
|
| 3340 | - { |
|
| 3341 | - $reflector = new ReflectionClass(get_class($this)); |
|
| 3342 | - return dirname($reflector->getFileName()); |
|
| 3343 | - } |
|
| 3344 | - |
|
| 3345 | - |
|
| 3346 | - |
|
| 3347 | - /** |
|
| 3348 | - * A helper for getting a "next link". |
|
| 3349 | - * |
|
| 3350 | - * @param string $url The url to link to |
|
| 3351 | - * @param string $class The class to use. |
|
| 3352 | - * @return string |
|
| 3353 | - */ |
|
| 3354 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 3355 | - { |
|
| 3356 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3357 | - } |
|
| 3358 | - |
|
| 3359 | - |
|
| 3360 | - |
|
| 3361 | - /** |
|
| 3362 | - * A helper for getting a "previous link". |
|
| 3363 | - * |
|
| 3364 | - * @param string $url The url to link to |
|
| 3365 | - * @param string $class The class to use. |
|
| 3366 | - * @return string |
|
| 3367 | - */ |
|
| 3368 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 3369 | - { |
|
| 3370 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3371 | - } |
|
| 3372 | - |
|
| 3373 | - |
|
| 3374 | - |
|
| 3375 | - |
|
| 3376 | - |
|
| 3377 | - |
|
| 3378 | - |
|
| 3379 | - //below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 3380 | - /** |
|
| 3381 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data |
|
| 3382 | - * array. |
|
| 3383 | - * |
|
| 3384 | - * @return bool success/fail |
|
| 3385 | - */ |
|
| 3386 | - protected function _process_resend_registration() |
|
| 3387 | - { |
|
| 3388 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 3389 | - do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data); |
|
| 3390 | - return $this->_template_args['success']; |
|
| 3391 | - } |
|
| 3392 | - |
|
| 3393 | - |
|
| 3394 | - |
|
| 3395 | - /** |
|
| 3396 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 3397 | - * |
|
| 3398 | - * @access protected |
|
| 3399 | - * @param \EE_Payment $payment |
|
| 3400 | - * @return bool success/fail |
|
| 3401 | - */ |
|
| 3402 | - protected function _process_payment_notification(EE_Payment $payment) |
|
| 3403 | - { |
|
| 3404 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 3405 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 3406 | - $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment); |
|
| 3407 | - return $this->_template_args['success']; |
|
| 3408 | - } |
|
| 2194 | + } |
|
| 2195 | + |
|
| 2196 | + |
|
| 2197 | + |
|
| 2198 | + /** |
|
| 2199 | + * facade for add_meta_box |
|
| 2200 | + * |
|
| 2201 | + * @param string $action where the metabox get's displayed |
|
| 2202 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2203 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here. |
|
| 2204 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2205 | + * @param string $column what metabox column |
|
| 2206 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2207 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box. |
|
| 2208 | + */ |
|
| 2209 | + public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true) |
|
| 2210 | + { |
|
| 2211 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2212 | + //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2213 | + if (empty($callback_args) && $create_func) { |
|
| 2214 | + $callback_args = array( |
|
| 2215 | + 'template_path' => $this->_template_path, |
|
| 2216 | + 'template_args' => $this->_template_args, |
|
| 2217 | + ); |
|
| 2218 | + } |
|
| 2219 | + //if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2220 | + $call_back_func = $create_func ? create_function('$post, $metabox', |
|
| 2221 | + 'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback; |
|
| 2222 | + add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args); |
|
| 2223 | + } |
|
| 2224 | + |
|
| 2225 | + |
|
| 2226 | + |
|
| 2227 | + /** |
|
| 2228 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2229 | + * |
|
| 2230 | + * @return [type] [description] |
|
| 2231 | + */ |
|
| 2232 | + public function display_admin_page_with_metabox_columns() |
|
| 2233 | + { |
|
| 2234 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2235 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true); |
|
| 2236 | + //the final wrapper |
|
| 2237 | + $this->admin_page_wrapper(); |
|
| 2238 | + } |
|
| 2239 | + |
|
| 2240 | + |
|
| 2241 | + |
|
| 2242 | + /** |
|
| 2243 | + * generates HTML wrapper for an admin details page |
|
| 2244 | + * |
|
| 2245 | + * @access public |
|
| 2246 | + * @return void |
|
| 2247 | + */ |
|
| 2248 | + public function display_admin_page_with_sidebar() |
|
| 2249 | + { |
|
| 2250 | + $this->_display_admin_page(true); |
|
| 2251 | + } |
|
| 2252 | + |
|
| 2253 | + |
|
| 2254 | + |
|
| 2255 | + /** |
|
| 2256 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2257 | + * |
|
| 2258 | + * @access public |
|
| 2259 | + * @return void |
|
| 2260 | + */ |
|
| 2261 | + public function display_admin_page_with_no_sidebar() |
|
| 2262 | + { |
|
| 2263 | + $this->_display_admin_page(); |
|
| 2264 | + } |
|
| 2265 | + |
|
| 2266 | + |
|
| 2267 | + |
|
| 2268 | + /** |
|
| 2269 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2270 | + * |
|
| 2271 | + * @access public |
|
| 2272 | + * @return void |
|
| 2273 | + */ |
|
| 2274 | + public function display_about_admin_page() |
|
| 2275 | + { |
|
| 2276 | + $this->_display_admin_page(false, true); |
|
| 2277 | + } |
|
| 2278 | + |
|
| 2279 | + |
|
| 2280 | + |
|
| 2281 | + /** |
|
| 2282 | + * display_admin_page |
|
| 2283 | + * contains the code for actually displaying an admin page |
|
| 2284 | + * |
|
| 2285 | + * @access private |
|
| 2286 | + * @param boolean $sidebar true with sidebar, false without |
|
| 2287 | + * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2288 | + * @return void |
|
| 2289 | + */ |
|
| 2290 | + private function _display_admin_page($sidebar = false, $about = false) |
|
| 2291 | + { |
|
| 2292 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2293 | + //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2294 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2295 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2296 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2297 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2298 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2299 | + ? 'poststuff' |
|
| 2300 | + : 'espresso-default-admin'; |
|
| 2301 | + $template_path = $sidebar |
|
| 2302 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2303 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2304 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2305 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2306 | + } |
|
| 2307 | + $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
|
| 2308 | + $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : ''; |
|
| 2309 | + $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''; |
|
| 2310 | + $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''; |
|
| 2311 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2312 | + // the final template wrapper |
|
| 2313 | + $this->admin_page_wrapper($about); |
|
| 2314 | + } |
|
| 2315 | + |
|
| 2316 | + |
|
| 2317 | + |
|
| 2318 | + /** |
|
| 2319 | + * This is used to display caf preview pages. |
|
| 2320 | + * |
|
| 2321 | + * @since 4.3.2 |
|
| 2322 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2323 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2324 | + * @return void |
|
| 2325 | + * @throws \EE_Error |
|
| 2326 | + */ |
|
| 2327 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2328 | + { |
|
| 2329 | + //let's generate a default preview action button if there isn't one already present. |
|
| 2330 | + $this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso'); |
|
| 2331 | + $buy_now_url = add_query_arg( |
|
| 2332 | + array( |
|
| 2333 | + 'ee_ver' => 'ee4', |
|
| 2334 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2335 | + 'utm_medium' => 'link', |
|
| 2336 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2337 | + 'utm_content' => 'buy_now_button', |
|
| 2338 | + ), |
|
| 2339 | + 'http://eventespresso.com/pricing/' |
|
| 2340 | + ); |
|
| 2341 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2342 | + ? $this->get_action_link_or_button( |
|
| 2343 | + '', |
|
| 2344 | + 'buy_now', |
|
| 2345 | + array(), |
|
| 2346 | + 'button-primary button-large', |
|
| 2347 | + $buy_now_url, |
|
| 2348 | + true |
|
| 2349 | + ) |
|
| 2350 | + : $this->_template_args['preview_action_button']; |
|
| 2351 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php'; |
|
| 2352 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2353 | + $template_path, |
|
| 2354 | + $this->_template_args, |
|
| 2355 | + true |
|
| 2356 | + ); |
|
| 2357 | + $this->_display_admin_page($display_sidebar); |
|
| 2358 | + } |
|
| 2359 | + |
|
| 2360 | + |
|
| 2361 | + |
|
| 2362 | + /** |
|
| 2363 | + * display_admin_list_table_page_with_sidebar |
|
| 2364 | + * generates HTML wrapper for an admin_page with list_table |
|
| 2365 | + * |
|
| 2366 | + * @access public |
|
| 2367 | + * @return void |
|
| 2368 | + */ |
|
| 2369 | + public function display_admin_list_table_page_with_sidebar() |
|
| 2370 | + { |
|
| 2371 | + $this->_display_admin_list_table_page(true); |
|
| 2372 | + } |
|
| 2373 | + |
|
| 2374 | + |
|
| 2375 | + |
|
| 2376 | + /** |
|
| 2377 | + * display_admin_list_table_page_with_no_sidebar |
|
| 2378 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2379 | + * |
|
| 2380 | + * @access public |
|
| 2381 | + * @return void |
|
| 2382 | + */ |
|
| 2383 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 2384 | + { |
|
| 2385 | + $this->_display_admin_list_table_page(); |
|
| 2386 | + } |
|
| 2387 | + |
|
| 2388 | + |
|
| 2389 | + |
|
| 2390 | + /** |
|
| 2391 | + * generates html wrapper for an admin_list_table page |
|
| 2392 | + * |
|
| 2393 | + * @access private |
|
| 2394 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2395 | + * @return void |
|
| 2396 | + */ |
|
| 2397 | + private function _display_admin_list_table_page($sidebar = false) |
|
| 2398 | + { |
|
| 2399 | + //setup search attributes |
|
| 2400 | + $this->_set_search_attributes(); |
|
| 2401 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2402 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2403 | + $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 2404 | + ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 2405 | + : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 2406 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2407 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 2408 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2409 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2410 | + if ( ! empty($ajax_sorting_callback)) { |
|
| 2411 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2412 | + $ajax_sorting_callback . '_nonce', |
|
| 2413 | + $ajax_sorting_callback . '_nonce', |
|
| 2414 | + false, |
|
| 2415 | + false |
|
| 2416 | + ); |
|
| 2417 | + // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
|
| 2418 | + // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
|
| 2419 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />'; |
|
| 2420 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />'; |
|
| 2421 | + } else { |
|
| 2422 | + $sortable_list_table_form_fields = ''; |
|
| 2423 | + } |
|
| 2424 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2425 | + $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : ''; |
|
| 2426 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2427 | + $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
|
| 2428 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2429 | + //display message about search results? |
|
| 2430 | + $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 2431 | + ? '<p class="ee-search-results">' . sprintf( |
|
| 2432 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 2433 | + trim($this->_req_data['s'], '%') |
|
| 2434 | + ) . '</p>' |
|
| 2435 | + : ''; |
|
| 2436 | + // filter before_list_table template arg |
|
| 2437 | + $this->_template_args['before_list_table'] = apply_filters( |
|
| 2438 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2439 | + $this->_template_args['before_list_table'], |
|
| 2440 | + $this->page_slug, |
|
| 2441 | + $this->_req_data, |
|
| 2442 | + $this->_req_action |
|
| 2443 | + ); |
|
| 2444 | + // convert to array and filter again |
|
| 2445 | + // arrays are easier to inject new items in a specific location, |
|
| 2446 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 2447 | + $this->_template_args['before_list_table'] = implode( |
|
| 2448 | + " \n", |
|
| 2449 | + (array) apply_filters( |
|
| 2450 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 2451 | + (array) $this->_template_args['before_list_table'], |
|
| 2452 | + $this->page_slug, |
|
| 2453 | + $this->_req_data, |
|
| 2454 | + $this->_req_action |
|
| 2455 | + ) |
|
| 2456 | + ); |
|
| 2457 | + // filter after_list_table template arg |
|
| 2458 | + $this->_template_args['after_list_table'] = apply_filters( |
|
| 2459 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 2460 | + $this->_template_args['after_list_table'], |
|
| 2461 | + $this->page_slug, |
|
| 2462 | + $this->_req_data, |
|
| 2463 | + $this->_req_action |
|
| 2464 | + ); |
|
| 2465 | + // convert to array and filter again |
|
| 2466 | + // arrays are easier to inject new items in a specific location, |
|
| 2467 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 2468 | + $this->_template_args['after_list_table'] = implode( |
|
| 2469 | + " \n", |
|
| 2470 | + (array) apply_filters( |
|
| 2471 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 2472 | + (array) $this->_template_args['after_list_table'], |
|
| 2473 | + $this->page_slug, |
|
| 2474 | + $this->_req_data, |
|
| 2475 | + $this->_req_action |
|
| 2476 | + ) |
|
| 2477 | + ); |
|
| 2478 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2479 | + $template_path, |
|
| 2480 | + $this->_template_args, |
|
| 2481 | + true |
|
| 2482 | + ); |
|
| 2483 | + // the final template wrapper |
|
| 2484 | + if ($sidebar) { |
|
| 2485 | + $this->display_admin_page_with_sidebar(); |
|
| 2486 | + } else { |
|
| 2487 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2488 | + } |
|
| 2489 | + } |
|
| 2490 | + |
|
| 2491 | + |
|
| 2492 | + |
|
| 2493 | + /** |
|
| 2494 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend. |
|
| 2495 | + * $items are expected in an array in the following format: |
|
| 2496 | + * $legend_items = array( |
|
| 2497 | + * 'item_id' => array( |
|
| 2498 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 2499 | + * 'desc' => __('localized description of item'); |
|
| 2500 | + * ) |
|
| 2501 | + * ); |
|
| 2502 | + * |
|
| 2503 | + * @param array $items see above for format of array |
|
| 2504 | + * @return string html string of legend |
|
| 2505 | + */ |
|
| 2506 | + protected function _display_legend($items) |
|
| 2507 | + { |
|
| 2508 | + $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this); |
|
| 2509 | + $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php'; |
|
| 2510 | + return EEH_Template::display_template($legend_template, $this->_template_args, true); |
|
| 2511 | + } |
|
| 2512 | + |
|
| 2513 | + |
|
| 2514 | + |
|
| 2515 | + /** |
|
| 2516 | + * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 2517 | + * |
|
| 2518 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed. |
|
| 2519 | + * The returned json object is created from an array in the following format: |
|
| 2520 | + * array( |
|
| 2521 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 2522 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 2523 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 2524 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 2525 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any |
|
| 2526 | + * specific template args that might be included in here) |
|
| 2527 | + * ) |
|
| 2528 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 2529 | + * @return void |
|
| 2530 | + */ |
|
| 2531 | + protected function _return_json($sticky_notices = false) |
|
| 2532 | + { |
|
| 2533 | + //make sure any EE_Error notices have been handled. |
|
| 2534 | + $this->_process_notices(array(), true, $sticky_notices); |
|
| 2535 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 2536 | + unset($this->_template_args['data']); |
|
| 2537 | + $json = array( |
|
| 2538 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 2539 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 2540 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 2541 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 2542 | + 'notices' => EE_Error::get_notices(), |
|
| 2543 | + 'content' => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '', |
|
| 2544 | + 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 2545 | + 'isEEajax' => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 2546 | + ); |
|
| 2547 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 2548 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 2549 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 2550 | + } |
|
| 2551 | + echo wp_json_encode($json); |
|
| 2552 | + |
|
| 2553 | + exit(); |
|
| 2554 | + } |
|
| 2555 | + |
|
| 2556 | + |
|
| 2557 | + |
|
| 2558 | + /** |
|
| 2559 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 2560 | + * |
|
| 2561 | + * @return void |
|
| 2562 | + * @throws EE_Error |
|
| 2563 | + */ |
|
| 2564 | + public function return_json() |
|
| 2565 | + { |
|
| 2566 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2567 | + $this->_return_json(); |
|
| 2568 | + } else { |
|
| 2569 | + throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__)); |
|
| 2570 | + } |
|
| 2571 | + } |
|
| 2572 | + |
|
| 2573 | + |
|
| 2574 | + |
|
| 2575 | + /** |
|
| 2576 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 2577 | + * |
|
| 2578 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 2579 | + * @access public |
|
| 2580 | + */ |
|
| 2581 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 2582 | + { |
|
| 2583 | + $this->_hook_obj = $hook_obj; |
|
| 2584 | + } |
|
| 2585 | + |
|
| 2586 | + |
|
| 2587 | + |
|
| 2588 | + /** |
|
| 2589 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 2590 | + * |
|
| 2591 | + * @access public |
|
| 2592 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
| 2593 | + * @return void |
|
| 2594 | + */ |
|
| 2595 | + public function admin_page_wrapper($about = false) |
|
| 2596 | + { |
|
| 2597 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2598 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 2599 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 2600 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 2601 | + $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2602 | + isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''); |
|
| 2603 | + $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2604 | + isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''); |
|
| 2605 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 2606 | + // load settings page wrapper template |
|
| 2607 | + $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php'; |
|
| 2608 | + //about page? |
|
| 2609 | + $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path; |
|
| 2610 | + if (defined('DOING_AJAX')) { |
|
| 2611 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2612 | + $this->_return_json(); |
|
| 2613 | + } else { |
|
| 2614 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 2615 | + } |
|
| 2616 | + } |
|
| 2617 | + |
|
| 2618 | + |
|
| 2619 | + |
|
| 2620 | + /** |
|
| 2621 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 2622 | + * |
|
| 2623 | + * @return string html |
|
| 2624 | + */ |
|
| 2625 | + protected function _get_main_nav_tabs() |
|
| 2626 | + { |
|
| 2627 | + //let's generate the html using the EEH_Tabbed_Content helper. We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array) |
|
| 2628 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 2629 | + } |
|
| 2630 | + |
|
| 2631 | + |
|
| 2632 | + |
|
| 2633 | + /** |
|
| 2634 | + * sort nav tabs |
|
| 2635 | + * |
|
| 2636 | + * @access public |
|
| 2637 | + * @param $a |
|
| 2638 | + * @param $b |
|
| 2639 | + * @return int |
|
| 2640 | + */ |
|
| 2641 | + private function _sort_nav_tabs($a, $b) |
|
| 2642 | + { |
|
| 2643 | + if ($a['order'] == $b['order']) { |
|
| 2644 | + return 0; |
|
| 2645 | + } |
|
| 2646 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 2647 | + } |
|
| 2648 | + |
|
| 2649 | + |
|
| 2650 | + |
|
| 2651 | + /** |
|
| 2652 | + * generates HTML for the forms used on admin pages |
|
| 2653 | + * |
|
| 2654 | + * @access protected |
|
| 2655 | + * @param array $input_vars - array of input field details |
|
| 2656 | + * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to use) |
|
| 2657 | + * @return string |
|
| 2658 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 2659 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 2660 | + */ |
|
| 2661 | + protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 2662 | + { |
|
| 2663 | + $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 2664 | + return $content; |
|
| 2665 | + } |
|
| 2666 | + |
|
| 2667 | + |
|
| 2668 | + |
|
| 2669 | + /** |
|
| 2670 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 2671 | + * |
|
| 2672 | + * @access protected |
|
| 2673 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & Close" button. |
|
| 2674 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close') |
|
| 2675 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button). We can also use this to just dump default actions by submitting some other value. |
|
| 2676 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling). |
|
| 2677 | + */ |
|
| 2678 | + protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 2679 | + { |
|
| 2680 | + //make sure $text and $actions are in an array |
|
| 2681 | + $text = (array)$text; |
|
| 2682 | + $actions = (array)$actions; |
|
| 2683 | + $referrer_url = empty($referrer) ? '' : $referrer; |
|
| 2684 | + $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />' |
|
| 2685 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />'; |
|
| 2686 | + $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso')); |
|
| 2687 | + $default_names = array('save', 'save_and_close'); |
|
| 2688 | + //add in a hidden index for the current page (so save and close redirects properly) |
|
| 2689 | + $this->_template_args['save_buttons'] = $referrer_url; |
|
| 2690 | + foreach ($button_text as $key => $button) { |
|
| 2691 | + $ref = $default_names[$key]; |
|
| 2692 | + $id = $this->_current_view . '_' . $ref; |
|
| 2693 | + $name = ! empty($actions) ? $actions[$key] : $ref; |
|
| 2694 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />'; |
|
| 2695 | + if ( ! $both) { |
|
| 2696 | + break; |
|
| 2697 | + } |
|
| 2698 | + } |
|
| 2699 | + } |
|
| 2700 | + |
|
| 2701 | + |
|
| 2702 | + |
|
| 2703 | + /** |
|
| 2704 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 2705 | + * |
|
| 2706 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 2707 | + * @since 4.6.0 |
|
| 2708 | + * @param string $route |
|
| 2709 | + * @param array $additional_hidden_fields |
|
| 2710 | + */ |
|
| 2711 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 2712 | + { |
|
| 2713 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 2714 | + } |
|
| 2715 | + |
|
| 2716 | + |
|
| 2717 | + |
|
| 2718 | + /** |
|
| 2719 | + * set form open and close tags on add/edit pages. |
|
| 2720 | + * |
|
| 2721 | + * @access protected |
|
| 2722 | + * @param string $route the route you want the form to direct to |
|
| 2723 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 2724 | + * @return void |
|
| 2725 | + */ |
|
| 2726 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 2727 | + { |
|
| 2728 | + if (empty($route)) { |
|
| 2729 | + $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso'); |
|
| 2730 | + $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__); |
|
| 2731 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2732 | + } |
|
| 2733 | + // open form |
|
| 2734 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >'; |
|
| 2735 | + // add nonce |
|
| 2736 | + $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 2737 | + // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
|
| 2738 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 2739 | + // add REQUIRED form action |
|
| 2740 | + $hidden_fields = array( |
|
| 2741 | + 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 2742 | + ); |
|
| 2743 | + // merge arrays |
|
| 2744 | + $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields; |
|
| 2745 | + // generate form fields |
|
| 2746 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 2747 | + // add fields to form |
|
| 2748 | + foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 2749 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 2750 | + } |
|
| 2751 | + // close form |
|
| 2752 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 2753 | + } |
|
| 2754 | + |
|
| 2755 | + |
|
| 2756 | + |
|
| 2757 | + /** |
|
| 2758 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 2759 | + * discovered it would be useful for external code to have access. |
|
| 2760 | + * |
|
| 2761 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 2762 | + * @since 4.5.0 |
|
| 2763 | + */ |
|
| 2764 | + public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false) |
|
| 2765 | + { |
|
| 2766 | + $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite); |
|
| 2767 | + } |
|
| 2768 | + |
|
| 2769 | + |
|
| 2770 | + |
|
| 2771 | + /** |
|
| 2772 | + * _redirect_after_action |
|
| 2773 | + * |
|
| 2774 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
| 2775 | + * @param string $what - what the action was performed on |
|
| 2776 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 2777 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin action is completed |
|
| 2778 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show. |
|
| 2779 | + * @access protected |
|
| 2780 | + * @return void |
|
| 2781 | + */ |
|
| 2782 | + protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false) |
|
| 2783 | + { |
|
| 2784 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2785 | + //class name for actions/filters. |
|
| 2786 | + $classname = get_class($this); |
|
| 2787 | + //set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url |
|
| 2788 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 2789 | + $notices = EE_Error::get_notices(false); |
|
| 2790 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 2791 | + if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 2792 | + EE_Error::overwrite_success(); |
|
| 2793 | + } |
|
| 2794 | + if ( ! empty($what) && ! empty($action_desc)) { |
|
| 2795 | + // how many records affected ? more than one record ? or just one ? |
|
| 2796 | + if ($success > 1 && empty($notices['errors'])) { |
|
| 2797 | + // set plural msg |
|
| 2798 | + EE_Error::add_success( |
|
| 2799 | + sprintf( |
|
| 2800 | + __('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 2801 | + $what, |
|
| 2802 | + $action_desc |
|
| 2803 | + ), |
|
| 2804 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2805 | + ); |
|
| 2806 | + } else if ($success == 1 && empty($notices['errors'])) { |
|
| 2807 | + // set singular msg |
|
| 2808 | + EE_Error::add_success( |
|
| 2809 | + sprintf( |
|
| 2810 | + __('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 2811 | + $what, |
|
| 2812 | + $action_desc |
|
| 2813 | + ), |
|
| 2814 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2815 | + ); |
|
| 2816 | + } |
|
| 2817 | + } |
|
| 2818 | + // check that $query_args isn't something crazy |
|
| 2819 | + if ( ! is_array($query_args)) { |
|
| 2820 | + $query_args = array(); |
|
| 2821 | + } |
|
| 2822 | + /** |
|
| 2823 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 2824 | + * redirections on save and close actions |
|
| 2825 | + * |
|
| 2826 | + * @since 4.2.0 |
|
| 2827 | + * @param array $query_args The original query_args array coming into the |
|
| 2828 | + * method. |
|
| 2829 | + */ |
|
| 2830 | + do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args); |
|
| 2831 | + //calculate where we're going (if we have a "save and close" button pushed) |
|
| 2832 | + if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) { |
|
| 2833 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 2834 | + $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 2835 | + // regenerate query args array from referrer URL |
|
| 2836 | + parse_str($parsed_url['query'], $query_args); |
|
| 2837 | + // correct page and action will be in the query args now |
|
| 2838 | + $redirect_url = admin_url('admin.php'); |
|
| 2839 | + } |
|
| 2840 | + //merge any default query_args set in _default_route_query_args property |
|
| 2841 | + if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 2842 | + $args_to_merge = array(); |
|
| 2843 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 2844 | + //is there a wp_referer array in our _default_route_query_args property? |
|
| 2845 | + if ($query_param == 'wp_referer') { |
|
| 2846 | + $query_value = (array)$query_value; |
|
| 2847 | + foreach ($query_value as $reference => $value) { |
|
| 2848 | + if (strpos($reference, 'nonce') !== false) { |
|
| 2849 | + continue; |
|
| 2850 | + } |
|
| 2851 | + //finally we will override any arguments in the referer with |
|
| 2852 | + //what might be set on the _default_route_query_args array. |
|
| 2853 | + if (isset($this->_default_route_query_args[$reference])) { |
|
| 2854 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 2855 | + } else { |
|
| 2856 | + $args_to_merge[$reference] = urlencode($value); |
|
| 2857 | + } |
|
| 2858 | + } |
|
| 2859 | + continue; |
|
| 2860 | + } |
|
| 2861 | + $args_to_merge[$query_param] = $query_value; |
|
| 2862 | + } |
|
| 2863 | + //now let's merge these arguments but override with what was specifically sent in to the |
|
| 2864 | + //redirect. |
|
| 2865 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 2866 | + } |
|
| 2867 | + $this->_process_notices($query_args); |
|
| 2868 | + // generate redirect url |
|
| 2869 | + // if redirecting to anything other than the main page, add a nonce |
|
| 2870 | + if (isset($query_args['action'])) { |
|
| 2871 | + // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 2872 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2873 | + } |
|
| 2874 | + //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that). |
|
| 2875 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 2876 | + $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args); |
|
| 2877 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 2878 | + if (defined('DOING_AJAX')) { |
|
| 2879 | + $default_data = array( |
|
| 2880 | + 'close' => true, |
|
| 2881 | + 'redirect_url' => $redirect_url, |
|
| 2882 | + 'where' => 'main', |
|
| 2883 | + 'what' => 'append', |
|
| 2884 | + ); |
|
| 2885 | + $this->_template_args['success'] = $success; |
|
| 2886 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data; |
|
| 2887 | + $this->_return_json(); |
|
| 2888 | + } |
|
| 2889 | + wp_safe_redirect($redirect_url); |
|
| 2890 | + exit(); |
|
| 2891 | + } |
|
| 2892 | + |
|
| 2893 | + |
|
| 2894 | + |
|
| 2895 | + /** |
|
| 2896 | + * process any notices before redirecting (or returning ajax request) |
|
| 2897 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 2898 | + * |
|
| 2899 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 2900 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet. |
|
| 2901 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice. |
|
| 2902 | + * @return void |
|
| 2903 | + */ |
|
| 2904 | + protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 2905 | + { |
|
| 2906 | + //first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 2907 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2908 | + $notices = EE_Error::get_notices(false); |
|
| 2909 | + if (empty($this->_template_args['success'])) { |
|
| 2910 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 2911 | + } |
|
| 2912 | + if (empty($this->_template_args['errors'])) { |
|
| 2913 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 2914 | + } |
|
| 2915 | + if (empty($this->_template_args['attention'])) { |
|
| 2916 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 2917 | + } |
|
| 2918 | + } |
|
| 2919 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 2920 | + //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 2921 | + if ( ! defined('DOING_AJAX') || $sticky_notices) { |
|
| 2922 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 2923 | + $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify); |
|
| 2924 | + } |
|
| 2925 | + } |
|
| 2926 | + |
|
| 2927 | + |
|
| 2928 | + |
|
| 2929 | + /** |
|
| 2930 | + * get_action_link_or_button |
|
| 2931 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 2932 | + * |
|
| 2933 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 2934 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) property. |
|
| 2935 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 2936 | + * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 2937 | + * @param string $base_url If this is not provided |
|
| 2938 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 2939 | + * Otherwise this value will be used. |
|
| 2940 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 2941 | + * @return string |
|
| 2942 | + * @throws \EE_Error |
|
| 2943 | + */ |
|
| 2944 | + public function get_action_link_or_button( |
|
| 2945 | + $action, |
|
| 2946 | + $type = 'add', |
|
| 2947 | + $extra_request = array(), |
|
| 2948 | + $class = 'button-primary', |
|
| 2949 | + $base_url = '', |
|
| 2950 | + $exclude_nonce = false |
|
| 2951 | + ) { |
|
| 2952 | + //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 2953 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 2954 | + throw new EE_Error( |
|
| 2955 | + sprintf( |
|
| 2956 | + __( |
|
| 2957 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 2958 | + 'event_espresso' |
|
| 2959 | + ), |
|
| 2960 | + $action |
|
| 2961 | + ) |
|
| 2962 | + ); |
|
| 2963 | + } |
|
| 2964 | + if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 2965 | + throw new EE_Error( |
|
| 2966 | + sprintf( |
|
| 2967 | + __( |
|
| 2968 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 2969 | + 'event_espresso' |
|
| 2970 | + ), |
|
| 2971 | + $type |
|
| 2972 | + ) |
|
| 2973 | + ); |
|
| 2974 | + } |
|
| 2975 | + //finally check user access for this button. |
|
| 2976 | + $has_access = $this->check_user_access($action, true); |
|
| 2977 | + if ( ! $has_access) { |
|
| 2978 | + return ''; |
|
| 2979 | + } |
|
| 2980 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 2981 | + $query_args = array( |
|
| 2982 | + 'action' => $action, |
|
| 2983 | + ); |
|
| 2984 | + //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 2985 | + if ( ! empty($extra_request)) { |
|
| 2986 | + $query_args = array_merge($extra_request, $query_args); |
|
| 2987 | + } |
|
| 2988 | + $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 2989 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 2990 | + } |
|
| 2991 | + |
|
| 2992 | + |
|
| 2993 | + |
|
| 2994 | + /** |
|
| 2995 | + * _per_page_screen_option |
|
| 2996 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 2997 | + * |
|
| 2998 | + * @return void |
|
| 2999 | + */ |
|
| 3000 | + protected function _per_page_screen_option() |
|
| 3001 | + { |
|
| 3002 | + $option = 'per_page'; |
|
| 3003 | + $args = array( |
|
| 3004 | + 'label' => $this->_admin_page_title, |
|
| 3005 | + 'default' => 10, |
|
| 3006 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3007 | + ); |
|
| 3008 | + //ONLY add the screen option if the user has access to it. |
|
| 3009 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 3010 | + add_screen_option($option, $args); |
|
| 3011 | + } |
|
| 3012 | + } |
|
| 3013 | + |
|
| 3014 | + |
|
| 3015 | + |
|
| 3016 | + /** |
|
| 3017 | + * set_per_page_screen_option |
|
| 3018 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3019 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu. |
|
| 3020 | + * |
|
| 3021 | + * @access private |
|
| 3022 | + * @return void |
|
| 3023 | + */ |
|
| 3024 | + private function _set_per_page_screen_options() |
|
| 3025 | + { |
|
| 3026 | + if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3027 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3028 | + if ( ! $user = wp_get_current_user()) { |
|
| 3029 | + return; |
|
| 3030 | + } |
|
| 3031 | + $option = $_POST['wp_screen_options']['option']; |
|
| 3032 | + $value = $_POST['wp_screen_options']['value']; |
|
| 3033 | + if ($option != sanitize_key($option)) { |
|
| 3034 | + return; |
|
| 3035 | + } |
|
| 3036 | + $map_option = $option; |
|
| 3037 | + $option = str_replace('-', '_', $option); |
|
| 3038 | + switch ($map_option) { |
|
| 3039 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3040 | + $value = (int)$value; |
|
| 3041 | + if ($value < 1 || $value > 999) { |
|
| 3042 | + return; |
|
| 3043 | + } |
|
| 3044 | + break; |
|
| 3045 | + default: |
|
| 3046 | + $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value); |
|
| 3047 | + if (false === $value) { |
|
| 3048 | + return; |
|
| 3049 | + } |
|
| 3050 | + break; |
|
| 3051 | + } |
|
| 3052 | + update_user_meta($user->ID, $option, $value); |
|
| 3053 | + wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3054 | + exit; |
|
| 3055 | + } |
|
| 3056 | + } |
|
| 3057 | + |
|
| 3058 | + |
|
| 3059 | + |
|
| 3060 | + /** |
|
| 3061 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3062 | + * |
|
| 3063 | + * @param array $data array that will be assigned to template args. |
|
| 3064 | + */ |
|
| 3065 | + public function set_template_args($data) |
|
| 3066 | + { |
|
| 3067 | + $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3068 | + } |
|
| 3069 | + |
|
| 3070 | + |
|
| 3071 | + |
|
| 3072 | + /** |
|
| 3073 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3074 | + * |
|
| 3075 | + * @access protected |
|
| 3076 | + * @param string $route the route that should receive the transient |
|
| 3077 | + * @param array $data the data that gets sent |
|
| 3078 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a normal route transient. |
|
| 3079 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used when we are adding a transient before page_routes have been defined. |
|
| 3080 | + * @return void |
|
| 3081 | + */ |
|
| 3082 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3083 | + { |
|
| 3084 | + $user_id = get_current_user_id(); |
|
| 3085 | + if ( ! $skip_route_verify) { |
|
| 3086 | + $this->_verify_route($route); |
|
| 3087 | + } |
|
| 3088 | + //now let's set the string for what kind of transient we're setting |
|
| 3089 | + $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3090 | + $data = $notices ? array('notices' => $data) : $data; |
|
| 3091 | + //is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3092 | + $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
|
| 3093 | + if ($existing) { |
|
| 3094 | + $data = array_merge((array)$data, (array)$existing); |
|
| 3095 | + } |
|
| 3096 | + if (is_multisite() && is_network_admin()) { |
|
| 3097 | + set_site_transient($transient, $data, 8); |
|
| 3098 | + } else { |
|
| 3099 | + set_transient($transient, $data, 8); |
|
| 3100 | + } |
|
| 3101 | + } |
|
| 3102 | + |
|
| 3103 | + |
|
| 3104 | + |
|
| 3105 | + /** |
|
| 3106 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3107 | + * |
|
| 3108 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3109 | + * @return mixed data |
|
| 3110 | + */ |
|
| 3111 | + protected function _get_transient($notices = false, $route = false) |
|
| 3112 | + { |
|
| 3113 | + $user_id = get_current_user_id(); |
|
| 3114 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3115 | + $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3116 | + $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
|
| 3117 | + //delete transient after retrieval (just in case it hasn't expired); |
|
| 3118 | + if (is_multisite() && is_network_admin()) { |
|
| 3119 | + delete_site_transient($transient); |
|
| 3120 | + } else { |
|
| 3121 | + delete_transient($transient); |
|
| 3122 | + } |
|
| 3123 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3124 | + } |
|
| 3125 | + |
|
| 3126 | + |
|
| 3127 | + |
|
| 3128 | + /** |
|
| 3129 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later. |
|
| 3130 | + * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.) |
|
| 3131 | + * |
|
| 3132 | + * @return void |
|
| 3133 | + */ |
|
| 3134 | + protected function _transient_garbage_collection() |
|
| 3135 | + { |
|
| 3136 | + global $wpdb; |
|
| 3137 | + //retrieve all existing transients |
|
| 3138 | + $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3139 | + if ($results = $wpdb->get_results($query)) { |
|
| 3140 | + foreach ($results as $result) { |
|
| 3141 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3142 | + get_transient($transient); |
|
| 3143 | + if (is_multisite() && is_network_admin()) { |
|
| 3144 | + get_site_transient($transient); |
|
| 3145 | + } |
|
| 3146 | + } |
|
| 3147 | + } |
|
| 3148 | + } |
|
| 3149 | + |
|
| 3150 | + |
|
| 3151 | + |
|
| 3152 | + /** |
|
| 3153 | + * get_view |
|
| 3154 | + * |
|
| 3155 | + * @access public |
|
| 3156 | + * @return string content of _view property |
|
| 3157 | + */ |
|
| 3158 | + public function get_view() |
|
| 3159 | + { |
|
| 3160 | + return $this->_view; |
|
| 3161 | + } |
|
| 3162 | + |
|
| 3163 | + |
|
| 3164 | + |
|
| 3165 | + /** |
|
| 3166 | + * getter for the protected $_views property |
|
| 3167 | + * |
|
| 3168 | + * @return array |
|
| 3169 | + */ |
|
| 3170 | + public function get_views() |
|
| 3171 | + { |
|
| 3172 | + return $this->_views; |
|
| 3173 | + } |
|
| 3174 | + |
|
| 3175 | + |
|
| 3176 | + |
|
| 3177 | + /** |
|
| 3178 | + * get_current_page |
|
| 3179 | + * |
|
| 3180 | + * @access public |
|
| 3181 | + * @return string _current_page property value |
|
| 3182 | + */ |
|
| 3183 | + public function get_current_page() |
|
| 3184 | + { |
|
| 3185 | + return $this->_current_page; |
|
| 3186 | + } |
|
| 3187 | + |
|
| 3188 | + |
|
| 3189 | + |
|
| 3190 | + /** |
|
| 3191 | + * get_current_view |
|
| 3192 | + * |
|
| 3193 | + * @access public |
|
| 3194 | + * @return string _current_view property value |
|
| 3195 | + */ |
|
| 3196 | + public function get_current_view() |
|
| 3197 | + { |
|
| 3198 | + return $this->_current_view; |
|
| 3199 | + } |
|
| 3200 | + |
|
| 3201 | + |
|
| 3202 | + |
|
| 3203 | + /** |
|
| 3204 | + * get_current_screen |
|
| 3205 | + * |
|
| 3206 | + * @access public |
|
| 3207 | + * @return object The current WP_Screen object |
|
| 3208 | + */ |
|
| 3209 | + public function get_current_screen() |
|
| 3210 | + { |
|
| 3211 | + return $this->_current_screen; |
|
| 3212 | + } |
|
| 3213 | + |
|
| 3214 | + |
|
| 3215 | + |
|
| 3216 | + /** |
|
| 3217 | + * get_current_page_view_url |
|
| 3218 | + * |
|
| 3219 | + * @access public |
|
| 3220 | + * @return string This returns the url for the current_page_view. |
|
| 3221 | + */ |
|
| 3222 | + public function get_current_page_view_url() |
|
| 3223 | + { |
|
| 3224 | + return $this->_current_page_view_url; |
|
| 3225 | + } |
|
| 3226 | + |
|
| 3227 | + |
|
| 3228 | + |
|
| 3229 | + /** |
|
| 3230 | + * just returns the _req_data property |
|
| 3231 | + * |
|
| 3232 | + * @return array |
|
| 3233 | + */ |
|
| 3234 | + public function get_request_data() |
|
| 3235 | + { |
|
| 3236 | + return $this->_req_data; |
|
| 3237 | + } |
|
| 3238 | + |
|
| 3239 | + |
|
| 3240 | + |
|
| 3241 | + /** |
|
| 3242 | + * returns the _req_data protected property |
|
| 3243 | + * |
|
| 3244 | + * @return string |
|
| 3245 | + */ |
|
| 3246 | + public function get_req_action() |
|
| 3247 | + { |
|
| 3248 | + return $this->_req_action; |
|
| 3249 | + } |
|
| 3250 | + |
|
| 3251 | + |
|
| 3252 | + |
|
| 3253 | + /** |
|
| 3254 | + * @return bool value of $_is_caf property |
|
| 3255 | + */ |
|
| 3256 | + public function is_caf() |
|
| 3257 | + { |
|
| 3258 | + return $this->_is_caf; |
|
| 3259 | + } |
|
| 3260 | + |
|
| 3261 | + |
|
| 3262 | + |
|
| 3263 | + /** |
|
| 3264 | + * @return mixed |
|
| 3265 | + */ |
|
| 3266 | + public function default_espresso_metaboxes() |
|
| 3267 | + { |
|
| 3268 | + return $this->_default_espresso_metaboxes; |
|
| 3269 | + } |
|
| 3270 | + |
|
| 3271 | + |
|
| 3272 | + |
|
| 3273 | + /** |
|
| 3274 | + * @return mixed |
|
| 3275 | + */ |
|
| 3276 | + public function admin_base_url() |
|
| 3277 | + { |
|
| 3278 | + return $this->_admin_base_url; |
|
| 3279 | + } |
|
| 3280 | + |
|
| 3281 | + |
|
| 3282 | + |
|
| 3283 | + /** |
|
| 3284 | + * @return mixed |
|
| 3285 | + */ |
|
| 3286 | + public function wp_page_slug() |
|
| 3287 | + { |
|
| 3288 | + return $this->_wp_page_slug; |
|
| 3289 | + } |
|
| 3290 | + |
|
| 3291 | + |
|
| 3292 | + |
|
| 3293 | + /** |
|
| 3294 | + * updates espresso configuration settings |
|
| 3295 | + * |
|
| 3296 | + * @access protected |
|
| 3297 | + * @param string $tab |
|
| 3298 | + * @param EE_Config_Base|EE_Config $config |
|
| 3299 | + * @param string $file file where error occurred |
|
| 3300 | + * @param string $func function where error occurred |
|
| 3301 | + * @param string $line line no where error occurred |
|
| 3302 | + * @return boolean |
|
| 3303 | + */ |
|
| 3304 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 3305 | + { |
|
| 3306 | + //remove any options that are NOT going to be saved with the config settings. |
|
| 3307 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 3308 | + $config->core->ee_ueip_has_notified = true; |
|
| 3309 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 3310 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 3311 | + update_option('ee_ueip_has_notified', true); |
|
| 3312 | + } |
|
| 3313 | + // and save it (note we're also doing the network save here) |
|
| 3314 | + $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 3315 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 3316 | + if ($config_saved && $net_saved) { |
|
| 3317 | + EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 3318 | + return true; |
|
| 3319 | + } else { |
|
| 3320 | + EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 3321 | + return false; |
|
| 3322 | + } |
|
| 3323 | + } |
|
| 3324 | + |
|
| 3325 | + |
|
| 3326 | + |
|
| 3327 | + /** |
|
| 3328 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 3329 | + * |
|
| 3330 | + * @return array |
|
| 3331 | + */ |
|
| 3332 | + public function get_yes_no_values() |
|
| 3333 | + { |
|
| 3334 | + return $this->_yes_no_values; |
|
| 3335 | + } |
|
| 3336 | + |
|
| 3337 | + |
|
| 3338 | + |
|
| 3339 | + protected function _get_dir() |
|
| 3340 | + { |
|
| 3341 | + $reflector = new ReflectionClass(get_class($this)); |
|
| 3342 | + return dirname($reflector->getFileName()); |
|
| 3343 | + } |
|
| 3344 | + |
|
| 3345 | + |
|
| 3346 | + |
|
| 3347 | + /** |
|
| 3348 | + * A helper for getting a "next link". |
|
| 3349 | + * |
|
| 3350 | + * @param string $url The url to link to |
|
| 3351 | + * @param string $class The class to use. |
|
| 3352 | + * @return string |
|
| 3353 | + */ |
|
| 3354 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 3355 | + { |
|
| 3356 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3357 | + } |
|
| 3358 | + |
|
| 3359 | + |
|
| 3360 | + |
|
| 3361 | + /** |
|
| 3362 | + * A helper for getting a "previous link". |
|
| 3363 | + * |
|
| 3364 | + * @param string $url The url to link to |
|
| 3365 | + * @param string $class The class to use. |
|
| 3366 | + * @return string |
|
| 3367 | + */ |
|
| 3368 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 3369 | + { |
|
| 3370 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3371 | + } |
|
| 3372 | + |
|
| 3373 | + |
|
| 3374 | + |
|
| 3375 | + |
|
| 3376 | + |
|
| 3377 | + |
|
| 3378 | + |
|
| 3379 | + //below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 3380 | + /** |
|
| 3381 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data |
|
| 3382 | + * array. |
|
| 3383 | + * |
|
| 3384 | + * @return bool success/fail |
|
| 3385 | + */ |
|
| 3386 | + protected function _process_resend_registration() |
|
| 3387 | + { |
|
| 3388 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 3389 | + do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data); |
|
| 3390 | + return $this->_template_args['success']; |
|
| 3391 | + } |
|
| 3392 | + |
|
| 3393 | + |
|
| 3394 | + |
|
| 3395 | + /** |
|
| 3396 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 3397 | + * |
|
| 3398 | + * @access protected |
|
| 3399 | + * @param \EE_Payment $payment |
|
| 3400 | + * @return bool success/fail |
|
| 3401 | + */ |
|
| 3402 | + protected function _process_payment_notification(EE_Payment $payment) |
|
| 3403 | + { |
|
| 3404 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 3405 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 3406 | + $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment); |
|
| 3407 | + return $this->_template_args['success']; |
|
| 3408 | + } |
|
| 3409 | 3409 | |
| 3410 | 3410 | |
| 3411 | 3411 | } |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
| 475 | 475 | $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this)))); |
| 476 | 476 | global $ee_menu_slugs; |
| 477 | - $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 477 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 478 | 478 | if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) { |
| 479 | 479 | return; |
| 480 | 480 | } |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
| 490 | 490 | $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
| 491 | 491 | $this->_current_view = $this->_req_action; |
| 492 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 492 | + $this->_req_nonce = $this->_req_action.'_nonce'; |
|
| 493 | 493 | $this->_define_page_props(); |
| 494 | 494 | $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url); |
| 495 | 495 | //default things |
@@ -510,11 +510,11 @@ discard block |
||
| 510 | 510 | $this->_extend_page_config_for_cpt(); |
| 511 | 511 | } |
| 512 | 512 | //filter routes and page_config so addons can add their stuff. Filtering done per class |
| 513 | - $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this); |
|
| 514 | - $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this); |
|
| 513 | + $this->_page_routes = apply_filters('FHEE__'.get_class($this).'__page_setup__page_routes', $this->_page_routes, $this); |
|
| 514 | + $this->_page_config = apply_filters('FHEE__'.get_class($this).'__page_setup__page_config', $this->_page_config, $this); |
|
| 515 | 515 | //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
| 516 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 517 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2); |
|
| 516 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) { |
|
| 517 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view), 10, 2); |
|
| 518 | 518 | } |
| 519 | 519 | //next route only if routing enabled |
| 520 | 520 | if ($this->_routing && ! defined('DOING_AJAX')) { |
@@ -524,8 +524,8 @@ discard block |
||
| 524 | 524 | if ($this->_is_UI_request) { |
| 525 | 525 | //admin_init stuff - global, all views for this page class, specific view |
| 526 | 526 | add_action('admin_init', array($this, 'admin_init'), 10); |
| 527 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 528 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 527 | + if (method_exists($this, 'admin_init_'.$this->_current_view)) { |
|
| 528 | + add_action('admin_init', array($this, 'admin_init_'.$this->_current_view), 15); |
|
| 529 | 529 | } |
| 530 | 530 | } else { |
| 531 | 531 | //hijack regular WP loading and route admin request immediately |
@@ -545,17 +545,17 @@ discard block |
||
| 545 | 545 | */ |
| 546 | 546 | private function _do_other_page_hooks() |
| 547 | 547 | { |
| 548 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 548 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, array()); |
|
| 549 | 549 | foreach ($registered_pages as $page) { |
| 550 | 550 | //now let's setup the file name and class that should be present |
| 551 | 551 | $classname = str_replace('.class.php', '', $page); |
| 552 | 552 | //autoloaders should take care of loading file |
| 553 | 553 | if ( ! class_exists($classname)) { |
| 554 | - $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page); |
|
| 554 | + $error_msg[] = sprintf(esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page); |
|
| 555 | 555 | $error_msg[] = $error_msg[0] |
| 556 | 556 | . "\r\n" |
| 557 | - . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 558 | - 'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>'); |
|
| 557 | + . sprintf(esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 558 | + 'event_espresso'), $page, '<br />', '<strong>'.$classname.'</strong>'); |
|
| 559 | 559 | throw new EE_Error(implode('||', $error_msg)); |
| 560 | 560 | } |
| 561 | 561 | $a = new ReflectionClass($classname); |
@@ -591,13 +591,13 @@ discard block |
||
| 591 | 591 | //load admin_notices - global, page class, and view specific |
| 592 | 592 | add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
| 593 | 593 | add_action('admin_notices', array($this, 'admin_notices'), 10); |
| 594 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 595 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 594 | + if (method_exists($this, 'admin_notices_'.$this->_current_view)) { |
|
| 595 | + add_action('admin_notices', array($this, 'admin_notices_'.$this->_current_view), 15); |
|
| 596 | 596 | } |
| 597 | 597 | //load network admin_notices - global, page class, and view specific |
| 598 | 598 | add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
| 599 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 600 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 599 | + if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) { |
|
| 600 | + add_action('network_admin_notices', array($this, 'network_admin_notices_'.$this->_current_view)); |
|
| 601 | 601 | } |
| 602 | 602 | //this will save any per_page screen options if they are present |
| 603 | 603 | $this->_set_per_page_screen_options(); |
@@ -609,8 +609,8 @@ discard block |
||
| 609 | 609 | //add screen options - global, page child class, and view specific |
| 610 | 610 | $this->_add_global_screen_options(); |
| 611 | 611 | $this->_add_screen_options(); |
| 612 | - if (method_exists($this, '_add_screen_options_' . $this->_current_view)) { |
|
| 613 | - call_user_func(array($this, '_add_screen_options_' . $this->_current_view)); |
|
| 612 | + if (method_exists($this, '_add_screen_options_'.$this->_current_view)) { |
|
| 613 | + call_user_func(array($this, '_add_screen_options_'.$this->_current_view)); |
|
| 614 | 614 | } |
| 615 | 615 | //add help tab(s) and tours- set via page_config and qtips. |
| 616 | 616 | $this->_add_help_tour(); |
@@ -619,31 +619,31 @@ discard block |
||
| 619 | 619 | //add feature_pointers - global, page child class, and view specific |
| 620 | 620 | $this->_add_feature_pointers(); |
| 621 | 621 | $this->_add_global_feature_pointers(); |
| 622 | - if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) { |
|
| 623 | - call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view)); |
|
| 622 | + if (method_exists($this, '_add_feature_pointer_'.$this->_current_view)) { |
|
| 623 | + call_user_func(array($this, '_add_feature_pointer_'.$this->_current_view)); |
|
| 624 | 624 | } |
| 625 | 625 | //enqueue scripts/styles - global, page class, and view specific |
| 626 | 626 | add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
| 627 | 627 | add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
| 628 | - if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) { |
|
| 629 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15); |
|
| 628 | + if (method_exists($this, 'load_scripts_styles_'.$this->_current_view)) { |
|
| 629 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_'.$this->_current_view), 15); |
|
| 630 | 630 | } |
| 631 | 631 | add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
| 632 | 632 | //admin_print_footer_scripts - global, page child class, and view specific. NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. In most cases that's doing_it_wrong(). But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these |
| 633 | 633 | add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
| 634 | 634 | add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
| 635 | - if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) { |
|
| 636 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101); |
|
| 635 | + if (method_exists($this, 'admin_footer_scripts_'.$this->_current_view)) { |
|
| 636 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_'.$this->_current_view), 101); |
|
| 637 | 637 | } |
| 638 | 638 | //admin footer scripts |
| 639 | 639 | add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
| 640 | 640 | add_action('admin_footer', array($this, 'admin_footer'), 100); |
| 641 | - if (method_exists($this, 'admin_footer_' . $this->_current_view)) { |
|
| 642 | - add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101); |
|
| 641 | + if (method_exists($this, 'admin_footer_'.$this->_current_view)) { |
|
| 642 | + add_action('admin_footer', array($this, 'admin_footer_'.$this->_current_view), 101); |
|
| 643 | 643 | } |
| 644 | 644 | do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
| 645 | 645 | //targeted hook |
| 646 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action); |
|
| 646 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__'.$this->page_slug.'__'.$this->_req_action); |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | 649 | |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | // user error msg |
| 720 | 720 | $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
| 721 | 721 | // developer error msg |
| 722 | - $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso'); |
|
| 722 | + $error_msg .= '||'.$error_msg.__(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso'); |
|
| 723 | 723 | throw new EE_Error($error_msg); |
| 724 | 724 | } |
| 725 | 725 | // and that the requested page route exists |
@@ -730,7 +730,7 @@ discard block |
||
| 730 | 730 | // user error msg |
| 731 | 731 | $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
| 732 | 732 | // developer error msg |
| 733 | - $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action); |
|
| 733 | + $error_msg .= '||'.$error_msg.sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action); |
|
| 734 | 734 | throw new EE_Error($error_msg); |
| 735 | 735 | } |
| 736 | 736 | // and that a default route exists |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | // user error msg |
| 739 | 739 | $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title); |
| 740 | 740 | // developer error msg |
| 741 | - $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso'); |
|
| 741 | + $error_msg .= '||'.$error_msg.__(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso'); |
|
| 742 | 742 | throw new EE_Error($error_msg); |
| 743 | 743 | } |
| 744 | 744 | //first lets' catch if the UI request has EVER been set. |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | // user error msg |
| 768 | 768 | $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
| 769 | 769 | // developer error msg |
| 770 | - $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route); |
|
| 770 | + $error_msg .= '||'.$error_msg.sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route); |
|
| 771 | 771 | throw new EE_Error($error_msg); |
| 772 | 772 | } |
| 773 | 773 | } |
@@ -789,7 +789,7 @@ discard block |
||
| 789 | 789 | // these are not the droids you are looking for !!! |
| 790 | 790 | $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>'); |
| 791 | 791 | if (WP_DEBUG) { |
| 792 | - $msg .= "\n " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__); |
|
| 792 | + $msg .= "\n ".sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__); |
|
| 793 | 793 | } |
| 794 | 794 | if ( ! defined('DOING_AJAX')) { |
| 795 | 795 | wp_die($msg); |
@@ -967,7 +967,7 @@ discard block |
||
| 967 | 967 | if (strpos($key, 'nonce') !== false) { |
| 968 | 968 | continue; |
| 969 | 969 | } |
| 970 | - $args['wp_referer[' . $key . ']'] = $value; |
|
| 970 | + $args['wp_referer['.$key.']'] = $value; |
|
| 971 | 971 | } |
| 972 | 972 | } |
| 973 | 973 | return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
@@ -1013,7 +1013,7 @@ discard block |
||
| 1013 | 1013 | if ($tour instanceof EE_Help_Tour_final_stop) { |
| 1014 | 1014 | continue; |
| 1015 | 1015 | } |
| 1016 | - $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>'; |
|
| 1016 | + $tb[] = '<button id="trigger-tour-'.$tour->get_slug().'" class="button-primary trigger-ee-help-tour">'.$tour->get_label().'</button>'; |
|
| 1017 | 1017 | } |
| 1018 | 1018 | $tour_buttons .= implode('<br />', $tb); |
| 1019 | 1019 | $tour_buttons .= '</div></div>'; |
@@ -1025,7 +1025,7 @@ discard block |
||
| 1025 | 1025 | throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
| 1026 | 1026 | 'event_espresso'), $config['help_sidebar'], get_class($this))); |
| 1027 | 1027 | } |
| 1028 | - $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar']))); |
|
| 1028 | + $content = apply_filters('FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar']))); |
|
| 1029 | 1029 | $content .= $tour_buttons; //add help tour buttons. |
| 1030 | 1030 | //do we have any help tours setup? Cause if we do we want to add the buttons |
| 1031 | 1031 | $this->_current_screen->set_help_sidebar($content); |
@@ -1038,13 +1038,13 @@ discard block |
||
| 1038 | 1038 | if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
| 1039 | 1039 | $_ht['id'] = $this->page_slug; |
| 1040 | 1040 | $_ht['title'] = __('Help Tours', 'event_espresso'); |
| 1041 | - $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>'; |
|
| 1041 | + $_ht['content'] = '<p>'.__('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso').'</p>'; |
|
| 1042 | 1042 | $this->_current_screen->add_help_tab($_ht); |
| 1043 | 1043 | }/**/ |
| 1044 | 1044 | if ( ! isset($config['help_tabs'])) { |
| 1045 | 1045 | return; |
| 1046 | 1046 | } //no help tabs for this route |
| 1047 | - foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1047 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1048 | 1048 | //we're here so there ARE help tabs! |
| 1049 | 1049 | //make sure we've got what we need |
| 1050 | 1050 | if ( ! isset($cfg['title'])) { |
@@ -1059,9 +1059,9 @@ discard block |
||
| 1059 | 1059 | $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
| 1060 | 1060 | //second priority goes to filename |
| 1061 | 1061 | } else if ( ! empty($cfg['filename'])) { |
| 1062 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1062 | + $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php'; |
|
| 1063 | 1063 | //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
| 1064 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path; |
|
| 1064 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tabs/'.$cfg['filename'].'.help_tab.php' : $file_path; |
|
| 1065 | 1065 | //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1066 | 1066 | if ( ! is_readable($file_path) && ! isset($cfg['callback'])) { |
| 1067 | 1067 | EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
@@ -1080,7 +1080,7 @@ discard block |
||
| 1080 | 1080 | return; |
| 1081 | 1081 | } |
| 1082 | 1082 | //setup config array for help tab method |
| 1083 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1083 | + $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id; |
|
| 1084 | 1084 | $_ht = array( |
| 1085 | 1085 | 'id' => $id, |
| 1086 | 1086 | 'title' => $cfg['title'], |
@@ -1118,9 +1118,9 @@ discard block |
||
| 1118 | 1118 | } |
| 1119 | 1119 | if (isset($config['help_tour'])) { |
| 1120 | 1120 | foreach ($config['help_tour'] as $tour) { |
| 1121 | - $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1121 | + $file_path = $this->_get_dir().'/help_tours/'.$tour.'.class.php'; |
|
| 1122 | 1122 | //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent |
| 1123 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path; |
|
| 1123 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tours/'.$tour.'.class.php' : $file_path; |
|
| 1124 | 1124 | //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1125 | 1125 | if ( ! is_readable($file_path)) { |
| 1126 | 1126 | EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'), |
@@ -1130,7 +1130,7 @@ discard block |
||
| 1130 | 1130 | require_once $file_path; |
| 1131 | 1131 | if ( ! class_exists($tour)) { |
| 1132 | 1132 | $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour); |
| 1133 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1133 | + $error_msg[] = $error_msg[0]."\r\n".sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1134 | 1134 | 'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this)); |
| 1135 | 1135 | throw new EE_Error(implode('||', $error_msg)); |
| 1136 | 1136 | } |
@@ -1162,11 +1162,11 @@ discard block |
||
| 1162 | 1162 | protected function _add_qtips() |
| 1163 | 1163 | { |
| 1164 | 1164 | if (isset($this->_route_config['qtips'])) { |
| 1165 | - $qtips = (array)$this->_route_config['qtips']; |
|
| 1165 | + $qtips = (array) $this->_route_config['qtips']; |
|
| 1166 | 1166 | //load qtip loader |
| 1167 | 1167 | $path = array( |
| 1168 | - $this->_get_dir() . '/qtips/', |
|
| 1169 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1168 | + $this->_get_dir().'/qtips/', |
|
| 1169 | + EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/', |
|
| 1170 | 1170 | ); |
| 1171 | 1171 | EEH_Qtip_Loader::instance()->register($qtips, $path); |
| 1172 | 1172 | } |
@@ -1196,11 +1196,11 @@ discard block |
||
| 1196 | 1196 | if ( ! $this->check_user_access($slug, true)) { |
| 1197 | 1197 | continue; |
| 1198 | 1198 | } //no nav tab becasue current user does not have access. |
| 1199 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1199 | + $css_class = isset($config['css_class']) ? $config['css_class'].' ' : ''; |
|
| 1200 | 1200 | $this->_nav_tabs[$slug] = array( |
| 1201 | 1201 | 'url' => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url), |
| 1202 | 1202 | 'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)), |
| 1203 | - 'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1203 | + 'css_class' => $this->_req_action == $slug ? $css_class.'nav-tab-active' : $css_class, |
|
| 1204 | 1204 | 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
| 1205 | 1205 | ); |
| 1206 | 1206 | $i++; |
@@ -1263,11 +1263,11 @@ discard block |
||
| 1263 | 1263 | $capability = empty($capability) ? 'manage_options' : $capability; |
| 1264 | 1264 | } |
| 1265 | 1265 | $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
| 1266 | - if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) { |
|
| 1266 | + if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug.'_'.$route_to_check, $id)) && ! defined('DOING_AJAX')) { |
|
| 1267 | 1267 | if ($verify_only) { |
| 1268 | 1268 | return false; |
| 1269 | 1269 | } else { |
| 1270 | - if ( is_user_logged_in() ) { |
|
| 1270 | + if (is_user_logged_in()) { |
|
| 1271 | 1271 | wp_die(__('You do not have access to this route.', 'event_espresso')); |
| 1272 | 1272 | } else { |
| 1273 | 1273 | return false; |
@@ -1359,7 +1359,7 @@ discard block |
||
| 1359 | 1359 | public function admin_footer_global() |
| 1360 | 1360 | { |
| 1361 | 1361 | //dialog container for dialog helper |
| 1362 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1362 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">'."\n"; |
|
| 1363 | 1363 | $d_cont .= '<div class="ee-notices"></div>'; |
| 1364 | 1364 | $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
| 1365 | 1365 | $d_cont .= '</div>'; |
@@ -1369,7 +1369,7 @@ discard block |
||
| 1369 | 1369 | echo implode('<br />', $this->_help_tour[$this->_req_action]); |
| 1370 | 1370 | } |
| 1371 | 1371 | //current set timezone for timezone js |
| 1372 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1372 | + echo '<span id="current_timezone" class="hidden">'.EEH_DTT_Helper::get_timezone().'</span>'; |
|
| 1373 | 1373 | } |
| 1374 | 1374 | |
| 1375 | 1375 | |
@@ -1394,7 +1394,7 @@ discard block |
||
| 1394 | 1394 | { |
| 1395 | 1395 | $content = ''; |
| 1396 | 1396 | $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
| 1397 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php'; |
|
| 1397 | + $template_path = EE_ADMIN_TEMPLATE.'admin_help_popup.template.php'; |
|
| 1398 | 1398 | //loop through the array and setup content |
| 1399 | 1399 | foreach ($help_array as $trigger => $help) { |
| 1400 | 1400 | //make sure the array is setup properly |
@@ -1428,7 +1428,7 @@ discard block |
||
| 1428 | 1428 | private function _get_help_content() |
| 1429 | 1429 | { |
| 1430 | 1430 | //what is the method we're looking for? |
| 1431 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1431 | + $method_name = '_help_popup_content_'.$this->_req_action; |
|
| 1432 | 1432 | //if method doesn't exist let's get out. |
| 1433 | 1433 | if ( ! method_exists($this, $method_name)) { |
| 1434 | 1434 | return array(); |
@@ -1472,8 +1472,8 @@ discard block |
||
| 1472 | 1472 | $help_content = $this->_set_help_popup_content($help_array, false); |
| 1473 | 1473 | } |
| 1474 | 1474 | //let's setup the trigger |
| 1475 | - $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1476 | - $content = $content . $help_content; |
|
| 1475 | + $content = '<a class="ee-dialog" href="?height='.$dimensions[0].'&width='.$dimensions[1].'&inlineId='.$trigger_id.'" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1476 | + $content = $content.$help_content; |
|
| 1477 | 1477 | if ($display) { |
| 1478 | 1478 | echo $content; |
| 1479 | 1479 | } else { |
@@ -1533,27 +1533,27 @@ discard block |
||
| 1533 | 1533 | add_action('admin_head', array($this, 'add_xdebug_style')); |
| 1534 | 1534 | } |
| 1535 | 1535 | // register all styles |
| 1536 | - wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1537 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1536 | + wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1537 | + wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1538 | 1538 | //helpers styles |
| 1539 | - wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1539 | + wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1540 | 1540 | /** SCRIPTS **/ |
| 1541 | 1541 | //register all scripts |
| 1542 | - wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1543 | - wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
| 1544 | - wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true); |
|
| 1542 | + wp_register_script('ee-dialog', EE_ADMIN_URL.'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1543 | + wp_register_script('ee_admin_js', EE_ADMIN_URL.'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
| 1544 | + wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true); |
|
| 1545 | 1545 | add_filter('FHEE_load_joyride', '__return_true'); |
| 1546 | 1546 | //script for sorting tables |
| 1547 | - wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1547 | + wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL."assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1548 | 1548 | //script for parsing uri's |
| 1549 | - wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1549 | + wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1550 | 1550 | //and parsing associative serialized form elements |
| 1551 | - wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1551 | + wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1552 | 1552 | //helpers scripts |
| 1553 | - wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1554 | - wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1555 | - wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 1556 | - wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true); |
|
| 1553 | + wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1554 | + wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1555 | + wp_register_script('ee-moment', EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 1556 | + wp_register_script('ee-datepicker', EE_ADMIN_URL.'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true); |
|
| 1557 | 1557 | //google charts |
| 1558 | 1558 | wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false); |
| 1559 | 1559 | // ENQUEUE ALL BASICS BY DEFAULT |
@@ -1577,7 +1577,7 @@ discard block |
||
| 1577 | 1577 | */ |
| 1578 | 1578 | if ( ! empty($this->_help_tour)) { |
| 1579 | 1579 | //register the js for kicking things off |
| 1580 | - wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true); |
|
| 1580 | + wp_enqueue_script('ee-help-tour', EE_ADMIN_URL.'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true); |
|
| 1581 | 1581 | //setup tours for the js tour object |
| 1582 | 1582 | foreach ($this->_help_tour['tours'] as $tour) { |
| 1583 | 1583 | $tours[] = array( |
@@ -1672,17 +1672,17 @@ discard block |
||
| 1672 | 1672 | return; |
| 1673 | 1673 | } //not a list_table view so get out. |
| 1674 | 1674 | //list table functions are per view specific (because some admin pages might have more than one listtable!) |
| 1675 | - if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) { |
|
| 1675 | + if (call_user_func(array($this, '_set_list_table_views_'.$this->_req_action)) === false) { |
|
| 1676 | 1676 | //user error msg |
| 1677 | 1677 | $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso'); |
| 1678 | 1678 | //developer error msg |
| 1679 | - $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'), |
|
| 1680 | - $this->_req_action, '_set_list_table_views_' . $this->_req_action); |
|
| 1679 | + $error_msg .= '||'.sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'), |
|
| 1680 | + $this->_req_action, '_set_list_table_views_'.$this->_req_action); |
|
| 1681 | 1681 | throw new EE_Error($error_msg); |
| 1682 | 1682 | } |
| 1683 | 1683 | //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
| 1684 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views); |
|
| 1685 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1684 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, $this->_views); |
|
| 1685 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views); |
|
| 1686 | 1686 | $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
| 1687 | 1687 | $this->_set_list_table_view(); |
| 1688 | 1688 | $this->_set_list_table_object(); |
@@ -1757,7 +1757,7 @@ discard block |
||
| 1757 | 1757 | // check for current view |
| 1758 | 1758 | $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : ''; |
| 1759 | 1759 | $query_args['action'] = $this->_req_action; |
| 1760 | - $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 1760 | + $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 1761 | 1761 | $query_args['status'] = $view['slug']; |
| 1762 | 1762 | //merge any other arguments sent in. |
| 1763 | 1763 | if (isset($extra_query_args[$view['slug']])) { |
@@ -1795,14 +1795,14 @@ discard block |
||
| 1795 | 1795 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 1796 | 1796 | foreach ($values as $value) { |
| 1797 | 1797 | if ($value < $max_entries) { |
| 1798 | - $selected = $value == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1798 | + $selected = $value == $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 1799 | 1799 | $entries_per_page_dropdown .= ' |
| 1800 | - <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
|
| 1800 | + <option value="' . $value.'"'.$selected.'>'.$value.' </option>'; |
|
| 1801 | 1801 | } |
| 1802 | 1802 | } |
| 1803 | - $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1803 | + $selected = $max_entries == $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 1804 | 1804 | $entries_per_page_dropdown .= ' |
| 1805 | - <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
|
| 1805 | + <option value="' . $max_entries.'"'.$selected.'>All </option>'; |
|
| 1806 | 1806 | $entries_per_page_dropdown .= ' |
| 1807 | 1807 | </select> |
| 1808 | 1808 | entries |
@@ -1824,7 +1824,7 @@ discard block |
||
| 1824 | 1824 | public function _set_search_attributes() |
| 1825 | 1825 | { |
| 1826 | 1826 | $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label); |
| 1827 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 1827 | + $this->_template_args['search']['callback'] = 'search_'.$this->page_slug; |
|
| 1828 | 1828 | } |
| 1829 | 1829 | |
| 1830 | 1830 | /*** END LIST TABLE METHODS **/ |
@@ -1862,7 +1862,7 @@ discard block |
||
| 1862 | 1862 | // user error msg |
| 1863 | 1863 | $error_msg = __('An error occurred. The requested metabox could not be found.', 'event_espresso'); |
| 1864 | 1864 | // developer error msg |
| 1865 | - $error_msg .= '||' . sprintf( |
|
| 1865 | + $error_msg .= '||'.sprintf( |
|
| 1866 | 1866 | __( |
| 1867 | 1867 | 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
| 1868 | 1868 | 'event_espresso' |
@@ -1892,15 +1892,15 @@ discard block |
||
| 1892 | 1892 | && is_array($this->_route_config['columns']) |
| 1893 | 1893 | && count($this->_route_config['columns']) === 2 |
| 1894 | 1894 | ) { |
| 1895 | - add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1])); |
|
| 1895 | + add_screen_option('layout_columns', array('max' => (int) $this->_route_config['columns'][0], 'default' => (int) $this->_route_config['columns'][1])); |
|
| 1896 | 1896 | $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
| 1897 | 1897 | $screen_id = $this->_current_screen->id; |
| 1898 | - $screen_columns = (int)get_user_option("screen_layout_$screen_id"); |
|
| 1898 | + $screen_columns = (int) get_user_option("screen_layout_$screen_id"); |
|
| 1899 | 1899 | $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1]; |
| 1900 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 1900 | + $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns; |
|
| 1901 | 1901 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 1902 | 1902 | $this->_template_args['screen'] = $this->_current_screen; |
| 1903 | - $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 1903 | + $this->_column_template_path = EE_ADMIN_TEMPLATE.'admin_details_metabox_column_wrapper.template.php'; |
|
| 1904 | 1904 | //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
| 1905 | 1905 | $this->_route_config['has_metaboxes'] = true; |
| 1906 | 1906 | } |
@@ -1947,7 +1947,7 @@ discard block |
||
| 1947 | 1947 | */ |
| 1948 | 1948 | public function espresso_ratings_request() |
| 1949 | 1949 | { |
| 1950 | - $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'; |
|
| 1950 | + $template_path = EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php'; |
|
| 1951 | 1951 | EEH_Template::display_template($template_path, array()); |
| 1952 | 1952 | } |
| 1953 | 1953 | |
@@ -1955,18 +1955,18 @@ discard block |
||
| 1955 | 1955 | |
| 1956 | 1956 | public static function cached_rss_display($rss_id, $url) |
| 1957 | 1957 | { |
| 1958 | - $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading…') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>'; |
|
| 1958 | + $loading = '<p class="widget-loading hide-if-no-js">'.__('Loading…').'</p><p class="hide-if-js">'.__('This widget requires JavaScript.').'</p>'; |
|
| 1959 | 1959 | $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX); |
| 1960 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 1961 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 1962 | - $post = '</div>' . "\n"; |
|
| 1963 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 1960 | + $pre = '<div class="espresso-rss-display">'."\n\t"; |
|
| 1961 | + $pre .= '<span id="'.$rss_id.'_url" class="hidden">'.$url.'</span>'; |
|
| 1962 | + $post = '</div>'."\n"; |
|
| 1963 | + $cache_key = 'ee_rss_'.md5($rss_id); |
|
| 1964 | 1964 | if (false != ($output = get_transient($cache_key))) { |
| 1965 | - echo $pre . $output . $post; |
|
| 1965 | + echo $pre.$output.$post; |
|
| 1966 | 1966 | return true; |
| 1967 | 1967 | } |
| 1968 | 1968 | if ( ! $doing_ajax) { |
| 1969 | - echo $pre . $loading . $post; |
|
| 1969 | + echo $pre.$loading.$post; |
|
| 1970 | 1970 | return false; |
| 1971 | 1971 | } |
| 1972 | 1972 | ob_start(); |
@@ -2025,7 +2025,7 @@ discard block |
||
| 2025 | 2025 | |
| 2026 | 2026 | public function espresso_sponsors_post_box() |
| 2027 | 2027 | { |
| 2028 | - $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'; |
|
| 2028 | + $templatepath = EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php'; |
|
| 2029 | 2029 | EEH_Template::display_template($templatepath); |
| 2030 | 2030 | } |
| 2031 | 2031 | |
@@ -2033,7 +2033,7 @@ discard block |
||
| 2033 | 2033 | |
| 2034 | 2034 | private function _publish_post_box() |
| 2035 | 2035 | { |
| 2036 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2036 | + $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview'; |
|
| 2037 | 2037 | //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label. Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
| 2038 | 2038 | if ( ! empty($this->_labels['publishbox'])) { |
| 2039 | 2039 | $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox']; |
@@ -2050,7 +2050,7 @@ discard block |
||
| 2050 | 2050 | { |
| 2051 | 2051 | //if we have extra content set let's add it in if not make sure its empty |
| 2052 | 2052 | $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
| 2053 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php'; |
|
| 2053 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php'; |
|
| 2054 | 2054 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 2055 | 2055 | } |
| 2056 | 2056 | |
@@ -2219,7 +2219,7 @@ discard block |
||
| 2219 | 2219 | //if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
| 2220 | 2220 | $call_back_func = $create_func ? create_function('$post, $metabox', |
| 2221 | 2221 | 'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback; |
| 2222 | - add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args); |
|
| 2222 | + add_meta_box(str_replace('_', '-', $action).'-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args); |
|
| 2223 | 2223 | } |
| 2224 | 2224 | |
| 2225 | 2225 | |
@@ -2299,10 +2299,10 @@ discard block |
||
| 2299 | 2299 | ? 'poststuff' |
| 2300 | 2300 | : 'espresso-default-admin'; |
| 2301 | 2301 | $template_path = $sidebar |
| 2302 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2303 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2302 | + ? EE_ADMIN_TEMPLATE.'admin_details_wrapper.template.php' |
|
| 2303 | + : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2304 | 2304 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 2305 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2305 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2306 | 2306 | } |
| 2307 | 2307 | $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
| 2308 | 2308 | $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : ''; |
@@ -2348,7 +2348,7 @@ discard block |
||
| 2348 | 2348 | true |
| 2349 | 2349 | ) |
| 2350 | 2350 | : $this->_template_args['preview_action_button']; |
| 2351 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php'; |
|
| 2351 | + $template_path = EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php'; |
|
| 2352 | 2352 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 2353 | 2353 | $template_path, |
| 2354 | 2354 | $this->_template_args, |
@@ -2399,7 +2399,7 @@ discard block |
||
| 2399 | 2399 | //setup search attributes |
| 2400 | 2400 | $this->_set_search_attributes(); |
| 2401 | 2401 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2402 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2402 | + $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php'; |
|
| 2403 | 2403 | $this->_template_args['table_url'] = defined('DOING_AJAX') |
| 2404 | 2404 | ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
| 2405 | 2405 | : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
@@ -2409,29 +2409,29 @@ discard block |
||
| 2409 | 2409 | $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
| 2410 | 2410 | if ( ! empty($ajax_sorting_callback)) { |
| 2411 | 2411 | $sortable_list_table_form_fields = wp_nonce_field( |
| 2412 | - $ajax_sorting_callback . '_nonce', |
|
| 2413 | - $ajax_sorting_callback . '_nonce', |
|
| 2412 | + $ajax_sorting_callback.'_nonce', |
|
| 2413 | + $ajax_sorting_callback.'_nonce', |
|
| 2414 | 2414 | false, |
| 2415 | 2415 | false |
| 2416 | 2416 | ); |
| 2417 | 2417 | // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
| 2418 | 2418 | // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
| 2419 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />'; |
|
| 2420 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />'; |
|
| 2419 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'.$this->page_slug.'" />'; |
|
| 2420 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'.$ajax_sorting_callback.'" />'; |
|
| 2421 | 2421 | } else { |
| 2422 | 2422 | $sortable_list_table_form_fields = ''; |
| 2423 | 2423 | } |
| 2424 | 2424 | $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
| 2425 | 2425 | $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : ''; |
| 2426 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2427 | - $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
|
| 2426 | + $nonce_ref = $this->_req_action.'_nonce'; |
|
| 2427 | + $hidden_form_fields .= '<input type="hidden" name="'.$nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">'; |
|
| 2428 | 2428 | $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
| 2429 | 2429 | //display message about search results? |
| 2430 | 2430 | $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
| 2431 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 2431 | + ? '<p class="ee-search-results">'.sprintf( |
|
| 2432 | 2432 | esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
| 2433 | 2433 | trim($this->_req_data['s'], '%') |
| 2434 | - ) . '</p>' |
|
| 2434 | + ).'</p>' |
|
| 2435 | 2435 | : ''; |
| 2436 | 2436 | // filter before_list_table template arg |
| 2437 | 2437 | $this->_template_args['before_list_table'] = apply_filters( |
@@ -2505,8 +2505,8 @@ discard block |
||
| 2505 | 2505 | */ |
| 2506 | 2506 | protected function _display_legend($items) |
| 2507 | 2507 | { |
| 2508 | - $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this); |
|
| 2509 | - $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php'; |
|
| 2508 | + $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array) $items, $this); |
|
| 2509 | + $legend_template = EE_ADMIN_TEMPLATE.'admin_details_legend.template.php'; |
|
| 2510 | 2510 | return EEH_Template::display_template($legend_template, $this->_template_args, true); |
| 2511 | 2511 | } |
| 2512 | 2512 | |
@@ -2598,15 +2598,15 @@ discard block |
||
| 2598 | 2598 | $this->_nav_tabs = $this->_get_main_nav_tabs(); |
| 2599 | 2599 | $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
| 2600 | 2600 | $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
| 2601 | - $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2601 | + $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content'.$this->_current_page.$this->_current_view, |
|
| 2602 | 2602 | isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''); |
| 2603 | - $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2603 | + $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content'.$this->_current_page.$this->_current_view, |
|
| 2604 | 2604 | isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''); |
| 2605 | 2605 | $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
| 2606 | 2606 | // load settings page wrapper template |
| 2607 | - $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php'; |
|
| 2607 | + $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE.'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php'; |
|
| 2608 | 2608 | //about page? |
| 2609 | - $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path; |
|
| 2609 | + $template_path = $about ? EE_ADMIN_TEMPLATE.'about_admin_wrapper.template.php' : $template_path; |
|
| 2610 | 2610 | if (defined('DOING_AJAX')) { |
| 2611 | 2611 | $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
| 2612 | 2612 | $this->_return_json(); |
@@ -2678,20 +2678,20 @@ discard block |
||
| 2678 | 2678 | protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
| 2679 | 2679 | { |
| 2680 | 2680 | //make sure $text and $actions are in an array |
| 2681 | - $text = (array)$text; |
|
| 2682 | - $actions = (array)$actions; |
|
| 2681 | + $text = (array) $text; |
|
| 2682 | + $actions = (array) $actions; |
|
| 2683 | 2683 | $referrer_url = empty($referrer) ? '' : $referrer; |
| 2684 | - $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />' |
|
| 2685 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />'; |
|
| 2684 | + $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$_SERVER['REQUEST_URI'].'" />' |
|
| 2685 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$referrer.'" />'; |
|
| 2686 | 2686 | $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso')); |
| 2687 | 2687 | $default_names = array('save', 'save_and_close'); |
| 2688 | 2688 | //add in a hidden index for the current page (so save and close redirects properly) |
| 2689 | 2689 | $this->_template_args['save_buttons'] = $referrer_url; |
| 2690 | 2690 | foreach ($button_text as $key => $button) { |
| 2691 | 2691 | $ref = $default_names[$key]; |
| 2692 | - $id = $this->_current_view . '_' . $ref; |
|
| 2692 | + $id = $this->_current_view.'_'.$ref; |
|
| 2693 | 2693 | $name = ! empty($actions) ? $actions[$key] : $ref; |
| 2694 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />'; |
|
| 2694 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '.$ref.'" value="'.$button.'" name="'.$name.'" id="'.$id.'" />'; |
|
| 2695 | 2695 | if ( ! $both) { |
| 2696 | 2696 | break; |
| 2697 | 2697 | } |
@@ -2727,15 +2727,15 @@ discard block |
||
| 2727 | 2727 | { |
| 2728 | 2728 | if (empty($route)) { |
| 2729 | 2729 | $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso'); |
| 2730 | - $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__); |
|
| 2731 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2730 | + $dev_msg = $user_msg."\n".sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__); |
|
| 2731 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2732 | 2732 | } |
| 2733 | 2733 | // open form |
| 2734 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >'; |
|
| 2734 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'.$this->_admin_base_url.'" id="'.$route.'_event_form" >'; |
|
| 2735 | 2735 | // add nonce |
| 2736 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 2736 | + $nonce = wp_nonce_field($route.'_nonce', $route.'_nonce', false, false); |
|
| 2737 | 2737 | // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
| 2738 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 2738 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce; |
|
| 2739 | 2739 | // add REQUIRED form action |
| 2740 | 2740 | $hidden_fields = array( |
| 2741 | 2741 | 'action' => array('type' => 'hidden', 'value' => $route), |
@@ -2745,8 +2745,8 @@ discard block |
||
| 2745 | 2745 | // generate form fields |
| 2746 | 2746 | $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
| 2747 | 2747 | // add fields to form |
| 2748 | - foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 2749 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 2748 | + foreach ((array) $form_fields as $field_name => $form_field) { |
|
| 2749 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field']; |
|
| 2750 | 2750 | } |
| 2751 | 2751 | // close form |
| 2752 | 2752 | $this->_template_args['after_admin_page_content'] = '</form>'; |
@@ -2827,7 +2827,7 @@ discard block |
||
| 2827 | 2827 | * @param array $query_args The original query_args array coming into the |
| 2828 | 2828 | * method. |
| 2829 | 2829 | */ |
| 2830 | - do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args); |
|
| 2830 | + do_action('AHEE__'.$classname.'___redirect_after_action__before_redirect_modification_'.$this->_req_action, $query_args); |
|
| 2831 | 2831 | //calculate where we're going (if we have a "save and close" button pushed) |
| 2832 | 2832 | if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) { |
| 2833 | 2833 | // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
@@ -2843,7 +2843,7 @@ discard block |
||
| 2843 | 2843 | foreach ($this->_default_route_query_args as $query_param => $query_value) { |
| 2844 | 2844 | //is there a wp_referer array in our _default_route_query_args property? |
| 2845 | 2845 | if ($query_param == 'wp_referer') { |
| 2846 | - $query_value = (array)$query_value; |
|
| 2846 | + $query_value = (array) $query_value; |
|
| 2847 | 2847 | foreach ($query_value as $reference => $value) { |
| 2848 | 2848 | if (strpos($reference, 'nonce') !== false) { |
| 2849 | 2849 | continue; |
@@ -2869,11 +2869,11 @@ discard block |
||
| 2869 | 2869 | // if redirecting to anything other than the main page, add a nonce |
| 2870 | 2870 | if (isset($query_args['action'])) { |
| 2871 | 2871 | // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars |
| 2872 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2872 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 2873 | 2873 | } |
| 2874 | 2874 | //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that). |
| 2875 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 2876 | - $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args); |
|
| 2875 | + do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args); |
|
| 2876 | + $redirect_url = apply_filters('FHEE_redirect_'.$classname.$this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args); |
|
| 2877 | 2877 | // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
| 2878 | 2878 | if (defined('DOING_AJAX')) { |
| 2879 | 2879 | $default_data = array( |
@@ -3003,7 +3003,7 @@ discard block |
||
| 3003 | 3003 | $args = array( |
| 3004 | 3004 | 'label' => $this->_admin_page_title, |
| 3005 | 3005 | 'default' => 10, |
| 3006 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3006 | + 'option' => $this->_current_page.'_'.$this->_current_view.'_per_page', |
|
| 3007 | 3007 | ); |
| 3008 | 3008 | //ONLY add the screen option if the user has access to it. |
| 3009 | 3009 | if ($this->check_user_access($this->_current_view, true)) { |
@@ -3036,8 +3036,8 @@ discard block |
||
| 3036 | 3036 | $map_option = $option; |
| 3037 | 3037 | $option = str_replace('-', '_', $option); |
| 3038 | 3038 | switch ($map_option) { |
| 3039 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3040 | - $value = (int)$value; |
|
| 3039 | + case $this->_current_page.'_'.$this->_current_view.'_per_page': |
|
| 3040 | + $value = (int) $value; |
|
| 3041 | 3041 | if ($value < 1 || $value > 999) { |
| 3042 | 3042 | return; |
| 3043 | 3043 | } |
@@ -3064,7 +3064,7 @@ discard block |
||
| 3064 | 3064 | */ |
| 3065 | 3065 | public function set_template_args($data) |
| 3066 | 3066 | { |
| 3067 | - $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3067 | + $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3068 | 3068 | } |
| 3069 | 3069 | |
| 3070 | 3070 | |
@@ -3086,12 +3086,12 @@ discard block |
||
| 3086 | 3086 | $this->_verify_route($route); |
| 3087 | 3087 | } |
| 3088 | 3088 | //now let's set the string for what kind of transient we're setting |
| 3089 | - $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3089 | + $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3090 | 3090 | $data = $notices ? array('notices' => $data) : $data; |
| 3091 | 3091 | //is there already a transient for this route? If there is then let's ADD to that transient |
| 3092 | 3092 | $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
| 3093 | 3093 | if ($existing) { |
| 3094 | - $data = array_merge((array)$data, (array)$existing); |
|
| 3094 | + $data = array_merge((array) $data, (array) $existing); |
|
| 3095 | 3095 | } |
| 3096 | 3096 | if (is_multisite() && is_network_admin()) { |
| 3097 | 3097 | set_site_transient($transient, $data, 8); |
@@ -3112,7 +3112,7 @@ discard block |
||
| 3112 | 3112 | { |
| 3113 | 3113 | $user_id = get_current_user_id(); |
| 3114 | 3114 | $route = ! $route ? $this->_req_action : $route; |
| 3115 | - $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3115 | + $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3116 | 3116 | $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
| 3117 | 3117 | //delete transient after retrieval (just in case it hasn't expired); |
| 3118 | 3118 | if (is_multisite() && is_network_admin()) { |
@@ -3353,7 +3353,7 @@ discard block |
||
| 3353 | 3353 | */ |
| 3354 | 3354 | protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
| 3355 | 3355 | { |
| 3356 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3356 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 3357 | 3357 | } |
| 3358 | 3358 | |
| 3359 | 3359 | |
@@ -3367,7 +3367,7 @@ discard block |
||
| 3367 | 3367 | */ |
| 3368 | 3368 | protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
| 3369 | 3369 | { |
| 3370 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3370 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 3371 | 3371 | } |
| 3372 | 3372 | |
| 3373 | 3373 | |
@@ -1104,8 +1104,8 @@ discard block |
||
| 1104 | 1104 | * @param array $datetime_tickets |
| 1105 | 1105 | * @param array $all_tickets |
| 1106 | 1106 | * @param bool $default |
| 1107 | - * @param array $all_datetimes |
|
| 1108 | - * @return mixed |
|
| 1107 | + * @param EE_Datetime[] $all_datetimes |
|
| 1108 | + * @return string |
|
| 1109 | 1109 | * @throws DomainException |
| 1110 | 1110 | * @throws EE_Error |
| 1111 | 1111 | */ |
@@ -1213,7 +1213,7 @@ discard block |
||
| 1213 | 1213 | * @param array $datetime_tickets |
| 1214 | 1214 | * @param array $all_tickets |
| 1215 | 1215 | * @param bool $default |
| 1216 | - * @return mixed |
|
| 1216 | + * @return string |
|
| 1217 | 1217 | * @throws DomainException |
| 1218 | 1218 | * @throws EE_Error |
| 1219 | 1219 | */ |
@@ -1282,7 +1282,7 @@ discard block |
||
| 1282 | 1282 | * @param EE_Ticket $ticket |
| 1283 | 1283 | * @param array $datetime_tickets |
| 1284 | 1284 | * @param bool $default |
| 1285 | - * @return mixed |
|
| 1285 | + * @return string |
|
| 1286 | 1286 | * @throws DomainException |
| 1287 | 1287 | * @throws EE_Error |
| 1288 | 1288 | */ |
@@ -1353,7 +1353,7 @@ discard block |
||
| 1353 | 1353 | * @param bool $default Whether default row being generated or not. |
| 1354 | 1354 | * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
| 1355 | 1355 | * (or empty in the case of defaults) |
| 1356 | - * @return mixed |
|
| 1356 | + * @return string |
|
| 1357 | 1357 | * @throws DomainException |
| 1358 | 1358 | * @throws EE_Error |
| 1359 | 1359 | */ |
@@ -1673,7 +1673,7 @@ discard block |
||
| 1673 | 1673 | * @param EE_Ticket|null $ticket |
| 1674 | 1674 | * @param bool $show_trash |
| 1675 | 1675 | * @param bool $show_create |
| 1676 | - * @return mixed |
|
| 1676 | + * @return string |
|
| 1677 | 1677 | * @throws DomainException |
| 1678 | 1678 | * @throws EE_Error |
| 1679 | 1679 | */ |
@@ -1769,7 +1769,7 @@ discard block |
||
| 1769 | 1769 | * @param EE_Price $price |
| 1770 | 1770 | * @param bool $default |
| 1771 | 1771 | * @param bool $disabled |
| 1772 | - * @return mixed |
|
| 1772 | + * @return string |
|
| 1773 | 1773 | * @throws DomainException |
| 1774 | 1774 | * @throws EE_Error |
| 1775 | 1775 | */ |
@@ -1788,7 +1788,7 @@ discard block |
||
| 1788 | 1788 | * @param int $price_row |
| 1789 | 1789 | * @param EE_Price $price |
| 1790 | 1790 | * @param bool $default |
| 1791 | - * @return mixed |
|
| 1791 | + * @return string |
|
| 1792 | 1792 | * @throws DomainException |
| 1793 | 1793 | * @throws EE_Error |
| 1794 | 1794 | */ |
@@ -1826,7 +1826,7 @@ discard block |
||
| 1826 | 1826 | * @param EE_Price $price |
| 1827 | 1827 | * @param bool $default |
| 1828 | 1828 | * @param bool $disabled |
| 1829 | - * @return mixed |
|
| 1829 | + * @return string |
|
| 1830 | 1830 | * @throws DomainException |
| 1831 | 1831 | * @throws EE_Error |
| 1832 | 1832 | */ |
@@ -1930,7 +1930,7 @@ discard block |
||
| 1930 | 1930 | * @param EE_Ticket|null $ticket |
| 1931 | 1931 | * @param array $ticket_datetimes |
| 1932 | 1932 | * @param bool $default |
| 1933 | - * @return mixed |
|
| 1933 | + * @return string |
|
| 1934 | 1934 | * @throws DomainException |
| 1935 | 1935 | * @throws EE_Error |
| 1936 | 1936 | */ |
@@ -1984,9 +1984,9 @@ discard block |
||
| 1984 | 1984 | |
| 1985 | 1985 | |
| 1986 | 1986 | /** |
| 1987 | - * @param array $all_datetimes |
|
| 1987 | + * @param EE_Datetime[] $all_datetimes |
|
| 1988 | 1988 | * @param array $all_tickets |
| 1989 | - * @return mixed |
|
| 1989 | + * @return string |
|
| 1990 | 1990 | * @throws DomainException |
| 1991 | 1991 | * @throws EE_Error |
| 1992 | 1992 | */ |
@@ -15,2116 +15,2116 @@ |
||
| 15 | 15 | class espresso_events_Pricing_Hooks extends EE_Admin_Hooks |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * This property is just used to hold the status of whether an event is currently being |
|
| 20 | - * created (true) or edited (false) |
|
| 21 | - * |
|
| 22 | - * @access protected |
|
| 23 | - * @var bool |
|
| 24 | - */ |
|
| 25 | - protected $_is_creating_event; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Used to contain the format strings for date and time that will be used for php date and |
|
| 30 | - * time. |
|
| 31 | - * Is set in the _set_hooks_properties() method. |
|
| 32 | - * |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 35 | - protected $_date_format_strings; |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var string $_date_time_format |
|
| 40 | - */ |
|
| 41 | - protected $_date_time_format; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * |
|
| 47 | - */ |
|
| 48 | - protected function _set_hooks_properties() |
|
| 49 | - { |
|
| 50 | - $this->_name = 'pricing'; |
|
| 51 | - //capability check |
|
| 52 | - if ( |
|
| 53 | - ! EE_Registry::instance()->CAP->current_user_can( |
|
| 54 | - 'ee_read_default_prices', |
|
| 55 | - 'advanced_ticket_datetime_metabox' |
|
| 56 | - ) |
|
| 57 | - ) { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 60 | - $this->_setup_metaboxes(); |
|
| 61 | - $this->_set_date_time_formats(); |
|
| 62 | - $this->_validate_format_strings(); |
|
| 63 | - $this->_set_scripts_styles(); |
|
| 64 | - // commented out temporarily until logic is implemented in callback |
|
| 65 | - // add_action( |
|
| 66 | - // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
| 67 | - // array($this, 'autosave_handling') |
|
| 68 | - // ); |
|
| 69 | - add_filter( |
|
| 70 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 71 | - array($this, 'caf_updates') |
|
| 72 | - ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @return void |
|
| 79 | - */ |
|
| 80 | - protected function _setup_metaboxes() |
|
| 81 | - { |
|
| 82 | - //if we were going to add our own metaboxes we'd use the below. |
|
| 83 | - $this->_metaboxes = array( |
|
| 84 | - 0 => array( |
|
| 85 | - 'page_route' => array('edit', 'create_new'), |
|
| 86 | - 'func' => 'pricing_metabox', |
|
| 87 | - 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
| 88 | - 'priority' => 'high', |
|
| 89 | - 'context' => 'normal', |
|
| 90 | - ), |
|
| 91 | - ); |
|
| 92 | - $this->_remove_metaboxes = array( |
|
| 93 | - 0 => array( |
|
| 94 | - 'page_route' => array('edit', 'create_new'), |
|
| 95 | - 'id' => 'espresso_event_editor_tickets', |
|
| 96 | - 'context' => 'normal', |
|
| 97 | - ), |
|
| 98 | - ); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @return void |
|
| 105 | - */ |
|
| 106 | - protected function _set_date_time_formats() |
|
| 107 | - { |
|
| 108 | - /** |
|
| 109 | - * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
| 110 | - * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
| 111 | - * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
| 112 | - * |
|
| 113 | - * @since 4.6.7 |
|
| 114 | - * @var array Expected an array returned with 'date' and 'time' keys. |
|
| 115 | - */ |
|
| 116 | - $this->_date_format_strings = apply_filters( |
|
| 117 | - 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
| 118 | - array( |
|
| 119 | - 'date' => 'Y-m-d', |
|
| 120 | - 'time' => 'h:i a', |
|
| 121 | - ) |
|
| 122 | - ); |
|
| 123 | - //validate |
|
| 124 | - $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
| 125 | - ? $this->_date_format_strings['date'] |
|
| 126 | - : null; |
|
| 127 | - $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
| 128 | - ? $this->_date_format_strings['time'] |
|
| 129 | - : null; |
|
| 130 | - $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @return void |
|
| 137 | - */ |
|
| 138 | - protected function _validate_format_strings() |
|
| 139 | - { |
|
| 140 | - //validate format strings |
|
| 141 | - $format_validation = EEH_DTT_Helper::validate_format_string( |
|
| 142 | - $this->_date_time_format |
|
| 143 | - ); |
|
| 144 | - if (is_array($format_validation)) { |
|
| 145 | - $msg = '<p>'; |
|
| 146 | - $msg .= sprintf( |
|
| 147 | - esc_html__( |
|
| 148 | - 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
| 149 | - 'event_espresso' |
|
| 150 | - ), |
|
| 151 | - $this->_date_time_format |
|
| 152 | - ); |
|
| 153 | - $msg .= '</p><ul>'; |
|
| 154 | - foreach ($format_validation as $error) { |
|
| 155 | - $msg .= '<li>' . $error . '</li>'; |
|
| 156 | - } |
|
| 157 | - $msg .= '</ul><p>'; |
|
| 158 | - $msg .= sprintf( |
|
| 159 | - esc_html__( |
|
| 160 | - '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
| 161 | - 'event_espresso' |
|
| 162 | - ), |
|
| 163 | - '<span style="color:#D54E21;">', |
|
| 164 | - '</span>' |
|
| 165 | - ); |
|
| 166 | - $msg .= '</p>'; |
|
| 167 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 168 | - $this->_date_format_strings = array( |
|
| 169 | - 'date' => 'Y-m-d', |
|
| 170 | - 'time' => 'h:i a', |
|
| 171 | - ); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @return void |
|
| 179 | - */ |
|
| 180 | - protected function _set_scripts_styles() |
|
| 181 | - { |
|
| 182 | - $this->_scripts_styles = array( |
|
| 183 | - 'registers' => array( |
|
| 184 | - 'ee-tickets-datetimes-css' => array( |
|
| 185 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 186 | - 'type' => 'css', |
|
| 187 | - ), |
|
| 188 | - 'ee-dtt-ticket-metabox' => array( |
|
| 189 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 190 | - 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
| 191 | - ), |
|
| 192 | - ), |
|
| 193 | - 'deregisters' => array( |
|
| 194 | - 'event-editor-css' => array('type' => 'css'), |
|
| 195 | - 'event-datetime-metabox' => array('type' => 'js'), |
|
| 196 | - ), |
|
| 197 | - 'enqueues' => array( |
|
| 198 | - 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
| 199 | - 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
| 200 | - ), |
|
| 201 | - 'localize' => array( |
|
| 202 | - 'ee-dtt-ticket-metabox' => array( |
|
| 203 | - 'DTT_TRASH_BLOCK' => array( |
|
| 204 | - 'main_warning' => esc_html__( |
|
| 205 | - 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
| 206 | - 'event_espresso' |
|
| 207 | - ), |
|
| 208 | - 'after_warning' => esc_html__( |
|
| 209 | - 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
| 210 | - 'event_espresso' |
|
| 211 | - ), |
|
| 212 | - 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 213 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
| 214 | - 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 215 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
| 216 | - 'single_warning_from_tkt' => esc_html__( |
|
| 217 | - 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 218 | - 'event_espresso' |
|
| 219 | - ), |
|
| 220 | - 'single_warning_from_dtt' => esc_html__( |
|
| 221 | - 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 222 | - 'event_espresso' |
|
| 223 | - ), |
|
| 224 | - 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 225 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
| 226 | - ), |
|
| 227 | - 'DTT_ERROR_MSG' => array( |
|
| 228 | - 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
| 229 | - 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' |
|
| 230 | - . esc_html__('Dismiss', 'event_espresso') . '</button></div>', |
|
| 231 | - ), |
|
| 232 | - 'DTT_OVERSELL_WARNING' => array( |
|
| 233 | - 'datetime_ticket' => esc_html__( |
|
| 234 | - 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
| 235 | - 'event_espresso' |
|
| 236 | - ), |
|
| 237 | - 'ticket_datetime' => esc_html__( |
|
| 238 | - 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
| 239 | - 'event_espresso' |
|
| 240 | - ), |
|
| 241 | - ), |
|
| 242 | - 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
| 243 | - $this->_date_format_strings['date'], |
|
| 244 | - $this->_date_format_strings['time'] |
|
| 245 | - ), |
|
| 246 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')), |
|
| 247 | - ), |
|
| 248 | - ), |
|
| 249 | - ); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @param array $update_callbacks |
|
| 256 | - * @return array |
|
| 257 | - */ |
|
| 258 | - public function caf_updates(array $update_callbacks) |
|
| 259 | - { |
|
| 260 | - foreach ($update_callbacks as $key => $callback) { |
|
| 261 | - if ($callback[1] === '_default_tickets_update') { |
|
| 262 | - unset($update_callbacks[$key]); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
| 266 | - return $update_callbacks; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 272 | - * |
|
| 273 | - * @param EE_Event $event The Event object we're attaching data to |
|
| 274 | - * @param array $data The request data from the form |
|
| 275 | - * @throws EE_Error |
|
| 276 | - * @throws InvalidArgumentException |
|
| 277 | - */ |
|
| 278 | - public function datetime_and_tickets_caf_update($event, $data) |
|
| 279 | - { |
|
| 280 | - //first we need to start with datetimes cause they are the "root" items attached to events. |
|
| 281 | - $saved_datetimes = $this->_update_datetimes($event, $data); |
|
| 282 | - //next tackle the tickets (and prices?) |
|
| 283 | - $this->_update_tickets($event, $saved_datetimes, $data); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * update event_datetimes |
|
| 289 | - * |
|
| 290 | - * @param EE_Event $event Event being updated |
|
| 291 | - * @param array $data the request data from the form |
|
| 292 | - * @return EE_Datetime[] |
|
| 293 | - * @throws InvalidArgumentException |
|
| 294 | - * @throws EE_Error |
|
| 295 | - */ |
|
| 296 | - protected function _update_datetimes($event, $data) |
|
| 297 | - { |
|
| 298 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 299 | - $saved_dtt_ids = array(); |
|
| 300 | - $saved_dtt_objs = array(); |
|
| 301 | - if (empty($data['edit_event_datetimes']) || !is_array($data['edit_event_datetimes'])) { |
|
| 302 | - throw new InvalidArgumentException( |
|
| 303 | - esc_html__( |
|
| 304 | - 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
| 305 | - 'event_espresso' |
|
| 306 | - ) |
|
| 307 | - ); |
|
| 308 | - } |
|
| 309 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
| 310 | - //trim all values to ensure any excess whitespace is removed. |
|
| 311 | - $datetime_data = array_map( |
|
| 312 | - function ($datetime_data) { |
|
| 313 | - return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
| 314 | - }, |
|
| 315 | - $datetime_data |
|
| 316 | - ); |
|
| 317 | - $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
| 318 | - && ! empty($datetime_data['DTT_EVT_end']) |
|
| 319 | - ? $datetime_data['DTT_EVT_end'] |
|
| 320 | - : $datetime_data['DTT_EVT_start']; |
|
| 321 | - $datetime_values = array( |
|
| 322 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
| 323 | - ? $datetime_data['DTT_ID'] |
|
| 324 | - : null, |
|
| 325 | - 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
| 326 | - ? $datetime_data['DTT_name'] |
|
| 327 | - : '', |
|
| 328 | - 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
| 329 | - ? $datetime_data['DTT_description'] |
|
| 330 | - : '', |
|
| 331 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
| 332 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
| 333 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
| 334 | - ? EE_INF |
|
| 335 | - : $datetime_data['DTT_reg_limit'], |
|
| 336 | - 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
| 337 | - ? $row |
|
| 338 | - : $datetime_data['DTT_order'], |
|
| 339 | - ); |
|
| 340 | - // if we have an id then let's get existing object first and then set the new values. |
|
| 341 | - // Otherwise we instantiate a new object for save. |
|
| 342 | - if (! empty($datetime_data['DTT_ID'])) { |
|
| 343 | - $datetime = EE_Registry::instance() |
|
| 344 | - ->load_model('Datetime', array($timezone)) |
|
| 345 | - ->get_one_by_ID($datetime_data['DTT_ID']); |
|
| 346 | - //set date and time format according to what is set in this class. |
|
| 347 | - $datetime->set_date_format($this->_date_format_strings['date']); |
|
| 348 | - $datetime->set_time_format($this->_date_format_strings['time']); |
|
| 349 | - foreach ($datetime_values as $field => $value) { |
|
| 350 | - $datetime->set($field, $value); |
|
| 351 | - } |
|
| 352 | - // make sure the $dtt_id here is saved just in case |
|
| 353 | - // after the add_relation_to() the autosave replaces it. |
|
| 354 | - // We need to do this so we dont' TRASH the parent DTT. |
|
| 355 | - // (save the ID for both key and value to avoid duplications) |
|
| 356 | - $saved_dtt_ids[$datetime->ID()] = $datetime->ID(); |
|
| 357 | - } else { |
|
| 358 | - $datetime = EE_Registry::instance()->load_class( |
|
| 359 | - 'Datetime', |
|
| 360 | - array( |
|
| 361 | - $datetime_values, |
|
| 362 | - $timezone, |
|
| 363 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
| 364 | - ), |
|
| 365 | - false, |
|
| 366 | - false |
|
| 367 | - ); |
|
| 368 | - foreach ($datetime_values as $field => $value) { |
|
| 369 | - $datetime->set($field, $value); |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - $datetime->save(); |
|
| 373 | - $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
| 374 | - // before going any further make sure our dates are setup correctly |
|
| 375 | - // so that the end date is always equal or greater than the start date. |
|
| 376 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
| 377 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
| 378 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
| 379 | - $datetime->save(); |
|
| 380 | - } |
|
| 381 | - // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
| 382 | - // because it is possible there was a new one created for the autosave. |
|
| 383 | - // (save the ID for both key and value to avoid duplications) |
|
| 384 | - $DTT_ID = $datetime->ID(); |
|
| 385 | - $saved_dtt_ids[$DTT_ID] = $DTT_ID; |
|
| 386 | - $saved_dtt_objs[$row] = $datetime; |
|
| 387 | - //todo if ANY of these updates fail then we want the appropriate global error message. |
|
| 388 | - } |
|
| 389 | - $event->save(); |
|
| 390 | - // now we need to REMOVE any datetimes that got deleted. |
|
| 391 | - // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
| 392 | - // So its safe to permanently delete at this point. |
|
| 393 | - $old_datetimes = explode(',', $data['datetime_IDs']); |
|
| 394 | - $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
| 395 | - if (is_array($old_datetimes)) { |
|
| 396 | - $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
| 397 | - foreach ($datetimes_to_delete as $id) { |
|
| 398 | - $id = absint($id); |
|
| 399 | - if (empty($id)) { |
|
| 400 | - continue; |
|
| 401 | - } |
|
| 402 | - $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
| 403 | - //remove tkt relationships. |
|
| 404 | - $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
| 405 | - foreach ($related_tickets as $tkt) { |
|
| 406 | - $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
| 407 | - } |
|
| 408 | - $event->_remove_relation_to($id, 'Datetime'); |
|
| 409 | - $dtt_to_remove->refresh_cache_of_related_objects(); |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - return $saved_dtt_objs; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * update tickets |
|
| 418 | - * |
|
| 419 | - * @param EE_Event $event Event object being updated |
|
| 420 | - * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
| 421 | - * @param array $data incoming request data |
|
| 422 | - * @return EE_Ticket[] |
|
| 423 | - * @throws InvalidArgumentException |
|
| 424 | - * @throws EE_Error |
|
| 425 | - */ |
|
| 426 | - protected function _update_tickets($event, $saved_datetimes, $data) |
|
| 427 | - { |
|
| 428 | - $new_tkt = null; |
|
| 429 | - $new_default = null; |
|
| 430 | - //stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
| 431 | - $data = stripslashes_deep($data); |
|
| 432 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 433 | - $saved_tickets = $datetimes_on_existing = array(); |
|
| 434 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 435 | - if(empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])){ |
|
| 436 | - throw new InvalidArgumentException( |
|
| 437 | - esc_html__( |
|
| 438 | - 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
| 439 | - 'event_espresso' |
|
| 440 | - ) |
|
| 441 | - ); |
|
| 442 | - } |
|
| 443 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 444 | - $update_prices = $create_new_TKT = false; |
|
| 445 | - // figure out what datetimes were added to the ticket |
|
| 446 | - // and what datetimes were removed from the ticket in the session. |
|
| 447 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
| 448 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
| 449 | - $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
| 450 | - $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
| 451 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 452 | - $tkt = array_map( |
|
| 453 | - function ($ticket_data) { |
|
| 454 | - return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
| 455 | - }, |
|
| 456 | - $tkt |
|
| 457 | - ); |
|
| 458 | - // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
| 459 | - // because we're doing calculations prior to using the models. |
|
| 460 | - // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
| 461 | - $ticket_price = isset($tkt['TKT_price']) |
|
| 462 | - ? round((float)$tkt['TKT_price'], 3) |
|
| 463 | - : 0; |
|
| 464 | - //note incoming base price needs converted from localized value. |
|
| 465 | - $base_price = isset($tkt['TKT_base_price']) |
|
| 466 | - ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
| 467 | - : 0; |
|
| 468 | - //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
| 469 | - $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
| 470 | - ? $base_price |
|
| 471 | - : $ticket_price; |
|
| 472 | - $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
| 473 | - ? $tkt['TKT_base_price_ID'] |
|
| 474 | - : 0; |
|
| 475 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) |
|
| 476 | - ? $data['edit_prices'][$row] |
|
| 477 | - : array(); |
|
| 478 | - $now = null; |
|
| 479 | - if (empty($tkt['TKT_start_date'])) { |
|
| 480 | - //lets' use now in the set timezone. |
|
| 481 | - $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
| 482 | - $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
| 483 | - } |
|
| 484 | - if (empty($tkt['TKT_end_date'])) { |
|
| 485 | - /** |
|
| 486 | - * set the TKT_end_date to the first datetime attached to the ticket. |
|
| 487 | - */ |
|
| 488 | - $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)]; |
|
| 489 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
| 490 | - } |
|
| 491 | - $TKT_values = array( |
|
| 492 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 493 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 494 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 495 | - 'TKT_description' => ! empty($tkt['TKT_description']) |
|
| 496 | - && $tkt['TKT_description'] !== esc_html__( |
|
| 497 | - 'You can modify this description', |
|
| 498 | - 'event_espresso' |
|
| 499 | - ) |
|
| 500 | - ? $tkt['TKT_description'] |
|
| 501 | - : '', |
|
| 502 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 503 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 504 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
| 505 | - ? EE_INF |
|
| 506 | - : $tkt['TKT_qty'], |
|
| 507 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
| 508 | - ? EE_INF |
|
| 509 | - : $tkt['TKT_uses'], |
|
| 510 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 511 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 512 | - 'TKT_row' => $row, |
|
| 513 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
| 514 | - 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
| 515 | - 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
| 516 | - 'TKT_price' => $ticket_price, |
|
| 517 | - ); |
|
| 518 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 519 | - // which means in turn that the prices will become new prices as well. |
|
| 520 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 521 | - $TKT_values['TKT_ID'] = 0; |
|
| 522 | - $TKT_values['TKT_is_default'] = 0; |
|
| 523 | - $update_prices = true; |
|
| 524 | - } |
|
| 525 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 526 | - // we actually do our saves ahead of doing any add_relations to |
|
| 527 | - // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
| 528 | - // but DID have it's items modified. |
|
| 529 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
| 530 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 531 | - if (absint($TKT_values['TKT_ID'])) { |
|
| 532 | - $ticket = EE_Registry::instance() |
|
| 533 | - ->load_model('Ticket', array($timezone)) |
|
| 534 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
| 535 | - if ($ticket instanceof EE_Ticket) { |
|
| 536 | - $ticket = $this->_update_ticket_datetimes( |
|
| 537 | - $ticket, |
|
| 538 | - $saved_datetimes, |
|
| 539 | - $datetimes_added, |
|
| 540 | - $datetimes_removed |
|
| 541 | - ); |
|
| 542 | - // are there any registrations using this ticket ? |
|
| 543 | - $tickets_sold = $ticket->count_related( |
|
| 544 | - 'Registration', |
|
| 545 | - array( |
|
| 546 | - array( |
|
| 547 | - 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
| 548 | - ), |
|
| 549 | - ) |
|
| 550 | - ); |
|
| 551 | - //set ticket formats |
|
| 552 | - $ticket->set_date_format($this->_date_format_strings['date']); |
|
| 553 | - $ticket->set_time_format($this->_date_format_strings['time']); |
|
| 554 | - // let's just check the total price for the existing ticket |
|
| 555 | - // and determine if it matches the new total price. |
|
| 556 | - // if they are different then we create a new ticket (if tickets sold) |
|
| 557 | - // if they aren't different then we go ahead and modify existing ticket. |
|
| 558 | - $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
| 559 | - //set new values |
|
| 560 | - foreach ($TKT_values as $field => $value) { |
|
| 561 | - if ($field === 'TKT_qty') { |
|
| 562 | - $ticket->set_qty($value); |
|
| 563 | - } else { |
|
| 564 | - $ticket->set($field, $value); |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - // if $create_new_TKT is false then we can safely update the existing ticket. |
|
| 568 | - // Otherwise we have to create a new ticket. |
|
| 569 | - if ($create_new_TKT) { |
|
| 570 | - $new_tkt = $this->_duplicate_ticket($ticket, $price_rows, $ticket_price, $base_price, |
|
| 571 | - $base_price_id); |
|
| 572 | - } |
|
| 573 | - } |
|
| 574 | - } else { |
|
| 575 | - // no TKT_id so a new TKT |
|
| 576 | - $ticket = EE_Ticket::new_instance( |
|
| 577 | - $TKT_values, |
|
| 578 | - $timezone, |
|
| 579 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 580 | - ); |
|
| 581 | - if ($ticket instanceof EE_Ticket) { |
|
| 582 | - // make sure ticket has an ID of setting relations won't work |
|
| 583 | - $ticket->save(); |
|
| 584 | - $ticket = $this->_update_ticket_datetimes( |
|
| 585 | - $ticket, |
|
| 586 | - $saved_datetimes, |
|
| 587 | - $datetimes_added, |
|
| 588 | - $datetimes_removed |
|
| 589 | - ); |
|
| 590 | - $update_prices = true; |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - //make sure any current values have been saved. |
|
| 594 | - //$ticket->save(); |
|
| 595 | - // before going any further make sure our dates are setup correctly |
|
| 596 | - // so that the end date is always equal or greater than the start date. |
|
| 597 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
| 598 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
| 599 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
| 600 | - } |
|
| 601 | - //let's make sure the base price is handled |
|
| 602 | - $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $ticket, $update_prices, $base_price, |
|
| 603 | - $base_price_id) : $ticket; |
|
| 604 | - //add/update price_modifiers |
|
| 605 | - $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) : $ticket; |
|
| 606 | - //need to make sue that the TKT_price is accurate after saving the prices. |
|
| 607 | - $ticket->ensure_TKT_Price_correct(); |
|
| 608 | - //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
| 609 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 610 | - $update_prices = true; |
|
| 611 | - $new_default = clone $ticket; |
|
| 612 | - $new_default->set('TKT_ID', 0); |
|
| 613 | - $new_default->set('TKT_is_default', 1); |
|
| 614 | - $new_default->set('TKT_row', 1); |
|
| 615 | - $new_default->set('TKT_price', $ticket_price); |
|
| 616 | - // remove any dtt relations cause we DON'T want dtt relations attached |
|
| 617 | - // (note this is just removing the cached relations in the object) |
|
| 618 | - $new_default->_remove_relations('Datetime'); |
|
| 619 | - //todo we need to add the current attached prices as new prices to the new default ticket. |
|
| 620 | - $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
| 621 | - //don't forget the base price! |
|
| 622 | - $new_default = $this->_add_prices_to_ticket( |
|
| 623 | - array(), |
|
| 624 | - $new_default, |
|
| 625 | - $update_prices, |
|
| 626 | - $base_price, |
|
| 627 | - $base_price_id |
|
| 628 | - ); |
|
| 629 | - $new_default->save(); |
|
| 630 | - do_action( |
|
| 631 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
| 632 | - $new_default, |
|
| 633 | - $row, |
|
| 634 | - $ticket, |
|
| 635 | - $data |
|
| 636 | - ); |
|
| 637 | - } |
|
| 638 | - // DO ALL dtt relationships for both current tickets and any archived tickets |
|
| 639 | - // for the given dtt that are related to the current ticket. |
|
| 640 | - // TODO... not sure exactly how we're going to do this considering we don't know |
|
| 641 | - // what current ticket the archived tickets are related to |
|
| 642 | - // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
| 643 | - //let's assign any tickets that have been setup to the saved_tickets tracker |
|
| 644 | - //save existing TKT |
|
| 645 | - $ticket->save(); |
|
| 646 | - if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
| 647 | - //save new TKT |
|
| 648 | - $new_tkt->save(); |
|
| 649 | - //add new ticket to array |
|
| 650 | - $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
| 651 | - do_action( |
|
| 652 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
| 653 | - $new_tkt, |
|
| 654 | - $row, |
|
| 655 | - $tkt, |
|
| 656 | - $data |
|
| 657 | - ); |
|
| 658 | - } else { |
|
| 659 | - //add tkt to saved tkts |
|
| 660 | - $saved_tickets[$ticket->ID()] = $ticket; |
|
| 661 | - do_action( |
|
| 662 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
| 663 | - $ticket, |
|
| 664 | - $row, |
|
| 665 | - $tkt, |
|
| 666 | - $data |
|
| 667 | - ); |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - // now we need to handle tickets actually "deleted permanently". |
|
| 671 | - // There are cases where we'd want this to happen |
|
| 672 | - // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
| 673 | - // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
| 674 | - // No sense in keeping all the related data in the db! |
|
| 675 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
| 676 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 677 | - foreach ($tickets_removed as $id) { |
|
| 678 | - $id = absint($id); |
|
| 679 | - //get the ticket for this id |
|
| 680 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 681 | - //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
| 682 | - if ($tkt_to_remove->get('TKT_is_default')) { |
|
| 683 | - continue; |
|
| 684 | - } |
|
| 685 | - // if this tkt has any registrations attached so then we just ARCHIVE |
|
| 686 | - // because we don't actually permanently delete these tickets. |
|
| 687 | - if ($tkt_to_remove->count_related('Registration') > 0) { |
|
| 688 | - $tkt_to_remove->delete(); |
|
| 689 | - continue; |
|
| 690 | - } |
|
| 691 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 692 | - // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 693 | - $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
| 694 | - foreach ($datetimes as $datetime) { |
|
| 695 | - $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
| 696 | - } |
|
| 697 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
| 698 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 699 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 700 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
| 701 | - // finally let's delete this ticket |
|
| 702 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 703 | - $tkt_to_remove->delete_permanently(); |
|
| 704 | - } |
|
| 705 | - return $saved_tickets; |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * @access protected |
|
| 712 | - * @param \EE_Ticket $ticket |
|
| 713 | - * @param \EE_Datetime[] $saved_datetimes |
|
| 714 | - * @param \EE_Datetime[] $added_datetimes |
|
| 715 | - * @param \EE_Datetime[] $removed_datetimes |
|
| 716 | - * @return \EE_Ticket |
|
| 717 | - * @throws \EE_Error |
|
| 718 | - */ |
|
| 719 | - protected function _update_ticket_datetimes( |
|
| 720 | - EE_Ticket $ticket, |
|
| 721 | - $saved_datetimes = array(), |
|
| 722 | - $added_datetimes = array(), |
|
| 723 | - $removed_datetimes = array() |
|
| 724 | - ) { |
|
| 725 | - // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
| 726 | - // and removing the ticket from datetimes it got removed from. |
|
| 727 | - // first let's add datetimes |
|
| 728 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 729 | - foreach ($added_datetimes as $row_id) { |
|
| 730 | - $row_id = (int)$row_id; |
|
| 731 | - if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 732 | - $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 733 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 734 | - // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
| 735 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 736 | - $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
| 737 | - $saved_datetimes[$row_id]->save(); |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - // then remove datetimes |
|
| 743 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 744 | - foreach ($removed_datetimes as $row_id) { |
|
| 745 | - $row_id = (int)$row_id; |
|
| 746 | - // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
| 747 | - // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
| 748 | - if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 749 | - $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 750 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 751 | - // If so, then we need to remove it's sold from the DTT_sold. |
|
| 752 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 753 | - $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
| 754 | - $saved_datetimes[$row_id]->save(); |
|
| 755 | - } |
|
| 756 | - } |
|
| 757 | - } |
|
| 758 | - } |
|
| 759 | - // cap ticket qty by datetime reg limits |
|
| 760 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 761 | - return $ticket; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * @access protected |
|
| 768 | - * @param \EE_Ticket $ticket |
|
| 769 | - * @param array $price_rows |
|
| 770 | - * @param int $ticket_price |
|
| 771 | - * @param int $base_price |
|
| 772 | - * @param int $base_price_id |
|
| 773 | - * @return \EE_Ticket |
|
| 774 | - * @throws \EE_Error |
|
| 775 | - */ |
|
| 776 | - protected function _duplicate_ticket( |
|
| 777 | - EE_Ticket $ticket, |
|
| 778 | - $price_rows = array(), |
|
| 779 | - $ticket_price = 0, |
|
| 780 | - $base_price = 0, |
|
| 781 | - $base_price_id = 0 |
|
| 782 | - ) { |
|
| 783 | - // create new ticket that's a copy of the existing |
|
| 784 | - // except a new id of course (and not archived) |
|
| 785 | - // AND has the new TKT_price associated with it. |
|
| 786 | - $new_ticket = clone $ticket; |
|
| 787 | - $new_ticket->set('TKT_ID', 0); |
|
| 788 | - $new_ticket->set('TKT_deleted', 0); |
|
| 789 | - $new_ticket->set('TKT_price', $ticket_price); |
|
| 790 | - $new_ticket->set('TKT_sold', 0); |
|
| 791 | - // let's get a new ID for this ticket |
|
| 792 | - $new_ticket->save(); |
|
| 793 | - // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
| 794 | - $datetimes_on_existing = $ticket->get_many_related('Datetime'); |
|
| 795 | - $new_ticket = $this->_update_ticket_datetimes( |
|
| 796 | - $new_ticket, |
|
| 797 | - $datetimes_on_existing, |
|
| 798 | - array_keys($datetimes_on_existing) |
|
| 799 | - ); |
|
| 800 | - // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
| 801 | - // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
| 802 | - // available. |
|
| 803 | - if ($ticket->sold() > 0) { |
|
| 804 | - $new_qty = $ticket->qty() - $ticket->sold(); |
|
| 805 | - $new_ticket->set_qty($new_qty); |
|
| 806 | - } |
|
| 807 | - //now we update the prices just for this ticket |
|
| 808 | - $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
| 809 | - //and we update the base price |
|
| 810 | - $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
| 811 | - return $new_ticket; |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - |
|
| 816 | - /** |
|
| 817 | - * This attaches a list of given prices to a ticket. |
|
| 818 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 819 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 820 | - * price info and prices are automatically "archived" via the ticket. |
|
| 821 | - * |
|
| 822 | - * @access private |
|
| 823 | - * @param array $prices Array of prices from the form. |
|
| 824 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 825 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 826 | - * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
| 827 | - * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
| 828 | - * @return EE_Ticket |
|
| 829 | - * @throws EE_Error |
|
| 830 | - */ |
|
| 831 | - protected function _add_prices_to_ticket( |
|
| 832 | - $prices = array(), |
|
| 833 | - EE_Ticket $ticket, |
|
| 834 | - $new_prices = false, |
|
| 835 | - $base_price = false, |
|
| 836 | - $base_price_id = false |
|
| 837 | - ) { |
|
| 838 | - // let's just get any current prices that may exist on the given ticket |
|
| 839 | - // so we can remove any prices that got trashed in this session. |
|
| 840 | - $current_prices_on_ticket = $base_price !== false |
|
| 841 | - ? $ticket->base_price(true) |
|
| 842 | - : $ticket->price_modifiers(); |
|
| 843 | - $updated_prices = array(); |
|
| 844 | - // if $base_price ! FALSE then updating a base price. |
|
| 845 | - if ($base_price !== false) { |
|
| 846 | - $prices[1] = array( |
|
| 847 | - 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
| 848 | - 'PRT_ID' => 1, |
|
| 849 | - 'PRC_amount' => $base_price, |
|
| 850 | - 'PRC_name' => $ticket->get('TKT_name'), |
|
| 851 | - 'PRC_desc' => $ticket->get('TKT_description'), |
|
| 852 | - ); |
|
| 853 | - } |
|
| 854 | - //possibly need to save tkt |
|
| 855 | - if (! $ticket->ID()) { |
|
| 856 | - $ticket->save(); |
|
| 857 | - } |
|
| 858 | - foreach ($prices as $row => $prc) { |
|
| 859 | - $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
| 860 | - if (empty($prt_id)) { |
|
| 861 | - continue; |
|
| 862 | - } //prices MUST have a price type id. |
|
| 863 | - $PRC_values = array( |
|
| 864 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 865 | - 'PRT_ID' => $prt_id, |
|
| 866 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 867 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 868 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 869 | - 'PRC_is_default' => false, |
|
| 870 | - //make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
| 871 | - 'PRC_order' => $row, |
|
| 872 | - ); |
|
| 873 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 874 | - $PRC_values['PRC_ID'] = 0; |
|
| 875 | - $price = EE_Registry::instance()->load_class( |
|
| 876 | - 'Price', |
|
| 877 | - array($PRC_values), |
|
| 878 | - false, |
|
| 879 | - false |
|
| 880 | - ); |
|
| 881 | - } else { |
|
| 882 | - $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 883 | - //update this price with new values |
|
| 884 | - foreach ($PRC_values as $field => $value) { |
|
| 885 | - $price->set($field, $value); |
|
| 886 | - } |
|
| 887 | - } |
|
| 888 | - $price->save(); |
|
| 889 | - $updated_prices[$price->ID()] = $price; |
|
| 890 | - $ticket->_add_relation_to($price, 'Price'); |
|
| 891 | - } |
|
| 892 | - //now let's remove any prices that got removed from the ticket |
|
| 893 | - if (! empty ($current_prices_on_ticket)) { |
|
| 894 | - $current = array_keys($current_prices_on_ticket); |
|
| 895 | - $updated = array_keys($updated_prices); |
|
| 896 | - $prices_to_remove = array_diff($current, $updated); |
|
| 897 | - if (! empty($prices_to_remove)) { |
|
| 898 | - foreach ($prices_to_remove as $prc_id) { |
|
| 899 | - $p = $current_prices_on_ticket[$prc_id]; |
|
| 900 | - $ticket->_remove_relation_to($p, 'Price'); |
|
| 901 | - //delete permanently the price |
|
| 902 | - $p->delete_permanently(); |
|
| 903 | - } |
|
| 904 | - } |
|
| 905 | - } |
|
| 906 | - return $ticket; |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - |
|
| 910 | - |
|
| 911 | - /** |
|
| 912 | - * @param Events_Admin_Page $event_admin_obj |
|
| 913 | - * @return Events_Admin_Page |
|
| 914 | - */ |
|
| 915 | - public function autosave_handling( Events_Admin_Page $event_admin_obj) |
|
| 916 | - { |
|
| 917 | - return $event_admin_obj; |
|
| 918 | - //doing nothing for the moment. |
|
| 919 | - // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
| 920 | - // (use the set_template_args() method) |
|
| 921 | - /** |
|
| 922 | - * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
| 923 | - * 1. TKT_is_default_selector (visible) |
|
| 924 | - * 2. TKT_is_default (hidden) |
|
| 925 | - * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
| 926 | - * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
| 927 | - * this ticket to be saved as a default. |
|
| 928 | - * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
| 929 | - * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
| 930 | - * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
| 931 | - * the TKT HAS been saved as a default.. |
|
| 932 | - * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
| 933 | - * On Autosave: |
|
| 934 | - * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
| 935 | - * then set the TKT_is_default to false. |
|
| 936 | - * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
| 937 | - * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
| 938 | - * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
| 939 | - */ |
|
| 940 | - } |
|
| 941 | - |
|
| 942 | - |
|
| 943 | - |
|
| 944 | - /** |
|
| 945 | - * @throws DomainException |
|
| 946 | - * @throws EE_Error |
|
| 947 | - */ |
|
| 948 | - public function pricing_metabox() |
|
| 949 | - { |
|
| 950 | - $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
| 951 | - $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
| 952 | - //set is_creating_event property. |
|
| 953 | - $EVT_ID = $event->ID(); |
|
| 954 | - $this->_is_creating_event = absint($EVT_ID) === 0; |
|
| 955 | - //default main template args |
|
| 956 | - $main_template_args = array( |
|
| 957 | - 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
| 958 | - 'event_editor_event_datetimes_help_tab', |
|
| 959 | - $this->_adminpage_obj->page_slug, |
|
| 960 | - $this->_adminpage_obj->get_req_action(), |
|
| 961 | - false, |
|
| 962 | - false |
|
| 963 | - ), |
|
| 964 | - // todo need to add a filter to the template for the help text |
|
| 965 | - // in the Events_Admin_Page core file so we can add further help |
|
| 966 | - 'existing_datetime_ids' => '', |
|
| 967 | - 'total_dtt_rows' => 1, |
|
| 968 | - 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
| 969 | - 'add_new_dtt_info', |
|
| 970 | - $this->_adminpage_obj->page_slug, |
|
| 971 | - $this->_adminpage_obj->get_req_action(), |
|
| 972 | - false, |
|
| 973 | - false |
|
| 974 | - ), |
|
| 975 | - //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 976 | - 'datetime_rows' => '', |
|
| 977 | - 'show_tickets_container' => '', |
|
| 978 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
| 979 | - 'ticket_rows' => '', |
|
| 980 | - 'existing_ticket_ids' => '', |
|
| 981 | - 'total_ticket_rows' => 1, |
|
| 982 | - 'ticket_js_structure' => '', |
|
| 983 | - 'ee_collapsible_status' => ' ee-collapsible-open' |
|
| 984 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
| 985 | - ); |
|
| 986 | - $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
| 987 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 988 | - /** |
|
| 989 | - * 1. Start with retrieving Datetimes |
|
| 990 | - * 2. For each datetime get related tickets |
|
| 991 | - * 3. For each ticket get related prices |
|
| 992 | - */ |
|
| 993 | - /** @var EEM_Datetime $datetime_model */ |
|
| 994 | - $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
| 995 | - $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
| 996 | - $main_template_args['total_dtt_rows'] = count($datetimes); |
|
| 997 | - /** |
|
| 998 | - * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
| 999 | - * for why we are counting $datetime_row and then setting that on the Datetime object |
|
| 1000 | - */ |
|
| 1001 | - $datetime_row = 1; |
|
| 1002 | - foreach ($datetimes as $datetime) { |
|
| 1003 | - $DTT_ID = $datetime->get('DTT_ID'); |
|
| 1004 | - $datetime->set('DTT_order', $datetime_row); |
|
| 1005 | - $existing_datetime_ids[] = $DTT_ID; |
|
| 1006 | - //tickets attached |
|
| 1007 | - $related_tickets = $datetime->ID() > 0 |
|
| 1008 | - ? $datetime->get_many_related( |
|
| 1009 | - 'Ticket', |
|
| 1010 | - array( |
|
| 1011 | - array( |
|
| 1012 | - 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
| 1013 | - ), |
|
| 1014 | - 'default_where_conditions' => 'none', |
|
| 1015 | - 'order_by' => array('TKT_order' => 'ASC'), |
|
| 1016 | - ) |
|
| 1017 | - ) |
|
| 1018 | - : array(); |
|
| 1019 | - //if there are no related tickets this is likely a new event OR autodraft |
|
| 1020 | - // event so we need to generate the default tickets because datetimes |
|
| 1021 | - // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
| 1022 | - // datetime on the event. |
|
| 1023 | - if (empty ($related_tickets) && count($datetimes) < 2) { |
|
| 1024 | - /** @var EEM_Ticket $ticket_model */ |
|
| 1025 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 1026 | - $related_tickets = $ticket_model->get_all_default_tickets(); |
|
| 1027 | - // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
| 1028 | - // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
| 1029 | - $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
| 1030 | - $main_default_ticket = reset($related_tickets); |
|
| 1031 | - if ($main_default_ticket instanceof EE_Ticket) { |
|
| 1032 | - foreach ($default_prices as $default_price) { |
|
| 1033 | - if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
| 1034 | - continue; |
|
| 1035 | - } |
|
| 1036 | - $main_default_ticket->cache('Price', $default_price); |
|
| 1037 | - } |
|
| 1038 | - } |
|
| 1039 | - } |
|
| 1040 | - // we can't actually setup rows in this loop yet cause we don't know all |
|
| 1041 | - // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
| 1042 | - // So we're going to temporarily cache some of that information. |
|
| 1043 | - //loop through and setup the ticket rows and make sure the order is set. |
|
| 1044 | - foreach ($related_tickets as $ticket) { |
|
| 1045 | - $TKT_ID = $ticket->get('TKT_ID'); |
|
| 1046 | - $ticket_row = $ticket->get('TKT_row'); |
|
| 1047 | - //we only want unique tickets in our final display!! |
|
| 1048 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1049 | - $existing_ticket_ids[] = $TKT_ID; |
|
| 1050 | - $all_tickets[] = $ticket; |
|
| 1051 | - } |
|
| 1052 | - //temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
| 1053 | - $datetime_tickets[$DTT_ID][] = $ticket_row; |
|
| 1054 | - //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
| 1055 | - if ( |
|
| 1056 | - ! isset($ticket_datetimes[$TKT_ID]) |
|
| 1057 | - || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true) |
|
| 1058 | - ) { |
|
| 1059 | - $ticket_datetimes[$TKT_ID][] = $datetime_row; |
|
| 1060 | - } |
|
| 1061 | - } |
|
| 1062 | - $datetime_row++; |
|
| 1063 | - } |
|
| 1064 | - $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
| 1065 | - $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1066 | - $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1067 | - //sort $all_tickets by order |
|
| 1068 | - usort( |
|
| 1069 | - $all_tickets, |
|
| 1070 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
| 1071 | - $a_order = (int)$a->get('TKT_order'); |
|
| 1072 | - $b_order = (int)$b->get('TKT_order'); |
|
| 1073 | - if ($a_order === $b_order) { |
|
| 1074 | - return 0; |
|
| 1075 | - } |
|
| 1076 | - return ($a_order < $b_order) ? -1 : 1; |
|
| 1077 | - } |
|
| 1078 | - ); |
|
| 1079 | - // k NOW we have all the data we need for setting up the dtt rows |
|
| 1080 | - // and ticket rows so we start our dtt loop again. |
|
| 1081 | - $datetime_row = 1; |
|
| 1082 | - foreach ($datetimes as $datetime) { |
|
| 1083 | - $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
| 1084 | - $datetime_row, |
|
| 1085 | - $datetime, |
|
| 1086 | - $datetime_tickets, |
|
| 1087 | - $all_tickets, |
|
| 1088 | - false, |
|
| 1089 | - $datetimes |
|
| 1090 | - ); |
|
| 1091 | - $datetime_row++; |
|
| 1092 | - } |
|
| 1093 | - //then loop through all tickets for the ticket rows. |
|
| 1094 | - $ticket_row = 1; |
|
| 1095 | - foreach ($all_tickets as $ticket) { |
|
| 1096 | - $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
| 1097 | - $ticket_row, |
|
| 1098 | - $ticket, |
|
| 1099 | - $ticket_datetimes, |
|
| 1100 | - $datetimes, |
|
| 1101 | - false, |
|
| 1102 | - $all_tickets |
|
| 1103 | - ); |
|
| 1104 | - $ticket_row++; |
|
| 1105 | - } |
|
| 1106 | - $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
| 1107 | - EEH_Template::display_template( |
|
| 1108 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
| 1109 | - $main_template_args |
|
| 1110 | - ); |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - |
|
| 1114 | - |
|
| 1115 | - /** |
|
| 1116 | - * @param int $datetime_row |
|
| 1117 | - * @param EE_Datetime $datetime |
|
| 1118 | - * @param array $datetime_tickets |
|
| 1119 | - * @param array $all_tickets |
|
| 1120 | - * @param bool $default |
|
| 1121 | - * @param array $all_datetimes |
|
| 1122 | - * @return mixed |
|
| 1123 | - * @throws DomainException |
|
| 1124 | - * @throws EE_Error |
|
| 1125 | - */ |
|
| 1126 | - protected function _get_datetime_row( |
|
| 1127 | - $datetime_row, |
|
| 1128 | - EE_Datetime $datetime, |
|
| 1129 | - $datetime_tickets = array(), |
|
| 1130 | - $all_tickets = array(), |
|
| 1131 | - $default = false, |
|
| 1132 | - $all_datetimes = array() |
|
| 1133 | - ) { |
|
| 1134 | - $dtt_display_template_args = array( |
|
| 1135 | - 'dtt_edit_row' => $this->_get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes), |
|
| 1136 | - 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
| 1137 | - $datetime_row, |
|
| 1138 | - $datetime, |
|
| 1139 | - $datetime_tickets, |
|
| 1140 | - $all_tickets, |
|
| 1141 | - $default |
|
| 1142 | - ), |
|
| 1143 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1144 | - ); |
|
| 1145 | - return EEH_Template::display_template( |
|
| 1146 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
| 1147 | - $dtt_display_template_args, |
|
| 1148 | - true |
|
| 1149 | - ); |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - |
|
| 1153 | - |
|
| 1154 | - /** |
|
| 1155 | - * This method is used to generate a dtt fields edit row. |
|
| 1156 | - * The same row is used to generate a row with valid DTT objects |
|
| 1157 | - * and the default row that is used as the skeleton by the js. |
|
| 1158 | - * |
|
| 1159 | - * @param int $datetime_row The row number for the row being generated. |
|
| 1160 | - * @param EE_Datetime $datetime |
|
| 1161 | - * @param bool $default Whether a default row is being generated or not. |
|
| 1162 | - * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
| 1163 | - * @return string |
|
| 1164 | - * @throws DomainException |
|
| 1165 | - * @throws EE_Error |
|
| 1166 | - */ |
|
| 1167 | - protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
| 1168 | - { |
|
| 1169 | - // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
| 1170 | - $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
| 1171 | - $template_args = array( |
|
| 1172 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1173 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1174 | - 'edit_dtt_expanded' => '', |
|
| 1175 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1176 | - 'DTT_name' => $default ? '' : $datetime->name(), |
|
| 1177 | - 'DTT_description' => $default ? '' : $datetime->description(), |
|
| 1178 | - 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
| 1179 | - 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
| 1180 | - 'DTT_reg_limit' => $default |
|
| 1181 | - ? '' |
|
| 1182 | - : $datetime->get_pretty( |
|
| 1183 | - 'DTT_reg_limit', |
|
| 1184 | - 'input' |
|
| 1185 | - ), |
|
| 1186 | - 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1187 | - 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
| 1188 | - 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
| 1189 | - 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1190 | - ? '' |
|
| 1191 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1192 | - 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1193 | - ? 'ee-lock-icon' |
|
| 1194 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1195 | - 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
| 1196 | - ? '' |
|
| 1197 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1198 | - array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
| 1199 | - REG_ADMIN_URL |
|
| 1200 | - ), |
|
| 1201 | - ); |
|
| 1202 | - $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1203 | - ? ' style="display:none"' |
|
| 1204 | - : ''; |
|
| 1205 | - //allow filtering of template args at this point. |
|
| 1206 | - $template_args = apply_filters( |
|
| 1207 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
| 1208 | - $template_args, |
|
| 1209 | - $datetime_row, |
|
| 1210 | - $datetime, |
|
| 1211 | - $default, |
|
| 1212 | - $all_datetimes, |
|
| 1213 | - $this->_is_creating_event |
|
| 1214 | - ); |
|
| 1215 | - return EEH_Template::display_template( |
|
| 1216 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
| 1217 | - $template_args, |
|
| 1218 | - true |
|
| 1219 | - ); |
|
| 1220 | - } |
|
| 1221 | - |
|
| 1222 | - |
|
| 1223 | - |
|
| 1224 | - /** |
|
| 1225 | - * @param int $datetime_row |
|
| 1226 | - * @param EE_Datetime $datetime |
|
| 1227 | - * @param array $datetime_tickets |
|
| 1228 | - * @param array $all_tickets |
|
| 1229 | - * @param bool $default |
|
| 1230 | - * @return mixed |
|
| 1231 | - * @throws DomainException |
|
| 1232 | - * @throws EE_Error |
|
| 1233 | - */ |
|
| 1234 | - protected function _get_dtt_attached_tickets_row( |
|
| 1235 | - $datetime_row, |
|
| 1236 | - $datetime, |
|
| 1237 | - $datetime_tickets = array(), |
|
| 1238 | - $all_tickets = array(), |
|
| 1239 | - $default |
|
| 1240 | - ) { |
|
| 1241 | - $template_args = array( |
|
| 1242 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1243 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1244 | - 'DTT_description' => $default ? '' : $datetime->description(), |
|
| 1245 | - 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1246 | - 'show_tickets_row' => ' style="display:none;"', |
|
| 1247 | - 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
| 1248 | - 'add_new_ticket_via_datetime', |
|
| 1249 | - $this->_adminpage_obj->page_slug, |
|
| 1250 | - $this->_adminpage_obj->get_req_action(), |
|
| 1251 | - false, |
|
| 1252 | - false |
|
| 1253 | - ), |
|
| 1254 | - //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1255 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1256 | - ); |
|
| 1257 | - //need to setup the list items (but only if this isn't a default skeleton setup) |
|
| 1258 | - if (! $default) { |
|
| 1259 | - $ticket_row = 1; |
|
| 1260 | - foreach ($all_tickets as $ticket) { |
|
| 1261 | - $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 1262 | - $datetime_row, |
|
| 1263 | - $ticket_row, |
|
| 1264 | - $datetime, |
|
| 1265 | - $ticket, |
|
| 1266 | - $datetime_tickets, |
|
| 1267 | - $default |
|
| 1268 | - ); |
|
| 1269 | - $ticket_row++; |
|
| 1270 | - } |
|
| 1271 | - } |
|
| 1272 | - //filter template args at this point |
|
| 1273 | - $template_args = apply_filters( |
|
| 1274 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
| 1275 | - $template_args, |
|
| 1276 | - $datetime_row, |
|
| 1277 | - $datetime, |
|
| 1278 | - $datetime_tickets, |
|
| 1279 | - $all_tickets, |
|
| 1280 | - $default, |
|
| 1281 | - $this->_is_creating_event |
|
| 1282 | - ); |
|
| 1283 | - return EEH_Template::display_template( |
|
| 1284 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1285 | - $template_args, |
|
| 1286 | - true |
|
| 1287 | - ); |
|
| 1288 | - } |
|
| 1289 | - |
|
| 1290 | - |
|
| 1291 | - |
|
| 1292 | - /** |
|
| 1293 | - * @param int $datetime_row |
|
| 1294 | - * @param int $ticket_row |
|
| 1295 | - * @param EE_Datetime $datetime |
|
| 1296 | - * @param EE_Ticket $ticket |
|
| 1297 | - * @param array $datetime_tickets |
|
| 1298 | - * @param bool $default |
|
| 1299 | - * @return mixed |
|
| 1300 | - * @throws DomainException |
|
| 1301 | - * @throws EE_Error |
|
| 1302 | - */ |
|
| 1303 | - protected function _get_datetime_tickets_list_item( |
|
| 1304 | - $datetime_row, |
|
| 1305 | - $ticket_row, |
|
| 1306 | - $datetime, |
|
| 1307 | - $ticket, |
|
| 1308 | - $datetime_tickets = array(), |
|
| 1309 | - $default |
|
| 1310 | - ) { |
|
| 1311 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()]) |
|
| 1312 | - ? $datetime_tickets[$datetime->ID()] |
|
| 1313 | - : array(); |
|
| 1314 | - $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
| 1315 | - $no_ticket = $default && empty($ticket); |
|
| 1316 | - $template_args = array( |
|
| 1317 | - 'dtt_row' => $default |
|
| 1318 | - ? 'DTTNUM' |
|
| 1319 | - : $datetime_row, |
|
| 1320 | - 'tkt_row' => $no_ticket |
|
| 1321 | - ? 'TICKETNUM' |
|
| 1322 | - : $ticket_row, |
|
| 1323 | - 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
| 1324 | - ? ' checked="checked"' |
|
| 1325 | - : '', |
|
| 1326 | - 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
| 1327 | - ? ' ticket-selected' |
|
| 1328 | - : '', |
|
| 1329 | - 'TKT_name' => $no_ticket |
|
| 1330 | - ? 'TKTNAME' |
|
| 1331 | - : $ticket->get('TKT_name'), |
|
| 1332 | - 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
| 1333 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1334 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1335 | - ); |
|
| 1336 | - //filter template args |
|
| 1337 | - $template_args = apply_filters( |
|
| 1338 | - 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
| 1339 | - $template_args, |
|
| 1340 | - $datetime_row, |
|
| 1341 | - $ticket_row, |
|
| 1342 | - $datetime, |
|
| 1343 | - $ticket, |
|
| 1344 | - $datetime_tickets, |
|
| 1345 | - $default, |
|
| 1346 | - $this->_is_creating_event |
|
| 1347 | - ); |
|
| 1348 | - return EEH_Template::display_template( |
|
| 1349 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1350 | - $template_args, |
|
| 1351 | - true |
|
| 1352 | - ); |
|
| 1353 | - } |
|
| 1354 | - |
|
| 1355 | - |
|
| 1356 | - |
|
| 1357 | - /** |
|
| 1358 | - * This generates the ticket row for tickets. |
|
| 1359 | - * This same method is used to generate both the actual rows and the js skeleton row |
|
| 1360 | - * (when default === true) |
|
| 1361 | - * |
|
| 1362 | - * @param int $ticket_row Represents the row number being generated. |
|
| 1363 | - * @param $ticket |
|
| 1364 | - * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
| 1365 | - * or empty for default |
|
| 1366 | - * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
| 1367 | - * @param bool $default Whether default row being generated or not. |
|
| 1368 | - * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
| 1369 | - * (or empty in the case of defaults) |
|
| 1370 | - * @return mixed |
|
| 1371 | - * @throws DomainException |
|
| 1372 | - * @throws EE_Error |
|
| 1373 | - */ |
|
| 1374 | - protected function _get_ticket_row( |
|
| 1375 | - $ticket_row, |
|
| 1376 | - $ticket, |
|
| 1377 | - $ticket_datetimes, |
|
| 1378 | - $all_datetimes, |
|
| 1379 | - $default = false, |
|
| 1380 | - $all_tickets = array() |
|
| 1381 | - ) { |
|
| 1382 | - // if $ticket is not an instance of EE_Ticket then force default to true. |
|
| 1383 | - $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
| 1384 | - $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', |
|
| 1385 | - array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
| 1386 | - // if there is only one price (which would be the base price) |
|
| 1387 | - // or NO prices and this ticket is a default ticket, |
|
| 1388 | - // let's just make sure there are no cached default prices on the object. |
|
| 1389 | - // This is done by not including any query_params. |
|
| 1390 | - if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
| 1391 | - $prices = $ticket->get_many_related('Price'); |
|
| 1392 | - } |
|
| 1393 | - // check if we're dealing with a default ticket in which case |
|
| 1394 | - // we don't want any starting_ticket_datetime_row values set |
|
| 1395 | - // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
| 1396 | - // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
| 1397 | - $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')); |
|
| 1398 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
| 1399 | - ? $ticket_datetimes[$ticket->ID()] |
|
| 1400 | - : array(); |
|
| 1401 | - $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1402 | - $base_price = $default ? null : $ticket->base_price(); |
|
| 1403 | - $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
| 1404 | - //breaking out complicated condition for ticket_status |
|
| 1405 | - if ($default) { |
|
| 1406 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1407 | - } else { |
|
| 1408 | - $ticket_status_class = $ticket->is_default() |
|
| 1409 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1410 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1411 | - } |
|
| 1412 | - //breaking out complicated condition for TKT_taxable |
|
| 1413 | - if ($default) { |
|
| 1414 | - $TKT_taxable = ''; |
|
| 1415 | - } else { |
|
| 1416 | - $TKT_taxable = $ticket->get('TKT_taxable') |
|
| 1417 | - ? ' checked="checked"' |
|
| 1418 | - : ''; |
|
| 1419 | - } |
|
| 1420 | - if ($default) { |
|
| 1421 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1422 | - } else if ($ticket->is_default()) { |
|
| 1423 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1424 | - } else { |
|
| 1425 | - $TKT_status = $ticket->ticket_status(true); |
|
| 1426 | - } |
|
| 1427 | - if ($default) { |
|
| 1428 | - $TKT_min = ''; |
|
| 1429 | - } else { |
|
| 1430 | - $TKT_min = $ticket->get('TKT_min'); |
|
| 1431 | - if ($TKT_min === -1 || $TKT_min === 0) { |
|
| 1432 | - $TKT_min = ''; |
|
| 1433 | - } |
|
| 1434 | - } |
|
| 1435 | - $template_args = array( |
|
| 1436 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1437 | - 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1438 | - //on initial page load this will always be the correct order. |
|
| 1439 | - 'tkt_status_class' => $ticket_status_class, |
|
| 1440 | - 'display_edit_tkt_row' => ' style="display:none;"', |
|
| 1441 | - 'edit_tkt_expanded' => '', |
|
| 1442 | - 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1443 | - 'TKT_name' => $default ? '' : $ticket->get('TKT_name'), |
|
| 1444 | - 'TKT_start_date' => $default |
|
| 1445 | - ? '' |
|
| 1446 | - : $ticket->get_date('TKT_start_date', |
|
| 1447 | - $this->_date_time_format), |
|
| 1448 | - 'TKT_end_date' => $default |
|
| 1449 | - ? '' |
|
| 1450 | - : $ticket->get_date('TKT_end_date', |
|
| 1451 | - $this->_date_time_format), |
|
| 1452 | - 'TKT_status' => $TKT_status, |
|
| 1453 | - 'TKT_price' => $default |
|
| 1454 | - ? '' |
|
| 1455 | - : EEH_Template::format_currency( |
|
| 1456 | - $ticket->get_ticket_total_with_taxes(), |
|
| 1457 | - false, |
|
| 1458 | - false |
|
| 1459 | - ), |
|
| 1460 | - 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
| 1461 | - 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
| 1462 | - 'TKT_qty' => $default |
|
| 1463 | - ? '' |
|
| 1464 | - : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
| 1465 | - 'TKT_qty_for_input' => $default |
|
| 1466 | - ? '' |
|
| 1467 | - : $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1468 | - 'TKT_uses' => $default |
|
| 1469 | - ? '' |
|
| 1470 | - : $ticket->get_pretty('TKT_uses', 'input'), |
|
| 1471 | - 'TKT_min' => $TKT_min, |
|
| 1472 | - 'TKT_max' => $default |
|
| 1473 | - ? '' |
|
| 1474 | - : $ticket->get_pretty('TKT_max', 'input'), |
|
| 1475 | - 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
| 1476 | - 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
| 1477 | - 'TKT_registrations' => $default |
|
| 1478 | - ? 0 |
|
| 1479 | - : $ticket->count_registrations( |
|
| 1480 | - array( |
|
| 1481 | - array( |
|
| 1482 | - 'STS_ID' => array( |
|
| 1483 | - '!=', |
|
| 1484 | - EEM_Registration::status_id_incomplete, |
|
| 1485 | - ), |
|
| 1486 | - ), |
|
| 1487 | - ) |
|
| 1488 | - ), |
|
| 1489 | - 'TKT_ID' => $default ? 0 : $ticket->get('TKT_ID'), |
|
| 1490 | - 'TKT_description' => $default ? '' : $ticket->get('TKT_description'), |
|
| 1491 | - 'TKT_is_default' => $default ? 0 : $ticket->get('TKT_is_default'), |
|
| 1492 | - 'TKT_required' => $default ? 0 : $ticket->required(), |
|
| 1493 | - 'TKT_is_default_selector' => '', |
|
| 1494 | - 'ticket_price_rows' => '', |
|
| 1495 | - 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
| 1496 | - ? '' |
|
| 1497 | - : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
| 1498 | - 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
| 1499 | - 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
| 1500 | - ? '' |
|
| 1501 | - : ' style="display:none;"', |
|
| 1502 | - 'show_price_mod_button' => count($prices) > 1 |
|
| 1503 | - || ($default && $count_price_mods > 0) |
|
| 1504 | - || (! $default && $ticket->get('TKT_deleted')) |
|
| 1505 | - ? ' style="display:none;"' |
|
| 1506 | - : '', |
|
| 1507 | - 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
| 1508 | - 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1509 | - 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
| 1510 | - 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
| 1511 | - 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
| 1512 | - 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
| 1513 | - 'TKT_taxable' => $TKT_taxable, |
|
| 1514 | - 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') |
|
| 1515 | - ? '' |
|
| 1516 | - : ' style="display:none"', |
|
| 1517 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1518 | - 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
| 1519 | - $ticket_subtotal, |
|
| 1520 | - false, |
|
| 1521 | - false |
|
| 1522 | - ), |
|
| 1523 | - 'TKT_subtotal_amount' => $ticket_subtotal, |
|
| 1524 | - 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
| 1525 | - 'disabled' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted'), |
|
| 1526 | - 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
| 1527 | - ? ' ticket-archived' |
|
| 1528 | - : '', |
|
| 1529 | - 'trash_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
| 1530 | - ? 'ee-lock-icon ' |
|
| 1531 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1532 | - 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
| 1533 | - ? '' |
|
| 1534 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1535 | - ); |
|
| 1536 | - $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1537 | - ? ' style="display:none"' |
|
| 1538 | - : ''; |
|
| 1539 | - //handle rows that should NOT be empty |
|
| 1540 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1541 | - //if empty then the start date will be now. |
|
| 1542 | - $template_args['TKT_start_date'] = date($this->_date_time_format, |
|
| 1543 | - current_time('timestamp')); |
|
| 1544 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1545 | - } |
|
| 1546 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1547 | - //get the earliest datetime (if present); |
|
| 1548 | - $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
| 1549 | - ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
| 1550 | - 'Datetime', |
|
| 1551 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1552 | - ) |
|
| 1553 | - : null; |
|
| 1554 | - if (! empty($earliest_dtt)) { |
|
| 1555 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
| 1556 | - 'DTT_EVT_start', |
|
| 1557 | - $this->_date_time_format |
|
| 1558 | - ); |
|
| 1559 | - } else { |
|
| 1560 | - //default so let's just use what's been set for the default date-time which is 30 days from now. |
|
| 1561 | - $template_args['TKT_end_date'] = date( |
|
| 1562 | - $this->_date_time_format, |
|
| 1563 | - mktime(24, 0, 0, date('m'), date('d') + 29, date('Y') |
|
| 1564 | - ) |
|
| 1565 | - ); |
|
| 1566 | - } |
|
| 1567 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1568 | - } |
|
| 1569 | - //generate ticket_datetime items |
|
| 1570 | - if (! $default) { |
|
| 1571 | - $datetime_row = 1; |
|
| 1572 | - foreach ($all_datetimes as $datetime) { |
|
| 1573 | - $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 1574 | - $datetime_row, |
|
| 1575 | - $ticket_row, |
|
| 1576 | - $datetime, |
|
| 1577 | - $ticket, |
|
| 1578 | - $ticket_datetimes, |
|
| 1579 | - $default |
|
| 1580 | - ); |
|
| 1581 | - $datetime_row++; |
|
| 1582 | - } |
|
| 1583 | - } |
|
| 1584 | - $price_row = 1; |
|
| 1585 | - foreach ($prices as $price) { |
|
| 1586 | - if (! $price instanceof EE_Price) { |
|
| 1587 | - continue; |
|
| 1588 | - } |
|
| 1589 | - if ($price->is_base_price()) { |
|
| 1590 | - $price_row++; |
|
| 1591 | - continue; |
|
| 1592 | - } |
|
| 1593 | - $show_trash = !((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
| 1594 | - $show_create = !(count($prices) > 1 && count($prices) !== $price_row); |
|
| 1595 | - $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
| 1596 | - $ticket_row, |
|
| 1597 | - $price_row, |
|
| 1598 | - $price, |
|
| 1599 | - $default, |
|
| 1600 | - $ticket, |
|
| 1601 | - $show_trash, |
|
| 1602 | - $show_create |
|
| 1603 | - ); |
|
| 1604 | - $price_row++; |
|
| 1605 | - } |
|
| 1606 | - //filter $template_args |
|
| 1607 | - $template_args = apply_filters( |
|
| 1608 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
| 1609 | - $template_args, |
|
| 1610 | - $ticket_row, |
|
| 1611 | - $ticket, |
|
| 1612 | - $ticket_datetimes, |
|
| 1613 | - $all_datetimes, |
|
| 1614 | - $default, |
|
| 1615 | - $all_tickets, |
|
| 1616 | - $this->_is_creating_event |
|
| 1617 | - ); |
|
| 1618 | - return EEH_Template::display_template( |
|
| 1619 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
| 1620 | - $template_args, |
|
| 1621 | - true |
|
| 1622 | - ); |
|
| 1623 | - } |
|
| 1624 | - |
|
| 1625 | - |
|
| 1626 | - |
|
| 1627 | - /** |
|
| 1628 | - * @param int $ticket_row |
|
| 1629 | - * @param EE_Ticket|null $ticket |
|
| 1630 | - * @return string |
|
| 1631 | - * @throws DomainException |
|
| 1632 | - * @throws EE_Error |
|
| 1633 | - */ |
|
| 1634 | - protected function _get_tax_rows($ticket_row, $ticket) |
|
| 1635 | - { |
|
| 1636 | - $tax_rows = ''; |
|
| 1637 | - /** @var EE_Price[] $taxes */ |
|
| 1638 | - $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
| 1639 | - foreach ($taxes as $tax) { |
|
| 1640 | - $tax_added = $this->_get_tax_added($tax, $ticket); |
|
| 1641 | - $template_args = array( |
|
| 1642 | - 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
| 1643 | - ? '' |
|
| 1644 | - : ' style="display:none;"', |
|
| 1645 | - 'tax_id' => $tax->ID(), |
|
| 1646 | - 'tkt_row' => $ticket_row, |
|
| 1647 | - 'tax_label' => $tax->get('PRC_name'), |
|
| 1648 | - 'tax_added' => $tax_added, |
|
| 1649 | - 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
| 1650 | - 'tax_amount' => $tax->get('PRC_amount'), |
|
| 1651 | - ); |
|
| 1652 | - $template_args = apply_filters( |
|
| 1653 | - 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
| 1654 | - $template_args, |
|
| 1655 | - $ticket_row, |
|
| 1656 | - $ticket, |
|
| 1657 | - $this->_is_creating_event |
|
| 1658 | - ); |
|
| 1659 | - $tax_rows .= EEH_Template::display_template( |
|
| 1660 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1661 | - $template_args, |
|
| 1662 | - true |
|
| 1663 | - ); |
|
| 1664 | - } |
|
| 1665 | - return $tax_rows; |
|
| 1666 | - } |
|
| 1667 | - |
|
| 1668 | - |
|
| 1669 | - |
|
| 1670 | - /** |
|
| 1671 | - * @param EE_Price $tax |
|
| 1672 | - * @param EE_Ticket|null $ticket |
|
| 1673 | - * @return float|int |
|
| 1674 | - * @throws EE_Error |
|
| 1675 | - */ |
|
| 1676 | - protected function _get_tax_added(EE_Price $tax, $ticket) |
|
| 1677 | - { |
|
| 1678 | - $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1679 | - return $subtotal * $tax->get('PRC_amount') / 100; |
|
| 1680 | - } |
|
| 1681 | - |
|
| 1682 | - |
|
| 1683 | - |
|
| 1684 | - /** |
|
| 1685 | - * @param int $ticket_row |
|
| 1686 | - * @param int $price_row |
|
| 1687 | - * @param EE_Price|null $price |
|
| 1688 | - * @param bool $default |
|
| 1689 | - * @param EE_Ticket|null $ticket |
|
| 1690 | - * @param bool $show_trash |
|
| 1691 | - * @param bool $show_create |
|
| 1692 | - * @return mixed |
|
| 1693 | - * @throws DomainException |
|
| 1694 | - * @throws EE_Error |
|
| 1695 | - */ |
|
| 1696 | - protected function _get_ticket_price_row( |
|
| 1697 | - $ticket_row, |
|
| 1698 | - $price_row, |
|
| 1699 | - $price, |
|
| 1700 | - $default, |
|
| 1701 | - $ticket, |
|
| 1702 | - $show_trash = true, |
|
| 1703 | - $show_create = true |
|
| 1704 | - ) { |
|
| 1705 | - $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
| 1706 | - $template_args = array( |
|
| 1707 | - 'tkt_row' => $default && empty($ticket) |
|
| 1708 | - ? 'TICKETNUM' |
|
| 1709 | - : $ticket_row, |
|
| 1710 | - 'PRC_order' => $default && empty($price) |
|
| 1711 | - ? 'PRICENUM' |
|
| 1712 | - : $price_row, |
|
| 1713 | - 'edit_prices_name' => $default && empty($price) |
|
| 1714 | - ? 'PRICENAMEATTR' |
|
| 1715 | - : 'edit_prices', |
|
| 1716 | - 'price_type_selector' => $default && empty($price) |
|
| 1717 | - ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1718 | - : $this->_get_price_type_selector($ticket_row, $price_row, $price, $default, $send_disabled), |
|
| 1719 | - 'PRC_ID' => $default && empty($price) |
|
| 1720 | - ? 0 |
|
| 1721 | - : $price->ID(), |
|
| 1722 | - 'PRC_is_default' => $default && empty($price) |
|
| 1723 | - ? 0 |
|
| 1724 | - : $price->get('PRC_is_default'), |
|
| 1725 | - 'PRC_name' => $default && empty($price) |
|
| 1726 | - ? '' |
|
| 1727 | - : $price->get('PRC_name'), |
|
| 1728 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1729 | - 'show_plus_or_minus' => $default && empty($price) |
|
| 1730 | - ? '' |
|
| 1731 | - : ' style="display:none;"', |
|
| 1732 | - 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
| 1733 | - ? ' style="display:none;"' |
|
| 1734 | - : '', |
|
| 1735 | - 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
| 1736 | - ? ' style="display:none;"' |
|
| 1737 | - : '', |
|
| 1738 | - 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
| 1739 | - ? ' style="display:none"' |
|
| 1740 | - : '', |
|
| 1741 | - 'PRC_amount' => $default && empty($price) |
|
| 1742 | - ? 0 |
|
| 1743 | - : $price->get_pretty('PRC_amount', |
|
| 1744 | - 'localized_float'), |
|
| 1745 | - 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
| 1746 | - ? ' style="display:none;"' |
|
| 1747 | - : '', |
|
| 1748 | - 'show_trash_icon' => $show_trash |
|
| 1749 | - ? '' |
|
| 1750 | - : ' style="display:none;"', |
|
| 1751 | - 'show_create_button' => $show_create |
|
| 1752 | - ? '' |
|
| 1753 | - : ' style="display:none;"', |
|
| 1754 | - 'PRC_desc' => $default && empty($price) |
|
| 1755 | - ? '' |
|
| 1756 | - : $price->get('PRC_desc'), |
|
| 1757 | - 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
| 1758 | - ); |
|
| 1759 | - $template_args = apply_filters( |
|
| 1760 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
| 1761 | - $template_args, |
|
| 1762 | - $ticket_row, |
|
| 1763 | - $price_row, |
|
| 1764 | - $price, |
|
| 1765 | - $default, |
|
| 1766 | - $ticket, |
|
| 1767 | - $show_trash, |
|
| 1768 | - $show_create, |
|
| 1769 | - $this->_is_creating_event |
|
| 1770 | - ); |
|
| 1771 | - return EEH_Template::display_template( |
|
| 1772 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1773 | - $template_args, |
|
| 1774 | - true |
|
| 1775 | - ); |
|
| 1776 | - } |
|
| 1777 | - |
|
| 1778 | - |
|
| 1779 | - |
|
| 1780 | - /** |
|
| 1781 | - * @param int $ticket_row |
|
| 1782 | - * @param int $price_row |
|
| 1783 | - * @param EE_Price $price |
|
| 1784 | - * @param bool $default |
|
| 1785 | - * @param bool $disabled |
|
| 1786 | - * @return mixed |
|
| 1787 | - * @throws DomainException |
|
| 1788 | - * @throws EE_Error |
|
| 1789 | - */ |
|
| 1790 | - protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
| 1791 | - { |
|
| 1792 | - if ($price->is_base_price()) { |
|
| 1793 | - return $this->_get_base_price_template($ticket_row, $price_row, $price, $default); |
|
| 1794 | - } |
|
| 1795 | - return $this->_get_price_modifier_template($ticket_row, $price_row, $price, $default, $disabled); |
|
| 1796 | - } |
|
| 1797 | - |
|
| 1798 | - |
|
| 1799 | - |
|
| 1800 | - /** |
|
| 1801 | - * @param int $ticket_row |
|
| 1802 | - * @param int $price_row |
|
| 1803 | - * @param EE_Price $price |
|
| 1804 | - * @param bool $default |
|
| 1805 | - * @return mixed |
|
| 1806 | - * @throws DomainException |
|
| 1807 | - * @throws EE_Error |
|
| 1808 | - */ |
|
| 1809 | - protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1810 | - { |
|
| 1811 | - $template_args = array( |
|
| 1812 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1813 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
| 1814 | - 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
| 1815 | - 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
| 1816 | - 'price_selected_operator' => '+', |
|
| 1817 | - 'price_selected_is_percent' => 0, |
|
| 1818 | - ); |
|
| 1819 | - $template_args = apply_filters( |
|
| 1820 | - 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
| 1821 | - $template_args, |
|
| 1822 | - $ticket_row, |
|
| 1823 | - $price_row, |
|
| 1824 | - $price, |
|
| 1825 | - $default, |
|
| 1826 | - $this->_is_creating_event |
|
| 1827 | - ); |
|
| 1828 | - return EEH_Template::display_template( |
|
| 1829 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
| 1830 | - $template_args, |
|
| 1831 | - true |
|
| 1832 | - ); |
|
| 1833 | - } |
|
| 1834 | - |
|
| 1835 | - |
|
| 1836 | - |
|
| 1837 | - /** |
|
| 1838 | - * @param int $ticket_row |
|
| 1839 | - * @param int $price_row |
|
| 1840 | - * @param EE_Price $price |
|
| 1841 | - * @param bool $default |
|
| 1842 | - * @param bool $disabled |
|
| 1843 | - * @return mixed |
|
| 1844 | - * @throws DomainException |
|
| 1845 | - * @throws EE_Error |
|
| 1846 | - */ |
|
| 1847 | - protected function _get_price_modifier_template( |
|
| 1848 | - $ticket_row, |
|
| 1849 | - $price_row, |
|
| 1850 | - $price, |
|
| 1851 | - $default, |
|
| 1852 | - $disabled = false |
|
| 1853 | - ) { |
|
| 1854 | - $select_name = $default && ! $price instanceof EE_Price |
|
| 1855 | - ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
| 1856 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
| 1857 | - /** @var EEM_Price_Type $price_type_model */ |
|
| 1858 | - $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
| 1859 | - $price_types = $price_type_model->get_all(array( |
|
| 1860 | - array( |
|
| 1861 | - 'OR' => array( |
|
| 1862 | - 'PBT_ID' => '2', |
|
| 1863 | - 'PBT_ID*' => '3', |
|
| 1864 | - ), |
|
| 1865 | - ), |
|
| 1866 | - )); |
|
| 1867 | - $all_price_types = $default && ! $price instanceof EE_Price |
|
| 1868 | - ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
| 1869 | - : array(); |
|
| 1870 | - $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
| 1871 | - $price_option_spans = ''; |
|
| 1872 | - //setup price types for selector |
|
| 1873 | - foreach ($price_types as $price_type) { |
|
| 1874 | - if (! $price_type instanceof EE_Price_Type) { |
|
| 1875 | - continue; |
|
| 1876 | - } |
|
| 1877 | - $all_price_types[$price_type->ID()] = $price_type->get('PRT_name'); |
|
| 1878 | - //while we're in the loop let's setup the option spans used by js |
|
| 1879 | - $span_args = array( |
|
| 1880 | - 'PRT_ID' => $price_type->ID(), |
|
| 1881 | - 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
| 1882 | - 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
| 1883 | - ); |
|
| 1884 | - $price_option_spans .= EEH_Template::display_template( |
|
| 1885 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
| 1886 | - $span_args, |
|
| 1887 | - true |
|
| 1888 | - ); |
|
| 1889 | - } |
|
| 1890 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' : $select_name; |
|
| 1891 | - $select_input = new EE_Select_Input( |
|
| 1892 | - $all_price_types, |
|
| 1893 | - array( |
|
| 1894 | - 'default' => $selected_price_type_id, |
|
| 1895 | - 'html_name' => $select_name, |
|
| 1896 | - 'html_class' => 'edit-price-PRT_ID', |
|
| 1897 | - 'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
| 1898 | - ) |
|
| 1899 | - ); |
|
| 1900 | - $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
| 1901 | - $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
| 1902 | - $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
| 1903 | - $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
| 1904 | - $template_args = array( |
|
| 1905 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1906 | - 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
| 1907 | - 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
| 1908 | - 'main_name' => $select_name, |
|
| 1909 | - 'selected_price_type_id' => $selected_price_type_id, |
|
| 1910 | - 'price_option_spans' => $price_option_spans, |
|
| 1911 | - 'price_selected_operator' => $price_selected_operator, |
|
| 1912 | - 'price_selected_is_percent' => $price_selected_is_percent, |
|
| 1913 | - 'disabled' => $disabled, |
|
| 1914 | - ); |
|
| 1915 | - $template_args = apply_filters( |
|
| 1916 | - 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
| 1917 | - $template_args, |
|
| 1918 | - $ticket_row, |
|
| 1919 | - $price_row, |
|
| 1920 | - $price, |
|
| 1921 | - $default, |
|
| 1922 | - $disabled, |
|
| 1923 | - $this->_is_creating_event |
|
| 1924 | - ); |
|
| 1925 | - return EEH_Template::display_template( |
|
| 1926 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 1927 | - $template_args, |
|
| 1928 | - true |
|
| 1929 | - ); |
|
| 1930 | - } |
|
| 1931 | - |
|
| 1932 | - |
|
| 1933 | - |
|
| 1934 | - /** |
|
| 1935 | - * @param int $datetime_row |
|
| 1936 | - * @param int $ticket_row |
|
| 1937 | - * @param EE_Datetime|null $datetime |
|
| 1938 | - * @param EE_Ticket|null $ticket |
|
| 1939 | - * @param array $ticket_datetimes |
|
| 1940 | - * @param bool $default |
|
| 1941 | - * @return mixed |
|
| 1942 | - * @throws DomainException |
|
| 1943 | - * @throws EE_Error |
|
| 1944 | - */ |
|
| 1945 | - protected function _get_ticket_datetime_list_item( |
|
| 1946 | - $datetime_row, |
|
| 1947 | - $ticket_row, |
|
| 1948 | - $datetime, |
|
| 1949 | - $ticket, |
|
| 1950 | - $ticket_datetimes = array(), |
|
| 1951 | - $default |
|
| 1952 | - ) { |
|
| 1953 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
| 1954 | - ? $ticket_datetimes[$ticket->ID()] |
|
| 1955 | - : array(); |
|
| 1956 | - $template_args = array( |
|
| 1957 | - 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
| 1958 | - ? 'DTTNUM' |
|
| 1959 | - : $datetime_row, |
|
| 1960 | - 'tkt_row' => $default |
|
| 1961 | - ? 'TICKETNUM' |
|
| 1962 | - : $ticket_row, |
|
| 1963 | - 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 1964 | - ? ' ticket-selected' |
|
| 1965 | - : '', |
|
| 1966 | - 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 1967 | - ? ' checked="checked"' |
|
| 1968 | - : '', |
|
| 1969 | - 'DTT_name' => $default && empty($datetime) |
|
| 1970 | - ? 'DTTNAME' |
|
| 1971 | - : $datetime->get_dtt_display_name(true), |
|
| 1972 | - 'tkt_status_class' => '', |
|
| 1973 | - ); |
|
| 1974 | - $template_args = apply_filters( |
|
| 1975 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
| 1976 | - $template_args, |
|
| 1977 | - $datetime_row, |
|
| 1978 | - $ticket_row, |
|
| 1979 | - $datetime, |
|
| 1980 | - $ticket, |
|
| 1981 | - $ticket_datetimes, |
|
| 1982 | - $default, |
|
| 1983 | - $this->_is_creating_event |
|
| 1984 | - ); |
|
| 1985 | - return EEH_Template::display_template( |
|
| 1986 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 1987 | - $template_args, |
|
| 1988 | - true |
|
| 1989 | - ); |
|
| 1990 | - } |
|
| 1991 | - |
|
| 1992 | - |
|
| 1993 | - |
|
| 1994 | - /** |
|
| 1995 | - * @param array $all_datetimes |
|
| 1996 | - * @param array $all_tickets |
|
| 1997 | - * @return mixed |
|
| 1998 | - * @throws DomainException |
|
| 1999 | - * @throws EE_Error |
|
| 2000 | - */ |
|
| 2001 | - protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
| 2002 | - { |
|
| 2003 | - $template_args = array( |
|
| 2004 | - 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
| 2005 | - 'DTTNUM', |
|
| 2006 | - null, |
|
| 2007 | - true, |
|
| 2008 | - $all_datetimes |
|
| 2009 | - ), |
|
| 2010 | - 'default_ticket_row' => $this->_get_ticket_row( |
|
| 2011 | - 'TICKETNUM', |
|
| 2012 | - null, |
|
| 2013 | - array(), |
|
| 2014 | - array(), |
|
| 2015 | - true |
|
| 2016 | - ), |
|
| 2017 | - 'default_price_row' => $this->_get_ticket_price_row( |
|
| 2018 | - 'TICKETNUM', |
|
| 2019 | - 'PRICENUM', |
|
| 2020 | - null, |
|
| 2021 | - true, |
|
| 2022 | - null |
|
| 2023 | - ), |
|
| 2024 | - 'default_price_rows' => '', |
|
| 2025 | - 'default_base_price_amount' => 0, |
|
| 2026 | - 'default_base_price_name' => '', |
|
| 2027 | - 'default_base_price_description' => '', |
|
| 2028 | - 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
| 2029 | - 'TICKETNUM', |
|
| 2030 | - 'PRICENUM', |
|
| 2031 | - null, |
|
| 2032 | - true |
|
| 2033 | - ), |
|
| 2034 | - 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
| 2035 | - 'DTTNUM', |
|
| 2036 | - null, |
|
| 2037 | - array(), |
|
| 2038 | - array(), |
|
| 2039 | - true |
|
| 2040 | - ), |
|
| 2041 | - 'existing_available_datetime_tickets_list' => '', |
|
| 2042 | - 'existing_available_ticket_datetimes_list' => '', |
|
| 2043 | - 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
| 2044 | - 'DTTNUM', |
|
| 2045 | - 'TICKETNUM', |
|
| 2046 | - null, |
|
| 2047 | - null, |
|
| 2048 | - array(), |
|
| 2049 | - true |
|
| 2050 | - ), |
|
| 2051 | - 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
| 2052 | - 'DTTNUM', |
|
| 2053 | - 'TICKETNUM', |
|
| 2054 | - null, |
|
| 2055 | - null, |
|
| 2056 | - array(), |
|
| 2057 | - true |
|
| 2058 | - ), |
|
| 2059 | - ); |
|
| 2060 | - $ticket_row = 1; |
|
| 2061 | - foreach ($all_tickets as $ticket) { |
|
| 2062 | - $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 2063 | - 'DTTNUM', |
|
| 2064 | - $ticket_row, |
|
| 2065 | - null, |
|
| 2066 | - $ticket, |
|
| 2067 | - array(), |
|
| 2068 | - true |
|
| 2069 | - ); |
|
| 2070 | - $ticket_row++; |
|
| 2071 | - } |
|
| 2072 | - $datetime_row = 1; |
|
| 2073 | - foreach ($all_datetimes as $datetime) { |
|
| 2074 | - $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 2075 | - $datetime_row, |
|
| 2076 | - 'TICKETNUM', |
|
| 2077 | - $datetime, |
|
| 2078 | - null, |
|
| 2079 | - array(), |
|
| 2080 | - true |
|
| 2081 | - ); |
|
| 2082 | - $datetime_row++; |
|
| 2083 | - } |
|
| 2084 | - /** @var EEM_Price $price_model */ |
|
| 2085 | - $price_model = EE_Registry::instance()->load_model('Price'); |
|
| 2086 | - $default_prices = $price_model->get_all_default_prices(); |
|
| 2087 | - $price_row = 1; |
|
| 2088 | - foreach ($default_prices as $price) { |
|
| 2089 | - if (! $price instanceof EE_Price) { |
|
| 2090 | - continue; |
|
| 2091 | - } |
|
| 2092 | - if ($price->is_base_price()) { |
|
| 2093 | - $template_args['default_base_price_amount'] = $price->get_pretty( |
|
| 2094 | - 'PRC_amount', |
|
| 2095 | - 'localized_float' |
|
| 2096 | - ); |
|
| 2097 | - $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
| 2098 | - $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
| 2099 | - $price_row++; |
|
| 2100 | - continue; |
|
| 2101 | - } |
|
| 2102 | - $show_trash = !((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1); |
|
| 2103 | - $show_create = !(count($default_prices) > 1 && count($default_prices) !== $price_row); |
|
| 2104 | - $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
| 2105 | - 'TICKETNUM', |
|
| 2106 | - $price_row, |
|
| 2107 | - $price, |
|
| 2108 | - true, |
|
| 2109 | - null, |
|
| 2110 | - $show_trash, |
|
| 2111 | - $show_create |
|
| 2112 | - ); |
|
| 2113 | - $price_row++; |
|
| 2114 | - } |
|
| 2115 | - $template_args = apply_filters( |
|
| 2116 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
| 2117 | - $template_args, |
|
| 2118 | - $all_datetimes, |
|
| 2119 | - $all_tickets, |
|
| 2120 | - $this->_is_creating_event |
|
| 2121 | - ); |
|
| 2122 | - return EEH_Template::display_template( |
|
| 2123 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2124 | - $template_args, |
|
| 2125 | - true |
|
| 2126 | - ); |
|
| 2127 | - } |
|
| 18 | + /** |
|
| 19 | + * This property is just used to hold the status of whether an event is currently being |
|
| 20 | + * created (true) or edited (false) |
|
| 21 | + * |
|
| 22 | + * @access protected |
|
| 23 | + * @var bool |
|
| 24 | + */ |
|
| 25 | + protected $_is_creating_event; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Used to contain the format strings for date and time that will be used for php date and |
|
| 30 | + * time. |
|
| 31 | + * Is set in the _set_hooks_properties() method. |
|
| 32 | + * |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | + protected $_date_format_strings; |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var string $_date_time_format |
|
| 40 | + */ |
|
| 41 | + protected $_date_time_format; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * |
|
| 47 | + */ |
|
| 48 | + protected function _set_hooks_properties() |
|
| 49 | + { |
|
| 50 | + $this->_name = 'pricing'; |
|
| 51 | + //capability check |
|
| 52 | + if ( |
|
| 53 | + ! EE_Registry::instance()->CAP->current_user_can( |
|
| 54 | + 'ee_read_default_prices', |
|
| 55 | + 'advanced_ticket_datetime_metabox' |
|
| 56 | + ) |
|
| 57 | + ) { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | + $this->_setup_metaboxes(); |
|
| 61 | + $this->_set_date_time_formats(); |
|
| 62 | + $this->_validate_format_strings(); |
|
| 63 | + $this->_set_scripts_styles(); |
|
| 64 | + // commented out temporarily until logic is implemented in callback |
|
| 65 | + // add_action( |
|
| 66 | + // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
| 67 | + // array($this, 'autosave_handling') |
|
| 68 | + // ); |
|
| 69 | + add_filter( |
|
| 70 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 71 | + array($this, 'caf_updates') |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @return void |
|
| 79 | + */ |
|
| 80 | + protected function _setup_metaboxes() |
|
| 81 | + { |
|
| 82 | + //if we were going to add our own metaboxes we'd use the below. |
|
| 83 | + $this->_metaboxes = array( |
|
| 84 | + 0 => array( |
|
| 85 | + 'page_route' => array('edit', 'create_new'), |
|
| 86 | + 'func' => 'pricing_metabox', |
|
| 87 | + 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
| 88 | + 'priority' => 'high', |
|
| 89 | + 'context' => 'normal', |
|
| 90 | + ), |
|
| 91 | + ); |
|
| 92 | + $this->_remove_metaboxes = array( |
|
| 93 | + 0 => array( |
|
| 94 | + 'page_route' => array('edit', 'create_new'), |
|
| 95 | + 'id' => 'espresso_event_editor_tickets', |
|
| 96 | + 'context' => 'normal', |
|
| 97 | + ), |
|
| 98 | + ); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @return void |
|
| 105 | + */ |
|
| 106 | + protected function _set_date_time_formats() |
|
| 107 | + { |
|
| 108 | + /** |
|
| 109 | + * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
| 110 | + * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
| 111 | + * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
| 112 | + * |
|
| 113 | + * @since 4.6.7 |
|
| 114 | + * @var array Expected an array returned with 'date' and 'time' keys. |
|
| 115 | + */ |
|
| 116 | + $this->_date_format_strings = apply_filters( |
|
| 117 | + 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
| 118 | + array( |
|
| 119 | + 'date' => 'Y-m-d', |
|
| 120 | + 'time' => 'h:i a', |
|
| 121 | + ) |
|
| 122 | + ); |
|
| 123 | + //validate |
|
| 124 | + $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
| 125 | + ? $this->_date_format_strings['date'] |
|
| 126 | + : null; |
|
| 127 | + $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
| 128 | + ? $this->_date_format_strings['time'] |
|
| 129 | + : null; |
|
| 130 | + $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @return void |
|
| 137 | + */ |
|
| 138 | + protected function _validate_format_strings() |
|
| 139 | + { |
|
| 140 | + //validate format strings |
|
| 141 | + $format_validation = EEH_DTT_Helper::validate_format_string( |
|
| 142 | + $this->_date_time_format |
|
| 143 | + ); |
|
| 144 | + if (is_array($format_validation)) { |
|
| 145 | + $msg = '<p>'; |
|
| 146 | + $msg .= sprintf( |
|
| 147 | + esc_html__( |
|
| 148 | + 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
| 149 | + 'event_espresso' |
|
| 150 | + ), |
|
| 151 | + $this->_date_time_format |
|
| 152 | + ); |
|
| 153 | + $msg .= '</p><ul>'; |
|
| 154 | + foreach ($format_validation as $error) { |
|
| 155 | + $msg .= '<li>' . $error . '</li>'; |
|
| 156 | + } |
|
| 157 | + $msg .= '</ul><p>'; |
|
| 158 | + $msg .= sprintf( |
|
| 159 | + esc_html__( |
|
| 160 | + '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
| 161 | + 'event_espresso' |
|
| 162 | + ), |
|
| 163 | + '<span style="color:#D54E21;">', |
|
| 164 | + '</span>' |
|
| 165 | + ); |
|
| 166 | + $msg .= '</p>'; |
|
| 167 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 168 | + $this->_date_format_strings = array( |
|
| 169 | + 'date' => 'Y-m-d', |
|
| 170 | + 'time' => 'h:i a', |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @return void |
|
| 179 | + */ |
|
| 180 | + protected function _set_scripts_styles() |
|
| 181 | + { |
|
| 182 | + $this->_scripts_styles = array( |
|
| 183 | + 'registers' => array( |
|
| 184 | + 'ee-tickets-datetimes-css' => array( |
|
| 185 | + 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 186 | + 'type' => 'css', |
|
| 187 | + ), |
|
| 188 | + 'ee-dtt-ticket-metabox' => array( |
|
| 189 | + 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 190 | + 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
| 191 | + ), |
|
| 192 | + ), |
|
| 193 | + 'deregisters' => array( |
|
| 194 | + 'event-editor-css' => array('type' => 'css'), |
|
| 195 | + 'event-datetime-metabox' => array('type' => 'js'), |
|
| 196 | + ), |
|
| 197 | + 'enqueues' => array( |
|
| 198 | + 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
| 199 | + 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
| 200 | + ), |
|
| 201 | + 'localize' => array( |
|
| 202 | + 'ee-dtt-ticket-metabox' => array( |
|
| 203 | + 'DTT_TRASH_BLOCK' => array( |
|
| 204 | + 'main_warning' => esc_html__( |
|
| 205 | + 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
| 206 | + 'event_espresso' |
|
| 207 | + ), |
|
| 208 | + 'after_warning' => esc_html__( |
|
| 209 | + 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
| 210 | + 'event_espresso' |
|
| 211 | + ), |
|
| 212 | + 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 213 | + . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
| 214 | + 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 215 | + . esc_html__('Close', 'event_espresso') . '</button>', |
|
| 216 | + 'single_warning_from_tkt' => esc_html__( |
|
| 217 | + 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 218 | + 'event_espresso' |
|
| 219 | + ), |
|
| 220 | + 'single_warning_from_dtt' => esc_html__( |
|
| 221 | + 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
| 222 | + 'event_espresso' |
|
| 223 | + ), |
|
| 224 | + 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 225 | + . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
| 226 | + ), |
|
| 227 | + 'DTT_ERROR_MSG' => array( |
|
| 228 | + 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
| 229 | + 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' |
|
| 230 | + . esc_html__('Dismiss', 'event_espresso') . '</button></div>', |
|
| 231 | + ), |
|
| 232 | + 'DTT_OVERSELL_WARNING' => array( |
|
| 233 | + 'datetime_ticket' => esc_html__( |
|
| 234 | + 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
| 235 | + 'event_espresso' |
|
| 236 | + ), |
|
| 237 | + 'ticket_datetime' => esc_html__( |
|
| 238 | + 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
| 239 | + 'event_espresso' |
|
| 240 | + ), |
|
| 241 | + ), |
|
| 242 | + 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
| 243 | + $this->_date_format_strings['date'], |
|
| 244 | + $this->_date_format_strings['time'] |
|
| 245 | + ), |
|
| 246 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')), |
|
| 247 | + ), |
|
| 248 | + ), |
|
| 249 | + ); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @param array $update_callbacks |
|
| 256 | + * @return array |
|
| 257 | + */ |
|
| 258 | + public function caf_updates(array $update_callbacks) |
|
| 259 | + { |
|
| 260 | + foreach ($update_callbacks as $key => $callback) { |
|
| 261 | + if ($callback[1] === '_default_tickets_update') { |
|
| 262 | + unset($update_callbacks[$key]); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
| 266 | + return $update_callbacks; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 272 | + * |
|
| 273 | + * @param EE_Event $event The Event object we're attaching data to |
|
| 274 | + * @param array $data The request data from the form |
|
| 275 | + * @throws EE_Error |
|
| 276 | + * @throws InvalidArgumentException |
|
| 277 | + */ |
|
| 278 | + public function datetime_and_tickets_caf_update($event, $data) |
|
| 279 | + { |
|
| 280 | + //first we need to start with datetimes cause they are the "root" items attached to events. |
|
| 281 | + $saved_datetimes = $this->_update_datetimes($event, $data); |
|
| 282 | + //next tackle the tickets (and prices?) |
|
| 283 | + $this->_update_tickets($event, $saved_datetimes, $data); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * update event_datetimes |
|
| 289 | + * |
|
| 290 | + * @param EE_Event $event Event being updated |
|
| 291 | + * @param array $data the request data from the form |
|
| 292 | + * @return EE_Datetime[] |
|
| 293 | + * @throws InvalidArgumentException |
|
| 294 | + * @throws EE_Error |
|
| 295 | + */ |
|
| 296 | + protected function _update_datetimes($event, $data) |
|
| 297 | + { |
|
| 298 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 299 | + $saved_dtt_ids = array(); |
|
| 300 | + $saved_dtt_objs = array(); |
|
| 301 | + if (empty($data['edit_event_datetimes']) || !is_array($data['edit_event_datetimes'])) { |
|
| 302 | + throw new InvalidArgumentException( |
|
| 303 | + esc_html__( |
|
| 304 | + 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
| 305 | + 'event_espresso' |
|
| 306 | + ) |
|
| 307 | + ); |
|
| 308 | + } |
|
| 309 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
| 310 | + //trim all values to ensure any excess whitespace is removed. |
|
| 311 | + $datetime_data = array_map( |
|
| 312 | + function ($datetime_data) { |
|
| 313 | + return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
| 314 | + }, |
|
| 315 | + $datetime_data |
|
| 316 | + ); |
|
| 317 | + $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
| 318 | + && ! empty($datetime_data['DTT_EVT_end']) |
|
| 319 | + ? $datetime_data['DTT_EVT_end'] |
|
| 320 | + : $datetime_data['DTT_EVT_start']; |
|
| 321 | + $datetime_values = array( |
|
| 322 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
| 323 | + ? $datetime_data['DTT_ID'] |
|
| 324 | + : null, |
|
| 325 | + 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
| 326 | + ? $datetime_data['DTT_name'] |
|
| 327 | + : '', |
|
| 328 | + 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
| 329 | + ? $datetime_data['DTT_description'] |
|
| 330 | + : '', |
|
| 331 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
| 332 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
| 333 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
| 334 | + ? EE_INF |
|
| 335 | + : $datetime_data['DTT_reg_limit'], |
|
| 336 | + 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
| 337 | + ? $row |
|
| 338 | + : $datetime_data['DTT_order'], |
|
| 339 | + ); |
|
| 340 | + // if we have an id then let's get existing object first and then set the new values. |
|
| 341 | + // Otherwise we instantiate a new object for save. |
|
| 342 | + if (! empty($datetime_data['DTT_ID'])) { |
|
| 343 | + $datetime = EE_Registry::instance() |
|
| 344 | + ->load_model('Datetime', array($timezone)) |
|
| 345 | + ->get_one_by_ID($datetime_data['DTT_ID']); |
|
| 346 | + //set date and time format according to what is set in this class. |
|
| 347 | + $datetime->set_date_format($this->_date_format_strings['date']); |
|
| 348 | + $datetime->set_time_format($this->_date_format_strings['time']); |
|
| 349 | + foreach ($datetime_values as $field => $value) { |
|
| 350 | + $datetime->set($field, $value); |
|
| 351 | + } |
|
| 352 | + // make sure the $dtt_id here is saved just in case |
|
| 353 | + // after the add_relation_to() the autosave replaces it. |
|
| 354 | + // We need to do this so we dont' TRASH the parent DTT. |
|
| 355 | + // (save the ID for both key and value to avoid duplications) |
|
| 356 | + $saved_dtt_ids[$datetime->ID()] = $datetime->ID(); |
|
| 357 | + } else { |
|
| 358 | + $datetime = EE_Registry::instance()->load_class( |
|
| 359 | + 'Datetime', |
|
| 360 | + array( |
|
| 361 | + $datetime_values, |
|
| 362 | + $timezone, |
|
| 363 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
| 364 | + ), |
|
| 365 | + false, |
|
| 366 | + false |
|
| 367 | + ); |
|
| 368 | + foreach ($datetime_values as $field => $value) { |
|
| 369 | + $datetime->set($field, $value); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + $datetime->save(); |
|
| 373 | + $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
| 374 | + // before going any further make sure our dates are setup correctly |
|
| 375 | + // so that the end date is always equal or greater than the start date. |
|
| 376 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
| 377 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
| 378 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
| 379 | + $datetime->save(); |
|
| 380 | + } |
|
| 381 | + // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
| 382 | + // because it is possible there was a new one created for the autosave. |
|
| 383 | + // (save the ID for both key and value to avoid duplications) |
|
| 384 | + $DTT_ID = $datetime->ID(); |
|
| 385 | + $saved_dtt_ids[$DTT_ID] = $DTT_ID; |
|
| 386 | + $saved_dtt_objs[$row] = $datetime; |
|
| 387 | + //todo if ANY of these updates fail then we want the appropriate global error message. |
|
| 388 | + } |
|
| 389 | + $event->save(); |
|
| 390 | + // now we need to REMOVE any datetimes that got deleted. |
|
| 391 | + // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
| 392 | + // So its safe to permanently delete at this point. |
|
| 393 | + $old_datetimes = explode(',', $data['datetime_IDs']); |
|
| 394 | + $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
| 395 | + if (is_array($old_datetimes)) { |
|
| 396 | + $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
| 397 | + foreach ($datetimes_to_delete as $id) { |
|
| 398 | + $id = absint($id); |
|
| 399 | + if (empty($id)) { |
|
| 400 | + continue; |
|
| 401 | + } |
|
| 402 | + $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
| 403 | + //remove tkt relationships. |
|
| 404 | + $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
| 405 | + foreach ($related_tickets as $tkt) { |
|
| 406 | + $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
| 407 | + } |
|
| 408 | + $event->_remove_relation_to($id, 'Datetime'); |
|
| 409 | + $dtt_to_remove->refresh_cache_of_related_objects(); |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + return $saved_dtt_objs; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * update tickets |
|
| 418 | + * |
|
| 419 | + * @param EE_Event $event Event object being updated |
|
| 420 | + * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
| 421 | + * @param array $data incoming request data |
|
| 422 | + * @return EE_Ticket[] |
|
| 423 | + * @throws InvalidArgumentException |
|
| 424 | + * @throws EE_Error |
|
| 425 | + */ |
|
| 426 | + protected function _update_tickets($event, $saved_datetimes, $data) |
|
| 427 | + { |
|
| 428 | + $new_tkt = null; |
|
| 429 | + $new_default = null; |
|
| 430 | + //stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
| 431 | + $data = stripslashes_deep($data); |
|
| 432 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 433 | + $saved_tickets = $datetimes_on_existing = array(); |
|
| 434 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 435 | + if(empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])){ |
|
| 436 | + throw new InvalidArgumentException( |
|
| 437 | + esc_html__( |
|
| 438 | + 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
| 439 | + 'event_espresso' |
|
| 440 | + ) |
|
| 441 | + ); |
|
| 442 | + } |
|
| 443 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 444 | + $update_prices = $create_new_TKT = false; |
|
| 445 | + // figure out what datetimes were added to the ticket |
|
| 446 | + // and what datetimes were removed from the ticket in the session. |
|
| 447 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
| 448 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
| 449 | + $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
| 450 | + $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
| 451 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 452 | + $tkt = array_map( |
|
| 453 | + function ($ticket_data) { |
|
| 454 | + return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
| 455 | + }, |
|
| 456 | + $tkt |
|
| 457 | + ); |
|
| 458 | + // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
| 459 | + // because we're doing calculations prior to using the models. |
|
| 460 | + // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
| 461 | + $ticket_price = isset($tkt['TKT_price']) |
|
| 462 | + ? round((float)$tkt['TKT_price'], 3) |
|
| 463 | + : 0; |
|
| 464 | + //note incoming base price needs converted from localized value. |
|
| 465 | + $base_price = isset($tkt['TKT_base_price']) |
|
| 466 | + ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
| 467 | + : 0; |
|
| 468 | + //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
| 469 | + $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
| 470 | + ? $base_price |
|
| 471 | + : $ticket_price; |
|
| 472 | + $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
| 473 | + ? $tkt['TKT_base_price_ID'] |
|
| 474 | + : 0; |
|
| 475 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) |
|
| 476 | + ? $data['edit_prices'][$row] |
|
| 477 | + : array(); |
|
| 478 | + $now = null; |
|
| 479 | + if (empty($tkt['TKT_start_date'])) { |
|
| 480 | + //lets' use now in the set timezone. |
|
| 481 | + $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
| 482 | + $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
| 483 | + } |
|
| 484 | + if (empty($tkt['TKT_end_date'])) { |
|
| 485 | + /** |
|
| 486 | + * set the TKT_end_date to the first datetime attached to the ticket. |
|
| 487 | + */ |
|
| 488 | + $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)]; |
|
| 489 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
| 490 | + } |
|
| 491 | + $TKT_values = array( |
|
| 492 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 493 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 494 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 495 | + 'TKT_description' => ! empty($tkt['TKT_description']) |
|
| 496 | + && $tkt['TKT_description'] !== esc_html__( |
|
| 497 | + 'You can modify this description', |
|
| 498 | + 'event_espresso' |
|
| 499 | + ) |
|
| 500 | + ? $tkt['TKT_description'] |
|
| 501 | + : '', |
|
| 502 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 503 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 504 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
| 505 | + ? EE_INF |
|
| 506 | + : $tkt['TKT_qty'], |
|
| 507 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
| 508 | + ? EE_INF |
|
| 509 | + : $tkt['TKT_uses'], |
|
| 510 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 511 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 512 | + 'TKT_row' => $row, |
|
| 513 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
| 514 | + 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
| 515 | + 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
| 516 | + 'TKT_price' => $ticket_price, |
|
| 517 | + ); |
|
| 518 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 519 | + // which means in turn that the prices will become new prices as well. |
|
| 520 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 521 | + $TKT_values['TKT_ID'] = 0; |
|
| 522 | + $TKT_values['TKT_is_default'] = 0; |
|
| 523 | + $update_prices = true; |
|
| 524 | + } |
|
| 525 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 526 | + // we actually do our saves ahead of doing any add_relations to |
|
| 527 | + // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
| 528 | + // but DID have it's items modified. |
|
| 529 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
| 530 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 531 | + if (absint($TKT_values['TKT_ID'])) { |
|
| 532 | + $ticket = EE_Registry::instance() |
|
| 533 | + ->load_model('Ticket', array($timezone)) |
|
| 534 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
| 535 | + if ($ticket instanceof EE_Ticket) { |
|
| 536 | + $ticket = $this->_update_ticket_datetimes( |
|
| 537 | + $ticket, |
|
| 538 | + $saved_datetimes, |
|
| 539 | + $datetimes_added, |
|
| 540 | + $datetimes_removed |
|
| 541 | + ); |
|
| 542 | + // are there any registrations using this ticket ? |
|
| 543 | + $tickets_sold = $ticket->count_related( |
|
| 544 | + 'Registration', |
|
| 545 | + array( |
|
| 546 | + array( |
|
| 547 | + 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
| 548 | + ), |
|
| 549 | + ) |
|
| 550 | + ); |
|
| 551 | + //set ticket formats |
|
| 552 | + $ticket->set_date_format($this->_date_format_strings['date']); |
|
| 553 | + $ticket->set_time_format($this->_date_format_strings['time']); |
|
| 554 | + // let's just check the total price for the existing ticket |
|
| 555 | + // and determine if it matches the new total price. |
|
| 556 | + // if they are different then we create a new ticket (if tickets sold) |
|
| 557 | + // if they aren't different then we go ahead and modify existing ticket. |
|
| 558 | + $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
| 559 | + //set new values |
|
| 560 | + foreach ($TKT_values as $field => $value) { |
|
| 561 | + if ($field === 'TKT_qty') { |
|
| 562 | + $ticket->set_qty($value); |
|
| 563 | + } else { |
|
| 564 | + $ticket->set($field, $value); |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + // if $create_new_TKT is false then we can safely update the existing ticket. |
|
| 568 | + // Otherwise we have to create a new ticket. |
|
| 569 | + if ($create_new_TKT) { |
|
| 570 | + $new_tkt = $this->_duplicate_ticket($ticket, $price_rows, $ticket_price, $base_price, |
|
| 571 | + $base_price_id); |
|
| 572 | + } |
|
| 573 | + } |
|
| 574 | + } else { |
|
| 575 | + // no TKT_id so a new TKT |
|
| 576 | + $ticket = EE_Ticket::new_instance( |
|
| 577 | + $TKT_values, |
|
| 578 | + $timezone, |
|
| 579 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 580 | + ); |
|
| 581 | + if ($ticket instanceof EE_Ticket) { |
|
| 582 | + // make sure ticket has an ID of setting relations won't work |
|
| 583 | + $ticket->save(); |
|
| 584 | + $ticket = $this->_update_ticket_datetimes( |
|
| 585 | + $ticket, |
|
| 586 | + $saved_datetimes, |
|
| 587 | + $datetimes_added, |
|
| 588 | + $datetimes_removed |
|
| 589 | + ); |
|
| 590 | + $update_prices = true; |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + //make sure any current values have been saved. |
|
| 594 | + //$ticket->save(); |
|
| 595 | + // before going any further make sure our dates are setup correctly |
|
| 596 | + // so that the end date is always equal or greater than the start date. |
|
| 597 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
| 598 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
| 599 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
| 600 | + } |
|
| 601 | + //let's make sure the base price is handled |
|
| 602 | + $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $ticket, $update_prices, $base_price, |
|
| 603 | + $base_price_id) : $ticket; |
|
| 604 | + //add/update price_modifiers |
|
| 605 | + $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) : $ticket; |
|
| 606 | + //need to make sue that the TKT_price is accurate after saving the prices. |
|
| 607 | + $ticket->ensure_TKT_Price_correct(); |
|
| 608 | + //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
| 609 | + if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 610 | + $update_prices = true; |
|
| 611 | + $new_default = clone $ticket; |
|
| 612 | + $new_default->set('TKT_ID', 0); |
|
| 613 | + $new_default->set('TKT_is_default', 1); |
|
| 614 | + $new_default->set('TKT_row', 1); |
|
| 615 | + $new_default->set('TKT_price', $ticket_price); |
|
| 616 | + // remove any dtt relations cause we DON'T want dtt relations attached |
|
| 617 | + // (note this is just removing the cached relations in the object) |
|
| 618 | + $new_default->_remove_relations('Datetime'); |
|
| 619 | + //todo we need to add the current attached prices as new prices to the new default ticket. |
|
| 620 | + $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
| 621 | + //don't forget the base price! |
|
| 622 | + $new_default = $this->_add_prices_to_ticket( |
|
| 623 | + array(), |
|
| 624 | + $new_default, |
|
| 625 | + $update_prices, |
|
| 626 | + $base_price, |
|
| 627 | + $base_price_id |
|
| 628 | + ); |
|
| 629 | + $new_default->save(); |
|
| 630 | + do_action( |
|
| 631 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
| 632 | + $new_default, |
|
| 633 | + $row, |
|
| 634 | + $ticket, |
|
| 635 | + $data |
|
| 636 | + ); |
|
| 637 | + } |
|
| 638 | + // DO ALL dtt relationships for both current tickets and any archived tickets |
|
| 639 | + // for the given dtt that are related to the current ticket. |
|
| 640 | + // TODO... not sure exactly how we're going to do this considering we don't know |
|
| 641 | + // what current ticket the archived tickets are related to |
|
| 642 | + // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
| 643 | + //let's assign any tickets that have been setup to the saved_tickets tracker |
|
| 644 | + //save existing TKT |
|
| 645 | + $ticket->save(); |
|
| 646 | + if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
| 647 | + //save new TKT |
|
| 648 | + $new_tkt->save(); |
|
| 649 | + //add new ticket to array |
|
| 650 | + $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
| 651 | + do_action( |
|
| 652 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
| 653 | + $new_tkt, |
|
| 654 | + $row, |
|
| 655 | + $tkt, |
|
| 656 | + $data |
|
| 657 | + ); |
|
| 658 | + } else { |
|
| 659 | + //add tkt to saved tkts |
|
| 660 | + $saved_tickets[$ticket->ID()] = $ticket; |
|
| 661 | + do_action( |
|
| 662 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
| 663 | + $ticket, |
|
| 664 | + $row, |
|
| 665 | + $tkt, |
|
| 666 | + $data |
|
| 667 | + ); |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + // now we need to handle tickets actually "deleted permanently". |
|
| 671 | + // There are cases where we'd want this to happen |
|
| 672 | + // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
| 673 | + // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
| 674 | + // No sense in keeping all the related data in the db! |
|
| 675 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
| 676 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 677 | + foreach ($tickets_removed as $id) { |
|
| 678 | + $id = absint($id); |
|
| 679 | + //get the ticket for this id |
|
| 680 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 681 | + //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
| 682 | + if ($tkt_to_remove->get('TKT_is_default')) { |
|
| 683 | + continue; |
|
| 684 | + } |
|
| 685 | + // if this tkt has any registrations attached so then we just ARCHIVE |
|
| 686 | + // because we don't actually permanently delete these tickets. |
|
| 687 | + if ($tkt_to_remove->count_related('Registration') > 0) { |
|
| 688 | + $tkt_to_remove->delete(); |
|
| 689 | + continue; |
|
| 690 | + } |
|
| 691 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 692 | + // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 693 | + $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
| 694 | + foreach ($datetimes as $datetime) { |
|
| 695 | + $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
| 696 | + } |
|
| 697 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
| 698 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 699 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 700 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
| 701 | + // finally let's delete this ticket |
|
| 702 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 703 | + $tkt_to_remove->delete_permanently(); |
|
| 704 | + } |
|
| 705 | + return $saved_tickets; |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * @access protected |
|
| 712 | + * @param \EE_Ticket $ticket |
|
| 713 | + * @param \EE_Datetime[] $saved_datetimes |
|
| 714 | + * @param \EE_Datetime[] $added_datetimes |
|
| 715 | + * @param \EE_Datetime[] $removed_datetimes |
|
| 716 | + * @return \EE_Ticket |
|
| 717 | + * @throws \EE_Error |
|
| 718 | + */ |
|
| 719 | + protected function _update_ticket_datetimes( |
|
| 720 | + EE_Ticket $ticket, |
|
| 721 | + $saved_datetimes = array(), |
|
| 722 | + $added_datetimes = array(), |
|
| 723 | + $removed_datetimes = array() |
|
| 724 | + ) { |
|
| 725 | + // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
| 726 | + // and removing the ticket from datetimes it got removed from. |
|
| 727 | + // first let's add datetimes |
|
| 728 | + if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 729 | + foreach ($added_datetimes as $row_id) { |
|
| 730 | + $row_id = (int)$row_id; |
|
| 731 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 732 | + $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 733 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 734 | + // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
| 735 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 736 | + $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
| 737 | + $saved_datetimes[$row_id]->save(); |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + // then remove datetimes |
|
| 743 | + if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 744 | + foreach ($removed_datetimes as $row_id) { |
|
| 745 | + $row_id = (int)$row_id; |
|
| 746 | + // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
| 747 | + // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
| 748 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 749 | + $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 750 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 751 | + // If so, then we need to remove it's sold from the DTT_sold. |
|
| 752 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 753 | + $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
| 754 | + $saved_datetimes[$row_id]->save(); |
|
| 755 | + } |
|
| 756 | + } |
|
| 757 | + } |
|
| 758 | + } |
|
| 759 | + // cap ticket qty by datetime reg limits |
|
| 760 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 761 | + return $ticket; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * @access protected |
|
| 768 | + * @param \EE_Ticket $ticket |
|
| 769 | + * @param array $price_rows |
|
| 770 | + * @param int $ticket_price |
|
| 771 | + * @param int $base_price |
|
| 772 | + * @param int $base_price_id |
|
| 773 | + * @return \EE_Ticket |
|
| 774 | + * @throws \EE_Error |
|
| 775 | + */ |
|
| 776 | + protected function _duplicate_ticket( |
|
| 777 | + EE_Ticket $ticket, |
|
| 778 | + $price_rows = array(), |
|
| 779 | + $ticket_price = 0, |
|
| 780 | + $base_price = 0, |
|
| 781 | + $base_price_id = 0 |
|
| 782 | + ) { |
|
| 783 | + // create new ticket that's a copy of the existing |
|
| 784 | + // except a new id of course (and not archived) |
|
| 785 | + // AND has the new TKT_price associated with it. |
|
| 786 | + $new_ticket = clone $ticket; |
|
| 787 | + $new_ticket->set('TKT_ID', 0); |
|
| 788 | + $new_ticket->set('TKT_deleted', 0); |
|
| 789 | + $new_ticket->set('TKT_price', $ticket_price); |
|
| 790 | + $new_ticket->set('TKT_sold', 0); |
|
| 791 | + // let's get a new ID for this ticket |
|
| 792 | + $new_ticket->save(); |
|
| 793 | + // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
| 794 | + $datetimes_on_existing = $ticket->get_many_related('Datetime'); |
|
| 795 | + $new_ticket = $this->_update_ticket_datetimes( |
|
| 796 | + $new_ticket, |
|
| 797 | + $datetimes_on_existing, |
|
| 798 | + array_keys($datetimes_on_existing) |
|
| 799 | + ); |
|
| 800 | + // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
| 801 | + // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
| 802 | + // available. |
|
| 803 | + if ($ticket->sold() > 0) { |
|
| 804 | + $new_qty = $ticket->qty() - $ticket->sold(); |
|
| 805 | + $new_ticket->set_qty($new_qty); |
|
| 806 | + } |
|
| 807 | + //now we update the prices just for this ticket |
|
| 808 | + $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
| 809 | + //and we update the base price |
|
| 810 | + $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
| 811 | + return $new_ticket; |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + |
|
| 816 | + /** |
|
| 817 | + * This attaches a list of given prices to a ticket. |
|
| 818 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 819 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 820 | + * price info and prices are automatically "archived" via the ticket. |
|
| 821 | + * |
|
| 822 | + * @access private |
|
| 823 | + * @param array $prices Array of prices from the form. |
|
| 824 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 825 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 826 | + * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
| 827 | + * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
| 828 | + * @return EE_Ticket |
|
| 829 | + * @throws EE_Error |
|
| 830 | + */ |
|
| 831 | + protected function _add_prices_to_ticket( |
|
| 832 | + $prices = array(), |
|
| 833 | + EE_Ticket $ticket, |
|
| 834 | + $new_prices = false, |
|
| 835 | + $base_price = false, |
|
| 836 | + $base_price_id = false |
|
| 837 | + ) { |
|
| 838 | + // let's just get any current prices that may exist on the given ticket |
|
| 839 | + // so we can remove any prices that got trashed in this session. |
|
| 840 | + $current_prices_on_ticket = $base_price !== false |
|
| 841 | + ? $ticket->base_price(true) |
|
| 842 | + : $ticket->price_modifiers(); |
|
| 843 | + $updated_prices = array(); |
|
| 844 | + // if $base_price ! FALSE then updating a base price. |
|
| 845 | + if ($base_price !== false) { |
|
| 846 | + $prices[1] = array( |
|
| 847 | + 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
| 848 | + 'PRT_ID' => 1, |
|
| 849 | + 'PRC_amount' => $base_price, |
|
| 850 | + 'PRC_name' => $ticket->get('TKT_name'), |
|
| 851 | + 'PRC_desc' => $ticket->get('TKT_description'), |
|
| 852 | + ); |
|
| 853 | + } |
|
| 854 | + //possibly need to save tkt |
|
| 855 | + if (! $ticket->ID()) { |
|
| 856 | + $ticket->save(); |
|
| 857 | + } |
|
| 858 | + foreach ($prices as $row => $prc) { |
|
| 859 | + $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
| 860 | + if (empty($prt_id)) { |
|
| 861 | + continue; |
|
| 862 | + } //prices MUST have a price type id. |
|
| 863 | + $PRC_values = array( |
|
| 864 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 865 | + 'PRT_ID' => $prt_id, |
|
| 866 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 867 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 868 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 869 | + 'PRC_is_default' => false, |
|
| 870 | + //make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
| 871 | + 'PRC_order' => $row, |
|
| 872 | + ); |
|
| 873 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 874 | + $PRC_values['PRC_ID'] = 0; |
|
| 875 | + $price = EE_Registry::instance()->load_class( |
|
| 876 | + 'Price', |
|
| 877 | + array($PRC_values), |
|
| 878 | + false, |
|
| 879 | + false |
|
| 880 | + ); |
|
| 881 | + } else { |
|
| 882 | + $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 883 | + //update this price with new values |
|
| 884 | + foreach ($PRC_values as $field => $value) { |
|
| 885 | + $price->set($field, $value); |
|
| 886 | + } |
|
| 887 | + } |
|
| 888 | + $price->save(); |
|
| 889 | + $updated_prices[$price->ID()] = $price; |
|
| 890 | + $ticket->_add_relation_to($price, 'Price'); |
|
| 891 | + } |
|
| 892 | + //now let's remove any prices that got removed from the ticket |
|
| 893 | + if (! empty ($current_prices_on_ticket)) { |
|
| 894 | + $current = array_keys($current_prices_on_ticket); |
|
| 895 | + $updated = array_keys($updated_prices); |
|
| 896 | + $prices_to_remove = array_diff($current, $updated); |
|
| 897 | + if (! empty($prices_to_remove)) { |
|
| 898 | + foreach ($prices_to_remove as $prc_id) { |
|
| 899 | + $p = $current_prices_on_ticket[$prc_id]; |
|
| 900 | + $ticket->_remove_relation_to($p, 'Price'); |
|
| 901 | + //delete permanently the price |
|
| 902 | + $p->delete_permanently(); |
|
| 903 | + } |
|
| 904 | + } |
|
| 905 | + } |
|
| 906 | + return $ticket; |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + |
|
| 910 | + |
|
| 911 | + /** |
|
| 912 | + * @param Events_Admin_Page $event_admin_obj |
|
| 913 | + * @return Events_Admin_Page |
|
| 914 | + */ |
|
| 915 | + public function autosave_handling( Events_Admin_Page $event_admin_obj) |
|
| 916 | + { |
|
| 917 | + return $event_admin_obj; |
|
| 918 | + //doing nothing for the moment. |
|
| 919 | + // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
| 920 | + // (use the set_template_args() method) |
|
| 921 | + /** |
|
| 922 | + * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
| 923 | + * 1. TKT_is_default_selector (visible) |
|
| 924 | + * 2. TKT_is_default (hidden) |
|
| 925 | + * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
| 926 | + * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
| 927 | + * this ticket to be saved as a default. |
|
| 928 | + * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
| 929 | + * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
| 930 | + * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
| 931 | + * the TKT HAS been saved as a default.. |
|
| 932 | + * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
| 933 | + * On Autosave: |
|
| 934 | + * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
| 935 | + * then set the TKT_is_default to false. |
|
| 936 | + * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
| 937 | + * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
| 938 | + * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
| 939 | + */ |
|
| 940 | + } |
|
| 941 | + |
|
| 942 | + |
|
| 943 | + |
|
| 944 | + /** |
|
| 945 | + * @throws DomainException |
|
| 946 | + * @throws EE_Error |
|
| 947 | + */ |
|
| 948 | + public function pricing_metabox() |
|
| 949 | + { |
|
| 950 | + $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
| 951 | + $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
| 952 | + //set is_creating_event property. |
|
| 953 | + $EVT_ID = $event->ID(); |
|
| 954 | + $this->_is_creating_event = absint($EVT_ID) === 0; |
|
| 955 | + //default main template args |
|
| 956 | + $main_template_args = array( |
|
| 957 | + 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
| 958 | + 'event_editor_event_datetimes_help_tab', |
|
| 959 | + $this->_adminpage_obj->page_slug, |
|
| 960 | + $this->_adminpage_obj->get_req_action(), |
|
| 961 | + false, |
|
| 962 | + false |
|
| 963 | + ), |
|
| 964 | + // todo need to add a filter to the template for the help text |
|
| 965 | + // in the Events_Admin_Page core file so we can add further help |
|
| 966 | + 'existing_datetime_ids' => '', |
|
| 967 | + 'total_dtt_rows' => 1, |
|
| 968 | + 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
| 969 | + 'add_new_dtt_info', |
|
| 970 | + $this->_adminpage_obj->page_slug, |
|
| 971 | + $this->_adminpage_obj->get_req_action(), |
|
| 972 | + false, |
|
| 973 | + false |
|
| 974 | + ), |
|
| 975 | + //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 976 | + 'datetime_rows' => '', |
|
| 977 | + 'show_tickets_container' => '', |
|
| 978 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
| 979 | + 'ticket_rows' => '', |
|
| 980 | + 'existing_ticket_ids' => '', |
|
| 981 | + 'total_ticket_rows' => 1, |
|
| 982 | + 'ticket_js_structure' => '', |
|
| 983 | + 'ee_collapsible_status' => ' ee-collapsible-open' |
|
| 984 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
| 985 | + ); |
|
| 986 | + $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
| 987 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 988 | + /** |
|
| 989 | + * 1. Start with retrieving Datetimes |
|
| 990 | + * 2. For each datetime get related tickets |
|
| 991 | + * 3. For each ticket get related prices |
|
| 992 | + */ |
|
| 993 | + /** @var EEM_Datetime $datetime_model */ |
|
| 994 | + $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
| 995 | + $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
| 996 | + $main_template_args['total_dtt_rows'] = count($datetimes); |
|
| 997 | + /** |
|
| 998 | + * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
| 999 | + * for why we are counting $datetime_row and then setting that on the Datetime object |
|
| 1000 | + */ |
|
| 1001 | + $datetime_row = 1; |
|
| 1002 | + foreach ($datetimes as $datetime) { |
|
| 1003 | + $DTT_ID = $datetime->get('DTT_ID'); |
|
| 1004 | + $datetime->set('DTT_order', $datetime_row); |
|
| 1005 | + $existing_datetime_ids[] = $DTT_ID; |
|
| 1006 | + //tickets attached |
|
| 1007 | + $related_tickets = $datetime->ID() > 0 |
|
| 1008 | + ? $datetime->get_many_related( |
|
| 1009 | + 'Ticket', |
|
| 1010 | + array( |
|
| 1011 | + array( |
|
| 1012 | + 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
| 1013 | + ), |
|
| 1014 | + 'default_where_conditions' => 'none', |
|
| 1015 | + 'order_by' => array('TKT_order' => 'ASC'), |
|
| 1016 | + ) |
|
| 1017 | + ) |
|
| 1018 | + : array(); |
|
| 1019 | + //if there are no related tickets this is likely a new event OR autodraft |
|
| 1020 | + // event so we need to generate the default tickets because datetimes |
|
| 1021 | + // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
| 1022 | + // datetime on the event. |
|
| 1023 | + if (empty ($related_tickets) && count($datetimes) < 2) { |
|
| 1024 | + /** @var EEM_Ticket $ticket_model */ |
|
| 1025 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 1026 | + $related_tickets = $ticket_model->get_all_default_tickets(); |
|
| 1027 | + // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
| 1028 | + // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
| 1029 | + $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
| 1030 | + $main_default_ticket = reset($related_tickets); |
|
| 1031 | + if ($main_default_ticket instanceof EE_Ticket) { |
|
| 1032 | + foreach ($default_prices as $default_price) { |
|
| 1033 | + if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
| 1034 | + continue; |
|
| 1035 | + } |
|
| 1036 | + $main_default_ticket->cache('Price', $default_price); |
|
| 1037 | + } |
|
| 1038 | + } |
|
| 1039 | + } |
|
| 1040 | + // we can't actually setup rows in this loop yet cause we don't know all |
|
| 1041 | + // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
| 1042 | + // So we're going to temporarily cache some of that information. |
|
| 1043 | + //loop through and setup the ticket rows and make sure the order is set. |
|
| 1044 | + foreach ($related_tickets as $ticket) { |
|
| 1045 | + $TKT_ID = $ticket->get('TKT_ID'); |
|
| 1046 | + $ticket_row = $ticket->get('TKT_row'); |
|
| 1047 | + //we only want unique tickets in our final display!! |
|
| 1048 | + if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1049 | + $existing_ticket_ids[] = $TKT_ID; |
|
| 1050 | + $all_tickets[] = $ticket; |
|
| 1051 | + } |
|
| 1052 | + //temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
| 1053 | + $datetime_tickets[$DTT_ID][] = $ticket_row; |
|
| 1054 | + //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
| 1055 | + if ( |
|
| 1056 | + ! isset($ticket_datetimes[$TKT_ID]) |
|
| 1057 | + || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true) |
|
| 1058 | + ) { |
|
| 1059 | + $ticket_datetimes[$TKT_ID][] = $datetime_row; |
|
| 1060 | + } |
|
| 1061 | + } |
|
| 1062 | + $datetime_row++; |
|
| 1063 | + } |
|
| 1064 | + $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
| 1065 | + $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1066 | + $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1067 | + //sort $all_tickets by order |
|
| 1068 | + usort( |
|
| 1069 | + $all_tickets, |
|
| 1070 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
| 1071 | + $a_order = (int)$a->get('TKT_order'); |
|
| 1072 | + $b_order = (int)$b->get('TKT_order'); |
|
| 1073 | + if ($a_order === $b_order) { |
|
| 1074 | + return 0; |
|
| 1075 | + } |
|
| 1076 | + return ($a_order < $b_order) ? -1 : 1; |
|
| 1077 | + } |
|
| 1078 | + ); |
|
| 1079 | + // k NOW we have all the data we need for setting up the dtt rows |
|
| 1080 | + // and ticket rows so we start our dtt loop again. |
|
| 1081 | + $datetime_row = 1; |
|
| 1082 | + foreach ($datetimes as $datetime) { |
|
| 1083 | + $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
| 1084 | + $datetime_row, |
|
| 1085 | + $datetime, |
|
| 1086 | + $datetime_tickets, |
|
| 1087 | + $all_tickets, |
|
| 1088 | + false, |
|
| 1089 | + $datetimes |
|
| 1090 | + ); |
|
| 1091 | + $datetime_row++; |
|
| 1092 | + } |
|
| 1093 | + //then loop through all tickets for the ticket rows. |
|
| 1094 | + $ticket_row = 1; |
|
| 1095 | + foreach ($all_tickets as $ticket) { |
|
| 1096 | + $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
| 1097 | + $ticket_row, |
|
| 1098 | + $ticket, |
|
| 1099 | + $ticket_datetimes, |
|
| 1100 | + $datetimes, |
|
| 1101 | + false, |
|
| 1102 | + $all_tickets |
|
| 1103 | + ); |
|
| 1104 | + $ticket_row++; |
|
| 1105 | + } |
|
| 1106 | + $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
| 1107 | + EEH_Template::display_template( |
|
| 1108 | + PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
| 1109 | + $main_template_args |
|
| 1110 | + ); |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + |
|
| 1114 | + |
|
| 1115 | + /** |
|
| 1116 | + * @param int $datetime_row |
|
| 1117 | + * @param EE_Datetime $datetime |
|
| 1118 | + * @param array $datetime_tickets |
|
| 1119 | + * @param array $all_tickets |
|
| 1120 | + * @param bool $default |
|
| 1121 | + * @param array $all_datetimes |
|
| 1122 | + * @return mixed |
|
| 1123 | + * @throws DomainException |
|
| 1124 | + * @throws EE_Error |
|
| 1125 | + */ |
|
| 1126 | + protected function _get_datetime_row( |
|
| 1127 | + $datetime_row, |
|
| 1128 | + EE_Datetime $datetime, |
|
| 1129 | + $datetime_tickets = array(), |
|
| 1130 | + $all_tickets = array(), |
|
| 1131 | + $default = false, |
|
| 1132 | + $all_datetimes = array() |
|
| 1133 | + ) { |
|
| 1134 | + $dtt_display_template_args = array( |
|
| 1135 | + 'dtt_edit_row' => $this->_get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes), |
|
| 1136 | + 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
| 1137 | + $datetime_row, |
|
| 1138 | + $datetime, |
|
| 1139 | + $datetime_tickets, |
|
| 1140 | + $all_tickets, |
|
| 1141 | + $default |
|
| 1142 | + ), |
|
| 1143 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1144 | + ); |
|
| 1145 | + return EEH_Template::display_template( |
|
| 1146 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
| 1147 | + $dtt_display_template_args, |
|
| 1148 | + true |
|
| 1149 | + ); |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + |
|
| 1153 | + |
|
| 1154 | + /** |
|
| 1155 | + * This method is used to generate a dtt fields edit row. |
|
| 1156 | + * The same row is used to generate a row with valid DTT objects |
|
| 1157 | + * and the default row that is used as the skeleton by the js. |
|
| 1158 | + * |
|
| 1159 | + * @param int $datetime_row The row number for the row being generated. |
|
| 1160 | + * @param EE_Datetime $datetime |
|
| 1161 | + * @param bool $default Whether a default row is being generated or not. |
|
| 1162 | + * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
| 1163 | + * @return string |
|
| 1164 | + * @throws DomainException |
|
| 1165 | + * @throws EE_Error |
|
| 1166 | + */ |
|
| 1167 | + protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
| 1168 | + { |
|
| 1169 | + // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
| 1170 | + $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
| 1171 | + $template_args = array( |
|
| 1172 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1173 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1174 | + 'edit_dtt_expanded' => '', |
|
| 1175 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1176 | + 'DTT_name' => $default ? '' : $datetime->name(), |
|
| 1177 | + 'DTT_description' => $default ? '' : $datetime->description(), |
|
| 1178 | + 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
| 1179 | + 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
| 1180 | + 'DTT_reg_limit' => $default |
|
| 1181 | + ? '' |
|
| 1182 | + : $datetime->get_pretty( |
|
| 1183 | + 'DTT_reg_limit', |
|
| 1184 | + 'input' |
|
| 1185 | + ), |
|
| 1186 | + 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1187 | + 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
| 1188 | + 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
| 1189 | + 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1190 | + ? '' |
|
| 1191 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1192 | + 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1193 | + ? 'ee-lock-icon' |
|
| 1194 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1195 | + 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
| 1196 | + ? '' |
|
| 1197 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1198 | + array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
| 1199 | + REG_ADMIN_URL |
|
| 1200 | + ), |
|
| 1201 | + ); |
|
| 1202 | + $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1203 | + ? ' style="display:none"' |
|
| 1204 | + : ''; |
|
| 1205 | + //allow filtering of template args at this point. |
|
| 1206 | + $template_args = apply_filters( |
|
| 1207 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
| 1208 | + $template_args, |
|
| 1209 | + $datetime_row, |
|
| 1210 | + $datetime, |
|
| 1211 | + $default, |
|
| 1212 | + $all_datetimes, |
|
| 1213 | + $this->_is_creating_event |
|
| 1214 | + ); |
|
| 1215 | + return EEH_Template::display_template( |
|
| 1216 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
| 1217 | + $template_args, |
|
| 1218 | + true |
|
| 1219 | + ); |
|
| 1220 | + } |
|
| 1221 | + |
|
| 1222 | + |
|
| 1223 | + |
|
| 1224 | + /** |
|
| 1225 | + * @param int $datetime_row |
|
| 1226 | + * @param EE_Datetime $datetime |
|
| 1227 | + * @param array $datetime_tickets |
|
| 1228 | + * @param array $all_tickets |
|
| 1229 | + * @param bool $default |
|
| 1230 | + * @return mixed |
|
| 1231 | + * @throws DomainException |
|
| 1232 | + * @throws EE_Error |
|
| 1233 | + */ |
|
| 1234 | + protected function _get_dtt_attached_tickets_row( |
|
| 1235 | + $datetime_row, |
|
| 1236 | + $datetime, |
|
| 1237 | + $datetime_tickets = array(), |
|
| 1238 | + $all_tickets = array(), |
|
| 1239 | + $default |
|
| 1240 | + ) { |
|
| 1241 | + $template_args = array( |
|
| 1242 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1243 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1244 | + 'DTT_description' => $default ? '' : $datetime->description(), |
|
| 1245 | + 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1246 | + 'show_tickets_row' => ' style="display:none;"', |
|
| 1247 | + 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
| 1248 | + 'add_new_ticket_via_datetime', |
|
| 1249 | + $this->_adminpage_obj->page_slug, |
|
| 1250 | + $this->_adminpage_obj->get_req_action(), |
|
| 1251 | + false, |
|
| 1252 | + false |
|
| 1253 | + ), |
|
| 1254 | + //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1255 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1256 | + ); |
|
| 1257 | + //need to setup the list items (but only if this isn't a default skeleton setup) |
|
| 1258 | + if (! $default) { |
|
| 1259 | + $ticket_row = 1; |
|
| 1260 | + foreach ($all_tickets as $ticket) { |
|
| 1261 | + $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 1262 | + $datetime_row, |
|
| 1263 | + $ticket_row, |
|
| 1264 | + $datetime, |
|
| 1265 | + $ticket, |
|
| 1266 | + $datetime_tickets, |
|
| 1267 | + $default |
|
| 1268 | + ); |
|
| 1269 | + $ticket_row++; |
|
| 1270 | + } |
|
| 1271 | + } |
|
| 1272 | + //filter template args at this point |
|
| 1273 | + $template_args = apply_filters( |
|
| 1274 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
| 1275 | + $template_args, |
|
| 1276 | + $datetime_row, |
|
| 1277 | + $datetime, |
|
| 1278 | + $datetime_tickets, |
|
| 1279 | + $all_tickets, |
|
| 1280 | + $default, |
|
| 1281 | + $this->_is_creating_event |
|
| 1282 | + ); |
|
| 1283 | + return EEH_Template::display_template( |
|
| 1284 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1285 | + $template_args, |
|
| 1286 | + true |
|
| 1287 | + ); |
|
| 1288 | + } |
|
| 1289 | + |
|
| 1290 | + |
|
| 1291 | + |
|
| 1292 | + /** |
|
| 1293 | + * @param int $datetime_row |
|
| 1294 | + * @param int $ticket_row |
|
| 1295 | + * @param EE_Datetime $datetime |
|
| 1296 | + * @param EE_Ticket $ticket |
|
| 1297 | + * @param array $datetime_tickets |
|
| 1298 | + * @param bool $default |
|
| 1299 | + * @return mixed |
|
| 1300 | + * @throws DomainException |
|
| 1301 | + * @throws EE_Error |
|
| 1302 | + */ |
|
| 1303 | + protected function _get_datetime_tickets_list_item( |
|
| 1304 | + $datetime_row, |
|
| 1305 | + $ticket_row, |
|
| 1306 | + $datetime, |
|
| 1307 | + $ticket, |
|
| 1308 | + $datetime_tickets = array(), |
|
| 1309 | + $default |
|
| 1310 | + ) { |
|
| 1311 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()]) |
|
| 1312 | + ? $datetime_tickets[$datetime->ID()] |
|
| 1313 | + : array(); |
|
| 1314 | + $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
| 1315 | + $no_ticket = $default && empty($ticket); |
|
| 1316 | + $template_args = array( |
|
| 1317 | + 'dtt_row' => $default |
|
| 1318 | + ? 'DTTNUM' |
|
| 1319 | + : $datetime_row, |
|
| 1320 | + 'tkt_row' => $no_ticket |
|
| 1321 | + ? 'TICKETNUM' |
|
| 1322 | + : $ticket_row, |
|
| 1323 | + 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
| 1324 | + ? ' checked="checked"' |
|
| 1325 | + : '', |
|
| 1326 | + 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
| 1327 | + ? ' ticket-selected' |
|
| 1328 | + : '', |
|
| 1329 | + 'TKT_name' => $no_ticket |
|
| 1330 | + ? 'TKTNAME' |
|
| 1331 | + : $ticket->get('TKT_name'), |
|
| 1332 | + 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
| 1333 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1334 | + : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1335 | + ); |
|
| 1336 | + //filter template args |
|
| 1337 | + $template_args = apply_filters( |
|
| 1338 | + 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
| 1339 | + $template_args, |
|
| 1340 | + $datetime_row, |
|
| 1341 | + $ticket_row, |
|
| 1342 | + $datetime, |
|
| 1343 | + $ticket, |
|
| 1344 | + $datetime_tickets, |
|
| 1345 | + $default, |
|
| 1346 | + $this->_is_creating_event |
|
| 1347 | + ); |
|
| 1348 | + return EEH_Template::display_template( |
|
| 1349 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1350 | + $template_args, |
|
| 1351 | + true |
|
| 1352 | + ); |
|
| 1353 | + } |
|
| 1354 | + |
|
| 1355 | + |
|
| 1356 | + |
|
| 1357 | + /** |
|
| 1358 | + * This generates the ticket row for tickets. |
|
| 1359 | + * This same method is used to generate both the actual rows and the js skeleton row |
|
| 1360 | + * (when default === true) |
|
| 1361 | + * |
|
| 1362 | + * @param int $ticket_row Represents the row number being generated. |
|
| 1363 | + * @param $ticket |
|
| 1364 | + * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
| 1365 | + * or empty for default |
|
| 1366 | + * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
| 1367 | + * @param bool $default Whether default row being generated or not. |
|
| 1368 | + * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
| 1369 | + * (or empty in the case of defaults) |
|
| 1370 | + * @return mixed |
|
| 1371 | + * @throws DomainException |
|
| 1372 | + * @throws EE_Error |
|
| 1373 | + */ |
|
| 1374 | + protected function _get_ticket_row( |
|
| 1375 | + $ticket_row, |
|
| 1376 | + $ticket, |
|
| 1377 | + $ticket_datetimes, |
|
| 1378 | + $all_datetimes, |
|
| 1379 | + $default = false, |
|
| 1380 | + $all_tickets = array() |
|
| 1381 | + ) { |
|
| 1382 | + // if $ticket is not an instance of EE_Ticket then force default to true. |
|
| 1383 | + $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
| 1384 | + $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', |
|
| 1385 | + array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
| 1386 | + // if there is only one price (which would be the base price) |
|
| 1387 | + // or NO prices and this ticket is a default ticket, |
|
| 1388 | + // let's just make sure there are no cached default prices on the object. |
|
| 1389 | + // This is done by not including any query_params. |
|
| 1390 | + if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
| 1391 | + $prices = $ticket->get_many_related('Price'); |
|
| 1392 | + } |
|
| 1393 | + // check if we're dealing with a default ticket in which case |
|
| 1394 | + // we don't want any starting_ticket_datetime_row values set |
|
| 1395 | + // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
| 1396 | + // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
| 1397 | + $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')); |
|
| 1398 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
| 1399 | + ? $ticket_datetimes[$ticket->ID()] |
|
| 1400 | + : array(); |
|
| 1401 | + $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1402 | + $base_price = $default ? null : $ticket->base_price(); |
|
| 1403 | + $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
| 1404 | + //breaking out complicated condition for ticket_status |
|
| 1405 | + if ($default) { |
|
| 1406 | + $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1407 | + } else { |
|
| 1408 | + $ticket_status_class = $ticket->is_default() |
|
| 1409 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1410 | + : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1411 | + } |
|
| 1412 | + //breaking out complicated condition for TKT_taxable |
|
| 1413 | + if ($default) { |
|
| 1414 | + $TKT_taxable = ''; |
|
| 1415 | + } else { |
|
| 1416 | + $TKT_taxable = $ticket->get('TKT_taxable') |
|
| 1417 | + ? ' checked="checked"' |
|
| 1418 | + : ''; |
|
| 1419 | + } |
|
| 1420 | + if ($default) { |
|
| 1421 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1422 | + } else if ($ticket->is_default()) { |
|
| 1423 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1424 | + } else { |
|
| 1425 | + $TKT_status = $ticket->ticket_status(true); |
|
| 1426 | + } |
|
| 1427 | + if ($default) { |
|
| 1428 | + $TKT_min = ''; |
|
| 1429 | + } else { |
|
| 1430 | + $TKT_min = $ticket->get('TKT_min'); |
|
| 1431 | + if ($TKT_min === -1 || $TKT_min === 0) { |
|
| 1432 | + $TKT_min = ''; |
|
| 1433 | + } |
|
| 1434 | + } |
|
| 1435 | + $template_args = array( |
|
| 1436 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1437 | + 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1438 | + //on initial page load this will always be the correct order. |
|
| 1439 | + 'tkt_status_class' => $ticket_status_class, |
|
| 1440 | + 'display_edit_tkt_row' => ' style="display:none;"', |
|
| 1441 | + 'edit_tkt_expanded' => '', |
|
| 1442 | + 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1443 | + 'TKT_name' => $default ? '' : $ticket->get('TKT_name'), |
|
| 1444 | + 'TKT_start_date' => $default |
|
| 1445 | + ? '' |
|
| 1446 | + : $ticket->get_date('TKT_start_date', |
|
| 1447 | + $this->_date_time_format), |
|
| 1448 | + 'TKT_end_date' => $default |
|
| 1449 | + ? '' |
|
| 1450 | + : $ticket->get_date('TKT_end_date', |
|
| 1451 | + $this->_date_time_format), |
|
| 1452 | + 'TKT_status' => $TKT_status, |
|
| 1453 | + 'TKT_price' => $default |
|
| 1454 | + ? '' |
|
| 1455 | + : EEH_Template::format_currency( |
|
| 1456 | + $ticket->get_ticket_total_with_taxes(), |
|
| 1457 | + false, |
|
| 1458 | + false |
|
| 1459 | + ), |
|
| 1460 | + 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
| 1461 | + 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
| 1462 | + 'TKT_qty' => $default |
|
| 1463 | + ? '' |
|
| 1464 | + : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
| 1465 | + 'TKT_qty_for_input' => $default |
|
| 1466 | + ? '' |
|
| 1467 | + : $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1468 | + 'TKT_uses' => $default |
|
| 1469 | + ? '' |
|
| 1470 | + : $ticket->get_pretty('TKT_uses', 'input'), |
|
| 1471 | + 'TKT_min' => $TKT_min, |
|
| 1472 | + 'TKT_max' => $default |
|
| 1473 | + ? '' |
|
| 1474 | + : $ticket->get_pretty('TKT_max', 'input'), |
|
| 1475 | + 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
| 1476 | + 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
| 1477 | + 'TKT_registrations' => $default |
|
| 1478 | + ? 0 |
|
| 1479 | + : $ticket->count_registrations( |
|
| 1480 | + array( |
|
| 1481 | + array( |
|
| 1482 | + 'STS_ID' => array( |
|
| 1483 | + '!=', |
|
| 1484 | + EEM_Registration::status_id_incomplete, |
|
| 1485 | + ), |
|
| 1486 | + ), |
|
| 1487 | + ) |
|
| 1488 | + ), |
|
| 1489 | + 'TKT_ID' => $default ? 0 : $ticket->get('TKT_ID'), |
|
| 1490 | + 'TKT_description' => $default ? '' : $ticket->get('TKT_description'), |
|
| 1491 | + 'TKT_is_default' => $default ? 0 : $ticket->get('TKT_is_default'), |
|
| 1492 | + 'TKT_required' => $default ? 0 : $ticket->required(), |
|
| 1493 | + 'TKT_is_default_selector' => '', |
|
| 1494 | + 'ticket_price_rows' => '', |
|
| 1495 | + 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
| 1496 | + ? '' |
|
| 1497 | + : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
| 1498 | + 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
| 1499 | + 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
| 1500 | + ? '' |
|
| 1501 | + : ' style="display:none;"', |
|
| 1502 | + 'show_price_mod_button' => count($prices) > 1 |
|
| 1503 | + || ($default && $count_price_mods > 0) |
|
| 1504 | + || (! $default && $ticket->get('TKT_deleted')) |
|
| 1505 | + ? ' style="display:none;"' |
|
| 1506 | + : '', |
|
| 1507 | + 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
| 1508 | + 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1509 | + 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
| 1510 | + 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
| 1511 | + 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
| 1512 | + 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
| 1513 | + 'TKT_taxable' => $TKT_taxable, |
|
| 1514 | + 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') |
|
| 1515 | + ? '' |
|
| 1516 | + : ' style="display:none"', |
|
| 1517 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1518 | + 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
| 1519 | + $ticket_subtotal, |
|
| 1520 | + false, |
|
| 1521 | + false |
|
| 1522 | + ), |
|
| 1523 | + 'TKT_subtotal_amount' => $ticket_subtotal, |
|
| 1524 | + 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
| 1525 | + 'disabled' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted'), |
|
| 1526 | + 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
| 1527 | + ? ' ticket-archived' |
|
| 1528 | + : '', |
|
| 1529 | + 'trash_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
| 1530 | + ? 'ee-lock-icon ' |
|
| 1531 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1532 | + 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
| 1533 | + ? '' |
|
| 1534 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1535 | + ); |
|
| 1536 | + $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1537 | + ? ' style="display:none"' |
|
| 1538 | + : ''; |
|
| 1539 | + //handle rows that should NOT be empty |
|
| 1540 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1541 | + //if empty then the start date will be now. |
|
| 1542 | + $template_args['TKT_start_date'] = date($this->_date_time_format, |
|
| 1543 | + current_time('timestamp')); |
|
| 1544 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1545 | + } |
|
| 1546 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1547 | + //get the earliest datetime (if present); |
|
| 1548 | + $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
| 1549 | + ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
| 1550 | + 'Datetime', |
|
| 1551 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1552 | + ) |
|
| 1553 | + : null; |
|
| 1554 | + if (! empty($earliest_dtt)) { |
|
| 1555 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
| 1556 | + 'DTT_EVT_start', |
|
| 1557 | + $this->_date_time_format |
|
| 1558 | + ); |
|
| 1559 | + } else { |
|
| 1560 | + //default so let's just use what's been set for the default date-time which is 30 days from now. |
|
| 1561 | + $template_args['TKT_end_date'] = date( |
|
| 1562 | + $this->_date_time_format, |
|
| 1563 | + mktime(24, 0, 0, date('m'), date('d') + 29, date('Y') |
|
| 1564 | + ) |
|
| 1565 | + ); |
|
| 1566 | + } |
|
| 1567 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1568 | + } |
|
| 1569 | + //generate ticket_datetime items |
|
| 1570 | + if (! $default) { |
|
| 1571 | + $datetime_row = 1; |
|
| 1572 | + foreach ($all_datetimes as $datetime) { |
|
| 1573 | + $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 1574 | + $datetime_row, |
|
| 1575 | + $ticket_row, |
|
| 1576 | + $datetime, |
|
| 1577 | + $ticket, |
|
| 1578 | + $ticket_datetimes, |
|
| 1579 | + $default |
|
| 1580 | + ); |
|
| 1581 | + $datetime_row++; |
|
| 1582 | + } |
|
| 1583 | + } |
|
| 1584 | + $price_row = 1; |
|
| 1585 | + foreach ($prices as $price) { |
|
| 1586 | + if (! $price instanceof EE_Price) { |
|
| 1587 | + continue; |
|
| 1588 | + } |
|
| 1589 | + if ($price->is_base_price()) { |
|
| 1590 | + $price_row++; |
|
| 1591 | + continue; |
|
| 1592 | + } |
|
| 1593 | + $show_trash = !((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
| 1594 | + $show_create = !(count($prices) > 1 && count($prices) !== $price_row); |
|
| 1595 | + $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
| 1596 | + $ticket_row, |
|
| 1597 | + $price_row, |
|
| 1598 | + $price, |
|
| 1599 | + $default, |
|
| 1600 | + $ticket, |
|
| 1601 | + $show_trash, |
|
| 1602 | + $show_create |
|
| 1603 | + ); |
|
| 1604 | + $price_row++; |
|
| 1605 | + } |
|
| 1606 | + //filter $template_args |
|
| 1607 | + $template_args = apply_filters( |
|
| 1608 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
| 1609 | + $template_args, |
|
| 1610 | + $ticket_row, |
|
| 1611 | + $ticket, |
|
| 1612 | + $ticket_datetimes, |
|
| 1613 | + $all_datetimes, |
|
| 1614 | + $default, |
|
| 1615 | + $all_tickets, |
|
| 1616 | + $this->_is_creating_event |
|
| 1617 | + ); |
|
| 1618 | + return EEH_Template::display_template( |
|
| 1619 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
| 1620 | + $template_args, |
|
| 1621 | + true |
|
| 1622 | + ); |
|
| 1623 | + } |
|
| 1624 | + |
|
| 1625 | + |
|
| 1626 | + |
|
| 1627 | + /** |
|
| 1628 | + * @param int $ticket_row |
|
| 1629 | + * @param EE_Ticket|null $ticket |
|
| 1630 | + * @return string |
|
| 1631 | + * @throws DomainException |
|
| 1632 | + * @throws EE_Error |
|
| 1633 | + */ |
|
| 1634 | + protected function _get_tax_rows($ticket_row, $ticket) |
|
| 1635 | + { |
|
| 1636 | + $tax_rows = ''; |
|
| 1637 | + /** @var EE_Price[] $taxes */ |
|
| 1638 | + $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
| 1639 | + foreach ($taxes as $tax) { |
|
| 1640 | + $tax_added = $this->_get_tax_added($tax, $ticket); |
|
| 1641 | + $template_args = array( |
|
| 1642 | + 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
| 1643 | + ? '' |
|
| 1644 | + : ' style="display:none;"', |
|
| 1645 | + 'tax_id' => $tax->ID(), |
|
| 1646 | + 'tkt_row' => $ticket_row, |
|
| 1647 | + 'tax_label' => $tax->get('PRC_name'), |
|
| 1648 | + 'tax_added' => $tax_added, |
|
| 1649 | + 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
| 1650 | + 'tax_amount' => $tax->get('PRC_amount'), |
|
| 1651 | + ); |
|
| 1652 | + $template_args = apply_filters( |
|
| 1653 | + 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
| 1654 | + $template_args, |
|
| 1655 | + $ticket_row, |
|
| 1656 | + $ticket, |
|
| 1657 | + $this->_is_creating_event |
|
| 1658 | + ); |
|
| 1659 | + $tax_rows .= EEH_Template::display_template( |
|
| 1660 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1661 | + $template_args, |
|
| 1662 | + true |
|
| 1663 | + ); |
|
| 1664 | + } |
|
| 1665 | + return $tax_rows; |
|
| 1666 | + } |
|
| 1667 | + |
|
| 1668 | + |
|
| 1669 | + |
|
| 1670 | + /** |
|
| 1671 | + * @param EE_Price $tax |
|
| 1672 | + * @param EE_Ticket|null $ticket |
|
| 1673 | + * @return float|int |
|
| 1674 | + * @throws EE_Error |
|
| 1675 | + */ |
|
| 1676 | + protected function _get_tax_added(EE_Price $tax, $ticket) |
|
| 1677 | + { |
|
| 1678 | + $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1679 | + return $subtotal * $tax->get('PRC_amount') / 100; |
|
| 1680 | + } |
|
| 1681 | + |
|
| 1682 | + |
|
| 1683 | + |
|
| 1684 | + /** |
|
| 1685 | + * @param int $ticket_row |
|
| 1686 | + * @param int $price_row |
|
| 1687 | + * @param EE_Price|null $price |
|
| 1688 | + * @param bool $default |
|
| 1689 | + * @param EE_Ticket|null $ticket |
|
| 1690 | + * @param bool $show_trash |
|
| 1691 | + * @param bool $show_create |
|
| 1692 | + * @return mixed |
|
| 1693 | + * @throws DomainException |
|
| 1694 | + * @throws EE_Error |
|
| 1695 | + */ |
|
| 1696 | + protected function _get_ticket_price_row( |
|
| 1697 | + $ticket_row, |
|
| 1698 | + $price_row, |
|
| 1699 | + $price, |
|
| 1700 | + $default, |
|
| 1701 | + $ticket, |
|
| 1702 | + $show_trash = true, |
|
| 1703 | + $show_create = true |
|
| 1704 | + ) { |
|
| 1705 | + $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
| 1706 | + $template_args = array( |
|
| 1707 | + 'tkt_row' => $default && empty($ticket) |
|
| 1708 | + ? 'TICKETNUM' |
|
| 1709 | + : $ticket_row, |
|
| 1710 | + 'PRC_order' => $default && empty($price) |
|
| 1711 | + ? 'PRICENUM' |
|
| 1712 | + : $price_row, |
|
| 1713 | + 'edit_prices_name' => $default && empty($price) |
|
| 1714 | + ? 'PRICENAMEATTR' |
|
| 1715 | + : 'edit_prices', |
|
| 1716 | + 'price_type_selector' => $default && empty($price) |
|
| 1717 | + ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1718 | + : $this->_get_price_type_selector($ticket_row, $price_row, $price, $default, $send_disabled), |
|
| 1719 | + 'PRC_ID' => $default && empty($price) |
|
| 1720 | + ? 0 |
|
| 1721 | + : $price->ID(), |
|
| 1722 | + 'PRC_is_default' => $default && empty($price) |
|
| 1723 | + ? 0 |
|
| 1724 | + : $price->get('PRC_is_default'), |
|
| 1725 | + 'PRC_name' => $default && empty($price) |
|
| 1726 | + ? '' |
|
| 1727 | + : $price->get('PRC_name'), |
|
| 1728 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1729 | + 'show_plus_or_minus' => $default && empty($price) |
|
| 1730 | + ? '' |
|
| 1731 | + : ' style="display:none;"', |
|
| 1732 | + 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
| 1733 | + ? ' style="display:none;"' |
|
| 1734 | + : '', |
|
| 1735 | + 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
| 1736 | + ? ' style="display:none;"' |
|
| 1737 | + : '', |
|
| 1738 | + 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
| 1739 | + ? ' style="display:none"' |
|
| 1740 | + : '', |
|
| 1741 | + 'PRC_amount' => $default && empty($price) |
|
| 1742 | + ? 0 |
|
| 1743 | + : $price->get_pretty('PRC_amount', |
|
| 1744 | + 'localized_float'), |
|
| 1745 | + 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
| 1746 | + ? ' style="display:none;"' |
|
| 1747 | + : '', |
|
| 1748 | + 'show_trash_icon' => $show_trash |
|
| 1749 | + ? '' |
|
| 1750 | + : ' style="display:none;"', |
|
| 1751 | + 'show_create_button' => $show_create |
|
| 1752 | + ? '' |
|
| 1753 | + : ' style="display:none;"', |
|
| 1754 | + 'PRC_desc' => $default && empty($price) |
|
| 1755 | + ? '' |
|
| 1756 | + : $price->get('PRC_desc'), |
|
| 1757 | + 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
| 1758 | + ); |
|
| 1759 | + $template_args = apply_filters( |
|
| 1760 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
| 1761 | + $template_args, |
|
| 1762 | + $ticket_row, |
|
| 1763 | + $price_row, |
|
| 1764 | + $price, |
|
| 1765 | + $default, |
|
| 1766 | + $ticket, |
|
| 1767 | + $show_trash, |
|
| 1768 | + $show_create, |
|
| 1769 | + $this->_is_creating_event |
|
| 1770 | + ); |
|
| 1771 | + return EEH_Template::display_template( |
|
| 1772 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1773 | + $template_args, |
|
| 1774 | + true |
|
| 1775 | + ); |
|
| 1776 | + } |
|
| 1777 | + |
|
| 1778 | + |
|
| 1779 | + |
|
| 1780 | + /** |
|
| 1781 | + * @param int $ticket_row |
|
| 1782 | + * @param int $price_row |
|
| 1783 | + * @param EE_Price $price |
|
| 1784 | + * @param bool $default |
|
| 1785 | + * @param bool $disabled |
|
| 1786 | + * @return mixed |
|
| 1787 | + * @throws DomainException |
|
| 1788 | + * @throws EE_Error |
|
| 1789 | + */ |
|
| 1790 | + protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
| 1791 | + { |
|
| 1792 | + if ($price->is_base_price()) { |
|
| 1793 | + return $this->_get_base_price_template($ticket_row, $price_row, $price, $default); |
|
| 1794 | + } |
|
| 1795 | + return $this->_get_price_modifier_template($ticket_row, $price_row, $price, $default, $disabled); |
|
| 1796 | + } |
|
| 1797 | + |
|
| 1798 | + |
|
| 1799 | + |
|
| 1800 | + /** |
|
| 1801 | + * @param int $ticket_row |
|
| 1802 | + * @param int $price_row |
|
| 1803 | + * @param EE_Price $price |
|
| 1804 | + * @param bool $default |
|
| 1805 | + * @return mixed |
|
| 1806 | + * @throws DomainException |
|
| 1807 | + * @throws EE_Error |
|
| 1808 | + */ |
|
| 1809 | + protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1810 | + { |
|
| 1811 | + $template_args = array( |
|
| 1812 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1813 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
| 1814 | + 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
| 1815 | + 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
| 1816 | + 'price_selected_operator' => '+', |
|
| 1817 | + 'price_selected_is_percent' => 0, |
|
| 1818 | + ); |
|
| 1819 | + $template_args = apply_filters( |
|
| 1820 | + 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
| 1821 | + $template_args, |
|
| 1822 | + $ticket_row, |
|
| 1823 | + $price_row, |
|
| 1824 | + $price, |
|
| 1825 | + $default, |
|
| 1826 | + $this->_is_creating_event |
|
| 1827 | + ); |
|
| 1828 | + return EEH_Template::display_template( |
|
| 1829 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
| 1830 | + $template_args, |
|
| 1831 | + true |
|
| 1832 | + ); |
|
| 1833 | + } |
|
| 1834 | + |
|
| 1835 | + |
|
| 1836 | + |
|
| 1837 | + /** |
|
| 1838 | + * @param int $ticket_row |
|
| 1839 | + * @param int $price_row |
|
| 1840 | + * @param EE_Price $price |
|
| 1841 | + * @param bool $default |
|
| 1842 | + * @param bool $disabled |
|
| 1843 | + * @return mixed |
|
| 1844 | + * @throws DomainException |
|
| 1845 | + * @throws EE_Error |
|
| 1846 | + */ |
|
| 1847 | + protected function _get_price_modifier_template( |
|
| 1848 | + $ticket_row, |
|
| 1849 | + $price_row, |
|
| 1850 | + $price, |
|
| 1851 | + $default, |
|
| 1852 | + $disabled = false |
|
| 1853 | + ) { |
|
| 1854 | + $select_name = $default && ! $price instanceof EE_Price |
|
| 1855 | + ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
| 1856 | + : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
| 1857 | + /** @var EEM_Price_Type $price_type_model */ |
|
| 1858 | + $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
| 1859 | + $price_types = $price_type_model->get_all(array( |
|
| 1860 | + array( |
|
| 1861 | + 'OR' => array( |
|
| 1862 | + 'PBT_ID' => '2', |
|
| 1863 | + 'PBT_ID*' => '3', |
|
| 1864 | + ), |
|
| 1865 | + ), |
|
| 1866 | + )); |
|
| 1867 | + $all_price_types = $default && ! $price instanceof EE_Price |
|
| 1868 | + ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
| 1869 | + : array(); |
|
| 1870 | + $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
| 1871 | + $price_option_spans = ''; |
|
| 1872 | + //setup price types for selector |
|
| 1873 | + foreach ($price_types as $price_type) { |
|
| 1874 | + if (! $price_type instanceof EE_Price_Type) { |
|
| 1875 | + continue; |
|
| 1876 | + } |
|
| 1877 | + $all_price_types[$price_type->ID()] = $price_type->get('PRT_name'); |
|
| 1878 | + //while we're in the loop let's setup the option spans used by js |
|
| 1879 | + $span_args = array( |
|
| 1880 | + 'PRT_ID' => $price_type->ID(), |
|
| 1881 | + 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
| 1882 | + 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
| 1883 | + ); |
|
| 1884 | + $price_option_spans .= EEH_Template::display_template( |
|
| 1885 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
| 1886 | + $span_args, |
|
| 1887 | + true |
|
| 1888 | + ); |
|
| 1889 | + } |
|
| 1890 | + $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' : $select_name; |
|
| 1891 | + $select_input = new EE_Select_Input( |
|
| 1892 | + $all_price_types, |
|
| 1893 | + array( |
|
| 1894 | + 'default' => $selected_price_type_id, |
|
| 1895 | + 'html_name' => $select_name, |
|
| 1896 | + 'html_class' => 'edit-price-PRT_ID', |
|
| 1897 | + 'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
| 1898 | + ) |
|
| 1899 | + ); |
|
| 1900 | + $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
| 1901 | + $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
| 1902 | + $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
| 1903 | + $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
| 1904 | + $template_args = array( |
|
| 1905 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1906 | + 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
| 1907 | + 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
| 1908 | + 'main_name' => $select_name, |
|
| 1909 | + 'selected_price_type_id' => $selected_price_type_id, |
|
| 1910 | + 'price_option_spans' => $price_option_spans, |
|
| 1911 | + 'price_selected_operator' => $price_selected_operator, |
|
| 1912 | + 'price_selected_is_percent' => $price_selected_is_percent, |
|
| 1913 | + 'disabled' => $disabled, |
|
| 1914 | + ); |
|
| 1915 | + $template_args = apply_filters( |
|
| 1916 | + 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
| 1917 | + $template_args, |
|
| 1918 | + $ticket_row, |
|
| 1919 | + $price_row, |
|
| 1920 | + $price, |
|
| 1921 | + $default, |
|
| 1922 | + $disabled, |
|
| 1923 | + $this->_is_creating_event |
|
| 1924 | + ); |
|
| 1925 | + return EEH_Template::display_template( |
|
| 1926 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 1927 | + $template_args, |
|
| 1928 | + true |
|
| 1929 | + ); |
|
| 1930 | + } |
|
| 1931 | + |
|
| 1932 | + |
|
| 1933 | + |
|
| 1934 | + /** |
|
| 1935 | + * @param int $datetime_row |
|
| 1936 | + * @param int $ticket_row |
|
| 1937 | + * @param EE_Datetime|null $datetime |
|
| 1938 | + * @param EE_Ticket|null $ticket |
|
| 1939 | + * @param array $ticket_datetimes |
|
| 1940 | + * @param bool $default |
|
| 1941 | + * @return mixed |
|
| 1942 | + * @throws DomainException |
|
| 1943 | + * @throws EE_Error |
|
| 1944 | + */ |
|
| 1945 | + protected function _get_ticket_datetime_list_item( |
|
| 1946 | + $datetime_row, |
|
| 1947 | + $ticket_row, |
|
| 1948 | + $datetime, |
|
| 1949 | + $ticket, |
|
| 1950 | + $ticket_datetimes = array(), |
|
| 1951 | + $default |
|
| 1952 | + ) { |
|
| 1953 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
| 1954 | + ? $ticket_datetimes[$ticket->ID()] |
|
| 1955 | + : array(); |
|
| 1956 | + $template_args = array( |
|
| 1957 | + 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
| 1958 | + ? 'DTTNUM' |
|
| 1959 | + : $datetime_row, |
|
| 1960 | + 'tkt_row' => $default |
|
| 1961 | + ? 'TICKETNUM' |
|
| 1962 | + : $ticket_row, |
|
| 1963 | + 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 1964 | + ? ' ticket-selected' |
|
| 1965 | + : '', |
|
| 1966 | + 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 1967 | + ? ' checked="checked"' |
|
| 1968 | + : '', |
|
| 1969 | + 'DTT_name' => $default && empty($datetime) |
|
| 1970 | + ? 'DTTNAME' |
|
| 1971 | + : $datetime->get_dtt_display_name(true), |
|
| 1972 | + 'tkt_status_class' => '', |
|
| 1973 | + ); |
|
| 1974 | + $template_args = apply_filters( |
|
| 1975 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
| 1976 | + $template_args, |
|
| 1977 | + $datetime_row, |
|
| 1978 | + $ticket_row, |
|
| 1979 | + $datetime, |
|
| 1980 | + $ticket, |
|
| 1981 | + $ticket_datetimes, |
|
| 1982 | + $default, |
|
| 1983 | + $this->_is_creating_event |
|
| 1984 | + ); |
|
| 1985 | + return EEH_Template::display_template( |
|
| 1986 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 1987 | + $template_args, |
|
| 1988 | + true |
|
| 1989 | + ); |
|
| 1990 | + } |
|
| 1991 | + |
|
| 1992 | + |
|
| 1993 | + |
|
| 1994 | + /** |
|
| 1995 | + * @param array $all_datetimes |
|
| 1996 | + * @param array $all_tickets |
|
| 1997 | + * @return mixed |
|
| 1998 | + * @throws DomainException |
|
| 1999 | + * @throws EE_Error |
|
| 2000 | + */ |
|
| 2001 | + protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
| 2002 | + { |
|
| 2003 | + $template_args = array( |
|
| 2004 | + 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
| 2005 | + 'DTTNUM', |
|
| 2006 | + null, |
|
| 2007 | + true, |
|
| 2008 | + $all_datetimes |
|
| 2009 | + ), |
|
| 2010 | + 'default_ticket_row' => $this->_get_ticket_row( |
|
| 2011 | + 'TICKETNUM', |
|
| 2012 | + null, |
|
| 2013 | + array(), |
|
| 2014 | + array(), |
|
| 2015 | + true |
|
| 2016 | + ), |
|
| 2017 | + 'default_price_row' => $this->_get_ticket_price_row( |
|
| 2018 | + 'TICKETNUM', |
|
| 2019 | + 'PRICENUM', |
|
| 2020 | + null, |
|
| 2021 | + true, |
|
| 2022 | + null |
|
| 2023 | + ), |
|
| 2024 | + 'default_price_rows' => '', |
|
| 2025 | + 'default_base_price_amount' => 0, |
|
| 2026 | + 'default_base_price_name' => '', |
|
| 2027 | + 'default_base_price_description' => '', |
|
| 2028 | + 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
| 2029 | + 'TICKETNUM', |
|
| 2030 | + 'PRICENUM', |
|
| 2031 | + null, |
|
| 2032 | + true |
|
| 2033 | + ), |
|
| 2034 | + 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
| 2035 | + 'DTTNUM', |
|
| 2036 | + null, |
|
| 2037 | + array(), |
|
| 2038 | + array(), |
|
| 2039 | + true |
|
| 2040 | + ), |
|
| 2041 | + 'existing_available_datetime_tickets_list' => '', |
|
| 2042 | + 'existing_available_ticket_datetimes_list' => '', |
|
| 2043 | + 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
| 2044 | + 'DTTNUM', |
|
| 2045 | + 'TICKETNUM', |
|
| 2046 | + null, |
|
| 2047 | + null, |
|
| 2048 | + array(), |
|
| 2049 | + true |
|
| 2050 | + ), |
|
| 2051 | + 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
| 2052 | + 'DTTNUM', |
|
| 2053 | + 'TICKETNUM', |
|
| 2054 | + null, |
|
| 2055 | + null, |
|
| 2056 | + array(), |
|
| 2057 | + true |
|
| 2058 | + ), |
|
| 2059 | + ); |
|
| 2060 | + $ticket_row = 1; |
|
| 2061 | + foreach ($all_tickets as $ticket) { |
|
| 2062 | + $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 2063 | + 'DTTNUM', |
|
| 2064 | + $ticket_row, |
|
| 2065 | + null, |
|
| 2066 | + $ticket, |
|
| 2067 | + array(), |
|
| 2068 | + true |
|
| 2069 | + ); |
|
| 2070 | + $ticket_row++; |
|
| 2071 | + } |
|
| 2072 | + $datetime_row = 1; |
|
| 2073 | + foreach ($all_datetimes as $datetime) { |
|
| 2074 | + $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 2075 | + $datetime_row, |
|
| 2076 | + 'TICKETNUM', |
|
| 2077 | + $datetime, |
|
| 2078 | + null, |
|
| 2079 | + array(), |
|
| 2080 | + true |
|
| 2081 | + ); |
|
| 2082 | + $datetime_row++; |
|
| 2083 | + } |
|
| 2084 | + /** @var EEM_Price $price_model */ |
|
| 2085 | + $price_model = EE_Registry::instance()->load_model('Price'); |
|
| 2086 | + $default_prices = $price_model->get_all_default_prices(); |
|
| 2087 | + $price_row = 1; |
|
| 2088 | + foreach ($default_prices as $price) { |
|
| 2089 | + if (! $price instanceof EE_Price) { |
|
| 2090 | + continue; |
|
| 2091 | + } |
|
| 2092 | + if ($price->is_base_price()) { |
|
| 2093 | + $template_args['default_base_price_amount'] = $price->get_pretty( |
|
| 2094 | + 'PRC_amount', |
|
| 2095 | + 'localized_float' |
|
| 2096 | + ); |
|
| 2097 | + $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
| 2098 | + $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
| 2099 | + $price_row++; |
|
| 2100 | + continue; |
|
| 2101 | + } |
|
| 2102 | + $show_trash = !((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1); |
|
| 2103 | + $show_create = !(count($default_prices) > 1 && count($default_prices) !== $price_row); |
|
| 2104 | + $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
| 2105 | + 'TICKETNUM', |
|
| 2106 | + $price_row, |
|
| 2107 | + $price, |
|
| 2108 | + true, |
|
| 2109 | + null, |
|
| 2110 | + $show_trash, |
|
| 2111 | + $show_create |
|
| 2112 | + ); |
|
| 2113 | + $price_row++; |
|
| 2114 | + } |
|
| 2115 | + $template_args = apply_filters( |
|
| 2116 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
| 2117 | + $template_args, |
|
| 2118 | + $all_datetimes, |
|
| 2119 | + $all_tickets, |
|
| 2120 | + $this->_is_creating_event |
|
| 2121 | + ); |
|
| 2122 | + return EEH_Template::display_template( |
|
| 2123 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2124 | + $template_args, |
|
| 2125 | + true |
|
| 2126 | + ); |
|
| 2127 | + } |
|
| 2128 | 2128 | |
| 2129 | 2129 | |
| 2130 | 2130 | } //end class espresso_events_Pricing_Hooks |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
| 128 | 128 | ? $this->_date_format_strings['time'] |
| 129 | 129 | : null; |
| 130 | - $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']; |
|
| 130 | + $this->_date_time_format = $this->_date_format_strings['date'].' '.$this->_date_format_strings['time']; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | ); |
| 153 | 153 | $msg .= '</p><ul>'; |
| 154 | 154 | foreach ($format_validation as $error) { |
| 155 | - $msg .= '<li>' . $error . '</li>'; |
|
| 155 | + $msg .= '<li>'.$error.'</li>'; |
|
| 156 | 156 | } |
| 157 | 157 | $msg .= '</ul><p>'; |
| 158 | 158 | $msg .= sprintf( |
@@ -182,11 +182,11 @@ discard block |
||
| 182 | 182 | $this->_scripts_styles = array( |
| 183 | 183 | 'registers' => array( |
| 184 | 184 | 'ee-tickets-datetimes-css' => array( |
| 185 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 185 | + 'url' => PRICING_ASSETS_URL.'event-tickets-datetimes.css', |
|
| 186 | 186 | 'type' => 'css', |
| 187 | 187 | ), |
| 188 | 188 | 'ee-dtt-ticket-metabox' => array( |
| 189 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 189 | + 'url' => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js', |
|
| 190 | 190 | 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
| 191 | 191 | ), |
| 192 | 192 | ), |
@@ -210,9 +210,9 @@ discard block |
||
| 210 | 210 | 'event_espresso' |
| 211 | 211 | ), |
| 212 | 212 | 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
| 213 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
| 213 | + . esc_html__('Cancel', 'event_espresso').'</button>', |
|
| 214 | 214 | 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
| 215 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
| 215 | + . esc_html__('Close', 'event_espresso').'</button>', |
|
| 216 | 216 | 'single_warning_from_tkt' => esc_html__( |
| 217 | 217 | 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
| 218 | 218 | 'event_espresso' |
@@ -222,12 +222,12 @@ discard block |
||
| 222 | 222 | 'event_espresso' |
| 223 | 223 | ), |
| 224 | 224 | 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
| 225 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
| 225 | + . esc_html__('Dismiss', 'event_espresso').'</button>', |
|
| 226 | 226 | ), |
| 227 | 227 | 'DTT_ERROR_MSG' => array( |
| 228 | 228 | 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
| 229 | 229 | 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' |
| 230 | - . esc_html__('Dismiss', 'event_espresso') . '</button></div>', |
|
| 230 | + . esc_html__('Dismiss', 'event_espresso').'</button></div>', |
|
| 231 | 231 | ), |
| 232 | 232 | 'DTT_OVERSELL_WARNING' => array( |
| 233 | 233 | 'datetime_ticket' => esc_html__( |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | $this->_date_format_strings['date'], |
| 244 | 244 | $this->_date_format_strings['time'] |
| 245 | 245 | ), |
| 246 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')), |
|
| 246 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')), |
|
| 247 | 247 | ), |
| 248 | 248 | ), |
| 249 | 249 | ); |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
| 299 | 299 | $saved_dtt_ids = array(); |
| 300 | 300 | $saved_dtt_objs = array(); |
| 301 | - if (empty($data['edit_event_datetimes']) || !is_array($data['edit_event_datetimes'])) { |
|
| 301 | + if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) { |
|
| 302 | 302 | throw new InvalidArgumentException( |
| 303 | 303 | esc_html__( |
| 304 | 304 | 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
| 310 | 310 | //trim all values to ensure any excess whitespace is removed. |
| 311 | 311 | $datetime_data = array_map( |
| 312 | - function ($datetime_data) { |
|
| 312 | + function($datetime_data) { |
|
| 313 | 313 | return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
| 314 | 314 | }, |
| 315 | 315 | $datetime_data |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | ); |
| 340 | 340 | // if we have an id then let's get existing object first and then set the new values. |
| 341 | 341 | // Otherwise we instantiate a new object for save. |
| 342 | - if (! empty($datetime_data['DTT_ID'])) { |
|
| 342 | + if ( ! empty($datetime_data['DTT_ID'])) { |
|
| 343 | 343 | $datetime = EE_Registry::instance() |
| 344 | 344 | ->load_model('Datetime', array($timezone)) |
| 345 | 345 | ->get_one_by_ID($datetime_data['DTT_ID']); |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
| 433 | 433 | $saved_tickets = $datetimes_on_existing = array(); |
| 434 | 434 | $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
| 435 | - if(empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])){ |
|
| 435 | + if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
| 436 | 436 | throw new InvalidArgumentException( |
| 437 | 437 | esc_html__( |
| 438 | 438 | 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
| 451 | 451 | // trim inputs to ensure any excess whitespace is removed. |
| 452 | 452 | $tkt = array_map( |
| 453 | - function ($ticket_data) { |
|
| 453 | + function($ticket_data) { |
|
| 454 | 454 | return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
| 455 | 455 | }, |
| 456 | 456 | $tkt |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | // because we're doing calculations prior to using the models. |
| 460 | 460 | // note incoming ['TKT_price'] value is already in standard notation (via js). |
| 461 | 461 | $ticket_price = isset($tkt['TKT_price']) |
| 462 | - ? round((float)$tkt['TKT_price'], 3) |
|
| 462 | + ? round((float) $tkt['TKT_price'], 3) |
|
| 463 | 463 | : 0; |
| 464 | 464 | //note incoming base price needs converted from localized value. |
| 465 | 465 | $base_price = isset($tkt['TKT_base_price']) |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | //need to make sue that the TKT_price is accurate after saving the prices. |
| 607 | 607 | $ticket->ensure_TKT_Price_correct(); |
| 608 | 608 | //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
| 609 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 609 | + if ( ! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 610 | 610 | $update_prices = true; |
| 611 | 611 | $new_default = clone $ticket; |
| 612 | 612 | $new_default->set('TKT_ID', 0); |
@@ -725,9 +725,9 @@ discard block |
||
| 725 | 725 | // to start we have to add the ticket to all the datetimes its supposed to be with, |
| 726 | 726 | // and removing the ticket from datetimes it got removed from. |
| 727 | 727 | // first let's add datetimes |
| 728 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 728 | + if ( ! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 729 | 729 | foreach ($added_datetimes as $row_id) { |
| 730 | - $row_id = (int)$row_id; |
|
| 730 | + $row_id = (int) $row_id; |
|
| 731 | 731 | if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
| 732 | 732 | $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
| 733 | 733 | // Is this an existing ticket (has an ID) and does it have any sold? |
@@ -740,9 +740,9 @@ discard block |
||
| 740 | 740 | } |
| 741 | 741 | } |
| 742 | 742 | // then remove datetimes |
| 743 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 743 | + if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 744 | 744 | foreach ($removed_datetimes as $row_id) { |
| 745 | - $row_id = (int)$row_id; |
|
| 745 | + $row_id = (int) $row_id; |
|
| 746 | 746 | // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
| 747 | 747 | // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
| 748 | 748 | if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
@@ -852,7 +852,7 @@ discard block |
||
| 852 | 852 | ); |
| 853 | 853 | } |
| 854 | 854 | //possibly need to save tkt |
| 855 | - if (! $ticket->ID()) { |
|
| 855 | + if ( ! $ticket->ID()) { |
|
| 856 | 856 | $ticket->save(); |
| 857 | 857 | } |
| 858 | 858 | foreach ($prices as $row => $prc) { |
@@ -890,11 +890,11 @@ discard block |
||
| 890 | 890 | $ticket->_add_relation_to($price, 'Price'); |
| 891 | 891 | } |
| 892 | 892 | //now let's remove any prices that got removed from the ticket |
| 893 | - if (! empty ($current_prices_on_ticket)) { |
|
| 893 | + if ( ! empty ($current_prices_on_ticket)) { |
|
| 894 | 894 | $current = array_keys($current_prices_on_ticket); |
| 895 | 895 | $updated = array_keys($updated_prices); |
| 896 | 896 | $prices_to_remove = array_diff($current, $updated); |
| 897 | - if (! empty($prices_to_remove)) { |
|
| 897 | + if ( ! empty($prices_to_remove)) { |
|
| 898 | 898 | foreach ($prices_to_remove as $prc_id) { |
| 899 | 899 | $p = $current_prices_on_ticket[$prc_id]; |
| 900 | 900 | $ticket->_remove_relation_to($p, 'Price'); |
@@ -912,7 +912,7 @@ discard block |
||
| 912 | 912 | * @param Events_Admin_Page $event_admin_obj |
| 913 | 913 | * @return Events_Admin_Page |
| 914 | 914 | */ |
| 915 | - public function autosave_handling( Events_Admin_Page $event_admin_obj) |
|
| 915 | + public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
| 916 | 916 | { |
| 917 | 917 | return $event_admin_obj; |
| 918 | 918 | //doing nothing for the moment. |
@@ -1045,7 +1045,7 @@ discard block |
||
| 1045 | 1045 | $TKT_ID = $ticket->get('TKT_ID'); |
| 1046 | 1046 | $ticket_row = $ticket->get('TKT_row'); |
| 1047 | 1047 | //we only want unique tickets in our final display!! |
| 1048 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1048 | + if ( ! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1049 | 1049 | $existing_ticket_ids[] = $TKT_ID; |
| 1050 | 1050 | $all_tickets[] = $ticket; |
| 1051 | 1051 | } |
@@ -1067,9 +1067,9 @@ discard block |
||
| 1067 | 1067 | //sort $all_tickets by order |
| 1068 | 1068 | usort( |
| 1069 | 1069 | $all_tickets, |
| 1070 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
| 1071 | - $a_order = (int)$a->get('TKT_order'); |
|
| 1072 | - $b_order = (int)$b->get('TKT_order'); |
|
| 1070 | + function(EE_Ticket $a, EE_Ticket $b) { |
|
| 1071 | + $a_order = (int) $a->get('TKT_order'); |
|
| 1072 | + $b_order = (int) $b->get('TKT_order'); |
|
| 1073 | 1073 | if ($a_order === $b_order) { |
| 1074 | 1074 | return 0; |
| 1075 | 1075 | } |
@@ -1105,7 +1105,7 @@ discard block |
||
| 1105 | 1105 | } |
| 1106 | 1106 | $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
| 1107 | 1107 | EEH_Template::display_template( |
| 1108 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
| 1108 | + PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php', |
|
| 1109 | 1109 | $main_template_args |
| 1110 | 1110 | ); |
| 1111 | 1111 | } |
@@ -1143,7 +1143,7 @@ discard block |
||
| 1143 | 1143 | 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
| 1144 | 1144 | ); |
| 1145 | 1145 | return EEH_Template::display_template( |
| 1146 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
| 1146 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php', |
|
| 1147 | 1147 | $dtt_display_template_args, |
| 1148 | 1148 | true |
| 1149 | 1149 | ); |
@@ -1213,7 +1213,7 @@ discard block |
||
| 1213 | 1213 | $this->_is_creating_event |
| 1214 | 1214 | ); |
| 1215 | 1215 | return EEH_Template::display_template( |
| 1216 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
| 1216 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php', |
|
| 1217 | 1217 | $template_args, |
| 1218 | 1218 | true |
| 1219 | 1219 | ); |
@@ -1255,7 +1255,7 @@ discard block |
||
| 1255 | 1255 | 'DTT_ID' => $default ? '' : $datetime->ID(), |
| 1256 | 1256 | ); |
| 1257 | 1257 | //need to setup the list items (but only if this isn't a default skeleton setup) |
| 1258 | - if (! $default) { |
|
| 1258 | + if ( ! $default) { |
|
| 1259 | 1259 | $ticket_row = 1; |
| 1260 | 1260 | foreach ($all_tickets as $ticket) { |
| 1261 | 1261 | $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
@@ -1281,7 +1281,7 @@ discard block |
||
| 1281 | 1281 | $this->_is_creating_event |
| 1282 | 1282 | ); |
| 1283 | 1283 | return EEH_Template::display_template( |
| 1284 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1284 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1285 | 1285 | $template_args, |
| 1286 | 1286 | true |
| 1287 | 1287 | ); |
@@ -1330,8 +1330,8 @@ discard block |
||
| 1330 | 1330 | ? 'TKTNAME' |
| 1331 | 1331 | : $ticket->get('TKT_name'), |
| 1332 | 1332 | 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
| 1333 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1334 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1333 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
| 1334 | + : ' tkt-status-'.$ticket->ticket_status(), |
|
| 1335 | 1335 | ); |
| 1336 | 1336 | //filter template args |
| 1337 | 1337 | $template_args = apply_filters( |
@@ -1346,7 +1346,7 @@ discard block |
||
| 1346 | 1346 | $this->_is_creating_event |
| 1347 | 1347 | ); |
| 1348 | 1348 | return EEH_Template::display_template( |
| 1349 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1349 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1350 | 1350 | $template_args, |
| 1351 | 1351 | true |
| 1352 | 1352 | ); |
@@ -1403,11 +1403,11 @@ discard block |
||
| 1403 | 1403 | $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
| 1404 | 1404 | //breaking out complicated condition for ticket_status |
| 1405 | 1405 | if ($default) { |
| 1406 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1406 | + $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1407 | 1407 | } else { |
| 1408 | 1408 | $ticket_status_class = $ticket->is_default() |
| 1409 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1410 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1409 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
| 1410 | + : ' tkt-status-'.$ticket->ticket_status(); |
|
| 1411 | 1411 | } |
| 1412 | 1412 | //breaking out complicated condition for TKT_taxable |
| 1413 | 1413 | if ($default) { |
@@ -1501,7 +1501,7 @@ discard block |
||
| 1501 | 1501 | : ' style="display:none;"', |
| 1502 | 1502 | 'show_price_mod_button' => count($prices) > 1 |
| 1503 | 1503 | || ($default && $count_price_mods > 0) |
| 1504 | - || (! $default && $ticket->get('TKT_deleted')) |
|
| 1504 | + || ( ! $default && $ticket->get('TKT_deleted')) |
|
| 1505 | 1505 | ? ' style="display:none;"' |
| 1506 | 1506 | : '', |
| 1507 | 1507 | 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
@@ -1541,7 +1541,7 @@ discard block |
||
| 1541 | 1541 | //if empty then the start date will be now. |
| 1542 | 1542 | $template_args['TKT_start_date'] = date($this->_date_time_format, |
| 1543 | 1543 | current_time('timestamp')); |
| 1544 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1544 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1545 | 1545 | } |
| 1546 | 1546 | if (empty($template_args['TKT_end_date'])) { |
| 1547 | 1547 | //get the earliest datetime (if present); |
@@ -1551,7 +1551,7 @@ discard block |
||
| 1551 | 1551 | array('order_by' => array('DTT_EVT_start' => 'ASC')) |
| 1552 | 1552 | ) |
| 1553 | 1553 | : null; |
| 1554 | - if (! empty($earliest_dtt)) { |
|
| 1554 | + if ( ! empty($earliest_dtt)) { |
|
| 1555 | 1555 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
| 1556 | 1556 | 'DTT_EVT_start', |
| 1557 | 1557 | $this->_date_time_format |
@@ -1564,10 +1564,10 @@ discard block |
||
| 1564 | 1564 | ) |
| 1565 | 1565 | ); |
| 1566 | 1566 | } |
| 1567 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1567 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1568 | 1568 | } |
| 1569 | 1569 | //generate ticket_datetime items |
| 1570 | - if (! $default) { |
|
| 1570 | + if ( ! $default) { |
|
| 1571 | 1571 | $datetime_row = 1; |
| 1572 | 1572 | foreach ($all_datetimes as $datetime) { |
| 1573 | 1573 | $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
@@ -1583,15 +1583,15 @@ discard block |
||
| 1583 | 1583 | } |
| 1584 | 1584 | $price_row = 1; |
| 1585 | 1585 | foreach ($prices as $price) { |
| 1586 | - if (! $price instanceof EE_Price) { |
|
| 1586 | + if ( ! $price instanceof EE_Price) { |
|
| 1587 | 1587 | continue; |
| 1588 | 1588 | } |
| 1589 | 1589 | if ($price->is_base_price()) { |
| 1590 | 1590 | $price_row++; |
| 1591 | 1591 | continue; |
| 1592 | 1592 | } |
| 1593 | - $show_trash = !((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
| 1594 | - $show_create = !(count($prices) > 1 && count($prices) !== $price_row); |
|
| 1593 | + $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
| 1594 | + $show_create = ! (count($prices) > 1 && count($prices) !== $price_row); |
|
| 1595 | 1595 | $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
| 1596 | 1596 | $ticket_row, |
| 1597 | 1597 | $price_row, |
@@ -1616,7 +1616,7 @@ discard block |
||
| 1616 | 1616 | $this->_is_creating_event |
| 1617 | 1617 | ); |
| 1618 | 1618 | return EEH_Template::display_template( |
| 1619 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
| 1619 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php', |
|
| 1620 | 1620 | $template_args, |
| 1621 | 1621 | true |
| 1622 | 1622 | ); |
@@ -1657,7 +1657,7 @@ discard block |
||
| 1657 | 1657 | $this->_is_creating_event |
| 1658 | 1658 | ); |
| 1659 | 1659 | $tax_rows .= EEH_Template::display_template( |
| 1660 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1660 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1661 | 1661 | $template_args, |
| 1662 | 1662 | true |
| 1663 | 1663 | ); |
@@ -1769,7 +1769,7 @@ discard block |
||
| 1769 | 1769 | $this->_is_creating_event |
| 1770 | 1770 | ); |
| 1771 | 1771 | return EEH_Template::display_template( |
| 1772 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1772 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1773 | 1773 | $template_args, |
| 1774 | 1774 | true |
| 1775 | 1775 | ); |
@@ -1826,7 +1826,7 @@ discard block |
||
| 1826 | 1826 | $this->_is_creating_event |
| 1827 | 1827 | ); |
| 1828 | 1828 | return EEH_Template::display_template( |
| 1829 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
| 1829 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php', |
|
| 1830 | 1830 | $template_args, |
| 1831 | 1831 | true |
| 1832 | 1832 | ); |
@@ -1853,7 +1853,7 @@ discard block |
||
| 1853 | 1853 | ) { |
| 1854 | 1854 | $select_name = $default && ! $price instanceof EE_Price |
| 1855 | 1855 | ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
| 1856 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
| 1856 | + : 'edit_prices['.$ticket_row.']['.$price_row.'][PRT_ID]'; |
|
| 1857 | 1857 | /** @var EEM_Price_Type $price_type_model */ |
| 1858 | 1858 | $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
| 1859 | 1859 | $price_types = $price_type_model->get_all(array( |
@@ -1871,7 +1871,7 @@ discard block |
||
| 1871 | 1871 | $price_option_spans = ''; |
| 1872 | 1872 | //setup price types for selector |
| 1873 | 1873 | foreach ($price_types as $price_type) { |
| 1874 | - if (! $price_type instanceof EE_Price_Type) { |
|
| 1874 | + if ( ! $price_type instanceof EE_Price_Type) { |
|
| 1875 | 1875 | continue; |
| 1876 | 1876 | } |
| 1877 | 1877 | $all_price_types[$price_type->ID()] = $price_type->get('PRT_name'); |
@@ -1882,12 +1882,12 @@ discard block |
||
| 1882 | 1882 | 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
| 1883 | 1883 | ); |
| 1884 | 1884 | $price_option_spans .= EEH_Template::display_template( |
| 1885 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
| 1885 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php', |
|
| 1886 | 1886 | $span_args, |
| 1887 | 1887 | true |
| 1888 | 1888 | ); |
| 1889 | 1889 | } |
| 1890 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' : $select_name; |
|
| 1890 | + $select_name = $disabled ? 'archive_price['.$ticket_row.']['.$price_row.'][PRT_ID]' : $select_name; |
|
| 1891 | 1891 | $select_input = new EE_Select_Input( |
| 1892 | 1892 | $all_price_types, |
| 1893 | 1893 | array( |
@@ -1923,7 +1923,7 @@ discard block |
||
| 1923 | 1923 | $this->_is_creating_event |
| 1924 | 1924 | ); |
| 1925 | 1925 | return EEH_Template::display_template( |
| 1926 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 1926 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 1927 | 1927 | $template_args, |
| 1928 | 1928 | true |
| 1929 | 1929 | ); |
@@ -1983,7 +1983,7 @@ discard block |
||
| 1983 | 1983 | $this->_is_creating_event |
| 1984 | 1984 | ); |
| 1985 | 1985 | return EEH_Template::display_template( |
| 1986 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 1986 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 1987 | 1987 | $template_args, |
| 1988 | 1988 | true |
| 1989 | 1989 | ); |
@@ -2086,7 +2086,7 @@ discard block |
||
| 2086 | 2086 | $default_prices = $price_model->get_all_default_prices(); |
| 2087 | 2087 | $price_row = 1; |
| 2088 | 2088 | foreach ($default_prices as $price) { |
| 2089 | - if (! $price instanceof EE_Price) { |
|
| 2089 | + if ( ! $price instanceof EE_Price) { |
|
| 2090 | 2090 | continue; |
| 2091 | 2091 | } |
| 2092 | 2092 | if ($price->is_base_price()) { |
@@ -2099,8 +2099,8 @@ discard block |
||
| 2099 | 2099 | $price_row++; |
| 2100 | 2100 | continue; |
| 2101 | 2101 | } |
| 2102 | - $show_trash = !((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1); |
|
| 2103 | - $show_create = !(count($default_prices) > 1 && count($default_prices) !== $price_row); |
|
| 2102 | + $show_trash = ! ((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1); |
|
| 2103 | + $show_create = ! (count($default_prices) > 1 && count($default_prices) !== $price_row); |
|
| 2104 | 2104 | $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
| 2105 | 2105 | 'TICKETNUM', |
| 2106 | 2106 | $price_row, |
@@ -2120,7 +2120,7 @@ discard block |
||
| 2120 | 2120 | $this->_is_creating_event |
| 2121 | 2121 | ); |
| 2122 | 2122 | return EEH_Template::display_template( |
| 2123 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2123 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2124 | 2124 | $template_args, |
| 2125 | 2125 | true |
| 2126 | 2126 | ); |
@@ -12,328 +12,328 @@ |
||
| 12 | 12 | class EEM_Ticket extends EEM_Soft_Delete_Base |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * private instance of the EEM_Ticket object |
|
| 17 | - * |
|
| 18 | - * @var EEM_Ticket $_instance |
|
| 19 | - */ |
|
| 20 | - protected static $_instance; |
|
| 15 | + /** |
|
| 16 | + * private instance of the EEM_Ticket object |
|
| 17 | + * |
|
| 18 | + * @var EEM_Ticket $_instance |
|
| 19 | + */ |
|
| 20 | + protected static $_instance; |
|
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * private constructor to prevent direct creation |
|
| 26 | - * |
|
| 27 | - * @Constructor |
|
| 28 | - * @access private |
|
| 29 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
| 30 | - * (and any incoming timezone data that gets saved). |
|
| 31 | - * Note this just sends the timezone info to the date time model field objects. |
|
| 32 | - * Default is NULL |
|
| 33 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
| 34 | - * @throws EE_Error |
|
| 35 | - */ |
|
| 36 | - protected function __construct($timezone) |
|
| 37 | - { |
|
| 38 | - $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
| 39 | - $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
| 40 | - $this->_tables = array( |
|
| 41 | - 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
| 42 | - ); |
|
| 43 | - $this->_fields = array( |
|
| 44 | - 'Ticket' => array( |
|
| 45 | - 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
| 46 | - 'TKT_ID', |
|
| 47 | - esc_html__('Ticket ID', 'event_espresso') |
|
| 48 | - ), |
|
| 49 | - 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
| 50 | - 'TTM_ID', |
|
| 51 | - esc_html__('Ticket Template ID', 'event_espresso'), |
|
| 52 | - false, |
|
| 53 | - 0, |
|
| 54 | - 'Ticket_Template' |
|
| 55 | - ), |
|
| 56 | - 'TKT_name' => new EE_Plain_Text_Field( |
|
| 57 | - 'TKT_name', |
|
| 58 | - esc_html__('Ticket Name', 'event_espresso'), |
|
| 59 | - false, |
|
| 60 | - '' |
|
| 61 | - ), |
|
| 62 | - 'TKT_description' => new EE_Post_Content_Field( |
|
| 63 | - 'TKT_description', |
|
| 64 | - esc_html__('Description of Ticket', 'event_espresso'), |
|
| 65 | - false, |
|
| 66 | - '' |
|
| 67 | - ), |
|
| 68 | - 'TKT_start_date' => new EE_Datetime_Field( |
|
| 69 | - 'TKT_start_date', |
|
| 70 | - esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
| 71 | - false, |
|
| 72 | - EE_Datetime_Field::now, |
|
| 73 | - $timezone |
|
| 74 | - ), |
|
| 75 | - 'TKT_end_date' => new EE_Datetime_Field( |
|
| 76 | - 'TKT_end_date', |
|
| 77 | - esc_html__('End time/date of Ticket', 'event_espresso'), |
|
| 78 | - false, |
|
| 79 | - EE_Datetime_Field::now, |
|
| 80 | - $timezone |
|
| 81 | - ), |
|
| 82 | - 'TKT_min' => new EE_Integer_Field( |
|
| 83 | - 'TKT_min', |
|
| 84 | - esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
| 85 | - false, |
|
| 86 | - 0 |
|
| 87 | - ), |
|
| 88 | - 'TKT_max' => new EE_Infinite_Integer_Field( |
|
| 89 | - 'TKT_max', |
|
| 90 | - esc_html__( |
|
| 91 | - 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
| 92 | - 'event_espresso' |
|
| 93 | - ), |
|
| 94 | - false, |
|
| 95 | - EE_INF |
|
| 96 | - ), |
|
| 97 | - 'TKT_price' => new EE_Money_Field( |
|
| 98 | - 'TKT_price', |
|
| 99 | - esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
| 100 | - false, |
|
| 101 | - 0 |
|
| 102 | - ), |
|
| 103 | - 'TKT_sold' => new EE_Integer_Field( |
|
| 104 | - 'TKT_sold', |
|
| 105 | - esc_html__('Number of this ticket sold', 'event_espresso'), |
|
| 106 | - false, |
|
| 107 | - 0 |
|
| 108 | - ), |
|
| 109 | - 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
| 110 | - 'TKT_qty', |
|
| 111 | - esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
| 112 | - false, |
|
| 113 | - EE_INF |
|
| 114 | - ), |
|
| 115 | - 'TKT_reserved' => new EE_Integer_Field( |
|
| 116 | - 'TKT_reserved', |
|
| 117 | - esc_html__( |
|
| 118 | - 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
| 119 | - 'event_espresso' |
|
| 120 | - ), |
|
| 121 | - false, |
|
| 122 | - 0 |
|
| 123 | - ), |
|
| 124 | - 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
| 125 | - 'TKT_uses', |
|
| 126 | - esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
| 127 | - false, |
|
| 128 | - EE_INF |
|
| 129 | - ), |
|
| 130 | - 'TKT_required' => new EE_Boolean_Field( |
|
| 131 | - 'TKT_required', |
|
| 132 | - esc_html__( |
|
| 133 | - 'Flag indicating whether this ticket must be purchased with a transaction', |
|
| 134 | - 'event_espresso' |
|
| 135 | - ), |
|
| 136 | - false, |
|
| 137 | - false |
|
| 138 | - ), |
|
| 139 | - 'TKT_taxable' => new EE_Boolean_Field( |
|
| 140 | - 'TKT_taxable', |
|
| 141 | - esc_html__( |
|
| 142 | - 'Flag indicating whether there is tax applied on this ticket', |
|
| 143 | - 'event_espresso' |
|
| 144 | - ), |
|
| 145 | - false, |
|
| 146 | - false |
|
| 147 | - ), |
|
| 148 | - 'TKT_is_default' => new EE_Boolean_Field( |
|
| 149 | - 'TKT_is_default', |
|
| 150 | - esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
| 151 | - false, |
|
| 152 | - false |
|
| 153 | - ), |
|
| 154 | - 'TKT_order' => new EE_Integer_Field( |
|
| 155 | - 'TKT_order', |
|
| 156 | - esc_html__( |
|
| 157 | - 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
| 158 | - 'event_espresso' |
|
| 159 | - ), |
|
| 160 | - false, |
|
| 161 | - 0 |
|
| 162 | - ), |
|
| 163 | - 'TKT_row' => new EE_Integer_Field( |
|
| 164 | - 'TKT_row', |
|
| 165 | - esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
| 166 | - false, |
|
| 167 | - 0 |
|
| 168 | - ), |
|
| 169 | - 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
| 170 | - 'TKT_deleted', |
|
| 171 | - esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
| 172 | - false, |
|
| 173 | - false |
|
| 174 | - ), |
|
| 175 | - 'TKT_wp_user' => new EE_WP_User_Field( |
|
| 176 | - 'TKT_wp_user', |
|
| 177 | - esc_html__('Ticket Creator ID', 'event_espresso'), |
|
| 178 | - false |
|
| 179 | - ), |
|
| 180 | - 'TKT_parent' => new EE_Integer_Field( |
|
| 181 | - 'TKT_parent', |
|
| 182 | - esc_html__( |
|
| 183 | - 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
| 184 | - 'event_espresso' |
|
| 185 | - ), |
|
| 186 | - true, |
|
| 187 | - 0 |
|
| 188 | - ), |
|
| 189 | - ), |
|
| 190 | - ); |
|
| 191 | - $this->_model_relations = array( |
|
| 192 | - 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
| 193 | - 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
| 194 | - 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
| 195 | - 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
| 196 | - 'Registration' => new EE_Has_Many_Relation(), |
|
| 197 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 198 | - ); |
|
| 199 | - //this model is generally available for reading |
|
| 200 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public( |
|
| 201 | - 'TKT_is_default', |
|
| 202 | - 'Datetime.Event' |
|
| 203 | - ); |
|
| 204 | - //account for default tickets in the caps |
|
| 205 | - $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected( |
|
| 206 | - 'TKT_is_default', |
|
| 207 | - 'Datetime.Event' |
|
| 208 | - ); |
|
| 209 | - $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected( |
|
| 210 | - 'TKT_is_default', |
|
| 211 | - 'Datetime.Event' |
|
| 212 | - ); |
|
| 213 | - $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected( |
|
| 214 | - 'TKT_is_default', |
|
| 215 | - 'Datetime.Event' |
|
| 216 | - ); |
|
| 217 | - parent::__construct($timezone); |
|
| 218 | - } |
|
| 24 | + /** |
|
| 25 | + * private constructor to prevent direct creation |
|
| 26 | + * |
|
| 27 | + * @Constructor |
|
| 28 | + * @access private |
|
| 29 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
| 30 | + * (and any incoming timezone data that gets saved). |
|
| 31 | + * Note this just sends the timezone info to the date time model field objects. |
|
| 32 | + * Default is NULL |
|
| 33 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
| 34 | + * @throws EE_Error |
|
| 35 | + */ |
|
| 36 | + protected function __construct($timezone) |
|
| 37 | + { |
|
| 38 | + $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
| 39 | + $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
| 40 | + $this->_tables = array( |
|
| 41 | + 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
| 42 | + ); |
|
| 43 | + $this->_fields = array( |
|
| 44 | + 'Ticket' => array( |
|
| 45 | + 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
| 46 | + 'TKT_ID', |
|
| 47 | + esc_html__('Ticket ID', 'event_espresso') |
|
| 48 | + ), |
|
| 49 | + 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
| 50 | + 'TTM_ID', |
|
| 51 | + esc_html__('Ticket Template ID', 'event_espresso'), |
|
| 52 | + false, |
|
| 53 | + 0, |
|
| 54 | + 'Ticket_Template' |
|
| 55 | + ), |
|
| 56 | + 'TKT_name' => new EE_Plain_Text_Field( |
|
| 57 | + 'TKT_name', |
|
| 58 | + esc_html__('Ticket Name', 'event_espresso'), |
|
| 59 | + false, |
|
| 60 | + '' |
|
| 61 | + ), |
|
| 62 | + 'TKT_description' => new EE_Post_Content_Field( |
|
| 63 | + 'TKT_description', |
|
| 64 | + esc_html__('Description of Ticket', 'event_espresso'), |
|
| 65 | + false, |
|
| 66 | + '' |
|
| 67 | + ), |
|
| 68 | + 'TKT_start_date' => new EE_Datetime_Field( |
|
| 69 | + 'TKT_start_date', |
|
| 70 | + esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
| 71 | + false, |
|
| 72 | + EE_Datetime_Field::now, |
|
| 73 | + $timezone |
|
| 74 | + ), |
|
| 75 | + 'TKT_end_date' => new EE_Datetime_Field( |
|
| 76 | + 'TKT_end_date', |
|
| 77 | + esc_html__('End time/date of Ticket', 'event_espresso'), |
|
| 78 | + false, |
|
| 79 | + EE_Datetime_Field::now, |
|
| 80 | + $timezone |
|
| 81 | + ), |
|
| 82 | + 'TKT_min' => new EE_Integer_Field( |
|
| 83 | + 'TKT_min', |
|
| 84 | + esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
| 85 | + false, |
|
| 86 | + 0 |
|
| 87 | + ), |
|
| 88 | + 'TKT_max' => new EE_Infinite_Integer_Field( |
|
| 89 | + 'TKT_max', |
|
| 90 | + esc_html__( |
|
| 91 | + 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
| 92 | + 'event_espresso' |
|
| 93 | + ), |
|
| 94 | + false, |
|
| 95 | + EE_INF |
|
| 96 | + ), |
|
| 97 | + 'TKT_price' => new EE_Money_Field( |
|
| 98 | + 'TKT_price', |
|
| 99 | + esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
| 100 | + false, |
|
| 101 | + 0 |
|
| 102 | + ), |
|
| 103 | + 'TKT_sold' => new EE_Integer_Field( |
|
| 104 | + 'TKT_sold', |
|
| 105 | + esc_html__('Number of this ticket sold', 'event_espresso'), |
|
| 106 | + false, |
|
| 107 | + 0 |
|
| 108 | + ), |
|
| 109 | + 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
| 110 | + 'TKT_qty', |
|
| 111 | + esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
| 112 | + false, |
|
| 113 | + EE_INF |
|
| 114 | + ), |
|
| 115 | + 'TKT_reserved' => new EE_Integer_Field( |
|
| 116 | + 'TKT_reserved', |
|
| 117 | + esc_html__( |
|
| 118 | + 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
| 119 | + 'event_espresso' |
|
| 120 | + ), |
|
| 121 | + false, |
|
| 122 | + 0 |
|
| 123 | + ), |
|
| 124 | + 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
| 125 | + 'TKT_uses', |
|
| 126 | + esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
| 127 | + false, |
|
| 128 | + EE_INF |
|
| 129 | + ), |
|
| 130 | + 'TKT_required' => new EE_Boolean_Field( |
|
| 131 | + 'TKT_required', |
|
| 132 | + esc_html__( |
|
| 133 | + 'Flag indicating whether this ticket must be purchased with a transaction', |
|
| 134 | + 'event_espresso' |
|
| 135 | + ), |
|
| 136 | + false, |
|
| 137 | + false |
|
| 138 | + ), |
|
| 139 | + 'TKT_taxable' => new EE_Boolean_Field( |
|
| 140 | + 'TKT_taxable', |
|
| 141 | + esc_html__( |
|
| 142 | + 'Flag indicating whether there is tax applied on this ticket', |
|
| 143 | + 'event_espresso' |
|
| 144 | + ), |
|
| 145 | + false, |
|
| 146 | + false |
|
| 147 | + ), |
|
| 148 | + 'TKT_is_default' => new EE_Boolean_Field( |
|
| 149 | + 'TKT_is_default', |
|
| 150 | + esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
| 151 | + false, |
|
| 152 | + false |
|
| 153 | + ), |
|
| 154 | + 'TKT_order' => new EE_Integer_Field( |
|
| 155 | + 'TKT_order', |
|
| 156 | + esc_html__( |
|
| 157 | + 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
| 158 | + 'event_espresso' |
|
| 159 | + ), |
|
| 160 | + false, |
|
| 161 | + 0 |
|
| 162 | + ), |
|
| 163 | + 'TKT_row' => new EE_Integer_Field( |
|
| 164 | + 'TKT_row', |
|
| 165 | + esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
| 166 | + false, |
|
| 167 | + 0 |
|
| 168 | + ), |
|
| 169 | + 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
| 170 | + 'TKT_deleted', |
|
| 171 | + esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
| 172 | + false, |
|
| 173 | + false |
|
| 174 | + ), |
|
| 175 | + 'TKT_wp_user' => new EE_WP_User_Field( |
|
| 176 | + 'TKT_wp_user', |
|
| 177 | + esc_html__('Ticket Creator ID', 'event_espresso'), |
|
| 178 | + false |
|
| 179 | + ), |
|
| 180 | + 'TKT_parent' => new EE_Integer_Field( |
|
| 181 | + 'TKT_parent', |
|
| 182 | + esc_html__( |
|
| 183 | + 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
| 184 | + 'event_espresso' |
|
| 185 | + ), |
|
| 186 | + true, |
|
| 187 | + 0 |
|
| 188 | + ), |
|
| 189 | + ), |
|
| 190 | + ); |
|
| 191 | + $this->_model_relations = array( |
|
| 192 | + 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
| 193 | + 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
| 194 | + 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
| 195 | + 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
| 196 | + 'Registration' => new EE_Has_Many_Relation(), |
|
| 197 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 198 | + ); |
|
| 199 | + //this model is generally available for reading |
|
| 200 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public( |
|
| 201 | + 'TKT_is_default', |
|
| 202 | + 'Datetime.Event' |
|
| 203 | + ); |
|
| 204 | + //account for default tickets in the caps |
|
| 205 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected( |
|
| 206 | + 'TKT_is_default', |
|
| 207 | + 'Datetime.Event' |
|
| 208 | + ); |
|
| 209 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected( |
|
| 210 | + 'TKT_is_default', |
|
| 211 | + 'Datetime.Event' |
|
| 212 | + ); |
|
| 213 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected( |
|
| 214 | + 'TKT_is_default', |
|
| 215 | + 'Datetime.Event' |
|
| 216 | + ); |
|
| 217 | + parent::__construct($timezone); |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | 220 | |
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * This returns all tickets that are defaults from the db |
|
| 224 | - * |
|
| 225 | - * @return EE_Ticket[] |
|
| 226 | - * @throws EE_Error |
|
| 227 | - */ |
|
| 228 | - public function get_all_default_tickets() |
|
| 229 | - { |
|
| 230 | - /** @type EE_Ticket[] $tickets */ |
|
| 231 | - $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC'))); |
|
| 232 | - //we need to set the start date and end date to today's date and the start of the default dtt |
|
| 233 | - return $this->_set_default_dates($tickets); |
|
| 234 | - } |
|
| 222 | + /** |
|
| 223 | + * This returns all tickets that are defaults from the db |
|
| 224 | + * |
|
| 225 | + * @return EE_Ticket[] |
|
| 226 | + * @throws EE_Error |
|
| 227 | + */ |
|
| 228 | + public function get_all_default_tickets() |
|
| 229 | + { |
|
| 230 | + /** @type EE_Ticket[] $tickets */ |
|
| 231 | + $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC'))); |
|
| 232 | + //we need to set the start date and end date to today's date and the start of the default dtt |
|
| 233 | + return $this->_set_default_dates($tickets); |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | 236 | |
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * sets up relevant start and end date for EE_Ticket (s) |
|
| 240 | - * |
|
| 241 | - * @param EE_Ticket[] $tickets |
|
| 242 | - * @return EE_Ticket[] |
|
| 243 | - * @throws EE_Error |
|
| 244 | - */ |
|
| 245 | - private function _set_default_dates($tickets) |
|
| 246 | - { |
|
| 247 | - foreach ($tickets as $ticket) { |
|
| 248 | - $ticket->set( |
|
| 249 | - 'TKT_start_date', |
|
| 250 | - (int)$this->current_time_for_query('TKT_start_date', true) |
|
| 251 | - ); |
|
| 252 | - $ticket->set( |
|
| 253 | - 'TKT_end_date', |
|
| 254 | - (int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
| 255 | - ); |
|
| 256 | - $ticket->set_end_time( |
|
| 257 | - $this->convert_datetime_for_query( |
|
| 258 | - 'TKT_end_date', |
|
| 259 | - '11:59 pm', |
|
| 260 | - 'g:i a', $this->_timezone |
|
| 261 | - ) |
|
| 262 | - ); |
|
| 263 | - } |
|
| 264 | - return $tickets; |
|
| 265 | - } |
|
| 238 | + /** |
|
| 239 | + * sets up relevant start and end date for EE_Ticket (s) |
|
| 240 | + * |
|
| 241 | + * @param EE_Ticket[] $tickets |
|
| 242 | + * @return EE_Ticket[] |
|
| 243 | + * @throws EE_Error |
|
| 244 | + */ |
|
| 245 | + private function _set_default_dates($tickets) |
|
| 246 | + { |
|
| 247 | + foreach ($tickets as $ticket) { |
|
| 248 | + $ticket->set( |
|
| 249 | + 'TKT_start_date', |
|
| 250 | + (int)$this->current_time_for_query('TKT_start_date', true) |
|
| 251 | + ); |
|
| 252 | + $ticket->set( |
|
| 253 | + 'TKT_end_date', |
|
| 254 | + (int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
| 255 | + ); |
|
| 256 | + $ticket->set_end_time( |
|
| 257 | + $this->convert_datetime_for_query( |
|
| 258 | + 'TKT_end_date', |
|
| 259 | + '11:59 pm', |
|
| 260 | + 'g:i a', $this->_timezone |
|
| 261 | + ) |
|
| 262 | + ); |
|
| 263 | + } |
|
| 264 | + return $tickets; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | 267 | |
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * Gets the total number of tickets available at a particular datetime (does |
|
| 271 | - * NOT take int account the datetime's spaces available) |
|
| 272 | - * |
|
| 273 | - * @param int $DTT_ID |
|
| 274 | - * @param array $query_params |
|
| 275 | - * @return int |
|
| 276 | - */ |
|
| 277 | - public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
| 278 | - { |
|
| 279 | - return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
| 280 | - } |
|
| 269 | + /** |
|
| 270 | + * Gets the total number of tickets available at a particular datetime (does |
|
| 271 | + * NOT take int account the datetime's spaces available) |
|
| 272 | + * |
|
| 273 | + * @param int $DTT_ID |
|
| 274 | + * @param array $query_params |
|
| 275 | + * @return int |
|
| 276 | + */ |
|
| 277 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
| 278 | + { |
|
| 279 | + return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | 282 | |
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
| 286 | - * |
|
| 287 | - * @param EE_Ticket[] $tickets |
|
| 288 | - * @return void |
|
| 289 | - * @throws EE_Error |
|
| 290 | - */ |
|
| 291 | - public function update_tickets_sold($tickets) |
|
| 292 | - { |
|
| 293 | - foreach ($tickets as $ticket) { |
|
| 294 | - /* @var $ticket EE_Ticket */ |
|
| 295 | - $ticket->update_tickets_sold(); |
|
| 296 | - } |
|
| 297 | - } |
|
| 284 | + /** |
|
| 285 | + * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
| 286 | + * |
|
| 287 | + * @param EE_Ticket[] $tickets |
|
| 288 | + * @return void |
|
| 289 | + * @throws EE_Error |
|
| 290 | + */ |
|
| 291 | + public function update_tickets_sold($tickets) |
|
| 292 | + { |
|
| 293 | + foreach ($tickets as $ticket) { |
|
| 294 | + /* @var $ticket EE_Ticket */ |
|
| 295 | + $ticket->update_tickets_sold(); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | 299 | |
| 300 | 300 | |
| 301 | - /** |
|
| 302 | - * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
| 303 | - * |
|
| 304 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
| 305 | - * @throws EE_Error |
|
| 306 | - */ |
|
| 307 | - public function get_tickets_with_reservations() |
|
| 308 | - { |
|
| 309 | - return $this->get_all( |
|
| 310 | - array( |
|
| 311 | - array( |
|
| 312 | - 'TKT_reserved' => array('>', 0), |
|
| 313 | - ), |
|
| 314 | - ) |
|
| 315 | - ); |
|
| 316 | - } |
|
| 301 | + /** |
|
| 302 | + * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
| 303 | + * |
|
| 304 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
| 305 | + * @throws EE_Error |
|
| 306 | + */ |
|
| 307 | + public function get_tickets_with_reservations() |
|
| 308 | + { |
|
| 309 | + return $this->get_all( |
|
| 310 | + array( |
|
| 311 | + array( |
|
| 312 | + 'TKT_reserved' => array('>', 0), |
|
| 313 | + ), |
|
| 314 | + ) |
|
| 315 | + ); |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | 318 | |
| 319 | 319 | |
| 320 | - /** |
|
| 321 | - * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
| 322 | - * |
|
| 323 | - * @param array $ticket_IDs |
|
| 324 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
| 325 | - * @throws EE_Error |
|
| 326 | - */ |
|
| 327 | - public function get_tickets_with_IDs(array $ticket_IDs) |
|
| 328 | - { |
|
| 329 | - return $this->get_all( |
|
| 330 | - array( |
|
| 331 | - array( |
|
| 332 | - 'TKT_ID' => array('IN', $ticket_IDs) |
|
| 333 | - ) |
|
| 334 | - ) |
|
| 335 | - ); |
|
| 336 | - } |
|
| 320 | + /** |
|
| 321 | + * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
| 322 | + * |
|
| 323 | + * @param array $ticket_IDs |
|
| 324 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
| 325 | + * @throws EE_Error |
|
| 326 | + */ |
|
| 327 | + public function get_tickets_with_IDs(array $ticket_IDs) |
|
| 328 | + { |
|
| 329 | + return $this->get_all( |
|
| 330 | + array( |
|
| 331 | + array( |
|
| 332 | + 'TKT_ID' => array('IN', $ticket_IDs) |
|
| 333 | + ) |
|
| 334 | + ) |
|
| 335 | + ); |
|
| 336 | + } |
|
| 337 | 337 | |
| 338 | 338 | |
| 339 | 339 | |
@@ -247,11 +247,11 @@ |
||
| 247 | 247 | foreach ($tickets as $ticket) { |
| 248 | 248 | $ticket->set( |
| 249 | 249 | 'TKT_start_date', |
| 250 | - (int)$this->current_time_for_query('TKT_start_date', true) |
|
| 250 | + (int) $this->current_time_for_query('TKT_start_date', true) |
|
| 251 | 251 | ); |
| 252 | 252 | $ticket->set( |
| 253 | 253 | 'TKT_end_date', |
| 254 | - (int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
| 254 | + (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
| 255 | 255 | ); |
| 256 | 256 | $ticket->set_end_time( |
| 257 | 257 | $this->convert_datetime_for_query( |
@@ -396,7 +396,7 @@ |
||
| 396 | 396 | |
| 397 | 397 | /** |
| 398 | 398 | * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
| 399 | - * @param $string |
|
| 399 | + * @param string $string |
|
| 400 | 400 | * @return bool |
| 401 | 401 | */ |
| 402 | 402 | protected function valid_base_64($string) |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | protected function __construct() |
| 72 | 72 | { |
| 73 | - if (! defined('ESPRESSO_ENCRYPT')) { |
|
| 73 | + if ( ! defined('ESPRESSO_ENCRYPT')) { |
|
| 74 | 74 | define('ESPRESSO_ENCRYPT', true); |
| 75 | 75 | } |
| 76 | 76 | if (extension_loaded('openssl')) { |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | public static function instance() |
| 94 | 94 | { |
| 95 | 95 | // check if class object is instantiated |
| 96 | - if (! self::$_instance instanceof EE_Encryption) { |
|
| 96 | + if ( ! self::$_instance instanceof EE_Encryption) { |
|
| 97 | 97 | self::$_instance = new self(); |
| 98 | 98 | } |
| 99 | 99 | return self::$_instance; |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | $iv |
| 288 | 288 | ); |
| 289 | 289 | // append the initialization vector |
| 290 | - $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv; |
|
| 290 | + $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER.$iv; |
|
| 291 | 291 | // trim and maybe encode |
| 292 | 292 | return $this->_use_base64_encode |
| 293 | 293 | ? trim(base64_encode($encrypted_text)) |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | 2 |
| 320 | 320 | ); |
| 321 | 321 | // check that iv exists, and if not, maybe text was encoded using mcrypt? |
| 322 | - if (! isset($encrypted_components[1]) && $this->_use_mcrypt) { |
|
| 322 | + if ( ! isset($encrypted_components[1]) && $this->_use_mcrypt) { |
|
| 323 | 323 | return $this->m_decrypt($encrypted_text); |
| 324 | 324 | } |
| 325 | 325 | // decrypt it |
@@ -402,16 +402,16 @@ discard block |
||
| 402 | 402 | protected function valid_base_64($string) |
| 403 | 403 | { |
| 404 | 404 | // ensure data is a string |
| 405 | - if (! is_string($string) || ! $this->_use_base64_encode) { |
|
| 405 | + if ( ! is_string($string) || ! $this->_use_base64_encode) { |
|
| 406 | 406 | return false; |
| 407 | 407 | } |
| 408 | 408 | $decoded = base64_decode($string, true); |
| 409 | 409 | // Check if there is no invalid character in string |
| 410 | - if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
| 410 | + if ( ! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
| 411 | 411 | return false; |
| 412 | 412 | } |
| 413 | 413 | // Decode the string in strict mode and send the response |
| 414 | - if (! base64_decode($string, true)) { |
|
| 414 | + if ( ! base64_decode($string, true)) { |
|
| 415 | 415 | return false; |
| 416 | 416 | } |
| 417 | 417 | // Encode and compare it to original one |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | $iterations = ceil($length / 40); |
| 433 | 433 | $random_string = ''; |
| 434 | 434 | for ($i = 0; $i < $iterations; $i++) { |
| 435 | - $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
| 435 | + $random_string .= sha1(microtime(true).mt_rand(10000, 90000)); |
|
| 436 | 436 | } |
| 437 | 437 | $random_string = substr($random_string, 0, $length); |
| 438 | 438 | return $random_string; |
@@ -16,516 +16,516 @@ |
||
| 16 | 16 | class EE_Encryption |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * key used for saving the encryption key to the wp_options table |
|
| 21 | - */ |
|
| 22 | - const ENCRYPTION_OPTION_KEY = 'ee_encryption_key'; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * the OPENSSL cipher method used |
|
| 26 | - */ |
|
| 27 | - const OPENSSL_CIPHER_METHOD = 'aes-256-ctr'; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * the OPENSSL digest method used |
|
| 31 | - */ |
|
| 32 | - const OPENSSL_DIGEST_METHOD = 'sha512'; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * separates the encrypted text from the initialization vector |
|
| 36 | - */ |
|
| 37 | - const OPENSSL_IV_DELIMITER = ':iv:'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * appended to text encrypted using the acme encryption |
|
| 41 | - */ |
|
| 42 | - const ACME_ENCRYPTION_FLAG = '::ae'; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * instance of the EE_Encryption object |
|
| 48 | - */ |
|
| 49 | - protected static $_instance; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var string $_encryption_key |
|
| 53 | - */ |
|
| 54 | - protected $_encryption_key; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var boolean $_use_openssl_encrypt |
|
| 58 | - */ |
|
| 59 | - protected $_use_openssl_encrypt = false; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var boolean $_use_mcrypt |
|
| 63 | - */ |
|
| 64 | - protected $_use_mcrypt = false; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var boolean $_use_base64_encode |
|
| 68 | - */ |
|
| 69 | - protected $_use_base64_encode = false; |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * protected constructor to prevent direct creation |
|
| 75 | - */ |
|
| 76 | - protected function __construct() |
|
| 77 | - { |
|
| 78 | - if (! defined('ESPRESSO_ENCRYPT')) { |
|
| 79 | - define('ESPRESSO_ENCRYPT', true); |
|
| 80 | - } |
|
| 81 | - if (extension_loaded('openssl')) { |
|
| 82 | - $this->_use_openssl_encrypt = true; |
|
| 83 | - } else if (extension_loaded('mcrypt')) { |
|
| 84 | - $this->_use_mcrypt = true; |
|
| 85 | - } |
|
| 86 | - if (function_exists('base64_encode')) { |
|
| 87 | - $this->_use_base64_encode = true; |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * singleton method used to instantiate class object |
|
| 95 | - * |
|
| 96 | - * @return EE_Encryption |
|
| 97 | - */ |
|
| 98 | - public static function instance() |
|
| 99 | - { |
|
| 100 | - // check if class object is instantiated |
|
| 101 | - if (! self::$_instance instanceof EE_Encryption) { |
|
| 102 | - self::$_instance = new self(); |
|
| 103 | - } |
|
| 104 | - return self::$_instance; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * get encryption key |
|
| 111 | - * |
|
| 112 | - * @return string |
|
| 113 | - */ |
|
| 114 | - public function get_encryption_key() |
|
| 115 | - { |
|
| 116 | - // if encryption key has not been set |
|
| 117 | - if (empty($this->_encryption_key)) { |
|
| 118 | - // retrieve encryption_key from db |
|
| 119 | - $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, ''); |
|
| 120 | - // WHAT?? No encryption_key in the db ?? |
|
| 121 | - if ($this->_encryption_key === '') { |
|
| 122 | - // let's make one. And md5 it to make it just the right size for a key |
|
| 123 | - $new_key = md5($this->generate_random_string()); |
|
| 124 | - // now save it to the db for later |
|
| 125 | - add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key); |
|
| 126 | - // here's the key - FINALLY ! |
|
| 127 | - $this->_encryption_key = $new_key; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - return $this->_encryption_key; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * encrypts data |
|
| 137 | - * |
|
| 138 | - * @param string $text_string - the text to be encrypted |
|
| 139 | - * @return string |
|
| 140 | - * @throws RuntimeException |
|
| 141 | - */ |
|
| 142 | - public function encrypt($text_string = '') |
|
| 143 | - { |
|
| 144 | - // you give me nothing??? GET OUT ! |
|
| 145 | - if (empty($text_string)) { |
|
| 146 | - return $text_string; |
|
| 147 | - } |
|
| 148 | - if ($this->_use_openssl_encrypt) { |
|
| 149 | - $encrypted_text = $this->openssl_encrypt($text_string); |
|
| 150 | - } else { |
|
| 151 | - $encrypted_text = $this->acme_encrypt($text_string); |
|
| 152 | - } |
|
| 153 | - return $encrypted_text; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * decrypts data |
|
| 160 | - * |
|
| 161 | - * @param string $encrypted_text - the text to be decrypted |
|
| 162 | - * @return string |
|
| 163 | - * @throws RuntimeException |
|
| 164 | - */ |
|
| 165 | - public function decrypt($encrypted_text = '') |
|
| 166 | - { |
|
| 167 | - // you give me nothing??? GET OUT ! |
|
| 168 | - if (empty($encrypted_text)) { |
|
| 169 | - return $encrypted_text; |
|
| 170 | - } |
|
| 171 | - // if PHP's mcrypt functions are installed then we'll use them |
|
| 172 | - if ($this->_use_openssl_encrypt) { |
|
| 173 | - $decrypted_text = $this->openssl_decrypt($encrypted_text); |
|
| 174 | - } else { |
|
| 175 | - $decrypted_text = $this->acme_decrypt($encrypted_text); |
|
| 176 | - } |
|
| 177 | - return $decrypted_text; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * encodes string with PHP's base64 encoding |
|
| 184 | - * |
|
| 185 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
| 186 | - * @param string $text_string the text to be encoded |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public function base64_string_encode($text_string = '') |
|
| 190 | - { |
|
| 191 | - // you give me nothing??? GET OUT ! |
|
| 192 | - if (empty($text_string) || ! $this->_use_base64_encode) { |
|
| 193 | - return $text_string; |
|
| 194 | - } |
|
| 195 | - // encode |
|
| 196 | - return base64_encode($text_string); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * decodes string that has been encoded with PHP's base64 encoding |
|
| 203 | - * |
|
| 204 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
| 205 | - * @param string $encoded_string the text to be decoded |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function base64_string_decode($encoded_string = '') |
|
| 209 | - { |
|
| 210 | - // you give me nothing??? GET OUT ! |
|
| 211 | - if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
| 212 | - return $encoded_string; |
|
| 213 | - } |
|
| 214 | - // decode |
|
| 215 | - return base64_decode($encoded_string); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * encodes url string with PHP's base64 encoding |
|
| 222 | - * |
|
| 223 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
| 224 | - * @param string $text_string the text to be encoded |
|
| 225 | - * @return string |
|
| 226 | - */ |
|
| 227 | - public function base64_url_encode($text_string = '') |
|
| 228 | - { |
|
| 229 | - // you give me nothing??? GET OUT ! |
|
| 230 | - if (empty($text_string) || ! $this->_use_base64_encode) { |
|
| 231 | - return $text_string; |
|
| 232 | - } |
|
| 233 | - // encode |
|
| 234 | - $encoded_string = base64_encode($text_string); |
|
| 235 | - // remove chars to make encoding more URL friendly |
|
| 236 | - return strtr($encoded_string, '+/=', '-_,'); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * decodes url string that has been encoded with PHP's base64 encoding |
|
| 243 | - * |
|
| 244 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
| 245 | - * @param string $encoded_string the text to be decoded |
|
| 246 | - * @return string |
|
| 247 | - */ |
|
| 248 | - public function base64_url_decode($encoded_string = '') |
|
| 249 | - { |
|
| 250 | - // you give me nothing??? GET OUT ! |
|
| 251 | - if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
| 252 | - return $encoded_string; |
|
| 253 | - } |
|
| 254 | - // replace previously removed characters |
|
| 255 | - $encoded_string = strtr($encoded_string, '-_,', '+/='); |
|
| 256 | - // decode |
|
| 257 | - return base64_decode($encoded_string); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * encrypts data using PHP's openssl functions |
|
| 264 | - * |
|
| 265 | - * @param string $text_string the text to be encrypted |
|
| 266 | - * @return string |
|
| 267 | - * @throws RuntimeException |
|
| 268 | - */ |
|
| 269 | - protected function openssl_encrypt($text_string = '') |
|
| 270 | - { |
|
| 271 | - // you give me nothing??? GET OUT ! |
|
| 272 | - if (empty($text_string)) { |
|
| 273 | - return $text_string; |
|
| 274 | - } |
|
| 275 | - // get initialization vector size |
|
| 276 | - $iv_size = openssl_cipher_iv_length(EE_Encryption::OPENSSL_CIPHER_METHOD); |
|
| 277 | - // generate initialization vector |
|
| 278 | - $iv = openssl_random_pseudo_bytes($iv_size, $is_strong); |
|
| 279 | - if ($iv === false || $is_strong === false) { |
|
| 280 | - throw new RuntimeException( |
|
| 281 | - esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso') |
|
| 282 | - ); |
|
| 283 | - } |
|
| 284 | - // encrypt it |
|
| 285 | - $encrypted_text = openssl_encrypt( |
|
| 286 | - $text_string, |
|
| 287 | - EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
| 288 | - openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD), |
|
| 289 | - 0, |
|
| 290 | - $iv |
|
| 291 | - ); |
|
| 292 | - // append the initialization vector |
|
| 293 | - $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv; |
|
| 294 | - // trim and maybe encode |
|
| 295 | - return $this->_use_base64_encode |
|
| 296 | - ? trim(base64_encode($encrypted_text)) |
|
| 297 | - : trim($encrypted_text); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * decrypts data that has been encrypted with PHP's openssl functions |
|
| 304 | - * |
|
| 305 | - * @param string $encrypted_text the text to be decrypted |
|
| 306 | - * @return string |
|
| 307 | - * @throws RuntimeException |
|
| 308 | - */ |
|
| 309 | - protected function openssl_decrypt($encrypted_text = '') |
|
| 310 | - { |
|
| 311 | - // you give me nothing??? GET OUT ! |
|
| 312 | - if (empty($encrypted_text)) { |
|
| 313 | - return $encrypted_text; |
|
| 314 | - } |
|
| 315 | - // decode |
|
| 316 | - $encrypted_text = $this->valid_base_64($encrypted_text) |
|
| 317 | - ? base64_decode($encrypted_text) |
|
| 318 | - : $encrypted_text; |
|
| 319 | - $encrypted_components = explode( |
|
| 320 | - EE_Encryption::OPENSSL_IV_DELIMITER, |
|
| 321 | - $encrypted_text, |
|
| 322 | - 2 |
|
| 323 | - ); |
|
| 324 | - // check that iv exists, and if not, maybe text was encoded using mcrypt? |
|
| 325 | - if (! isset($encrypted_components[1]) && $this->_use_mcrypt) { |
|
| 326 | - return $this->m_decrypt($encrypted_text); |
|
| 327 | - } |
|
| 328 | - // decrypt it |
|
| 329 | - $decrypted_text = openssl_decrypt( |
|
| 330 | - $encrypted_components[0], |
|
| 331 | - EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
| 332 | - openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD), |
|
| 333 | - 0, |
|
| 334 | - $encrypted_components[1] |
|
| 335 | - ); |
|
| 336 | - $decrypted_text = trim($decrypted_text); |
|
| 337 | - return $decrypted_text; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * encrypts data for acme servers that didn't bother to install PHP mcrypt |
|
| 344 | - * |
|
| 345 | - * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
| 346 | - * @param string $text_string the text to be decrypted |
|
| 347 | - * @return string |
|
| 348 | - */ |
|
| 349 | - protected function acme_encrypt($text_string = '') |
|
| 350 | - { |
|
| 351 | - // you give me nothing??? GET OUT ! |
|
| 352 | - if (empty($text_string)) { |
|
| 353 | - return $text_string; |
|
| 354 | - } |
|
| 355 | - $key_bits = str_split( |
|
| 356 | - str_pad('', strlen($text_string), $this->get_encryption_key(), STR_PAD_RIGHT) |
|
| 357 | - ); |
|
| 358 | - $string_bits = str_split($text_string); |
|
| 359 | - foreach ($string_bits as $k => $v) { |
|
| 360 | - $temp = ord($v) + ord($key_bits[$k]); |
|
| 361 | - $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
| 362 | - } |
|
| 363 | - $encrypted_text = implode('', $string_bits); |
|
| 364 | - $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG; |
|
| 365 | - return $this->_use_base64_encode |
|
| 366 | - ? base64_encode($encrypted_text) |
|
| 367 | - : $encrypted_text; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * decrypts data for acme servers that didn't bother to install PHP mcrypt |
|
| 374 | - * |
|
| 375 | - * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
| 376 | - * @param string $encrypted_text the text to be decrypted |
|
| 377 | - * @return string |
|
| 378 | - */ |
|
| 379 | - protected function acme_decrypt($encrypted_text = '') |
|
| 380 | - { |
|
| 381 | - // you give me nothing??? GET OUT ! |
|
| 382 | - if (empty($encrypted_text)) { |
|
| 383 | - return $encrypted_text; |
|
| 384 | - } |
|
| 385 | - // decode the data ? |
|
| 386 | - $encrypted_text = $this->valid_base_64($encrypted_text) |
|
| 387 | - ? base64_decode($encrypted_text) |
|
| 388 | - : $encrypted_text; |
|
| 389 | - if (strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false && $this->_use_mcrypt) { |
|
| 390 | - return $this->m_decrypt($encrypted_text); |
|
| 391 | - } |
|
| 392 | - $encrypted_text = substr($encrypted_text, 0, -4); |
|
| 393 | - $key_bits = str_split( |
|
| 394 | - str_pad('', strlen($encrypted_text), $this->get_encryption_key(), STR_PAD_RIGHT) |
|
| 395 | - ); |
|
| 396 | - $string_bits = str_split($encrypted_text); |
|
| 397 | - foreach ($string_bits as $k => $v) { |
|
| 398 | - $temp = ord($v) - ord($key_bits[$k]); |
|
| 399 | - $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
| 400 | - } |
|
| 401 | - return implode('', $string_bits); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
|
| 408 | - * @param $string |
|
| 409 | - * @return bool |
|
| 410 | - */ |
|
| 411 | - protected function valid_base_64($string) |
|
| 412 | - { |
|
| 413 | - // ensure data is a string |
|
| 414 | - if (! is_string($string) || ! $this->_use_base64_encode) { |
|
| 415 | - return false; |
|
| 416 | - } |
|
| 417 | - $decoded = base64_decode($string, true); |
|
| 418 | - // Check if there is no invalid character in string |
|
| 419 | - if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
| 420 | - return false; |
|
| 421 | - } |
|
| 422 | - // Decode the string in strict mode and send the response |
|
| 423 | - if (! base64_decode($string, true)) { |
|
| 424 | - return false; |
|
| 425 | - } |
|
| 426 | - // Encode and compare it to original one |
|
| 427 | - return base64_encode($decoded) === $string; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * generate random string |
|
| 434 | - * |
|
| 435 | - * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
|
| 436 | - * @param int $length number of characters for random string |
|
| 437 | - * @return string |
|
| 438 | - */ |
|
| 439 | - public function generate_random_string($length = 40) |
|
| 440 | - { |
|
| 441 | - $iterations = ceil($length / 40); |
|
| 442 | - $random_string = ''; |
|
| 443 | - for ($i = 0; $i < $iterations; $i++) { |
|
| 444 | - $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
| 445 | - } |
|
| 446 | - $random_string = substr($random_string, 0, $length); |
|
| 447 | - return $random_string; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * encrypts data using PHP's mcrypt functions |
|
| 454 | - * |
|
| 455 | - * @deprecated 4.9.39 |
|
| 456 | - * @param string $text_string |
|
| 457 | - * @internal param $string - the text to be encrypted |
|
| 458 | - * @return string |
|
| 459 | - * @throws RuntimeException |
|
| 460 | - */ |
|
| 461 | - protected function m_encrypt($text_string = '') |
|
| 462 | - { |
|
| 463 | - // you give me nothing??? GET OUT ! |
|
| 464 | - if (empty($text_string)) { |
|
| 465 | - return $text_string; |
|
| 466 | - } |
|
| 467 | - // get the initialization vector size |
|
| 468 | - $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
| 469 | - // initialization vector |
|
| 470 | - $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
| 471 | - if ($iv === false) { |
|
| 472 | - throw new RuntimeException( |
|
| 473 | - esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
| 474 | - ); |
|
| 475 | - } |
|
| 476 | - // encrypt it |
|
| 477 | - $encrypted_text = mcrypt_encrypt( |
|
| 478 | - MCRYPT_RIJNDAEL_256, |
|
| 479 | - $this->get_encryption_key(), |
|
| 480 | - $text_string, |
|
| 481 | - MCRYPT_MODE_ECB, |
|
| 482 | - $iv |
|
| 483 | - ); |
|
| 484 | - // trim and maybe encode |
|
| 485 | - return $this->_use_base64_encode |
|
| 486 | - ? trim(base64_encode($encrypted_text)) |
|
| 487 | - : trim($encrypted_text); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * decrypts data that has been encrypted with PHP's mcrypt functions |
|
| 494 | - * |
|
| 495 | - * @deprecated 4.9.39 |
|
| 496 | - * @param string $encrypted_text the text to be decrypted |
|
| 497 | - * @return string |
|
| 498 | - * @throws RuntimeException |
|
| 499 | - */ |
|
| 500 | - protected function m_decrypt($encrypted_text = '') |
|
| 501 | - { |
|
| 502 | - // you give me nothing??? GET OUT ! |
|
| 503 | - if (empty($encrypted_text)) { |
|
| 504 | - return $encrypted_text; |
|
| 505 | - } |
|
| 506 | - // decode |
|
| 507 | - $encrypted_text = $this->valid_base_64($encrypted_text) |
|
| 508 | - ? base64_decode($encrypted_text) |
|
| 509 | - : $encrypted_text; |
|
| 510 | - // get the initialization vector size |
|
| 511 | - $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
| 512 | - $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
| 513 | - if ($iv === false) { |
|
| 514 | - throw new RuntimeException( |
|
| 515 | - esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
| 516 | - ); |
|
| 517 | - } |
|
| 518 | - // decrypt it |
|
| 519 | - $decrypted_text = mcrypt_decrypt( |
|
| 520 | - MCRYPT_RIJNDAEL_256, |
|
| 521 | - $this->get_encryption_key(), |
|
| 522 | - $encrypted_text, |
|
| 523 | - MCRYPT_MODE_ECB, |
|
| 524 | - $iv |
|
| 525 | - ); |
|
| 526 | - $decrypted_text = trim($decrypted_text); |
|
| 527 | - return $decrypted_text; |
|
| 528 | - } |
|
| 19 | + /** |
|
| 20 | + * key used for saving the encryption key to the wp_options table |
|
| 21 | + */ |
|
| 22 | + const ENCRYPTION_OPTION_KEY = 'ee_encryption_key'; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * the OPENSSL cipher method used |
|
| 26 | + */ |
|
| 27 | + const OPENSSL_CIPHER_METHOD = 'aes-256-ctr'; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * the OPENSSL digest method used |
|
| 31 | + */ |
|
| 32 | + const OPENSSL_DIGEST_METHOD = 'sha512'; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * separates the encrypted text from the initialization vector |
|
| 36 | + */ |
|
| 37 | + const OPENSSL_IV_DELIMITER = ':iv:'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * appended to text encrypted using the acme encryption |
|
| 41 | + */ |
|
| 42 | + const ACME_ENCRYPTION_FLAG = '::ae'; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * instance of the EE_Encryption object |
|
| 48 | + */ |
|
| 49 | + protected static $_instance; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var string $_encryption_key |
|
| 53 | + */ |
|
| 54 | + protected $_encryption_key; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var boolean $_use_openssl_encrypt |
|
| 58 | + */ |
|
| 59 | + protected $_use_openssl_encrypt = false; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var boolean $_use_mcrypt |
|
| 63 | + */ |
|
| 64 | + protected $_use_mcrypt = false; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var boolean $_use_base64_encode |
|
| 68 | + */ |
|
| 69 | + protected $_use_base64_encode = false; |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * protected constructor to prevent direct creation |
|
| 75 | + */ |
|
| 76 | + protected function __construct() |
|
| 77 | + { |
|
| 78 | + if (! defined('ESPRESSO_ENCRYPT')) { |
|
| 79 | + define('ESPRESSO_ENCRYPT', true); |
|
| 80 | + } |
|
| 81 | + if (extension_loaded('openssl')) { |
|
| 82 | + $this->_use_openssl_encrypt = true; |
|
| 83 | + } else if (extension_loaded('mcrypt')) { |
|
| 84 | + $this->_use_mcrypt = true; |
|
| 85 | + } |
|
| 86 | + if (function_exists('base64_encode')) { |
|
| 87 | + $this->_use_base64_encode = true; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * singleton method used to instantiate class object |
|
| 95 | + * |
|
| 96 | + * @return EE_Encryption |
|
| 97 | + */ |
|
| 98 | + public static function instance() |
|
| 99 | + { |
|
| 100 | + // check if class object is instantiated |
|
| 101 | + if (! self::$_instance instanceof EE_Encryption) { |
|
| 102 | + self::$_instance = new self(); |
|
| 103 | + } |
|
| 104 | + return self::$_instance; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * get encryption key |
|
| 111 | + * |
|
| 112 | + * @return string |
|
| 113 | + */ |
|
| 114 | + public function get_encryption_key() |
|
| 115 | + { |
|
| 116 | + // if encryption key has not been set |
|
| 117 | + if (empty($this->_encryption_key)) { |
|
| 118 | + // retrieve encryption_key from db |
|
| 119 | + $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, ''); |
|
| 120 | + // WHAT?? No encryption_key in the db ?? |
|
| 121 | + if ($this->_encryption_key === '') { |
|
| 122 | + // let's make one. And md5 it to make it just the right size for a key |
|
| 123 | + $new_key = md5($this->generate_random_string()); |
|
| 124 | + // now save it to the db for later |
|
| 125 | + add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key); |
|
| 126 | + // here's the key - FINALLY ! |
|
| 127 | + $this->_encryption_key = $new_key; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + return $this->_encryption_key; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * encrypts data |
|
| 137 | + * |
|
| 138 | + * @param string $text_string - the text to be encrypted |
|
| 139 | + * @return string |
|
| 140 | + * @throws RuntimeException |
|
| 141 | + */ |
|
| 142 | + public function encrypt($text_string = '') |
|
| 143 | + { |
|
| 144 | + // you give me nothing??? GET OUT ! |
|
| 145 | + if (empty($text_string)) { |
|
| 146 | + return $text_string; |
|
| 147 | + } |
|
| 148 | + if ($this->_use_openssl_encrypt) { |
|
| 149 | + $encrypted_text = $this->openssl_encrypt($text_string); |
|
| 150 | + } else { |
|
| 151 | + $encrypted_text = $this->acme_encrypt($text_string); |
|
| 152 | + } |
|
| 153 | + return $encrypted_text; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * decrypts data |
|
| 160 | + * |
|
| 161 | + * @param string $encrypted_text - the text to be decrypted |
|
| 162 | + * @return string |
|
| 163 | + * @throws RuntimeException |
|
| 164 | + */ |
|
| 165 | + public function decrypt($encrypted_text = '') |
|
| 166 | + { |
|
| 167 | + // you give me nothing??? GET OUT ! |
|
| 168 | + if (empty($encrypted_text)) { |
|
| 169 | + return $encrypted_text; |
|
| 170 | + } |
|
| 171 | + // if PHP's mcrypt functions are installed then we'll use them |
|
| 172 | + if ($this->_use_openssl_encrypt) { |
|
| 173 | + $decrypted_text = $this->openssl_decrypt($encrypted_text); |
|
| 174 | + } else { |
|
| 175 | + $decrypted_text = $this->acme_decrypt($encrypted_text); |
|
| 176 | + } |
|
| 177 | + return $decrypted_text; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * encodes string with PHP's base64 encoding |
|
| 184 | + * |
|
| 185 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
| 186 | + * @param string $text_string the text to be encoded |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public function base64_string_encode($text_string = '') |
|
| 190 | + { |
|
| 191 | + // you give me nothing??? GET OUT ! |
|
| 192 | + if (empty($text_string) || ! $this->_use_base64_encode) { |
|
| 193 | + return $text_string; |
|
| 194 | + } |
|
| 195 | + // encode |
|
| 196 | + return base64_encode($text_string); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * decodes string that has been encoded with PHP's base64 encoding |
|
| 203 | + * |
|
| 204 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
| 205 | + * @param string $encoded_string the text to be decoded |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function base64_string_decode($encoded_string = '') |
|
| 209 | + { |
|
| 210 | + // you give me nothing??? GET OUT ! |
|
| 211 | + if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
| 212 | + return $encoded_string; |
|
| 213 | + } |
|
| 214 | + // decode |
|
| 215 | + return base64_decode($encoded_string); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * encodes url string with PHP's base64 encoding |
|
| 222 | + * |
|
| 223 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
| 224 | + * @param string $text_string the text to be encoded |
|
| 225 | + * @return string |
|
| 226 | + */ |
|
| 227 | + public function base64_url_encode($text_string = '') |
|
| 228 | + { |
|
| 229 | + // you give me nothing??? GET OUT ! |
|
| 230 | + if (empty($text_string) || ! $this->_use_base64_encode) { |
|
| 231 | + return $text_string; |
|
| 232 | + } |
|
| 233 | + // encode |
|
| 234 | + $encoded_string = base64_encode($text_string); |
|
| 235 | + // remove chars to make encoding more URL friendly |
|
| 236 | + return strtr($encoded_string, '+/=', '-_,'); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * decodes url string that has been encoded with PHP's base64 encoding |
|
| 243 | + * |
|
| 244 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
| 245 | + * @param string $encoded_string the text to be decoded |
|
| 246 | + * @return string |
|
| 247 | + */ |
|
| 248 | + public function base64_url_decode($encoded_string = '') |
|
| 249 | + { |
|
| 250 | + // you give me nothing??? GET OUT ! |
|
| 251 | + if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
| 252 | + return $encoded_string; |
|
| 253 | + } |
|
| 254 | + // replace previously removed characters |
|
| 255 | + $encoded_string = strtr($encoded_string, '-_,', '+/='); |
|
| 256 | + // decode |
|
| 257 | + return base64_decode($encoded_string); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * encrypts data using PHP's openssl functions |
|
| 264 | + * |
|
| 265 | + * @param string $text_string the text to be encrypted |
|
| 266 | + * @return string |
|
| 267 | + * @throws RuntimeException |
|
| 268 | + */ |
|
| 269 | + protected function openssl_encrypt($text_string = '') |
|
| 270 | + { |
|
| 271 | + // you give me nothing??? GET OUT ! |
|
| 272 | + if (empty($text_string)) { |
|
| 273 | + return $text_string; |
|
| 274 | + } |
|
| 275 | + // get initialization vector size |
|
| 276 | + $iv_size = openssl_cipher_iv_length(EE_Encryption::OPENSSL_CIPHER_METHOD); |
|
| 277 | + // generate initialization vector |
|
| 278 | + $iv = openssl_random_pseudo_bytes($iv_size, $is_strong); |
|
| 279 | + if ($iv === false || $is_strong === false) { |
|
| 280 | + throw new RuntimeException( |
|
| 281 | + esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso') |
|
| 282 | + ); |
|
| 283 | + } |
|
| 284 | + // encrypt it |
|
| 285 | + $encrypted_text = openssl_encrypt( |
|
| 286 | + $text_string, |
|
| 287 | + EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
| 288 | + openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD), |
|
| 289 | + 0, |
|
| 290 | + $iv |
|
| 291 | + ); |
|
| 292 | + // append the initialization vector |
|
| 293 | + $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv; |
|
| 294 | + // trim and maybe encode |
|
| 295 | + return $this->_use_base64_encode |
|
| 296 | + ? trim(base64_encode($encrypted_text)) |
|
| 297 | + : trim($encrypted_text); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * decrypts data that has been encrypted with PHP's openssl functions |
|
| 304 | + * |
|
| 305 | + * @param string $encrypted_text the text to be decrypted |
|
| 306 | + * @return string |
|
| 307 | + * @throws RuntimeException |
|
| 308 | + */ |
|
| 309 | + protected function openssl_decrypt($encrypted_text = '') |
|
| 310 | + { |
|
| 311 | + // you give me nothing??? GET OUT ! |
|
| 312 | + if (empty($encrypted_text)) { |
|
| 313 | + return $encrypted_text; |
|
| 314 | + } |
|
| 315 | + // decode |
|
| 316 | + $encrypted_text = $this->valid_base_64($encrypted_text) |
|
| 317 | + ? base64_decode($encrypted_text) |
|
| 318 | + : $encrypted_text; |
|
| 319 | + $encrypted_components = explode( |
|
| 320 | + EE_Encryption::OPENSSL_IV_DELIMITER, |
|
| 321 | + $encrypted_text, |
|
| 322 | + 2 |
|
| 323 | + ); |
|
| 324 | + // check that iv exists, and if not, maybe text was encoded using mcrypt? |
|
| 325 | + if (! isset($encrypted_components[1]) && $this->_use_mcrypt) { |
|
| 326 | + return $this->m_decrypt($encrypted_text); |
|
| 327 | + } |
|
| 328 | + // decrypt it |
|
| 329 | + $decrypted_text = openssl_decrypt( |
|
| 330 | + $encrypted_components[0], |
|
| 331 | + EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
| 332 | + openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD), |
|
| 333 | + 0, |
|
| 334 | + $encrypted_components[1] |
|
| 335 | + ); |
|
| 336 | + $decrypted_text = trim($decrypted_text); |
|
| 337 | + return $decrypted_text; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * encrypts data for acme servers that didn't bother to install PHP mcrypt |
|
| 344 | + * |
|
| 345 | + * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
| 346 | + * @param string $text_string the text to be decrypted |
|
| 347 | + * @return string |
|
| 348 | + */ |
|
| 349 | + protected function acme_encrypt($text_string = '') |
|
| 350 | + { |
|
| 351 | + // you give me nothing??? GET OUT ! |
|
| 352 | + if (empty($text_string)) { |
|
| 353 | + return $text_string; |
|
| 354 | + } |
|
| 355 | + $key_bits = str_split( |
|
| 356 | + str_pad('', strlen($text_string), $this->get_encryption_key(), STR_PAD_RIGHT) |
|
| 357 | + ); |
|
| 358 | + $string_bits = str_split($text_string); |
|
| 359 | + foreach ($string_bits as $k => $v) { |
|
| 360 | + $temp = ord($v) + ord($key_bits[$k]); |
|
| 361 | + $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
| 362 | + } |
|
| 363 | + $encrypted_text = implode('', $string_bits); |
|
| 364 | + $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG; |
|
| 365 | + return $this->_use_base64_encode |
|
| 366 | + ? base64_encode($encrypted_text) |
|
| 367 | + : $encrypted_text; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * decrypts data for acme servers that didn't bother to install PHP mcrypt |
|
| 374 | + * |
|
| 375 | + * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
| 376 | + * @param string $encrypted_text the text to be decrypted |
|
| 377 | + * @return string |
|
| 378 | + */ |
|
| 379 | + protected function acme_decrypt($encrypted_text = '') |
|
| 380 | + { |
|
| 381 | + // you give me nothing??? GET OUT ! |
|
| 382 | + if (empty($encrypted_text)) { |
|
| 383 | + return $encrypted_text; |
|
| 384 | + } |
|
| 385 | + // decode the data ? |
|
| 386 | + $encrypted_text = $this->valid_base_64($encrypted_text) |
|
| 387 | + ? base64_decode($encrypted_text) |
|
| 388 | + : $encrypted_text; |
|
| 389 | + if (strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false && $this->_use_mcrypt) { |
|
| 390 | + return $this->m_decrypt($encrypted_text); |
|
| 391 | + } |
|
| 392 | + $encrypted_text = substr($encrypted_text, 0, -4); |
|
| 393 | + $key_bits = str_split( |
|
| 394 | + str_pad('', strlen($encrypted_text), $this->get_encryption_key(), STR_PAD_RIGHT) |
|
| 395 | + ); |
|
| 396 | + $string_bits = str_split($encrypted_text); |
|
| 397 | + foreach ($string_bits as $k => $v) { |
|
| 398 | + $temp = ord($v) - ord($key_bits[$k]); |
|
| 399 | + $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
| 400 | + } |
|
| 401 | + return implode('', $string_bits); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
|
| 408 | + * @param $string |
|
| 409 | + * @return bool |
|
| 410 | + */ |
|
| 411 | + protected function valid_base_64($string) |
|
| 412 | + { |
|
| 413 | + // ensure data is a string |
|
| 414 | + if (! is_string($string) || ! $this->_use_base64_encode) { |
|
| 415 | + return false; |
|
| 416 | + } |
|
| 417 | + $decoded = base64_decode($string, true); |
|
| 418 | + // Check if there is no invalid character in string |
|
| 419 | + if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
| 420 | + return false; |
|
| 421 | + } |
|
| 422 | + // Decode the string in strict mode and send the response |
|
| 423 | + if (! base64_decode($string, true)) { |
|
| 424 | + return false; |
|
| 425 | + } |
|
| 426 | + // Encode and compare it to original one |
|
| 427 | + return base64_encode($decoded) === $string; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * generate random string |
|
| 434 | + * |
|
| 435 | + * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
|
| 436 | + * @param int $length number of characters for random string |
|
| 437 | + * @return string |
|
| 438 | + */ |
|
| 439 | + public function generate_random_string($length = 40) |
|
| 440 | + { |
|
| 441 | + $iterations = ceil($length / 40); |
|
| 442 | + $random_string = ''; |
|
| 443 | + for ($i = 0; $i < $iterations; $i++) { |
|
| 444 | + $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
| 445 | + } |
|
| 446 | + $random_string = substr($random_string, 0, $length); |
|
| 447 | + return $random_string; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * encrypts data using PHP's mcrypt functions |
|
| 454 | + * |
|
| 455 | + * @deprecated 4.9.39 |
|
| 456 | + * @param string $text_string |
|
| 457 | + * @internal param $string - the text to be encrypted |
|
| 458 | + * @return string |
|
| 459 | + * @throws RuntimeException |
|
| 460 | + */ |
|
| 461 | + protected function m_encrypt($text_string = '') |
|
| 462 | + { |
|
| 463 | + // you give me nothing??? GET OUT ! |
|
| 464 | + if (empty($text_string)) { |
|
| 465 | + return $text_string; |
|
| 466 | + } |
|
| 467 | + // get the initialization vector size |
|
| 468 | + $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
| 469 | + // initialization vector |
|
| 470 | + $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
| 471 | + if ($iv === false) { |
|
| 472 | + throw new RuntimeException( |
|
| 473 | + esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
| 474 | + ); |
|
| 475 | + } |
|
| 476 | + // encrypt it |
|
| 477 | + $encrypted_text = mcrypt_encrypt( |
|
| 478 | + MCRYPT_RIJNDAEL_256, |
|
| 479 | + $this->get_encryption_key(), |
|
| 480 | + $text_string, |
|
| 481 | + MCRYPT_MODE_ECB, |
|
| 482 | + $iv |
|
| 483 | + ); |
|
| 484 | + // trim and maybe encode |
|
| 485 | + return $this->_use_base64_encode |
|
| 486 | + ? trim(base64_encode($encrypted_text)) |
|
| 487 | + : trim($encrypted_text); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * decrypts data that has been encrypted with PHP's mcrypt functions |
|
| 494 | + * |
|
| 495 | + * @deprecated 4.9.39 |
|
| 496 | + * @param string $encrypted_text the text to be decrypted |
|
| 497 | + * @return string |
|
| 498 | + * @throws RuntimeException |
|
| 499 | + */ |
|
| 500 | + protected function m_decrypt($encrypted_text = '') |
|
| 501 | + { |
|
| 502 | + // you give me nothing??? GET OUT ! |
|
| 503 | + if (empty($encrypted_text)) { |
|
| 504 | + return $encrypted_text; |
|
| 505 | + } |
|
| 506 | + // decode |
|
| 507 | + $encrypted_text = $this->valid_base_64($encrypted_text) |
|
| 508 | + ? base64_decode($encrypted_text) |
|
| 509 | + : $encrypted_text; |
|
| 510 | + // get the initialization vector size |
|
| 511 | + $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
| 512 | + $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
| 513 | + if ($iv === false) { |
|
| 514 | + throw new RuntimeException( |
|
| 515 | + esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
| 516 | + ); |
|
| 517 | + } |
|
| 518 | + // decrypt it |
|
| 519 | + $decrypted_text = mcrypt_decrypt( |
|
| 520 | + MCRYPT_RIJNDAEL_256, |
|
| 521 | + $this->get_encryption_key(), |
|
| 522 | + $encrypted_text, |
|
| 523 | + MCRYPT_MODE_ECB, |
|
| 524 | + $iv |
|
| 525 | + ); |
|
| 526 | + $decrypted_text = trim($decrypted_text); |
|
| 527 | + return $decrypted_text; |
|
| 528 | + } |
|
| 529 | 529 | |
| 530 | 530 | } |
| 531 | 531 | /* End of file EE_Encryption.class.php */ |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public static function instance() { |
| 42 | 42 | // check if class object is instantiated |
| 43 | - if ( ! self::$_instance instanceof EE_Admin ) { |
|
| 43 | + if ( ! self::$_instance instanceof EE_Admin) { |
|
| 44 | 44 | self::$_instance = new self(); |
| 45 | 45 | } |
| 46 | 46 | return self::$_instance; |
@@ -57,25 +57,25 @@ discard block |
||
| 57 | 57 | // define global EE_Admin constants |
| 58 | 58 | $this->_define_all_constants(); |
| 59 | 59 | // set autoloaders for our admin page classes based on included path information |
| 60 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( EE_ADMIN ); |
|
| 60 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 61 | 61 | // admin hooks |
| 62 | - add_filter( 'plugin_action_links', array( $this, 'filter_plugin_actions' ), 10, 2 ); |
|
| 62 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
| 63 | 63 | // load EE_Request_Handler early |
| 64 | - add_action( 'AHEE__EE_System__core_loaded_and_ready', array( $this, 'get_request' )); |
|
| 65 | - add_action( 'AHEE__EE_System__initialize_last', array( $this, 'init' )); |
|
| 66 | - add_action( 'AHEE__EE_Admin_Page__route_admin_request', array( $this, 'route_admin_request' ), 100, 2 ); |
|
| 67 | - add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 100 ); |
|
| 68 | - add_action( 'admin_init', array( $this, 'admin_init' ), 100 ); |
|
| 69 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 20 ); |
|
| 70 | - add_action( 'admin_notices', array( $this, 'display_admin_notices' ), 10 ); |
|
| 71 | - add_action( 'network_admin_notices', array( $this, 'display_admin_notices' ), 10 ); |
|
| 72 | - add_filter( 'pre_update_option', array( $this, 'check_for_invalid_datetime_formats' ), 100, 2 ); |
|
| 73 | - add_filter('admin_footer_text', array( $this, 'espresso_admin_footer' )); |
|
| 64 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
| 65 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
| 66 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
| 67 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
| 68 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
| 69 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
| 70 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 71 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 72 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
| 73 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
| 74 | 74 | |
| 75 | 75 | //reset Environment config (we only do this on admin page loads); |
| 76 | 76 | EE_Registry::instance()->CFG->environment->recheck_values(); |
| 77 | 77 | |
| 78 | - do_action( 'AHEE__EE_Admin__loaded' ); |
|
| 78 | + do_action('AHEE__EE_Admin__loaded'); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
@@ -90,11 +90,11 @@ discard block |
||
| 90 | 90 | * @return void |
| 91 | 91 | */ |
| 92 | 92 | private function _define_all_constants() { |
| 93 | - define( 'EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/' ); |
|
| 94 | - define( 'EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/' ); |
|
| 95 | - define( 'EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS ); |
|
| 96 | - define( 'WP_ADMIN_PATH', ABSPATH . 'wp-admin/' ); |
|
| 97 | - define( 'WP_AJAX_URL', admin_url( 'admin-ajax.php' )); |
|
| 93 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/'); |
|
| 94 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/'); |
|
| 95 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS); |
|
| 96 | + define('WP_ADMIN_PATH', ABSPATH.'wp-admin/'); |
|
| 97 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
@@ -107,23 +107,23 @@ discard block |
||
| 107 | 107 | * @param string $plugin |
| 108 | 108 | * @return array |
| 109 | 109 | */ |
| 110 | - public function filter_plugin_actions( $links, $plugin ) { |
|
| 110 | + public function filter_plugin_actions($links, $plugin) { |
|
| 111 | 111 | // set $main_file in stone |
| 112 | 112 | static $main_file; |
| 113 | 113 | // if $main_file is not set yet |
| 114 | - if ( ! $main_file ) { |
|
| 115 | - $main_file = plugin_basename( EVENT_ESPRESSO_MAIN_FILE ); |
|
| 114 | + if ( ! $main_file) { |
|
| 115 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
| 116 | 116 | } |
| 117 | - if ( $plugin === $main_file ) { |
|
| 117 | + if ($plugin === $main_file) { |
|
| 118 | 118 | // compare current plugin to this one |
| 119 | - if ( EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance ) { |
|
| 120 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode. Click this link to learn why.">' . __('Maintenance Mode Active', 'event_espresso' ) . '</a>'; |
|
| 121 | - array_unshift( $links, $maintenance_link ); |
|
| 119 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 120 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode. Click this link to learn why.">'.__('Maintenance Mode Active', 'event_espresso').'</a>'; |
|
| 121 | + array_unshift($links, $maintenance_link); |
|
| 122 | 122 | } else { |
| 123 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' . __( 'Settings', 'event_espresso' ) . '</a>'; |
|
| 124 | - $events_link = '<a href="admin.php?page=espresso_events">' . __( 'Events', 'event_espresso' ) . '</a>'; |
|
| 123 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'.__('Settings', 'event_espresso').'</a>'; |
|
| 124 | + $events_link = '<a href="admin.php?page=espresso_events">'.__('Events', 'event_espresso').'</a>'; |
|
| 125 | 125 | // add before other links |
| 126 | - array_unshift( $links, $org_settings_link, $events_link ); |
|
| 126 | + array_unshift($links, $org_settings_link, $events_link); |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | return $links; |
@@ -138,8 +138,8 @@ discard block |
||
| 138 | 138 | * @return void |
| 139 | 139 | */ |
| 140 | 140 | public function get_request() { |
| 141 | - EE_Registry::instance()->load_core( 'Request_Handler' ); |
|
| 142 | - EE_Registry::instance()->load_core( 'CPT_Strategy' ); |
|
| 141 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 142 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -151,11 +151,11 @@ discard block |
||
| 151 | 151 | * @param array $admin_page_folder_names |
| 152 | 152 | * @return array |
| 153 | 153 | */ |
| 154 | - public function hide_admin_pages_except_maintenance_mode( $admin_page_folder_names = array() ){ |
|
| 154 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) { |
|
| 155 | 155 | return array( |
| 156 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 157 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 158 | - 'support' => EE_ADMIN_PAGES . 'support' . DS |
|
| 156 | + 'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS, |
|
| 157 | + 'about' => EE_ADMIN_PAGES.'about'.DS, |
|
| 158 | + 'support' => EE_ADMIN_PAGES.'support'.DS |
|
| 159 | 159 | ); |
| 160 | 160 | } |
| 161 | 161 | |
@@ -169,31 +169,31 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | public function init() { |
| 171 | 171 | //only enable most of the EE_Admin IF we're not in full maintenance mode |
| 172 | - if ( EE_Maintenance_Mode::instance()->models_can_query() ){ |
|
| 172 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 173 | 173 | //ok so we want to enable the entire admin |
| 174 | - add_action( 'wp_ajax_dismiss_ee_nag_notice', array( $this, 'dismiss_ee_nag_notice_callback' )); |
|
| 175 | - add_action( 'admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 ); |
|
| 176 | - add_action( 'network_admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 ); |
|
| 174 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
| 175 | + add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 176 | + add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 177 | 177 | //at a glance dashboard widget |
| 178 | - add_filter( 'dashboard_glance_items', array( $this, 'dashboard_glance_items' ), 10 ); |
|
| 178 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
| 179 | 179 | //filter for get_edit_post_link used on comments for custom post types |
| 180 | - add_filter( 'get_edit_post_link', array( $this, 'modify_edit_post_link' ), 10, 2 ); |
|
| 180 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
| 181 | 181 | } |
| 182 | 182 | // run the admin page factory but ONLY if we are doing an ee admin ajax request |
| 183 | - if ( !defined('DOING_AJAX') || EE_ADMIN_AJAX ) { |
|
| 183 | + if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 184 | 184 | try { |
| 185 | 185 | //this loads the controller for the admin pages which will setup routing etc |
| 186 | - EE_Registry::instance()->load_core( 'Admin_Page_Loader' ); |
|
| 187 | - } catch ( EE_Error $e ) { |
|
| 186 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
| 187 | + } catch (EE_Error $e) { |
|
| 188 | 188 | $e->get_error(); |
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | - add_filter( 'content_save_pre', array( $this, 'its_eSpresso' ), 10, 1 ); |
|
| 191 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
| 192 | 192 | //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
| 193 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes' ), 10 ); |
|
| 194 | - add_action('admin_head', array( $this, 'register_custom_nav_menu_boxes' ), 10 ); |
|
| 193 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
| 194 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
| 195 | 195 | //exclude EE critical pages from all nav menus and wp_list_pages |
| 196 | - add_filter('nav_menu_meta_box_object', array( $this, 'remove_pages_from_nav_menu'), 10 ); |
|
| 196 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | * @param object $post_type WP post type object |
| 207 | 207 | * @return object WP post type object |
| 208 | 208 | */ |
| 209 | - public function remove_pages_from_nav_menu( $post_type ) { |
|
| 209 | + public function remove_pages_from_nav_menu($post_type) { |
|
| 210 | 210 | //if this isn't the "pages" post type let's get out |
| 211 | - if ( $post_type->name !== 'page' ) { |
|
| 211 | + if ($post_type->name !== 'page') { |
|
| 212 | 212 | return $post_type; |
| 213 | 213 | } |
| 214 | 214 | $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
@@ -228,28 +228,28 @@ discard block |
||
| 228 | 228 | */ |
| 229 | 229 | public function enable_hidden_ee_nav_menu_metaboxes() { |
| 230 | 230 | global $wp_meta_boxes, $pagenow; |
| 231 | - if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php' ) { |
|
| 231 | + if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 232 | 232 | return; |
| 233 | 233 | } |
| 234 | 234 | $user = wp_get_current_user(); |
| 235 | 235 | //has this been done yet? |
| 236 | - if ( get_user_option( 'ee_nav_menu_initialized', $user->ID ) ) { |
|
| 236 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 237 | 237 | return; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - $hidden_meta_boxes = get_user_option( 'metaboxhidden_nav-menus', $user->ID ); |
|
| 241 | - $initial_meta_boxes = apply_filters( 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', array( 'nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category', 'add-espresso_events', 'add-espresso_venues', 'add-espresso_event_categories', 'add-espresso_venue_categories', 'add-post-type-post', 'add-post-type-page' ) ); |
|
| 240 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 241 | + $initial_meta_boxes = apply_filters('FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', array('nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category', 'add-espresso_events', 'add-espresso_venues', 'add-espresso_event_categories', 'add-espresso_venue_categories', 'add-post-type-post', 'add-post-type-page')); |
|
| 242 | 242 | |
| 243 | - if ( is_array( $hidden_meta_boxes ) ) { |
|
| 244 | - foreach ( $hidden_meta_boxes as $key => $meta_box_id ) { |
|
| 245 | - if ( in_array( $meta_box_id, $initial_meta_boxes ) ) { |
|
| 246 | - unset( $hidden_meta_boxes[ $key ] ); |
|
| 243 | + if (is_array($hidden_meta_boxes)) { |
|
| 244 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 245 | + if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
| 246 | + unset($hidden_meta_boxes[$key]); |
|
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true ); |
|
| 252 | - update_user_option( $user->ID, 'ee_nav_menu_initialized', 1, true ); |
|
| 251 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 252 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | * @return void |
| 269 | 269 | */ |
| 270 | 270 | public function register_custom_nav_menu_boxes() { |
| 271 | - add_meta_box( 'add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array( $this, 'ee_cpt_archive_pages' ), 'nav-menus', 'side', 'core' ); |
|
| 271 | + add_meta_box('add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array($this, 'ee_cpt_archive_pages'), 'nav-menus', 'side', 'core'); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | |
@@ -284,16 +284,16 @@ discard block |
||
| 284 | 284 | * |
| 285 | 285 | * @return string the (maybe) modified link |
| 286 | 286 | */ |
| 287 | - public function modify_edit_post_link( $link, $id ) { |
|
| 288 | - if ( ! $post = get_post( $id ) ){ |
|
| 287 | + public function modify_edit_post_link($link, $id) { |
|
| 288 | + if ( ! $post = get_post($id)) { |
|
| 289 | 289 | return $link; |
| 290 | 290 | } |
| 291 | - if ( $post->post_type === 'espresso_attendees' ) { |
|
| 291 | + if ($post->post_type === 'espresso_attendees') { |
|
| 292 | 292 | $query_args = array( |
| 293 | 293 | 'action' => 'edit_attendee', |
| 294 | 294 | 'post' => $id |
| 295 | 295 | ); |
| 296 | - return EEH_URL::add_query_args_and_nonce( $query_args, admin_url('admin.php?page=espresso_registrations') ); |
|
| 296 | + return EEH_URL::add_query_args_and_nonce($query_args, admin_url('admin.php?page=espresso_registrations')); |
|
| 297 | 297 | } |
| 298 | 298 | return $link; |
| 299 | 299 | } |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | global $nav_menu_selected_id; |
| 306 | 306 | |
| 307 | 307 | $db_fields = false; |
| 308 | - $walker = new Walker_Nav_Menu_Checklist( $db_fields ); |
|
| 308 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
| 309 | 309 | $current_tab = 'event-archives'; |
| 310 | 310 | |
| 311 | 311 | /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
@@ -324,9 +324,9 @@ discard block |
||
| 324 | 324 | ?> |
| 325 | 325 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
| 326 | 326 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
| 327 | - <li <?php echo ( 'event-archives' === $current_tab ? ' class="tabs"' : '' ); ?>> |
|
| 328 | - <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" href="<?php if ( $nav_menu_selected_id ) {echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', remove_query_arg($removed_args)));} ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 329 | - <?php _e( 'Event Archive Pages', 'event_espresso' ); ?> |
|
| 327 | + <li <?php echo ('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
|
| 328 | + <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" href="<?php if ($nav_menu_selected_id) {echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', remove_query_arg($removed_args))); } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 329 | + <?php _e('Event Archive Pages', 'event_espresso'); ?> |
|
| 330 | 330 | </a> |
| 331 | 331 | </li> |
| 332 | 332 | <?php /* // temporarily removing but leaving skeleton in place in case we ever decide to add more tabs. |
@@ -344,13 +344,13 @@ discard block |
||
| 344 | 344 | <?php */ ?> |
| 345 | 345 | |
| 346 | 346 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
| 347 | - echo ( 'event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); |
|
| 347 | + echo ('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
| 348 | 348 | ?>"> |
| 349 | 349 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
| 350 | 350 | <?php |
| 351 | 351 | $pages = $this->_get_extra_nav_menu_pages_items(); |
| 352 | 352 | $args['walker'] = $walker; |
| 353 | - echo walk_nav_menu_tree( array_map( array( $this, '_setup_extra_nav_menu_pages_items' ), $pages), 0, (object) $args ); |
|
| 353 | + echo walk_nav_menu_tree(array_map(array($this, '_setup_extra_nav_menu_pages_items'), $pages), 0, (object) $args); |
|
| 354 | 354 | ?> |
| 355 | 355 | </ul> |
| 356 | 356 | </div><!-- /.tabs-panel --> |
@@ -358,18 +358,18 @@ discard block |
||
| 358 | 358 | <p class="button-controls"> |
| 359 | 359 | <span class="list-controls"> |
| 360 | 360 | <a href="<?php |
| 361 | - echo esc_url( add_query_arg( |
|
| 361 | + echo esc_url(add_query_arg( |
|
| 362 | 362 | array( |
| 363 | 363 | 'extra-nav-menu-pages-tab' => 'event-archives', |
| 364 | 364 | 'selectall' => 1, |
| 365 | 365 | ), |
| 366 | - remove_query_arg( $removed_args ) |
|
| 366 | + remove_query_arg($removed_args) |
|
| 367 | 367 | )); |
| 368 | 368 | ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
| 369 | 369 | </span> |
| 370 | 370 | |
| 371 | 371 | <span class="add-to-menu"> |
| 372 | - <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e( 'submit-posttype-extra-nav-menu-pages' ); ?>" /> |
|
| 372 | + <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e(__('Add to Menu')); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e('submit-posttype-extra-nav-menu-pages'); ?>" /> |
|
| 373 | 373 | <span class="spinner"></span> |
| 374 | 374 | </span> |
| 375 | 375 | </p> |
@@ -390,10 +390,10 @@ discard block |
||
| 390 | 390 | private function _get_extra_nav_menu_pages_items() { |
| 391 | 391 | $menuitems[] = array( |
| 392 | 392 | 'title' => __('Event List', 'event_espresso'), |
| 393 | - 'url' => get_post_type_archive_link( 'espresso_events' ), |
|
| 393 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
| 394 | 394 | 'description' => __('Archive page for all events.', 'event_espresso') |
| 395 | 395 | ); |
| 396 | - return apply_filters( 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems ); |
|
| 396 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | * @param $menu_item_values |
| 406 | 406 | * @return stdClass |
| 407 | 407 | */ |
| 408 | - private function _setup_extra_nav_menu_pages_items( $menu_item_values ) { |
|
| 408 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) { |
|
| 409 | 409 | $menu_item = new stdClass(); |
| 410 | 410 | $keys = array( |
| 411 | 411 | 'ID' => 0, |
@@ -425,8 +425,8 @@ discard block |
||
| 425 | 425 | 'xfn' => '' |
| 426 | 426 | ); |
| 427 | 427 | |
| 428 | - foreach ( $keys as $key => $value) { |
|
| 429 | - $menu_item->{$key} = isset( $menu_item_values[ $key]) ? $menu_item_values[ $key] : $value; |
|
| 428 | + foreach ($keys as $key => $value) { |
|
| 429 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
| 430 | 430 | } |
| 431 | 431 | return $menu_item; |
| 432 | 432 | } |
@@ -465,9 +465,9 @@ discard block |
||
| 465 | 465 | * - check if doing post processing of one of EE CPTs |
| 466 | 466 | * - instantiate the corresponding EE CPT model for the post_type being processed. |
| 467 | 467 | */ |
| 468 | - if ( isset( $_POST['action'], $_POST['post_type'] ) && $_POST['action'] === 'editpost' ) { |
|
| 469 | - EE_Registry::instance()->load_core( 'Register_CPTs' ); |
|
| 470 | - EE_Register_CPTs::instantiate_cpt_models( $_POST['post_type'] ); |
|
| 468 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
| 469 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 470 | + EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | * tab in the EE General Settings Admin page. |
| 478 | 478 | * This is for user-proofing. |
| 479 | 479 | */ |
| 480 | - add_filter( 'wp_dropdown_pages', array( $this, 'modify_dropdown_pages' ) ); |
|
| 480 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
| 481 | 481 | |
| 482 | 482 | } |
| 483 | 483 | |
@@ -488,25 +488,25 @@ discard block |
||
| 488 | 488 | * @param string $output Current output. |
| 489 | 489 | * @return string |
| 490 | 490 | */ |
| 491 | - public function modify_dropdown_pages( $output ) { |
|
| 491 | + public function modify_dropdown_pages($output) { |
|
| 492 | 492 | //get critical pages |
| 493 | 493 | $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
| 494 | 494 | |
| 495 | 495 | //split current output by line break for easier parsing. |
| 496 | - $split_output = explode( "\n", $output ); |
|
| 496 | + $split_output = explode("\n", $output); |
|
| 497 | 497 | |
| 498 | 498 | //loop through to remove any critical pages from the array. |
| 499 | - foreach ( $critical_pages as $page_id ) { |
|
| 500 | - $needle = 'value="' . $page_id . '"'; |
|
| 501 | - foreach( $split_output as $key => $haystack ) { |
|
| 502 | - if( strpos( $haystack, $needle ) !== false ) { |
|
| 503 | - unset( $split_output[$key] ); |
|
| 499 | + foreach ($critical_pages as $page_id) { |
|
| 500 | + $needle = 'value="'.$page_id.'"'; |
|
| 501 | + foreach ($split_output as $key => $haystack) { |
|
| 502 | + if (strpos($haystack, $needle) !== false) { |
|
| 503 | + unset($split_output[$key]); |
|
| 504 | 504 | } |
| 505 | 505 | } |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | //replace output with the new contents |
| 509 | - return implode( "\n", $split_output ); |
|
| 509 | + return implode("\n", $split_output); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | |
@@ -520,17 +520,17 @@ discard block |
||
| 520 | 520 | public function enqueue_admin_scripts() { |
| 521 | 521 | // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
| 522 | 522 | // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script calls. |
| 523 | - wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 523 | + wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 524 | 524 | // register cookie script for future dependencies |
| 525 | - wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE ); |
|
| 525 | + wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE); |
|
| 526 | 526 | //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again vai: add_filter('FHEE_load_joyride', '__return_true' ); |
| 527 | - if ( apply_filters( 'FHEE_load_joyride', FALSE ) ) { |
|
| 527 | + if (apply_filters('FHEE_load_joyride', FALSE)) { |
|
| 528 | 528 | //joyride style |
| 529 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 530 | - wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION ); |
|
| 531 | - wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', array(), '2.1', TRUE ); |
|
| 529 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 530 | + wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION); |
|
| 531 | + wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', array(), '2.1', TRUE); |
|
| 532 | 532 | //joyride JS |
| 533 | - wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE ); |
|
| 533 | + wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE); |
|
| 534 | 534 | // wanna go for a joyride? |
| 535 | 535 | wp_enqueue_style('ee-joyride-css'); |
| 536 | 536 | wp_enqueue_script('jquery-joyride'); |
@@ -560,11 +560,11 @@ discard block |
||
| 560 | 560 | public function get_persistent_admin_notices() { |
| 561 | 561 | // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
| 562 | 562 | $args = array( |
| 563 | - 'page' => EE_Registry::instance()->REQ->is_set( 'page' ) ? EE_Registry::instance()->REQ->get( 'page' ) : '', |
|
| 564 | - 'action' => EE_Registry::instance()->REQ->is_set( 'action' ) ? EE_Registry::instance()->REQ->get( 'action' ) : '', |
|
| 563 | + 'page' => EE_Registry::instance()->REQ->is_set('page') ? EE_Registry::instance()->REQ->get('page') : '', |
|
| 564 | + 'action' => EE_Registry::instance()->REQ->is_set('action') ? EE_Registry::instance()->REQ->get('action') : '', |
|
| 565 | 565 | ); |
| 566 | - $return_url = EE_Admin_Page::add_query_args_and_nonce( $args, EE_ADMIN_URL ); |
|
| 567 | - echo EE_Error::get_persistent_admin_notices( $return_url ); |
|
| 566 | + $return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL); |
|
| 567 | + echo EE_Error::get_persistent_admin_notices($return_url); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | |
@@ -589,24 +589,24 @@ discard block |
||
| 589 | 589 | public function dashboard_glance_items($elements) { |
| 590 | 590 | $elements = is_array($elements) ? $elements : array($elements); |
| 591 | 591 | $events = EEM_Event::instance()->count(); |
| 592 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_events'), admin_url('admin.php') ); |
|
| 593 | - $items['events']['text'] = sprintf( _n( '%s Event', '%s Events', $events ), number_format_i18n( $events ) ); |
|
| 592 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_events'), admin_url('admin.php')); |
|
| 593 | + $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
| 594 | 594 | $items['events']['title'] = __('Click to view all Events', 'event_espresso'); |
| 595 | 595 | $registrations = EEM_Registration::instance()->count( |
| 596 | 596 | array( |
| 597 | 597 | array( |
| 598 | - 'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete ) |
|
| 598 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete) |
|
| 599 | 599 | ) |
| 600 | 600 | ) |
| 601 | 601 | ); |
| 602 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_registrations' ), admin_url('admin.php') ); |
|
| 603 | - $items['registrations']['text'] = sprintf( _n( '%s Registration', '%s Registrations', $registrations ), number_format_i18n($registrations) ); |
|
| 602 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_registrations'), admin_url('admin.php')); |
|
| 603 | + $items['registrations']['text'] = sprintf(_n('%s Registration', '%s Registrations', $registrations), number_format_i18n($registrations)); |
|
| 604 | 604 | $items['registrations']['title'] = __('Click to view all registrations', 'event_espresso'); |
| 605 | 605 | |
| 606 | - $items = (array) apply_filters( 'FHEE__EE_Admin__dashboard_glance_items__items', $items ); |
|
| 606 | + $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 607 | 607 | |
| 608 | - foreach ( $items as $type => $item_properties ) { |
|
| 609 | - $elements[] = sprintf( '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text'] ); |
|
| 608 | + foreach ($items as $type => $item_properties) { |
|
| 609 | + $elements[] = sprintf('<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text']); |
|
| 610 | 610 | } |
| 611 | 611 | return $elements; |
| 612 | 612 | } |
@@ -623,31 +623,31 @@ discard block |
||
| 623 | 623 | * @throws EE_Error |
| 624 | 624 | * @return string |
| 625 | 625 | */ |
| 626 | - public function check_for_invalid_datetime_formats( $value, $option ) { |
|
| 626 | + public function check_for_invalid_datetime_formats($value, $option) { |
|
| 627 | 627 | // check for date_format or time_format |
| 628 | - switch ( $option ) { |
|
| 628 | + switch ($option) { |
|
| 629 | 629 | case 'date_format' : |
| 630 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 630 | + $date_time_format = $value.' '.get_option('time_format'); |
|
| 631 | 631 | break; |
| 632 | 632 | case 'time_format' : |
| 633 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 633 | + $date_time_format = get_option('date_format').' '.$value; |
|
| 634 | 634 | break; |
| 635 | 635 | default : |
| 636 | 636 | $date_time_format = FALSE; |
| 637 | 637 | } |
| 638 | 638 | // do we have a date_time format to check ? |
| 639 | - if ( $date_time_format ) { |
|
| 640 | - $error_msg = EEH_DTT_Helper::validate_format_string( $date_time_format ); |
|
| 639 | + if ($date_time_format) { |
|
| 640 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 641 | 641 | |
| 642 | - if ( is_array( $error_msg ) ) { |
|
| 643 | - $msg = '<p>' . sprintf( __( 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', 'event_espresso' ), date( $date_time_format ) , $date_time_format ) . '</p><p><ul>'; |
|
| 642 | + if (is_array($error_msg)) { |
|
| 643 | + $msg = '<p>'.sprintf(__('The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', 'event_espresso'), date($date_time_format), $date_time_format).'</p><p><ul>'; |
|
| 644 | 644 | |
| 645 | 645 | |
| 646 | - foreach ( $error_msg as $error ) { |
|
| 647 | - $msg .= '<li>' . $error . '</li>'; |
|
| 646 | + foreach ($error_msg as $error) { |
|
| 647 | + $msg .= '<li>'.$error.'</li>'; |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - $msg .= '</ul></p><p>' . sprintf( __( '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', 'event_espresso' ), '<span style="color:#D54E21;">', '</span>' ) . '</p>'; |
|
| 650 | + $msg .= '</ul></p><p>'.sprintf(__('%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', 'event_espresso'), '<span style="color:#D54E21;">', '</span>').'</p>'; |
|
| 651 | 651 | |
| 652 | 652 | // trigger WP settings error |
| 653 | 653 | add_settings_error( |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | ); |
| 658 | 658 | |
| 659 | 659 | // set format to something valid |
| 660 | - switch ( $option ) { |
|
| 660 | + switch ($option) { |
|
| 661 | 661 | case 'date_format' : |
| 662 | 662 | $value = 'F j, Y'; |
| 663 | 663 | break; |
@@ -679,8 +679,8 @@ discard block |
||
| 679 | 679 | * @param $content |
| 680 | 680 | * @return string |
| 681 | 681 | */ |
| 682 | - public function its_eSpresso( $content ) { |
|
| 683 | - return str_replace( '[EXPRESSO_', '[ESPRESSO_', $content ); |
|
| 682 | + public function its_eSpresso($content) { |
|
| 683 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | * @return string |
| 693 | 693 | */ |
| 694 | 694 | public function espresso_admin_footer() { |
| 695 | - return \EEH_Template::powered_by_event_espresso( 'aln-cntr', '', array( 'utm_content' => 'admin_footer' )); |
|
| 695 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | |
@@ -711,12 +711,12 @@ discard block |
||
| 711 | 711 | * @param array $config |
| 712 | 712 | * @return void |
| 713 | 713 | */ |
| 714 | - public static function register_ee_admin_page( $page_basename, $page_path, $config = array() ) { |
|
| 715 | - EE_Error::doing_it_wrong( __METHOD__, sprintf( __('Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', 'event_espresso'), $page_basename), '4.3' ); |
|
| 716 | - if ( class_exists( 'EE_Register_Admin_Page' ) ) { |
|
| 714 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) { |
|
| 715 | + EE_Error::doing_it_wrong(__METHOD__, sprintf(__('Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', 'event_espresso'), $page_basename), '4.3'); |
|
| 716 | + if (class_exists('EE_Register_Admin_Page')) { |
|
| 717 | 717 | $config['page_path'] = $page_path; |
| 718 | 718 | } |
| 719 | - EE_Register_Admin_Page::register( $page_basename, $config ); |
|
| 719 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
| 720 | 720 | |
| 721 | 721 | } |
| 722 | 722 | |
@@ -729,7 +729,7 @@ discard block |
||
| 729 | 729 | * @param \WP_Post $post |
| 730 | 730 | * @return void |
| 731 | 731 | */ |
| 732 | - public static function parse_post_content_on_save( $post_ID, $post ) { |
|
| 732 | + public static function parse_post_content_on_save($post_ID, $post) { |
|
| 733 | 733 | EE_Error::doing_it_wrong( |
| 734 | 734 | __METHOD__, |
| 735 | 735 | __('Usage is deprecated', 'event_espresso'), |
@@ -747,7 +747,7 @@ discard block |
||
| 747 | 747 | * @param $value |
| 748 | 748 | * @return void |
| 749 | 749 | */ |
| 750 | - public function reset_page_for_posts_on_change( $option, $old_value, $value ) { |
|
| 750 | + public function reset_page_for_posts_on_change($option, $old_value, $value) { |
|
| 751 | 751 | EE_Error::doing_it_wrong( |
| 752 | 752 | __METHOD__, |
| 753 | 753 | __('Usage is deprecated', 'event_espresso'), |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | use EventEspresso\core\services\shortcodes\ShortcodesManager; |
| 3 | 3 | |
| 4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 5 | - exit('No direct script access allowed'); |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -19,1412 +19,1412 @@ discard block |
||
| 19 | 19 | { |
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 24 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 25 | - */ |
|
| 26 | - const req_type_normal = 0; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Indicates this is a brand new installation of EE so we should install |
|
| 30 | - * tables and default data etc |
|
| 31 | - */ |
|
| 32 | - const req_type_new_activation = 1; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 36 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 37 | - * and that default data is setup too |
|
| 38 | - */ |
|
| 39 | - const req_type_reactivation = 2; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * indicates that EE has been upgraded since its previous request. |
|
| 43 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 44 | - */ |
|
| 45 | - const req_type_upgrade = 3; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 49 | - */ |
|
| 50 | - const req_type_downgrade = 4; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @deprecated since version 4.6.0.dev.006 |
|
| 54 | - * Now whenever a new_activation is detected the request type is still just |
|
| 55 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
| 56 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 57 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 58 | - * (Specifically, when the migration manager indicates migrations are finished |
|
| 59 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 60 | - */ |
|
| 61 | - const req_type_activation_but_not_installed = 5; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 65 | - */ |
|
| 66 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * instance of the EE_System object |
|
| 71 | - * |
|
| 72 | - * @var $_instance |
|
| 73 | - * @access private |
|
| 74 | - */ |
|
| 75 | - private static $_instance = null; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @type EE_Registry $Registry |
|
| 79 | - * @access protected |
|
| 80 | - */ |
|
| 81 | - protected $registry; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 85 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 86 | - * |
|
| 87 | - * @var int |
|
| 88 | - */ |
|
| 89 | - private $_req_type; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
| 93 | - * |
|
| 94 | - * @var boolean |
|
| 95 | - */ |
|
| 96 | - private $_major_version_change = false; |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @singleton method used to instantiate class object |
|
| 102 | - * @access public |
|
| 103 | - * @param \EE_Registry $Registry |
|
| 104 | - * @return \EE_System |
|
| 105 | - */ |
|
| 106 | - public static function instance(EE_Registry $Registry = null) |
|
| 107 | - { |
|
| 108 | - // check if class object is instantiated |
|
| 109 | - if ( ! self::$_instance instanceof EE_System) { |
|
| 110 | - self::$_instance = new self($Registry); |
|
| 111 | - } |
|
| 112 | - return self::$_instance; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * resets the instance and returns it |
|
| 119 | - * |
|
| 120 | - * @return EE_System |
|
| 121 | - */ |
|
| 122 | - public static function reset() |
|
| 123 | - { |
|
| 124 | - self::$_instance->_req_type = null; |
|
| 125 | - //make sure none of the old hooks are left hanging around |
|
| 126 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 127 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
| 128 | - EE_Data_Migration_Manager::reset(); |
|
| 129 | - self::instance()->detect_activations_or_upgrades(); |
|
| 130 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 131 | - return self::instance(); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * sets hooks for running rest of system |
|
| 138 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 139 | - * starting EE Addons from any other point may lead to problems |
|
| 140 | - * |
|
| 141 | - * @access private |
|
| 142 | - * @param \EE_Registry $Registry |
|
| 143 | - */ |
|
| 144 | - private function __construct(EE_Registry $Registry) |
|
| 145 | - { |
|
| 146 | - $this->registry = $Registry; |
|
| 147 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
| 148 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 149 | - add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
| 150 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
| 151 | - // because the newly-activated addon didn't get a chance to run at all |
|
| 152 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
| 153 | - // detect whether install or upgrade |
|
| 154 | - add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
| 155 | - 3); |
|
| 156 | - // load EE_Config, EE_Textdomain, etc |
|
| 157 | - add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
| 158 | - // load EE_Config, EE_Textdomain, etc |
|
| 159 | - add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 160 | - array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
| 161 | - // you wanna get going? I wanna get going... let's get going! |
|
| 162 | - add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
| 163 | - //other housekeeping |
|
| 164 | - //exclude EE critical pages from wp_list_pages |
|
| 165 | - add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
| 166 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 167 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 168 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * load_espresso_addons |
|
| 175 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 176 | - * this is hooked into both: |
|
| 177 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 178 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 179 | - * and the WP 'activate_plugin' hookpoint |
|
| 180 | - * |
|
| 181 | - * @access public |
|
| 182 | - * @return void |
|
| 183 | - */ |
|
| 184 | - public function load_espresso_addons() |
|
| 185 | - { |
|
| 186 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
| 187 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
| 188 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 189 | - //load and setup EE_Capabilities |
|
| 190 | - $this->registry->load_core('Capabilities'); |
|
| 191 | - //caps need to be initialized on every request so that capability maps are set. |
|
| 192 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 193 | - $this->registry->CAP->init_caps(); |
|
| 194 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
| 195 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
| 196 | - //We want it for mobile apps. Just include the entire plugin |
|
| 197 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
| 198 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
| 199 | - //and causes a fatal error |
|
| 200 | - if ( ! function_exists('json_basic_auth_handler') |
|
| 201 | - && ! function_exists('json_basic_auth_error') |
|
| 202 | - && ! ( |
|
| 203 | - isset($_GET['action']) |
|
| 204 | - && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
| 205 | - ) |
|
| 206 | - && ! ( |
|
| 207 | - isset($_GET['activate']) |
|
| 208 | - && $_GET['activate'] === 'true' |
|
| 209 | - ) |
|
| 210 | - ) { |
|
| 211 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 212 | - } |
|
| 213 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * detect_activations_or_upgrades |
|
| 220 | - * Checks for activation or upgrade of core first; |
|
| 221 | - * then also checks if any registered addons have been activated or upgraded |
|
| 222 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 223 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 224 | - * |
|
| 225 | - * @access public |
|
| 226 | - * @return void |
|
| 227 | - */ |
|
| 228 | - public function detect_activations_or_upgrades() |
|
| 229 | - { |
|
| 230 | - //first off: let's make sure to handle core |
|
| 231 | - $this->detect_if_activation_or_upgrade(); |
|
| 232 | - foreach ($this->registry->addons as $addon) { |
|
| 233 | - //detect teh request type for that addon |
|
| 234 | - $addon->detect_activation_or_upgrade(); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * detect_if_activation_or_upgrade |
|
| 242 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 243 | - * and either setting up the DB or setting up maintenance mode etc. |
|
| 244 | - * |
|
| 245 | - * @access public |
|
| 246 | - * @return void |
|
| 247 | - */ |
|
| 248 | - public function detect_if_activation_or_upgrade() |
|
| 249 | - { |
|
| 250 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 251 | - // load M-Mode class |
|
| 252 | - $this->registry->load_core('Maintenance_Mode'); |
|
| 253 | - // check if db has been updated, or if its a brand-new installation |
|
| 254 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 255 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
| 256 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 257 | - switch ($request_type) { |
|
| 258 | - case EE_System::req_type_new_activation: |
|
| 259 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 260 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 261 | - break; |
|
| 262 | - case EE_System::req_type_reactivation: |
|
| 263 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 264 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 265 | - break; |
|
| 266 | - case EE_System::req_type_upgrade: |
|
| 267 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 268 | - //migrations may be required now that we've upgraded |
|
| 269 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 270 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 271 | - // echo "done upgrade";die; |
|
| 272 | - break; |
|
| 273 | - case EE_System::req_type_downgrade: |
|
| 274 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 275 | - //its possible migrations are no longer required |
|
| 276 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 277 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 278 | - break; |
|
| 279 | - case EE_System::req_type_normal: |
|
| 280 | - default: |
|
| 281 | - // $this->_maybe_redirect_to_ee_about(); |
|
| 282 | - break; |
|
| 283 | - } |
|
| 284 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Updates the list of installed versions and sets hooks for |
|
| 291 | - * initializing the database later during the request |
|
| 292 | - * |
|
| 293 | - * @param array $espresso_db_update |
|
| 294 | - */ |
|
| 295 | - protected function _handle_core_version_change($espresso_db_update) |
|
| 296 | - { |
|
| 297 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
| 298 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 299 | - add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 300 | - array($this, 'initialize_db_if_no_migrations_required')); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 307 | - * information about what versions of EE have been installed and activated, |
|
| 308 | - * NOT necessarily the state of the database |
|
| 309 | - * |
|
| 310 | - * @param null $espresso_db_update |
|
| 311 | - * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
| 312 | - * from the options table |
|
| 313 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 314 | - */ |
|
| 315 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
| 316 | - { |
|
| 317 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 318 | - if ( ! $espresso_db_update) { |
|
| 319 | - $espresso_db_update = get_option('espresso_db_update'); |
|
| 320 | - } |
|
| 321 | - // check that option is an array |
|
| 322 | - if ( ! is_array($espresso_db_update)) { |
|
| 323 | - // if option is FALSE, then it never existed |
|
| 324 | - if ($espresso_db_update === false) { |
|
| 325 | - // make $espresso_db_update an array and save option with autoload OFF |
|
| 326 | - $espresso_db_update = array(); |
|
| 327 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 328 | - } else { |
|
| 329 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 330 | - $espresso_db_update = array($espresso_db_update => array()); |
|
| 331 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 332 | - } |
|
| 333 | - } else { |
|
| 334 | - $corrected_db_update = array(); |
|
| 335 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 336 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 337 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 338 | - //the key is an int, and the value IS NOT an array |
|
| 339 | - //so it must be numerically-indexed, where values are versions installed... |
|
| 340 | - //fix it! |
|
| 341 | - $version_string = $should_be_array; |
|
| 342 | - $corrected_db_update[$version_string] = array('unknown-date'); |
|
| 343 | - } else { |
|
| 344 | - //ok it checks out |
|
| 345 | - $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - $espresso_db_update = $corrected_db_update; |
|
| 349 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 350 | - } |
|
| 351 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 352 | - return $espresso_db_update; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 359 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 360 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 361 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 362 | - * so that it will be done when migrations are finished |
|
| 363 | - * |
|
| 364 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 365 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 366 | - * This is a resource-intensive job |
|
| 367 | - * so we prefer to only do it when necessary |
|
| 368 | - * @return void |
|
| 369 | - */ |
|
| 370 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 371 | - { |
|
| 372 | - $request_type = $this->detect_req_type(); |
|
| 373 | - //only initialize system if we're not in maintenance mode. |
|
| 374 | - if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 375 | - update_option('ee_flush_rewrite_rules', true); |
|
| 376 | - if ($verify_schema) { |
|
| 377 | - EEH_Activation::initialize_db_and_folders(); |
|
| 378 | - } |
|
| 379 | - EEH_Activation::initialize_db_content(); |
|
| 380 | - EEH_Activation::system_initialization(); |
|
| 381 | - if ($initialize_addons_too) { |
|
| 382 | - $this->initialize_addons(); |
|
| 383 | - } |
|
| 384 | - } else { |
|
| 385 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 386 | - } |
|
| 387 | - if ($request_type === EE_System::req_type_new_activation |
|
| 388 | - || $request_type === EE_System::req_type_reactivation |
|
| 389 | - || ( |
|
| 390 | - $request_type === EE_System::req_type_upgrade |
|
| 391 | - && $this->is_major_version_change() |
|
| 392 | - ) |
|
| 393 | - ) { |
|
| 394 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * Initializes the db for all registered addons |
|
| 402 | - */ |
|
| 403 | - public function initialize_addons() |
|
| 404 | - { |
|
| 405 | - //foreach registered addon, make sure its db is up-to-date too |
|
| 406 | - foreach ($this->registry->addons as $addon) { |
|
| 407 | - $addon->initialize_db_if_no_migrations_required(); |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 415 | - * |
|
| 416 | - * @param array $version_history |
|
| 417 | - * @param string $current_version_to_add version to be added to the version history |
|
| 418 | - * @return boolean success as to whether or not this option was changed |
|
| 419 | - */ |
|
| 420 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 421 | - { |
|
| 422 | - if ( ! $version_history) { |
|
| 423 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 424 | - } |
|
| 425 | - if ($current_version_to_add == null) { |
|
| 426 | - $current_version_to_add = espresso_version(); |
|
| 427 | - } |
|
| 428 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
| 429 | - // re-save |
|
| 430 | - return update_option('espresso_db_update', $version_history); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Detects if the current version indicated in the has existed in the list of |
|
| 437 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 438 | - * |
|
| 439 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 440 | - * If not supplied, fetches it from the options table. |
|
| 441 | - * Also, caches its result so later parts of the code can also know whether |
|
| 442 | - * there's been an update or not. This way we can add the current version to |
|
| 443 | - * espresso_db_update, but still know if this is a new install or not |
|
| 444 | - * @return int one of the constants on EE_System::req_type_ |
|
| 445 | - */ |
|
| 446 | - public function detect_req_type($espresso_db_update = null) |
|
| 447 | - { |
|
| 448 | - if ($this->_req_type === null) { |
|
| 449 | - $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
| 450 | - : $this->fix_espresso_db_upgrade_option(); |
|
| 451 | - $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
| 452 | - 'ee_espresso_activation', espresso_version()); |
|
| 453 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
| 454 | - } |
|
| 455 | - return $this->_req_type; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
| 462 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
| 463 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 464 | - * |
|
| 465 | - * @param $activation_history |
|
| 466 | - * @return bool |
|
| 467 | - */ |
|
| 468 | - protected function _detect_major_version_change($activation_history) |
|
| 469 | - { |
|
| 470 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
| 471 | - $previous_version_parts = explode('.', $previous_version); |
|
| 472 | - $current_version_parts = explode('.', espresso_version()); |
|
| 473 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
| 474 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
| 475 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
| 476 | - ); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * Returns true if either the major or minor version of EE changed during this request. |
|
| 483 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 484 | - * |
|
| 485 | - * @return bool |
|
| 486 | - */ |
|
| 487 | - public function is_major_version_change() |
|
| 488 | - { |
|
| 489 | - return $this->_major_version_change; |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 496 | - * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
| 497 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 498 | - * just activated to (for core that will always be espresso_version()) |
|
| 499 | - * |
|
| 500 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
| 501 | - * ee plugin. for core that's 'espresso_db_update' |
|
| 502 | - * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
| 503 | - * indicate that this plugin was just activated |
|
| 504 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
| 505 | - * espresso_version()) |
|
| 506 | - * @return int one of the constants on EE_System::req_type_* |
|
| 507 | - */ |
|
| 508 | - public static function detect_req_type_given_activation_history( |
|
| 509 | - $activation_history_for_addon, |
|
| 510 | - $activation_indicator_option_name, |
|
| 511 | - $version_to_upgrade_to |
|
| 512 | - ) { |
|
| 513 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
| 514 | - if ($activation_history_for_addon) { |
|
| 515 | - //it exists, so this isn't a completely new install |
|
| 516 | - //check if this version already in that list of previously installed versions |
|
| 517 | - if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 518 | - //it a version we haven't seen before |
|
| 519 | - if ($version_is_higher === 1) { |
|
| 520 | - $req_type = EE_System::req_type_upgrade; |
|
| 521 | - } else { |
|
| 522 | - $req_type = EE_System::req_type_downgrade; |
|
| 523 | - } |
|
| 524 | - delete_option($activation_indicator_option_name); |
|
| 525 | - } else { |
|
| 526 | - // its not an update. maybe a reactivation? |
|
| 527 | - if (get_option($activation_indicator_option_name, false)) { |
|
| 528 | - if ($version_is_higher === -1) { |
|
| 529 | - $req_type = EE_System::req_type_downgrade; |
|
| 530 | - } elseif ($version_is_higher === 0) { |
|
| 531 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
| 532 | - $req_type = EE_System::req_type_reactivation; |
|
| 533 | - } else {//$version_is_higher === 1 |
|
| 534 | - $req_type = EE_System::req_type_upgrade; |
|
| 535 | - } |
|
| 536 | - delete_option($activation_indicator_option_name); |
|
| 537 | - } else { |
|
| 538 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
| 539 | - if ($version_is_higher === -1) { |
|
| 540 | - $req_type = EE_System::req_type_downgrade; |
|
| 541 | - } elseif ($version_is_higher === 0) { |
|
| 542 | - //we've seen this version before and it's not an activation. its normal request |
|
| 543 | - $req_type = EE_System::req_type_normal; |
|
| 544 | - } else {//$version_is_higher === 1 |
|
| 545 | - $req_type = EE_System::req_type_upgrade; |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - } else { |
|
| 550 | - //brand new install |
|
| 551 | - $req_type = EE_System::req_type_new_activation; |
|
| 552 | - delete_option($activation_indicator_option_name); |
|
| 553 | - } |
|
| 554 | - return $req_type; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 561 | - * the $activation_history_for_addon |
|
| 562 | - * |
|
| 563 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
| 564 | - * sometimes containing 'unknown-date' |
|
| 565 | - * @param string $version_to_upgrade_to (current version) |
|
| 566 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 567 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 568 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 569 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 570 | - */ |
|
| 571 | - protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
| 572 | - { |
|
| 573 | - //find the most recently-activated version |
|
| 574 | - $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
| 575 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Gets the most recently active version listed in the activation history, |
|
| 582 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
| 583 | - * |
|
| 584 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
| 585 | - * sometimes containing 'unknown-date' |
|
| 586 | - * @return string |
|
| 587 | - */ |
|
| 588 | - protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
| 589 | - { |
|
| 590 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
| 591 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
| 592 | - if (is_array($activation_history)) { |
|
| 593 | - foreach ($activation_history as $version => $times_activated) { |
|
| 594 | - //check there is a record of when this version was activated. Otherwise, |
|
| 595 | - //mark it as unknown |
|
| 596 | - if ( ! $times_activated) { |
|
| 597 | - $times_activated = array('unknown-date'); |
|
| 598 | - } |
|
| 599 | - if (is_string($times_activated)) { |
|
| 600 | - $times_activated = array($times_activated); |
|
| 601 | - } |
|
| 602 | - foreach ($times_activated as $an_activation) { |
|
| 603 | - if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
| 604 | - $most_recently_active_version = $version; |
|
| 605 | - $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
| 606 | - ? '1970-01-01 00:00:00' : $an_activation; |
|
| 607 | - } |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - } |
|
| 611 | - return $most_recently_active_version; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * This redirects to the about EE page after activation |
|
| 618 | - * |
|
| 619 | - * @return void |
|
| 620 | - */ |
|
| 621 | - public function redirect_to_about_ee() |
|
| 622 | - { |
|
| 623 | - $notices = EE_Error::get_notices(false); |
|
| 624 | - //if current user is an admin and it's not an ajax or rest request |
|
| 625 | - if ( |
|
| 626 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 627 | - && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
| 628 | - && ! isset($notices['errors']) |
|
| 629 | - && apply_filters( |
|
| 630 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
| 631 | - $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
| 632 | - ) |
|
| 633 | - ) { |
|
| 634 | - $query_params = array('page' => 'espresso_about'); |
|
| 635 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
| 636 | - $query_params['new_activation'] = true; |
|
| 637 | - } |
|
| 638 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
| 639 | - $query_params['reactivation'] = true; |
|
| 640 | - } |
|
| 641 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 642 | - wp_safe_redirect($url); |
|
| 643 | - exit(); |
|
| 644 | - } |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * load_core_configuration |
|
| 651 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 652 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 653 | - * |
|
| 654 | - * @return void |
|
| 655 | - */ |
|
| 656 | - public function load_core_configuration() |
|
| 657 | - { |
|
| 658 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 659 | - $this->registry->load_core('EE_Load_Textdomain'); |
|
| 660 | - //load textdomain |
|
| 661 | - EE_Load_Textdomain::load_textdomain(); |
|
| 662 | - // load and setup EE_Config and EE_Network_Config |
|
| 663 | - $this->registry->load_core('Config'); |
|
| 664 | - $this->registry->load_core('Network_Config'); |
|
| 665 | - // setup autoloaders |
|
| 666 | - // enable logging? |
|
| 667 | - if ($this->registry->CFG->admin->use_full_logging) { |
|
| 668 | - $this->registry->load_core('Log'); |
|
| 669 | - } |
|
| 670 | - // check for activation errors |
|
| 671 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 672 | - if ($activation_errors) { |
|
| 673 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 674 | - update_option('ee_plugin_activation_errors', false); |
|
| 675 | - } |
|
| 676 | - // get model names |
|
| 677 | - $this->_parse_model_names(); |
|
| 678 | - //load caf stuff a chance to play during the activation process too. |
|
| 679 | - $this->_maybe_brew_regular(); |
|
| 680 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 687 | - * |
|
| 688 | - * @return void |
|
| 689 | - */ |
|
| 690 | - private function _parse_model_names() |
|
| 691 | - { |
|
| 692 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
| 693 | - $models = glob(EE_MODELS . '*.model.php'); |
|
| 694 | - $model_names = array(); |
|
| 695 | - $non_abstract_db_models = array(); |
|
| 696 | - foreach ($models as $model) { |
|
| 697 | - // get model classname |
|
| 698 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 699 | - $short_name = str_replace('EEM_', '', $classname); |
|
| 700 | - $reflectionClass = new ReflectionClass($classname); |
|
| 701 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 702 | - $non_abstract_db_models[$short_name] = $classname; |
|
| 703 | - } |
|
| 704 | - $model_names[$short_name] = $classname; |
|
| 705 | - } |
|
| 706 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 707 | - $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
| 708 | - $non_abstract_db_models); |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 715 | - * that need to be setup before our EE_System launches. |
|
| 716 | - * |
|
| 717 | - * @return void |
|
| 718 | - */ |
|
| 719 | - private function _maybe_brew_regular() |
|
| 720 | - { |
|
| 721 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 722 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 723 | - } |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - |
|
| 727 | - |
|
| 728 | - /** |
|
| 729 | - * register_shortcodes_modules_and_widgets |
|
| 730 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
| 731 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 732 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 733 | - * |
|
| 734 | - * @access public |
|
| 735 | - * @return void |
|
| 736 | - */ |
|
| 737 | - public function register_shortcodes_modules_and_widgets() |
|
| 738 | - { |
|
| 739 | - try { |
|
| 740 | - // load, register, and add shortcodes the new way |
|
| 741 | - new ShortcodesManager( |
|
| 742 | - // and the old way, but we'll put it under control of the new system |
|
| 743 | - EE_Config::getLegacyShortcodesManager() |
|
| 744 | - ); |
|
| 745 | - } catch (Exception $exception) { |
|
| 746 | - new ExceptionStackTraceDisplay($exception); |
|
| 747 | - } |
|
| 748 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 749 | - // check for addons using old hookpoint |
|
| 750 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 751 | - $this->_incompatible_addon_error(); |
|
| 752 | - } |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - /** |
|
| 758 | - * _incompatible_addon_error |
|
| 759 | - * |
|
| 760 | - * @access public |
|
| 761 | - * @return void |
|
| 762 | - */ |
|
| 763 | - private function _incompatible_addon_error() |
|
| 764 | - { |
|
| 765 | - // get array of classes hooking into here |
|
| 766 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
| 767 | - if ( ! empty($class_names)) { |
|
| 768 | - $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 769 | - 'event_espresso'); |
|
| 770 | - $msg .= '<ul>'; |
|
| 771 | - foreach ($class_names as $class_name) { |
|
| 772 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 773 | - $class_name) . '</b></li>'; |
|
| 774 | - } |
|
| 775 | - $msg .= '</ul>'; |
|
| 776 | - $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 777 | - 'event_espresso'); |
|
| 778 | - // save list of incompatible addons to wp-options for later use |
|
| 779 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 780 | - if (is_admin()) { |
|
| 781 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - |
|
| 787 | - |
|
| 788 | - /** |
|
| 789 | - * brew_espresso |
|
| 790 | - * begins the process of setting hooks for initializing EE in the correct order |
|
| 791 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
| 792 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 793 | - * |
|
| 794 | - * @return void |
|
| 795 | - */ |
|
| 796 | - public function brew_espresso() |
|
| 797 | - { |
|
| 798 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 799 | - // load some final core systems |
|
| 800 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
| 801 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
| 802 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
| 803 | - add_action('init', array($this, 'load_controllers'), 7); |
|
| 804 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
| 805 | - add_action('init', array($this, 'initialize'), 10); |
|
| 806 | - add_action('init', array($this, 'initialize_last'), 100); |
|
| 807 | - add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
| 808 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
| 809 | - // pew pew pew |
|
| 810 | - $this->registry->load_core('PUE'); |
|
| 811 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
| 812 | - } |
|
| 813 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - |
|
| 817 | - |
|
| 818 | - /** |
|
| 819 | - * set_hooks_for_core |
|
| 820 | - * |
|
| 821 | - * @access public |
|
| 822 | - * @return void |
|
| 823 | - */ |
|
| 824 | - public function set_hooks_for_core() |
|
| 825 | - { |
|
| 826 | - $this->_deactivate_incompatible_addons(); |
|
| 827 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - |
|
| 831 | - |
|
| 832 | - /** |
|
| 833 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 834 | - * deactivates any addons considered incompatible with the current version of EE |
|
| 835 | - */ |
|
| 836 | - private function _deactivate_incompatible_addons() |
|
| 837 | - { |
|
| 838 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
| 839 | - if ( ! empty($incompatible_addons)) { |
|
| 840 | - $active_plugins = get_option('active_plugins', array()); |
|
| 841 | - foreach ($active_plugins as $active_plugin) { |
|
| 842 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
| 843 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 844 | - unset($_GET['activate']); |
|
| 845 | - espresso_deactivate_plugin($active_plugin); |
|
| 846 | - } |
|
| 847 | - } |
|
| 848 | - } |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - |
|
| 853 | - |
|
| 854 | - /** |
|
| 855 | - * perform_activations_upgrades_and_migrations |
|
| 856 | - * |
|
| 857 | - * @access public |
|
| 858 | - * @return void |
|
| 859 | - */ |
|
| 860 | - public function perform_activations_upgrades_and_migrations() |
|
| 861 | - { |
|
| 862 | - //first check if we had previously attempted to setup EE's directories but failed |
|
| 863 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
| 864 | - EEH_Activation::create_upload_directories(); |
|
| 865 | - } |
|
| 866 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - |
|
| 870 | - |
|
| 871 | - /** |
|
| 872 | - * load_CPTs_and_session |
|
| 873 | - * |
|
| 874 | - * @access public |
|
| 875 | - * @return void |
|
| 876 | - */ |
|
| 877 | - public function load_CPTs_and_session() |
|
| 878 | - { |
|
| 879 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 880 | - // register Custom Post Types |
|
| 881 | - $this->registry->load_core('Register_CPTs'); |
|
| 882 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - |
|
| 886 | - |
|
| 887 | - /** |
|
| 888 | - * load_controllers |
|
| 889 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
| 890 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 891 | - * time |
|
| 892 | - * |
|
| 893 | - * @access public |
|
| 894 | - * @return void |
|
| 895 | - */ |
|
| 896 | - public function load_controllers() |
|
| 897 | - { |
|
| 898 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
| 899 | - // let's get it started |
|
| 900 | - if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
| 901 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 902 | - $this->registry->load_core('Front_Controller'); |
|
| 903 | - } else if ( ! EE_FRONT_AJAX) { |
|
| 904 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
| 905 | - EE_Registry::instance()->load_core('Admin'); |
|
| 906 | - } |
|
| 907 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - |
|
| 911 | - |
|
| 912 | - /** |
|
| 913 | - * core_loaded_and_ready |
|
| 914 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 915 | - * |
|
| 916 | - * @access public |
|
| 917 | - * @return void |
|
| 918 | - */ |
|
| 919 | - public function core_loaded_and_ready() |
|
| 920 | - { |
|
| 921 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 922 | - // load_espresso_template_tags |
|
| 923 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 924 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 925 | - } |
|
| 926 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 927 | - $this->registry->load_core('Session'); |
|
| 928 | - $this->registry->create('EventEspresso\core\services\assets\Registry'); |
|
| 929 | - wp_enqueue_script('espresso_core'); |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * initialize |
|
| 936 | - * this is the best place to begin initializing client code |
|
| 937 | - * |
|
| 938 | - * @access public |
|
| 939 | - * @return void |
|
| 940 | - */ |
|
| 941 | - public function initialize() |
|
| 942 | - { |
|
| 943 | - do_action('AHEE__EE_System__initialize'); |
|
| 944 | - } |
|
| 945 | - |
|
| 946 | - |
|
| 947 | - |
|
| 948 | - /** |
|
| 949 | - * initialize_last |
|
| 950 | - * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
| 951 | - * initialize has done so |
|
| 952 | - * |
|
| 953 | - * @access public |
|
| 954 | - * @return void |
|
| 955 | - */ |
|
| 956 | - public function initialize_last() |
|
| 957 | - { |
|
| 958 | - do_action('AHEE__EE_System__initialize_last'); |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - |
|
| 962 | - |
|
| 963 | - /** |
|
| 964 | - * set_hooks_for_shortcodes_modules_and_addons |
|
| 965 | - * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
| 966 | - * this happens at the very beginning of the wp_loaded hookpoint |
|
| 967 | - * |
|
| 968 | - * @access public |
|
| 969 | - * @return void |
|
| 970 | - */ |
|
| 971 | - public function set_hooks_for_shortcodes_modules_and_addons() |
|
| 972 | - { |
|
| 973 | - // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - /** |
|
| 979 | - * do_not_cache |
|
| 980 | - * sets no cache headers and defines no cache constants for WP plugins |
|
| 981 | - * |
|
| 982 | - * @access public |
|
| 983 | - * @return void |
|
| 984 | - */ |
|
| 985 | - public static function do_not_cache() |
|
| 986 | - { |
|
| 987 | - // set no cache constants |
|
| 988 | - if ( ! defined('DONOTCACHEPAGE')) { |
|
| 989 | - define('DONOTCACHEPAGE', true); |
|
| 990 | - } |
|
| 991 | - if ( ! defined('DONOTCACHCEOBJECT')) { |
|
| 992 | - define('DONOTCACHCEOBJECT', true); |
|
| 993 | - } |
|
| 994 | - if ( ! defined('DONOTCACHEDB')) { |
|
| 995 | - define('DONOTCACHEDB', true); |
|
| 996 | - } |
|
| 997 | - // add no cache headers |
|
| 998 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
| 999 | - // plus a little extra for nginx and Google Chrome |
|
| 1000 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
| 1001 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 1002 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - |
|
| 1006 | - |
|
| 1007 | - /** |
|
| 1008 | - * extra_nocache_headers |
|
| 1009 | - * |
|
| 1010 | - * @access public |
|
| 1011 | - * @param $headers |
|
| 1012 | - * @return array |
|
| 1013 | - */ |
|
| 1014 | - public static function extra_nocache_headers($headers) |
|
| 1015 | - { |
|
| 1016 | - // for NGINX |
|
| 1017 | - $headers['X-Accel-Expires'] = 0; |
|
| 1018 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 1019 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 1020 | - return $headers; |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - |
|
| 1024 | - |
|
| 1025 | - /** |
|
| 1026 | - * nocache_headers |
|
| 1027 | - * |
|
| 1028 | - * @access public |
|
| 1029 | - * @return void |
|
| 1030 | - */ |
|
| 1031 | - public static function nocache_headers() |
|
| 1032 | - { |
|
| 1033 | - nocache_headers(); |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - |
|
| 1037 | - |
|
| 1038 | - /** |
|
| 1039 | - * espresso_toolbar_items |
|
| 1040 | - * |
|
| 1041 | - * @access public |
|
| 1042 | - * @param WP_Admin_Bar $admin_bar |
|
| 1043 | - * @return void |
|
| 1044 | - */ |
|
| 1045 | - public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
| 1046 | - { |
|
| 1047 | - // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
| 1048 | - if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1049 | - || defined('DOING_AJAX') |
|
| 1050 | - || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
| 1051 | - ) { |
|
| 1052 | - return; |
|
| 1053 | - } |
|
| 1054 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1055 | - $menu_class = 'espresso_menu_item_class'; |
|
| 1056 | - //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
| 1057 | - //because they're only defined in each of their respective constructors |
|
| 1058 | - //and this might be a frontend request, in which case they aren't available |
|
| 1059 | - $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
| 1060 | - $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
| 1061 | - $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
| 1062 | - //Top Level |
|
| 1063 | - $admin_bar->add_menu(array( |
|
| 1064 | - 'id' => 'espresso-toolbar', |
|
| 1065 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
| 1066 | - . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
| 1067 | - . '</span>', |
|
| 1068 | - 'href' => $events_admin_url, |
|
| 1069 | - 'meta' => array( |
|
| 1070 | - 'title' => __('Event Espresso', 'event_espresso'), |
|
| 1071 | - 'class' => $menu_class . 'first', |
|
| 1072 | - ), |
|
| 1073 | - )); |
|
| 1074 | - //Events |
|
| 1075 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
| 1076 | - $admin_bar->add_menu(array( |
|
| 1077 | - 'id' => 'espresso-toolbar-events', |
|
| 1078 | - 'parent' => 'espresso-toolbar', |
|
| 1079 | - 'title' => __('Events', 'event_espresso'), |
|
| 1080 | - 'href' => $events_admin_url, |
|
| 1081 | - 'meta' => array( |
|
| 1082 | - 'title' => __('Events', 'event_espresso'), |
|
| 1083 | - 'target' => '', |
|
| 1084 | - 'class' => $menu_class, |
|
| 1085 | - ), |
|
| 1086 | - )); |
|
| 1087 | - } |
|
| 1088 | - if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
| 1089 | - //Events Add New |
|
| 1090 | - $admin_bar->add_menu(array( |
|
| 1091 | - 'id' => 'espresso-toolbar-events-new', |
|
| 1092 | - 'parent' => 'espresso-toolbar-events', |
|
| 1093 | - 'title' => __('Add New', 'event_espresso'), |
|
| 1094 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
| 1095 | - 'meta' => array( |
|
| 1096 | - 'title' => __('Add New', 'event_espresso'), |
|
| 1097 | - 'target' => '', |
|
| 1098 | - 'class' => $menu_class, |
|
| 1099 | - ), |
|
| 1100 | - )); |
|
| 1101 | - } |
|
| 1102 | - if (is_single() && (get_post_type() == 'espresso_events')) { |
|
| 1103 | - //Current post |
|
| 1104 | - global $post; |
|
| 1105 | - if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
| 1106 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
| 1107 | - ) { |
|
| 1108 | - //Events Edit Current Event |
|
| 1109 | - $admin_bar->add_menu(array( |
|
| 1110 | - 'id' => 'espresso-toolbar-events-edit', |
|
| 1111 | - 'parent' => 'espresso-toolbar-events', |
|
| 1112 | - 'title' => __('Edit Event', 'event_espresso'), |
|
| 1113 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
| 1114 | - $events_admin_url), |
|
| 1115 | - 'meta' => array( |
|
| 1116 | - 'title' => __('Edit Event', 'event_espresso'), |
|
| 1117 | - 'target' => '', |
|
| 1118 | - 'class' => $menu_class, |
|
| 1119 | - ), |
|
| 1120 | - )); |
|
| 1121 | - } |
|
| 1122 | - } |
|
| 1123 | - //Events View |
|
| 1124 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1125 | - 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
| 1126 | - ) { |
|
| 1127 | - $admin_bar->add_menu(array( |
|
| 1128 | - 'id' => 'espresso-toolbar-events-view', |
|
| 1129 | - 'parent' => 'espresso-toolbar-events', |
|
| 1130 | - 'title' => __('View', 'event_espresso'), |
|
| 1131 | - 'href' => $events_admin_url, |
|
| 1132 | - 'meta' => array( |
|
| 1133 | - 'title' => __('View', 'event_espresso'), |
|
| 1134 | - 'target' => '', |
|
| 1135 | - 'class' => $menu_class, |
|
| 1136 | - ), |
|
| 1137 | - )); |
|
| 1138 | - } |
|
| 1139 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
| 1140 | - //Events View All |
|
| 1141 | - $admin_bar->add_menu(array( |
|
| 1142 | - 'id' => 'espresso-toolbar-events-all', |
|
| 1143 | - 'parent' => 'espresso-toolbar-events-view', |
|
| 1144 | - 'title' => __('All', 'event_espresso'), |
|
| 1145 | - 'href' => $events_admin_url, |
|
| 1146 | - 'meta' => array( |
|
| 1147 | - 'title' => __('All', 'event_espresso'), |
|
| 1148 | - 'target' => '', |
|
| 1149 | - 'class' => $menu_class, |
|
| 1150 | - ), |
|
| 1151 | - )); |
|
| 1152 | - } |
|
| 1153 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1154 | - 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
| 1155 | - ) { |
|
| 1156 | - //Events View Today |
|
| 1157 | - $admin_bar->add_menu(array( |
|
| 1158 | - 'id' => 'espresso-toolbar-events-today', |
|
| 1159 | - 'parent' => 'espresso-toolbar-events-view', |
|
| 1160 | - 'title' => __('Today', 'event_espresso'), |
|
| 1161 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1162 | - $events_admin_url), |
|
| 1163 | - 'meta' => array( |
|
| 1164 | - 'title' => __('Today', 'event_espresso'), |
|
| 1165 | - 'target' => '', |
|
| 1166 | - 'class' => $menu_class, |
|
| 1167 | - ), |
|
| 1168 | - )); |
|
| 1169 | - } |
|
| 1170 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1171 | - 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
| 1172 | - ) { |
|
| 1173 | - //Events View This Month |
|
| 1174 | - $admin_bar->add_menu(array( |
|
| 1175 | - 'id' => 'espresso-toolbar-events-month', |
|
| 1176 | - 'parent' => 'espresso-toolbar-events-view', |
|
| 1177 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1178 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1179 | - $events_admin_url), |
|
| 1180 | - 'meta' => array( |
|
| 1181 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1182 | - 'target' => '', |
|
| 1183 | - 'class' => $menu_class, |
|
| 1184 | - ), |
|
| 1185 | - )); |
|
| 1186 | - } |
|
| 1187 | - //Registration Overview |
|
| 1188 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1189 | - 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
| 1190 | - ) { |
|
| 1191 | - $admin_bar->add_menu(array( |
|
| 1192 | - 'id' => 'espresso-toolbar-registrations', |
|
| 1193 | - 'parent' => 'espresso-toolbar', |
|
| 1194 | - 'title' => __('Registrations', 'event_espresso'), |
|
| 1195 | - 'href' => $reg_admin_url, |
|
| 1196 | - 'meta' => array( |
|
| 1197 | - 'title' => __('Registrations', 'event_espresso'), |
|
| 1198 | - 'target' => '', |
|
| 1199 | - 'class' => $menu_class, |
|
| 1200 | - ), |
|
| 1201 | - )); |
|
| 1202 | - } |
|
| 1203 | - //Registration Overview Today |
|
| 1204 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1205 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
| 1206 | - ) { |
|
| 1207 | - $admin_bar->add_menu(array( |
|
| 1208 | - 'id' => 'espresso-toolbar-registrations-today', |
|
| 1209 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 1210 | - 'title' => __('Today', 'event_espresso'), |
|
| 1211 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1212 | - $reg_admin_url), |
|
| 1213 | - 'meta' => array( |
|
| 1214 | - 'title' => __('Today', 'event_espresso'), |
|
| 1215 | - 'target' => '', |
|
| 1216 | - 'class' => $menu_class, |
|
| 1217 | - ), |
|
| 1218 | - )); |
|
| 1219 | - } |
|
| 1220 | - //Registration Overview Today Completed |
|
| 1221 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1222 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
| 1223 | - ) { |
|
| 1224 | - $admin_bar->add_menu(array( |
|
| 1225 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
| 1226 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1227 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1228 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1229 | - 'action' => 'default', |
|
| 1230 | - 'status' => 'today', |
|
| 1231 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1232 | - ), $reg_admin_url), |
|
| 1233 | - 'meta' => array( |
|
| 1234 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1235 | - 'target' => '', |
|
| 1236 | - 'class' => $menu_class, |
|
| 1237 | - ), |
|
| 1238 | - )); |
|
| 1239 | - } |
|
| 1240 | - //Registration Overview Today Pending\ |
|
| 1241 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1242 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
| 1243 | - ) { |
|
| 1244 | - $admin_bar->add_menu(array( |
|
| 1245 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
| 1246 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1247 | - 'title' => __('Pending', 'event_espresso'), |
|
| 1248 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1249 | - 'action' => 'default', |
|
| 1250 | - 'status' => 'today', |
|
| 1251 | - 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1252 | - ), $reg_admin_url), |
|
| 1253 | - 'meta' => array( |
|
| 1254 | - 'title' => __('Pending Payment', 'event_espresso'), |
|
| 1255 | - 'target' => '', |
|
| 1256 | - 'class' => $menu_class, |
|
| 1257 | - ), |
|
| 1258 | - )); |
|
| 1259 | - } |
|
| 1260 | - //Registration Overview Today Incomplete |
|
| 1261 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1262 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
| 1263 | - ) { |
|
| 1264 | - $admin_bar->add_menu(array( |
|
| 1265 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
| 1266 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1267 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1268 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1269 | - 'action' => 'default', |
|
| 1270 | - 'status' => 'today', |
|
| 1271 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1272 | - ), $reg_admin_url), |
|
| 1273 | - 'meta' => array( |
|
| 1274 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1275 | - 'target' => '', |
|
| 1276 | - 'class' => $menu_class, |
|
| 1277 | - ), |
|
| 1278 | - )); |
|
| 1279 | - } |
|
| 1280 | - //Registration Overview Today Incomplete |
|
| 1281 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1282 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
| 1283 | - ) { |
|
| 1284 | - $admin_bar->add_menu(array( |
|
| 1285 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
| 1286 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1287 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1288 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1289 | - 'action' => 'default', |
|
| 1290 | - 'status' => 'today', |
|
| 1291 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1292 | - ), $reg_admin_url), |
|
| 1293 | - 'meta' => array( |
|
| 1294 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1295 | - 'target' => '', |
|
| 1296 | - 'class' => $menu_class, |
|
| 1297 | - ), |
|
| 1298 | - )); |
|
| 1299 | - } |
|
| 1300 | - //Registration Overview This Month |
|
| 1301 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1302 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
| 1303 | - ) { |
|
| 1304 | - $admin_bar->add_menu(array( |
|
| 1305 | - 'id' => 'espresso-toolbar-registrations-month', |
|
| 1306 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 1307 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1308 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1309 | - $reg_admin_url), |
|
| 1310 | - 'meta' => array( |
|
| 1311 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1312 | - 'target' => '', |
|
| 1313 | - 'class' => $menu_class, |
|
| 1314 | - ), |
|
| 1315 | - )); |
|
| 1316 | - } |
|
| 1317 | - //Registration Overview This Month Approved |
|
| 1318 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1319 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
| 1320 | - ) { |
|
| 1321 | - $admin_bar->add_menu(array( |
|
| 1322 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
| 1323 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1324 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1325 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1326 | - 'action' => 'default', |
|
| 1327 | - 'status' => 'month', |
|
| 1328 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1329 | - ), $reg_admin_url), |
|
| 1330 | - 'meta' => array( |
|
| 1331 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1332 | - 'target' => '', |
|
| 1333 | - 'class' => $menu_class, |
|
| 1334 | - ), |
|
| 1335 | - )); |
|
| 1336 | - } |
|
| 1337 | - //Registration Overview This Month Pending |
|
| 1338 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1339 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
| 1340 | - ) { |
|
| 1341 | - $admin_bar->add_menu(array( |
|
| 1342 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
| 1343 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1344 | - 'title' => __('Pending', 'event_espresso'), |
|
| 1345 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1346 | - 'action' => 'default', |
|
| 1347 | - 'status' => 'month', |
|
| 1348 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1349 | - ), $reg_admin_url), |
|
| 1350 | - 'meta' => array( |
|
| 1351 | - 'title' => __('Pending', 'event_espresso'), |
|
| 1352 | - 'target' => '', |
|
| 1353 | - 'class' => $menu_class, |
|
| 1354 | - ), |
|
| 1355 | - )); |
|
| 1356 | - } |
|
| 1357 | - //Registration Overview This Month Not Approved |
|
| 1358 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1359 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
| 1360 | - ) { |
|
| 1361 | - $admin_bar->add_menu(array( |
|
| 1362 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
| 1363 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1364 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1365 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1366 | - 'action' => 'default', |
|
| 1367 | - 'status' => 'month', |
|
| 1368 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1369 | - ), $reg_admin_url), |
|
| 1370 | - 'meta' => array( |
|
| 1371 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1372 | - 'target' => '', |
|
| 1373 | - 'class' => $menu_class, |
|
| 1374 | - ), |
|
| 1375 | - )); |
|
| 1376 | - } |
|
| 1377 | - //Registration Overview This Month Cancelled |
|
| 1378 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1379 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
| 1380 | - ) { |
|
| 1381 | - $admin_bar->add_menu(array( |
|
| 1382 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
| 1383 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1384 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1385 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1386 | - 'action' => 'default', |
|
| 1387 | - 'status' => 'month', |
|
| 1388 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1389 | - ), $reg_admin_url), |
|
| 1390 | - 'meta' => array( |
|
| 1391 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1392 | - 'target' => '', |
|
| 1393 | - 'class' => $menu_class, |
|
| 1394 | - ), |
|
| 1395 | - )); |
|
| 1396 | - } |
|
| 1397 | - //Extensions & Services |
|
| 1398 | - if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
| 1399 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
| 1400 | - ) { |
|
| 1401 | - $admin_bar->add_menu(array( |
|
| 1402 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
| 1403 | - 'parent' => 'espresso-toolbar', |
|
| 1404 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1405 | - 'href' => $extensions_admin_url, |
|
| 1406 | - 'meta' => array( |
|
| 1407 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1408 | - 'target' => '', |
|
| 1409 | - 'class' => $menu_class, |
|
| 1410 | - ), |
|
| 1411 | - )); |
|
| 1412 | - } |
|
| 1413 | - } |
|
| 1414 | - |
|
| 1415 | - |
|
| 1416 | - |
|
| 1417 | - /** |
|
| 1418 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1419 | - * never returned with the function. |
|
| 1420 | - * |
|
| 1421 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1422 | - * @return array |
|
| 1423 | - */ |
|
| 1424 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
| 1425 | - { |
|
| 1426 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1427 | - } |
|
| 22 | + /** |
|
| 23 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 24 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 25 | + */ |
|
| 26 | + const req_type_normal = 0; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Indicates this is a brand new installation of EE so we should install |
|
| 30 | + * tables and default data etc |
|
| 31 | + */ |
|
| 32 | + const req_type_new_activation = 1; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 36 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 37 | + * and that default data is setup too |
|
| 38 | + */ |
|
| 39 | + const req_type_reactivation = 2; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * indicates that EE has been upgraded since its previous request. |
|
| 43 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 44 | + */ |
|
| 45 | + const req_type_upgrade = 3; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 49 | + */ |
|
| 50 | + const req_type_downgrade = 4; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @deprecated since version 4.6.0.dev.006 |
|
| 54 | + * Now whenever a new_activation is detected the request type is still just |
|
| 55 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
| 56 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 57 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 58 | + * (Specifically, when the migration manager indicates migrations are finished |
|
| 59 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 60 | + */ |
|
| 61 | + const req_type_activation_but_not_installed = 5; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 65 | + */ |
|
| 66 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * instance of the EE_System object |
|
| 71 | + * |
|
| 72 | + * @var $_instance |
|
| 73 | + * @access private |
|
| 74 | + */ |
|
| 75 | + private static $_instance = null; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @type EE_Registry $Registry |
|
| 79 | + * @access protected |
|
| 80 | + */ |
|
| 81 | + protected $registry; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 85 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 86 | + * |
|
| 87 | + * @var int |
|
| 88 | + */ |
|
| 89 | + private $_req_type; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
| 93 | + * |
|
| 94 | + * @var boolean |
|
| 95 | + */ |
|
| 96 | + private $_major_version_change = false; |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @singleton method used to instantiate class object |
|
| 102 | + * @access public |
|
| 103 | + * @param \EE_Registry $Registry |
|
| 104 | + * @return \EE_System |
|
| 105 | + */ |
|
| 106 | + public static function instance(EE_Registry $Registry = null) |
|
| 107 | + { |
|
| 108 | + // check if class object is instantiated |
|
| 109 | + if ( ! self::$_instance instanceof EE_System) { |
|
| 110 | + self::$_instance = new self($Registry); |
|
| 111 | + } |
|
| 112 | + return self::$_instance; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * resets the instance and returns it |
|
| 119 | + * |
|
| 120 | + * @return EE_System |
|
| 121 | + */ |
|
| 122 | + public static function reset() |
|
| 123 | + { |
|
| 124 | + self::$_instance->_req_type = null; |
|
| 125 | + //make sure none of the old hooks are left hanging around |
|
| 126 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 127 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
| 128 | + EE_Data_Migration_Manager::reset(); |
|
| 129 | + self::instance()->detect_activations_or_upgrades(); |
|
| 130 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 131 | + return self::instance(); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * sets hooks for running rest of system |
|
| 138 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 139 | + * starting EE Addons from any other point may lead to problems |
|
| 140 | + * |
|
| 141 | + * @access private |
|
| 142 | + * @param \EE_Registry $Registry |
|
| 143 | + */ |
|
| 144 | + private function __construct(EE_Registry $Registry) |
|
| 145 | + { |
|
| 146 | + $this->registry = $Registry; |
|
| 147 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
| 148 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 149 | + add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
| 150 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
| 151 | + // because the newly-activated addon didn't get a chance to run at all |
|
| 152 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
| 153 | + // detect whether install or upgrade |
|
| 154 | + add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
| 155 | + 3); |
|
| 156 | + // load EE_Config, EE_Textdomain, etc |
|
| 157 | + add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
| 158 | + // load EE_Config, EE_Textdomain, etc |
|
| 159 | + add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 160 | + array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
| 161 | + // you wanna get going? I wanna get going... let's get going! |
|
| 162 | + add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
| 163 | + //other housekeeping |
|
| 164 | + //exclude EE critical pages from wp_list_pages |
|
| 165 | + add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
| 166 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 167 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 168 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * load_espresso_addons |
|
| 175 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 176 | + * this is hooked into both: |
|
| 177 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 178 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 179 | + * and the WP 'activate_plugin' hookpoint |
|
| 180 | + * |
|
| 181 | + * @access public |
|
| 182 | + * @return void |
|
| 183 | + */ |
|
| 184 | + public function load_espresso_addons() |
|
| 185 | + { |
|
| 186 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
| 187 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
| 188 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 189 | + //load and setup EE_Capabilities |
|
| 190 | + $this->registry->load_core('Capabilities'); |
|
| 191 | + //caps need to be initialized on every request so that capability maps are set. |
|
| 192 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 193 | + $this->registry->CAP->init_caps(); |
|
| 194 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
| 195 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
| 196 | + //We want it for mobile apps. Just include the entire plugin |
|
| 197 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
| 198 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
| 199 | + //and causes a fatal error |
|
| 200 | + if ( ! function_exists('json_basic_auth_handler') |
|
| 201 | + && ! function_exists('json_basic_auth_error') |
|
| 202 | + && ! ( |
|
| 203 | + isset($_GET['action']) |
|
| 204 | + && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
| 205 | + ) |
|
| 206 | + && ! ( |
|
| 207 | + isset($_GET['activate']) |
|
| 208 | + && $_GET['activate'] === 'true' |
|
| 209 | + ) |
|
| 210 | + ) { |
|
| 211 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 212 | + } |
|
| 213 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * detect_activations_or_upgrades |
|
| 220 | + * Checks for activation or upgrade of core first; |
|
| 221 | + * then also checks if any registered addons have been activated or upgraded |
|
| 222 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 223 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 224 | + * |
|
| 225 | + * @access public |
|
| 226 | + * @return void |
|
| 227 | + */ |
|
| 228 | + public function detect_activations_or_upgrades() |
|
| 229 | + { |
|
| 230 | + //first off: let's make sure to handle core |
|
| 231 | + $this->detect_if_activation_or_upgrade(); |
|
| 232 | + foreach ($this->registry->addons as $addon) { |
|
| 233 | + //detect teh request type for that addon |
|
| 234 | + $addon->detect_activation_or_upgrade(); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * detect_if_activation_or_upgrade |
|
| 242 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 243 | + * and either setting up the DB or setting up maintenance mode etc. |
|
| 244 | + * |
|
| 245 | + * @access public |
|
| 246 | + * @return void |
|
| 247 | + */ |
|
| 248 | + public function detect_if_activation_or_upgrade() |
|
| 249 | + { |
|
| 250 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 251 | + // load M-Mode class |
|
| 252 | + $this->registry->load_core('Maintenance_Mode'); |
|
| 253 | + // check if db has been updated, or if its a brand-new installation |
|
| 254 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 255 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
| 256 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 257 | + switch ($request_type) { |
|
| 258 | + case EE_System::req_type_new_activation: |
|
| 259 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 260 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 261 | + break; |
|
| 262 | + case EE_System::req_type_reactivation: |
|
| 263 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 264 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 265 | + break; |
|
| 266 | + case EE_System::req_type_upgrade: |
|
| 267 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 268 | + //migrations may be required now that we've upgraded |
|
| 269 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 270 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 271 | + // echo "done upgrade";die; |
|
| 272 | + break; |
|
| 273 | + case EE_System::req_type_downgrade: |
|
| 274 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 275 | + //its possible migrations are no longer required |
|
| 276 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 277 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 278 | + break; |
|
| 279 | + case EE_System::req_type_normal: |
|
| 280 | + default: |
|
| 281 | + // $this->_maybe_redirect_to_ee_about(); |
|
| 282 | + break; |
|
| 283 | + } |
|
| 284 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Updates the list of installed versions and sets hooks for |
|
| 291 | + * initializing the database later during the request |
|
| 292 | + * |
|
| 293 | + * @param array $espresso_db_update |
|
| 294 | + */ |
|
| 295 | + protected function _handle_core_version_change($espresso_db_update) |
|
| 296 | + { |
|
| 297 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
| 298 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 299 | + add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 300 | + array($this, 'initialize_db_if_no_migrations_required')); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 307 | + * information about what versions of EE have been installed and activated, |
|
| 308 | + * NOT necessarily the state of the database |
|
| 309 | + * |
|
| 310 | + * @param null $espresso_db_update |
|
| 311 | + * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
| 312 | + * from the options table |
|
| 313 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 314 | + */ |
|
| 315 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
| 316 | + { |
|
| 317 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 318 | + if ( ! $espresso_db_update) { |
|
| 319 | + $espresso_db_update = get_option('espresso_db_update'); |
|
| 320 | + } |
|
| 321 | + // check that option is an array |
|
| 322 | + if ( ! is_array($espresso_db_update)) { |
|
| 323 | + // if option is FALSE, then it never existed |
|
| 324 | + if ($espresso_db_update === false) { |
|
| 325 | + // make $espresso_db_update an array and save option with autoload OFF |
|
| 326 | + $espresso_db_update = array(); |
|
| 327 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 328 | + } else { |
|
| 329 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 330 | + $espresso_db_update = array($espresso_db_update => array()); |
|
| 331 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 332 | + } |
|
| 333 | + } else { |
|
| 334 | + $corrected_db_update = array(); |
|
| 335 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 336 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 337 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 338 | + //the key is an int, and the value IS NOT an array |
|
| 339 | + //so it must be numerically-indexed, where values are versions installed... |
|
| 340 | + //fix it! |
|
| 341 | + $version_string = $should_be_array; |
|
| 342 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
| 343 | + } else { |
|
| 344 | + //ok it checks out |
|
| 345 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + $espresso_db_update = $corrected_db_update; |
|
| 349 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 350 | + } |
|
| 351 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 352 | + return $espresso_db_update; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 359 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 360 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 361 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 362 | + * so that it will be done when migrations are finished |
|
| 363 | + * |
|
| 364 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 365 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 366 | + * This is a resource-intensive job |
|
| 367 | + * so we prefer to only do it when necessary |
|
| 368 | + * @return void |
|
| 369 | + */ |
|
| 370 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 371 | + { |
|
| 372 | + $request_type = $this->detect_req_type(); |
|
| 373 | + //only initialize system if we're not in maintenance mode. |
|
| 374 | + if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 375 | + update_option('ee_flush_rewrite_rules', true); |
|
| 376 | + if ($verify_schema) { |
|
| 377 | + EEH_Activation::initialize_db_and_folders(); |
|
| 378 | + } |
|
| 379 | + EEH_Activation::initialize_db_content(); |
|
| 380 | + EEH_Activation::system_initialization(); |
|
| 381 | + if ($initialize_addons_too) { |
|
| 382 | + $this->initialize_addons(); |
|
| 383 | + } |
|
| 384 | + } else { |
|
| 385 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 386 | + } |
|
| 387 | + if ($request_type === EE_System::req_type_new_activation |
|
| 388 | + || $request_type === EE_System::req_type_reactivation |
|
| 389 | + || ( |
|
| 390 | + $request_type === EE_System::req_type_upgrade |
|
| 391 | + && $this->is_major_version_change() |
|
| 392 | + ) |
|
| 393 | + ) { |
|
| 394 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * Initializes the db for all registered addons |
|
| 402 | + */ |
|
| 403 | + public function initialize_addons() |
|
| 404 | + { |
|
| 405 | + //foreach registered addon, make sure its db is up-to-date too |
|
| 406 | + foreach ($this->registry->addons as $addon) { |
|
| 407 | + $addon->initialize_db_if_no_migrations_required(); |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 415 | + * |
|
| 416 | + * @param array $version_history |
|
| 417 | + * @param string $current_version_to_add version to be added to the version history |
|
| 418 | + * @return boolean success as to whether or not this option was changed |
|
| 419 | + */ |
|
| 420 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 421 | + { |
|
| 422 | + if ( ! $version_history) { |
|
| 423 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 424 | + } |
|
| 425 | + if ($current_version_to_add == null) { |
|
| 426 | + $current_version_to_add = espresso_version(); |
|
| 427 | + } |
|
| 428 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
| 429 | + // re-save |
|
| 430 | + return update_option('espresso_db_update', $version_history); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Detects if the current version indicated in the has existed in the list of |
|
| 437 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 438 | + * |
|
| 439 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 440 | + * If not supplied, fetches it from the options table. |
|
| 441 | + * Also, caches its result so later parts of the code can also know whether |
|
| 442 | + * there's been an update or not. This way we can add the current version to |
|
| 443 | + * espresso_db_update, but still know if this is a new install or not |
|
| 444 | + * @return int one of the constants on EE_System::req_type_ |
|
| 445 | + */ |
|
| 446 | + public function detect_req_type($espresso_db_update = null) |
|
| 447 | + { |
|
| 448 | + if ($this->_req_type === null) { |
|
| 449 | + $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
| 450 | + : $this->fix_espresso_db_upgrade_option(); |
|
| 451 | + $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
| 452 | + 'ee_espresso_activation', espresso_version()); |
|
| 453 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
| 454 | + } |
|
| 455 | + return $this->_req_type; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
| 462 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
| 463 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 464 | + * |
|
| 465 | + * @param $activation_history |
|
| 466 | + * @return bool |
|
| 467 | + */ |
|
| 468 | + protected function _detect_major_version_change($activation_history) |
|
| 469 | + { |
|
| 470 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
| 471 | + $previous_version_parts = explode('.', $previous_version); |
|
| 472 | + $current_version_parts = explode('.', espresso_version()); |
|
| 473 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
| 474 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
| 475 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
| 476 | + ); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * Returns true if either the major or minor version of EE changed during this request. |
|
| 483 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 484 | + * |
|
| 485 | + * @return bool |
|
| 486 | + */ |
|
| 487 | + public function is_major_version_change() |
|
| 488 | + { |
|
| 489 | + return $this->_major_version_change; |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 496 | + * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
| 497 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 498 | + * just activated to (for core that will always be espresso_version()) |
|
| 499 | + * |
|
| 500 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
| 501 | + * ee plugin. for core that's 'espresso_db_update' |
|
| 502 | + * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
| 503 | + * indicate that this plugin was just activated |
|
| 504 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
| 505 | + * espresso_version()) |
|
| 506 | + * @return int one of the constants on EE_System::req_type_* |
|
| 507 | + */ |
|
| 508 | + public static function detect_req_type_given_activation_history( |
|
| 509 | + $activation_history_for_addon, |
|
| 510 | + $activation_indicator_option_name, |
|
| 511 | + $version_to_upgrade_to |
|
| 512 | + ) { |
|
| 513 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
| 514 | + if ($activation_history_for_addon) { |
|
| 515 | + //it exists, so this isn't a completely new install |
|
| 516 | + //check if this version already in that list of previously installed versions |
|
| 517 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 518 | + //it a version we haven't seen before |
|
| 519 | + if ($version_is_higher === 1) { |
|
| 520 | + $req_type = EE_System::req_type_upgrade; |
|
| 521 | + } else { |
|
| 522 | + $req_type = EE_System::req_type_downgrade; |
|
| 523 | + } |
|
| 524 | + delete_option($activation_indicator_option_name); |
|
| 525 | + } else { |
|
| 526 | + // its not an update. maybe a reactivation? |
|
| 527 | + if (get_option($activation_indicator_option_name, false)) { |
|
| 528 | + if ($version_is_higher === -1) { |
|
| 529 | + $req_type = EE_System::req_type_downgrade; |
|
| 530 | + } elseif ($version_is_higher === 0) { |
|
| 531 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
| 532 | + $req_type = EE_System::req_type_reactivation; |
|
| 533 | + } else {//$version_is_higher === 1 |
|
| 534 | + $req_type = EE_System::req_type_upgrade; |
|
| 535 | + } |
|
| 536 | + delete_option($activation_indicator_option_name); |
|
| 537 | + } else { |
|
| 538 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
| 539 | + if ($version_is_higher === -1) { |
|
| 540 | + $req_type = EE_System::req_type_downgrade; |
|
| 541 | + } elseif ($version_is_higher === 0) { |
|
| 542 | + //we've seen this version before and it's not an activation. its normal request |
|
| 543 | + $req_type = EE_System::req_type_normal; |
|
| 544 | + } else {//$version_is_higher === 1 |
|
| 545 | + $req_type = EE_System::req_type_upgrade; |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + } else { |
|
| 550 | + //brand new install |
|
| 551 | + $req_type = EE_System::req_type_new_activation; |
|
| 552 | + delete_option($activation_indicator_option_name); |
|
| 553 | + } |
|
| 554 | + return $req_type; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 561 | + * the $activation_history_for_addon |
|
| 562 | + * |
|
| 563 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
| 564 | + * sometimes containing 'unknown-date' |
|
| 565 | + * @param string $version_to_upgrade_to (current version) |
|
| 566 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 567 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 568 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 569 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 570 | + */ |
|
| 571 | + protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
| 572 | + { |
|
| 573 | + //find the most recently-activated version |
|
| 574 | + $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
| 575 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Gets the most recently active version listed in the activation history, |
|
| 582 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
| 583 | + * |
|
| 584 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
| 585 | + * sometimes containing 'unknown-date' |
|
| 586 | + * @return string |
|
| 587 | + */ |
|
| 588 | + protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
| 589 | + { |
|
| 590 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
| 591 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
| 592 | + if (is_array($activation_history)) { |
|
| 593 | + foreach ($activation_history as $version => $times_activated) { |
|
| 594 | + //check there is a record of when this version was activated. Otherwise, |
|
| 595 | + //mark it as unknown |
|
| 596 | + if ( ! $times_activated) { |
|
| 597 | + $times_activated = array('unknown-date'); |
|
| 598 | + } |
|
| 599 | + if (is_string($times_activated)) { |
|
| 600 | + $times_activated = array($times_activated); |
|
| 601 | + } |
|
| 602 | + foreach ($times_activated as $an_activation) { |
|
| 603 | + if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
| 604 | + $most_recently_active_version = $version; |
|
| 605 | + $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
| 606 | + ? '1970-01-01 00:00:00' : $an_activation; |
|
| 607 | + } |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | + return $most_recently_active_version; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * This redirects to the about EE page after activation |
|
| 618 | + * |
|
| 619 | + * @return void |
|
| 620 | + */ |
|
| 621 | + public function redirect_to_about_ee() |
|
| 622 | + { |
|
| 623 | + $notices = EE_Error::get_notices(false); |
|
| 624 | + //if current user is an admin and it's not an ajax or rest request |
|
| 625 | + if ( |
|
| 626 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 627 | + && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
| 628 | + && ! isset($notices['errors']) |
|
| 629 | + && apply_filters( |
|
| 630 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
| 631 | + $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
| 632 | + ) |
|
| 633 | + ) { |
|
| 634 | + $query_params = array('page' => 'espresso_about'); |
|
| 635 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
| 636 | + $query_params['new_activation'] = true; |
|
| 637 | + } |
|
| 638 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
| 639 | + $query_params['reactivation'] = true; |
|
| 640 | + } |
|
| 641 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 642 | + wp_safe_redirect($url); |
|
| 643 | + exit(); |
|
| 644 | + } |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * load_core_configuration |
|
| 651 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 652 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 653 | + * |
|
| 654 | + * @return void |
|
| 655 | + */ |
|
| 656 | + public function load_core_configuration() |
|
| 657 | + { |
|
| 658 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 659 | + $this->registry->load_core('EE_Load_Textdomain'); |
|
| 660 | + //load textdomain |
|
| 661 | + EE_Load_Textdomain::load_textdomain(); |
|
| 662 | + // load and setup EE_Config and EE_Network_Config |
|
| 663 | + $this->registry->load_core('Config'); |
|
| 664 | + $this->registry->load_core('Network_Config'); |
|
| 665 | + // setup autoloaders |
|
| 666 | + // enable logging? |
|
| 667 | + if ($this->registry->CFG->admin->use_full_logging) { |
|
| 668 | + $this->registry->load_core('Log'); |
|
| 669 | + } |
|
| 670 | + // check for activation errors |
|
| 671 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 672 | + if ($activation_errors) { |
|
| 673 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 674 | + update_option('ee_plugin_activation_errors', false); |
|
| 675 | + } |
|
| 676 | + // get model names |
|
| 677 | + $this->_parse_model_names(); |
|
| 678 | + //load caf stuff a chance to play during the activation process too. |
|
| 679 | + $this->_maybe_brew_regular(); |
|
| 680 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 687 | + * |
|
| 688 | + * @return void |
|
| 689 | + */ |
|
| 690 | + private function _parse_model_names() |
|
| 691 | + { |
|
| 692 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
| 693 | + $models = glob(EE_MODELS . '*.model.php'); |
|
| 694 | + $model_names = array(); |
|
| 695 | + $non_abstract_db_models = array(); |
|
| 696 | + foreach ($models as $model) { |
|
| 697 | + // get model classname |
|
| 698 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 699 | + $short_name = str_replace('EEM_', '', $classname); |
|
| 700 | + $reflectionClass = new ReflectionClass($classname); |
|
| 701 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 702 | + $non_abstract_db_models[$short_name] = $classname; |
|
| 703 | + } |
|
| 704 | + $model_names[$short_name] = $classname; |
|
| 705 | + } |
|
| 706 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 707 | + $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
| 708 | + $non_abstract_db_models); |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 715 | + * that need to be setup before our EE_System launches. |
|
| 716 | + * |
|
| 717 | + * @return void |
|
| 718 | + */ |
|
| 719 | + private function _maybe_brew_regular() |
|
| 720 | + { |
|
| 721 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 722 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 723 | + } |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + |
|
| 727 | + |
|
| 728 | + /** |
|
| 729 | + * register_shortcodes_modules_and_widgets |
|
| 730 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
| 731 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 732 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 733 | + * |
|
| 734 | + * @access public |
|
| 735 | + * @return void |
|
| 736 | + */ |
|
| 737 | + public function register_shortcodes_modules_and_widgets() |
|
| 738 | + { |
|
| 739 | + try { |
|
| 740 | + // load, register, and add shortcodes the new way |
|
| 741 | + new ShortcodesManager( |
|
| 742 | + // and the old way, but we'll put it under control of the new system |
|
| 743 | + EE_Config::getLegacyShortcodesManager() |
|
| 744 | + ); |
|
| 745 | + } catch (Exception $exception) { |
|
| 746 | + new ExceptionStackTraceDisplay($exception); |
|
| 747 | + } |
|
| 748 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 749 | + // check for addons using old hookpoint |
|
| 750 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 751 | + $this->_incompatible_addon_error(); |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + /** |
|
| 758 | + * _incompatible_addon_error |
|
| 759 | + * |
|
| 760 | + * @access public |
|
| 761 | + * @return void |
|
| 762 | + */ |
|
| 763 | + private function _incompatible_addon_error() |
|
| 764 | + { |
|
| 765 | + // get array of classes hooking into here |
|
| 766 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
| 767 | + if ( ! empty($class_names)) { |
|
| 768 | + $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 769 | + 'event_espresso'); |
|
| 770 | + $msg .= '<ul>'; |
|
| 771 | + foreach ($class_names as $class_name) { |
|
| 772 | + $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 773 | + $class_name) . '</b></li>'; |
|
| 774 | + } |
|
| 775 | + $msg .= '</ul>'; |
|
| 776 | + $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 777 | + 'event_espresso'); |
|
| 778 | + // save list of incompatible addons to wp-options for later use |
|
| 779 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 780 | + if (is_admin()) { |
|
| 781 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + |
|
| 787 | + |
|
| 788 | + /** |
|
| 789 | + * brew_espresso |
|
| 790 | + * begins the process of setting hooks for initializing EE in the correct order |
|
| 791 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
| 792 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 793 | + * |
|
| 794 | + * @return void |
|
| 795 | + */ |
|
| 796 | + public function brew_espresso() |
|
| 797 | + { |
|
| 798 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 799 | + // load some final core systems |
|
| 800 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
| 801 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
| 802 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
| 803 | + add_action('init', array($this, 'load_controllers'), 7); |
|
| 804 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
| 805 | + add_action('init', array($this, 'initialize'), 10); |
|
| 806 | + add_action('init', array($this, 'initialize_last'), 100); |
|
| 807 | + add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
| 808 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
| 809 | + // pew pew pew |
|
| 810 | + $this->registry->load_core('PUE'); |
|
| 811 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
| 812 | + } |
|
| 813 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + |
|
| 817 | + |
|
| 818 | + /** |
|
| 819 | + * set_hooks_for_core |
|
| 820 | + * |
|
| 821 | + * @access public |
|
| 822 | + * @return void |
|
| 823 | + */ |
|
| 824 | + public function set_hooks_for_core() |
|
| 825 | + { |
|
| 826 | + $this->_deactivate_incompatible_addons(); |
|
| 827 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + |
|
| 831 | + |
|
| 832 | + /** |
|
| 833 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 834 | + * deactivates any addons considered incompatible with the current version of EE |
|
| 835 | + */ |
|
| 836 | + private function _deactivate_incompatible_addons() |
|
| 837 | + { |
|
| 838 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
| 839 | + if ( ! empty($incompatible_addons)) { |
|
| 840 | + $active_plugins = get_option('active_plugins', array()); |
|
| 841 | + foreach ($active_plugins as $active_plugin) { |
|
| 842 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
| 843 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 844 | + unset($_GET['activate']); |
|
| 845 | + espresso_deactivate_plugin($active_plugin); |
|
| 846 | + } |
|
| 847 | + } |
|
| 848 | + } |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + |
|
| 853 | + |
|
| 854 | + /** |
|
| 855 | + * perform_activations_upgrades_and_migrations |
|
| 856 | + * |
|
| 857 | + * @access public |
|
| 858 | + * @return void |
|
| 859 | + */ |
|
| 860 | + public function perform_activations_upgrades_and_migrations() |
|
| 861 | + { |
|
| 862 | + //first check if we had previously attempted to setup EE's directories but failed |
|
| 863 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
| 864 | + EEH_Activation::create_upload_directories(); |
|
| 865 | + } |
|
| 866 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + |
|
| 870 | + |
|
| 871 | + /** |
|
| 872 | + * load_CPTs_and_session |
|
| 873 | + * |
|
| 874 | + * @access public |
|
| 875 | + * @return void |
|
| 876 | + */ |
|
| 877 | + public function load_CPTs_and_session() |
|
| 878 | + { |
|
| 879 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 880 | + // register Custom Post Types |
|
| 881 | + $this->registry->load_core('Register_CPTs'); |
|
| 882 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + |
|
| 886 | + |
|
| 887 | + /** |
|
| 888 | + * load_controllers |
|
| 889 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
| 890 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 891 | + * time |
|
| 892 | + * |
|
| 893 | + * @access public |
|
| 894 | + * @return void |
|
| 895 | + */ |
|
| 896 | + public function load_controllers() |
|
| 897 | + { |
|
| 898 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
| 899 | + // let's get it started |
|
| 900 | + if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
| 901 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 902 | + $this->registry->load_core('Front_Controller'); |
|
| 903 | + } else if ( ! EE_FRONT_AJAX) { |
|
| 904 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
| 905 | + EE_Registry::instance()->load_core('Admin'); |
|
| 906 | + } |
|
| 907 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + |
|
| 911 | + |
|
| 912 | + /** |
|
| 913 | + * core_loaded_and_ready |
|
| 914 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 915 | + * |
|
| 916 | + * @access public |
|
| 917 | + * @return void |
|
| 918 | + */ |
|
| 919 | + public function core_loaded_and_ready() |
|
| 920 | + { |
|
| 921 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 922 | + // load_espresso_template_tags |
|
| 923 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 924 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 925 | + } |
|
| 926 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 927 | + $this->registry->load_core('Session'); |
|
| 928 | + $this->registry->create('EventEspresso\core\services\assets\Registry'); |
|
| 929 | + wp_enqueue_script('espresso_core'); |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * initialize |
|
| 936 | + * this is the best place to begin initializing client code |
|
| 937 | + * |
|
| 938 | + * @access public |
|
| 939 | + * @return void |
|
| 940 | + */ |
|
| 941 | + public function initialize() |
|
| 942 | + { |
|
| 943 | + do_action('AHEE__EE_System__initialize'); |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + |
|
| 947 | + |
|
| 948 | + /** |
|
| 949 | + * initialize_last |
|
| 950 | + * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
| 951 | + * initialize has done so |
|
| 952 | + * |
|
| 953 | + * @access public |
|
| 954 | + * @return void |
|
| 955 | + */ |
|
| 956 | + public function initialize_last() |
|
| 957 | + { |
|
| 958 | + do_action('AHEE__EE_System__initialize_last'); |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + |
|
| 962 | + |
|
| 963 | + /** |
|
| 964 | + * set_hooks_for_shortcodes_modules_and_addons |
|
| 965 | + * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
| 966 | + * this happens at the very beginning of the wp_loaded hookpoint |
|
| 967 | + * |
|
| 968 | + * @access public |
|
| 969 | + * @return void |
|
| 970 | + */ |
|
| 971 | + public function set_hooks_for_shortcodes_modules_and_addons() |
|
| 972 | + { |
|
| 973 | + // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + /** |
|
| 979 | + * do_not_cache |
|
| 980 | + * sets no cache headers and defines no cache constants for WP plugins |
|
| 981 | + * |
|
| 982 | + * @access public |
|
| 983 | + * @return void |
|
| 984 | + */ |
|
| 985 | + public static function do_not_cache() |
|
| 986 | + { |
|
| 987 | + // set no cache constants |
|
| 988 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
| 989 | + define('DONOTCACHEPAGE', true); |
|
| 990 | + } |
|
| 991 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
| 992 | + define('DONOTCACHCEOBJECT', true); |
|
| 993 | + } |
|
| 994 | + if ( ! defined('DONOTCACHEDB')) { |
|
| 995 | + define('DONOTCACHEDB', true); |
|
| 996 | + } |
|
| 997 | + // add no cache headers |
|
| 998 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
| 999 | + // plus a little extra for nginx and Google Chrome |
|
| 1000 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
| 1001 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 1002 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + |
|
| 1006 | + |
|
| 1007 | + /** |
|
| 1008 | + * extra_nocache_headers |
|
| 1009 | + * |
|
| 1010 | + * @access public |
|
| 1011 | + * @param $headers |
|
| 1012 | + * @return array |
|
| 1013 | + */ |
|
| 1014 | + public static function extra_nocache_headers($headers) |
|
| 1015 | + { |
|
| 1016 | + // for NGINX |
|
| 1017 | + $headers['X-Accel-Expires'] = 0; |
|
| 1018 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 1019 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 1020 | + return $headers; |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + |
|
| 1024 | + |
|
| 1025 | + /** |
|
| 1026 | + * nocache_headers |
|
| 1027 | + * |
|
| 1028 | + * @access public |
|
| 1029 | + * @return void |
|
| 1030 | + */ |
|
| 1031 | + public static function nocache_headers() |
|
| 1032 | + { |
|
| 1033 | + nocache_headers(); |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + |
|
| 1037 | + |
|
| 1038 | + /** |
|
| 1039 | + * espresso_toolbar_items |
|
| 1040 | + * |
|
| 1041 | + * @access public |
|
| 1042 | + * @param WP_Admin_Bar $admin_bar |
|
| 1043 | + * @return void |
|
| 1044 | + */ |
|
| 1045 | + public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
| 1046 | + { |
|
| 1047 | + // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
| 1048 | + if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1049 | + || defined('DOING_AJAX') |
|
| 1050 | + || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
| 1051 | + ) { |
|
| 1052 | + return; |
|
| 1053 | + } |
|
| 1054 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1055 | + $menu_class = 'espresso_menu_item_class'; |
|
| 1056 | + //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
| 1057 | + //because they're only defined in each of their respective constructors |
|
| 1058 | + //and this might be a frontend request, in which case they aren't available |
|
| 1059 | + $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
| 1060 | + $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
| 1061 | + $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
| 1062 | + //Top Level |
|
| 1063 | + $admin_bar->add_menu(array( |
|
| 1064 | + 'id' => 'espresso-toolbar', |
|
| 1065 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
| 1066 | + . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
| 1067 | + . '</span>', |
|
| 1068 | + 'href' => $events_admin_url, |
|
| 1069 | + 'meta' => array( |
|
| 1070 | + 'title' => __('Event Espresso', 'event_espresso'), |
|
| 1071 | + 'class' => $menu_class . 'first', |
|
| 1072 | + ), |
|
| 1073 | + )); |
|
| 1074 | + //Events |
|
| 1075 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
| 1076 | + $admin_bar->add_menu(array( |
|
| 1077 | + 'id' => 'espresso-toolbar-events', |
|
| 1078 | + 'parent' => 'espresso-toolbar', |
|
| 1079 | + 'title' => __('Events', 'event_espresso'), |
|
| 1080 | + 'href' => $events_admin_url, |
|
| 1081 | + 'meta' => array( |
|
| 1082 | + 'title' => __('Events', 'event_espresso'), |
|
| 1083 | + 'target' => '', |
|
| 1084 | + 'class' => $menu_class, |
|
| 1085 | + ), |
|
| 1086 | + )); |
|
| 1087 | + } |
|
| 1088 | + if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
| 1089 | + //Events Add New |
|
| 1090 | + $admin_bar->add_menu(array( |
|
| 1091 | + 'id' => 'espresso-toolbar-events-new', |
|
| 1092 | + 'parent' => 'espresso-toolbar-events', |
|
| 1093 | + 'title' => __('Add New', 'event_espresso'), |
|
| 1094 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
| 1095 | + 'meta' => array( |
|
| 1096 | + 'title' => __('Add New', 'event_espresso'), |
|
| 1097 | + 'target' => '', |
|
| 1098 | + 'class' => $menu_class, |
|
| 1099 | + ), |
|
| 1100 | + )); |
|
| 1101 | + } |
|
| 1102 | + if (is_single() && (get_post_type() == 'espresso_events')) { |
|
| 1103 | + //Current post |
|
| 1104 | + global $post; |
|
| 1105 | + if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
| 1106 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
| 1107 | + ) { |
|
| 1108 | + //Events Edit Current Event |
|
| 1109 | + $admin_bar->add_menu(array( |
|
| 1110 | + 'id' => 'espresso-toolbar-events-edit', |
|
| 1111 | + 'parent' => 'espresso-toolbar-events', |
|
| 1112 | + 'title' => __('Edit Event', 'event_espresso'), |
|
| 1113 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
| 1114 | + $events_admin_url), |
|
| 1115 | + 'meta' => array( |
|
| 1116 | + 'title' => __('Edit Event', 'event_espresso'), |
|
| 1117 | + 'target' => '', |
|
| 1118 | + 'class' => $menu_class, |
|
| 1119 | + ), |
|
| 1120 | + )); |
|
| 1121 | + } |
|
| 1122 | + } |
|
| 1123 | + //Events View |
|
| 1124 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1125 | + 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
| 1126 | + ) { |
|
| 1127 | + $admin_bar->add_menu(array( |
|
| 1128 | + 'id' => 'espresso-toolbar-events-view', |
|
| 1129 | + 'parent' => 'espresso-toolbar-events', |
|
| 1130 | + 'title' => __('View', 'event_espresso'), |
|
| 1131 | + 'href' => $events_admin_url, |
|
| 1132 | + 'meta' => array( |
|
| 1133 | + 'title' => __('View', 'event_espresso'), |
|
| 1134 | + 'target' => '', |
|
| 1135 | + 'class' => $menu_class, |
|
| 1136 | + ), |
|
| 1137 | + )); |
|
| 1138 | + } |
|
| 1139 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
| 1140 | + //Events View All |
|
| 1141 | + $admin_bar->add_menu(array( |
|
| 1142 | + 'id' => 'espresso-toolbar-events-all', |
|
| 1143 | + 'parent' => 'espresso-toolbar-events-view', |
|
| 1144 | + 'title' => __('All', 'event_espresso'), |
|
| 1145 | + 'href' => $events_admin_url, |
|
| 1146 | + 'meta' => array( |
|
| 1147 | + 'title' => __('All', 'event_espresso'), |
|
| 1148 | + 'target' => '', |
|
| 1149 | + 'class' => $menu_class, |
|
| 1150 | + ), |
|
| 1151 | + )); |
|
| 1152 | + } |
|
| 1153 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1154 | + 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
| 1155 | + ) { |
|
| 1156 | + //Events View Today |
|
| 1157 | + $admin_bar->add_menu(array( |
|
| 1158 | + 'id' => 'espresso-toolbar-events-today', |
|
| 1159 | + 'parent' => 'espresso-toolbar-events-view', |
|
| 1160 | + 'title' => __('Today', 'event_espresso'), |
|
| 1161 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1162 | + $events_admin_url), |
|
| 1163 | + 'meta' => array( |
|
| 1164 | + 'title' => __('Today', 'event_espresso'), |
|
| 1165 | + 'target' => '', |
|
| 1166 | + 'class' => $menu_class, |
|
| 1167 | + ), |
|
| 1168 | + )); |
|
| 1169 | + } |
|
| 1170 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1171 | + 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
| 1172 | + ) { |
|
| 1173 | + //Events View This Month |
|
| 1174 | + $admin_bar->add_menu(array( |
|
| 1175 | + 'id' => 'espresso-toolbar-events-month', |
|
| 1176 | + 'parent' => 'espresso-toolbar-events-view', |
|
| 1177 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1178 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1179 | + $events_admin_url), |
|
| 1180 | + 'meta' => array( |
|
| 1181 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1182 | + 'target' => '', |
|
| 1183 | + 'class' => $menu_class, |
|
| 1184 | + ), |
|
| 1185 | + )); |
|
| 1186 | + } |
|
| 1187 | + //Registration Overview |
|
| 1188 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1189 | + 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
| 1190 | + ) { |
|
| 1191 | + $admin_bar->add_menu(array( |
|
| 1192 | + 'id' => 'espresso-toolbar-registrations', |
|
| 1193 | + 'parent' => 'espresso-toolbar', |
|
| 1194 | + 'title' => __('Registrations', 'event_espresso'), |
|
| 1195 | + 'href' => $reg_admin_url, |
|
| 1196 | + 'meta' => array( |
|
| 1197 | + 'title' => __('Registrations', 'event_espresso'), |
|
| 1198 | + 'target' => '', |
|
| 1199 | + 'class' => $menu_class, |
|
| 1200 | + ), |
|
| 1201 | + )); |
|
| 1202 | + } |
|
| 1203 | + //Registration Overview Today |
|
| 1204 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1205 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
| 1206 | + ) { |
|
| 1207 | + $admin_bar->add_menu(array( |
|
| 1208 | + 'id' => 'espresso-toolbar-registrations-today', |
|
| 1209 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 1210 | + 'title' => __('Today', 'event_espresso'), |
|
| 1211 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1212 | + $reg_admin_url), |
|
| 1213 | + 'meta' => array( |
|
| 1214 | + 'title' => __('Today', 'event_espresso'), |
|
| 1215 | + 'target' => '', |
|
| 1216 | + 'class' => $menu_class, |
|
| 1217 | + ), |
|
| 1218 | + )); |
|
| 1219 | + } |
|
| 1220 | + //Registration Overview Today Completed |
|
| 1221 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1222 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
| 1223 | + ) { |
|
| 1224 | + $admin_bar->add_menu(array( |
|
| 1225 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
| 1226 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1227 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1228 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1229 | + 'action' => 'default', |
|
| 1230 | + 'status' => 'today', |
|
| 1231 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1232 | + ), $reg_admin_url), |
|
| 1233 | + 'meta' => array( |
|
| 1234 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1235 | + 'target' => '', |
|
| 1236 | + 'class' => $menu_class, |
|
| 1237 | + ), |
|
| 1238 | + )); |
|
| 1239 | + } |
|
| 1240 | + //Registration Overview Today Pending\ |
|
| 1241 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1242 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
| 1243 | + ) { |
|
| 1244 | + $admin_bar->add_menu(array( |
|
| 1245 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
| 1246 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1247 | + 'title' => __('Pending', 'event_espresso'), |
|
| 1248 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1249 | + 'action' => 'default', |
|
| 1250 | + 'status' => 'today', |
|
| 1251 | + 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1252 | + ), $reg_admin_url), |
|
| 1253 | + 'meta' => array( |
|
| 1254 | + 'title' => __('Pending Payment', 'event_espresso'), |
|
| 1255 | + 'target' => '', |
|
| 1256 | + 'class' => $menu_class, |
|
| 1257 | + ), |
|
| 1258 | + )); |
|
| 1259 | + } |
|
| 1260 | + //Registration Overview Today Incomplete |
|
| 1261 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1262 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
| 1263 | + ) { |
|
| 1264 | + $admin_bar->add_menu(array( |
|
| 1265 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
| 1266 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1267 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1268 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1269 | + 'action' => 'default', |
|
| 1270 | + 'status' => 'today', |
|
| 1271 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1272 | + ), $reg_admin_url), |
|
| 1273 | + 'meta' => array( |
|
| 1274 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1275 | + 'target' => '', |
|
| 1276 | + 'class' => $menu_class, |
|
| 1277 | + ), |
|
| 1278 | + )); |
|
| 1279 | + } |
|
| 1280 | + //Registration Overview Today Incomplete |
|
| 1281 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1282 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
| 1283 | + ) { |
|
| 1284 | + $admin_bar->add_menu(array( |
|
| 1285 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
| 1286 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1287 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1288 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1289 | + 'action' => 'default', |
|
| 1290 | + 'status' => 'today', |
|
| 1291 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1292 | + ), $reg_admin_url), |
|
| 1293 | + 'meta' => array( |
|
| 1294 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1295 | + 'target' => '', |
|
| 1296 | + 'class' => $menu_class, |
|
| 1297 | + ), |
|
| 1298 | + )); |
|
| 1299 | + } |
|
| 1300 | + //Registration Overview This Month |
|
| 1301 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1302 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
| 1303 | + ) { |
|
| 1304 | + $admin_bar->add_menu(array( |
|
| 1305 | + 'id' => 'espresso-toolbar-registrations-month', |
|
| 1306 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 1307 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1308 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1309 | + $reg_admin_url), |
|
| 1310 | + 'meta' => array( |
|
| 1311 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1312 | + 'target' => '', |
|
| 1313 | + 'class' => $menu_class, |
|
| 1314 | + ), |
|
| 1315 | + )); |
|
| 1316 | + } |
|
| 1317 | + //Registration Overview This Month Approved |
|
| 1318 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1319 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
| 1320 | + ) { |
|
| 1321 | + $admin_bar->add_menu(array( |
|
| 1322 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
| 1323 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1324 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1325 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1326 | + 'action' => 'default', |
|
| 1327 | + 'status' => 'month', |
|
| 1328 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1329 | + ), $reg_admin_url), |
|
| 1330 | + 'meta' => array( |
|
| 1331 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1332 | + 'target' => '', |
|
| 1333 | + 'class' => $menu_class, |
|
| 1334 | + ), |
|
| 1335 | + )); |
|
| 1336 | + } |
|
| 1337 | + //Registration Overview This Month Pending |
|
| 1338 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1339 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
| 1340 | + ) { |
|
| 1341 | + $admin_bar->add_menu(array( |
|
| 1342 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
| 1343 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1344 | + 'title' => __('Pending', 'event_espresso'), |
|
| 1345 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1346 | + 'action' => 'default', |
|
| 1347 | + 'status' => 'month', |
|
| 1348 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1349 | + ), $reg_admin_url), |
|
| 1350 | + 'meta' => array( |
|
| 1351 | + 'title' => __('Pending', 'event_espresso'), |
|
| 1352 | + 'target' => '', |
|
| 1353 | + 'class' => $menu_class, |
|
| 1354 | + ), |
|
| 1355 | + )); |
|
| 1356 | + } |
|
| 1357 | + //Registration Overview This Month Not Approved |
|
| 1358 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1359 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
| 1360 | + ) { |
|
| 1361 | + $admin_bar->add_menu(array( |
|
| 1362 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
| 1363 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1364 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1365 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1366 | + 'action' => 'default', |
|
| 1367 | + 'status' => 'month', |
|
| 1368 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1369 | + ), $reg_admin_url), |
|
| 1370 | + 'meta' => array( |
|
| 1371 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1372 | + 'target' => '', |
|
| 1373 | + 'class' => $menu_class, |
|
| 1374 | + ), |
|
| 1375 | + )); |
|
| 1376 | + } |
|
| 1377 | + //Registration Overview This Month Cancelled |
|
| 1378 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1379 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
| 1380 | + ) { |
|
| 1381 | + $admin_bar->add_menu(array( |
|
| 1382 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
| 1383 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1384 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1385 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1386 | + 'action' => 'default', |
|
| 1387 | + 'status' => 'month', |
|
| 1388 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1389 | + ), $reg_admin_url), |
|
| 1390 | + 'meta' => array( |
|
| 1391 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1392 | + 'target' => '', |
|
| 1393 | + 'class' => $menu_class, |
|
| 1394 | + ), |
|
| 1395 | + )); |
|
| 1396 | + } |
|
| 1397 | + //Extensions & Services |
|
| 1398 | + if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
| 1399 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
| 1400 | + ) { |
|
| 1401 | + $admin_bar->add_menu(array( |
|
| 1402 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
| 1403 | + 'parent' => 'espresso-toolbar', |
|
| 1404 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1405 | + 'href' => $extensions_admin_url, |
|
| 1406 | + 'meta' => array( |
|
| 1407 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1408 | + 'target' => '', |
|
| 1409 | + 'class' => $menu_class, |
|
| 1410 | + ), |
|
| 1411 | + )); |
|
| 1412 | + } |
|
| 1413 | + } |
|
| 1414 | + |
|
| 1415 | + |
|
| 1416 | + |
|
| 1417 | + /** |
|
| 1418 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1419 | + * never returned with the function. |
|
| 1420 | + * |
|
| 1421 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1422 | + * @return array |
|
| 1423 | + */ |
|
| 1424 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
| 1425 | + { |
|
| 1426 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1427 | + } |
|
| 1428 | 1428 | |
| 1429 | 1429 | |
| 1430 | 1430 | |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | { |
| 186 | 186 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
| 187 | 187 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
| 188 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 188 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
| 189 | 189 | //load and setup EE_Capabilities |
| 190 | 190 | $this->registry->load_core('Capabilities'); |
| 191 | 191 | //caps need to be initialized on every request so that capability maps are set. |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | && $_GET['activate'] === 'true' |
| 209 | 209 | ) |
| 210 | 210 | ) { |
| 211 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 211 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php'; |
|
| 212 | 212 | } |
| 213 | 213 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
| 214 | 214 | } |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | private function _parse_model_names() |
| 691 | 691 | { |
| 692 | 692 | //get all the files in the EE_MODELS folder that end in .model.php |
| 693 | - $models = glob(EE_MODELS . '*.model.php'); |
|
| 693 | + $models = glob(EE_MODELS.'*.model.php'); |
|
| 694 | 694 | $model_names = array(); |
| 695 | 695 | $non_abstract_db_models = array(); |
| 696 | 696 | foreach ($models as $model) { |
@@ -718,8 +718,8 @@ discard block |
||
| 718 | 718 | */ |
| 719 | 719 | private function _maybe_brew_regular() |
| 720 | 720 | { |
| 721 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 722 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 721 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) { |
|
| 722 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
| 723 | 723 | } |
| 724 | 724 | } |
| 725 | 725 | |
@@ -769,8 +769,8 @@ discard block |
||
| 769 | 769 | 'event_espresso'); |
| 770 | 770 | $msg .= '<ul>'; |
| 771 | 771 | foreach ($class_names as $class_name) { |
| 772 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 773 | - $class_name) . '</b></li>'; |
|
| 772 | + $msg .= '<li><b>Event Espresso - '.str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 773 | + $class_name).'</b></li>'; |
|
| 774 | 774 | } |
| 775 | 775 | $msg .= '</ul>'; |
| 776 | 776 | $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
@@ -920,8 +920,8 @@ discard block |
||
| 920 | 920 | { |
| 921 | 921 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
| 922 | 922 | // load_espresso_template_tags |
| 923 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 924 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 923 | + if (is_readable(EE_PUBLIC.'template_tags.php')) { |
|
| 924 | + require_once(EE_PUBLIC.'template_tags.php'); |
|
| 925 | 925 | } |
| 926 | 926 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
| 927 | 927 | $this->registry->load_core('Session'); |
@@ -1068,7 +1068,7 @@ discard block |
||
| 1068 | 1068 | 'href' => $events_admin_url, |
| 1069 | 1069 | 'meta' => array( |
| 1070 | 1070 | 'title' => __('Event Espresso', 'event_espresso'), |
| 1071 | - 'class' => $menu_class . 'first', |
|
| 1071 | + 'class' => $menu_class.'first', |
|
| 1072 | 1072 | ), |
| 1073 | 1073 | )); |
| 1074 | 1074 | //Events |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use EventEspresso\widgets\EspressoWidget; |
| 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 | /** |
@@ -26,379 +26,379 @@ discard block |
||
| 26 | 26 | final class EE_Front_Controller |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var string $_template_path |
|
| 31 | - */ |
|
| 32 | - private $_template_path; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var string $_template |
|
| 36 | - */ |
|
| 37 | - private $_template; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @type EE_Registry $Registry |
|
| 41 | - */ |
|
| 42 | - protected $Registry; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @type EE_Request_Handler $Request_Handler |
|
| 46 | - */ |
|
| 47 | - protected $Request_Handler; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @type EE_Module_Request_Router $Module_Request_Router |
|
| 51 | - */ |
|
| 52 | - protected $Module_Request_Router; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * class constructor |
|
| 57 | - * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
| 58 | - * |
|
| 59 | - * @access public |
|
| 60 | - * @param \EE_Registry $Registry |
|
| 61 | - * @param \EE_Request_Handler $Request_Handler |
|
| 62 | - * @param \EE_Module_Request_Router $Module_Request_Router |
|
| 63 | - */ |
|
| 64 | - public function __construct( |
|
| 65 | - EE_Registry $Registry, |
|
| 66 | - EE_Request_Handler $Request_Handler, |
|
| 67 | - EE_Module_Request_Router $Module_Request_Router |
|
| 68 | - ) { |
|
| 69 | - $this->Registry = $Registry; |
|
| 70 | - $this->Request_Handler = $Request_Handler; |
|
| 71 | - $this->Module_Request_Router = $Module_Request_Router; |
|
| 72 | - // determine how to integrate WP_Query with the EE models |
|
| 73 | - add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
| 74 | - // load other resources and begin to actually run shortcodes and modules |
|
| 75 | - add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
| 76 | - // analyse the incoming WP request |
|
| 77 | - add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
| 78 | - // process request with module factory |
|
| 79 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
| 80 | - // before headers sent |
|
| 81 | - add_action('wp', array($this, 'wp'), 5); |
|
| 82 | - // after headers sent but before any markup is output, |
|
| 83 | - // primarily used to process any content shortcodes |
|
| 84 | - add_action('get_header', array($this, 'get_header')); |
|
| 85 | - // header |
|
| 86 | - add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
| 87 | - add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
| 88 | - add_filter('template_include', array($this, 'template_include'), 1); |
|
| 89 | - // display errors |
|
| 90 | - add_action('loop_start', array($this, 'display_errors'), 2); |
|
| 91 | - // the content |
|
| 92 | - // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
| 93 | - //exclude our private cpt comments |
|
| 94 | - add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
| 95 | - //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
| 96 | - add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
| 97 | - // action hook EE |
|
| 98 | - do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
| 99 | - // for checking that browser cookies are enabled |
|
| 100 | - if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
| 101 | - setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return EE_Request_Handler |
|
| 108 | - */ |
|
| 109 | - public function Request_Handler() |
|
| 110 | - { |
|
| 111 | - return $this->Request_Handler; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return EE_Module_Request_Router |
|
| 117 | - */ |
|
| 118 | - public function Module_Request_Router() |
|
| 119 | - { |
|
| 120 | - return $this->Module_Request_Router; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @return LegacyShortcodesManager |
|
| 127 | - */ |
|
| 128 | - public function getLegacyShortcodesManager() |
|
| 129 | - { |
|
| 130 | - return EE_Config::getLegacyShortcodesManager(); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * filter_wp_comments |
|
| 143 | - * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
| 144 | - * widgets/queries done on frontend |
|
| 145 | - * |
|
| 146 | - * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
| 147 | - * @return array array of comment clauses with modifications. |
|
| 148 | - */ |
|
| 149 | - public function filter_wp_comments($clauses) |
|
| 150 | - { |
|
| 151 | - global $wpdb; |
|
| 152 | - if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
| 153 | - $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
| 154 | - foreach ($cpts as $cpt => $details) { |
|
| 155 | - $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - return $clauses; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * employ_CPT_Strategy |
|
| 164 | - * |
|
| 165 | - * @access public |
|
| 166 | - * @return void |
|
| 167 | - */ |
|
| 168 | - public function employ_CPT_Strategy() |
|
| 169 | - { |
|
| 170 | - if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
| 171 | - $this->Registry->load_core('CPT_Strategy'); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
| 178 | - * |
|
| 179 | - * @param string $url incoming url |
|
| 180 | - * @return string final assembled url |
|
| 181 | - */ |
|
| 182 | - public function maybe_force_admin_ajax_ssl($url) |
|
| 183 | - { |
|
| 184 | - if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
| 185 | - $url = str_replace('http://', 'https://', $url); |
|
| 186 | - } |
|
| 187 | - return $url; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
| 200 | - * default priority init phases have run |
|
| 201 | - * |
|
| 202 | - * @access public |
|
| 203 | - * @return void |
|
| 204 | - */ |
|
| 205 | - public function wp_loaded() |
|
| 206 | - { |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
| 214 | - /** |
|
| 215 | - * _get_request |
|
| 216 | - * |
|
| 217 | - * @access public |
|
| 218 | - * @param WP $WP |
|
| 219 | - * @return void |
|
| 220 | - */ |
|
| 221 | - public function get_request(WP $WP) |
|
| 222 | - { |
|
| 223 | - do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
| 224 | - $this->Request_Handler->parse_request($WP); |
|
| 225 | - do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
| 232 | - * |
|
| 233 | - * @access public |
|
| 234 | - * @param WP_Query $WP_Query |
|
| 235 | - * @return void |
|
| 236 | - */ |
|
| 237 | - public function pre_get_posts($WP_Query) |
|
| 238 | - { |
|
| 239 | - // only load Module_Request_Router if this is the main query |
|
| 240 | - if ( |
|
| 241 | - $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
| 242 | - && $WP_Query->is_main_query() |
|
| 243 | - ) { |
|
| 244 | - // cycle thru module routes |
|
| 245 | - while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
| 246 | - // determine module and method for route |
|
| 247 | - $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
| 248 | - if ($module instanceof EED_Module) { |
|
| 249 | - // get registered view for route |
|
| 250 | - $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
| 251 | - // grab module name |
|
| 252 | - $module_name = $module->module_name(); |
|
| 253 | - // map the module to the module objects |
|
| 254 | - $this->Registry->modules->{$module_name} = $module; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - /*********************************************** WP HOOK ***********************************************/ |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * wp - basically last chance to do stuff before headers sent |
|
| 269 | - * |
|
| 270 | - * @access public |
|
| 271 | - * @return void |
|
| 272 | - */ |
|
| 273 | - public function wp() |
|
| 274 | - { |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * callback for the WP "get_header" hook point |
|
| 285 | - * checks sidebars for EE widgets |
|
| 286 | - * loads resources and assets accordingly |
|
| 287 | - * |
|
| 288 | - * @return void |
|
| 289 | - */ |
|
| 290 | - public function get_header() |
|
| 291 | - { |
|
| 292 | - global $wp_query; |
|
| 293 | - if (empty($wp_query->posts)){ |
|
| 294 | - return; |
|
| 295 | - } |
|
| 296 | - // if we already know this is an espresso page, then load assets |
|
| 297 | - $load_assets = $this->Request_Handler->is_espresso_page(); |
|
| 298 | - // if we are already loading assets then just move along, otherwise check for widgets |
|
| 299 | - $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
| 300 | - if ( $load_assets){ |
|
| 301 | - wp_enqueue_style('espresso_default'); |
|
| 302 | - wp_enqueue_style('espresso_custom_css'); |
|
| 303 | - wp_enqueue_script('espresso_core'); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * builds list of active widgets then scans active sidebars looking for them |
|
| 311 | - * returns true is an EE widget is found in an active sidebar |
|
| 312 | - * Please Note: this does NOT mean that the sidebar or widget |
|
| 313 | - * is actually in use in a given template, as that is unfortunately not known |
|
| 314 | - * until a sidebar and it's widgets are actually loaded |
|
| 315 | - * |
|
| 316 | - * @return boolean |
|
| 317 | - */ |
|
| 318 | - private function espresso_widgets_in_active_sidebars() |
|
| 319 | - { |
|
| 320 | - $espresso_widgets = array(); |
|
| 321 | - foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
| 322 | - $id_base = EspressoWidget::getIdBase($widget_class); |
|
| 323 | - if (is_active_widget(false, false, $id_base)) { |
|
| 324 | - $espresso_widgets[] = $id_base; |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
| 328 | - foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
| 329 | - if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
| 330 | - foreach ($sidebar_widgets as $sidebar_widget) { |
|
| 331 | - foreach ($espresso_widgets as $espresso_widget) { |
|
| 332 | - if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
| 333 | - return true; |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - return false; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * header_meta_tag |
|
| 347 | - * |
|
| 348 | - * @access public |
|
| 349 | - * @return void |
|
| 350 | - */ |
|
| 351 | - public function header_meta_tag() |
|
| 352 | - { |
|
| 353 | - print( |
|
| 354 | - apply_filters( |
|
| 355 | - 'FHEE__EE_Front_Controller__header_meta_tag', |
|
| 356 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
| 357 | - ); |
|
| 358 | - |
|
| 359 | - //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
| 360 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
| 361 | - //also exclude all critical pages from indexing |
|
| 362 | - if ( |
|
| 363 | - ( |
|
| 364 | - is_tax('espresso_event_type') |
|
| 365 | - && get_option( 'blog_public' ) !== '0' |
|
| 366 | - ) |
|
| 367 | - || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
| 368 | - ) { |
|
| 369 | - print( |
|
| 370 | - apply_filters( |
|
| 371 | - 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
| 372 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
| 373 | - ) |
|
| 374 | - ); |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * wp_print_scripts |
|
| 382 | - * |
|
| 383 | - * @return void |
|
| 384 | - */ |
|
| 385 | - public function wp_print_scripts() |
|
| 386 | - { |
|
| 387 | - global $post; |
|
| 388 | - if ( |
|
| 389 | - isset($post->EE_Event) |
|
| 390 | - && $post->EE_Event instanceof EE_Event |
|
| 391 | - && get_post_type() === 'espresso_events' |
|
| 392 | - && is_singular() |
|
| 393 | - ) { |
|
| 394 | - \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
| 29 | + /** |
|
| 30 | + * @var string $_template_path |
|
| 31 | + */ |
|
| 32 | + private $_template_path; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var string $_template |
|
| 36 | + */ |
|
| 37 | + private $_template; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @type EE_Registry $Registry |
|
| 41 | + */ |
|
| 42 | + protected $Registry; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @type EE_Request_Handler $Request_Handler |
|
| 46 | + */ |
|
| 47 | + protected $Request_Handler; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @type EE_Module_Request_Router $Module_Request_Router |
|
| 51 | + */ |
|
| 52 | + protected $Module_Request_Router; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * class constructor |
|
| 57 | + * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
| 58 | + * |
|
| 59 | + * @access public |
|
| 60 | + * @param \EE_Registry $Registry |
|
| 61 | + * @param \EE_Request_Handler $Request_Handler |
|
| 62 | + * @param \EE_Module_Request_Router $Module_Request_Router |
|
| 63 | + */ |
|
| 64 | + public function __construct( |
|
| 65 | + EE_Registry $Registry, |
|
| 66 | + EE_Request_Handler $Request_Handler, |
|
| 67 | + EE_Module_Request_Router $Module_Request_Router |
|
| 68 | + ) { |
|
| 69 | + $this->Registry = $Registry; |
|
| 70 | + $this->Request_Handler = $Request_Handler; |
|
| 71 | + $this->Module_Request_Router = $Module_Request_Router; |
|
| 72 | + // determine how to integrate WP_Query with the EE models |
|
| 73 | + add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
| 74 | + // load other resources and begin to actually run shortcodes and modules |
|
| 75 | + add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
| 76 | + // analyse the incoming WP request |
|
| 77 | + add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
| 78 | + // process request with module factory |
|
| 79 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
| 80 | + // before headers sent |
|
| 81 | + add_action('wp', array($this, 'wp'), 5); |
|
| 82 | + // after headers sent but before any markup is output, |
|
| 83 | + // primarily used to process any content shortcodes |
|
| 84 | + add_action('get_header', array($this, 'get_header')); |
|
| 85 | + // header |
|
| 86 | + add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
| 87 | + add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
| 88 | + add_filter('template_include', array($this, 'template_include'), 1); |
|
| 89 | + // display errors |
|
| 90 | + add_action('loop_start', array($this, 'display_errors'), 2); |
|
| 91 | + // the content |
|
| 92 | + // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
| 93 | + //exclude our private cpt comments |
|
| 94 | + add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
| 95 | + //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
| 96 | + add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
| 97 | + // action hook EE |
|
| 98 | + do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
| 99 | + // for checking that browser cookies are enabled |
|
| 100 | + if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
| 101 | + setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return EE_Request_Handler |
|
| 108 | + */ |
|
| 109 | + public function Request_Handler() |
|
| 110 | + { |
|
| 111 | + return $this->Request_Handler; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @return EE_Module_Request_Router |
|
| 117 | + */ |
|
| 118 | + public function Module_Request_Router() |
|
| 119 | + { |
|
| 120 | + return $this->Module_Request_Router; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @return LegacyShortcodesManager |
|
| 127 | + */ |
|
| 128 | + public function getLegacyShortcodesManager() |
|
| 129 | + { |
|
| 130 | + return EE_Config::getLegacyShortcodesManager(); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * filter_wp_comments |
|
| 143 | + * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
| 144 | + * widgets/queries done on frontend |
|
| 145 | + * |
|
| 146 | + * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
| 147 | + * @return array array of comment clauses with modifications. |
|
| 148 | + */ |
|
| 149 | + public function filter_wp_comments($clauses) |
|
| 150 | + { |
|
| 151 | + global $wpdb; |
|
| 152 | + if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
| 153 | + $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
| 154 | + foreach ($cpts as $cpt => $details) { |
|
| 155 | + $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + return $clauses; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * employ_CPT_Strategy |
|
| 164 | + * |
|
| 165 | + * @access public |
|
| 166 | + * @return void |
|
| 167 | + */ |
|
| 168 | + public function employ_CPT_Strategy() |
|
| 169 | + { |
|
| 170 | + if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
| 171 | + $this->Registry->load_core('CPT_Strategy'); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
| 178 | + * |
|
| 179 | + * @param string $url incoming url |
|
| 180 | + * @return string final assembled url |
|
| 181 | + */ |
|
| 182 | + public function maybe_force_admin_ajax_ssl($url) |
|
| 183 | + { |
|
| 184 | + if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
| 185 | + $url = str_replace('http://', 'https://', $url); |
|
| 186 | + } |
|
| 187 | + return $url; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
| 200 | + * default priority init phases have run |
|
| 201 | + * |
|
| 202 | + * @access public |
|
| 203 | + * @return void |
|
| 204 | + */ |
|
| 205 | + public function wp_loaded() |
|
| 206 | + { |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
| 214 | + /** |
|
| 215 | + * _get_request |
|
| 216 | + * |
|
| 217 | + * @access public |
|
| 218 | + * @param WP $WP |
|
| 219 | + * @return void |
|
| 220 | + */ |
|
| 221 | + public function get_request(WP $WP) |
|
| 222 | + { |
|
| 223 | + do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
| 224 | + $this->Request_Handler->parse_request($WP); |
|
| 225 | + do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
| 232 | + * |
|
| 233 | + * @access public |
|
| 234 | + * @param WP_Query $WP_Query |
|
| 235 | + * @return void |
|
| 236 | + */ |
|
| 237 | + public function pre_get_posts($WP_Query) |
|
| 238 | + { |
|
| 239 | + // only load Module_Request_Router if this is the main query |
|
| 240 | + if ( |
|
| 241 | + $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
| 242 | + && $WP_Query->is_main_query() |
|
| 243 | + ) { |
|
| 244 | + // cycle thru module routes |
|
| 245 | + while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
| 246 | + // determine module and method for route |
|
| 247 | + $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
| 248 | + if ($module instanceof EED_Module) { |
|
| 249 | + // get registered view for route |
|
| 250 | + $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
| 251 | + // grab module name |
|
| 252 | + $module_name = $module->module_name(); |
|
| 253 | + // map the module to the module objects |
|
| 254 | + $this->Registry->modules->{$module_name} = $module; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + /*********************************************** WP HOOK ***********************************************/ |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * wp - basically last chance to do stuff before headers sent |
|
| 269 | + * |
|
| 270 | + * @access public |
|
| 271 | + * @return void |
|
| 272 | + */ |
|
| 273 | + public function wp() |
|
| 274 | + { |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * callback for the WP "get_header" hook point |
|
| 285 | + * checks sidebars for EE widgets |
|
| 286 | + * loads resources and assets accordingly |
|
| 287 | + * |
|
| 288 | + * @return void |
|
| 289 | + */ |
|
| 290 | + public function get_header() |
|
| 291 | + { |
|
| 292 | + global $wp_query; |
|
| 293 | + if (empty($wp_query->posts)){ |
|
| 294 | + return; |
|
| 295 | + } |
|
| 296 | + // if we already know this is an espresso page, then load assets |
|
| 297 | + $load_assets = $this->Request_Handler->is_espresso_page(); |
|
| 298 | + // if we are already loading assets then just move along, otherwise check for widgets |
|
| 299 | + $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
| 300 | + if ( $load_assets){ |
|
| 301 | + wp_enqueue_style('espresso_default'); |
|
| 302 | + wp_enqueue_style('espresso_custom_css'); |
|
| 303 | + wp_enqueue_script('espresso_core'); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * builds list of active widgets then scans active sidebars looking for them |
|
| 311 | + * returns true is an EE widget is found in an active sidebar |
|
| 312 | + * Please Note: this does NOT mean that the sidebar or widget |
|
| 313 | + * is actually in use in a given template, as that is unfortunately not known |
|
| 314 | + * until a sidebar and it's widgets are actually loaded |
|
| 315 | + * |
|
| 316 | + * @return boolean |
|
| 317 | + */ |
|
| 318 | + private function espresso_widgets_in_active_sidebars() |
|
| 319 | + { |
|
| 320 | + $espresso_widgets = array(); |
|
| 321 | + foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
| 322 | + $id_base = EspressoWidget::getIdBase($widget_class); |
|
| 323 | + if (is_active_widget(false, false, $id_base)) { |
|
| 324 | + $espresso_widgets[] = $id_base; |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
| 328 | + foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
| 329 | + if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
| 330 | + foreach ($sidebar_widgets as $sidebar_widget) { |
|
| 331 | + foreach ($espresso_widgets as $espresso_widget) { |
|
| 332 | + if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
| 333 | + return true; |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + return false; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * header_meta_tag |
|
| 347 | + * |
|
| 348 | + * @access public |
|
| 349 | + * @return void |
|
| 350 | + */ |
|
| 351 | + public function header_meta_tag() |
|
| 352 | + { |
|
| 353 | + print( |
|
| 354 | + apply_filters( |
|
| 355 | + 'FHEE__EE_Front_Controller__header_meta_tag', |
|
| 356 | + '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
| 357 | + ); |
|
| 358 | + |
|
| 359 | + //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
| 360 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
| 361 | + //also exclude all critical pages from indexing |
|
| 362 | + if ( |
|
| 363 | + ( |
|
| 364 | + is_tax('espresso_event_type') |
|
| 365 | + && get_option( 'blog_public' ) !== '0' |
|
| 366 | + ) |
|
| 367 | + || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
| 368 | + ) { |
|
| 369 | + print( |
|
| 370 | + apply_filters( |
|
| 371 | + 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
| 372 | + '<meta name="robots" content="noindex,follow" />' . "\n" |
|
| 373 | + ) |
|
| 374 | + ); |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * wp_print_scripts |
|
| 382 | + * |
|
| 383 | + * @return void |
|
| 384 | + */ |
|
| 385 | + public function wp_print_scripts() |
|
| 386 | + { |
|
| 387 | + global $post; |
|
| 388 | + if ( |
|
| 389 | + isset($post->EE_Event) |
|
| 390 | + && $post->EE_Event instanceof EE_Event |
|
| 391 | + && get_post_type() === 'espresso_events' |
|
| 392 | + && is_singular() |
|
| 393 | + ) { |
|
| 394 | + \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
| 402 | 402 | |
| 403 | 403 | |
| 404 | 404 | |
@@ -409,99 +409,99 @@ discard block |
||
| 409 | 409 | // * @param $the_content |
| 410 | 410 | // * @return string |
| 411 | 411 | // */ |
| 412 | - // public function the_content( $the_content ) { |
|
| 413 | - // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
| 414 | - // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
| 415 | - // } |
|
| 416 | - // return $the_content; |
|
| 417 | - // } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /*********************************************** WP_FOOTER ***********************************************/ |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * display_errors |
|
| 426 | - * |
|
| 427 | - * @access public |
|
| 428 | - * @return void |
|
| 429 | - */ |
|
| 430 | - public function display_errors() |
|
| 431 | - { |
|
| 432 | - static $shown_already = false; |
|
| 433 | - do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
| 434 | - if ( |
|
| 435 | - ! $shown_already |
|
| 436 | - && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
| 437 | - && is_main_query() |
|
| 438 | - && ! is_feed() |
|
| 439 | - && in_the_loop() |
|
| 440 | - && $this->Request_Handler->is_espresso_page() |
|
| 441 | - ) { |
|
| 442 | - echo EE_Error::get_notices(); |
|
| 443 | - $shown_already = true; |
|
| 444 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
| 445 | - } |
|
| 446 | - do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - |
|
| 453 | - /*********************************************** UTILITIES ***********************************************/ |
|
| 454 | - /** |
|
| 455 | - * template_include |
|
| 456 | - * |
|
| 457 | - * @access public |
|
| 458 | - * @param string $template_include_path |
|
| 459 | - * @return string |
|
| 460 | - */ |
|
| 461 | - public function template_include($template_include_path = null) |
|
| 462 | - { |
|
| 463 | - if ($this->Request_Handler->is_espresso_page()) { |
|
| 464 | - $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
| 465 | - $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
| 466 | - $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
| 467 | - $this->_template = basename($this->_template_path); |
|
| 468 | - return $this->_template_path; |
|
| 469 | - } |
|
| 470 | - return $template_include_path; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * get_selected_template |
|
| 476 | - * |
|
| 477 | - * @access public |
|
| 478 | - * @param bool $with_path |
|
| 479 | - * @return string |
|
| 480 | - */ |
|
| 481 | - public function get_selected_template($with_path = false) |
|
| 482 | - { |
|
| 483 | - return $with_path ? $this->_template_path : $this->_template; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * @deprecated 4.9.26 |
|
| 490 | - * @param string $shortcode_class |
|
| 491 | - * @param \WP $wp |
|
| 492 | - */ |
|
| 493 | - public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
| 494 | - { |
|
| 495 | - \EE_Error::doing_it_wrong( |
|
| 496 | - __METHOD__, |
|
| 497 | - __( |
|
| 498 | - 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
| 499 | - 'event_espresso' |
|
| 500 | - ), |
|
| 501 | - '4.9.26' |
|
| 502 | - ); |
|
| 503 | - $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
| 504 | - } |
|
| 412 | + // public function the_content( $the_content ) { |
|
| 413 | + // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
| 414 | + // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
| 415 | + // } |
|
| 416 | + // return $the_content; |
|
| 417 | + // } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + /*********************************************** WP_FOOTER ***********************************************/ |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * display_errors |
|
| 426 | + * |
|
| 427 | + * @access public |
|
| 428 | + * @return void |
|
| 429 | + */ |
|
| 430 | + public function display_errors() |
|
| 431 | + { |
|
| 432 | + static $shown_already = false; |
|
| 433 | + do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
| 434 | + if ( |
|
| 435 | + ! $shown_already |
|
| 436 | + && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
| 437 | + && is_main_query() |
|
| 438 | + && ! is_feed() |
|
| 439 | + && in_the_loop() |
|
| 440 | + && $this->Request_Handler->is_espresso_page() |
|
| 441 | + ) { |
|
| 442 | + echo EE_Error::get_notices(); |
|
| 443 | + $shown_already = true; |
|
| 444 | + EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
| 445 | + } |
|
| 446 | + do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + |
|
| 453 | + /*********************************************** UTILITIES ***********************************************/ |
|
| 454 | + /** |
|
| 455 | + * template_include |
|
| 456 | + * |
|
| 457 | + * @access public |
|
| 458 | + * @param string $template_include_path |
|
| 459 | + * @return string |
|
| 460 | + */ |
|
| 461 | + public function template_include($template_include_path = null) |
|
| 462 | + { |
|
| 463 | + if ($this->Request_Handler->is_espresso_page()) { |
|
| 464 | + $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
| 465 | + $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
| 466 | + $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
| 467 | + $this->_template = basename($this->_template_path); |
|
| 468 | + return $this->_template_path; |
|
| 469 | + } |
|
| 470 | + return $template_include_path; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * get_selected_template |
|
| 476 | + * |
|
| 477 | + * @access public |
|
| 478 | + * @param bool $with_path |
|
| 479 | + * @return string |
|
| 480 | + */ |
|
| 481 | + public function get_selected_template($with_path = false) |
|
| 482 | + { |
|
| 483 | + return $with_path ? $this->_template_path : $this->_template; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * @deprecated 4.9.26 |
|
| 490 | + * @param string $shortcode_class |
|
| 491 | + * @param \WP $wp |
|
| 492 | + */ |
|
| 493 | + public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
| 494 | + { |
|
| 495 | + \EE_Error::doing_it_wrong( |
|
| 496 | + __METHOD__, |
|
| 497 | + __( |
|
| 498 | + 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
| 499 | + 'event_espresso' |
|
| 500 | + ), |
|
| 501 | + '4.9.26' |
|
| 502 | + ); |
|
| 503 | + $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
| 504 | + } |
|
| 505 | 505 | |
| 506 | 506 | } |
| 507 | 507 | // End of file EE_Front_Controller.core.php |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | do_action('AHEE__EE_Front_Controller__construct__done', $this); |
| 99 | 99 | // for checking that browser cookies are enabled |
| 100 | 100 | if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
| 101 | - setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
| 101 | + setcookie('ee_cookie_test', uniqid('ect', true), time() + DAY_IN_SECONDS, '/'); |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
@@ -290,14 +290,14 @@ discard block |
||
| 290 | 290 | public function get_header() |
| 291 | 291 | { |
| 292 | 292 | global $wp_query; |
| 293 | - if (empty($wp_query->posts)){ |
|
| 293 | + if (empty($wp_query->posts)) { |
|
| 294 | 294 | return; |
| 295 | 295 | } |
| 296 | 296 | // if we already know this is an espresso page, then load assets |
| 297 | 297 | $load_assets = $this->Request_Handler->is_espresso_page(); |
| 298 | 298 | // if we are already loading assets then just move along, otherwise check for widgets |
| 299 | 299 | $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
| 300 | - if ( $load_assets){ |
|
| 300 | + if ($load_assets) { |
|
| 301 | 301 | wp_enqueue_style('espresso_default'); |
| 302 | 302 | wp_enqueue_style('espresso_custom_css'); |
| 303 | 303 | wp_enqueue_script('espresso_core'); |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | print( |
| 354 | 354 | apply_filters( |
| 355 | 355 | 'FHEE__EE_Front_Controller__header_meta_tag', |
| 356 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
| 356 | + '<meta name="generator" content="Event Espresso Version '.EVENT_ESPRESSO_VERSION."\" />\n") |
|
| 357 | 357 | ); |
| 358 | 358 | |
| 359 | 359 | //let's exclude all event type taxonomy term archive pages from search engine indexing |
@@ -362,14 +362,14 @@ discard block |
||
| 362 | 362 | if ( |
| 363 | 363 | ( |
| 364 | 364 | is_tax('espresso_event_type') |
| 365 | - && get_option( 'blog_public' ) !== '0' |
|
| 365 | + && get_option('blog_public') !== '0' |
|
| 366 | 366 | ) |
| 367 | 367 | || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
| 368 | 368 | ) { |
| 369 | 369 | print( |
| 370 | 370 | apply_filters( |
| 371 | 371 | 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
| 372 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
| 372 | + '<meta name="robots" content="noindex,follow" />'."\n" |
|
| 373 | 373 | ) |
| 374 | 374 | ); |
| 375 | 375 | } |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | ) { |
| 442 | 442 | echo EE_Error::get_notices(); |
| 443 | 443 | $shown_already = true; |
| 444 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
| 444 | + EEH_Template::display_template(EE_TEMPLATES.'espresso-ajax-notices.template.php'); |
|
| 445 | 445 | } |
| 446 | 446 | do_action('AHEE__EE_Front_Controller__display_errors__end'); |
| 447 | 447 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 5 | 5 | |
| 6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 7 | - exit('No direct script access allowed'); |
|
| 7 | + exit('No direct script access allowed'); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | |
@@ -22,653 +22,653 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * This means that the requested class dependency is not present in the dependency map |
|
| 27 | - */ |
|
| 28 | - const not_registered = 0; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 33 | - */ |
|
| 34 | - const load_new_object = 1; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 38 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 39 | - */ |
|
| 40 | - const load_from_cache = 2; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @type EE_Dependency_Map $_instance |
|
| 44 | - */ |
|
| 45 | - protected static $_instance; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @type EE_Request $request |
|
| 49 | - */ |
|
| 50 | - protected $_request; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @type EE_Response $response |
|
| 54 | - */ |
|
| 55 | - protected $_response; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @type LoaderInterface $loader |
|
| 59 | - */ |
|
| 60 | - protected $loader; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @type array $_dependency_map |
|
| 64 | - */ |
|
| 65 | - protected $_dependency_map = array(); |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @type array $_class_loaders |
|
| 69 | - */ |
|
| 70 | - protected $_class_loaders = array(); |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @type array $_aliases |
|
| 74 | - */ |
|
| 75 | - protected $_aliases = array(); |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * EE_Dependency_Map constructor. |
|
| 81 | - * |
|
| 82 | - * @param EE_Request $request |
|
| 83 | - * @param EE_Response $response |
|
| 84 | - */ |
|
| 85 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
| 86 | - { |
|
| 87 | - $this->_request = $request; |
|
| 88 | - $this->_response = $response; |
|
| 89 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 90 | - do_action('EE_Dependency_Map____construct'); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @throws InvalidDataTypeException |
|
| 97 | - * @throws InvalidInterfaceException |
|
| 98 | - * @throws InvalidArgumentException |
|
| 99 | - */ |
|
| 100 | - public function initialize() |
|
| 101 | - { |
|
| 102 | - $this->_register_core_dependencies(); |
|
| 103 | - $this->_register_core_class_loaders(); |
|
| 104 | - $this->_register_core_aliases(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @singleton method used to instantiate class object |
|
| 111 | - * @access public |
|
| 112 | - * @param EE_Request $request |
|
| 113 | - * @param EE_Response $response |
|
| 114 | - * @return EE_Dependency_Map |
|
| 115 | - */ |
|
| 116 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 117 | - { |
|
| 118 | - // check if class object is instantiated, and instantiated properly |
|
| 119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 120 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 121 | - } |
|
| 122 | - return self::$_instance; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @param LoaderInterface $loader |
|
| 129 | - */ |
|
| 130 | - public function setLoader(LoaderInterface $loader) |
|
| 131 | - { |
|
| 132 | - $this->loader = $loader; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @param string $class |
|
| 139 | - * @param array $dependencies |
|
| 140 | - * @return boolean |
|
| 141 | - */ |
|
| 142 | - public static function register_dependencies($class, $dependencies) |
|
| 143 | - { |
|
| 144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 145 | - // we need to make sure that any aliases used when registering a dependency |
|
| 146 | - // get resolved to the correct class name |
|
| 147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 148 | - $alias = self::$_instance->get_alias($dependency); |
|
| 149 | - unset($dependencies[$dependency]); |
|
| 150 | - $dependencies[$alias] = $load_source; |
|
| 151 | - } |
|
| 152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 153 | - return true; |
|
| 154 | - } |
|
| 155 | - return false; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @param string $class_name |
|
| 162 | - * @param string $loader |
|
| 163 | - * @return bool |
|
| 164 | - * @throws EE_Error |
|
| 165 | - */ |
|
| 166 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 167 | - { |
|
| 168 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 169 | - if ( |
|
| 170 | - ! is_callable($loader) |
|
| 171 | - && ( |
|
| 172 | - strpos($loader, 'load_') !== 0 |
|
| 173 | - || ! method_exists('EE_Registry', $loader) |
|
| 174 | - ) |
|
| 175 | - ) { |
|
| 176 | - throw new EE_Error( |
|
| 177 | - sprintf( |
|
| 178 | - esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
| 179 | - $loader |
|
| 180 | - ) |
|
| 181 | - ); |
|
| 182 | - } |
|
| 183 | - $class_name = self::$_instance->get_alias($class_name); |
|
| 184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 185 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 186 | - return true; |
|
| 187 | - } |
|
| 188 | - return false; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @return array |
|
| 195 | - */ |
|
| 196 | - public function dependency_map() |
|
| 197 | - { |
|
| 198 | - return $this->_dependency_map; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 205 | - * |
|
| 206 | - * @param string $class_name |
|
| 207 | - * @return boolean |
|
| 208 | - */ |
|
| 209 | - public function has($class_name = '') |
|
| 210 | - { |
|
| 211 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 218 | - * |
|
| 219 | - * @param string $class_name |
|
| 220 | - * @param string $dependency |
|
| 221 | - * @return bool |
|
| 222 | - */ |
|
| 223 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 224 | - { |
|
| 225 | - $dependency = $this->get_alias($dependency); |
|
| 226 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 227 | - ? true |
|
| 228 | - : false; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 235 | - * |
|
| 236 | - * @param string $class_name |
|
| 237 | - * @param string $dependency |
|
| 238 | - * @return int |
|
| 239 | - */ |
|
| 240 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 241 | - { |
|
| 242 | - $dependency = $this->get_alias($dependency); |
|
| 243 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 244 | - ? $this->_dependency_map[$class_name][$dependency] |
|
| 245 | - : EE_Dependency_Map::not_registered; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @param string $class_name |
|
| 252 | - * @return string | Closure |
|
| 253 | - */ |
|
| 254 | - public function class_loader($class_name) |
|
| 255 | - { |
|
| 256 | - $class_name = $this->get_alias($class_name); |
|
| 257 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @return array |
|
| 264 | - */ |
|
| 265 | - public function class_loaders() |
|
| 266 | - { |
|
| 267 | - return $this->_class_loaders; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * adds an alias for a classname |
|
| 274 | - * |
|
| 275 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 276 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 277 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 278 | - */ |
|
| 279 | - public function add_alias($class_name, $alias, $for_class = '') |
|
| 280 | - { |
|
| 281 | - if ($for_class !== '') { |
|
| 282 | - if (! isset($this->_aliases[$for_class])) { |
|
| 283 | - $this->_aliases[$for_class] = array(); |
|
| 284 | - } |
|
| 285 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
| 286 | - } |
|
| 287 | - $this->_aliases[$class_name] = $alias; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * returns TRUE if the provided class name has an alias |
|
| 294 | - * |
|
| 295 | - * @param string $class_name |
|
| 296 | - * @param string $for_class |
|
| 297 | - * @return bool |
|
| 298 | - */ |
|
| 299 | - public function has_alias($class_name = '', $for_class = '') |
|
| 300 | - { |
|
| 301 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 302 | - || ( |
|
| 303 | - isset($this->_aliases[$class_name]) |
|
| 304 | - && ! is_array($this->_aliases[$class_name]) |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
| 312 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 313 | - * for example: |
|
| 314 | - * if the following two entries were added to the _aliases array: |
|
| 315 | - * array( |
|
| 316 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 317 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 318 | - * ) |
|
| 319 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 320 | - * to load an instance of 'some\namespace\classname' |
|
| 321 | - * |
|
| 322 | - * @param string $class_name |
|
| 323 | - * @param string $for_class |
|
| 324 | - * @return string |
|
| 325 | - */ |
|
| 326 | - public function get_alias($class_name = '', $for_class = '') |
|
| 327 | - { |
|
| 328 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 329 | - return $class_name; |
|
| 330 | - } |
|
| 331 | - if ($for_class !== '') { |
|
| 332 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 333 | - } |
|
| 334 | - return $this->get_alias($this->_aliases[$class_name]); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 341 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 342 | - * This is done by using the following class constants: |
|
| 343 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 344 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 345 | - */ |
|
| 346 | - protected function _register_core_dependencies() |
|
| 347 | - { |
|
| 348 | - $this->_dependency_map = array( |
|
| 349 | - 'EE_Request_Handler' => array( |
|
| 350 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 351 | - ), |
|
| 352 | - 'EE_System' => array( |
|
| 353 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 354 | - ), |
|
| 355 | - 'EE_Session' => array( |
|
| 356 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 357 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 358 | - ), |
|
| 359 | - 'EE_Cart' => array( |
|
| 360 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 361 | - ), |
|
| 362 | - 'EE_Front_Controller' => array( |
|
| 363 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 364 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 365 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 366 | - ), |
|
| 367 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 368 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 369 | - ), |
|
| 370 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 371 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 372 | - ), |
|
| 373 | - 'EE_Message_Resource_Manager' => array( |
|
| 374 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 375 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 376 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 377 | - ), |
|
| 378 | - 'EE_Message_Factory' => array( |
|
| 379 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 380 | - ), |
|
| 381 | - 'EE_messages' => array( |
|
| 382 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 383 | - ), |
|
| 384 | - 'EE_Messages_Generator' => array( |
|
| 385 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 386 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 387 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 388 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 389 | - ), |
|
| 390 | - 'EE_Messages_Processor' => array( |
|
| 391 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 392 | - ), |
|
| 393 | - 'EE_Messages_Queue' => array( |
|
| 394 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 395 | - ), |
|
| 396 | - 'EE_Messages_Template_Defaults' => array( |
|
| 397 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 398 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 399 | - ), |
|
| 400 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 401 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 402 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 403 | - ), |
|
| 404 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 405 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 406 | - ), |
|
| 407 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 408 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 409 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 410 | - ), |
|
| 411 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 412 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 413 | - ), |
|
| 414 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 415 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 416 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 417 | - ), |
|
| 418 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 419 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 420 | - ), |
|
| 421 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 422 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 423 | - ), |
|
| 424 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 425 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 426 | - ), |
|
| 427 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 428 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 429 | - ), |
|
| 430 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 431 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 432 | - ), |
|
| 433 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 434 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 435 | - ), |
|
| 436 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 437 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 438 | - ), |
|
| 439 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 440 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 441 | - ), |
|
| 442 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 443 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 444 | - ), |
|
| 445 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 446 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 447 | - ), |
|
| 448 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 449 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 450 | - ), |
|
| 451 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 452 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 453 | - ), |
|
| 454 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 455 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 456 | - ), |
|
| 457 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 458 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 459 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 460 | - ), |
|
| 461 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 462 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 463 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 464 | - ), |
|
| 465 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 466 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 467 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 468 | - ), |
|
| 469 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 470 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 471 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 472 | - ), |
|
| 473 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 474 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 475 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 476 | - ), |
|
| 477 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 478 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 479 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 480 | - ), |
|
| 481 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 482 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 483 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 484 | - ), |
|
| 485 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 486 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 487 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 488 | - ), |
|
| 489 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 490 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 491 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 492 | - ), |
|
| 493 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 494 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 495 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 496 | - ), |
|
| 497 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
| 498 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 499 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 500 | - ), |
|
| 501 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 502 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 503 | - ), |
|
| 504 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 505 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 506 | - ), |
|
| 507 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 508 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 509 | - ), |
|
| 510 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 511 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 512 | - ), |
|
| 513 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 514 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 515 | - ), |
|
| 516 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 517 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 518 | - ), |
|
| 519 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 520 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 521 | - ), |
|
| 522 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 523 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 524 | - ), |
|
| 525 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 526 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 527 | - ), |
|
| 528 | - ); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Registers how core classes are loaded. |
|
| 535 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 536 | - * 'EE_Request_Handler' => 'load_core' |
|
| 537 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 538 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 539 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 540 | - * 'Some_Class' => function () { |
|
| 541 | - * return new Some_Class(); |
|
| 542 | - * }, |
|
| 543 | - * This is required for instantiating dependencies |
|
| 544 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 545 | - * 'Required_Interface' => function () { |
|
| 546 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 547 | - * }, |
|
| 548 | - */ |
|
| 549 | - protected function _register_core_class_loaders() |
|
| 550 | - { |
|
| 551 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 552 | - //be used in a closure. |
|
| 553 | - $request = &$this->_request; |
|
| 554 | - $response = &$this->_response; |
|
| 555 | - $loader = &$this->loader; |
|
| 556 | - $this->_class_loaders = array( |
|
| 557 | - //load_core |
|
| 558 | - 'EE_Capabilities' => 'load_core', |
|
| 559 | - 'EE_Encryption' => 'load_core', |
|
| 560 | - 'EE_Front_Controller' => 'load_core', |
|
| 561 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 562 | - 'EE_Registry' => 'load_core', |
|
| 563 | - 'EE_Request' => function () use (&$request) { |
|
| 564 | - return $request; |
|
| 565 | - }, |
|
| 566 | - 'EE_Response' => function () use (&$response) { |
|
| 567 | - return $response; |
|
| 568 | - }, |
|
| 569 | - 'EE_Request_Handler' => 'load_core', |
|
| 570 | - 'EE_Session' => 'load_core', |
|
| 571 | - 'EE_System' => 'load_core', |
|
| 572 | - //load_lib |
|
| 573 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 574 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 575 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 576 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 577 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 578 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 579 | - 'EE_Message_Repository' => 'load_lib', |
|
| 580 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 581 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 582 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 583 | - 'EE_Messages_Generator' => function () { |
|
| 584 | - return EE_Registry::instance()->load_lib( |
|
| 585 | - 'Messages_Generator', |
|
| 586 | - array(), |
|
| 587 | - false, |
|
| 588 | - false |
|
| 589 | - ); |
|
| 590 | - }, |
|
| 591 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 592 | - return EE_Registry::instance()->load_lib( |
|
| 593 | - 'Messages_Template_Defaults', |
|
| 594 | - $arguments, |
|
| 595 | - false, |
|
| 596 | - false |
|
| 597 | - ); |
|
| 598 | - }, |
|
| 599 | - //load_model |
|
| 600 | - 'EEM_Message_Template_Group' => 'load_model', |
|
| 601 | - 'EEM_Message_Template' => 'load_model', |
|
| 602 | - //load_helper |
|
| 603 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 604 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 605 | - return new EEH_Parse_Shortcodes(); |
|
| 606 | - } |
|
| 607 | - return null; |
|
| 608 | - }, |
|
| 609 | - 'EE_Template_Config' => function () { |
|
| 610 | - return EE_Config::instance()->template_settings; |
|
| 611 | - }, |
|
| 612 | - 'EE_Currency_Config' => function () { |
|
| 613 | - return EE_Config::instance()->currency; |
|
| 614 | - }, |
|
| 615 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
| 616 | - return $loader; |
|
| 617 | - }, |
|
| 618 | - ); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - /** |
|
| 624 | - * can be used for supplying alternate names for classes, |
|
| 625 | - * or for connecting interface names to instantiable classes |
|
| 626 | - */ |
|
| 627 | - protected function _register_core_aliases() |
|
| 628 | - { |
|
| 629 | - $this->_aliases = array( |
|
| 630 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 631 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 632 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 633 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 634 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 635 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 636 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 637 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 638 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 639 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 640 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 641 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 642 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 643 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 644 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 645 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 646 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 647 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 648 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 649 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 650 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 651 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 652 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 653 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 654 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 655 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 656 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 657 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 658 | - ); |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 665 | - * request Primarily used by unit tests. |
|
| 666 | - */ |
|
| 667 | - public function reset() |
|
| 668 | - { |
|
| 669 | - $this->_register_core_class_loaders(); |
|
| 670 | - $this->_register_core_dependencies(); |
|
| 671 | - } |
|
| 25 | + /** |
|
| 26 | + * This means that the requested class dependency is not present in the dependency map |
|
| 27 | + */ |
|
| 28 | + const not_registered = 0; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 33 | + */ |
|
| 34 | + const load_new_object = 1; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 38 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 39 | + */ |
|
| 40 | + const load_from_cache = 2; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @type EE_Dependency_Map $_instance |
|
| 44 | + */ |
|
| 45 | + protected static $_instance; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @type EE_Request $request |
|
| 49 | + */ |
|
| 50 | + protected $_request; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @type EE_Response $response |
|
| 54 | + */ |
|
| 55 | + protected $_response; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @type LoaderInterface $loader |
|
| 59 | + */ |
|
| 60 | + protected $loader; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @type array $_dependency_map |
|
| 64 | + */ |
|
| 65 | + protected $_dependency_map = array(); |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @type array $_class_loaders |
|
| 69 | + */ |
|
| 70 | + protected $_class_loaders = array(); |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @type array $_aliases |
|
| 74 | + */ |
|
| 75 | + protected $_aliases = array(); |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * EE_Dependency_Map constructor. |
|
| 81 | + * |
|
| 82 | + * @param EE_Request $request |
|
| 83 | + * @param EE_Response $response |
|
| 84 | + */ |
|
| 85 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
| 86 | + { |
|
| 87 | + $this->_request = $request; |
|
| 88 | + $this->_response = $response; |
|
| 89 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 90 | + do_action('EE_Dependency_Map____construct'); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @throws InvalidDataTypeException |
|
| 97 | + * @throws InvalidInterfaceException |
|
| 98 | + * @throws InvalidArgumentException |
|
| 99 | + */ |
|
| 100 | + public function initialize() |
|
| 101 | + { |
|
| 102 | + $this->_register_core_dependencies(); |
|
| 103 | + $this->_register_core_class_loaders(); |
|
| 104 | + $this->_register_core_aliases(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @singleton method used to instantiate class object |
|
| 111 | + * @access public |
|
| 112 | + * @param EE_Request $request |
|
| 113 | + * @param EE_Response $response |
|
| 114 | + * @return EE_Dependency_Map |
|
| 115 | + */ |
|
| 116 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 117 | + { |
|
| 118 | + // check if class object is instantiated, and instantiated properly |
|
| 119 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 120 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 121 | + } |
|
| 122 | + return self::$_instance; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param LoaderInterface $loader |
|
| 129 | + */ |
|
| 130 | + public function setLoader(LoaderInterface $loader) |
|
| 131 | + { |
|
| 132 | + $this->loader = $loader; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @param string $class |
|
| 139 | + * @param array $dependencies |
|
| 140 | + * @return boolean |
|
| 141 | + */ |
|
| 142 | + public static function register_dependencies($class, $dependencies) |
|
| 143 | + { |
|
| 144 | + if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 145 | + // we need to make sure that any aliases used when registering a dependency |
|
| 146 | + // get resolved to the correct class name |
|
| 147 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 148 | + $alias = self::$_instance->get_alias($dependency); |
|
| 149 | + unset($dependencies[$dependency]); |
|
| 150 | + $dependencies[$alias] = $load_source; |
|
| 151 | + } |
|
| 152 | + self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 153 | + return true; |
|
| 154 | + } |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @param string $class_name |
|
| 162 | + * @param string $loader |
|
| 163 | + * @return bool |
|
| 164 | + * @throws EE_Error |
|
| 165 | + */ |
|
| 166 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 167 | + { |
|
| 168 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 169 | + if ( |
|
| 170 | + ! is_callable($loader) |
|
| 171 | + && ( |
|
| 172 | + strpos($loader, 'load_') !== 0 |
|
| 173 | + || ! method_exists('EE_Registry', $loader) |
|
| 174 | + ) |
|
| 175 | + ) { |
|
| 176 | + throw new EE_Error( |
|
| 177 | + sprintf( |
|
| 178 | + esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
| 179 | + $loader |
|
| 180 | + ) |
|
| 181 | + ); |
|
| 182 | + } |
|
| 183 | + $class_name = self::$_instance->get_alias($class_name); |
|
| 184 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 185 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 186 | + return true; |
|
| 187 | + } |
|
| 188 | + return false; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @return array |
|
| 195 | + */ |
|
| 196 | + public function dependency_map() |
|
| 197 | + { |
|
| 198 | + return $this->_dependency_map; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 205 | + * |
|
| 206 | + * @param string $class_name |
|
| 207 | + * @return boolean |
|
| 208 | + */ |
|
| 209 | + public function has($class_name = '') |
|
| 210 | + { |
|
| 211 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 218 | + * |
|
| 219 | + * @param string $class_name |
|
| 220 | + * @param string $dependency |
|
| 221 | + * @return bool |
|
| 222 | + */ |
|
| 223 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 224 | + { |
|
| 225 | + $dependency = $this->get_alias($dependency); |
|
| 226 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 227 | + ? true |
|
| 228 | + : false; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 235 | + * |
|
| 236 | + * @param string $class_name |
|
| 237 | + * @param string $dependency |
|
| 238 | + * @return int |
|
| 239 | + */ |
|
| 240 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 241 | + { |
|
| 242 | + $dependency = $this->get_alias($dependency); |
|
| 243 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 244 | + ? $this->_dependency_map[$class_name][$dependency] |
|
| 245 | + : EE_Dependency_Map::not_registered; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * @param string $class_name |
|
| 252 | + * @return string | Closure |
|
| 253 | + */ |
|
| 254 | + public function class_loader($class_name) |
|
| 255 | + { |
|
| 256 | + $class_name = $this->get_alias($class_name); |
|
| 257 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @return array |
|
| 264 | + */ |
|
| 265 | + public function class_loaders() |
|
| 266 | + { |
|
| 267 | + return $this->_class_loaders; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * adds an alias for a classname |
|
| 274 | + * |
|
| 275 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 276 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 277 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 278 | + */ |
|
| 279 | + public function add_alias($class_name, $alias, $for_class = '') |
|
| 280 | + { |
|
| 281 | + if ($for_class !== '') { |
|
| 282 | + if (! isset($this->_aliases[$for_class])) { |
|
| 283 | + $this->_aliases[$for_class] = array(); |
|
| 284 | + } |
|
| 285 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
| 286 | + } |
|
| 287 | + $this->_aliases[$class_name] = $alias; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * returns TRUE if the provided class name has an alias |
|
| 294 | + * |
|
| 295 | + * @param string $class_name |
|
| 296 | + * @param string $for_class |
|
| 297 | + * @return bool |
|
| 298 | + */ |
|
| 299 | + public function has_alias($class_name = '', $for_class = '') |
|
| 300 | + { |
|
| 301 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 302 | + || ( |
|
| 303 | + isset($this->_aliases[$class_name]) |
|
| 304 | + && ! is_array($this->_aliases[$class_name]) |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
| 312 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 313 | + * for example: |
|
| 314 | + * if the following two entries were added to the _aliases array: |
|
| 315 | + * array( |
|
| 316 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 317 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 318 | + * ) |
|
| 319 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 320 | + * to load an instance of 'some\namespace\classname' |
|
| 321 | + * |
|
| 322 | + * @param string $class_name |
|
| 323 | + * @param string $for_class |
|
| 324 | + * @return string |
|
| 325 | + */ |
|
| 326 | + public function get_alias($class_name = '', $for_class = '') |
|
| 327 | + { |
|
| 328 | + if (! $this->has_alias($class_name, $for_class)) { |
|
| 329 | + return $class_name; |
|
| 330 | + } |
|
| 331 | + if ($for_class !== '') { |
|
| 332 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 333 | + } |
|
| 334 | + return $this->get_alias($this->_aliases[$class_name]); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 341 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 342 | + * This is done by using the following class constants: |
|
| 343 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 344 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 345 | + */ |
|
| 346 | + protected function _register_core_dependencies() |
|
| 347 | + { |
|
| 348 | + $this->_dependency_map = array( |
|
| 349 | + 'EE_Request_Handler' => array( |
|
| 350 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 351 | + ), |
|
| 352 | + 'EE_System' => array( |
|
| 353 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 354 | + ), |
|
| 355 | + 'EE_Session' => array( |
|
| 356 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 357 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 358 | + ), |
|
| 359 | + 'EE_Cart' => array( |
|
| 360 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 361 | + ), |
|
| 362 | + 'EE_Front_Controller' => array( |
|
| 363 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 364 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 365 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 366 | + ), |
|
| 367 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 368 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 369 | + ), |
|
| 370 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 371 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 372 | + ), |
|
| 373 | + 'EE_Message_Resource_Manager' => array( |
|
| 374 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 375 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 376 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 377 | + ), |
|
| 378 | + 'EE_Message_Factory' => array( |
|
| 379 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 380 | + ), |
|
| 381 | + 'EE_messages' => array( |
|
| 382 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 383 | + ), |
|
| 384 | + 'EE_Messages_Generator' => array( |
|
| 385 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 386 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 387 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 388 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 389 | + ), |
|
| 390 | + 'EE_Messages_Processor' => array( |
|
| 391 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 392 | + ), |
|
| 393 | + 'EE_Messages_Queue' => array( |
|
| 394 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 395 | + ), |
|
| 396 | + 'EE_Messages_Template_Defaults' => array( |
|
| 397 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 398 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 399 | + ), |
|
| 400 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 401 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 402 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 403 | + ), |
|
| 404 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 405 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 406 | + ), |
|
| 407 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 408 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 409 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 410 | + ), |
|
| 411 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 412 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 413 | + ), |
|
| 414 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 415 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 416 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 417 | + ), |
|
| 418 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 419 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 420 | + ), |
|
| 421 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 422 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 423 | + ), |
|
| 424 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 425 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 426 | + ), |
|
| 427 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 428 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 429 | + ), |
|
| 430 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 431 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 432 | + ), |
|
| 433 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 434 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 435 | + ), |
|
| 436 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 437 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 438 | + ), |
|
| 439 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 440 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 441 | + ), |
|
| 442 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 443 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 444 | + ), |
|
| 445 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 446 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 447 | + ), |
|
| 448 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 449 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 450 | + ), |
|
| 451 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 452 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 453 | + ), |
|
| 454 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 455 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 456 | + ), |
|
| 457 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 458 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 459 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 460 | + ), |
|
| 461 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 462 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 463 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 464 | + ), |
|
| 465 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 466 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 467 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 468 | + ), |
|
| 469 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 470 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 471 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 472 | + ), |
|
| 473 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 474 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 475 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 476 | + ), |
|
| 477 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 478 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 479 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 480 | + ), |
|
| 481 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 482 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 483 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 484 | + ), |
|
| 485 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 486 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 487 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 488 | + ), |
|
| 489 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 490 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 491 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 492 | + ), |
|
| 493 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 494 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 495 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 496 | + ), |
|
| 497 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
| 498 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 499 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 500 | + ), |
|
| 501 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 502 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 503 | + ), |
|
| 504 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 505 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 506 | + ), |
|
| 507 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 508 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 509 | + ), |
|
| 510 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 511 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 512 | + ), |
|
| 513 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 514 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 515 | + ), |
|
| 516 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 517 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 518 | + ), |
|
| 519 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 520 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 521 | + ), |
|
| 522 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 523 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 524 | + ), |
|
| 525 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 526 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 527 | + ), |
|
| 528 | + ); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * Registers how core classes are loaded. |
|
| 535 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 536 | + * 'EE_Request_Handler' => 'load_core' |
|
| 537 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 538 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 539 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 540 | + * 'Some_Class' => function () { |
|
| 541 | + * return new Some_Class(); |
|
| 542 | + * }, |
|
| 543 | + * This is required for instantiating dependencies |
|
| 544 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 545 | + * 'Required_Interface' => function () { |
|
| 546 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 547 | + * }, |
|
| 548 | + */ |
|
| 549 | + protected function _register_core_class_loaders() |
|
| 550 | + { |
|
| 551 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 552 | + //be used in a closure. |
|
| 553 | + $request = &$this->_request; |
|
| 554 | + $response = &$this->_response; |
|
| 555 | + $loader = &$this->loader; |
|
| 556 | + $this->_class_loaders = array( |
|
| 557 | + //load_core |
|
| 558 | + 'EE_Capabilities' => 'load_core', |
|
| 559 | + 'EE_Encryption' => 'load_core', |
|
| 560 | + 'EE_Front_Controller' => 'load_core', |
|
| 561 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 562 | + 'EE_Registry' => 'load_core', |
|
| 563 | + 'EE_Request' => function () use (&$request) { |
|
| 564 | + return $request; |
|
| 565 | + }, |
|
| 566 | + 'EE_Response' => function () use (&$response) { |
|
| 567 | + return $response; |
|
| 568 | + }, |
|
| 569 | + 'EE_Request_Handler' => 'load_core', |
|
| 570 | + 'EE_Session' => 'load_core', |
|
| 571 | + 'EE_System' => 'load_core', |
|
| 572 | + //load_lib |
|
| 573 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 574 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 575 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 576 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 577 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 578 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 579 | + 'EE_Message_Repository' => 'load_lib', |
|
| 580 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 581 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 582 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 583 | + 'EE_Messages_Generator' => function () { |
|
| 584 | + return EE_Registry::instance()->load_lib( |
|
| 585 | + 'Messages_Generator', |
|
| 586 | + array(), |
|
| 587 | + false, |
|
| 588 | + false |
|
| 589 | + ); |
|
| 590 | + }, |
|
| 591 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 592 | + return EE_Registry::instance()->load_lib( |
|
| 593 | + 'Messages_Template_Defaults', |
|
| 594 | + $arguments, |
|
| 595 | + false, |
|
| 596 | + false |
|
| 597 | + ); |
|
| 598 | + }, |
|
| 599 | + //load_model |
|
| 600 | + 'EEM_Message_Template_Group' => 'load_model', |
|
| 601 | + 'EEM_Message_Template' => 'load_model', |
|
| 602 | + //load_helper |
|
| 603 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 604 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 605 | + return new EEH_Parse_Shortcodes(); |
|
| 606 | + } |
|
| 607 | + return null; |
|
| 608 | + }, |
|
| 609 | + 'EE_Template_Config' => function () { |
|
| 610 | + return EE_Config::instance()->template_settings; |
|
| 611 | + }, |
|
| 612 | + 'EE_Currency_Config' => function () { |
|
| 613 | + return EE_Config::instance()->currency; |
|
| 614 | + }, |
|
| 615 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
| 616 | + return $loader; |
|
| 617 | + }, |
|
| 618 | + ); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + /** |
|
| 624 | + * can be used for supplying alternate names for classes, |
|
| 625 | + * or for connecting interface names to instantiable classes |
|
| 626 | + */ |
|
| 627 | + protected function _register_core_aliases() |
|
| 628 | + { |
|
| 629 | + $this->_aliases = array( |
|
| 630 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 631 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 632 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 633 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 634 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 635 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 636 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 637 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 638 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 639 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 640 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 641 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 642 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 643 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 644 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 645 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 646 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 647 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 648 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 649 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 650 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 651 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 652 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 653 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 654 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 655 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 656 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 657 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 658 | + ); |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 665 | + * request Primarily used by unit tests. |
|
| 666 | + */ |
|
| 667 | + public function reset() |
|
| 668 | + { |
|
| 669 | + $this->_register_core_class_loaders(); |
|
| 670 | + $this->_register_core_dependencies(); |
|
| 671 | + } |
|
| 672 | 672 | |
| 673 | 673 | |
| 674 | 674 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 5 | 5 | |
| 6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 7 | 7 | exit('No direct script access allowed'); |
| 8 | 8 | } |
| 9 | 9 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
| 117 | 117 | { |
| 118 | 118 | // check if class object is instantiated, and instantiated properly |
| 119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 119 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
| 120 | 120 | self::$_instance = new EE_Dependency_Map($request, $response); |
| 121 | 121 | } |
| 122 | 122 | return self::$_instance; |
@@ -141,15 +141,15 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public static function register_dependencies($class, $dependencies) |
| 143 | 143 | { |
| 144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 144 | + if ( ! isset(self::$_instance->_dependency_map[$class])) { |
|
| 145 | 145 | // we need to make sure that any aliases used when registering a dependency |
| 146 | 146 | // get resolved to the correct class name |
| 147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 147 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
| 148 | 148 | $alias = self::$_instance->get_alias($dependency); |
| 149 | 149 | unset($dependencies[$dependency]); |
| 150 | 150 | $dependencies[$alias] = $load_source; |
| 151 | 151 | } |
| 152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 152 | + self::$_instance->_dependency_map[$class] = (array) $dependencies; |
|
| 153 | 153 | return true; |
| 154 | 154 | } |
| 155 | 155 | return false; |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | ); |
| 182 | 182 | } |
| 183 | 183 | $class_name = self::$_instance->get_alias($class_name); |
| 184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 184 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 185 | 185 | self::$_instance->_class_loaders[$class_name] = $loader; |
| 186 | 186 | return true; |
| 187 | 187 | } |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | public function add_alias($class_name, $alias, $for_class = '') |
| 280 | 280 | { |
| 281 | 281 | if ($for_class !== '') { |
| 282 | - if (! isset($this->_aliases[$for_class])) { |
|
| 282 | + if ( ! isset($this->_aliases[$for_class])) { |
|
| 283 | 283 | $this->_aliases[$for_class] = array(); |
| 284 | 284 | } |
| 285 | 285 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | */ |
| 326 | 326 | public function get_alias($class_name = '', $for_class = '') |
| 327 | 327 | { |
| 328 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 328 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
| 329 | 329 | return $class_name; |
| 330 | 330 | } |
| 331 | 331 | if ($for_class !== '') { |
@@ -560,10 +560,10 @@ discard block |
||
| 560 | 560 | 'EE_Front_Controller' => 'load_core', |
| 561 | 561 | 'EE_Module_Request_Router' => 'load_core', |
| 562 | 562 | 'EE_Registry' => 'load_core', |
| 563 | - 'EE_Request' => function () use (&$request) { |
|
| 563 | + 'EE_Request' => function() use (&$request) { |
|
| 564 | 564 | return $request; |
| 565 | 565 | }, |
| 566 | - 'EE_Response' => function () use (&$response) { |
|
| 566 | + 'EE_Response' => function() use (&$response) { |
|
| 567 | 567 | return $response; |
| 568 | 568 | }, |
| 569 | 569 | 'EE_Request_Handler' => 'load_core', |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | 'EE_Messages_Queue' => 'load_lib', |
| 581 | 581 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
| 582 | 582 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
| 583 | - 'EE_Messages_Generator' => function () { |
|
| 583 | + 'EE_Messages_Generator' => function() { |
|
| 584 | 584 | return EE_Registry::instance()->load_lib( |
| 585 | 585 | 'Messages_Generator', |
| 586 | 586 | array(), |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | false |
| 589 | 589 | ); |
| 590 | 590 | }, |
| 591 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 591 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
| 592 | 592 | return EE_Registry::instance()->load_lib( |
| 593 | 593 | 'Messages_Template_Defaults', |
| 594 | 594 | $arguments, |
@@ -600,19 +600,19 @@ discard block |
||
| 600 | 600 | 'EEM_Message_Template_Group' => 'load_model', |
| 601 | 601 | 'EEM_Message_Template' => 'load_model', |
| 602 | 602 | //load_helper |
| 603 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 603 | + 'EEH_Parse_Shortcodes' => function() { |
|
| 604 | 604 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
| 605 | 605 | return new EEH_Parse_Shortcodes(); |
| 606 | 606 | } |
| 607 | 607 | return null; |
| 608 | 608 | }, |
| 609 | - 'EE_Template_Config' => function () { |
|
| 609 | + 'EE_Template_Config' => function() { |
|
| 610 | 610 | return EE_Config::instance()->template_settings; |
| 611 | 611 | }, |
| 612 | - 'EE_Currency_Config' => function () { |
|
| 612 | + 'EE_Currency_Config' => function() { |
|
| 613 | 613 | return EE_Config::instance()->currency; |
| 614 | 614 | }, |
| 615 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
| 615 | + 'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) { |
|
| 616 | 616 | return $loader; |
| 617 | 617 | }, |
| 618 | 618 | ); |