@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | * Returns template for the additional datetime. |
| 340 | 340 | * @param $template |
| 341 | 341 | * @param $template_args |
| 342 | - * @return mixed |
|
| 342 | + * @return string |
|
| 343 | 343 | * @throws DomainException |
| 344 | 344 | */ |
| 345 | 345 | public function add_additional_datetime_button($template, $template_args) |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | * Returns the template for cloning a datetime. |
| 357 | 357 | * @param $template |
| 358 | 358 | * @param $template_args |
| 359 | - * @return mixed |
|
| 359 | + * @return string |
|
| 360 | 360 | * @throws DomainException |
| 361 | 361 | */ |
| 362 | 362 | public function add_datetime_clone_button($template, $template_args) |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | * Returns the template for datetime timezones. |
| 374 | 374 | * @param $template |
| 375 | 375 | * @param $template_args |
| 376 | - * @return mixed |
|
| 376 | + * @return string |
|
| 377 | 377 | * @throws DomainException |
| 378 | 378 | */ |
| 379 | 379 | public function datetime_timezones_template($template, $template_args) |
@@ -14,1239 +14,1239 @@ |
||
| 14 | 14 | { |
| 15 | 15 | |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Extend_Events_Admin_Page constructor. |
|
| 19 | - * |
|
| 20 | - * @param bool $routing |
|
| 21 | - */ |
|
| 22 | - public function __construct($routing = true) |
|
| 23 | - { |
|
| 24 | - parent::__construct($routing); |
|
| 25 | - if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 26 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
| 27 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
| 28 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
| 29 | - } |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Sets routes. |
|
| 35 | - */ |
|
| 36 | - protected function _extend_page_config() |
|
| 37 | - { |
|
| 38 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
| 39 | - //is there a evt_id in the request? |
|
| 40 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 41 | - ? $this->_req_data['EVT_ID'] |
|
| 42 | - : 0; |
|
| 43 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 44 | - //tkt_id? |
|
| 45 | - $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
| 46 | - ? $this->_req_data['TKT_ID'] |
|
| 47 | - : 0; |
|
| 48 | - $new_page_routes = array( |
|
| 49 | - 'duplicate_event' => array( |
|
| 50 | - 'func' => '_duplicate_event', |
|
| 51 | - 'capability' => 'ee_edit_event', |
|
| 52 | - 'obj_id' => $evt_id, |
|
| 53 | - 'noheader' => true, |
|
| 54 | - ), |
|
| 55 | - 'ticket_list_table' => array( |
|
| 56 | - 'func' => '_tickets_overview_list_table', |
|
| 57 | - 'capability' => 'ee_read_default_tickets', |
|
| 58 | - ), |
|
| 59 | - 'trash_ticket' => array( |
|
| 60 | - 'func' => '_trash_or_restore_ticket', |
|
| 61 | - 'capability' => 'ee_delete_default_ticket', |
|
| 62 | - 'obj_id' => $tkt_id, |
|
| 63 | - 'noheader' => true, |
|
| 64 | - 'args' => array('trash' => true), |
|
| 65 | - ), |
|
| 66 | - 'trash_tickets' => array( |
|
| 67 | - 'func' => '_trash_or_restore_ticket', |
|
| 68 | - 'capability' => 'ee_delete_default_tickets', |
|
| 69 | - 'noheader' => true, |
|
| 70 | - 'args' => array('trash' => true), |
|
| 71 | - ), |
|
| 72 | - 'restore_ticket' => array( |
|
| 73 | - 'func' => '_trash_or_restore_ticket', |
|
| 74 | - 'capability' => 'ee_delete_default_ticket', |
|
| 75 | - 'obj_id' => $tkt_id, |
|
| 76 | - 'noheader' => true, |
|
| 77 | - ), |
|
| 78 | - 'restore_tickets' => array( |
|
| 79 | - 'func' => '_trash_or_restore_ticket', |
|
| 80 | - 'capability' => 'ee_delete_default_tickets', |
|
| 81 | - 'noheader' => true, |
|
| 82 | - ), |
|
| 83 | - 'delete_ticket' => array( |
|
| 84 | - 'func' => '_delete_ticket', |
|
| 85 | - 'capability' => 'ee_delete_default_ticket', |
|
| 86 | - 'obj_id' => $tkt_id, |
|
| 87 | - 'noheader' => true, |
|
| 88 | - ), |
|
| 89 | - 'delete_tickets' => array( |
|
| 90 | - 'func' => '_delete_ticket', |
|
| 91 | - 'capability' => 'ee_delete_default_tickets', |
|
| 92 | - 'noheader' => true, |
|
| 93 | - ), |
|
| 94 | - 'import_page' => array( |
|
| 95 | - 'func' => '_import_page', |
|
| 96 | - 'capability' => 'import', |
|
| 97 | - ), |
|
| 98 | - 'import' => array( |
|
| 99 | - 'func' => '_import_events', |
|
| 100 | - 'capability' => 'import', |
|
| 101 | - 'noheader' => true, |
|
| 102 | - ), |
|
| 103 | - 'import_events' => array( |
|
| 104 | - 'func' => '_import_events', |
|
| 105 | - 'capability' => 'import', |
|
| 106 | - 'noheader' => true, |
|
| 107 | - ), |
|
| 108 | - 'export_events' => array( |
|
| 109 | - 'func' => '_events_export', |
|
| 110 | - 'capability' => 'export', |
|
| 111 | - 'noheader' => true, |
|
| 112 | - ), |
|
| 113 | - 'export_categories' => array( |
|
| 114 | - 'func' => '_categories_export', |
|
| 115 | - 'capability' => 'export', |
|
| 116 | - 'noheader' => true, |
|
| 117 | - ), |
|
| 118 | - 'sample_export_file' => array( |
|
| 119 | - 'func' => '_sample_export_file', |
|
| 120 | - 'capability' => 'export', |
|
| 121 | - 'noheader' => true, |
|
| 122 | - ), |
|
| 123 | - 'update_template_settings' => array( |
|
| 124 | - 'func' => '_update_template_settings', |
|
| 125 | - 'capability' => 'manage_options', |
|
| 126 | - 'noheader' => true, |
|
| 127 | - ), |
|
| 128 | - ); |
|
| 129 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 130 | - //partial route/config override |
|
| 131 | - $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
| 132 | - $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 133 | - $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 134 | - $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 135 | - $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 136 | - $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
| 137 | - //add tickets tab but only if there are more than one default ticket! |
|
| 138 | - $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 139 | - array(array('TKT_is_default' => 1)), |
|
| 140 | - 'TKT_ID', |
|
| 141 | - true |
|
| 142 | - ); |
|
| 143 | - if ($tkt_count > 1) { |
|
| 144 | - $new_page_config = array( |
|
| 145 | - 'ticket_list_table' => array( |
|
| 146 | - 'nav' => array( |
|
| 147 | - 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
| 148 | - 'order' => 60, |
|
| 149 | - ), |
|
| 150 | - 'list_table' => 'Tickets_List_Table', |
|
| 151 | - 'require_nonce' => false, |
|
| 152 | - ), |
|
| 153 | - ); |
|
| 154 | - } |
|
| 155 | - //template settings |
|
| 156 | - $new_page_config['template_settings'] = array( |
|
| 157 | - 'nav' => array( |
|
| 158 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 159 | - 'order' => 30, |
|
| 160 | - ), |
|
| 161 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 162 | - 'help_tabs' => array( |
|
| 163 | - 'general_settings_templates_help_tab' => array( |
|
| 164 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 165 | - 'filename' => 'general_settings_templates', |
|
| 166 | - ), |
|
| 167 | - ), |
|
| 168 | - 'help_tour' => array('Templates_Help_Tour'), |
|
| 169 | - 'require_nonce' => false, |
|
| 170 | - ); |
|
| 171 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 172 | - //add filters and actions |
|
| 173 | - //modifying _views |
|
| 174 | - add_filter( |
|
| 175 | - 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
| 176 | - array($this, 'add_additional_datetime_button'), |
|
| 177 | - 10, |
|
| 178 | - 2 |
|
| 179 | - ); |
|
| 180 | - add_filter( |
|
| 181 | - 'FHEE_event_datetime_metabox_clone_button_template', |
|
| 182 | - array($this, 'add_datetime_clone_button'), |
|
| 183 | - 10, |
|
| 184 | - 2 |
|
| 185 | - ); |
|
| 186 | - add_filter( |
|
| 187 | - 'FHEE_event_datetime_metabox_timezones_template', |
|
| 188 | - array($this, 'datetime_timezones_template'), |
|
| 189 | - 10, |
|
| 190 | - 2 |
|
| 191 | - ); |
|
| 192 | - //filters for event list table |
|
| 193 | - add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2); |
|
| 194 | - add_filter( |
|
| 195 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 196 | - array($this, 'extra_list_table_actions'), |
|
| 197 | - 10, |
|
| 198 | - 2 |
|
| 199 | - ); |
|
| 200 | - //legend item |
|
| 201 | - add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items')); |
|
| 202 | - add_action('admin_init', array($this, 'admin_init')); |
|
| 203 | - //heartbeat stuff |
|
| 204 | - add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * admin_init |
|
| 210 | - */ |
|
| 211 | - public function admin_init() |
|
| 212 | - { |
|
| 213 | - EE_Registry::$i18n_js_strings = array_merge( |
|
| 214 | - EE_Registry::$i18n_js_strings, |
|
| 215 | - array( |
|
| 216 | - 'image_confirm' => esc_html__( |
|
| 217 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 218 | - 'event_espresso' |
|
| 219 | - ), |
|
| 220 | - 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
| 221 | - 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
| 222 | - 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
| 223 | - 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
| 224 | - 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
| 225 | - ) |
|
| 226 | - ); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle |
|
| 232 | - * accordingly. |
|
| 233 | - * |
|
| 234 | - * @param array $response The existing heartbeat response array. |
|
| 235 | - * @param array $data The incoming data package. |
|
| 236 | - * @return array possibly appended response. |
|
| 237 | - */ |
|
| 238 | - public function heartbeat_response($response, $data) |
|
| 239 | - { |
|
| 240 | - /** |
|
| 241 | - * check whether count of tickets is approaching the potential |
|
| 242 | - * limits for the server. |
|
| 243 | - */ |
|
| 244 | - if (! empty($data['input_count'])) { |
|
| 245 | - $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check( |
|
| 246 | - $data['input_count'] |
|
| 247 | - ); |
|
| 248 | - } |
|
| 249 | - return $response; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Add per page screen options to the default ticket list table view. |
|
| 255 | - */ |
|
| 256 | - protected function _add_screen_options_ticket_list_table() |
|
| 257 | - { |
|
| 258 | - $this->_per_page_screen_option(); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @param string $return |
|
| 264 | - * @param int $id |
|
| 265 | - * @param string $new_title |
|
| 266 | - * @param string $new_slug |
|
| 267 | - * @return string |
|
| 268 | - */ |
|
| 269 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 270 | - { |
|
| 271 | - $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
| 272 | - //make sure this is only when editing |
|
| 273 | - if (! empty($id)) { |
|
| 274 | - $href = EE_Admin_Page::add_query_args_and_nonce( |
|
| 275 | - array('action' => 'duplicate_event', 'EVT_ID' => $id), |
|
| 276 | - $this->_admin_base_url |
|
| 277 | - ); |
|
| 278 | - $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
| 279 | - $return .= '<a href="' |
|
| 280 | - . $href |
|
| 281 | - . '" title="' |
|
| 282 | - . $title |
|
| 283 | - . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
| 284 | - . $title |
|
| 285 | - . '</button>'; |
|
| 286 | - } |
|
| 287 | - return $return; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Set the list table views for the default ticket list table view. |
|
| 293 | - */ |
|
| 294 | - public function _set_list_table_views_ticket_list_table() |
|
| 295 | - { |
|
| 296 | - $this->_views = array( |
|
| 297 | - 'all' => array( |
|
| 298 | - 'slug' => 'all', |
|
| 299 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 300 | - 'count' => 0, |
|
| 301 | - 'bulk_action' => array( |
|
| 302 | - 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 303 | - ), |
|
| 304 | - ), |
|
| 305 | - 'trashed' => array( |
|
| 306 | - 'slug' => 'trashed', |
|
| 307 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 308 | - 'count' => 0, |
|
| 309 | - 'bulk_action' => array( |
|
| 310 | - 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 311 | - 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 312 | - ), |
|
| 313 | - ), |
|
| 314 | - ); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Enqueue scripts and styles for the event editor. |
|
| 320 | - */ |
|
| 321 | - public function load_scripts_styles_edit() |
|
| 322 | - { |
|
| 323 | - wp_register_script( |
|
| 324 | - 'ee-event-editor-heartbeat', |
|
| 325 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
| 326 | - array('ee_admin_js', 'heartbeat'), |
|
| 327 | - EVENT_ESPRESSO_VERSION, |
|
| 328 | - true |
|
| 329 | - ); |
|
| 330 | - wp_enqueue_script('ee-accounting'); |
|
| 331 | - //styles |
|
| 332 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 333 | - wp_enqueue_script('event_editor_js'); |
|
| 334 | - wp_enqueue_script('ee-event-editor-heartbeat'); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Returns template for the additional datetime. |
|
| 340 | - * @param $template |
|
| 341 | - * @param $template_args |
|
| 342 | - * @return mixed |
|
| 343 | - * @throws DomainException |
|
| 344 | - */ |
|
| 345 | - public function add_additional_datetime_button($template, $template_args) |
|
| 346 | - { |
|
| 347 | - return EEH_Template::display_template( |
|
| 348 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
| 349 | - $template_args, |
|
| 350 | - true |
|
| 351 | - ); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Returns the template for cloning a datetime. |
|
| 357 | - * @param $template |
|
| 358 | - * @param $template_args |
|
| 359 | - * @return mixed |
|
| 360 | - * @throws DomainException |
|
| 361 | - */ |
|
| 362 | - public function add_datetime_clone_button($template, $template_args) |
|
| 363 | - { |
|
| 364 | - return EEH_Template::display_template( |
|
| 365 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
| 366 | - $template_args, |
|
| 367 | - true |
|
| 368 | - ); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Returns the template for datetime timezones. |
|
| 374 | - * @param $template |
|
| 375 | - * @param $template_args |
|
| 376 | - * @return mixed |
|
| 377 | - * @throws DomainException |
|
| 378 | - */ |
|
| 379 | - public function datetime_timezones_template($template, $template_args) |
|
| 380 | - { |
|
| 381 | - return EEH_Template::display_template( |
|
| 382 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
| 383 | - $template_args, |
|
| 384 | - true |
|
| 385 | - ); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Sets the views for the default list table view. |
|
| 391 | - */ |
|
| 392 | - protected function _set_list_table_views_default() |
|
| 393 | - { |
|
| 394 | - parent::_set_list_table_views_default(); |
|
| 395 | - $new_views = array( |
|
| 396 | - 'today' => array( |
|
| 397 | - 'slug' => 'today', |
|
| 398 | - 'label' => esc_html__('Today', 'event_espresso'), |
|
| 399 | - 'count' => $this->total_events_today(), |
|
| 400 | - 'bulk_action' => array( |
|
| 401 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 402 | - ), |
|
| 403 | - ), |
|
| 404 | - 'month' => array( |
|
| 405 | - 'slug' => 'month', |
|
| 406 | - 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 407 | - 'count' => $this->total_events_this_month(), |
|
| 408 | - 'bulk_action' => array( |
|
| 409 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 410 | - ), |
|
| 411 | - ), |
|
| 412 | - ); |
|
| 413 | - $this->_views = array_merge($this->_views, $new_views); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * Returns the extra action links for the default list table view. |
|
| 419 | - * @param array $action_links |
|
| 420 | - * @param \EE_Event $event |
|
| 421 | - * @return array |
|
| 422 | - * @throws EE_Error |
|
| 423 | - */ |
|
| 424 | - public function extra_list_table_actions(array $action_links, \EE_Event $event) |
|
| 425 | - { |
|
| 426 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 427 | - 'ee_read_registrations', |
|
| 428 | - 'espresso_registrations_reports', |
|
| 429 | - $event->ID() |
|
| 430 | - ) |
|
| 431 | - ) { |
|
| 432 | - $reports_query_args = array( |
|
| 433 | - 'action' => 'reports', |
|
| 434 | - 'EVT_ID' => $event->ID(), |
|
| 435 | - ); |
|
| 436 | - $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
| 437 | - $action_links[] = '<a href="' |
|
| 438 | - . $reports_link |
|
| 439 | - . '" title="' |
|
| 440 | - . esc_attr__('View Report', 'event_espresso') |
|
| 441 | - . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
| 442 | - . "\n\t"; |
|
| 443 | - } |
|
| 444 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 445 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 446 | - $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
| 447 | - 'see_notifications_for', |
|
| 448 | - null, |
|
| 449 | - array('EVT_ID' => $event->ID()) |
|
| 450 | - ); |
|
| 451 | - } |
|
| 452 | - return $action_links; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * @param $items |
|
| 458 | - * @return mixed |
|
| 459 | - */ |
|
| 460 | - public function additional_legend_items($items) |
|
| 461 | - { |
|
| 462 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 463 | - 'ee_read_registrations', |
|
| 464 | - 'espresso_registrations_reports' |
|
| 465 | - ) |
|
| 466 | - ) { |
|
| 467 | - $items['reports'] = array( |
|
| 468 | - 'class' => 'dashicons dashicons-chart-bar', |
|
| 469 | - 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
| 470 | - ); |
|
| 471 | - } |
|
| 472 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 473 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 474 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 475 | - $items['view_related_messages'] = array( |
|
| 476 | - 'class' => $related_for_icon['css_class'], |
|
| 477 | - 'desc' => $related_for_icon['label'], |
|
| 478 | - ); |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - return $items; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * This is the callback method for the duplicate event route |
|
| 487 | - * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
| 488 | - * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
| 489 | - * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
| 490 | - * After duplication the redirect is to the new event edit page. |
|
| 491 | - * |
|
| 492 | - * @return void |
|
| 493 | - * @access protected |
|
| 494 | - * @throws EE_Error If EE_Event is not available with given ID |
|
| 495 | - */ |
|
| 496 | - protected function _duplicate_event() |
|
| 497 | - { |
|
| 498 | - // first make sure the ID for the event is in the request. |
|
| 499 | - // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
| 500 | - if (! isset($this->_req_data['EVT_ID'])) { |
|
| 501 | - EE_Error::add_error( |
|
| 502 | - esc_html__( |
|
| 503 | - 'In order to duplicate an event an Event ID is required. None was given.', |
|
| 504 | - 'event_espresso' |
|
| 505 | - ), |
|
| 506 | - __FILE__, |
|
| 507 | - __FUNCTION__, |
|
| 508 | - __LINE__ |
|
| 509 | - ); |
|
| 510 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 511 | - return; |
|
| 512 | - } |
|
| 513 | - //k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
| 514 | - $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
| 515 | - if (! $orig_event instanceof EE_Event) { |
|
| 516 | - throw new EE_Error( |
|
| 517 | - sprintf( |
|
| 518 | - esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
| 519 | - $this->_req_data['EVT_ID'] |
|
| 520 | - ) |
|
| 521 | - ); |
|
| 522 | - } |
|
| 523 | - //k now let's clone the $orig_event before getting relations |
|
| 524 | - $new_event = clone $orig_event; |
|
| 525 | - //original datetimes |
|
| 526 | - $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
| 527 | - //other original relations |
|
| 528 | - $orig_ven = $orig_event->get_many_related('Venue'); |
|
| 529 | - //reset the ID and modify other details to make it clear this is a dupe |
|
| 530 | - $new_event->set('EVT_ID', 0); |
|
| 531 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 532 | - $new_event->set('EVT_name', $new_name); |
|
| 533 | - $new_event->set( |
|
| 534 | - 'EVT_slug', |
|
| 535 | - wp_unique_post_slug( |
|
| 536 | - sanitize_title($orig_event->name()), |
|
| 537 | - 0, |
|
| 538 | - 'publish', |
|
| 539 | - 'espresso_events', |
|
| 540 | - 0 |
|
| 541 | - ) |
|
| 542 | - ); |
|
| 543 | - $new_event->set('status', 'draft'); |
|
| 544 | - //duplicate discussion settings |
|
| 545 | - $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
| 546 | - $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
| 547 | - //save the new event |
|
| 548 | - $new_event->save(); |
|
| 549 | - //venues |
|
| 550 | - foreach ($orig_ven as $ven) { |
|
| 551 | - $new_event->_add_relation_to($ven, 'Venue'); |
|
| 552 | - } |
|
| 553 | - $new_event->save(); |
|
| 554 | - //now we need to get the question group relations and handle that |
|
| 555 | - //first primary question groups |
|
| 556 | - $orig_primary_qgs = $orig_event->get_many_related( |
|
| 557 | - 'Question_Group', |
|
| 558 | - array(array('Event_Question_Group.EQG_primary' => 1)) |
|
| 559 | - ); |
|
| 560 | - if (! empty($orig_primary_qgs)) { |
|
| 561 | - foreach ($orig_primary_qgs as $id => $obj) { |
|
| 562 | - if ($obj instanceof EE_Question_Group) { |
|
| 563 | - $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1)); |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - //next additional attendee question groups |
|
| 568 | - $orig_additional_qgs = $orig_event->get_many_related( |
|
| 569 | - 'Question_Group', |
|
| 570 | - array(array('Event_Question_Group.EQG_primary' => 0)) |
|
| 571 | - ); |
|
| 572 | - if (! empty($orig_additional_qgs)) { |
|
| 573 | - foreach ($orig_additional_qgs as $id => $obj) { |
|
| 574 | - if ($obj instanceof EE_Question_Group) { |
|
| 575 | - $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0)); |
|
| 576 | - } |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - //now save |
|
| 580 | - $new_event->save(); |
|
| 581 | - //k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
| 582 | - $cloned_tickets = array(); |
|
| 583 | - foreach ($orig_datetimes as $orig_dtt) { |
|
| 584 | - if (! $orig_dtt instanceof EE_Datetime) { |
|
| 585 | - continue; |
|
| 586 | - } |
|
| 587 | - $new_dtt = clone $orig_dtt; |
|
| 588 | - $orig_tkts = $orig_dtt->tickets(); |
|
| 589 | - //save new dtt then add to event |
|
| 590 | - $new_dtt->set('DTT_ID', 0); |
|
| 591 | - $new_dtt->set('DTT_sold', 0); |
|
| 592 | - $new_dtt->set_reserved(0); |
|
| 593 | - $new_dtt->save(); |
|
| 594 | - $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
| 595 | - $new_event->save(); |
|
| 596 | - //now let's get the ticket relations setup. |
|
| 597 | - foreach ((array)$orig_tkts as $orig_tkt) { |
|
| 598 | - //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
| 599 | - if (! $orig_tkt instanceof EE_Ticket) { |
|
| 600 | - continue; |
|
| 601 | - } |
|
| 602 | - //is this ticket archived? If it is then let's skip |
|
| 603 | - if ($orig_tkt->get('TKT_deleted')) { |
|
| 604 | - continue; |
|
| 605 | - } |
|
| 606 | - // does this original ticket already exist in the clone_tickets cache? |
|
| 607 | - // If so we'll just use the new ticket from it. |
|
| 608 | - if (isset($cloned_tickets[$orig_tkt->ID()])) { |
|
| 609 | - $new_tkt = $cloned_tickets[$orig_tkt->ID()]; |
|
| 610 | - } else { |
|
| 611 | - $new_tkt = clone $orig_tkt; |
|
| 612 | - //get relations on the $orig_tkt that we need to setup. |
|
| 613 | - $orig_prices = $orig_tkt->prices(); |
|
| 614 | - $new_tkt->set('TKT_ID', 0); |
|
| 615 | - $new_tkt->set('TKT_sold', 0); |
|
| 616 | - $new_tkt->set('TKT_reserved', 0); |
|
| 617 | - $new_tkt->save(); //make sure new ticket has ID. |
|
| 618 | - //price relations on new ticket need to be setup. |
|
| 619 | - foreach ($orig_prices as $orig_price) { |
|
| 620 | - $new_price = clone $orig_price; |
|
| 621 | - $new_price->set('PRC_ID', 0); |
|
| 622 | - $new_price->save(); |
|
| 623 | - $new_tkt->_add_relation_to($new_price, 'Price'); |
|
| 624 | - $new_tkt->save(); |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - // k now we can add the new ticket as a relation to the new datetime |
|
| 628 | - // and make sure its added to our cached $cloned_tickets array |
|
| 629 | - // for use with later datetimes that have the same ticket. |
|
| 630 | - $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
| 631 | - $new_dtt->save(); |
|
| 632 | - $cloned_tickets[$orig_tkt->ID()] = $new_tkt; |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - //clone taxonomy information |
|
| 636 | - $taxonomies_to_clone_with = apply_filters( |
|
| 637 | - 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
| 638 | - array('espresso_event_categories', 'espresso_event_type', 'post_tag') |
|
| 639 | - ); |
|
| 640 | - //get terms for original event (notice) |
|
| 641 | - $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
| 642 | - //loop through terms and add them to new event. |
|
| 643 | - foreach ($orig_terms as $term) { |
|
| 644 | - wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
| 645 | - } |
|
| 646 | - do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
| 647 | - //now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
| 648 | - if ($new_event->ID()) { |
|
| 649 | - $redirect_args = array( |
|
| 650 | - 'post' => $new_event->ID(), |
|
| 651 | - 'action' => 'edit', |
|
| 652 | - ); |
|
| 653 | - EE_Error::add_success( |
|
| 654 | - esc_html__( |
|
| 655 | - 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
| 656 | - 'event_espresso' |
|
| 657 | - ) |
|
| 658 | - ); |
|
| 659 | - } else { |
|
| 660 | - $redirect_args = array( |
|
| 661 | - 'action' => 'default', |
|
| 662 | - ); |
|
| 663 | - EE_Error::add_error( |
|
| 664 | - esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
| 665 | - __FILE__, |
|
| 666 | - __FUNCTION__, |
|
| 667 | - __LINE__ |
|
| 668 | - ); |
|
| 669 | - } |
|
| 670 | - $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * Generates output for the import page. |
|
| 676 | - * @throws DomainException |
|
| 677 | - */ |
|
| 678 | - protected function _import_page() |
|
| 679 | - { |
|
| 680 | - $title = esc_html__('Import', 'event_espresso'); |
|
| 681 | - $intro = esc_html__( |
|
| 682 | - 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
| 683 | - 'event_espresso' |
|
| 684 | - ); |
|
| 685 | - $form_url = EVENTS_ADMIN_URL; |
|
| 686 | - $action = 'import_events'; |
|
| 687 | - $type = 'csv'; |
|
| 688 | - $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
| 689 | - $title, $intro, $form_url, $action, $type |
|
| 690 | - ); |
|
| 691 | - $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 692 | - array('action' => 'sample_export_file'), |
|
| 693 | - $this->_admin_base_url |
|
| 694 | - ); |
|
| 695 | - $content = EEH_Template::display_template( |
|
| 696 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
| 697 | - $this->_template_args, |
|
| 698 | - true |
|
| 699 | - ); |
|
| 700 | - $this->_template_args['admin_page_content'] = $content; |
|
| 701 | - $this->display_admin_page_with_sidebar(); |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * _import_events |
|
| 707 | - * This handles displaying the screen and running imports for importing events. |
|
| 708 | - * |
|
| 709 | - * @return void |
|
| 710 | - */ |
|
| 711 | - protected function _import_events() |
|
| 712 | - { |
|
| 713 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
| 714 | - $success = EE_Import::instance()->import(); |
|
| 715 | - $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - |
|
| 719 | - /** |
|
| 720 | - * _events_export |
|
| 721 | - * Will export all (or just the given event) to a Excel compatible file. |
|
| 722 | - * |
|
| 723 | - * @access protected |
|
| 724 | - * @return void |
|
| 725 | - */ |
|
| 726 | - protected function _events_export() |
|
| 727 | - { |
|
| 728 | - if (isset($this->_req_data['EVT_ID'])) { |
|
| 729 | - $event_ids = $this->_req_data['EVT_ID']; |
|
| 730 | - } elseif (isset($this->_req_data['EVT_IDs'])) { |
|
| 731 | - $event_ids = $this->_req_data['EVT_IDs']; |
|
| 732 | - } else { |
|
| 733 | - $event_ids = null; |
|
| 734 | - } |
|
| 735 | - //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 736 | - $new_request_args = array( |
|
| 737 | - 'export' => 'report', |
|
| 738 | - 'action' => 'all_event_data', |
|
| 739 | - 'EVT_ID' => $event_ids, |
|
| 740 | - ); |
|
| 741 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 742 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 743 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 744 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 745 | - $EE_Export->export(); |
|
| 746 | - } |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * handle category exports() |
|
| 752 | - * |
|
| 753 | - * @return void |
|
| 754 | - */ |
|
| 755 | - protected function _categories_export() |
|
| 756 | - { |
|
| 757 | - //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 758 | - $new_request_args = array( |
|
| 759 | - 'export' => 'report', |
|
| 760 | - 'action' => 'categories', |
|
| 761 | - 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
| 762 | - ); |
|
| 763 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 764 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 765 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 766 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 767 | - $EE_Export->export(); |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * Creates a sample CSV file for importing |
|
| 774 | - */ |
|
| 775 | - protected function _sample_export_file() |
|
| 776 | - { |
|
| 777 | - // require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 778 | - EE_Export::instance()->export_sample(); |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - |
|
| 782 | - /************* Template Settings *************/ |
|
| 783 | - /** |
|
| 784 | - * Generates template settings page output |
|
| 785 | - * @throws DomainException |
|
| 786 | - * @throws EE_Error |
|
| 787 | - */ |
|
| 788 | - protected function _template_settings() |
|
| 789 | - { |
|
| 790 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 791 | - /** |
|
| 792 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 793 | - * from General_Settings_Admin_Page to here. |
|
| 794 | - */ |
|
| 795 | - $this->_template_args = apply_filters( |
|
| 796 | - 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
| 797 | - $this->_template_args |
|
| 798 | - ); |
|
| 799 | - $this->_set_add_edit_form_tags('update_template_settings'); |
|
| 800 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 801 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 802 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
| 803 | - $this->_template_args, |
|
| 804 | - true |
|
| 805 | - ); |
|
| 806 | - $this->display_admin_page_with_sidebar(); |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - |
|
| 810 | - /** |
|
| 811 | - * Handler for updating template settings. |
|
| 812 | - */ |
|
| 813 | - protected function _update_template_settings() |
|
| 814 | - { |
|
| 815 | - /** |
|
| 816 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 817 | - * from General_Settings_Admin_Page to here. |
|
| 818 | - */ |
|
| 819 | - EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
| 820 | - 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
| 821 | - EE_Registry::instance()->CFG->template_settings, |
|
| 822 | - $this->_req_data |
|
| 823 | - ); |
|
| 824 | - //update custom post type slugs and detect if we need to flush rewrite rules |
|
| 825 | - $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
| 826 | - EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
| 827 | - ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
| 828 | - : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']); |
|
| 829 | - $what = 'Template Settings'; |
|
| 830 | - $success = $this->_update_espresso_configuration( |
|
| 831 | - $what, |
|
| 832 | - EE_Registry::instance()->CFG->template_settings, |
|
| 833 | - __FILE__, |
|
| 834 | - __FUNCTION__, |
|
| 835 | - __LINE__ |
|
| 836 | - ); |
|
| 837 | - if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
| 838 | - update_option('ee_flush_rewrite_rules', true); |
|
| 839 | - } |
|
| 840 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings')); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - |
|
| 844 | - /** |
|
| 845 | - * _premium_event_editor_meta_boxes |
|
| 846 | - * add all metaboxes related to the event_editor |
|
| 847 | - * |
|
| 848 | - * @access protected |
|
| 849 | - * @return void |
|
| 850 | - * @throws EE_Error |
|
| 851 | - */ |
|
| 852 | - protected function _premium_event_editor_meta_boxes() |
|
| 853 | - { |
|
| 854 | - $this->verify_cpt_object(); |
|
| 855 | - add_meta_box( |
|
| 856 | - 'espresso_event_editor_event_options', |
|
| 857 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 858 | - array($this, 'registration_options_meta_box'), |
|
| 859 | - $this->page_slug, |
|
| 860 | - 'side', |
|
| 861 | - 'core' |
|
| 862 | - ); |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - |
|
| 866 | - /** |
|
| 867 | - * override caf metabox |
|
| 868 | - * |
|
| 869 | - * @return void |
|
| 870 | - * @throws DomainException |
|
| 871 | - */ |
|
| 872 | - public function registration_options_meta_box() |
|
| 873 | - { |
|
| 874 | - $yes_no_values = array( |
|
| 875 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 876 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 877 | - ); |
|
| 878 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 879 | - array( |
|
| 880 | - EEM_Registration::status_id_cancelled, |
|
| 881 | - EEM_Registration::status_id_declined, |
|
| 882 | - EEM_Registration::status_id_incomplete, |
|
| 883 | - EEM_Registration::status_id_wait_list, |
|
| 884 | - ), |
|
| 885 | - true |
|
| 886 | - ); |
|
| 887 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 888 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 889 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 890 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 891 | - 'default_reg_status', |
|
| 892 | - $default_reg_status_values, |
|
| 893 | - $this->_cpt_model_obj->default_registration_status() |
|
| 894 | - ); |
|
| 895 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 896 | - 'display_desc', |
|
| 897 | - $yes_no_values, |
|
| 898 | - $this->_cpt_model_obj->display_description() |
|
| 899 | - ); |
|
| 900 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 901 | - 'display_ticket_selector', |
|
| 902 | - $yes_no_values, |
|
| 903 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 904 | - '', |
|
| 905 | - '', |
|
| 906 | - false |
|
| 907 | - ); |
|
| 908 | - $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 909 | - 'EVT_default_registration_status', |
|
| 910 | - $default_reg_status_values, |
|
| 911 | - $this->_cpt_model_obj->default_registration_status() |
|
| 912 | - ); |
|
| 913 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 914 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 915 | - '', |
|
| 916 | - $template_args, |
|
| 917 | - $yes_no_values, |
|
| 918 | - $default_reg_status_values |
|
| 919 | - ); |
|
| 920 | - EEH_Template::display_template( |
|
| 921 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 922 | - $template_args |
|
| 923 | - ); |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * wp_list_table_mods for caf |
|
| 930 | - * ============================ |
|
| 931 | - */ |
|
| 932 | - /** |
|
| 933 | - * hook into list table filters and provide filters for caffeinated list table |
|
| 934 | - * |
|
| 935 | - * @param array $old_filters any existing filters present |
|
| 936 | - * @param array $list_table_obj the list table object |
|
| 937 | - * @return array new filters |
|
| 938 | - */ |
|
| 939 | - public function list_table_filters($old_filters, $list_table_obj) |
|
| 940 | - { |
|
| 941 | - $filters = array(); |
|
| 942 | - //first month/year filters |
|
| 943 | - $filters[] = $this->espresso_event_months_dropdown(); |
|
| 944 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 945 | - //active status dropdown |
|
| 946 | - if ($status !== 'draft') { |
|
| 947 | - $filters[] = $this->active_status_dropdown( |
|
| 948 | - isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
| 949 | - ); |
|
| 950 | - } |
|
| 951 | - //category filter |
|
| 952 | - $filters[] = $this->category_dropdown(); |
|
| 953 | - return array_merge($old_filters, $filters); |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * espresso_event_months_dropdown |
|
| 959 | - * |
|
| 960 | - * @access public |
|
| 961 | - * @return string dropdown listing month/year selections for events. |
|
| 962 | - */ |
|
| 963 | - public function espresso_event_months_dropdown() |
|
| 964 | - { |
|
| 965 | - // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
| 966 | - // Note we need to include any other filters that are set! |
|
| 967 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 968 | - //categories? |
|
| 969 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 970 | - ? $this->_req_data['EVT_CAT'] |
|
| 971 | - : null; |
|
| 972 | - //active status? |
|
| 973 | - $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
| 974 | - $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
| 975 | - return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - |
|
| 979 | - /** |
|
| 980 | - * returns a list of "active" statuses on the event |
|
| 981 | - * |
|
| 982 | - * @param string $current_value whatever the current active status is |
|
| 983 | - * @return string |
|
| 984 | - */ |
|
| 985 | - public function active_status_dropdown($current_value = '') |
|
| 986 | - { |
|
| 987 | - $select_name = 'active_status'; |
|
| 988 | - $values = array( |
|
| 989 | - 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
| 990 | - 'active' => esc_html__('Active', 'event_espresso'), |
|
| 991 | - 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
| 992 | - 'expired' => esc_html__('Expired', 'event_espresso'), |
|
| 993 | - 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
| 994 | - ); |
|
| 995 | - $id = 'id="espresso-active-status-dropdown-filter"'; |
|
| 996 | - $class = 'wide'; |
|
| 997 | - return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class); |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - |
|
| 1001 | - /** |
|
| 1002 | - * output a dropdown of the categories for the category filter on the event admin list table |
|
| 1003 | - * |
|
| 1004 | - * @access public |
|
| 1005 | - * @return string html |
|
| 1006 | - */ |
|
| 1007 | - public function category_dropdown() |
|
| 1008 | - { |
|
| 1009 | - $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
| 1010 | - return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - |
|
| 1014 | - /** |
|
| 1015 | - * get total number of events today |
|
| 1016 | - * |
|
| 1017 | - * @access public |
|
| 1018 | - * @return int |
|
| 1019 | - * @throws EE_Error |
|
| 1020 | - */ |
|
| 1021 | - public function total_events_today() |
|
| 1022 | - { |
|
| 1023 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1024 | - 'DTT_EVT_start', |
|
| 1025 | - date('Y-m-d') . ' 00:00:00', |
|
| 1026 | - 'Y-m-d H:i:s', |
|
| 1027 | - 'UTC' |
|
| 1028 | - ); |
|
| 1029 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1030 | - 'DTT_EVT_start', |
|
| 1031 | - date('Y-m-d') . ' 23:59:59', |
|
| 1032 | - 'Y-m-d H:i:s', |
|
| 1033 | - 'UTC' |
|
| 1034 | - ); |
|
| 1035 | - $where = array( |
|
| 1036 | - 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
| 1037 | - ); |
|
| 1038 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 1039 | - return $count; |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - /** |
|
| 1044 | - * get total number of events this month |
|
| 1045 | - * |
|
| 1046 | - * @access public |
|
| 1047 | - * @return int |
|
| 1048 | - * @throws EE_Error |
|
| 1049 | - */ |
|
| 1050 | - public function total_events_this_month() |
|
| 1051 | - { |
|
| 1052 | - //Dates |
|
| 1053 | - $this_year_r = date('Y'); |
|
| 1054 | - $this_month_r = date('m'); |
|
| 1055 | - $days_this_month = date('t'); |
|
| 1056 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1057 | - 'DTT_EVT_start', |
|
| 1058 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
| 1059 | - 'Y-m-d H:i:s', |
|
| 1060 | - 'UTC' |
|
| 1061 | - ); |
|
| 1062 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1063 | - 'DTT_EVT_start', |
|
| 1064 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
| 1065 | - 'Y-m-d H:i:s', |
|
| 1066 | - 'UTC' |
|
| 1067 | - ); |
|
| 1068 | - $where = array( |
|
| 1069 | - 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
| 1070 | - ); |
|
| 1071 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 1072 | - return $count; |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - |
|
| 1076 | - /** DEFAULT TICKETS STUFF **/ |
|
| 1077 | - |
|
| 1078 | - /** |
|
| 1079 | - * Output default tickets list table view. |
|
| 1080 | - */ |
|
| 1081 | - public function _tickets_overview_list_table() |
|
| 1082 | - { |
|
| 1083 | - $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
| 1084 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1085 | - } |
|
| 1086 | - |
|
| 1087 | - |
|
| 1088 | - /** |
|
| 1089 | - * @param int $per_page |
|
| 1090 | - * @param bool $count |
|
| 1091 | - * @param bool $trashed |
|
| 1092 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 1093 | - */ |
|
| 1094 | - public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
| 1095 | - { |
|
| 1096 | - $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
| 1097 | - $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
| 1098 | - switch ($orderby) { |
|
| 1099 | - case 'TKT_name': |
|
| 1100 | - $orderby = array('TKT_name' => $order); |
|
| 1101 | - break; |
|
| 1102 | - case 'TKT_price': |
|
| 1103 | - $orderby = array('TKT_price' => $order); |
|
| 1104 | - break; |
|
| 1105 | - case 'TKT_uses': |
|
| 1106 | - $orderby = array('TKT_uses' => $order); |
|
| 1107 | - break; |
|
| 1108 | - case 'TKT_min': |
|
| 1109 | - $orderby = array('TKT_min' => $order); |
|
| 1110 | - break; |
|
| 1111 | - case 'TKT_max': |
|
| 1112 | - $orderby = array('TKT_max' => $order); |
|
| 1113 | - break; |
|
| 1114 | - case 'TKT_qty': |
|
| 1115 | - $orderby = array('TKT_qty' => $order); |
|
| 1116 | - break; |
|
| 1117 | - } |
|
| 1118 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1119 | - ? $this->_req_data['paged'] |
|
| 1120 | - : 1; |
|
| 1121 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1122 | - ? $this->_req_data['perpage'] |
|
| 1123 | - : $per_page; |
|
| 1124 | - $_where = array( |
|
| 1125 | - 'TKT_is_default' => 1, |
|
| 1126 | - 'TKT_deleted' => $trashed, |
|
| 1127 | - ); |
|
| 1128 | - $offset = ($current_page - 1) * $per_page; |
|
| 1129 | - $limit = array($offset, $per_page); |
|
| 1130 | - if (isset($this->_req_data['s'])) { |
|
| 1131 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1132 | - $_where['OR'] = array( |
|
| 1133 | - 'TKT_name' => array('LIKE', $sstr), |
|
| 1134 | - 'TKT_description' => array('LIKE', $sstr), |
|
| 1135 | - ); |
|
| 1136 | - } |
|
| 1137 | - $query_params = array( |
|
| 1138 | - $_where, |
|
| 1139 | - 'order_by' => $orderby, |
|
| 1140 | - 'limit' => $limit, |
|
| 1141 | - 'group_by' => 'TKT_ID', |
|
| 1142 | - ); |
|
| 1143 | - if ($count) { |
|
| 1144 | - return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where)); |
|
| 1145 | - } else { |
|
| 1146 | - return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 1147 | - } |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - |
|
| 1151 | - /** |
|
| 1152 | - * @param bool $trash |
|
| 1153 | - * @throws EE_Error |
|
| 1154 | - */ |
|
| 1155 | - protected function _trash_or_restore_ticket($trash = false) |
|
| 1156 | - { |
|
| 1157 | - $success = 1; |
|
| 1158 | - $TKT = EEM_Ticket::instance(); |
|
| 1159 | - //checkboxes? |
|
| 1160 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1161 | - //if array has more than one element then success message should be plural |
|
| 1162 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1163 | - //cycle thru the boxes |
|
| 1164 | - while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1165 | - if ($trash) { |
|
| 1166 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1167 | - $success = 0; |
|
| 1168 | - } |
|
| 1169 | - } else { |
|
| 1170 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1171 | - $success = 0; |
|
| 1172 | - } |
|
| 1173 | - } |
|
| 1174 | - } |
|
| 1175 | - } else { |
|
| 1176 | - //grab single id and trash |
|
| 1177 | - $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1178 | - if ($trash) { |
|
| 1179 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1180 | - $success = 0; |
|
| 1181 | - } |
|
| 1182 | - } else { |
|
| 1183 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1184 | - $success = 0; |
|
| 1185 | - } |
|
| 1186 | - } |
|
| 1187 | - } |
|
| 1188 | - $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
| 1189 | - $query_args = array( |
|
| 1190 | - 'action' => 'ticket_list_table', |
|
| 1191 | - 'status' => $trash ? '' : 'trashed', |
|
| 1192 | - ); |
|
| 1193 | - $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - |
|
| 1197 | - /** |
|
| 1198 | - * Handles trashing default ticket. |
|
| 1199 | - */ |
|
| 1200 | - protected function _delete_ticket() |
|
| 1201 | - { |
|
| 1202 | - $success = 1; |
|
| 1203 | - //checkboxes? |
|
| 1204 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1205 | - //if array has more than one element then success message should be plural |
|
| 1206 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1207 | - //cycle thru the boxes |
|
| 1208 | - while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1209 | - //delete |
|
| 1210 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1211 | - $success = 0; |
|
| 1212 | - } |
|
| 1213 | - } |
|
| 1214 | - } else { |
|
| 1215 | - //grab single id and trash |
|
| 1216 | - $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1217 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1218 | - $success = 0; |
|
| 1219 | - } |
|
| 1220 | - } |
|
| 1221 | - $action_desc = 'deleted'; |
|
| 1222 | - $query_args = array( |
|
| 1223 | - 'action' => 'ticket_list_table', |
|
| 1224 | - 'status' => 'trashed', |
|
| 1225 | - ); |
|
| 1226 | - //fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
| 1227 | - if (EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 1228 | - array(array('TKT_is_default' => 1)), |
|
| 1229 | - 'TKT_ID', |
|
| 1230 | - true |
|
| 1231 | - ) |
|
| 1232 | - ) { |
|
| 1233 | - $query_args = array(); |
|
| 1234 | - } |
|
| 1235 | - $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - |
|
| 1239 | - /** |
|
| 1240 | - * @param int $TKT_ID |
|
| 1241 | - * @return bool|int |
|
| 1242 | - * @throws EE_Error |
|
| 1243 | - */ |
|
| 1244 | - protected function _delete_the_ticket($TKT_ID) |
|
| 1245 | - { |
|
| 1246 | - $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
| 1247 | - $tkt->_remove_relations('Datetime'); |
|
| 1248 | - //delete all related prices first |
|
| 1249 | - $tkt->delete_related_permanently('Price'); |
|
| 1250 | - return $tkt->delete_permanently(); |
|
| 1251 | - } |
|
| 17 | + /** |
|
| 18 | + * Extend_Events_Admin_Page constructor. |
|
| 19 | + * |
|
| 20 | + * @param bool $routing |
|
| 21 | + */ |
|
| 22 | + public function __construct($routing = true) |
|
| 23 | + { |
|
| 24 | + parent::__construct($routing); |
|
| 25 | + if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 26 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
| 27 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
| 28 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Sets routes. |
|
| 35 | + */ |
|
| 36 | + protected function _extend_page_config() |
|
| 37 | + { |
|
| 38 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
| 39 | + //is there a evt_id in the request? |
|
| 40 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 41 | + ? $this->_req_data['EVT_ID'] |
|
| 42 | + : 0; |
|
| 43 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 44 | + //tkt_id? |
|
| 45 | + $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
| 46 | + ? $this->_req_data['TKT_ID'] |
|
| 47 | + : 0; |
|
| 48 | + $new_page_routes = array( |
|
| 49 | + 'duplicate_event' => array( |
|
| 50 | + 'func' => '_duplicate_event', |
|
| 51 | + 'capability' => 'ee_edit_event', |
|
| 52 | + 'obj_id' => $evt_id, |
|
| 53 | + 'noheader' => true, |
|
| 54 | + ), |
|
| 55 | + 'ticket_list_table' => array( |
|
| 56 | + 'func' => '_tickets_overview_list_table', |
|
| 57 | + 'capability' => 'ee_read_default_tickets', |
|
| 58 | + ), |
|
| 59 | + 'trash_ticket' => array( |
|
| 60 | + 'func' => '_trash_or_restore_ticket', |
|
| 61 | + 'capability' => 'ee_delete_default_ticket', |
|
| 62 | + 'obj_id' => $tkt_id, |
|
| 63 | + 'noheader' => true, |
|
| 64 | + 'args' => array('trash' => true), |
|
| 65 | + ), |
|
| 66 | + 'trash_tickets' => array( |
|
| 67 | + 'func' => '_trash_or_restore_ticket', |
|
| 68 | + 'capability' => 'ee_delete_default_tickets', |
|
| 69 | + 'noheader' => true, |
|
| 70 | + 'args' => array('trash' => true), |
|
| 71 | + ), |
|
| 72 | + 'restore_ticket' => array( |
|
| 73 | + 'func' => '_trash_or_restore_ticket', |
|
| 74 | + 'capability' => 'ee_delete_default_ticket', |
|
| 75 | + 'obj_id' => $tkt_id, |
|
| 76 | + 'noheader' => true, |
|
| 77 | + ), |
|
| 78 | + 'restore_tickets' => array( |
|
| 79 | + 'func' => '_trash_or_restore_ticket', |
|
| 80 | + 'capability' => 'ee_delete_default_tickets', |
|
| 81 | + 'noheader' => true, |
|
| 82 | + ), |
|
| 83 | + 'delete_ticket' => array( |
|
| 84 | + 'func' => '_delete_ticket', |
|
| 85 | + 'capability' => 'ee_delete_default_ticket', |
|
| 86 | + 'obj_id' => $tkt_id, |
|
| 87 | + 'noheader' => true, |
|
| 88 | + ), |
|
| 89 | + 'delete_tickets' => array( |
|
| 90 | + 'func' => '_delete_ticket', |
|
| 91 | + 'capability' => 'ee_delete_default_tickets', |
|
| 92 | + 'noheader' => true, |
|
| 93 | + ), |
|
| 94 | + 'import_page' => array( |
|
| 95 | + 'func' => '_import_page', |
|
| 96 | + 'capability' => 'import', |
|
| 97 | + ), |
|
| 98 | + 'import' => array( |
|
| 99 | + 'func' => '_import_events', |
|
| 100 | + 'capability' => 'import', |
|
| 101 | + 'noheader' => true, |
|
| 102 | + ), |
|
| 103 | + 'import_events' => array( |
|
| 104 | + 'func' => '_import_events', |
|
| 105 | + 'capability' => 'import', |
|
| 106 | + 'noheader' => true, |
|
| 107 | + ), |
|
| 108 | + 'export_events' => array( |
|
| 109 | + 'func' => '_events_export', |
|
| 110 | + 'capability' => 'export', |
|
| 111 | + 'noheader' => true, |
|
| 112 | + ), |
|
| 113 | + 'export_categories' => array( |
|
| 114 | + 'func' => '_categories_export', |
|
| 115 | + 'capability' => 'export', |
|
| 116 | + 'noheader' => true, |
|
| 117 | + ), |
|
| 118 | + 'sample_export_file' => array( |
|
| 119 | + 'func' => '_sample_export_file', |
|
| 120 | + 'capability' => 'export', |
|
| 121 | + 'noheader' => true, |
|
| 122 | + ), |
|
| 123 | + 'update_template_settings' => array( |
|
| 124 | + 'func' => '_update_template_settings', |
|
| 125 | + 'capability' => 'manage_options', |
|
| 126 | + 'noheader' => true, |
|
| 127 | + ), |
|
| 128 | + ); |
|
| 129 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 130 | + //partial route/config override |
|
| 131 | + $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
| 132 | + $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 133 | + $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 134 | + $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 135 | + $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 136 | + $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
| 137 | + //add tickets tab but only if there are more than one default ticket! |
|
| 138 | + $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 139 | + array(array('TKT_is_default' => 1)), |
|
| 140 | + 'TKT_ID', |
|
| 141 | + true |
|
| 142 | + ); |
|
| 143 | + if ($tkt_count > 1) { |
|
| 144 | + $new_page_config = array( |
|
| 145 | + 'ticket_list_table' => array( |
|
| 146 | + 'nav' => array( |
|
| 147 | + 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
| 148 | + 'order' => 60, |
|
| 149 | + ), |
|
| 150 | + 'list_table' => 'Tickets_List_Table', |
|
| 151 | + 'require_nonce' => false, |
|
| 152 | + ), |
|
| 153 | + ); |
|
| 154 | + } |
|
| 155 | + //template settings |
|
| 156 | + $new_page_config['template_settings'] = array( |
|
| 157 | + 'nav' => array( |
|
| 158 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 159 | + 'order' => 30, |
|
| 160 | + ), |
|
| 161 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 162 | + 'help_tabs' => array( |
|
| 163 | + 'general_settings_templates_help_tab' => array( |
|
| 164 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 165 | + 'filename' => 'general_settings_templates', |
|
| 166 | + ), |
|
| 167 | + ), |
|
| 168 | + 'help_tour' => array('Templates_Help_Tour'), |
|
| 169 | + 'require_nonce' => false, |
|
| 170 | + ); |
|
| 171 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 172 | + //add filters and actions |
|
| 173 | + //modifying _views |
|
| 174 | + add_filter( |
|
| 175 | + 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
| 176 | + array($this, 'add_additional_datetime_button'), |
|
| 177 | + 10, |
|
| 178 | + 2 |
|
| 179 | + ); |
|
| 180 | + add_filter( |
|
| 181 | + 'FHEE_event_datetime_metabox_clone_button_template', |
|
| 182 | + array($this, 'add_datetime_clone_button'), |
|
| 183 | + 10, |
|
| 184 | + 2 |
|
| 185 | + ); |
|
| 186 | + add_filter( |
|
| 187 | + 'FHEE_event_datetime_metabox_timezones_template', |
|
| 188 | + array($this, 'datetime_timezones_template'), |
|
| 189 | + 10, |
|
| 190 | + 2 |
|
| 191 | + ); |
|
| 192 | + //filters for event list table |
|
| 193 | + add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2); |
|
| 194 | + add_filter( |
|
| 195 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 196 | + array($this, 'extra_list_table_actions'), |
|
| 197 | + 10, |
|
| 198 | + 2 |
|
| 199 | + ); |
|
| 200 | + //legend item |
|
| 201 | + add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items')); |
|
| 202 | + add_action('admin_init', array($this, 'admin_init')); |
|
| 203 | + //heartbeat stuff |
|
| 204 | + add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * admin_init |
|
| 210 | + */ |
|
| 211 | + public function admin_init() |
|
| 212 | + { |
|
| 213 | + EE_Registry::$i18n_js_strings = array_merge( |
|
| 214 | + EE_Registry::$i18n_js_strings, |
|
| 215 | + array( |
|
| 216 | + 'image_confirm' => esc_html__( |
|
| 217 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 218 | + 'event_espresso' |
|
| 219 | + ), |
|
| 220 | + 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
| 221 | + 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
| 222 | + 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
| 223 | + 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
| 224 | + 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
| 225 | + ) |
|
| 226 | + ); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle |
|
| 232 | + * accordingly. |
|
| 233 | + * |
|
| 234 | + * @param array $response The existing heartbeat response array. |
|
| 235 | + * @param array $data The incoming data package. |
|
| 236 | + * @return array possibly appended response. |
|
| 237 | + */ |
|
| 238 | + public function heartbeat_response($response, $data) |
|
| 239 | + { |
|
| 240 | + /** |
|
| 241 | + * check whether count of tickets is approaching the potential |
|
| 242 | + * limits for the server. |
|
| 243 | + */ |
|
| 244 | + if (! empty($data['input_count'])) { |
|
| 245 | + $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check( |
|
| 246 | + $data['input_count'] |
|
| 247 | + ); |
|
| 248 | + } |
|
| 249 | + return $response; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Add per page screen options to the default ticket list table view. |
|
| 255 | + */ |
|
| 256 | + protected function _add_screen_options_ticket_list_table() |
|
| 257 | + { |
|
| 258 | + $this->_per_page_screen_option(); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @param string $return |
|
| 264 | + * @param int $id |
|
| 265 | + * @param string $new_title |
|
| 266 | + * @param string $new_slug |
|
| 267 | + * @return string |
|
| 268 | + */ |
|
| 269 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 270 | + { |
|
| 271 | + $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
| 272 | + //make sure this is only when editing |
|
| 273 | + if (! empty($id)) { |
|
| 274 | + $href = EE_Admin_Page::add_query_args_and_nonce( |
|
| 275 | + array('action' => 'duplicate_event', 'EVT_ID' => $id), |
|
| 276 | + $this->_admin_base_url |
|
| 277 | + ); |
|
| 278 | + $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
| 279 | + $return .= '<a href="' |
|
| 280 | + . $href |
|
| 281 | + . '" title="' |
|
| 282 | + . $title |
|
| 283 | + . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
| 284 | + . $title |
|
| 285 | + . '</button>'; |
|
| 286 | + } |
|
| 287 | + return $return; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Set the list table views for the default ticket list table view. |
|
| 293 | + */ |
|
| 294 | + public function _set_list_table_views_ticket_list_table() |
|
| 295 | + { |
|
| 296 | + $this->_views = array( |
|
| 297 | + 'all' => array( |
|
| 298 | + 'slug' => 'all', |
|
| 299 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 300 | + 'count' => 0, |
|
| 301 | + 'bulk_action' => array( |
|
| 302 | + 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 303 | + ), |
|
| 304 | + ), |
|
| 305 | + 'trashed' => array( |
|
| 306 | + 'slug' => 'trashed', |
|
| 307 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 308 | + 'count' => 0, |
|
| 309 | + 'bulk_action' => array( |
|
| 310 | + 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 311 | + 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 312 | + ), |
|
| 313 | + ), |
|
| 314 | + ); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Enqueue scripts and styles for the event editor. |
|
| 320 | + */ |
|
| 321 | + public function load_scripts_styles_edit() |
|
| 322 | + { |
|
| 323 | + wp_register_script( |
|
| 324 | + 'ee-event-editor-heartbeat', |
|
| 325 | + EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
| 326 | + array('ee_admin_js', 'heartbeat'), |
|
| 327 | + EVENT_ESPRESSO_VERSION, |
|
| 328 | + true |
|
| 329 | + ); |
|
| 330 | + wp_enqueue_script('ee-accounting'); |
|
| 331 | + //styles |
|
| 332 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 333 | + wp_enqueue_script('event_editor_js'); |
|
| 334 | + wp_enqueue_script('ee-event-editor-heartbeat'); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Returns template for the additional datetime. |
|
| 340 | + * @param $template |
|
| 341 | + * @param $template_args |
|
| 342 | + * @return mixed |
|
| 343 | + * @throws DomainException |
|
| 344 | + */ |
|
| 345 | + public function add_additional_datetime_button($template, $template_args) |
|
| 346 | + { |
|
| 347 | + return EEH_Template::display_template( |
|
| 348 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
| 349 | + $template_args, |
|
| 350 | + true |
|
| 351 | + ); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Returns the template for cloning a datetime. |
|
| 357 | + * @param $template |
|
| 358 | + * @param $template_args |
|
| 359 | + * @return mixed |
|
| 360 | + * @throws DomainException |
|
| 361 | + */ |
|
| 362 | + public function add_datetime_clone_button($template, $template_args) |
|
| 363 | + { |
|
| 364 | + return EEH_Template::display_template( |
|
| 365 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
| 366 | + $template_args, |
|
| 367 | + true |
|
| 368 | + ); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Returns the template for datetime timezones. |
|
| 374 | + * @param $template |
|
| 375 | + * @param $template_args |
|
| 376 | + * @return mixed |
|
| 377 | + * @throws DomainException |
|
| 378 | + */ |
|
| 379 | + public function datetime_timezones_template($template, $template_args) |
|
| 380 | + { |
|
| 381 | + return EEH_Template::display_template( |
|
| 382 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
| 383 | + $template_args, |
|
| 384 | + true |
|
| 385 | + ); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Sets the views for the default list table view. |
|
| 391 | + */ |
|
| 392 | + protected function _set_list_table_views_default() |
|
| 393 | + { |
|
| 394 | + parent::_set_list_table_views_default(); |
|
| 395 | + $new_views = array( |
|
| 396 | + 'today' => array( |
|
| 397 | + 'slug' => 'today', |
|
| 398 | + 'label' => esc_html__('Today', 'event_espresso'), |
|
| 399 | + 'count' => $this->total_events_today(), |
|
| 400 | + 'bulk_action' => array( |
|
| 401 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 402 | + ), |
|
| 403 | + ), |
|
| 404 | + 'month' => array( |
|
| 405 | + 'slug' => 'month', |
|
| 406 | + 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 407 | + 'count' => $this->total_events_this_month(), |
|
| 408 | + 'bulk_action' => array( |
|
| 409 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 410 | + ), |
|
| 411 | + ), |
|
| 412 | + ); |
|
| 413 | + $this->_views = array_merge($this->_views, $new_views); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * Returns the extra action links for the default list table view. |
|
| 419 | + * @param array $action_links |
|
| 420 | + * @param \EE_Event $event |
|
| 421 | + * @return array |
|
| 422 | + * @throws EE_Error |
|
| 423 | + */ |
|
| 424 | + public function extra_list_table_actions(array $action_links, \EE_Event $event) |
|
| 425 | + { |
|
| 426 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 427 | + 'ee_read_registrations', |
|
| 428 | + 'espresso_registrations_reports', |
|
| 429 | + $event->ID() |
|
| 430 | + ) |
|
| 431 | + ) { |
|
| 432 | + $reports_query_args = array( |
|
| 433 | + 'action' => 'reports', |
|
| 434 | + 'EVT_ID' => $event->ID(), |
|
| 435 | + ); |
|
| 436 | + $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
| 437 | + $action_links[] = '<a href="' |
|
| 438 | + . $reports_link |
|
| 439 | + . '" title="' |
|
| 440 | + . esc_attr__('View Report', 'event_espresso') |
|
| 441 | + . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
| 442 | + . "\n\t"; |
|
| 443 | + } |
|
| 444 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 445 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 446 | + $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
| 447 | + 'see_notifications_for', |
|
| 448 | + null, |
|
| 449 | + array('EVT_ID' => $event->ID()) |
|
| 450 | + ); |
|
| 451 | + } |
|
| 452 | + return $action_links; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * @param $items |
|
| 458 | + * @return mixed |
|
| 459 | + */ |
|
| 460 | + public function additional_legend_items($items) |
|
| 461 | + { |
|
| 462 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 463 | + 'ee_read_registrations', |
|
| 464 | + 'espresso_registrations_reports' |
|
| 465 | + ) |
|
| 466 | + ) { |
|
| 467 | + $items['reports'] = array( |
|
| 468 | + 'class' => 'dashicons dashicons-chart-bar', |
|
| 469 | + 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
| 470 | + ); |
|
| 471 | + } |
|
| 472 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 473 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 474 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 475 | + $items['view_related_messages'] = array( |
|
| 476 | + 'class' => $related_for_icon['css_class'], |
|
| 477 | + 'desc' => $related_for_icon['label'], |
|
| 478 | + ); |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + return $items; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * This is the callback method for the duplicate event route |
|
| 487 | + * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
| 488 | + * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
| 489 | + * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
| 490 | + * After duplication the redirect is to the new event edit page. |
|
| 491 | + * |
|
| 492 | + * @return void |
|
| 493 | + * @access protected |
|
| 494 | + * @throws EE_Error If EE_Event is not available with given ID |
|
| 495 | + */ |
|
| 496 | + protected function _duplicate_event() |
|
| 497 | + { |
|
| 498 | + // first make sure the ID for the event is in the request. |
|
| 499 | + // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
| 500 | + if (! isset($this->_req_data['EVT_ID'])) { |
|
| 501 | + EE_Error::add_error( |
|
| 502 | + esc_html__( |
|
| 503 | + 'In order to duplicate an event an Event ID is required. None was given.', |
|
| 504 | + 'event_espresso' |
|
| 505 | + ), |
|
| 506 | + __FILE__, |
|
| 507 | + __FUNCTION__, |
|
| 508 | + __LINE__ |
|
| 509 | + ); |
|
| 510 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 511 | + return; |
|
| 512 | + } |
|
| 513 | + //k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
| 514 | + $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
| 515 | + if (! $orig_event instanceof EE_Event) { |
|
| 516 | + throw new EE_Error( |
|
| 517 | + sprintf( |
|
| 518 | + esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
| 519 | + $this->_req_data['EVT_ID'] |
|
| 520 | + ) |
|
| 521 | + ); |
|
| 522 | + } |
|
| 523 | + //k now let's clone the $orig_event before getting relations |
|
| 524 | + $new_event = clone $orig_event; |
|
| 525 | + //original datetimes |
|
| 526 | + $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
| 527 | + //other original relations |
|
| 528 | + $orig_ven = $orig_event->get_many_related('Venue'); |
|
| 529 | + //reset the ID and modify other details to make it clear this is a dupe |
|
| 530 | + $new_event->set('EVT_ID', 0); |
|
| 531 | + $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 532 | + $new_event->set('EVT_name', $new_name); |
|
| 533 | + $new_event->set( |
|
| 534 | + 'EVT_slug', |
|
| 535 | + wp_unique_post_slug( |
|
| 536 | + sanitize_title($orig_event->name()), |
|
| 537 | + 0, |
|
| 538 | + 'publish', |
|
| 539 | + 'espresso_events', |
|
| 540 | + 0 |
|
| 541 | + ) |
|
| 542 | + ); |
|
| 543 | + $new_event->set('status', 'draft'); |
|
| 544 | + //duplicate discussion settings |
|
| 545 | + $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
| 546 | + $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
| 547 | + //save the new event |
|
| 548 | + $new_event->save(); |
|
| 549 | + //venues |
|
| 550 | + foreach ($orig_ven as $ven) { |
|
| 551 | + $new_event->_add_relation_to($ven, 'Venue'); |
|
| 552 | + } |
|
| 553 | + $new_event->save(); |
|
| 554 | + //now we need to get the question group relations and handle that |
|
| 555 | + //first primary question groups |
|
| 556 | + $orig_primary_qgs = $orig_event->get_many_related( |
|
| 557 | + 'Question_Group', |
|
| 558 | + array(array('Event_Question_Group.EQG_primary' => 1)) |
|
| 559 | + ); |
|
| 560 | + if (! empty($orig_primary_qgs)) { |
|
| 561 | + foreach ($orig_primary_qgs as $id => $obj) { |
|
| 562 | + if ($obj instanceof EE_Question_Group) { |
|
| 563 | + $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1)); |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + //next additional attendee question groups |
|
| 568 | + $orig_additional_qgs = $orig_event->get_many_related( |
|
| 569 | + 'Question_Group', |
|
| 570 | + array(array('Event_Question_Group.EQG_primary' => 0)) |
|
| 571 | + ); |
|
| 572 | + if (! empty($orig_additional_qgs)) { |
|
| 573 | + foreach ($orig_additional_qgs as $id => $obj) { |
|
| 574 | + if ($obj instanceof EE_Question_Group) { |
|
| 575 | + $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0)); |
|
| 576 | + } |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + //now save |
|
| 580 | + $new_event->save(); |
|
| 581 | + //k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
| 582 | + $cloned_tickets = array(); |
|
| 583 | + foreach ($orig_datetimes as $orig_dtt) { |
|
| 584 | + if (! $orig_dtt instanceof EE_Datetime) { |
|
| 585 | + continue; |
|
| 586 | + } |
|
| 587 | + $new_dtt = clone $orig_dtt; |
|
| 588 | + $orig_tkts = $orig_dtt->tickets(); |
|
| 589 | + //save new dtt then add to event |
|
| 590 | + $new_dtt->set('DTT_ID', 0); |
|
| 591 | + $new_dtt->set('DTT_sold', 0); |
|
| 592 | + $new_dtt->set_reserved(0); |
|
| 593 | + $new_dtt->save(); |
|
| 594 | + $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
| 595 | + $new_event->save(); |
|
| 596 | + //now let's get the ticket relations setup. |
|
| 597 | + foreach ((array)$orig_tkts as $orig_tkt) { |
|
| 598 | + //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
| 599 | + if (! $orig_tkt instanceof EE_Ticket) { |
|
| 600 | + continue; |
|
| 601 | + } |
|
| 602 | + //is this ticket archived? If it is then let's skip |
|
| 603 | + if ($orig_tkt->get('TKT_deleted')) { |
|
| 604 | + continue; |
|
| 605 | + } |
|
| 606 | + // does this original ticket already exist in the clone_tickets cache? |
|
| 607 | + // If so we'll just use the new ticket from it. |
|
| 608 | + if (isset($cloned_tickets[$orig_tkt->ID()])) { |
|
| 609 | + $new_tkt = $cloned_tickets[$orig_tkt->ID()]; |
|
| 610 | + } else { |
|
| 611 | + $new_tkt = clone $orig_tkt; |
|
| 612 | + //get relations on the $orig_tkt that we need to setup. |
|
| 613 | + $orig_prices = $orig_tkt->prices(); |
|
| 614 | + $new_tkt->set('TKT_ID', 0); |
|
| 615 | + $new_tkt->set('TKT_sold', 0); |
|
| 616 | + $new_tkt->set('TKT_reserved', 0); |
|
| 617 | + $new_tkt->save(); //make sure new ticket has ID. |
|
| 618 | + //price relations on new ticket need to be setup. |
|
| 619 | + foreach ($orig_prices as $orig_price) { |
|
| 620 | + $new_price = clone $orig_price; |
|
| 621 | + $new_price->set('PRC_ID', 0); |
|
| 622 | + $new_price->save(); |
|
| 623 | + $new_tkt->_add_relation_to($new_price, 'Price'); |
|
| 624 | + $new_tkt->save(); |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + // k now we can add the new ticket as a relation to the new datetime |
|
| 628 | + // and make sure its added to our cached $cloned_tickets array |
|
| 629 | + // for use with later datetimes that have the same ticket. |
|
| 630 | + $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
| 631 | + $new_dtt->save(); |
|
| 632 | + $cloned_tickets[$orig_tkt->ID()] = $new_tkt; |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + //clone taxonomy information |
|
| 636 | + $taxonomies_to_clone_with = apply_filters( |
|
| 637 | + 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
| 638 | + array('espresso_event_categories', 'espresso_event_type', 'post_tag') |
|
| 639 | + ); |
|
| 640 | + //get terms for original event (notice) |
|
| 641 | + $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
| 642 | + //loop through terms and add them to new event. |
|
| 643 | + foreach ($orig_terms as $term) { |
|
| 644 | + wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
| 645 | + } |
|
| 646 | + do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
| 647 | + //now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
| 648 | + if ($new_event->ID()) { |
|
| 649 | + $redirect_args = array( |
|
| 650 | + 'post' => $new_event->ID(), |
|
| 651 | + 'action' => 'edit', |
|
| 652 | + ); |
|
| 653 | + EE_Error::add_success( |
|
| 654 | + esc_html__( |
|
| 655 | + 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
| 656 | + 'event_espresso' |
|
| 657 | + ) |
|
| 658 | + ); |
|
| 659 | + } else { |
|
| 660 | + $redirect_args = array( |
|
| 661 | + 'action' => 'default', |
|
| 662 | + ); |
|
| 663 | + EE_Error::add_error( |
|
| 664 | + esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
| 665 | + __FILE__, |
|
| 666 | + __FUNCTION__, |
|
| 667 | + __LINE__ |
|
| 668 | + ); |
|
| 669 | + } |
|
| 670 | + $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * Generates output for the import page. |
|
| 676 | + * @throws DomainException |
|
| 677 | + */ |
|
| 678 | + protected function _import_page() |
|
| 679 | + { |
|
| 680 | + $title = esc_html__('Import', 'event_espresso'); |
|
| 681 | + $intro = esc_html__( |
|
| 682 | + 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
| 683 | + 'event_espresso' |
|
| 684 | + ); |
|
| 685 | + $form_url = EVENTS_ADMIN_URL; |
|
| 686 | + $action = 'import_events'; |
|
| 687 | + $type = 'csv'; |
|
| 688 | + $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
| 689 | + $title, $intro, $form_url, $action, $type |
|
| 690 | + ); |
|
| 691 | + $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 692 | + array('action' => 'sample_export_file'), |
|
| 693 | + $this->_admin_base_url |
|
| 694 | + ); |
|
| 695 | + $content = EEH_Template::display_template( |
|
| 696 | + EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
| 697 | + $this->_template_args, |
|
| 698 | + true |
|
| 699 | + ); |
|
| 700 | + $this->_template_args['admin_page_content'] = $content; |
|
| 701 | + $this->display_admin_page_with_sidebar(); |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * _import_events |
|
| 707 | + * This handles displaying the screen and running imports for importing events. |
|
| 708 | + * |
|
| 709 | + * @return void |
|
| 710 | + */ |
|
| 711 | + protected function _import_events() |
|
| 712 | + { |
|
| 713 | + require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
| 714 | + $success = EE_Import::instance()->import(); |
|
| 715 | + $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + |
|
| 719 | + /** |
|
| 720 | + * _events_export |
|
| 721 | + * Will export all (or just the given event) to a Excel compatible file. |
|
| 722 | + * |
|
| 723 | + * @access protected |
|
| 724 | + * @return void |
|
| 725 | + */ |
|
| 726 | + protected function _events_export() |
|
| 727 | + { |
|
| 728 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 729 | + $event_ids = $this->_req_data['EVT_ID']; |
|
| 730 | + } elseif (isset($this->_req_data['EVT_IDs'])) { |
|
| 731 | + $event_ids = $this->_req_data['EVT_IDs']; |
|
| 732 | + } else { |
|
| 733 | + $event_ids = null; |
|
| 734 | + } |
|
| 735 | + //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 736 | + $new_request_args = array( |
|
| 737 | + 'export' => 'report', |
|
| 738 | + 'action' => 'all_event_data', |
|
| 739 | + 'EVT_ID' => $event_ids, |
|
| 740 | + ); |
|
| 741 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 742 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 743 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 744 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 745 | + $EE_Export->export(); |
|
| 746 | + } |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * handle category exports() |
|
| 752 | + * |
|
| 753 | + * @return void |
|
| 754 | + */ |
|
| 755 | + protected function _categories_export() |
|
| 756 | + { |
|
| 757 | + //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 758 | + $new_request_args = array( |
|
| 759 | + 'export' => 'report', |
|
| 760 | + 'action' => 'categories', |
|
| 761 | + 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
| 762 | + ); |
|
| 763 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 764 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 765 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 766 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 767 | + $EE_Export->export(); |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * Creates a sample CSV file for importing |
|
| 774 | + */ |
|
| 775 | + protected function _sample_export_file() |
|
| 776 | + { |
|
| 777 | + // require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 778 | + EE_Export::instance()->export_sample(); |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + |
|
| 782 | + /************* Template Settings *************/ |
|
| 783 | + /** |
|
| 784 | + * Generates template settings page output |
|
| 785 | + * @throws DomainException |
|
| 786 | + * @throws EE_Error |
|
| 787 | + */ |
|
| 788 | + protected function _template_settings() |
|
| 789 | + { |
|
| 790 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 791 | + /** |
|
| 792 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 793 | + * from General_Settings_Admin_Page to here. |
|
| 794 | + */ |
|
| 795 | + $this->_template_args = apply_filters( |
|
| 796 | + 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
| 797 | + $this->_template_args |
|
| 798 | + ); |
|
| 799 | + $this->_set_add_edit_form_tags('update_template_settings'); |
|
| 800 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 801 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 802 | + EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
| 803 | + $this->_template_args, |
|
| 804 | + true |
|
| 805 | + ); |
|
| 806 | + $this->display_admin_page_with_sidebar(); |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + |
|
| 810 | + /** |
|
| 811 | + * Handler for updating template settings. |
|
| 812 | + */ |
|
| 813 | + protected function _update_template_settings() |
|
| 814 | + { |
|
| 815 | + /** |
|
| 816 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 817 | + * from General_Settings_Admin_Page to here. |
|
| 818 | + */ |
|
| 819 | + EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
| 820 | + 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
| 821 | + EE_Registry::instance()->CFG->template_settings, |
|
| 822 | + $this->_req_data |
|
| 823 | + ); |
|
| 824 | + //update custom post type slugs and detect if we need to flush rewrite rules |
|
| 825 | + $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
| 826 | + EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
| 827 | + ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
| 828 | + : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']); |
|
| 829 | + $what = 'Template Settings'; |
|
| 830 | + $success = $this->_update_espresso_configuration( |
|
| 831 | + $what, |
|
| 832 | + EE_Registry::instance()->CFG->template_settings, |
|
| 833 | + __FILE__, |
|
| 834 | + __FUNCTION__, |
|
| 835 | + __LINE__ |
|
| 836 | + ); |
|
| 837 | + if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
| 838 | + update_option('ee_flush_rewrite_rules', true); |
|
| 839 | + } |
|
| 840 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings')); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + |
|
| 844 | + /** |
|
| 845 | + * _premium_event_editor_meta_boxes |
|
| 846 | + * add all metaboxes related to the event_editor |
|
| 847 | + * |
|
| 848 | + * @access protected |
|
| 849 | + * @return void |
|
| 850 | + * @throws EE_Error |
|
| 851 | + */ |
|
| 852 | + protected function _premium_event_editor_meta_boxes() |
|
| 853 | + { |
|
| 854 | + $this->verify_cpt_object(); |
|
| 855 | + add_meta_box( |
|
| 856 | + 'espresso_event_editor_event_options', |
|
| 857 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 858 | + array($this, 'registration_options_meta_box'), |
|
| 859 | + $this->page_slug, |
|
| 860 | + 'side', |
|
| 861 | + 'core' |
|
| 862 | + ); |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + |
|
| 866 | + /** |
|
| 867 | + * override caf metabox |
|
| 868 | + * |
|
| 869 | + * @return void |
|
| 870 | + * @throws DomainException |
|
| 871 | + */ |
|
| 872 | + public function registration_options_meta_box() |
|
| 873 | + { |
|
| 874 | + $yes_no_values = array( |
|
| 875 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 876 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 877 | + ); |
|
| 878 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 879 | + array( |
|
| 880 | + EEM_Registration::status_id_cancelled, |
|
| 881 | + EEM_Registration::status_id_declined, |
|
| 882 | + EEM_Registration::status_id_incomplete, |
|
| 883 | + EEM_Registration::status_id_wait_list, |
|
| 884 | + ), |
|
| 885 | + true |
|
| 886 | + ); |
|
| 887 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 888 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 889 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 890 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 891 | + 'default_reg_status', |
|
| 892 | + $default_reg_status_values, |
|
| 893 | + $this->_cpt_model_obj->default_registration_status() |
|
| 894 | + ); |
|
| 895 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 896 | + 'display_desc', |
|
| 897 | + $yes_no_values, |
|
| 898 | + $this->_cpt_model_obj->display_description() |
|
| 899 | + ); |
|
| 900 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 901 | + 'display_ticket_selector', |
|
| 902 | + $yes_no_values, |
|
| 903 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 904 | + '', |
|
| 905 | + '', |
|
| 906 | + false |
|
| 907 | + ); |
|
| 908 | + $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 909 | + 'EVT_default_registration_status', |
|
| 910 | + $default_reg_status_values, |
|
| 911 | + $this->_cpt_model_obj->default_registration_status() |
|
| 912 | + ); |
|
| 913 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 914 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 915 | + '', |
|
| 916 | + $template_args, |
|
| 917 | + $yes_no_values, |
|
| 918 | + $default_reg_status_values |
|
| 919 | + ); |
|
| 920 | + EEH_Template::display_template( |
|
| 921 | + EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 922 | + $template_args |
|
| 923 | + ); |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * wp_list_table_mods for caf |
|
| 930 | + * ============================ |
|
| 931 | + */ |
|
| 932 | + /** |
|
| 933 | + * hook into list table filters and provide filters for caffeinated list table |
|
| 934 | + * |
|
| 935 | + * @param array $old_filters any existing filters present |
|
| 936 | + * @param array $list_table_obj the list table object |
|
| 937 | + * @return array new filters |
|
| 938 | + */ |
|
| 939 | + public function list_table_filters($old_filters, $list_table_obj) |
|
| 940 | + { |
|
| 941 | + $filters = array(); |
|
| 942 | + //first month/year filters |
|
| 943 | + $filters[] = $this->espresso_event_months_dropdown(); |
|
| 944 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 945 | + //active status dropdown |
|
| 946 | + if ($status !== 'draft') { |
|
| 947 | + $filters[] = $this->active_status_dropdown( |
|
| 948 | + isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
| 949 | + ); |
|
| 950 | + } |
|
| 951 | + //category filter |
|
| 952 | + $filters[] = $this->category_dropdown(); |
|
| 953 | + return array_merge($old_filters, $filters); |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * espresso_event_months_dropdown |
|
| 959 | + * |
|
| 960 | + * @access public |
|
| 961 | + * @return string dropdown listing month/year selections for events. |
|
| 962 | + */ |
|
| 963 | + public function espresso_event_months_dropdown() |
|
| 964 | + { |
|
| 965 | + // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
| 966 | + // Note we need to include any other filters that are set! |
|
| 967 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 968 | + //categories? |
|
| 969 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 970 | + ? $this->_req_data['EVT_CAT'] |
|
| 971 | + : null; |
|
| 972 | + //active status? |
|
| 973 | + $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
| 974 | + $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
| 975 | + return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + |
|
| 979 | + /** |
|
| 980 | + * returns a list of "active" statuses on the event |
|
| 981 | + * |
|
| 982 | + * @param string $current_value whatever the current active status is |
|
| 983 | + * @return string |
|
| 984 | + */ |
|
| 985 | + public function active_status_dropdown($current_value = '') |
|
| 986 | + { |
|
| 987 | + $select_name = 'active_status'; |
|
| 988 | + $values = array( |
|
| 989 | + 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
| 990 | + 'active' => esc_html__('Active', 'event_espresso'), |
|
| 991 | + 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
| 992 | + 'expired' => esc_html__('Expired', 'event_espresso'), |
|
| 993 | + 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
| 994 | + ); |
|
| 995 | + $id = 'id="espresso-active-status-dropdown-filter"'; |
|
| 996 | + $class = 'wide'; |
|
| 997 | + return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class); |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + |
|
| 1001 | + /** |
|
| 1002 | + * output a dropdown of the categories for the category filter on the event admin list table |
|
| 1003 | + * |
|
| 1004 | + * @access public |
|
| 1005 | + * @return string html |
|
| 1006 | + */ |
|
| 1007 | + public function category_dropdown() |
|
| 1008 | + { |
|
| 1009 | + $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
| 1010 | + return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + |
|
| 1014 | + /** |
|
| 1015 | + * get total number of events today |
|
| 1016 | + * |
|
| 1017 | + * @access public |
|
| 1018 | + * @return int |
|
| 1019 | + * @throws EE_Error |
|
| 1020 | + */ |
|
| 1021 | + public function total_events_today() |
|
| 1022 | + { |
|
| 1023 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1024 | + 'DTT_EVT_start', |
|
| 1025 | + date('Y-m-d') . ' 00:00:00', |
|
| 1026 | + 'Y-m-d H:i:s', |
|
| 1027 | + 'UTC' |
|
| 1028 | + ); |
|
| 1029 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1030 | + 'DTT_EVT_start', |
|
| 1031 | + date('Y-m-d') . ' 23:59:59', |
|
| 1032 | + 'Y-m-d H:i:s', |
|
| 1033 | + 'UTC' |
|
| 1034 | + ); |
|
| 1035 | + $where = array( |
|
| 1036 | + 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
| 1037 | + ); |
|
| 1038 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 1039 | + return $count; |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + /** |
|
| 1044 | + * get total number of events this month |
|
| 1045 | + * |
|
| 1046 | + * @access public |
|
| 1047 | + * @return int |
|
| 1048 | + * @throws EE_Error |
|
| 1049 | + */ |
|
| 1050 | + public function total_events_this_month() |
|
| 1051 | + { |
|
| 1052 | + //Dates |
|
| 1053 | + $this_year_r = date('Y'); |
|
| 1054 | + $this_month_r = date('m'); |
|
| 1055 | + $days_this_month = date('t'); |
|
| 1056 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1057 | + 'DTT_EVT_start', |
|
| 1058 | + $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
| 1059 | + 'Y-m-d H:i:s', |
|
| 1060 | + 'UTC' |
|
| 1061 | + ); |
|
| 1062 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1063 | + 'DTT_EVT_start', |
|
| 1064 | + $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
| 1065 | + 'Y-m-d H:i:s', |
|
| 1066 | + 'UTC' |
|
| 1067 | + ); |
|
| 1068 | + $where = array( |
|
| 1069 | + 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
| 1070 | + ); |
|
| 1071 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 1072 | + return $count; |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + |
|
| 1076 | + /** DEFAULT TICKETS STUFF **/ |
|
| 1077 | + |
|
| 1078 | + /** |
|
| 1079 | + * Output default tickets list table view. |
|
| 1080 | + */ |
|
| 1081 | + public function _tickets_overview_list_table() |
|
| 1082 | + { |
|
| 1083 | + $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
| 1084 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + |
|
| 1088 | + /** |
|
| 1089 | + * @param int $per_page |
|
| 1090 | + * @param bool $count |
|
| 1091 | + * @param bool $trashed |
|
| 1092 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 1093 | + */ |
|
| 1094 | + public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
| 1095 | + { |
|
| 1096 | + $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
| 1097 | + $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
| 1098 | + switch ($orderby) { |
|
| 1099 | + case 'TKT_name': |
|
| 1100 | + $orderby = array('TKT_name' => $order); |
|
| 1101 | + break; |
|
| 1102 | + case 'TKT_price': |
|
| 1103 | + $orderby = array('TKT_price' => $order); |
|
| 1104 | + break; |
|
| 1105 | + case 'TKT_uses': |
|
| 1106 | + $orderby = array('TKT_uses' => $order); |
|
| 1107 | + break; |
|
| 1108 | + case 'TKT_min': |
|
| 1109 | + $orderby = array('TKT_min' => $order); |
|
| 1110 | + break; |
|
| 1111 | + case 'TKT_max': |
|
| 1112 | + $orderby = array('TKT_max' => $order); |
|
| 1113 | + break; |
|
| 1114 | + case 'TKT_qty': |
|
| 1115 | + $orderby = array('TKT_qty' => $order); |
|
| 1116 | + break; |
|
| 1117 | + } |
|
| 1118 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1119 | + ? $this->_req_data['paged'] |
|
| 1120 | + : 1; |
|
| 1121 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1122 | + ? $this->_req_data['perpage'] |
|
| 1123 | + : $per_page; |
|
| 1124 | + $_where = array( |
|
| 1125 | + 'TKT_is_default' => 1, |
|
| 1126 | + 'TKT_deleted' => $trashed, |
|
| 1127 | + ); |
|
| 1128 | + $offset = ($current_page - 1) * $per_page; |
|
| 1129 | + $limit = array($offset, $per_page); |
|
| 1130 | + if (isset($this->_req_data['s'])) { |
|
| 1131 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1132 | + $_where['OR'] = array( |
|
| 1133 | + 'TKT_name' => array('LIKE', $sstr), |
|
| 1134 | + 'TKT_description' => array('LIKE', $sstr), |
|
| 1135 | + ); |
|
| 1136 | + } |
|
| 1137 | + $query_params = array( |
|
| 1138 | + $_where, |
|
| 1139 | + 'order_by' => $orderby, |
|
| 1140 | + 'limit' => $limit, |
|
| 1141 | + 'group_by' => 'TKT_ID', |
|
| 1142 | + ); |
|
| 1143 | + if ($count) { |
|
| 1144 | + return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where)); |
|
| 1145 | + } else { |
|
| 1146 | + return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 1147 | + } |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + |
|
| 1151 | + /** |
|
| 1152 | + * @param bool $trash |
|
| 1153 | + * @throws EE_Error |
|
| 1154 | + */ |
|
| 1155 | + protected function _trash_or_restore_ticket($trash = false) |
|
| 1156 | + { |
|
| 1157 | + $success = 1; |
|
| 1158 | + $TKT = EEM_Ticket::instance(); |
|
| 1159 | + //checkboxes? |
|
| 1160 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1161 | + //if array has more than one element then success message should be plural |
|
| 1162 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1163 | + //cycle thru the boxes |
|
| 1164 | + while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1165 | + if ($trash) { |
|
| 1166 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1167 | + $success = 0; |
|
| 1168 | + } |
|
| 1169 | + } else { |
|
| 1170 | + if (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1171 | + $success = 0; |
|
| 1172 | + } |
|
| 1173 | + } |
|
| 1174 | + } |
|
| 1175 | + } else { |
|
| 1176 | + //grab single id and trash |
|
| 1177 | + $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1178 | + if ($trash) { |
|
| 1179 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1180 | + $success = 0; |
|
| 1181 | + } |
|
| 1182 | + } else { |
|
| 1183 | + if (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1184 | + $success = 0; |
|
| 1185 | + } |
|
| 1186 | + } |
|
| 1187 | + } |
|
| 1188 | + $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
| 1189 | + $query_args = array( |
|
| 1190 | + 'action' => 'ticket_list_table', |
|
| 1191 | + 'status' => $trash ? '' : 'trashed', |
|
| 1192 | + ); |
|
| 1193 | + $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + |
|
| 1197 | + /** |
|
| 1198 | + * Handles trashing default ticket. |
|
| 1199 | + */ |
|
| 1200 | + protected function _delete_ticket() |
|
| 1201 | + { |
|
| 1202 | + $success = 1; |
|
| 1203 | + //checkboxes? |
|
| 1204 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1205 | + //if array has more than one element then success message should be plural |
|
| 1206 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1207 | + //cycle thru the boxes |
|
| 1208 | + while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1209 | + //delete |
|
| 1210 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1211 | + $success = 0; |
|
| 1212 | + } |
|
| 1213 | + } |
|
| 1214 | + } else { |
|
| 1215 | + //grab single id and trash |
|
| 1216 | + $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1217 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1218 | + $success = 0; |
|
| 1219 | + } |
|
| 1220 | + } |
|
| 1221 | + $action_desc = 'deleted'; |
|
| 1222 | + $query_args = array( |
|
| 1223 | + 'action' => 'ticket_list_table', |
|
| 1224 | + 'status' => 'trashed', |
|
| 1225 | + ); |
|
| 1226 | + //fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
| 1227 | + if (EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 1228 | + array(array('TKT_is_default' => 1)), |
|
| 1229 | + 'TKT_ID', |
|
| 1230 | + true |
|
| 1231 | + ) |
|
| 1232 | + ) { |
|
| 1233 | + $query_args = array(); |
|
| 1234 | + } |
|
| 1235 | + $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + |
|
| 1239 | + /** |
|
| 1240 | + * @param int $TKT_ID |
|
| 1241 | + * @return bool|int |
|
| 1242 | + * @throws EE_Error |
|
| 1243 | + */ |
|
| 1244 | + protected function _delete_the_ticket($TKT_ID) |
|
| 1245 | + { |
|
| 1246 | + $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
| 1247 | + $tkt->_remove_relations('Datetime'); |
|
| 1248 | + //delete all related prices first |
|
| 1249 | + $tkt->delete_related_permanently('Price'); |
|
| 1250 | + return $tkt->delete_permanently(); |
|
| 1251 | + } |
|
| 1252 | 1252 | } |
@@ -22,10 +22,10 @@ discard block |
||
| 22 | 22 | public function __construct($routing = true) |
| 23 | 23 | { |
| 24 | 24 | parent::__construct($routing); |
| 25 | - if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 26 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
| 27 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
| 28 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
| 25 | + if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 26 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/'); |
|
| 27 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/'); |
|
| 28 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/'); |
|
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | protected function _extend_page_config() |
| 37 | 37 | { |
| 38 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
| 38 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events'; |
|
| 39 | 39 | //is there a evt_id in the request? |
| 40 | 40 | $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
| 41 | 41 | ? $this->_req_data['EVT_ID'] |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | 'help_tour' => array('Templates_Help_Tour'), |
| 169 | 169 | 'require_nonce' => false, |
| 170 | 170 | ); |
| 171 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 171 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 172 | 172 | //add filters and actions |
| 173 | 173 | //modifying _views |
| 174 | 174 | add_filter( |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * check whether count of tickets is approaching the potential |
| 242 | 242 | * limits for the server. |
| 243 | 243 | */ |
| 244 | - if (! empty($data['input_count'])) { |
|
| 244 | + if ( ! empty($data['input_count'])) { |
|
| 245 | 245 | $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check( |
| 246 | 246 | $data['input_count'] |
| 247 | 247 | ); |
@@ -270,12 +270,12 @@ discard block |
||
| 270 | 270 | { |
| 271 | 271 | $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
| 272 | 272 | //make sure this is only when editing |
| 273 | - if (! empty($id)) { |
|
| 274 | - $href = EE_Admin_Page::add_query_args_and_nonce( |
|
| 273 | + if ( ! empty($id)) { |
|
| 274 | + $href = EE_Admin_Page::add_query_args_and_nonce( |
|
| 275 | 275 | array('action' => 'duplicate_event', 'EVT_ID' => $id), |
| 276 | 276 | $this->_admin_base_url |
| 277 | 277 | ); |
| 278 | - $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
| 278 | + $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
| 279 | 279 | $return .= '<a href="' |
| 280 | 280 | . $href |
| 281 | 281 | . '" title="' |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | { |
| 323 | 323 | wp_register_script( |
| 324 | 324 | 'ee-event-editor-heartbeat', |
| 325 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
| 325 | + EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js', |
|
| 326 | 326 | array('ee_admin_js', 'heartbeat'), |
| 327 | 327 | EVENT_ESPRESSO_VERSION, |
| 328 | 328 | true |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | public function add_additional_datetime_button($template, $template_args) |
| 346 | 346 | { |
| 347 | 347 | return EEH_Template::display_template( |
| 348 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
| 348 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php', |
|
| 349 | 349 | $template_args, |
| 350 | 350 | true |
| 351 | 351 | ); |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | public function add_datetime_clone_button($template, $template_args) |
| 363 | 363 | { |
| 364 | 364 | return EEH_Template::display_template( |
| 365 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
| 365 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php', |
|
| 366 | 366 | $template_args, |
| 367 | 367 | true |
| 368 | 368 | ); |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | public function datetime_timezones_template($template, $template_args) |
| 380 | 380 | { |
| 381 | 381 | return EEH_Template::display_template( |
| 382 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
| 382 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php', |
|
| 383 | 383 | $template_args, |
| 384 | 384 | true |
| 385 | 385 | ); |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | protected function _set_list_table_views_default() |
| 393 | 393 | { |
| 394 | 394 | parent::_set_list_table_views_default(); |
| 395 | - $new_views = array( |
|
| 395 | + $new_views = array( |
|
| 396 | 396 | 'today' => array( |
| 397 | 397 | 'slug' => 'today', |
| 398 | 398 | 'label' => esc_html__('Today', 'event_espresso'), |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | { |
| 498 | 498 | // first make sure the ID for the event is in the request. |
| 499 | 499 | // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
| 500 | - if (! isset($this->_req_data['EVT_ID'])) { |
|
| 500 | + if ( ! isset($this->_req_data['EVT_ID'])) { |
|
| 501 | 501 | EE_Error::add_error( |
| 502 | 502 | esc_html__( |
| 503 | 503 | 'In order to duplicate an event an Event ID is required. None was given.', |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | } |
| 513 | 513 | //k we've got EVT_ID so let's use that to get the event we'll duplicate |
| 514 | 514 | $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
| 515 | - if (! $orig_event instanceof EE_Event) { |
|
| 515 | + if ( ! $orig_event instanceof EE_Event) { |
|
| 516 | 516 | throw new EE_Error( |
| 517 | 517 | sprintf( |
| 518 | 518 | esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | $orig_ven = $orig_event->get_many_related('Venue'); |
| 529 | 529 | //reset the ID and modify other details to make it clear this is a dupe |
| 530 | 530 | $new_event->set('EVT_ID', 0); |
| 531 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 531 | + $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 532 | 532 | $new_event->set('EVT_name', $new_name); |
| 533 | 533 | $new_event->set( |
| 534 | 534 | 'EVT_slug', |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | 'Question_Group', |
| 558 | 558 | array(array('Event_Question_Group.EQG_primary' => 1)) |
| 559 | 559 | ); |
| 560 | - if (! empty($orig_primary_qgs)) { |
|
| 560 | + if ( ! empty($orig_primary_qgs)) { |
|
| 561 | 561 | foreach ($orig_primary_qgs as $id => $obj) { |
| 562 | 562 | if ($obj instanceof EE_Question_Group) { |
| 563 | 563 | $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1)); |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | 'Question_Group', |
| 570 | 570 | array(array('Event_Question_Group.EQG_primary' => 0)) |
| 571 | 571 | ); |
| 572 | - if (! empty($orig_additional_qgs)) { |
|
| 572 | + if ( ! empty($orig_additional_qgs)) { |
|
| 573 | 573 | foreach ($orig_additional_qgs as $id => $obj) { |
| 574 | 574 | if ($obj instanceof EE_Question_Group) { |
| 575 | 575 | $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0)); |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | //k now that we have the new event saved we can loop through the datetimes and start adding relations. |
| 582 | 582 | $cloned_tickets = array(); |
| 583 | 583 | foreach ($orig_datetimes as $orig_dtt) { |
| 584 | - if (! $orig_dtt instanceof EE_Datetime) { |
|
| 584 | + if ( ! $orig_dtt instanceof EE_Datetime) { |
|
| 585 | 585 | continue; |
| 586 | 586 | } |
| 587 | 587 | $new_dtt = clone $orig_dtt; |
@@ -594,9 +594,9 @@ discard block |
||
| 594 | 594 | $new_event->_add_relation_to($new_dtt, 'Datetime'); |
| 595 | 595 | $new_event->save(); |
| 596 | 596 | //now let's get the ticket relations setup. |
| 597 | - foreach ((array)$orig_tkts as $orig_tkt) { |
|
| 597 | + foreach ((array) $orig_tkts as $orig_tkt) { |
|
| 598 | 598 | //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
| 599 | - if (! $orig_tkt instanceof EE_Ticket) { |
|
| 599 | + if ( ! $orig_tkt instanceof EE_Ticket) { |
|
| 600 | 600 | continue; |
| 601 | 601 | } |
| 602 | 602 | //is this ticket archived? If it is then let's skip |
@@ -692,8 +692,8 @@ discard block |
||
| 692 | 692 | array('action' => 'sample_export_file'), |
| 693 | 693 | $this->_admin_base_url |
| 694 | 694 | ); |
| 695 | - $content = EEH_Template::display_template( |
|
| 696 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
| 695 | + $content = EEH_Template::display_template( |
|
| 696 | + EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php', |
|
| 697 | 697 | $this->_template_args, |
| 698 | 698 | true |
| 699 | 699 | ); |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | */ |
| 711 | 711 | protected function _import_events() |
| 712 | 712 | { |
| 713 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
| 713 | + require_once(EE_CLASSES.'EE_Import.class.php'); |
|
| 714 | 714 | $success = EE_Import::instance()->import(); |
| 715 | 715 | $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
| 716 | 716 | } |
@@ -738,9 +738,9 @@ discard block |
||
| 738 | 738 | 'action' => 'all_event_data', |
| 739 | 739 | 'EVT_ID' => $event_ids, |
| 740 | 740 | ); |
| 741 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 742 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 743 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 741 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 742 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
| 743 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
| 744 | 744 | $EE_Export = EE_Export::instance($this->_req_data); |
| 745 | 745 | $EE_Export->export(); |
| 746 | 746 | } |
@@ -760,9 +760,9 @@ discard block |
||
| 760 | 760 | 'action' => 'categories', |
| 761 | 761 | 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
| 762 | 762 | ); |
| 763 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 764 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 765 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 763 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 764 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
| 765 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
| 766 | 766 | $EE_Export = EE_Export::instance($this->_req_data); |
| 767 | 767 | $EE_Export->export(); |
| 768 | 768 | } |
@@ -799,7 +799,7 @@ discard block |
||
| 799 | 799 | $this->_set_add_edit_form_tags('update_template_settings'); |
| 800 | 800 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
| 801 | 801 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 802 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
| 802 | + EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php', |
|
| 803 | 803 | $this->_template_args, |
| 804 | 804 | true |
| 805 | 805 | ); |
@@ -871,11 +871,11 @@ discard block |
||
| 871 | 871 | */ |
| 872 | 872 | public function registration_options_meta_box() |
| 873 | 873 | { |
| 874 | - $yes_no_values = array( |
|
| 874 | + $yes_no_values = array( |
|
| 875 | 875 | array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
| 876 | 876 | array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
| 877 | 877 | ); |
| 878 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 878 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 879 | 879 | array( |
| 880 | 880 | EEM_Registration::status_id_cancelled, |
| 881 | 881 | EEM_Registration::status_id_declined, |
@@ -892,12 +892,12 @@ discard block |
||
| 892 | 892 | $default_reg_status_values, |
| 893 | 893 | $this->_cpt_model_obj->default_registration_status() |
| 894 | 894 | ); |
| 895 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 895 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 896 | 896 | 'display_desc', |
| 897 | 897 | $yes_no_values, |
| 898 | 898 | $this->_cpt_model_obj->display_description() |
| 899 | 899 | ); |
| 900 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 900 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 901 | 901 | 'display_ticket_selector', |
| 902 | 902 | $yes_no_values, |
| 903 | 903 | $this->_cpt_model_obj->display_ticket_selector(), |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | $default_reg_status_values |
| 919 | 919 | ); |
| 920 | 920 | EEH_Template::display_template( |
| 921 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 921 | + EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php', |
|
| 922 | 922 | $template_args |
| 923 | 923 | ); |
| 924 | 924 | } |
@@ -1022,13 +1022,13 @@ discard block |
||
| 1022 | 1022 | { |
| 1023 | 1023 | $start = EEM_Datetime::instance()->convert_datetime_for_query( |
| 1024 | 1024 | 'DTT_EVT_start', |
| 1025 | - date('Y-m-d') . ' 00:00:00', |
|
| 1025 | + date('Y-m-d').' 00:00:00', |
|
| 1026 | 1026 | 'Y-m-d H:i:s', |
| 1027 | 1027 | 'UTC' |
| 1028 | 1028 | ); |
| 1029 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1029 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1030 | 1030 | 'DTT_EVT_start', |
| 1031 | - date('Y-m-d') . ' 23:59:59', |
|
| 1031 | + date('Y-m-d').' 23:59:59', |
|
| 1032 | 1032 | 'Y-m-d H:i:s', |
| 1033 | 1033 | 'UTC' |
| 1034 | 1034 | ); |
@@ -1055,13 +1055,13 @@ discard block |
||
| 1055 | 1055 | $days_this_month = date('t'); |
| 1056 | 1056 | $start = EEM_Datetime::instance()->convert_datetime_for_query( |
| 1057 | 1057 | 'DTT_EVT_start', |
| 1058 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
| 1058 | + $this_year_r.'-'.$this_month_r.'-01 00:00:00', |
|
| 1059 | 1059 | 'Y-m-d H:i:s', |
| 1060 | 1060 | 'UTC' |
| 1061 | 1061 | ); |
| 1062 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1062 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1063 | 1063 | 'DTT_EVT_start', |
| 1064 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
| 1064 | + $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59', |
|
| 1065 | 1065 | 'Y-m-d H:i:s', |
| 1066 | 1066 | 'UTC' |
| 1067 | 1067 | ); |
@@ -1128,7 +1128,7 @@ discard block |
||
| 1128 | 1128 | $offset = ($current_page - 1) * $per_page; |
| 1129 | 1129 | $limit = array($offset, $per_page); |
| 1130 | 1130 | if (isset($this->_req_data['s'])) { |
| 1131 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1131 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
| 1132 | 1132 | $_where['OR'] = array( |
| 1133 | 1133 | 'TKT_name' => array('LIKE', $sstr), |
| 1134 | 1134 | 'TKT_description' => array('LIKE', $sstr), |
@@ -1157,17 +1157,17 @@ discard block |
||
| 1157 | 1157 | $success = 1; |
| 1158 | 1158 | $TKT = EEM_Ticket::instance(); |
| 1159 | 1159 | //checkboxes? |
| 1160 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1160 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1161 | 1161 | //if array has more than one element then success message should be plural |
| 1162 | 1162 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
| 1163 | 1163 | //cycle thru the boxes |
| 1164 | 1164 | while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
| 1165 | 1165 | if ($trash) { |
| 1166 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1166 | + if ( ! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1167 | 1167 | $success = 0; |
| 1168 | 1168 | } |
| 1169 | 1169 | } else { |
| 1170 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1170 | + if ( ! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1171 | 1171 | $success = 0; |
| 1172 | 1172 | } |
| 1173 | 1173 | } |
@@ -1176,11 +1176,11 @@ discard block |
||
| 1176 | 1176 | //grab single id and trash |
| 1177 | 1177 | $TKT_ID = absint($this->_req_data['TKT_ID']); |
| 1178 | 1178 | if ($trash) { |
| 1179 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1179 | + if ( ! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1180 | 1180 | $success = 0; |
| 1181 | 1181 | } |
| 1182 | 1182 | } else { |
| 1183 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1183 | + if ( ! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1184 | 1184 | $success = 0; |
| 1185 | 1185 | } |
| 1186 | 1186 | } |
@@ -1201,20 +1201,20 @@ discard block |
||
| 1201 | 1201 | { |
| 1202 | 1202 | $success = 1; |
| 1203 | 1203 | //checkboxes? |
| 1204 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1204 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1205 | 1205 | //if array has more than one element then success message should be plural |
| 1206 | 1206 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
| 1207 | 1207 | //cycle thru the boxes |
| 1208 | 1208 | while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
| 1209 | 1209 | //delete |
| 1210 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1210 | + if ( ! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1211 | 1211 | $success = 0; |
| 1212 | 1212 | } |
| 1213 | 1213 | } |
| 1214 | 1214 | } else { |
| 1215 | 1215 | //grab single id and trash |
| 1216 | 1216 | $TKT_ID = absint($this->_req_data['TKT_ID']); |
| 1217 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1217 | + if ( ! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1218 | 1218 | $success = 0; |
| 1219 | 1219 | } |
| 1220 | 1220 | } |
@@ -748,7 +748,7 @@ discard block |
||
| 748 | 748 | * |
| 749 | 749 | * @access public |
| 750 | 750 | * @param string $CNT_ISO |
| 751 | - * @return mixed string | array |
|
| 751 | + * @return string|null string | array |
|
| 752 | 752 | * @throws DomainException |
| 753 | 753 | */ |
| 754 | 754 | public function display_country_settings($CNT_ISO = '') |
@@ -1064,7 +1064,7 @@ discard block |
||
| 1064 | 1064 | * delete_state |
| 1065 | 1065 | * |
| 1066 | 1066 | * @access public |
| 1067 | - * @return boolean |
|
| 1067 | + * @return false|null |
|
| 1068 | 1068 | */ |
| 1069 | 1069 | public function delete_state() |
| 1070 | 1070 | { |
@@ -17,1386 +17,1386 @@ |
||
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * _question_group |
|
| 22 | - * holds the specific question group object for the question group details screen |
|
| 23 | - * |
|
| 24 | - * @var object |
|
| 25 | - */ |
|
| 26 | - protected $_question_group; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Initialize basic properties. |
|
| 31 | - */ |
|
| 32 | - protected function _init_page_props() |
|
| 33 | - { |
|
| 34 | - $this->page_slug = GEN_SET_PG_SLUG; |
|
| 35 | - $this->page_label = GEN_SET_LABEL; |
|
| 36 | - $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
| 37 | - $this->_admin_base_path = GEN_SET_ADMIN; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Set ajax hooks |
|
| 43 | - */ |
|
| 44 | - protected function _ajax_hooks() |
|
| 45 | - { |
|
| 46 | - add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings')); |
|
| 47 | - add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states')); |
|
| 48 | - add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3); |
|
| 49 | - add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state')); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * More page properties initialization. |
|
| 55 | - */ |
|
| 56 | - protected function _define_page_props() |
|
| 57 | - { |
|
| 58 | - $this->_admin_page_title = GEN_SET_LABEL; |
|
| 59 | - $this->_labels = array( |
|
| 60 | - 'publishbox' => __('Update Settings', 'event_espresso'), |
|
| 61 | - ); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Set page routes property. |
|
| 67 | - */ |
|
| 68 | - protected function _set_page_routes() |
|
| 69 | - { |
|
| 70 | - $this->_page_routes = array( |
|
| 71 | - |
|
| 72 | - 'critical_pages' => array( |
|
| 73 | - 'func' => '_espresso_page_settings', |
|
| 74 | - 'capability' => 'manage_options', |
|
| 75 | - ), |
|
| 76 | - 'update_espresso_page_settings' => array( |
|
| 77 | - 'func' => '_update_espresso_page_settings', |
|
| 78 | - 'capability' => 'manage_options', |
|
| 79 | - 'noheader' => true, |
|
| 80 | - ), |
|
| 81 | - 'default' => array( |
|
| 82 | - 'func' => '_your_organization_settings', |
|
| 83 | - 'capability' => 'manage_options', |
|
| 84 | - ), |
|
| 85 | - |
|
| 86 | - 'update_your_organization_settings' => array( |
|
| 87 | - 'func' => '_update_your_organization_settings', |
|
| 88 | - 'capability' => 'manage_options', |
|
| 89 | - 'noheader' => true, |
|
| 90 | - ), |
|
| 91 | - |
|
| 92 | - 'admin_option_settings' => array( |
|
| 93 | - 'func' => '_admin_option_settings', |
|
| 94 | - 'capability' => 'manage_options', |
|
| 95 | - ), |
|
| 96 | - |
|
| 97 | - 'update_admin_option_settings' => array( |
|
| 98 | - 'func' => '_update_admin_option_settings', |
|
| 99 | - 'capability' => 'manage_options', |
|
| 100 | - 'noheader' => true, |
|
| 101 | - ), |
|
| 102 | - |
|
| 103 | - 'country_settings' => array( |
|
| 104 | - 'func' => '_country_settings', |
|
| 105 | - 'capability' => 'manage_options', |
|
| 106 | - ), |
|
| 107 | - |
|
| 108 | - 'update_country_settings' => array( |
|
| 109 | - 'func' => '_update_country_settings', |
|
| 110 | - 'capability' => 'manage_options', |
|
| 111 | - 'noheader' => true, |
|
| 112 | - ), |
|
| 113 | - |
|
| 114 | - 'display_country_settings' => array( |
|
| 115 | - 'func' => 'display_country_settings', |
|
| 116 | - 'capability' => 'manage_options', |
|
| 117 | - 'noheader' => true, |
|
| 118 | - ), |
|
| 119 | - |
|
| 120 | - 'add_new_state' => array( |
|
| 121 | - 'func' => 'add_new_state', |
|
| 122 | - 'capability' => 'manage_options', |
|
| 123 | - 'noheader' => true, |
|
| 124 | - ), |
|
| 125 | - |
|
| 126 | - 'delete_state' => array( |
|
| 127 | - 'func' => 'delete_state', |
|
| 128 | - 'capability' => 'manage_options', |
|
| 129 | - 'noheader' => true, |
|
| 130 | - ), |
|
| 131 | - ); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Set page configuration property |
|
| 137 | - */ |
|
| 138 | - protected function _set_page_config() |
|
| 139 | - { |
|
| 140 | - $this->_page_config = array( |
|
| 141 | - 'critical_pages' => array( |
|
| 142 | - 'nav' => array( |
|
| 143 | - 'label' => __('Critical Pages', 'event_espresso'), |
|
| 144 | - 'order' => 50, |
|
| 145 | - ), |
|
| 146 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 147 | - 'help_tabs' => array( |
|
| 148 | - 'general_settings_critical_pages_help_tab' => array( |
|
| 149 | - 'title' => __('Critical Pages', 'event_espresso'), |
|
| 150 | - 'filename' => 'general_settings_critical_pages', |
|
| 151 | - ), |
|
| 152 | - ), |
|
| 153 | - 'help_tour' => array('Critical_Pages_Help_Tour'), |
|
| 154 | - 'require_nonce' => false, |
|
| 155 | - ), |
|
| 156 | - 'default' => array( |
|
| 157 | - 'nav' => array( |
|
| 158 | - 'label' => __('Your Organization', 'event_espresso'), |
|
| 159 | - 'order' => 20, |
|
| 160 | - ), |
|
| 161 | - 'help_tabs' => array( |
|
| 162 | - 'general_settings_your_organization_help_tab' => array( |
|
| 163 | - 'title' => __('Your Organization', 'event_espresso'), |
|
| 164 | - 'filename' => 'general_settings_your_organization', |
|
| 165 | - ), |
|
| 166 | - ), |
|
| 167 | - 'help_tour' => array('Your_Organization_Help_Tour'), |
|
| 168 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 169 | - 'require_nonce' => false, |
|
| 170 | - ), |
|
| 171 | - 'admin_option_settings' => array( |
|
| 172 | - 'nav' => array( |
|
| 173 | - 'label' => __('Admin Options', 'event_espresso'), |
|
| 174 | - 'order' => 60, |
|
| 175 | - ), |
|
| 176 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 177 | - 'help_tabs' => array( |
|
| 178 | - 'general_settings_admin_options_help_tab' => array( |
|
| 179 | - 'title' => __('Admin Options', 'event_espresso'), |
|
| 180 | - 'filename' => 'general_settings_admin_options', |
|
| 181 | - ), |
|
| 182 | - ), |
|
| 183 | - 'help_tour' => array('Admin_Options_Help_Tour'), |
|
| 184 | - 'require_nonce' => false, |
|
| 185 | - ), |
|
| 186 | - 'country_settings' => array( |
|
| 187 | - 'nav' => array( |
|
| 188 | - 'label' => __('Countries', 'event_espresso'), |
|
| 189 | - 'order' => 70, |
|
| 190 | - ), |
|
| 191 | - 'help_tabs' => array( |
|
| 192 | - 'general_settings_countries_help_tab' => array( |
|
| 193 | - 'title' => __('Countries', 'event_espresso'), |
|
| 194 | - 'filename' => 'general_settings_countries', |
|
| 195 | - ), |
|
| 196 | - ), |
|
| 197 | - 'help_tour' => array('Countries_Help_Tour'), |
|
| 198 | - 'require_nonce' => false, |
|
| 199 | - ), |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - protected function _add_screen_options() |
|
| 206 | - { |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - protected function _add_feature_pointers() |
|
| 210 | - { |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
| 216 | - */ |
|
| 217 | - public function load_scripts_styles() |
|
| 218 | - { |
|
| 219 | - //styles |
|
| 220 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 221 | - //scripts |
|
| 222 | - wp_enqueue_script('ee_admin_js'); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Execute logic running on `admin_init` |
|
| 228 | - */ |
|
| 229 | - public function admin_init() |
|
| 230 | - { |
|
| 231 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = __( |
|
| 232 | - '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.', |
|
| 233 | - 'event_espresso' |
|
| 234 | - ); |
|
| 235 | - EE_Registry::$i18n_js_strings['error_occurred'] = __( |
|
| 236 | - 'An error occurred! Please refresh the page and try again.', |
|
| 237 | - 'event_espresso' |
|
| 238 | - ); |
|
| 239 | - EE_Registry::$i18n_js_strings['confirm_delete_state'] = __( |
|
| 240 | - 'Are you sure you want to delete this State / Province?', |
|
| 241 | - 'event_espresso' |
|
| 242 | - ); |
|
| 243 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 244 | - EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
| 245 | - 'admin-ajax.php?page=espresso_general_settings', |
|
| 246 | - $protocol |
|
| 247 | - ); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - public function admin_notices() |
|
| 251 | - { |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - public function admin_footer_scripts() |
|
| 255 | - { |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Enqueue scripts and styles for the default route. |
|
| 261 | - */ |
|
| 262 | - public function load_scripts_styles_default() |
|
| 263 | - { |
|
| 264 | - //styles |
|
| 265 | - wp_enqueue_style('thickbox'); |
|
| 266 | - //scripts |
|
| 267 | - wp_enqueue_script('media-upload'); |
|
| 268 | - wp_enqueue_script('thickbox'); |
|
| 269 | - wp_register_script( |
|
| 270 | - 'organization_settings', |
|
| 271 | - GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
| 272 | - array('jquery', 'media-upload', 'thickbox'), |
|
| 273 | - EVENT_ESPRESSO_VERSION, |
|
| 274 | - true |
|
| 275 | - ); |
|
| 276 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 277 | - wp_enqueue_script('organization_settings'); |
|
| 278 | - wp_enqueue_style('organization-css'); |
|
| 279 | - $confirm_image_delete = array( |
|
| 280 | - 'text' => __( |
|
| 281 | - 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
| 282 | - 'event_espresso' |
|
| 283 | - ), |
|
| 284 | - ); |
|
| 285 | - wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Enqueue scripts and styles for the country settings route. |
|
| 291 | - */ |
|
| 292 | - public function load_scripts_styles_country_settings() |
|
| 293 | - { |
|
| 294 | - //scripts |
|
| 295 | - wp_register_script( |
|
| 296 | - 'gen_settings_countries', |
|
| 297 | - GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
| 298 | - array('ee_admin_js'), |
|
| 299 | - EVENT_ESPRESSO_VERSION, |
|
| 300 | - true |
|
| 301 | - ); |
|
| 302 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 303 | - wp_enqueue_script('gen_settings_countries'); |
|
| 304 | - wp_enqueue_style('organization-css'); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /************* Espresso Pages *************/ |
|
| 309 | - /** |
|
| 310 | - * _espresso_page_settings |
|
| 311 | - * |
|
| 312 | - * @throws \EE_Error |
|
| 313 | - */ |
|
| 314 | - protected function _espresso_page_settings() |
|
| 315 | - { |
|
| 316 | - // Check to make sure all of the main pages are setup properly, |
|
| 317 | - // if not create the default pages and display an admin notice |
|
| 318 | - EEH_Activation::verify_default_pages_exist(); |
|
| 319 | - $this->_transient_garbage_collection(); |
|
| 320 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 321 | - $this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 322 | - ? EE_Registry::instance()->CFG->core->reg_page_id |
|
| 323 | - : null; |
|
| 324 | - $this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 325 | - ? get_page(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 326 | - : false; |
|
| 327 | - $this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 328 | - ? EE_Registry::instance()->CFG->core->txn_page_id |
|
| 329 | - : null; |
|
| 330 | - $this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 331 | - ? get_page(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 332 | - : false; |
|
| 333 | - $this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 334 | - ? EE_Registry::instance()->CFG->core->thank_you_page_id |
|
| 335 | - : null; |
|
| 336 | - $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 337 | - ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 338 | - : false; |
|
| 339 | - $this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 340 | - ? EE_Registry::instance()->CFG->core->cancel_page_id |
|
| 341 | - : null; |
|
| 342 | - $this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 343 | - ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 344 | - : false; |
|
| 345 | - $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
| 346 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 347 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 348 | - GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
| 349 | - $this->_template_args, |
|
| 350 | - true |
|
| 351 | - ); |
|
| 352 | - $this->display_admin_page_with_sidebar(); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Handler for updating espresso page settings. |
|
| 358 | - */ |
|
| 359 | - protected function _update_espresso_page_settings() |
|
| 360 | - { |
|
| 361 | - // capture incoming request data && set page IDs |
|
| 362 | - EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id']) |
|
| 363 | - ? absint($this->_req_data['reg_page_id']) |
|
| 364 | - : EE_Registry::instance()->CFG->core->reg_page_id; |
|
| 365 | - EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id']) |
|
| 366 | - ? absint($this->_req_data['txn_page_id']) |
|
| 367 | - : EE_Registry::instance()->CFG->core->txn_page_id; |
|
| 368 | - EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id']) |
|
| 369 | - ? absint($this->_req_data['thank_you_page_id']) |
|
| 370 | - : EE_Registry::instance()->CFG->core->thank_you_page_id; |
|
| 371 | - EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id']) |
|
| 372 | - ? absint($this->_req_data['cancel_page_id']) |
|
| 373 | - : EE_Registry::instance()->CFG->core->cancel_page_id; |
|
| 374 | - |
|
| 375 | - EE_Registry::instance()->CFG->core = apply_filters( |
|
| 376 | - 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
| 377 | - EE_Registry::instance()->CFG->core, |
|
| 378 | - $this->_req_data |
|
| 379 | - ); |
|
| 380 | - $what = __('Critical Pages & Shortcodes', 'event_espresso'); |
|
| 381 | - $this->_redirect_after_action( |
|
| 382 | - $this->_update_espresso_configuration( |
|
| 383 | - $what, |
|
| 384 | - EE_Registry::instance()->CFG->core, |
|
| 385 | - __FILE__, |
|
| 386 | - __FUNCTION__, |
|
| 387 | - __LINE__ |
|
| 388 | - ), |
|
| 389 | - $what, |
|
| 390 | - '', |
|
| 391 | - array( |
|
| 392 | - 'action' => 'critical_pages', |
|
| 393 | - ), |
|
| 394 | - true |
|
| 395 | - ); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - /************* Your Organization *************/ |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * Output for the Your Organization settings route. |
|
| 404 | - * @throws DomainException |
|
| 405 | - * @throws EE_Error |
|
| 406 | - */ |
|
| 407 | - protected function _your_organization_settings() |
|
| 408 | - { |
|
| 409 | - |
|
| 410 | - $this->_template_args['site_license_key'] = isset( |
|
| 411 | - EE_Registry::instance()->NET_CFG->core->site_license_key |
|
| 412 | - ) |
|
| 413 | - ? EE_Registry::instance()->NET_CFG->core->get_pretty('site_license_key') |
|
| 414 | - : ''; |
|
| 415 | - $this->_template_args['organization_name'] = isset(EE_Registry::instance()->CFG->organization->name) |
|
| 416 | - ? EE_Registry::instance()->CFG->organization->get_pretty('name') |
|
| 417 | - : ''; |
|
| 418 | - $this->_template_args['organization_address_1'] = isset(EE_Registry::instance()->CFG->organization->address_1) |
|
| 419 | - ? EE_Registry::instance()->CFG->organization->get_pretty('address_1') |
|
| 420 | - : ''; |
|
| 421 | - $this->_template_args['organization_address_2'] = isset(EE_Registry::instance()->CFG->organization->address_2) |
|
| 422 | - ? EE_Registry::instance()->CFG->organization->get_pretty('address_2') |
|
| 423 | - : ''; |
|
| 424 | - $this->_template_args['organization_city'] = isset(EE_Registry::instance()->CFG->organization->city) |
|
| 425 | - ? EE_Registry::instance()->CFG->organization->get_pretty('city') |
|
| 426 | - : ''; |
|
| 427 | - $this->_template_args['organization_zip'] = isset(EE_Registry::instance()->CFG->organization->zip) |
|
| 428 | - ? EE_Registry::instance()->CFG->organization->get_pretty('zip') |
|
| 429 | - : ''; |
|
| 430 | - $this->_template_args['organization_email'] = isset(EE_Registry::instance()->CFG->organization->email) |
|
| 431 | - ? EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 432 | - : ''; |
|
| 433 | - $this->_template_args['organization_phone'] = isset(EE_Registry::instance()->CFG->organization->phone) |
|
| 434 | - ? EE_Registry::instance()->CFG->organization->get_pretty('phone') |
|
| 435 | - : ''; |
|
| 436 | - $this->_template_args['organization_vat'] = isset(EE_Registry::instance()->CFG->organization->vat) |
|
| 437 | - ? EE_Registry::instance()->CFG->organization->get_pretty('vat') |
|
| 438 | - : ''; |
|
| 439 | - $this->_template_args['currency_sign'] = isset(EE_Registry::instance()->CFG->currency->sign) |
|
| 440 | - ? EE_Registry::instance()->CFG->currency->get_pretty('sign') |
|
| 441 | - : '$'; |
|
| 442 | - $this->_template_args['organization_logo_url'] = isset(EE_Registry::instance()->CFG->organization->logo_url) |
|
| 443 | - ? EE_Registry::instance()->CFG->organization->get_pretty('logo_url') |
|
| 444 | - : false; |
|
| 445 | - $this->_template_args['organization_facebook'] = isset(EE_Registry::instance()->CFG->organization->facebook) |
|
| 446 | - ? EE_Registry::instance()->CFG->organization->get_pretty('facebook') |
|
| 447 | - : ''; |
|
| 448 | - $this->_template_args['organization_twitter'] = isset(EE_Registry::instance()->CFG->organization->twitter) |
|
| 449 | - ? EE_Registry::instance()->CFG->organization->get_pretty('twitter') |
|
| 450 | - : ''; |
|
| 451 | - $this->_template_args['organization_linkedin'] = isset(EE_Registry::instance()->CFG->organization->linkedin) |
|
| 452 | - ? EE_Registry::instance()->CFG->organization->get_pretty('linkedin') |
|
| 453 | - : ''; |
|
| 454 | - $this->_template_args['organization_pinterest'] = isset(EE_Registry::instance()->CFG->organization->pinterest) |
|
| 455 | - ? EE_Registry::instance()->CFG->organization->get_pretty('pinterest') |
|
| 456 | - : ''; |
|
| 457 | - $this->_template_args['organization_google'] = isset(EE_Registry::instance()->CFG->organization->google) |
|
| 458 | - ? EE_Registry::instance()->CFG->organization->get_pretty('google') |
|
| 459 | - : ''; |
|
| 460 | - $this->_template_args['organization_instagram'] = isset(EE_Registry::instance()->CFG->organization->instagram) |
|
| 461 | - ? EE_Registry::instance()->CFG->organization->get_pretty('instagram') |
|
| 462 | - : ''; |
|
| 463 | - //UXIP settings |
|
| 464 | - $this->_template_args['ee_ueip_optin'] = isset(EE_Registry::instance()->CFG->core->ee_ueip_optin) |
|
| 465 | - ? EE_Registry::instance()->CFG->core->get_pretty('ee_ueip_optin') |
|
| 466 | - : true; |
|
| 467 | - |
|
| 468 | - $STA_ID = isset(EE_Registry::instance()->CFG->organization->STA_ID) |
|
| 469 | - ? EE_Registry::instance()->CFG->organization->STA_ID |
|
| 470 | - : 4; |
|
| 471 | - $this->_template_args['states'] = new EE_Question_Form_Input( |
|
| 472 | - EE_Question::new_instance(array( |
|
| 473 | - 'QST_ID' => 0, |
|
| 474 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 475 | - 'QST_system' => 'admin-state', |
|
| 476 | - )), |
|
| 477 | - EE_Answer::new_instance(array( |
|
| 478 | - 'ANS_ID' => 0, |
|
| 479 | - 'ANS_value' => $STA_ID, |
|
| 480 | - )), |
|
| 481 | - array( |
|
| 482 | - 'input_id' => 'organization_state', |
|
| 483 | - 'input_name' => 'organization_state', |
|
| 484 | - 'input_prefix' => '', |
|
| 485 | - 'append_qstn_id' => false, |
|
| 486 | - ) |
|
| 487 | - ); |
|
| 488 | - |
|
| 489 | - $CNT_ISO = isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 490 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 491 | - : 'US'; |
|
| 492 | - $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
| 493 | - EE_Question::new_instance(array( |
|
| 494 | - 'QST_ID' => 0, |
|
| 495 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 496 | - 'QST_system' => 'admin-country', |
|
| 497 | - )), |
|
| 498 | - EE_Answer::new_instance(array( |
|
| 499 | - 'ANS_ID' => 0, |
|
| 500 | - 'ANS_value' => $CNT_ISO, |
|
| 501 | - )), |
|
| 502 | - array( |
|
| 503 | - 'input_id' => 'organization_country', |
|
| 504 | - 'input_name' => 'organization_country', |
|
| 505 | - 'input_prefix' => '', |
|
| 506 | - 'append_qstn_id' => false, |
|
| 507 | - ) |
|
| 508 | - ); |
|
| 509 | - |
|
| 510 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 511 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 512 | - |
|
| 513 | - //PUE verification stuff |
|
| 514 | - $ver_option_key = 'puvererr_' . basename(EE_PLUGIN_BASENAME); |
|
| 515 | - $verify_fail = get_option($ver_option_key); |
|
| 516 | - $this->_template_args['site_license_key_verified'] = $verify_fail |
|
| 517 | - || ! empty($verify_fail) |
|
| 518 | - || (empty($this->_template_args['site_license_key']) |
|
| 519 | - && empty($verify_fail) |
|
| 520 | - ) |
|
| 521 | - ? '<span class="dashicons dashicons-admin-network ee-icon-color-ee-red ee-icon-size-20"></span>' |
|
| 522 | - : '<span class="dashicons dashicons-admin-network ee-icon-color-ee-green ee-icon-size-20"></span>'; |
|
| 523 | - |
|
| 524 | - $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
| 525 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 526 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 527 | - GEN_SET_TEMPLATE_PATH . 'your_organization_settings.template.php', |
|
| 528 | - $this->_template_args, |
|
| 529 | - true |
|
| 530 | - ); |
|
| 531 | - |
|
| 532 | - $this->display_admin_page_with_sidebar(); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * Handler for updating organziation settings. |
|
| 538 | - */ |
|
| 539 | - protected function _update_your_organization_settings() |
|
| 540 | - { |
|
| 541 | - if (is_main_site()) { |
|
| 542 | - EE_Registry::instance()->NET_CFG->core->site_license_key = isset($this->_req_data['site_license_key']) |
|
| 543 | - ? sanitize_text_field($this->_req_data['site_license_key']) |
|
| 544 | - : EE_Registry::instance()->NET_CFG->core->site_license_key; |
|
| 545 | - } |
|
| 546 | - EE_Registry::instance()->CFG->organization->name = isset($this->_req_data['organization_name']) |
|
| 547 | - ? sanitize_text_field($this->_req_data['organization_name']) |
|
| 548 | - : EE_Registry::instance()->CFG->organization->name; |
|
| 549 | - EE_Registry::instance()->CFG->organization->address_1 = isset($this->_req_data['organization_address_1']) |
|
| 550 | - ? sanitize_text_field($this->_req_data['organization_address_1']) |
|
| 551 | - : EE_Registry::instance()->CFG->organization->address_1; |
|
| 552 | - EE_Registry::instance()->CFG->organization->address_2 = isset($this->_req_data['organization_address_2']) |
|
| 553 | - ? sanitize_text_field($this->_req_data['organization_address_2']) |
|
| 554 | - : EE_Registry::instance()->CFG->organization->address_2; |
|
| 555 | - EE_Registry::instance()->CFG->organization->city = isset($this->_req_data['organization_city']) |
|
| 556 | - ? sanitize_text_field($this->_req_data['organization_city']) |
|
| 557 | - : EE_Registry::instance()->CFG->organization->city; |
|
| 558 | - EE_Registry::instance()->CFG->organization->STA_ID = isset($this->_req_data['organization_state']) |
|
| 559 | - ? absint($this->_req_data['organization_state']) |
|
| 560 | - : EE_Registry::instance()->CFG->organization->STA_ID; |
|
| 561 | - EE_Registry::instance()->CFG->organization->CNT_ISO = isset($this->_req_data['organization_country']) |
|
| 562 | - ? sanitize_text_field($this->_req_data['organization_country']) |
|
| 563 | - : EE_Registry::instance()->CFG->organization->CNT_ISO; |
|
| 564 | - EE_Registry::instance()->CFG->organization->zip = isset($this->_req_data['organization_zip']) |
|
| 565 | - ? sanitize_text_field($this->_req_data['organization_zip']) |
|
| 566 | - : EE_Registry::instance()->CFG->organization->zip; |
|
| 567 | - EE_Registry::instance()->CFG->organization->email = isset($this->_req_data['organization_email']) |
|
| 568 | - ? sanitize_email($this->_req_data['organization_email']) |
|
| 569 | - : EE_Registry::instance()->CFG->organization->email; |
|
| 570 | - EE_Registry::instance()->CFG->organization->vat = isset($this->_req_data['organization_vat']) |
|
| 571 | - ? sanitize_text_field($this->_req_data['organization_vat']) |
|
| 572 | - : EE_Registry::instance()->CFG->organization->vat; |
|
| 573 | - EE_Registry::instance()->CFG->organization->phone = isset($this->_req_data['organization_phone']) |
|
| 574 | - ? sanitize_text_field($this->_req_data['organization_phone']) |
|
| 575 | - : EE_Registry::instance()->CFG->organization->phone; |
|
| 576 | - EE_Registry::instance()->CFG->organization->logo_url = isset($this->_req_data['organization_logo_url']) |
|
| 577 | - ? esc_url_raw($this->_req_data['organization_logo_url']) |
|
| 578 | - : EE_Registry::instance()->CFG->organization->logo_url; |
|
| 579 | - EE_Registry::instance()->CFG->organization->facebook = isset($this->_req_data['organization_facebook']) |
|
| 580 | - ? esc_url_raw($this->_req_data['organization_facebook']) |
|
| 581 | - : EE_Registry::instance()->CFG->organization->facebook; |
|
| 582 | - EE_Registry::instance()->CFG->organization->twitter = isset($this->_req_data['organization_twitter']) |
|
| 583 | - ? esc_url_raw($this->_req_data['organization_twitter']) |
|
| 584 | - : EE_Registry::instance()->CFG->organization->twitter; |
|
| 585 | - EE_Registry::instance()->CFG->organization->linkedin = isset($this->_req_data['organization_linkedin']) |
|
| 586 | - ? esc_url_raw($this->_req_data['organization_linkedin']) |
|
| 587 | - : EE_Registry::instance()->CFG->organization->linkedin; |
|
| 588 | - EE_Registry::instance()->CFG->organization->pinterest = isset($this->_req_data['organization_pinterest']) |
|
| 589 | - ? esc_url_raw($this->_req_data['organization_pinterest']) |
|
| 590 | - : EE_Registry::instance()->CFG->organization->pinterest; |
|
| 591 | - EE_Registry::instance()->CFG->organization->google = isset($this->_req_data['organization_google']) |
|
| 592 | - ? esc_url_raw($this->_req_data['organization_google']) |
|
| 593 | - : EE_Registry::instance()->CFG->organization->google; |
|
| 594 | - EE_Registry::instance()->CFG->organization->instagram = isset($this->_req_data['organization_instagram']) |
|
| 595 | - ? esc_url_raw($this->_req_data['organization_instagram']) |
|
| 596 | - : EE_Registry::instance()->CFG->organization->instagram; |
|
| 597 | - EE_Registry::instance()->CFG->core->ee_ueip_optin = isset($this->_req_data['ueip_optin']) |
|
| 598 | - && ! empty($this->_req_data['ueip_optin']) |
|
| 599 | - ? $this->_req_data['ueip_optin'] |
|
| 600 | - : EE_Registry::instance()->CFG->core->ee_ueip_optin; |
|
| 601 | - |
|
| 602 | - EE_Registry::instance()->CFG->currency = new EE_Currency_Config( |
|
| 603 | - EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 604 | - ); |
|
| 605 | - |
|
| 606 | - EE_Registry::instance()->CFG = apply_filters( |
|
| 607 | - 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
| 608 | - EE_Registry::instance()->CFG |
|
| 609 | - ); |
|
| 610 | - |
|
| 611 | - $what = 'Your Organization Settings'; |
|
| 612 | - $success = $this->_update_espresso_configuration( |
|
| 613 | - $what, |
|
| 614 | - EE_Registry::instance()->CFG, |
|
| 615 | - __FILE__, |
|
| 616 | - __FUNCTION__, |
|
| 617 | - __LINE__ |
|
| 618 | - ); |
|
| 619 | - |
|
| 620 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default')); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - |
|
| 625 | - /************* Admin Options *************/ |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * _admin_option_settings |
|
| 630 | - * |
|
| 631 | - * @throws \EE_Error |
|
| 632 | - * @throws \LogicException |
|
| 633 | - */ |
|
| 634 | - protected function _admin_option_settings() |
|
| 635 | - { |
|
| 636 | - $this->_template_args['admin_page_content'] = ''; |
|
| 637 | - try { |
|
| 638 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 639 | - // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
| 640 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 641 | - // also need to account for the do_action that was in the old template |
|
| 642 | - $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
| 643 | - $this->_template_args['admin_page_content'] = $admin_options_settings_form->display(); |
|
| 644 | - } catch (Exception $e) { |
|
| 645 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 646 | - } |
|
| 647 | - $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
| 648 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 649 | - $this->display_admin_page_with_sidebar(); |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * _update_admin_option_settings |
|
| 655 | - * |
|
| 656 | - * @throws \EE_Error |
|
| 657 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 658 | - * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException |
|
| 659 | - * @throws \InvalidArgumentException |
|
| 660 | - * @throws \LogicException |
|
| 661 | - */ |
|
| 662 | - protected function _update_admin_option_settings() |
|
| 663 | - { |
|
| 664 | - try { |
|
| 665 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 666 | - $admin_options_settings_form->process($this->_req_data[$admin_options_settings_form->slug()]); |
|
| 667 | - EE_Registry::instance()->CFG->admin = apply_filters( |
|
| 668 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
| 669 | - EE_Registry::instance()->CFG->admin |
|
| 670 | - ); |
|
| 671 | - } catch (Exception $e) { |
|
| 672 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 673 | - } |
|
| 674 | - $this->_redirect_after_action( |
|
| 675 | - apply_filters( |
|
| 676 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
| 677 | - $this->_update_espresso_configuration( |
|
| 678 | - 'Admin Options', |
|
| 679 | - EE_Registry::instance()->CFG->admin, |
|
| 680 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 681 | - ) |
|
| 682 | - ), |
|
| 683 | - 'Admin Options', |
|
| 684 | - 'updated', |
|
| 685 | - array('action' => 'admin_option_settings') |
|
| 686 | - ); |
|
| 687 | - |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /************* Countries *************/ |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * Output Country Settings view. |
|
| 696 | - * @throws DomainException |
|
| 697 | - * @throws EE_Error |
|
| 698 | - */ |
|
| 699 | - protected function _country_settings() |
|
| 700 | - { |
|
| 701 | - $CNT_ISO = isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 702 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 703 | - : 'US'; |
|
| 704 | - $CNT_ISO = isset($this->_req_data['country']) |
|
| 705 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 706 | - : $CNT_ISO; |
|
| 707 | - |
|
| 708 | - //load field generator helper |
|
| 709 | - |
|
| 710 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 711 | - |
|
| 712 | - $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
| 713 | - EE_Question::new_instance(array( |
|
| 714 | - 'QST_ID' => 0, |
|
| 715 | - 'QST_display_text' => __('Select Country', 'event_espresso'), |
|
| 716 | - 'QST_system' => 'admin-country', |
|
| 717 | - )), |
|
| 718 | - EE_Answer::new_instance(array( |
|
| 719 | - 'ANS_ID' => 0, |
|
| 720 | - 'ANS_value' => $CNT_ISO, |
|
| 721 | - )), |
|
| 722 | - array( |
|
| 723 | - 'input_id' => 'country', |
|
| 724 | - 'input_name' => 'country', |
|
| 725 | - 'input_prefix' => '', |
|
| 726 | - 'append_qstn_id' => false, |
|
| 727 | - ) |
|
| 728 | - ); |
|
| 729 | - |
|
| 730 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 731 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 732 | - $this->_template_args['country_details_settings'] = $this->display_country_settings(); |
|
| 733 | - $this->_template_args['country_states_settings'] = $this->display_country_states(); |
|
| 734 | - |
|
| 735 | - $this->_set_add_edit_form_tags('update_country_settings'); |
|
| 736 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 737 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 738 | - GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
| 739 | - $this->_template_args, |
|
| 740 | - true |
|
| 741 | - ); |
|
| 742 | - $this->display_admin_page_with_no_sidebar(); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * display_country_settings |
|
| 748 | - * |
|
| 749 | - * @access public |
|
| 750 | - * @param string $CNT_ISO |
|
| 751 | - * @return mixed string | array |
|
| 752 | - * @throws DomainException |
|
| 753 | - */ |
|
| 754 | - public function display_country_settings($CNT_ISO = '') |
|
| 755 | - { |
|
| 756 | - |
|
| 757 | - $CNT_ISO = isset($this->_req_data['country']) |
|
| 758 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 759 | - : $CNT_ISO; |
|
| 760 | - if (! $CNT_ISO) { |
|
| 761 | - return ''; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - // for ajax |
|
| 765 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 766 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 767 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 768 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 769 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 770 | - |
|
| 771 | - $country_input_types = array( |
|
| 772 | - 'CNT_active' => array( |
|
| 773 | - 'type' => 'RADIO_BTN', |
|
| 774 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 775 | - 'class' => '', |
|
| 776 | - 'options' => $this->_yes_no_values, |
|
| 777 | - 'use_desc_4_label' => true, |
|
| 778 | - ), |
|
| 779 | - 'CNT_ISO' => array( |
|
| 780 | - 'type' => 'TEXT', |
|
| 781 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 782 | - 'class' => 'small-text', |
|
| 783 | - ), |
|
| 784 | - 'CNT_ISO3' => array( |
|
| 785 | - 'type' => 'TEXT', |
|
| 786 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 787 | - 'class' => 'small-text', |
|
| 788 | - ), |
|
| 789 | - 'RGN_ID' => array( |
|
| 790 | - 'type' => 'TEXT', |
|
| 791 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 792 | - 'class' => 'small-text', |
|
| 793 | - ), |
|
| 794 | - 'CNT_name' => array( |
|
| 795 | - 'type' => 'TEXT', |
|
| 796 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 797 | - 'class' => 'regular-text', |
|
| 798 | - ), |
|
| 799 | - 'CNT_cur_code' => array( |
|
| 800 | - 'type' => 'TEXT', |
|
| 801 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 802 | - 'class' => 'small-text', |
|
| 803 | - ), |
|
| 804 | - 'CNT_cur_single' => array( |
|
| 805 | - 'type' => 'TEXT', |
|
| 806 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 807 | - 'class' => 'medium-text', |
|
| 808 | - ), |
|
| 809 | - 'CNT_cur_plural' => array( |
|
| 810 | - 'type' => 'TEXT', |
|
| 811 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 812 | - 'class' => 'medium-text', |
|
| 813 | - ), |
|
| 814 | - 'CNT_cur_sign' => array( |
|
| 815 | - 'type' => 'TEXT', |
|
| 816 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 817 | - 'class' => 'small-text', |
|
| 818 | - 'htmlentities' => false, |
|
| 819 | - ), |
|
| 820 | - 'CNT_cur_sign_b4' => array( |
|
| 821 | - 'type' => 'RADIO_BTN', |
|
| 822 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 823 | - 'class' => '', |
|
| 824 | - 'options' => $this->_yes_no_values, |
|
| 825 | - 'use_desc_4_label' => true, |
|
| 826 | - ), |
|
| 827 | - 'CNT_cur_dec_plc' => array( |
|
| 828 | - 'type' => 'RADIO_BTN', |
|
| 829 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 830 | - 'class' => '', |
|
| 831 | - 'options' => array( |
|
| 832 | - array('id' => 0, 'text' => ''), |
|
| 833 | - array('id' => 1, 'text' => ''), |
|
| 834 | - array('id' => 2, 'text' => ''), |
|
| 835 | - array('id' => 3, 'text' => ''), |
|
| 836 | - ), |
|
| 837 | - ), |
|
| 838 | - 'CNT_cur_dec_mrk' => array( |
|
| 839 | - 'type' => 'RADIO_BTN', |
|
| 840 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 841 | - 'class' => '', |
|
| 842 | - 'options' => array( |
|
| 843 | - array( |
|
| 844 | - 'id' => ',', |
|
| 845 | - 'text' => __(', (comma)', 'event_espresso'), |
|
| 846 | - ), |
|
| 847 | - array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')), |
|
| 848 | - ), |
|
| 849 | - 'use_desc_4_label' => true, |
|
| 850 | - ), |
|
| 851 | - 'CNT_cur_thsnds' => array( |
|
| 852 | - 'type' => 'RADIO_BTN', |
|
| 853 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 854 | - 'class' => '', |
|
| 855 | - 'options' => array( |
|
| 856 | - array( |
|
| 857 | - 'id' => ',', |
|
| 858 | - 'text' => __(', (comma)', 'event_espresso'), |
|
| 859 | - ), |
|
| 860 | - array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')), |
|
| 861 | - ), |
|
| 862 | - 'use_desc_4_label' => true, |
|
| 863 | - ), |
|
| 864 | - 'CNT_tel_code' => array( |
|
| 865 | - 'type' => 'TEXT', |
|
| 866 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 867 | - 'class' => 'small-text', |
|
| 868 | - ), |
|
| 869 | - 'CNT_is_EU' => array( |
|
| 870 | - 'type' => 'RADIO_BTN', |
|
| 871 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 872 | - 'class' => '', |
|
| 873 | - 'options' => $this->_yes_no_values, |
|
| 874 | - 'use_desc_4_label' => true, |
|
| 875 | - ), |
|
| 876 | - ); |
|
| 877 | - $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 878 | - $country, |
|
| 879 | - $country_input_types |
|
| 880 | - ); |
|
| 881 | - $country_details_settings = EEH_Template::display_template( |
|
| 882 | - GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
| 883 | - $this->_template_args, |
|
| 884 | - true |
|
| 885 | - ); |
|
| 886 | - |
|
| 887 | - if (defined('DOING_AJAX')) { |
|
| 888 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 889 | - echo wp_json_encode(array( |
|
| 890 | - 'return_data' => $country_details_settings, |
|
| 891 | - 'success' => $notices['success'], |
|
| 892 | - 'errors' => $notices['errors'], |
|
| 893 | - )); |
|
| 894 | - die(); |
|
| 895 | - } else { |
|
| 896 | - return $country_details_settings; |
|
| 897 | - } |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - |
|
| 901 | - /** |
|
| 902 | - * display_country_states |
|
| 903 | - * |
|
| 904 | - * @access public |
|
| 905 | - * @param string $CNT_ISO |
|
| 906 | - * @return string |
|
| 907 | - * @throws DomainException |
|
| 908 | - */ |
|
| 909 | - public function display_country_states($CNT_ISO = '') |
|
| 910 | - { |
|
| 911 | - |
|
| 912 | - $CNT_ISO = isset($this->_req_data['country']) ? sanitize_text_field($this->_req_data['country']) : $CNT_ISO; |
|
| 913 | - |
|
| 914 | - if (! $CNT_ISO) { |
|
| 915 | - return ''; |
|
| 916 | - } |
|
| 917 | - // for ajax |
|
| 918 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 919 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 920 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2); |
|
| 921 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2); |
|
| 922 | - $states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO)); |
|
| 923 | - |
|
| 924 | - if ($states) { |
|
| 925 | - foreach ($states as $STA_ID => $state) { |
|
| 926 | - if ($state instanceof EE_State) { |
|
| 927 | - //STA_abbrev STA_name STA_active |
|
| 928 | - $state_input_types = array( |
|
| 929 | - 'STA_abbrev' => array( |
|
| 930 | - 'type' => 'TEXT', |
|
| 931 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 932 | - 'class' => 'mid-text', |
|
| 933 | - ), |
|
| 934 | - 'STA_name' => array( |
|
| 935 | - 'type' => 'TEXT', |
|
| 936 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 937 | - 'class' => 'regular-text', |
|
| 938 | - ), |
|
| 939 | - 'STA_active' => array( |
|
| 940 | - 'type' => 'RADIO_BTN', |
|
| 941 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 942 | - 'options' => $this->_yes_no_values, |
|
| 943 | - 'use_desc_4_label' => true, |
|
| 944 | - ), |
|
| 945 | - ); |
|
| 946 | - $this->_template_args['states'][$STA_ID]['inputs'] = |
|
| 947 | - EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 948 | - $state, |
|
| 949 | - $state_input_types |
|
| 950 | - ); |
|
| 951 | - $query_args = array( |
|
| 952 | - 'action' => 'delete_state', |
|
| 953 | - 'STA_ID' => $STA_ID, |
|
| 954 | - 'CNT_ISO' => $CNT_ISO, |
|
| 955 | - 'STA_abbrev' => $state->abbrev(), |
|
| 956 | - ); |
|
| 957 | - $this->_template_args['states'][$STA_ID]['delete_state_url'] = |
|
| 958 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 959 | - $query_args, |
|
| 960 | - GEN_SET_ADMIN_URL |
|
| 961 | - ); |
|
| 962 | - } |
|
| 963 | - } |
|
| 964 | - } else { |
|
| 965 | - $this->_template_args['states'] = false; |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 969 | - array('action' => 'add_new_state'), |
|
| 970 | - GEN_SET_ADMIN_URL |
|
| 971 | - ); |
|
| 972 | - |
|
| 973 | - $state_details_settings = EEH_Template::display_template( |
|
| 974 | - GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
| 975 | - $this->_template_args, |
|
| 976 | - true |
|
| 977 | - ); |
|
| 978 | - |
|
| 979 | - if (defined('DOING_AJAX')) { |
|
| 980 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 981 | - echo wp_json_encode(array( |
|
| 982 | - 'return_data' => $state_details_settings, |
|
| 983 | - 'success' => $notices['success'], |
|
| 984 | - 'errors' => $notices['errors'], |
|
| 985 | - )); |
|
| 986 | - die(); |
|
| 987 | - } else { |
|
| 988 | - return $state_details_settings; |
|
| 989 | - } |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - |
|
| 993 | - /** |
|
| 994 | - * add_new_state |
|
| 995 | - * |
|
| 996 | - * @access public |
|
| 997 | - * @return void |
|
| 998 | - * @throws EE_Error |
|
| 999 | - */ |
|
| 1000 | - public function add_new_state() |
|
| 1001 | - { |
|
| 1002 | - |
|
| 1003 | - $success = true; |
|
| 1004 | - |
|
| 1005 | - $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
| 1006 | - ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
| 1007 | - : false; |
|
| 1008 | - if (! $CNT_ISO) { |
|
| 1009 | - EE_Error::add_error( |
|
| 1010 | - __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 1011 | - __FILE__, |
|
| 1012 | - __FUNCTION__, |
|
| 1013 | - __LINE__ |
|
| 1014 | - ); |
|
| 1015 | - $success = false; |
|
| 1016 | - } |
|
| 1017 | - $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
| 1018 | - ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
| 1019 | - : false; |
|
| 1020 | - if (! $STA_abbrev) { |
|
| 1021 | - EE_Error::add_error( |
|
| 1022 | - __('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
| 1023 | - __FILE__, |
|
| 1024 | - __FUNCTION__, |
|
| 1025 | - __LINE__ |
|
| 1026 | - ); |
|
| 1027 | - $success = false; |
|
| 1028 | - } |
|
| 1029 | - $STA_name = isset($this->_req_data['STA_name']) |
|
| 1030 | - ? sanitize_text_field($this->_req_data['STA_name']) |
|
| 1031 | - : false; |
|
| 1032 | - if (! $STA_name) { |
|
| 1033 | - EE_Error::add_error( |
|
| 1034 | - __('No State name or an invalid State name was received.', 'event_espresso'), |
|
| 1035 | - __FILE__, |
|
| 1036 | - __FUNCTION__, |
|
| 1037 | - __LINE__ |
|
| 1038 | - ); |
|
| 1039 | - $success = false; |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - if ($success) { |
|
| 1043 | - $cols_n_values = array( |
|
| 1044 | - 'CNT_ISO' => $CNT_ISO, |
|
| 1045 | - 'STA_abbrev' => $STA_abbrev, |
|
| 1046 | - 'STA_name' => $STA_name, |
|
| 1047 | - 'STA_active' => true, |
|
| 1048 | - ); |
|
| 1049 | - $success = EEM_State::instance()->insert($cols_n_values); |
|
| 1050 | - EE_Error::add_success(__('The State was added successfully.', 'event_espresso')); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - if (defined('DOING_AJAX')) { |
|
| 1054 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 1055 | - echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO))); |
|
| 1056 | - die(); |
|
| 1057 | - } else { |
|
| 1058 | - $this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings')); |
|
| 1059 | - } |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - |
|
| 1063 | - /** |
|
| 1064 | - * delete_state |
|
| 1065 | - * |
|
| 1066 | - * @access public |
|
| 1067 | - * @return boolean |
|
| 1068 | - */ |
|
| 1069 | - public function delete_state() |
|
| 1070 | - { |
|
| 1071 | - $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
| 1072 | - ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
| 1073 | - : false; |
|
| 1074 | - $STA_ID = isset($this->_req_data['STA_ID']) |
|
| 1075 | - ? sanitize_text_field($this->_req_data['STA_ID']) |
|
| 1076 | - : false; |
|
| 1077 | - $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
| 1078 | - ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
| 1079 | - : false; |
|
| 1080 | - if (! $STA_ID) { |
|
| 1081 | - EE_Error::add_error( |
|
| 1082 | - __('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
| 1083 | - __FILE__, |
|
| 1084 | - __FUNCTION__, |
|
| 1085 | - __LINE__ |
|
| 1086 | - ); |
|
| 1087 | - return false; |
|
| 1088 | - } |
|
| 1089 | - |
|
| 1090 | - $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
| 1091 | - if ($success !== false) { |
|
| 1092 | - do_action( |
|
| 1093 | - 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 1094 | - $CNT_ISO, |
|
| 1095 | - $STA_ID, |
|
| 1096 | - array('STA_abbrev' => $STA_abbrev) |
|
| 1097 | - ); |
|
| 1098 | - EE_Error::add_success(__('The State was deleted successfully.', 'event_espresso')); |
|
| 1099 | - } |
|
| 1100 | - if (defined('DOING_AJAX')) { |
|
| 1101 | - $notices = EE_Error::get_notices(false, false); |
|
| 1102 | - $notices['return_data'] = true; |
|
| 1103 | - echo wp_json_encode($notices); |
|
| 1104 | - die(); |
|
| 1105 | - } else { |
|
| 1106 | - $this->_redirect_after_action( |
|
| 1107 | - $success, |
|
| 1108 | - 'State', |
|
| 1109 | - 'deleted', |
|
| 1110 | - array('action' => 'country_settings') |
|
| 1111 | - ); |
|
| 1112 | - } |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - |
|
| 1116 | - /** |
|
| 1117 | - * _update_country_settings |
|
| 1118 | - * |
|
| 1119 | - * @access protected |
|
| 1120 | - * @return void |
|
| 1121 | - * @throws EE_Error |
|
| 1122 | - */ |
|
| 1123 | - protected function _update_country_settings() |
|
| 1124 | - { |
|
| 1125 | - // grab the country ISO code |
|
| 1126 | - $CNT_ISO = isset($this->_req_data['country']) |
|
| 1127 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 1128 | - : false; |
|
| 1129 | - if (! $CNT_ISO) { |
|
| 1130 | - EE_Error::add_error( |
|
| 1131 | - __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 1132 | - __FILE__, |
|
| 1133 | - __FUNCTION__, |
|
| 1134 | - __LINE__ |
|
| 1135 | - ); |
|
| 1136 | - |
|
| 1137 | - return; |
|
| 1138 | - } |
|
| 1139 | - $cols_n_values = array(); |
|
| 1140 | - $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3']) |
|
| 1141 | - ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'])) |
|
| 1142 | - : false; |
|
| 1143 | - $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) |
|
| 1144 | - ? absint($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) |
|
| 1145 | - : null; |
|
| 1146 | - $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) |
|
| 1147 | - ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) |
|
| 1148 | - : null; |
|
| 1149 | - $cols_n_values['CNT_cur_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code']) |
|
| 1150 | - ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])) |
|
| 1151 | - : 'USD'; |
|
| 1152 | - $cols_n_values['CNT_cur_single'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single']) |
|
| 1153 | - ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single']) |
|
| 1154 | - : 'dollar'; |
|
| 1155 | - $cols_n_values['CNT_cur_plural'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural']) |
|
| 1156 | - ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural']) |
|
| 1157 | - : 'dollars'; |
|
| 1158 | - $cols_n_values['CNT_cur_sign'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign']) |
|
| 1159 | - ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign']) |
|
| 1160 | - : '$'; |
|
| 1161 | - $cols_n_values['CNT_cur_sign_b4'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4']) |
|
| 1162 | - ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4']) |
|
| 1163 | - : true; |
|
| 1164 | - $cols_n_values['CNT_cur_dec_plc'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc']) |
|
| 1165 | - ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc']) |
|
| 1166 | - : 2; |
|
| 1167 | - $cols_n_values['CNT_cur_dec_mrk'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk']) |
|
| 1168 | - ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk']) |
|
| 1169 | - : '.'; |
|
| 1170 | - $cols_n_values['CNT_cur_thsnds'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds']) |
|
| 1171 | - ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds']) |
|
| 1172 | - : ','; |
|
| 1173 | - $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) |
|
| 1174 | - ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) |
|
| 1175 | - : null; |
|
| 1176 | - $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) |
|
| 1177 | - ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) |
|
| 1178 | - : false; |
|
| 1179 | - $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) |
|
| 1180 | - ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) |
|
| 1181 | - : false; |
|
| 1182 | - // allow filtering of country data |
|
| 1183 | - $cols_n_values = apply_filters( |
|
| 1184 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
| 1185 | - $cols_n_values |
|
| 1186 | - ); |
|
| 1187 | - |
|
| 1188 | - // where values |
|
| 1189 | - $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO)); |
|
| 1190 | - // run the update |
|
| 1191 | - $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1192 | - |
|
| 1193 | - if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) { |
|
| 1194 | - // allow filtering of states data |
|
| 1195 | - $states = apply_filters( |
|
| 1196 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
| 1197 | - $this->_req_data['states'] |
|
| 1198 | - ); |
|
| 1199 | - |
|
| 1200 | - // loop thru state data ( looks like : states[75][STA_name] ) |
|
| 1201 | - foreach ($states as $STA_ID => $state) { |
|
| 1202 | - $cols_n_values = array( |
|
| 1203 | - 'CNT_ISO' => $CNT_ISO, |
|
| 1204 | - 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
| 1205 | - 'STA_name' => sanitize_text_field($state['STA_name']), |
|
| 1206 | - 'STA_active' => (bool)absint($state['STA_active']), |
|
| 1207 | - ); |
|
| 1208 | - // where values |
|
| 1209 | - $where_cols_n_values = array(array('STA_ID' => $STA_ID)); |
|
| 1210 | - // run the update |
|
| 1211 | - $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1212 | - if ($success !== false) { |
|
| 1213 | - do_action( |
|
| 1214 | - 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 1215 | - $CNT_ISO, |
|
| 1216 | - $STA_ID, |
|
| 1217 | - $cols_n_values |
|
| 1218 | - ); |
|
| 1219 | - } |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
| 1223 | - if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 1224 | - && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 1225 | - ) { |
|
| 1226 | - EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
| 1227 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - if ($success !== false) { |
|
| 1231 | - EE_Error::add_success( |
|
| 1232 | - esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
| 1233 | - ); |
|
| 1234 | - } |
|
| 1235 | - $this->_redirect_after_action( |
|
| 1236 | - $success, |
|
| 1237 | - '', |
|
| 1238 | - '', |
|
| 1239 | - array('action' => 'country_settings', 'country' => $CNT_ISO), |
|
| 1240 | - true |
|
| 1241 | - ); |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - |
|
| 1245 | - /** |
|
| 1246 | - * form_form_field_label_wrap |
|
| 1247 | - * |
|
| 1248 | - * @access public |
|
| 1249 | - * @param string $label |
|
| 1250 | - * @return string |
|
| 1251 | - */ |
|
| 1252 | - public function country_form_field_label_wrap($label, $required_text) |
|
| 1253 | - { |
|
| 1254 | - return ' |
|
| 20 | + /** |
|
| 21 | + * _question_group |
|
| 22 | + * holds the specific question group object for the question group details screen |
|
| 23 | + * |
|
| 24 | + * @var object |
|
| 25 | + */ |
|
| 26 | + protected $_question_group; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Initialize basic properties. |
|
| 31 | + */ |
|
| 32 | + protected function _init_page_props() |
|
| 33 | + { |
|
| 34 | + $this->page_slug = GEN_SET_PG_SLUG; |
|
| 35 | + $this->page_label = GEN_SET_LABEL; |
|
| 36 | + $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
| 37 | + $this->_admin_base_path = GEN_SET_ADMIN; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Set ajax hooks |
|
| 43 | + */ |
|
| 44 | + protected function _ajax_hooks() |
|
| 45 | + { |
|
| 46 | + add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings')); |
|
| 47 | + add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states')); |
|
| 48 | + add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3); |
|
| 49 | + add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state')); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * More page properties initialization. |
|
| 55 | + */ |
|
| 56 | + protected function _define_page_props() |
|
| 57 | + { |
|
| 58 | + $this->_admin_page_title = GEN_SET_LABEL; |
|
| 59 | + $this->_labels = array( |
|
| 60 | + 'publishbox' => __('Update Settings', 'event_espresso'), |
|
| 61 | + ); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Set page routes property. |
|
| 67 | + */ |
|
| 68 | + protected function _set_page_routes() |
|
| 69 | + { |
|
| 70 | + $this->_page_routes = array( |
|
| 71 | + |
|
| 72 | + 'critical_pages' => array( |
|
| 73 | + 'func' => '_espresso_page_settings', |
|
| 74 | + 'capability' => 'manage_options', |
|
| 75 | + ), |
|
| 76 | + 'update_espresso_page_settings' => array( |
|
| 77 | + 'func' => '_update_espresso_page_settings', |
|
| 78 | + 'capability' => 'manage_options', |
|
| 79 | + 'noheader' => true, |
|
| 80 | + ), |
|
| 81 | + 'default' => array( |
|
| 82 | + 'func' => '_your_organization_settings', |
|
| 83 | + 'capability' => 'manage_options', |
|
| 84 | + ), |
|
| 85 | + |
|
| 86 | + 'update_your_organization_settings' => array( |
|
| 87 | + 'func' => '_update_your_organization_settings', |
|
| 88 | + 'capability' => 'manage_options', |
|
| 89 | + 'noheader' => true, |
|
| 90 | + ), |
|
| 91 | + |
|
| 92 | + 'admin_option_settings' => array( |
|
| 93 | + 'func' => '_admin_option_settings', |
|
| 94 | + 'capability' => 'manage_options', |
|
| 95 | + ), |
|
| 96 | + |
|
| 97 | + 'update_admin_option_settings' => array( |
|
| 98 | + 'func' => '_update_admin_option_settings', |
|
| 99 | + 'capability' => 'manage_options', |
|
| 100 | + 'noheader' => true, |
|
| 101 | + ), |
|
| 102 | + |
|
| 103 | + 'country_settings' => array( |
|
| 104 | + 'func' => '_country_settings', |
|
| 105 | + 'capability' => 'manage_options', |
|
| 106 | + ), |
|
| 107 | + |
|
| 108 | + 'update_country_settings' => array( |
|
| 109 | + 'func' => '_update_country_settings', |
|
| 110 | + 'capability' => 'manage_options', |
|
| 111 | + 'noheader' => true, |
|
| 112 | + ), |
|
| 113 | + |
|
| 114 | + 'display_country_settings' => array( |
|
| 115 | + 'func' => 'display_country_settings', |
|
| 116 | + 'capability' => 'manage_options', |
|
| 117 | + 'noheader' => true, |
|
| 118 | + ), |
|
| 119 | + |
|
| 120 | + 'add_new_state' => array( |
|
| 121 | + 'func' => 'add_new_state', |
|
| 122 | + 'capability' => 'manage_options', |
|
| 123 | + 'noheader' => true, |
|
| 124 | + ), |
|
| 125 | + |
|
| 126 | + 'delete_state' => array( |
|
| 127 | + 'func' => 'delete_state', |
|
| 128 | + 'capability' => 'manage_options', |
|
| 129 | + 'noheader' => true, |
|
| 130 | + ), |
|
| 131 | + ); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Set page configuration property |
|
| 137 | + */ |
|
| 138 | + protected function _set_page_config() |
|
| 139 | + { |
|
| 140 | + $this->_page_config = array( |
|
| 141 | + 'critical_pages' => array( |
|
| 142 | + 'nav' => array( |
|
| 143 | + 'label' => __('Critical Pages', 'event_espresso'), |
|
| 144 | + 'order' => 50, |
|
| 145 | + ), |
|
| 146 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 147 | + 'help_tabs' => array( |
|
| 148 | + 'general_settings_critical_pages_help_tab' => array( |
|
| 149 | + 'title' => __('Critical Pages', 'event_espresso'), |
|
| 150 | + 'filename' => 'general_settings_critical_pages', |
|
| 151 | + ), |
|
| 152 | + ), |
|
| 153 | + 'help_tour' => array('Critical_Pages_Help_Tour'), |
|
| 154 | + 'require_nonce' => false, |
|
| 155 | + ), |
|
| 156 | + 'default' => array( |
|
| 157 | + 'nav' => array( |
|
| 158 | + 'label' => __('Your Organization', 'event_espresso'), |
|
| 159 | + 'order' => 20, |
|
| 160 | + ), |
|
| 161 | + 'help_tabs' => array( |
|
| 162 | + 'general_settings_your_organization_help_tab' => array( |
|
| 163 | + 'title' => __('Your Organization', 'event_espresso'), |
|
| 164 | + 'filename' => 'general_settings_your_organization', |
|
| 165 | + ), |
|
| 166 | + ), |
|
| 167 | + 'help_tour' => array('Your_Organization_Help_Tour'), |
|
| 168 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 169 | + 'require_nonce' => false, |
|
| 170 | + ), |
|
| 171 | + 'admin_option_settings' => array( |
|
| 172 | + 'nav' => array( |
|
| 173 | + 'label' => __('Admin Options', 'event_espresso'), |
|
| 174 | + 'order' => 60, |
|
| 175 | + ), |
|
| 176 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 177 | + 'help_tabs' => array( |
|
| 178 | + 'general_settings_admin_options_help_tab' => array( |
|
| 179 | + 'title' => __('Admin Options', 'event_espresso'), |
|
| 180 | + 'filename' => 'general_settings_admin_options', |
|
| 181 | + ), |
|
| 182 | + ), |
|
| 183 | + 'help_tour' => array('Admin_Options_Help_Tour'), |
|
| 184 | + 'require_nonce' => false, |
|
| 185 | + ), |
|
| 186 | + 'country_settings' => array( |
|
| 187 | + 'nav' => array( |
|
| 188 | + 'label' => __('Countries', 'event_espresso'), |
|
| 189 | + 'order' => 70, |
|
| 190 | + ), |
|
| 191 | + 'help_tabs' => array( |
|
| 192 | + 'general_settings_countries_help_tab' => array( |
|
| 193 | + 'title' => __('Countries', 'event_espresso'), |
|
| 194 | + 'filename' => 'general_settings_countries', |
|
| 195 | + ), |
|
| 196 | + ), |
|
| 197 | + 'help_tour' => array('Countries_Help_Tour'), |
|
| 198 | + 'require_nonce' => false, |
|
| 199 | + ), |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + protected function _add_screen_options() |
|
| 206 | + { |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + protected function _add_feature_pointers() |
|
| 210 | + { |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
| 216 | + */ |
|
| 217 | + public function load_scripts_styles() |
|
| 218 | + { |
|
| 219 | + //styles |
|
| 220 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 221 | + //scripts |
|
| 222 | + wp_enqueue_script('ee_admin_js'); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Execute logic running on `admin_init` |
|
| 228 | + */ |
|
| 229 | + public function admin_init() |
|
| 230 | + { |
|
| 231 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = __( |
|
| 232 | + '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.', |
|
| 233 | + 'event_espresso' |
|
| 234 | + ); |
|
| 235 | + EE_Registry::$i18n_js_strings['error_occurred'] = __( |
|
| 236 | + 'An error occurred! Please refresh the page and try again.', |
|
| 237 | + 'event_espresso' |
|
| 238 | + ); |
|
| 239 | + EE_Registry::$i18n_js_strings['confirm_delete_state'] = __( |
|
| 240 | + 'Are you sure you want to delete this State / Province?', |
|
| 241 | + 'event_espresso' |
|
| 242 | + ); |
|
| 243 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 244 | + EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
| 245 | + 'admin-ajax.php?page=espresso_general_settings', |
|
| 246 | + $protocol |
|
| 247 | + ); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + public function admin_notices() |
|
| 251 | + { |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + public function admin_footer_scripts() |
|
| 255 | + { |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Enqueue scripts and styles for the default route. |
|
| 261 | + */ |
|
| 262 | + public function load_scripts_styles_default() |
|
| 263 | + { |
|
| 264 | + //styles |
|
| 265 | + wp_enqueue_style('thickbox'); |
|
| 266 | + //scripts |
|
| 267 | + wp_enqueue_script('media-upload'); |
|
| 268 | + wp_enqueue_script('thickbox'); |
|
| 269 | + wp_register_script( |
|
| 270 | + 'organization_settings', |
|
| 271 | + GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
| 272 | + array('jquery', 'media-upload', 'thickbox'), |
|
| 273 | + EVENT_ESPRESSO_VERSION, |
|
| 274 | + true |
|
| 275 | + ); |
|
| 276 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 277 | + wp_enqueue_script('organization_settings'); |
|
| 278 | + wp_enqueue_style('organization-css'); |
|
| 279 | + $confirm_image_delete = array( |
|
| 280 | + 'text' => __( |
|
| 281 | + 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
| 282 | + 'event_espresso' |
|
| 283 | + ), |
|
| 284 | + ); |
|
| 285 | + wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Enqueue scripts and styles for the country settings route. |
|
| 291 | + */ |
|
| 292 | + public function load_scripts_styles_country_settings() |
|
| 293 | + { |
|
| 294 | + //scripts |
|
| 295 | + wp_register_script( |
|
| 296 | + 'gen_settings_countries', |
|
| 297 | + GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
| 298 | + array('ee_admin_js'), |
|
| 299 | + EVENT_ESPRESSO_VERSION, |
|
| 300 | + true |
|
| 301 | + ); |
|
| 302 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 303 | + wp_enqueue_script('gen_settings_countries'); |
|
| 304 | + wp_enqueue_style('organization-css'); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /************* Espresso Pages *************/ |
|
| 309 | + /** |
|
| 310 | + * _espresso_page_settings |
|
| 311 | + * |
|
| 312 | + * @throws \EE_Error |
|
| 313 | + */ |
|
| 314 | + protected function _espresso_page_settings() |
|
| 315 | + { |
|
| 316 | + // Check to make sure all of the main pages are setup properly, |
|
| 317 | + // if not create the default pages and display an admin notice |
|
| 318 | + EEH_Activation::verify_default_pages_exist(); |
|
| 319 | + $this->_transient_garbage_collection(); |
|
| 320 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 321 | + $this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 322 | + ? EE_Registry::instance()->CFG->core->reg_page_id |
|
| 323 | + : null; |
|
| 324 | + $this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 325 | + ? get_page(EE_Registry::instance()->CFG->core->reg_page_id) |
|
| 326 | + : false; |
|
| 327 | + $this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 328 | + ? EE_Registry::instance()->CFG->core->txn_page_id |
|
| 329 | + : null; |
|
| 330 | + $this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 331 | + ? get_page(EE_Registry::instance()->CFG->core->txn_page_id) |
|
| 332 | + : false; |
|
| 333 | + $this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 334 | + ? EE_Registry::instance()->CFG->core->thank_you_page_id |
|
| 335 | + : null; |
|
| 336 | + $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 337 | + ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
| 338 | + : false; |
|
| 339 | + $this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 340 | + ? EE_Registry::instance()->CFG->core->cancel_page_id |
|
| 341 | + : null; |
|
| 342 | + $this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 343 | + ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
| 344 | + : false; |
|
| 345 | + $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
| 346 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 347 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 348 | + GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
| 349 | + $this->_template_args, |
|
| 350 | + true |
|
| 351 | + ); |
|
| 352 | + $this->display_admin_page_with_sidebar(); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Handler for updating espresso page settings. |
|
| 358 | + */ |
|
| 359 | + protected function _update_espresso_page_settings() |
|
| 360 | + { |
|
| 361 | + // capture incoming request data && set page IDs |
|
| 362 | + EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id']) |
|
| 363 | + ? absint($this->_req_data['reg_page_id']) |
|
| 364 | + : EE_Registry::instance()->CFG->core->reg_page_id; |
|
| 365 | + EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id']) |
|
| 366 | + ? absint($this->_req_data['txn_page_id']) |
|
| 367 | + : EE_Registry::instance()->CFG->core->txn_page_id; |
|
| 368 | + EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id']) |
|
| 369 | + ? absint($this->_req_data['thank_you_page_id']) |
|
| 370 | + : EE_Registry::instance()->CFG->core->thank_you_page_id; |
|
| 371 | + EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id']) |
|
| 372 | + ? absint($this->_req_data['cancel_page_id']) |
|
| 373 | + : EE_Registry::instance()->CFG->core->cancel_page_id; |
|
| 374 | + |
|
| 375 | + EE_Registry::instance()->CFG->core = apply_filters( |
|
| 376 | + 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
| 377 | + EE_Registry::instance()->CFG->core, |
|
| 378 | + $this->_req_data |
|
| 379 | + ); |
|
| 380 | + $what = __('Critical Pages & Shortcodes', 'event_espresso'); |
|
| 381 | + $this->_redirect_after_action( |
|
| 382 | + $this->_update_espresso_configuration( |
|
| 383 | + $what, |
|
| 384 | + EE_Registry::instance()->CFG->core, |
|
| 385 | + __FILE__, |
|
| 386 | + __FUNCTION__, |
|
| 387 | + __LINE__ |
|
| 388 | + ), |
|
| 389 | + $what, |
|
| 390 | + '', |
|
| 391 | + array( |
|
| 392 | + 'action' => 'critical_pages', |
|
| 393 | + ), |
|
| 394 | + true |
|
| 395 | + ); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + /************* Your Organization *************/ |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * Output for the Your Organization settings route. |
|
| 404 | + * @throws DomainException |
|
| 405 | + * @throws EE_Error |
|
| 406 | + */ |
|
| 407 | + protected function _your_organization_settings() |
|
| 408 | + { |
|
| 409 | + |
|
| 410 | + $this->_template_args['site_license_key'] = isset( |
|
| 411 | + EE_Registry::instance()->NET_CFG->core->site_license_key |
|
| 412 | + ) |
|
| 413 | + ? EE_Registry::instance()->NET_CFG->core->get_pretty('site_license_key') |
|
| 414 | + : ''; |
|
| 415 | + $this->_template_args['organization_name'] = isset(EE_Registry::instance()->CFG->organization->name) |
|
| 416 | + ? EE_Registry::instance()->CFG->organization->get_pretty('name') |
|
| 417 | + : ''; |
|
| 418 | + $this->_template_args['organization_address_1'] = isset(EE_Registry::instance()->CFG->organization->address_1) |
|
| 419 | + ? EE_Registry::instance()->CFG->organization->get_pretty('address_1') |
|
| 420 | + : ''; |
|
| 421 | + $this->_template_args['organization_address_2'] = isset(EE_Registry::instance()->CFG->organization->address_2) |
|
| 422 | + ? EE_Registry::instance()->CFG->organization->get_pretty('address_2') |
|
| 423 | + : ''; |
|
| 424 | + $this->_template_args['organization_city'] = isset(EE_Registry::instance()->CFG->organization->city) |
|
| 425 | + ? EE_Registry::instance()->CFG->organization->get_pretty('city') |
|
| 426 | + : ''; |
|
| 427 | + $this->_template_args['organization_zip'] = isset(EE_Registry::instance()->CFG->organization->zip) |
|
| 428 | + ? EE_Registry::instance()->CFG->organization->get_pretty('zip') |
|
| 429 | + : ''; |
|
| 430 | + $this->_template_args['organization_email'] = isset(EE_Registry::instance()->CFG->organization->email) |
|
| 431 | + ? EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 432 | + : ''; |
|
| 433 | + $this->_template_args['organization_phone'] = isset(EE_Registry::instance()->CFG->organization->phone) |
|
| 434 | + ? EE_Registry::instance()->CFG->organization->get_pretty('phone') |
|
| 435 | + : ''; |
|
| 436 | + $this->_template_args['organization_vat'] = isset(EE_Registry::instance()->CFG->organization->vat) |
|
| 437 | + ? EE_Registry::instance()->CFG->organization->get_pretty('vat') |
|
| 438 | + : ''; |
|
| 439 | + $this->_template_args['currency_sign'] = isset(EE_Registry::instance()->CFG->currency->sign) |
|
| 440 | + ? EE_Registry::instance()->CFG->currency->get_pretty('sign') |
|
| 441 | + : '$'; |
|
| 442 | + $this->_template_args['organization_logo_url'] = isset(EE_Registry::instance()->CFG->organization->logo_url) |
|
| 443 | + ? EE_Registry::instance()->CFG->organization->get_pretty('logo_url') |
|
| 444 | + : false; |
|
| 445 | + $this->_template_args['organization_facebook'] = isset(EE_Registry::instance()->CFG->organization->facebook) |
|
| 446 | + ? EE_Registry::instance()->CFG->organization->get_pretty('facebook') |
|
| 447 | + : ''; |
|
| 448 | + $this->_template_args['organization_twitter'] = isset(EE_Registry::instance()->CFG->organization->twitter) |
|
| 449 | + ? EE_Registry::instance()->CFG->organization->get_pretty('twitter') |
|
| 450 | + : ''; |
|
| 451 | + $this->_template_args['organization_linkedin'] = isset(EE_Registry::instance()->CFG->organization->linkedin) |
|
| 452 | + ? EE_Registry::instance()->CFG->organization->get_pretty('linkedin') |
|
| 453 | + : ''; |
|
| 454 | + $this->_template_args['organization_pinterest'] = isset(EE_Registry::instance()->CFG->organization->pinterest) |
|
| 455 | + ? EE_Registry::instance()->CFG->organization->get_pretty('pinterest') |
|
| 456 | + : ''; |
|
| 457 | + $this->_template_args['organization_google'] = isset(EE_Registry::instance()->CFG->organization->google) |
|
| 458 | + ? EE_Registry::instance()->CFG->organization->get_pretty('google') |
|
| 459 | + : ''; |
|
| 460 | + $this->_template_args['organization_instagram'] = isset(EE_Registry::instance()->CFG->organization->instagram) |
|
| 461 | + ? EE_Registry::instance()->CFG->organization->get_pretty('instagram') |
|
| 462 | + : ''; |
|
| 463 | + //UXIP settings |
|
| 464 | + $this->_template_args['ee_ueip_optin'] = isset(EE_Registry::instance()->CFG->core->ee_ueip_optin) |
|
| 465 | + ? EE_Registry::instance()->CFG->core->get_pretty('ee_ueip_optin') |
|
| 466 | + : true; |
|
| 467 | + |
|
| 468 | + $STA_ID = isset(EE_Registry::instance()->CFG->organization->STA_ID) |
|
| 469 | + ? EE_Registry::instance()->CFG->organization->STA_ID |
|
| 470 | + : 4; |
|
| 471 | + $this->_template_args['states'] = new EE_Question_Form_Input( |
|
| 472 | + EE_Question::new_instance(array( |
|
| 473 | + 'QST_ID' => 0, |
|
| 474 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 475 | + 'QST_system' => 'admin-state', |
|
| 476 | + )), |
|
| 477 | + EE_Answer::new_instance(array( |
|
| 478 | + 'ANS_ID' => 0, |
|
| 479 | + 'ANS_value' => $STA_ID, |
|
| 480 | + )), |
|
| 481 | + array( |
|
| 482 | + 'input_id' => 'organization_state', |
|
| 483 | + 'input_name' => 'organization_state', |
|
| 484 | + 'input_prefix' => '', |
|
| 485 | + 'append_qstn_id' => false, |
|
| 486 | + ) |
|
| 487 | + ); |
|
| 488 | + |
|
| 489 | + $CNT_ISO = isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 490 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 491 | + : 'US'; |
|
| 492 | + $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
| 493 | + EE_Question::new_instance(array( |
|
| 494 | + 'QST_ID' => 0, |
|
| 495 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 496 | + 'QST_system' => 'admin-country', |
|
| 497 | + )), |
|
| 498 | + EE_Answer::new_instance(array( |
|
| 499 | + 'ANS_ID' => 0, |
|
| 500 | + 'ANS_value' => $CNT_ISO, |
|
| 501 | + )), |
|
| 502 | + array( |
|
| 503 | + 'input_id' => 'organization_country', |
|
| 504 | + 'input_name' => 'organization_country', |
|
| 505 | + 'input_prefix' => '', |
|
| 506 | + 'append_qstn_id' => false, |
|
| 507 | + ) |
|
| 508 | + ); |
|
| 509 | + |
|
| 510 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 511 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 512 | + |
|
| 513 | + //PUE verification stuff |
|
| 514 | + $ver_option_key = 'puvererr_' . basename(EE_PLUGIN_BASENAME); |
|
| 515 | + $verify_fail = get_option($ver_option_key); |
|
| 516 | + $this->_template_args['site_license_key_verified'] = $verify_fail |
|
| 517 | + || ! empty($verify_fail) |
|
| 518 | + || (empty($this->_template_args['site_license_key']) |
|
| 519 | + && empty($verify_fail) |
|
| 520 | + ) |
|
| 521 | + ? '<span class="dashicons dashicons-admin-network ee-icon-color-ee-red ee-icon-size-20"></span>' |
|
| 522 | + : '<span class="dashicons dashicons-admin-network ee-icon-color-ee-green ee-icon-size-20"></span>'; |
|
| 523 | + |
|
| 524 | + $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
| 525 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 526 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 527 | + GEN_SET_TEMPLATE_PATH . 'your_organization_settings.template.php', |
|
| 528 | + $this->_template_args, |
|
| 529 | + true |
|
| 530 | + ); |
|
| 531 | + |
|
| 532 | + $this->display_admin_page_with_sidebar(); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Handler for updating organziation settings. |
|
| 538 | + */ |
|
| 539 | + protected function _update_your_organization_settings() |
|
| 540 | + { |
|
| 541 | + if (is_main_site()) { |
|
| 542 | + EE_Registry::instance()->NET_CFG->core->site_license_key = isset($this->_req_data['site_license_key']) |
|
| 543 | + ? sanitize_text_field($this->_req_data['site_license_key']) |
|
| 544 | + : EE_Registry::instance()->NET_CFG->core->site_license_key; |
|
| 545 | + } |
|
| 546 | + EE_Registry::instance()->CFG->organization->name = isset($this->_req_data['organization_name']) |
|
| 547 | + ? sanitize_text_field($this->_req_data['organization_name']) |
|
| 548 | + : EE_Registry::instance()->CFG->organization->name; |
|
| 549 | + EE_Registry::instance()->CFG->organization->address_1 = isset($this->_req_data['organization_address_1']) |
|
| 550 | + ? sanitize_text_field($this->_req_data['organization_address_1']) |
|
| 551 | + : EE_Registry::instance()->CFG->organization->address_1; |
|
| 552 | + EE_Registry::instance()->CFG->organization->address_2 = isset($this->_req_data['organization_address_2']) |
|
| 553 | + ? sanitize_text_field($this->_req_data['organization_address_2']) |
|
| 554 | + : EE_Registry::instance()->CFG->organization->address_2; |
|
| 555 | + EE_Registry::instance()->CFG->organization->city = isset($this->_req_data['organization_city']) |
|
| 556 | + ? sanitize_text_field($this->_req_data['organization_city']) |
|
| 557 | + : EE_Registry::instance()->CFG->organization->city; |
|
| 558 | + EE_Registry::instance()->CFG->organization->STA_ID = isset($this->_req_data['organization_state']) |
|
| 559 | + ? absint($this->_req_data['organization_state']) |
|
| 560 | + : EE_Registry::instance()->CFG->organization->STA_ID; |
|
| 561 | + EE_Registry::instance()->CFG->organization->CNT_ISO = isset($this->_req_data['organization_country']) |
|
| 562 | + ? sanitize_text_field($this->_req_data['organization_country']) |
|
| 563 | + : EE_Registry::instance()->CFG->organization->CNT_ISO; |
|
| 564 | + EE_Registry::instance()->CFG->organization->zip = isset($this->_req_data['organization_zip']) |
|
| 565 | + ? sanitize_text_field($this->_req_data['organization_zip']) |
|
| 566 | + : EE_Registry::instance()->CFG->organization->zip; |
|
| 567 | + EE_Registry::instance()->CFG->organization->email = isset($this->_req_data['organization_email']) |
|
| 568 | + ? sanitize_email($this->_req_data['organization_email']) |
|
| 569 | + : EE_Registry::instance()->CFG->organization->email; |
|
| 570 | + EE_Registry::instance()->CFG->organization->vat = isset($this->_req_data['organization_vat']) |
|
| 571 | + ? sanitize_text_field($this->_req_data['organization_vat']) |
|
| 572 | + : EE_Registry::instance()->CFG->organization->vat; |
|
| 573 | + EE_Registry::instance()->CFG->organization->phone = isset($this->_req_data['organization_phone']) |
|
| 574 | + ? sanitize_text_field($this->_req_data['organization_phone']) |
|
| 575 | + : EE_Registry::instance()->CFG->organization->phone; |
|
| 576 | + EE_Registry::instance()->CFG->organization->logo_url = isset($this->_req_data['organization_logo_url']) |
|
| 577 | + ? esc_url_raw($this->_req_data['organization_logo_url']) |
|
| 578 | + : EE_Registry::instance()->CFG->organization->logo_url; |
|
| 579 | + EE_Registry::instance()->CFG->organization->facebook = isset($this->_req_data['organization_facebook']) |
|
| 580 | + ? esc_url_raw($this->_req_data['organization_facebook']) |
|
| 581 | + : EE_Registry::instance()->CFG->organization->facebook; |
|
| 582 | + EE_Registry::instance()->CFG->organization->twitter = isset($this->_req_data['organization_twitter']) |
|
| 583 | + ? esc_url_raw($this->_req_data['organization_twitter']) |
|
| 584 | + : EE_Registry::instance()->CFG->organization->twitter; |
|
| 585 | + EE_Registry::instance()->CFG->organization->linkedin = isset($this->_req_data['organization_linkedin']) |
|
| 586 | + ? esc_url_raw($this->_req_data['organization_linkedin']) |
|
| 587 | + : EE_Registry::instance()->CFG->organization->linkedin; |
|
| 588 | + EE_Registry::instance()->CFG->organization->pinterest = isset($this->_req_data['organization_pinterest']) |
|
| 589 | + ? esc_url_raw($this->_req_data['organization_pinterest']) |
|
| 590 | + : EE_Registry::instance()->CFG->organization->pinterest; |
|
| 591 | + EE_Registry::instance()->CFG->organization->google = isset($this->_req_data['organization_google']) |
|
| 592 | + ? esc_url_raw($this->_req_data['organization_google']) |
|
| 593 | + : EE_Registry::instance()->CFG->organization->google; |
|
| 594 | + EE_Registry::instance()->CFG->organization->instagram = isset($this->_req_data['organization_instagram']) |
|
| 595 | + ? esc_url_raw($this->_req_data['organization_instagram']) |
|
| 596 | + : EE_Registry::instance()->CFG->organization->instagram; |
|
| 597 | + EE_Registry::instance()->CFG->core->ee_ueip_optin = isset($this->_req_data['ueip_optin']) |
|
| 598 | + && ! empty($this->_req_data['ueip_optin']) |
|
| 599 | + ? $this->_req_data['ueip_optin'] |
|
| 600 | + : EE_Registry::instance()->CFG->core->ee_ueip_optin; |
|
| 601 | + |
|
| 602 | + EE_Registry::instance()->CFG->currency = new EE_Currency_Config( |
|
| 603 | + EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 604 | + ); |
|
| 605 | + |
|
| 606 | + EE_Registry::instance()->CFG = apply_filters( |
|
| 607 | + 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
| 608 | + EE_Registry::instance()->CFG |
|
| 609 | + ); |
|
| 610 | + |
|
| 611 | + $what = 'Your Organization Settings'; |
|
| 612 | + $success = $this->_update_espresso_configuration( |
|
| 613 | + $what, |
|
| 614 | + EE_Registry::instance()->CFG, |
|
| 615 | + __FILE__, |
|
| 616 | + __FUNCTION__, |
|
| 617 | + __LINE__ |
|
| 618 | + ); |
|
| 619 | + |
|
| 620 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default')); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + |
|
| 625 | + /************* Admin Options *************/ |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * _admin_option_settings |
|
| 630 | + * |
|
| 631 | + * @throws \EE_Error |
|
| 632 | + * @throws \LogicException |
|
| 633 | + */ |
|
| 634 | + protected function _admin_option_settings() |
|
| 635 | + { |
|
| 636 | + $this->_template_args['admin_page_content'] = ''; |
|
| 637 | + try { |
|
| 638 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 639 | + // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
| 640 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 641 | + // also need to account for the do_action that was in the old template |
|
| 642 | + $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
| 643 | + $this->_template_args['admin_page_content'] = $admin_options_settings_form->display(); |
|
| 644 | + } catch (Exception $e) { |
|
| 645 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 646 | + } |
|
| 647 | + $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
| 648 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 649 | + $this->display_admin_page_with_sidebar(); |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * _update_admin_option_settings |
|
| 655 | + * |
|
| 656 | + * @throws \EE_Error |
|
| 657 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 658 | + * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException |
|
| 659 | + * @throws \InvalidArgumentException |
|
| 660 | + * @throws \LogicException |
|
| 661 | + */ |
|
| 662 | + protected function _update_admin_option_settings() |
|
| 663 | + { |
|
| 664 | + try { |
|
| 665 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
| 666 | + $admin_options_settings_form->process($this->_req_data[$admin_options_settings_form->slug()]); |
|
| 667 | + EE_Registry::instance()->CFG->admin = apply_filters( |
|
| 668 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
| 669 | + EE_Registry::instance()->CFG->admin |
|
| 670 | + ); |
|
| 671 | + } catch (Exception $e) { |
|
| 672 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 673 | + } |
|
| 674 | + $this->_redirect_after_action( |
|
| 675 | + apply_filters( |
|
| 676 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
| 677 | + $this->_update_espresso_configuration( |
|
| 678 | + 'Admin Options', |
|
| 679 | + EE_Registry::instance()->CFG->admin, |
|
| 680 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 681 | + ) |
|
| 682 | + ), |
|
| 683 | + 'Admin Options', |
|
| 684 | + 'updated', |
|
| 685 | + array('action' => 'admin_option_settings') |
|
| 686 | + ); |
|
| 687 | + |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /************* Countries *************/ |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * Output Country Settings view. |
|
| 696 | + * @throws DomainException |
|
| 697 | + * @throws EE_Error |
|
| 698 | + */ |
|
| 699 | + protected function _country_settings() |
|
| 700 | + { |
|
| 701 | + $CNT_ISO = isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 702 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 703 | + : 'US'; |
|
| 704 | + $CNT_ISO = isset($this->_req_data['country']) |
|
| 705 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 706 | + : $CNT_ISO; |
|
| 707 | + |
|
| 708 | + //load field generator helper |
|
| 709 | + |
|
| 710 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 711 | + |
|
| 712 | + $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
| 713 | + EE_Question::new_instance(array( |
|
| 714 | + 'QST_ID' => 0, |
|
| 715 | + 'QST_display_text' => __('Select Country', 'event_espresso'), |
|
| 716 | + 'QST_system' => 'admin-country', |
|
| 717 | + )), |
|
| 718 | + EE_Answer::new_instance(array( |
|
| 719 | + 'ANS_ID' => 0, |
|
| 720 | + 'ANS_value' => $CNT_ISO, |
|
| 721 | + )), |
|
| 722 | + array( |
|
| 723 | + 'input_id' => 'country', |
|
| 724 | + 'input_name' => 'country', |
|
| 725 | + 'input_prefix' => '', |
|
| 726 | + 'append_qstn_id' => false, |
|
| 727 | + ) |
|
| 728 | + ); |
|
| 729 | + |
|
| 730 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 731 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 732 | + $this->_template_args['country_details_settings'] = $this->display_country_settings(); |
|
| 733 | + $this->_template_args['country_states_settings'] = $this->display_country_states(); |
|
| 734 | + |
|
| 735 | + $this->_set_add_edit_form_tags('update_country_settings'); |
|
| 736 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 737 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 738 | + GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
| 739 | + $this->_template_args, |
|
| 740 | + true |
|
| 741 | + ); |
|
| 742 | + $this->display_admin_page_with_no_sidebar(); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * display_country_settings |
|
| 748 | + * |
|
| 749 | + * @access public |
|
| 750 | + * @param string $CNT_ISO |
|
| 751 | + * @return mixed string | array |
|
| 752 | + * @throws DomainException |
|
| 753 | + */ |
|
| 754 | + public function display_country_settings($CNT_ISO = '') |
|
| 755 | + { |
|
| 756 | + |
|
| 757 | + $CNT_ISO = isset($this->_req_data['country']) |
|
| 758 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 759 | + : $CNT_ISO; |
|
| 760 | + if (! $CNT_ISO) { |
|
| 761 | + return ''; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + // for ajax |
|
| 765 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 766 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 767 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
| 768 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
| 769 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 770 | + |
|
| 771 | + $country_input_types = array( |
|
| 772 | + 'CNT_active' => array( |
|
| 773 | + 'type' => 'RADIO_BTN', |
|
| 774 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 775 | + 'class' => '', |
|
| 776 | + 'options' => $this->_yes_no_values, |
|
| 777 | + 'use_desc_4_label' => true, |
|
| 778 | + ), |
|
| 779 | + 'CNT_ISO' => array( |
|
| 780 | + 'type' => 'TEXT', |
|
| 781 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 782 | + 'class' => 'small-text', |
|
| 783 | + ), |
|
| 784 | + 'CNT_ISO3' => array( |
|
| 785 | + 'type' => 'TEXT', |
|
| 786 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 787 | + 'class' => 'small-text', |
|
| 788 | + ), |
|
| 789 | + 'RGN_ID' => array( |
|
| 790 | + 'type' => 'TEXT', |
|
| 791 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 792 | + 'class' => 'small-text', |
|
| 793 | + ), |
|
| 794 | + 'CNT_name' => array( |
|
| 795 | + 'type' => 'TEXT', |
|
| 796 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 797 | + 'class' => 'regular-text', |
|
| 798 | + ), |
|
| 799 | + 'CNT_cur_code' => array( |
|
| 800 | + 'type' => 'TEXT', |
|
| 801 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 802 | + 'class' => 'small-text', |
|
| 803 | + ), |
|
| 804 | + 'CNT_cur_single' => array( |
|
| 805 | + 'type' => 'TEXT', |
|
| 806 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 807 | + 'class' => 'medium-text', |
|
| 808 | + ), |
|
| 809 | + 'CNT_cur_plural' => array( |
|
| 810 | + 'type' => 'TEXT', |
|
| 811 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 812 | + 'class' => 'medium-text', |
|
| 813 | + ), |
|
| 814 | + 'CNT_cur_sign' => array( |
|
| 815 | + 'type' => 'TEXT', |
|
| 816 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 817 | + 'class' => 'small-text', |
|
| 818 | + 'htmlentities' => false, |
|
| 819 | + ), |
|
| 820 | + 'CNT_cur_sign_b4' => array( |
|
| 821 | + 'type' => 'RADIO_BTN', |
|
| 822 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 823 | + 'class' => '', |
|
| 824 | + 'options' => $this->_yes_no_values, |
|
| 825 | + 'use_desc_4_label' => true, |
|
| 826 | + ), |
|
| 827 | + 'CNT_cur_dec_plc' => array( |
|
| 828 | + 'type' => 'RADIO_BTN', |
|
| 829 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 830 | + 'class' => '', |
|
| 831 | + 'options' => array( |
|
| 832 | + array('id' => 0, 'text' => ''), |
|
| 833 | + array('id' => 1, 'text' => ''), |
|
| 834 | + array('id' => 2, 'text' => ''), |
|
| 835 | + array('id' => 3, 'text' => ''), |
|
| 836 | + ), |
|
| 837 | + ), |
|
| 838 | + 'CNT_cur_dec_mrk' => array( |
|
| 839 | + 'type' => 'RADIO_BTN', |
|
| 840 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 841 | + 'class' => '', |
|
| 842 | + 'options' => array( |
|
| 843 | + array( |
|
| 844 | + 'id' => ',', |
|
| 845 | + 'text' => __(', (comma)', 'event_espresso'), |
|
| 846 | + ), |
|
| 847 | + array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')), |
|
| 848 | + ), |
|
| 849 | + 'use_desc_4_label' => true, |
|
| 850 | + ), |
|
| 851 | + 'CNT_cur_thsnds' => array( |
|
| 852 | + 'type' => 'RADIO_BTN', |
|
| 853 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 854 | + 'class' => '', |
|
| 855 | + 'options' => array( |
|
| 856 | + array( |
|
| 857 | + 'id' => ',', |
|
| 858 | + 'text' => __(', (comma)', 'event_espresso'), |
|
| 859 | + ), |
|
| 860 | + array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')), |
|
| 861 | + ), |
|
| 862 | + 'use_desc_4_label' => true, |
|
| 863 | + ), |
|
| 864 | + 'CNT_tel_code' => array( |
|
| 865 | + 'type' => 'TEXT', |
|
| 866 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 867 | + 'class' => 'small-text', |
|
| 868 | + ), |
|
| 869 | + 'CNT_is_EU' => array( |
|
| 870 | + 'type' => 'RADIO_BTN', |
|
| 871 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 872 | + 'class' => '', |
|
| 873 | + 'options' => $this->_yes_no_values, |
|
| 874 | + 'use_desc_4_label' => true, |
|
| 875 | + ), |
|
| 876 | + ); |
|
| 877 | + $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 878 | + $country, |
|
| 879 | + $country_input_types |
|
| 880 | + ); |
|
| 881 | + $country_details_settings = EEH_Template::display_template( |
|
| 882 | + GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
| 883 | + $this->_template_args, |
|
| 884 | + true |
|
| 885 | + ); |
|
| 886 | + |
|
| 887 | + if (defined('DOING_AJAX')) { |
|
| 888 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 889 | + echo wp_json_encode(array( |
|
| 890 | + 'return_data' => $country_details_settings, |
|
| 891 | + 'success' => $notices['success'], |
|
| 892 | + 'errors' => $notices['errors'], |
|
| 893 | + )); |
|
| 894 | + die(); |
|
| 895 | + } else { |
|
| 896 | + return $country_details_settings; |
|
| 897 | + } |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + |
|
| 901 | + /** |
|
| 902 | + * display_country_states |
|
| 903 | + * |
|
| 904 | + * @access public |
|
| 905 | + * @param string $CNT_ISO |
|
| 906 | + * @return string |
|
| 907 | + * @throws DomainException |
|
| 908 | + */ |
|
| 909 | + public function display_country_states($CNT_ISO = '') |
|
| 910 | + { |
|
| 911 | + |
|
| 912 | + $CNT_ISO = isset($this->_req_data['country']) ? sanitize_text_field($this->_req_data['country']) : $CNT_ISO; |
|
| 913 | + |
|
| 914 | + if (! $CNT_ISO) { |
|
| 915 | + return ''; |
|
| 916 | + } |
|
| 917 | + // for ajax |
|
| 918 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
| 919 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
| 920 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2); |
|
| 921 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2); |
|
| 922 | + $states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO)); |
|
| 923 | + |
|
| 924 | + if ($states) { |
|
| 925 | + foreach ($states as $STA_ID => $state) { |
|
| 926 | + if ($state instanceof EE_State) { |
|
| 927 | + //STA_abbrev STA_name STA_active |
|
| 928 | + $state_input_types = array( |
|
| 929 | + 'STA_abbrev' => array( |
|
| 930 | + 'type' => 'TEXT', |
|
| 931 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
| 932 | + 'class' => 'mid-text', |
|
| 933 | + ), |
|
| 934 | + 'STA_name' => array( |
|
| 935 | + 'type' => 'TEXT', |
|
| 936 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
| 937 | + 'class' => 'regular-text', |
|
| 938 | + ), |
|
| 939 | + 'STA_active' => array( |
|
| 940 | + 'type' => 'RADIO_BTN', |
|
| 941 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
| 942 | + 'options' => $this->_yes_no_values, |
|
| 943 | + 'use_desc_4_label' => true, |
|
| 944 | + ), |
|
| 945 | + ); |
|
| 946 | + $this->_template_args['states'][$STA_ID]['inputs'] = |
|
| 947 | + EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
| 948 | + $state, |
|
| 949 | + $state_input_types |
|
| 950 | + ); |
|
| 951 | + $query_args = array( |
|
| 952 | + 'action' => 'delete_state', |
|
| 953 | + 'STA_ID' => $STA_ID, |
|
| 954 | + 'CNT_ISO' => $CNT_ISO, |
|
| 955 | + 'STA_abbrev' => $state->abbrev(), |
|
| 956 | + ); |
|
| 957 | + $this->_template_args['states'][$STA_ID]['delete_state_url'] = |
|
| 958 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 959 | + $query_args, |
|
| 960 | + GEN_SET_ADMIN_URL |
|
| 961 | + ); |
|
| 962 | + } |
|
| 963 | + } |
|
| 964 | + } else { |
|
| 965 | + $this->_template_args['states'] = false; |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 969 | + array('action' => 'add_new_state'), |
|
| 970 | + GEN_SET_ADMIN_URL |
|
| 971 | + ); |
|
| 972 | + |
|
| 973 | + $state_details_settings = EEH_Template::display_template( |
|
| 974 | + GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
| 975 | + $this->_template_args, |
|
| 976 | + true |
|
| 977 | + ); |
|
| 978 | + |
|
| 979 | + if (defined('DOING_AJAX')) { |
|
| 980 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 981 | + echo wp_json_encode(array( |
|
| 982 | + 'return_data' => $state_details_settings, |
|
| 983 | + 'success' => $notices['success'], |
|
| 984 | + 'errors' => $notices['errors'], |
|
| 985 | + )); |
|
| 986 | + die(); |
|
| 987 | + } else { |
|
| 988 | + return $state_details_settings; |
|
| 989 | + } |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + |
|
| 993 | + /** |
|
| 994 | + * add_new_state |
|
| 995 | + * |
|
| 996 | + * @access public |
|
| 997 | + * @return void |
|
| 998 | + * @throws EE_Error |
|
| 999 | + */ |
|
| 1000 | + public function add_new_state() |
|
| 1001 | + { |
|
| 1002 | + |
|
| 1003 | + $success = true; |
|
| 1004 | + |
|
| 1005 | + $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
| 1006 | + ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
| 1007 | + : false; |
|
| 1008 | + if (! $CNT_ISO) { |
|
| 1009 | + EE_Error::add_error( |
|
| 1010 | + __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 1011 | + __FILE__, |
|
| 1012 | + __FUNCTION__, |
|
| 1013 | + __LINE__ |
|
| 1014 | + ); |
|
| 1015 | + $success = false; |
|
| 1016 | + } |
|
| 1017 | + $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
| 1018 | + ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
| 1019 | + : false; |
|
| 1020 | + if (! $STA_abbrev) { |
|
| 1021 | + EE_Error::add_error( |
|
| 1022 | + __('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
| 1023 | + __FILE__, |
|
| 1024 | + __FUNCTION__, |
|
| 1025 | + __LINE__ |
|
| 1026 | + ); |
|
| 1027 | + $success = false; |
|
| 1028 | + } |
|
| 1029 | + $STA_name = isset($this->_req_data['STA_name']) |
|
| 1030 | + ? sanitize_text_field($this->_req_data['STA_name']) |
|
| 1031 | + : false; |
|
| 1032 | + if (! $STA_name) { |
|
| 1033 | + EE_Error::add_error( |
|
| 1034 | + __('No State name or an invalid State name was received.', 'event_espresso'), |
|
| 1035 | + __FILE__, |
|
| 1036 | + __FUNCTION__, |
|
| 1037 | + __LINE__ |
|
| 1038 | + ); |
|
| 1039 | + $success = false; |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + if ($success) { |
|
| 1043 | + $cols_n_values = array( |
|
| 1044 | + 'CNT_ISO' => $CNT_ISO, |
|
| 1045 | + 'STA_abbrev' => $STA_abbrev, |
|
| 1046 | + 'STA_name' => $STA_name, |
|
| 1047 | + 'STA_active' => true, |
|
| 1048 | + ); |
|
| 1049 | + $success = EEM_State::instance()->insert($cols_n_values); |
|
| 1050 | + EE_Error::add_success(__('The State was added successfully.', 'event_espresso')); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + if (defined('DOING_AJAX')) { |
|
| 1054 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 1055 | + echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO))); |
|
| 1056 | + die(); |
|
| 1057 | + } else { |
|
| 1058 | + $this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings')); |
|
| 1059 | + } |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + |
|
| 1063 | + /** |
|
| 1064 | + * delete_state |
|
| 1065 | + * |
|
| 1066 | + * @access public |
|
| 1067 | + * @return boolean |
|
| 1068 | + */ |
|
| 1069 | + public function delete_state() |
|
| 1070 | + { |
|
| 1071 | + $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
| 1072 | + ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
| 1073 | + : false; |
|
| 1074 | + $STA_ID = isset($this->_req_data['STA_ID']) |
|
| 1075 | + ? sanitize_text_field($this->_req_data['STA_ID']) |
|
| 1076 | + : false; |
|
| 1077 | + $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
| 1078 | + ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
| 1079 | + : false; |
|
| 1080 | + if (! $STA_ID) { |
|
| 1081 | + EE_Error::add_error( |
|
| 1082 | + __('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
| 1083 | + __FILE__, |
|
| 1084 | + __FUNCTION__, |
|
| 1085 | + __LINE__ |
|
| 1086 | + ); |
|
| 1087 | + return false; |
|
| 1088 | + } |
|
| 1089 | + |
|
| 1090 | + $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
| 1091 | + if ($success !== false) { |
|
| 1092 | + do_action( |
|
| 1093 | + 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 1094 | + $CNT_ISO, |
|
| 1095 | + $STA_ID, |
|
| 1096 | + array('STA_abbrev' => $STA_abbrev) |
|
| 1097 | + ); |
|
| 1098 | + EE_Error::add_success(__('The State was deleted successfully.', 'event_espresso')); |
|
| 1099 | + } |
|
| 1100 | + if (defined('DOING_AJAX')) { |
|
| 1101 | + $notices = EE_Error::get_notices(false, false); |
|
| 1102 | + $notices['return_data'] = true; |
|
| 1103 | + echo wp_json_encode($notices); |
|
| 1104 | + die(); |
|
| 1105 | + } else { |
|
| 1106 | + $this->_redirect_after_action( |
|
| 1107 | + $success, |
|
| 1108 | + 'State', |
|
| 1109 | + 'deleted', |
|
| 1110 | + array('action' => 'country_settings') |
|
| 1111 | + ); |
|
| 1112 | + } |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + |
|
| 1116 | + /** |
|
| 1117 | + * _update_country_settings |
|
| 1118 | + * |
|
| 1119 | + * @access protected |
|
| 1120 | + * @return void |
|
| 1121 | + * @throws EE_Error |
|
| 1122 | + */ |
|
| 1123 | + protected function _update_country_settings() |
|
| 1124 | + { |
|
| 1125 | + // grab the country ISO code |
|
| 1126 | + $CNT_ISO = isset($this->_req_data['country']) |
|
| 1127 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
| 1128 | + : false; |
|
| 1129 | + if (! $CNT_ISO) { |
|
| 1130 | + EE_Error::add_error( |
|
| 1131 | + __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
| 1132 | + __FILE__, |
|
| 1133 | + __FUNCTION__, |
|
| 1134 | + __LINE__ |
|
| 1135 | + ); |
|
| 1136 | + |
|
| 1137 | + return; |
|
| 1138 | + } |
|
| 1139 | + $cols_n_values = array(); |
|
| 1140 | + $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3']) |
|
| 1141 | + ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'])) |
|
| 1142 | + : false; |
|
| 1143 | + $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) |
|
| 1144 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) |
|
| 1145 | + : null; |
|
| 1146 | + $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) |
|
| 1147 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) |
|
| 1148 | + : null; |
|
| 1149 | + $cols_n_values['CNT_cur_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code']) |
|
| 1150 | + ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])) |
|
| 1151 | + : 'USD'; |
|
| 1152 | + $cols_n_values['CNT_cur_single'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single']) |
|
| 1153 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single']) |
|
| 1154 | + : 'dollar'; |
|
| 1155 | + $cols_n_values['CNT_cur_plural'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural']) |
|
| 1156 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural']) |
|
| 1157 | + : 'dollars'; |
|
| 1158 | + $cols_n_values['CNT_cur_sign'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign']) |
|
| 1159 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign']) |
|
| 1160 | + : '$'; |
|
| 1161 | + $cols_n_values['CNT_cur_sign_b4'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4']) |
|
| 1162 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4']) |
|
| 1163 | + : true; |
|
| 1164 | + $cols_n_values['CNT_cur_dec_plc'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc']) |
|
| 1165 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc']) |
|
| 1166 | + : 2; |
|
| 1167 | + $cols_n_values['CNT_cur_dec_mrk'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk']) |
|
| 1168 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk']) |
|
| 1169 | + : '.'; |
|
| 1170 | + $cols_n_values['CNT_cur_thsnds'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds']) |
|
| 1171 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds']) |
|
| 1172 | + : ','; |
|
| 1173 | + $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) |
|
| 1174 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) |
|
| 1175 | + : null; |
|
| 1176 | + $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) |
|
| 1177 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) |
|
| 1178 | + : false; |
|
| 1179 | + $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) |
|
| 1180 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) |
|
| 1181 | + : false; |
|
| 1182 | + // allow filtering of country data |
|
| 1183 | + $cols_n_values = apply_filters( |
|
| 1184 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
| 1185 | + $cols_n_values |
|
| 1186 | + ); |
|
| 1187 | + |
|
| 1188 | + // where values |
|
| 1189 | + $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO)); |
|
| 1190 | + // run the update |
|
| 1191 | + $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1192 | + |
|
| 1193 | + if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) { |
|
| 1194 | + // allow filtering of states data |
|
| 1195 | + $states = apply_filters( |
|
| 1196 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
| 1197 | + $this->_req_data['states'] |
|
| 1198 | + ); |
|
| 1199 | + |
|
| 1200 | + // loop thru state data ( looks like : states[75][STA_name] ) |
|
| 1201 | + foreach ($states as $STA_ID => $state) { |
|
| 1202 | + $cols_n_values = array( |
|
| 1203 | + 'CNT_ISO' => $CNT_ISO, |
|
| 1204 | + 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
| 1205 | + 'STA_name' => sanitize_text_field($state['STA_name']), |
|
| 1206 | + 'STA_active' => (bool)absint($state['STA_active']), |
|
| 1207 | + ); |
|
| 1208 | + // where values |
|
| 1209 | + $where_cols_n_values = array(array('STA_ID' => $STA_ID)); |
|
| 1210 | + // run the update |
|
| 1211 | + $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
| 1212 | + if ($success !== false) { |
|
| 1213 | + do_action( |
|
| 1214 | + 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 1215 | + $CNT_ISO, |
|
| 1216 | + $STA_ID, |
|
| 1217 | + $cols_n_values |
|
| 1218 | + ); |
|
| 1219 | + } |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
| 1223 | + if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
| 1224 | + && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 1225 | + ) { |
|
| 1226 | + EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
| 1227 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + if ($success !== false) { |
|
| 1231 | + EE_Error::add_success( |
|
| 1232 | + esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
| 1233 | + ); |
|
| 1234 | + } |
|
| 1235 | + $this->_redirect_after_action( |
|
| 1236 | + $success, |
|
| 1237 | + '', |
|
| 1238 | + '', |
|
| 1239 | + array('action' => 'country_settings', 'country' => $CNT_ISO), |
|
| 1240 | + true |
|
| 1241 | + ); |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + |
|
| 1245 | + /** |
|
| 1246 | + * form_form_field_label_wrap |
|
| 1247 | + * |
|
| 1248 | + * @access public |
|
| 1249 | + * @param string $label |
|
| 1250 | + * @return string |
|
| 1251 | + */ |
|
| 1252 | + public function country_form_field_label_wrap($label, $required_text) |
|
| 1253 | + { |
|
| 1254 | + return ' |
|
| 1255 | 1255 | <tr> |
| 1256 | 1256 | <th> |
| 1257 | 1257 | ' . $label . ' |
| 1258 | 1258 | </th>'; |
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - |
|
| 1262 | - /** |
|
| 1263 | - * form_form_field_input__wrap |
|
| 1264 | - * |
|
| 1265 | - * @access public |
|
| 1266 | - * @param string $label |
|
| 1267 | - * @return string |
|
| 1268 | - */ |
|
| 1269 | - public function country_form_field_input__wrap($input, $label) |
|
| 1270 | - { |
|
| 1271 | - return ' |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + |
|
| 1262 | + /** |
|
| 1263 | + * form_form_field_input__wrap |
|
| 1264 | + * |
|
| 1265 | + * @access public |
|
| 1266 | + * @param string $label |
|
| 1267 | + * @return string |
|
| 1268 | + */ |
|
| 1269 | + public function country_form_field_input__wrap($input, $label) |
|
| 1270 | + { |
|
| 1271 | + return ' |
|
| 1272 | 1272 | <td class="general-settings-country-input-td"> |
| 1273 | 1273 | ' . $input . ' |
| 1274 | 1274 | </td> |
| 1275 | 1275 | </tr>'; |
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - |
|
| 1279 | - /** |
|
| 1280 | - * form_form_field_label_wrap |
|
| 1281 | - * |
|
| 1282 | - * @access public |
|
| 1283 | - * @param string $label |
|
| 1284 | - * @param string $required_text |
|
| 1285 | - * @return string |
|
| 1286 | - */ |
|
| 1287 | - public function state_form_field_label_wrap($label, $required_text) |
|
| 1288 | - { |
|
| 1289 | - return $required_text; |
|
| 1290 | - } |
|
| 1291 | - |
|
| 1292 | - |
|
| 1293 | - /** |
|
| 1294 | - * form_form_field_input__wrap |
|
| 1295 | - * |
|
| 1296 | - * @access public |
|
| 1297 | - * @param string $label |
|
| 1298 | - * @return string |
|
| 1299 | - */ |
|
| 1300 | - public function state_form_field_input__wrap($input, $label) |
|
| 1301 | - { |
|
| 1302 | - return ' |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + |
|
| 1279 | + /** |
|
| 1280 | + * form_form_field_label_wrap |
|
| 1281 | + * |
|
| 1282 | + * @access public |
|
| 1283 | + * @param string $label |
|
| 1284 | + * @param string $required_text |
|
| 1285 | + * @return string |
|
| 1286 | + */ |
|
| 1287 | + public function state_form_field_label_wrap($label, $required_text) |
|
| 1288 | + { |
|
| 1289 | + return $required_text; |
|
| 1290 | + } |
|
| 1291 | + |
|
| 1292 | + |
|
| 1293 | + /** |
|
| 1294 | + * form_form_field_input__wrap |
|
| 1295 | + * |
|
| 1296 | + * @access public |
|
| 1297 | + * @param string $label |
|
| 1298 | + * @return string |
|
| 1299 | + */ |
|
| 1300 | + public function state_form_field_input__wrap($input, $label) |
|
| 1301 | + { |
|
| 1302 | + return ' |
|
| 1303 | 1303 | <td class="general-settings-country-state-input-td"> |
| 1304 | 1304 | ' . $input . ' |
| 1305 | 1305 | </td>'; |
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - /***********/ |
|
| 1310 | - |
|
| 1311 | - |
|
| 1312 | - /** |
|
| 1313 | - * displays edit and view links for critical EE pages |
|
| 1314 | - * |
|
| 1315 | - * @access public |
|
| 1316 | - * @param int $ee_page_id |
|
| 1317 | - * @return string |
|
| 1318 | - */ |
|
| 1319 | - public static function edit_view_links($ee_page_id) |
|
| 1320 | - { |
|
| 1321 | - $links = '<a href="' |
|
| 1322 | - . add_query_arg( |
|
| 1323 | - array('post' => $ee_page_id, 'action' => 'edit'), |
|
| 1324 | - admin_url('post.php') |
|
| 1325 | - ) |
|
| 1326 | - . '" >' |
|
| 1327 | - . __('Edit', 'event_espresso') |
|
| 1328 | - . '</a>'; |
|
| 1329 | - $links .= ' | '; |
|
| 1330 | - $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>'; |
|
| 1331 | - |
|
| 1332 | - return $links; |
|
| 1333 | - } |
|
| 1334 | - |
|
| 1335 | - |
|
| 1336 | - /** |
|
| 1337 | - * displays page and shortcode status for critical EE pages |
|
| 1338 | - * |
|
| 1339 | - * @param WP page object $ee_page |
|
| 1340 | - * @return string |
|
| 1341 | - */ |
|
| 1342 | - public static function page_and_shortcode_status($ee_page, $shortcode) |
|
| 1343 | - { |
|
| 1344 | - |
|
| 1345 | - // page status |
|
| 1346 | - if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
| 1347 | - $pg_colour = 'green'; |
|
| 1348 | - $pg_status = sprintf(__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
| 1349 | - } else { |
|
| 1350 | - $pg_colour = 'red'; |
|
| 1351 | - $pg_status = sprintf(__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
| 1352 | - } |
|
| 1353 | - |
|
| 1354 | - // shortcode status |
|
| 1355 | - if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
| 1356 | - $sc_colour = 'green'; |
|
| 1357 | - $sc_status = sprintf(__('Shortcode%sOK', 'event_espresso'), ' '); |
|
| 1358 | - } else { |
|
| 1359 | - $sc_colour = 'red'; |
|
| 1360 | - $sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
| 1364 | - . $pg_status |
|
| 1365 | - . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - /** |
|
| 1370 | - * generates a dropdown of all parent pages - copied from WP core |
|
| 1371 | - * |
|
| 1372 | - * @param int $default |
|
| 1373 | - * @param int $parent |
|
| 1374 | - * @param int $level |
|
| 1375 | - */ |
|
| 1376 | - public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0) |
|
| 1377 | - { |
|
| 1378 | - global $wpdb; |
|
| 1379 | - $items = $wpdb->get_results( |
|
| 1380 | - $wpdb->prepare( |
|
| 1381 | - "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
| 1382 | - $parent |
|
| 1383 | - ) |
|
| 1384 | - ); |
|
| 1385 | - |
|
| 1386 | - if ($items) { |
|
| 1387 | - foreach ($items as $item) { |
|
| 1388 | - $pad = str_repeat(' ', $level * 3); |
|
| 1389 | - if ($item->ID == $default) { |
|
| 1390 | - $current = ' selected="selected"'; |
|
| 1391 | - } else { |
|
| 1392 | - $current = ''; |
|
| 1393 | - } |
|
| 1394 | - |
|
| 1395 | - echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " |
|
| 1396 | - . esc_html($item->post_title) |
|
| 1397 | - . "</option>"; |
|
| 1398 | - parent_dropdown($default, $item->ID, $level + 1); |
|
| 1399 | - } |
|
| 1400 | - } |
|
| 1401 | - } |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + /***********/ |
|
| 1310 | + |
|
| 1311 | + |
|
| 1312 | + /** |
|
| 1313 | + * displays edit and view links for critical EE pages |
|
| 1314 | + * |
|
| 1315 | + * @access public |
|
| 1316 | + * @param int $ee_page_id |
|
| 1317 | + * @return string |
|
| 1318 | + */ |
|
| 1319 | + public static function edit_view_links($ee_page_id) |
|
| 1320 | + { |
|
| 1321 | + $links = '<a href="' |
|
| 1322 | + . add_query_arg( |
|
| 1323 | + array('post' => $ee_page_id, 'action' => 'edit'), |
|
| 1324 | + admin_url('post.php') |
|
| 1325 | + ) |
|
| 1326 | + . '" >' |
|
| 1327 | + . __('Edit', 'event_espresso') |
|
| 1328 | + . '</a>'; |
|
| 1329 | + $links .= ' | '; |
|
| 1330 | + $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>'; |
|
| 1331 | + |
|
| 1332 | + return $links; |
|
| 1333 | + } |
|
| 1334 | + |
|
| 1335 | + |
|
| 1336 | + /** |
|
| 1337 | + * displays page and shortcode status for critical EE pages |
|
| 1338 | + * |
|
| 1339 | + * @param WP page object $ee_page |
|
| 1340 | + * @return string |
|
| 1341 | + */ |
|
| 1342 | + public static function page_and_shortcode_status($ee_page, $shortcode) |
|
| 1343 | + { |
|
| 1344 | + |
|
| 1345 | + // page status |
|
| 1346 | + if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
| 1347 | + $pg_colour = 'green'; |
|
| 1348 | + $pg_status = sprintf(__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
| 1349 | + } else { |
|
| 1350 | + $pg_colour = 'red'; |
|
| 1351 | + $pg_status = sprintf(__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
| 1352 | + } |
|
| 1353 | + |
|
| 1354 | + // shortcode status |
|
| 1355 | + if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
| 1356 | + $sc_colour = 'green'; |
|
| 1357 | + $sc_status = sprintf(__('Shortcode%sOK', 'event_espresso'), ' '); |
|
| 1358 | + } else { |
|
| 1359 | + $sc_colour = 'red'; |
|
| 1360 | + $sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
| 1364 | + . $pg_status |
|
| 1365 | + . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + /** |
|
| 1370 | + * generates a dropdown of all parent pages - copied from WP core |
|
| 1371 | + * |
|
| 1372 | + * @param int $default |
|
| 1373 | + * @param int $parent |
|
| 1374 | + * @param int $level |
|
| 1375 | + */ |
|
| 1376 | + public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0) |
|
| 1377 | + { |
|
| 1378 | + global $wpdb; |
|
| 1379 | + $items = $wpdb->get_results( |
|
| 1380 | + $wpdb->prepare( |
|
| 1381 | + "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
| 1382 | + $parent |
|
| 1383 | + ) |
|
| 1384 | + ); |
|
| 1385 | + |
|
| 1386 | + if ($items) { |
|
| 1387 | + foreach ($items as $item) { |
|
| 1388 | + $pad = str_repeat(' ', $level * 3); |
|
| 1389 | + if ($item->ID == $default) { |
|
| 1390 | + $current = ' selected="selected"'; |
|
| 1391 | + } else { |
|
| 1392 | + $current = ''; |
|
| 1393 | + } |
|
| 1394 | + |
|
| 1395 | + echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " |
|
| 1396 | + . esc_html($item->post_title) |
|
| 1397 | + . "</option>"; |
|
| 1398 | + parent_dropdown($default, $item->ID, $level + 1); |
|
| 1399 | + } |
|
| 1400 | + } |
|
| 1401 | + } |
|
| 1402 | 1402 | } |
@@ -232,11 +232,11 @@ discard block |
||
| 232 | 232 | '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.', |
| 233 | 233 | 'event_espresso' |
| 234 | 234 | ); |
| 235 | - EE_Registry::$i18n_js_strings['error_occurred'] = __( |
|
| 235 | + EE_Registry::$i18n_js_strings['error_occurred'] = __( |
|
| 236 | 236 | 'An error occurred! Please refresh the page and try again.', |
| 237 | 237 | 'event_espresso' |
| 238 | 238 | ); |
| 239 | - EE_Registry::$i18n_js_strings['confirm_delete_state'] = __( |
|
| 239 | + EE_Registry::$i18n_js_strings['confirm_delete_state'] = __( |
|
| 240 | 240 | 'Are you sure you want to delete this State / Province?', |
| 241 | 241 | 'event_espresso' |
| 242 | 242 | ); |
@@ -268,12 +268,12 @@ discard block |
||
| 268 | 268 | wp_enqueue_script('thickbox'); |
| 269 | 269 | wp_register_script( |
| 270 | 270 | 'organization_settings', |
| 271 | - GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
| 271 | + GEN_SET_ASSETS_URL.'your_organization_settings.js', |
|
| 272 | 272 | array('jquery', 'media-upload', 'thickbox'), |
| 273 | 273 | EVENT_ESPRESSO_VERSION, |
| 274 | 274 | true |
| 275 | 275 | ); |
| 276 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 276 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 277 | 277 | wp_enqueue_script('organization_settings'); |
| 278 | 278 | wp_enqueue_style('organization-css'); |
| 279 | 279 | $confirm_image_delete = array( |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | //scripts |
| 295 | 295 | wp_register_script( |
| 296 | 296 | 'gen_settings_countries', |
| 297 | - GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
| 297 | + GEN_SET_ASSETS_URL.'gen_settings_countries.js', |
|
| 298 | 298 | array('ee_admin_js'), |
| 299 | 299 | EVENT_ESPRESSO_VERSION, |
| 300 | 300 | true |
| 301 | 301 | ); |
| 302 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 302 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 303 | 303 | wp_enqueue_script('gen_settings_countries'); |
| 304 | 304 | wp_enqueue_style('organization-css'); |
| 305 | 305 | } |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
| 346 | 346 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
| 347 | 347 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 348 | - GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
| 348 | + GEN_SET_TEMPLATE_PATH.'espresso_page_settings.template.php', |
|
| 349 | 349 | $this->_template_args, |
| 350 | 350 | true |
| 351 | 351 | ); |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | EE_Registry::instance()->CFG->core, |
| 378 | 378 | $this->_req_data |
| 379 | 379 | ); |
| 380 | - $what = __('Critical Pages & Shortcodes', 'event_espresso'); |
|
| 380 | + $what = __('Critical Pages & Shortcodes', 'event_espresso'); |
|
| 381 | 381 | $this->_redirect_after_action( |
| 382 | 382 | $this->_update_espresso_configuration( |
| 383 | 383 | $what, |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | protected function _your_organization_settings() |
| 408 | 408 | { |
| 409 | 409 | |
| 410 | - $this->_template_args['site_license_key'] = isset( |
|
| 410 | + $this->_template_args['site_license_key'] = isset( |
|
| 411 | 411 | EE_Registry::instance()->NET_CFG->core->site_license_key |
| 412 | 412 | ) |
| 413 | 413 | ? EE_Registry::instance()->NET_CFG->core->get_pretty('site_license_key') |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
| 512 | 512 | |
| 513 | 513 | //PUE verification stuff |
| 514 | - $ver_option_key = 'puvererr_' . basename(EE_PLUGIN_BASENAME); |
|
| 514 | + $ver_option_key = 'puvererr_'.basename(EE_PLUGIN_BASENAME); |
|
| 515 | 515 | $verify_fail = get_option($ver_option_key); |
| 516 | 516 | $this->_template_args['site_license_key_verified'] = $verify_fail |
| 517 | 517 | || ! empty($verify_fail) |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | $this->_set_add_edit_form_tags('update_your_organization_settings'); |
| 525 | 525 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
| 526 | 526 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 527 | - GEN_SET_TEMPLATE_PATH . 'your_organization_settings.template.php', |
|
| 527 | + GEN_SET_TEMPLATE_PATH.'your_organization_settings.template.php', |
|
| 528 | 528 | $this->_template_args, |
| 529 | 529 | true |
| 530 | 530 | ); |
@@ -735,7 +735,7 @@ discard block |
||
| 735 | 735 | $this->_set_add_edit_form_tags('update_country_settings'); |
| 736 | 736 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
| 737 | 737 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 738 | - GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
| 738 | + GEN_SET_TEMPLATE_PATH.'countries_settings.template.php', |
|
| 739 | 739 | $this->_template_args, |
| 740 | 740 | true |
| 741 | 741 | ); |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | $CNT_ISO = isset($this->_req_data['country']) |
| 758 | 758 | ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
| 759 | 759 | : $CNT_ISO; |
| 760 | - if (! $CNT_ISO) { |
|
| 760 | + if ( ! $CNT_ISO) { |
|
| 761 | 761 | return ''; |
| 762 | 762 | } |
| 763 | 763 | |
@@ -768,65 +768,65 @@ discard block |
||
| 768 | 768 | add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
| 769 | 769 | $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
| 770 | 770 | |
| 771 | - $country_input_types = array( |
|
| 771 | + $country_input_types = array( |
|
| 772 | 772 | 'CNT_active' => array( |
| 773 | 773 | 'type' => 'RADIO_BTN', |
| 774 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 774 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 775 | 775 | 'class' => '', |
| 776 | 776 | 'options' => $this->_yes_no_values, |
| 777 | 777 | 'use_desc_4_label' => true, |
| 778 | 778 | ), |
| 779 | 779 | 'CNT_ISO' => array( |
| 780 | 780 | 'type' => 'TEXT', |
| 781 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 781 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 782 | 782 | 'class' => 'small-text', |
| 783 | 783 | ), |
| 784 | 784 | 'CNT_ISO3' => array( |
| 785 | 785 | 'type' => 'TEXT', |
| 786 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 786 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 787 | 787 | 'class' => 'small-text', |
| 788 | 788 | ), |
| 789 | 789 | 'RGN_ID' => array( |
| 790 | 790 | 'type' => 'TEXT', |
| 791 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 791 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 792 | 792 | 'class' => 'small-text', |
| 793 | 793 | ), |
| 794 | 794 | 'CNT_name' => array( |
| 795 | 795 | 'type' => 'TEXT', |
| 796 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 796 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 797 | 797 | 'class' => 'regular-text', |
| 798 | 798 | ), |
| 799 | 799 | 'CNT_cur_code' => array( |
| 800 | 800 | 'type' => 'TEXT', |
| 801 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 801 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 802 | 802 | 'class' => 'small-text', |
| 803 | 803 | ), |
| 804 | 804 | 'CNT_cur_single' => array( |
| 805 | 805 | 'type' => 'TEXT', |
| 806 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 806 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 807 | 807 | 'class' => 'medium-text', |
| 808 | 808 | ), |
| 809 | 809 | 'CNT_cur_plural' => array( |
| 810 | 810 | 'type' => 'TEXT', |
| 811 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 811 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 812 | 812 | 'class' => 'medium-text', |
| 813 | 813 | ), |
| 814 | 814 | 'CNT_cur_sign' => array( |
| 815 | 815 | 'type' => 'TEXT', |
| 816 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 816 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 817 | 817 | 'class' => 'small-text', |
| 818 | 818 | 'htmlentities' => false, |
| 819 | 819 | ), |
| 820 | 820 | 'CNT_cur_sign_b4' => array( |
| 821 | 821 | 'type' => 'RADIO_BTN', |
| 822 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 822 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 823 | 823 | 'class' => '', |
| 824 | 824 | 'options' => $this->_yes_no_values, |
| 825 | 825 | 'use_desc_4_label' => true, |
| 826 | 826 | ), |
| 827 | 827 | 'CNT_cur_dec_plc' => array( |
| 828 | 828 | 'type' => 'RADIO_BTN', |
| 829 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 829 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 830 | 830 | 'class' => '', |
| 831 | 831 | 'options' => array( |
| 832 | 832 | array('id' => 0, 'text' => ''), |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | ), |
| 838 | 838 | 'CNT_cur_dec_mrk' => array( |
| 839 | 839 | 'type' => 'RADIO_BTN', |
| 840 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 840 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 841 | 841 | 'class' => '', |
| 842 | 842 | 'options' => array( |
| 843 | 843 | array( |
@@ -850,7 +850,7 @@ discard block |
||
| 850 | 850 | ), |
| 851 | 851 | 'CNT_cur_thsnds' => array( |
| 852 | 852 | 'type' => 'RADIO_BTN', |
| 853 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 853 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 854 | 854 | 'class' => '', |
| 855 | 855 | 'options' => array( |
| 856 | 856 | array( |
@@ -863,12 +863,12 @@ discard block |
||
| 863 | 863 | ), |
| 864 | 864 | 'CNT_tel_code' => array( |
| 865 | 865 | 'type' => 'TEXT', |
| 866 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 866 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 867 | 867 | 'class' => 'small-text', |
| 868 | 868 | ), |
| 869 | 869 | 'CNT_is_EU' => array( |
| 870 | 870 | 'type' => 'RADIO_BTN', |
| 871 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
| 871 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
| 872 | 872 | 'class' => '', |
| 873 | 873 | 'options' => $this->_yes_no_values, |
| 874 | 874 | 'use_desc_4_label' => true, |
@@ -878,8 +878,8 @@ discard block |
||
| 878 | 878 | $country, |
| 879 | 879 | $country_input_types |
| 880 | 880 | ); |
| 881 | - $country_details_settings = EEH_Template::display_template( |
|
| 882 | - GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
| 881 | + $country_details_settings = EEH_Template::display_template( |
|
| 882 | + GEN_SET_TEMPLATE_PATH.'country_details_settings.template.php', |
|
| 883 | 883 | $this->_template_args, |
| 884 | 884 | true |
| 885 | 885 | ); |
@@ -911,7 +911,7 @@ discard block |
||
| 911 | 911 | |
| 912 | 912 | $CNT_ISO = isset($this->_req_data['country']) ? sanitize_text_field($this->_req_data['country']) : $CNT_ISO; |
| 913 | 913 | |
| 914 | - if (! $CNT_ISO) { |
|
| 914 | + if ( ! $CNT_ISO) { |
|
| 915 | 915 | return ''; |
| 916 | 916 | } |
| 917 | 917 | // for ajax |
@@ -925,20 +925,20 @@ discard block |
||
| 925 | 925 | foreach ($states as $STA_ID => $state) { |
| 926 | 926 | if ($state instanceof EE_State) { |
| 927 | 927 | //STA_abbrev STA_name STA_active |
| 928 | - $state_input_types = array( |
|
| 928 | + $state_input_types = array( |
|
| 929 | 929 | 'STA_abbrev' => array( |
| 930 | 930 | 'type' => 'TEXT', |
| 931 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 931 | + 'input_name' => 'states['.$STA_ID.']', |
|
| 932 | 932 | 'class' => 'mid-text', |
| 933 | 933 | ), |
| 934 | 934 | 'STA_name' => array( |
| 935 | 935 | 'type' => 'TEXT', |
| 936 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 936 | + 'input_name' => 'states['.$STA_ID.']', |
|
| 937 | 937 | 'class' => 'regular-text', |
| 938 | 938 | ), |
| 939 | 939 | 'STA_active' => array( |
| 940 | 940 | 'type' => 'RADIO_BTN', |
| 941 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
| 941 | + 'input_name' => 'states['.$STA_ID.']', |
|
| 942 | 942 | 'options' => $this->_yes_no_values, |
| 943 | 943 | 'use_desc_4_label' => true, |
| 944 | 944 | ), |
@@ -948,7 +948,7 @@ discard block |
||
| 948 | 948 | $state, |
| 949 | 949 | $state_input_types |
| 950 | 950 | ); |
| 951 | - $query_args = array( |
|
| 951 | + $query_args = array( |
|
| 952 | 952 | 'action' => 'delete_state', |
| 953 | 953 | 'STA_ID' => $STA_ID, |
| 954 | 954 | 'CNT_ISO' => $CNT_ISO, |
@@ -971,7 +971,7 @@ discard block |
||
| 971 | 971 | ); |
| 972 | 972 | |
| 973 | 973 | $state_details_settings = EEH_Template::display_template( |
| 974 | - GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
| 974 | + GEN_SET_TEMPLATE_PATH.'state_details_settings.template.php', |
|
| 975 | 975 | $this->_template_args, |
| 976 | 976 | true |
| 977 | 977 | ); |
@@ -1005,7 +1005,7 @@ discard block |
||
| 1005 | 1005 | $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
| 1006 | 1006 | ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
| 1007 | 1007 | : false; |
| 1008 | - if (! $CNT_ISO) { |
|
| 1008 | + if ( ! $CNT_ISO) { |
|
| 1009 | 1009 | EE_Error::add_error( |
| 1010 | 1010 | __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
| 1011 | 1011 | __FILE__, |
@@ -1017,7 +1017,7 @@ discard block |
||
| 1017 | 1017 | $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
| 1018 | 1018 | ? sanitize_text_field($this->_req_data['STA_abbrev']) |
| 1019 | 1019 | : false; |
| 1020 | - if (! $STA_abbrev) { |
|
| 1020 | + if ( ! $STA_abbrev) { |
|
| 1021 | 1021 | EE_Error::add_error( |
| 1022 | 1022 | __('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
| 1023 | 1023 | __FILE__, |
@@ -1029,7 +1029,7 @@ discard block |
||
| 1029 | 1029 | $STA_name = isset($this->_req_data['STA_name']) |
| 1030 | 1030 | ? sanitize_text_field($this->_req_data['STA_name']) |
| 1031 | 1031 | : false; |
| 1032 | - if (! $STA_name) { |
|
| 1032 | + if ( ! $STA_name) { |
|
| 1033 | 1033 | EE_Error::add_error( |
| 1034 | 1034 | __('No State name or an invalid State name was received.', 'event_espresso'), |
| 1035 | 1035 | __FILE__, |
@@ -1046,7 +1046,7 @@ discard block |
||
| 1046 | 1046 | 'STA_name' => $STA_name, |
| 1047 | 1047 | 'STA_active' => true, |
| 1048 | 1048 | ); |
| 1049 | - $success = EEM_State::instance()->insert($cols_n_values); |
|
| 1049 | + $success = EEM_State::instance()->insert($cols_n_values); |
|
| 1050 | 1050 | EE_Error::add_success(__('The State was added successfully.', 'event_espresso')); |
| 1051 | 1051 | } |
| 1052 | 1052 | |
@@ -1077,7 +1077,7 @@ discard block |
||
| 1077 | 1077 | $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
| 1078 | 1078 | ? sanitize_text_field($this->_req_data['STA_abbrev']) |
| 1079 | 1079 | : false; |
| 1080 | - if (! $STA_ID) { |
|
| 1080 | + if ( ! $STA_ID) { |
|
| 1081 | 1081 | EE_Error::add_error( |
| 1082 | 1082 | __('No State ID or an invalid State ID was received.', 'event_espresso'), |
| 1083 | 1083 | __FILE__, |
@@ -1126,7 +1126,7 @@ discard block |
||
| 1126 | 1126 | $CNT_ISO = isset($this->_req_data['country']) |
| 1127 | 1127 | ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
| 1128 | 1128 | : false; |
| 1129 | - if (! $CNT_ISO) { |
|
| 1129 | + if ( ! $CNT_ISO) { |
|
| 1130 | 1130 | EE_Error::add_error( |
| 1131 | 1131 | __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
| 1132 | 1132 | __FILE__, |
@@ -1203,7 +1203,7 @@ discard block |
||
| 1203 | 1203 | 'CNT_ISO' => $CNT_ISO, |
| 1204 | 1204 | 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
| 1205 | 1205 | 'STA_name' => sanitize_text_field($state['STA_name']), |
| 1206 | - 'STA_active' => (bool)absint($state['STA_active']), |
|
| 1206 | + 'STA_active' => (bool) absint($state['STA_active']), |
|
| 1207 | 1207 | ); |
| 1208 | 1208 | // where values |
| 1209 | 1209 | $where_cols_n_values = array(array('STA_ID' => $STA_ID)); |
@@ -1254,7 +1254,7 @@ discard block |
||
| 1254 | 1254 | return ' |
| 1255 | 1255 | <tr> |
| 1256 | 1256 | <th> |
| 1257 | - ' . $label . ' |
|
| 1257 | + ' . $label.' |
|
| 1258 | 1258 | </th>'; |
| 1259 | 1259 | } |
| 1260 | 1260 | |
@@ -1270,7 +1270,7 @@ discard block |
||
| 1270 | 1270 | { |
| 1271 | 1271 | return ' |
| 1272 | 1272 | <td class="general-settings-country-input-td"> |
| 1273 | - ' . $input . ' |
|
| 1273 | + ' . $input.' |
|
| 1274 | 1274 | </td> |
| 1275 | 1275 | </tr>'; |
| 1276 | 1276 | } |
@@ -1301,7 +1301,7 @@ discard block |
||
| 1301 | 1301 | { |
| 1302 | 1302 | return ' |
| 1303 | 1303 | <td class="general-settings-country-state-input-td"> |
| 1304 | - ' . $input . ' |
|
| 1304 | + ' . $input.' |
|
| 1305 | 1305 | </td>'; |
| 1306 | 1306 | } |
| 1307 | 1307 | |
@@ -1327,7 +1327,7 @@ discard block |
||
| 1327 | 1327 | . __('Edit', 'event_espresso') |
| 1328 | 1328 | . '</a>'; |
| 1329 | 1329 | $links .= ' | '; |
| 1330 | - $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>'; |
|
| 1330 | + $links .= '<a href="'.get_permalink($ee_page_id).'" >'.__('View', 'event_espresso').'</a>'; |
|
| 1331 | 1331 | |
| 1332 | 1332 | return $links; |
| 1333 | 1333 | } |
@@ -1360,9 +1360,9 @@ discard block |
||
| 1360 | 1360 | $sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), ' '); |
| 1361 | 1361 | } |
| 1362 | 1362 | |
| 1363 | - return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
| 1363 | + return '<span style="color:'.$pg_colour.'; margin-right:2em;"><strong>' |
|
| 1364 | 1364 | . $pg_status |
| 1365 | - . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
| 1365 | + . '</strong></span><span style="color:'.$sc_colour.'"><strong>'.$sc_status.'</strong></span>'; |
|
| 1366 | 1366 | } |
| 1367 | 1367 | |
| 1368 | 1368 | |
@@ -23,449 +23,449 @@ |
||
| 23 | 23 | class Registry |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var EE_Template_Config $template_config |
|
| 28 | - */ |
|
| 29 | - protected $template_config; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var EE_Currency_Config $currency_config |
|
| 33 | - */ |
|
| 34 | - protected $currency_config; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 38 | - * |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - protected $jsdata = array(); |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
| 46 | - * page source. |
|
| 47 | - * @var array |
|
| 48 | - */ |
|
| 49 | - protected $script_handles_with_data = array(); |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Registry constructor. |
|
| 55 | - * Hooking into WP actions for script registry. |
|
| 56 | - * |
|
| 57 | - * @param EE_Template_Config $template_config |
|
| 58 | - * @param EE_Currency_Config $currency_config |
|
| 59 | - */ |
|
| 60 | - public function __construct(EE_Template_Config $template_config, EE_Currency_Config $currency_config) |
|
| 61 | - { |
|
| 62 | - $this->template_config = $template_config; |
|
| 63 | - $this->currency_config = $currency_config; |
|
| 64 | - add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 65 | - add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 66 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 67 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 68 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 69 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Callback for the WP script actions. |
|
| 76 | - * Used to register globally accessible core scripts. |
|
| 77 | - * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
| 78 | - */ |
|
| 79 | - public function scripts() |
|
| 80 | - { |
|
| 81 | - global $wp_version; |
|
| 82 | - wp_register_script( |
|
| 83 | - 'eejs-core', |
|
| 84 | - EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
| 85 | - array(), |
|
| 86 | - EVENT_ESPRESSO_VERSION, |
|
| 87 | - true |
|
| 88 | - ); |
|
| 89 | - //only run this if WordPress 4.4.0 > is in use. |
|
| 90 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 91 | - //js.api |
|
| 92 | - wp_register_script( |
|
| 93 | - 'eejs-api', |
|
| 94 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 95 | - array('underscore', 'eejs-core'), |
|
| 96 | - EVENT_ESPRESSO_VERSION, |
|
| 97 | - true |
|
| 98 | - ); |
|
| 99 | - $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
| 100 | - $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
| 101 | - } |
|
| 102 | - if (! is_admin()) { |
|
| 103 | - $this->loadCoreCss(); |
|
| 104 | - } |
|
| 105 | - $this->loadCoreJs(); |
|
| 106 | - $this->loadJqueryValidate(); |
|
| 107 | - $this->loadAccountingJs(); |
|
| 108 | - $this->loadQtipJs(); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Call back for the script print in frontend and backend. |
|
| 115 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
| 116 | - * |
|
| 117 | - * @since 4.9.31.rc.015 |
|
| 118 | - */ |
|
| 119 | - public function enqueueData() |
|
| 120 | - { |
|
| 121 | - $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
| 122 | - wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata)); |
|
| 123 | - wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 124 | - $this->localizeAccountingJs(); |
|
| 125 | - $this->addRegisteredScriptHandlesWithData('eejs-core'); |
|
| 126 | - $this->addRegisteredScriptHandlesWithData('espresso_core'); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Used to add data to eejs.data object. |
|
| 133 | - * Note: Overriding existing data is not allowed. |
|
| 134 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 135 | - * If the data you add is something like this: |
|
| 136 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 137 | - * It will be exposed in the page source as: |
|
| 138 | - * eejs.data.my_plugin_data.foo == gar |
|
| 139 | - * |
|
| 140 | - * @param string $key Key used to access your data |
|
| 141 | - * @param string|array $value Value to attach to key |
|
| 142 | - * @throws InvalidArgumentException |
|
| 143 | - */ |
|
| 144 | - public function addData($key, $value) |
|
| 145 | - { |
|
| 146 | - if ($this->verifyDataNotExisting($key)) { |
|
| 147 | - $this->jsdata[$key] = $value; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 155 | - * elements in an array. |
|
| 156 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 157 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
| 158 | - * object like this, eejs.data.test = [ my_data, |
|
| 159 | - * ] |
|
| 160 | - * If there has already been a scalar value attached to the data object given key, then |
|
| 161 | - * this will throw an exception. |
|
| 162 | - * |
|
| 163 | - * @param string $key Key to attach data to. |
|
| 164 | - * @param string|array $value Value being registered. |
|
| 165 | - * @throws InvalidArgumentException |
|
| 166 | - */ |
|
| 167 | - public function pushData($key, $value) |
|
| 168 | - { |
|
| 169 | - if (isset($this->jsdata[$key]) |
|
| 170 | - && ! is_array($this->jsdata[$key]) |
|
| 171 | - ) { |
|
| 172 | - throw new invalidArgumentException( |
|
| 173 | - sprintf( |
|
| 174 | - __( |
|
| 175 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 26 | + /** |
|
| 27 | + * @var EE_Template_Config $template_config |
|
| 28 | + */ |
|
| 29 | + protected $template_config; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var EE_Currency_Config $currency_config |
|
| 33 | + */ |
|
| 34 | + protected $currency_config; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 38 | + * |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + protected $jsdata = array(); |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
| 46 | + * page source. |
|
| 47 | + * @var array |
|
| 48 | + */ |
|
| 49 | + protected $script_handles_with_data = array(); |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Registry constructor. |
|
| 55 | + * Hooking into WP actions for script registry. |
|
| 56 | + * |
|
| 57 | + * @param EE_Template_Config $template_config |
|
| 58 | + * @param EE_Currency_Config $currency_config |
|
| 59 | + */ |
|
| 60 | + public function __construct(EE_Template_Config $template_config, EE_Currency_Config $currency_config) |
|
| 61 | + { |
|
| 62 | + $this->template_config = $template_config; |
|
| 63 | + $this->currency_config = $currency_config; |
|
| 64 | + add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 65 | + add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 66 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 67 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
| 68 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 69 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Callback for the WP script actions. |
|
| 76 | + * Used to register globally accessible core scripts. |
|
| 77 | + * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
| 78 | + */ |
|
| 79 | + public function scripts() |
|
| 80 | + { |
|
| 81 | + global $wp_version; |
|
| 82 | + wp_register_script( |
|
| 83 | + 'eejs-core', |
|
| 84 | + EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
| 85 | + array(), |
|
| 86 | + EVENT_ESPRESSO_VERSION, |
|
| 87 | + true |
|
| 88 | + ); |
|
| 89 | + //only run this if WordPress 4.4.0 > is in use. |
|
| 90 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 91 | + //js.api |
|
| 92 | + wp_register_script( |
|
| 93 | + 'eejs-api', |
|
| 94 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 95 | + array('underscore', 'eejs-core'), |
|
| 96 | + EVENT_ESPRESSO_VERSION, |
|
| 97 | + true |
|
| 98 | + ); |
|
| 99 | + $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
| 100 | + $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
| 101 | + } |
|
| 102 | + if (! is_admin()) { |
|
| 103 | + $this->loadCoreCss(); |
|
| 104 | + } |
|
| 105 | + $this->loadCoreJs(); |
|
| 106 | + $this->loadJqueryValidate(); |
|
| 107 | + $this->loadAccountingJs(); |
|
| 108 | + $this->loadQtipJs(); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Call back for the script print in frontend and backend. |
|
| 115 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
| 116 | + * |
|
| 117 | + * @since 4.9.31.rc.015 |
|
| 118 | + */ |
|
| 119 | + public function enqueueData() |
|
| 120 | + { |
|
| 121 | + $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
| 122 | + wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata)); |
|
| 123 | + wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 124 | + $this->localizeAccountingJs(); |
|
| 125 | + $this->addRegisteredScriptHandlesWithData('eejs-core'); |
|
| 126 | + $this->addRegisteredScriptHandlesWithData('espresso_core'); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Used to add data to eejs.data object. |
|
| 133 | + * Note: Overriding existing data is not allowed. |
|
| 134 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 135 | + * If the data you add is something like this: |
|
| 136 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 137 | + * It will be exposed in the page source as: |
|
| 138 | + * eejs.data.my_plugin_data.foo == gar |
|
| 139 | + * |
|
| 140 | + * @param string $key Key used to access your data |
|
| 141 | + * @param string|array $value Value to attach to key |
|
| 142 | + * @throws InvalidArgumentException |
|
| 143 | + */ |
|
| 144 | + public function addData($key, $value) |
|
| 145 | + { |
|
| 146 | + if ($this->verifyDataNotExisting($key)) { |
|
| 147 | + $this->jsdata[$key] = $value; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 155 | + * elements in an array. |
|
| 156 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 157 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
| 158 | + * object like this, eejs.data.test = [ my_data, |
|
| 159 | + * ] |
|
| 160 | + * If there has already been a scalar value attached to the data object given key, then |
|
| 161 | + * this will throw an exception. |
|
| 162 | + * |
|
| 163 | + * @param string $key Key to attach data to. |
|
| 164 | + * @param string|array $value Value being registered. |
|
| 165 | + * @throws InvalidArgumentException |
|
| 166 | + */ |
|
| 167 | + public function pushData($key, $value) |
|
| 168 | + { |
|
| 169 | + if (isset($this->jsdata[$key]) |
|
| 170 | + && ! is_array($this->jsdata[$key]) |
|
| 171 | + ) { |
|
| 172 | + throw new invalidArgumentException( |
|
| 173 | + sprintf( |
|
| 174 | + __( |
|
| 175 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 176 | 176 | push values to this data element when it is an array.', |
| 177 | - 'event_espresso' |
|
| 178 | - ), |
|
| 179 | - $key, |
|
| 180 | - __METHOD__ |
|
| 181 | - ) |
|
| 182 | - ); |
|
| 183 | - } |
|
| 184 | - $this->jsdata[$key][] = $value; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Used to set content used by javascript for a template. |
|
| 191 | - * Note: Overrides of existing registered templates are not allowed. |
|
| 192 | - * |
|
| 193 | - * @param string $template_reference |
|
| 194 | - * @param string $template_content |
|
| 195 | - * @throws InvalidArgumentException |
|
| 196 | - */ |
|
| 197 | - public function addTemplate($template_reference, $template_content) |
|
| 198 | - { |
|
| 199 | - if (! isset($this->jsdata['templates'])) { |
|
| 200 | - $this->jsdata['templates'] = array(); |
|
| 201 | - } |
|
| 202 | - //no overrides allowed. |
|
| 203 | - if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 204 | - throw new invalidArgumentException( |
|
| 205 | - sprintf( |
|
| 206 | - __( |
|
| 207 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 208 | - 'event_espresso' |
|
| 209 | - ), |
|
| 210 | - $template_reference |
|
| 211 | - ) |
|
| 212 | - ); |
|
| 213 | - } |
|
| 214 | - $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Retrieve the template content already registered for the given reference. |
|
| 221 | - * |
|
| 222 | - * @param string $template_reference |
|
| 223 | - * @return string |
|
| 224 | - */ |
|
| 225 | - public function getTemplate($template_reference) |
|
| 226 | - { |
|
| 227 | - return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
| 228 | - ? $this->jsdata['templates'][$template_reference] |
|
| 229 | - : ''; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Retrieve registered data. |
|
| 236 | - * |
|
| 237 | - * @param string $key Name of key to attach data to. |
|
| 238 | - * @return mixed If there is no for the given key, then false is returned. |
|
| 239 | - */ |
|
| 240 | - public function getData($key) |
|
| 241 | - { |
|
| 242 | - return isset($this->jsdata[$key]) |
|
| 243 | - ? $this->jsdata[$key] |
|
| 244 | - : false; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Verifies whether the given data exists already on the jsdata array. |
|
| 251 | - * Overriding data is not allowed. |
|
| 252 | - * |
|
| 253 | - * @param string $key Index for data. |
|
| 254 | - * @return bool If valid then return true. |
|
| 255 | - * @throws InvalidArgumentException if data already exists. |
|
| 256 | - */ |
|
| 257 | - protected function verifyDataNotExisting($key) |
|
| 258 | - { |
|
| 259 | - if (isset($this->jsdata[$key])) { |
|
| 260 | - if (is_array($this->jsdata[$key])) { |
|
| 261 | - throw new InvalidArgumentException( |
|
| 262 | - sprintf( |
|
| 263 | - __( |
|
| 264 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
| 177 | + 'event_espresso' |
|
| 178 | + ), |
|
| 179 | + $key, |
|
| 180 | + __METHOD__ |
|
| 181 | + ) |
|
| 182 | + ); |
|
| 183 | + } |
|
| 184 | + $this->jsdata[$key][] = $value; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Used to set content used by javascript for a template. |
|
| 191 | + * Note: Overrides of existing registered templates are not allowed. |
|
| 192 | + * |
|
| 193 | + * @param string $template_reference |
|
| 194 | + * @param string $template_content |
|
| 195 | + * @throws InvalidArgumentException |
|
| 196 | + */ |
|
| 197 | + public function addTemplate($template_reference, $template_content) |
|
| 198 | + { |
|
| 199 | + if (! isset($this->jsdata['templates'])) { |
|
| 200 | + $this->jsdata['templates'] = array(); |
|
| 201 | + } |
|
| 202 | + //no overrides allowed. |
|
| 203 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 204 | + throw new invalidArgumentException( |
|
| 205 | + sprintf( |
|
| 206 | + __( |
|
| 207 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 208 | + 'event_espresso' |
|
| 209 | + ), |
|
| 210 | + $template_reference |
|
| 211 | + ) |
|
| 212 | + ); |
|
| 213 | + } |
|
| 214 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Retrieve the template content already registered for the given reference. |
|
| 221 | + * |
|
| 222 | + * @param string $template_reference |
|
| 223 | + * @return string |
|
| 224 | + */ |
|
| 225 | + public function getTemplate($template_reference) |
|
| 226 | + { |
|
| 227 | + return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
| 228 | + ? $this->jsdata['templates'][$template_reference] |
|
| 229 | + : ''; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Retrieve registered data. |
|
| 236 | + * |
|
| 237 | + * @param string $key Name of key to attach data to. |
|
| 238 | + * @return mixed If there is no for the given key, then false is returned. |
|
| 239 | + */ |
|
| 240 | + public function getData($key) |
|
| 241 | + { |
|
| 242 | + return isset($this->jsdata[$key]) |
|
| 243 | + ? $this->jsdata[$key] |
|
| 244 | + : false; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Verifies whether the given data exists already on the jsdata array. |
|
| 251 | + * Overriding data is not allowed. |
|
| 252 | + * |
|
| 253 | + * @param string $key Index for data. |
|
| 254 | + * @return bool If valid then return true. |
|
| 255 | + * @throws InvalidArgumentException if data already exists. |
|
| 256 | + */ |
|
| 257 | + protected function verifyDataNotExisting($key) |
|
| 258 | + { |
|
| 259 | + if (isset($this->jsdata[$key])) { |
|
| 260 | + if (is_array($this->jsdata[$key])) { |
|
| 261 | + throw new InvalidArgumentException( |
|
| 262 | + sprintf( |
|
| 263 | + __( |
|
| 264 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
| 265 | 265 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
| 266 | 266 | %2$s method to push your value to the array.', |
| 267 | - 'event_espresso' |
|
| 268 | - ), |
|
| 269 | - $key, |
|
| 270 | - 'pushData()' |
|
| 271 | - ) |
|
| 272 | - ); |
|
| 273 | - } |
|
| 274 | - throw new InvalidArgumentException( |
|
| 275 | - sprintf( |
|
| 276 | - __( |
|
| 277 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 267 | + 'event_espresso' |
|
| 268 | + ), |
|
| 269 | + $key, |
|
| 270 | + 'pushData()' |
|
| 271 | + ) |
|
| 272 | + ); |
|
| 273 | + } |
|
| 274 | + throw new InvalidArgumentException( |
|
| 275 | + sprintf( |
|
| 276 | + __( |
|
| 277 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 278 | 278 | allowed. Consider attaching your value to a different key', |
| 279 | - 'event_espresso' |
|
| 280 | - ), |
|
| 281 | - $key |
|
| 282 | - ) |
|
| 283 | - ); |
|
| 284 | - } |
|
| 285 | - return true; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * registers core default stylesheets |
|
| 292 | - */ |
|
| 293 | - private function loadCoreCss() |
|
| 294 | - { |
|
| 295 | - if ($this->template_config->enable_default_style) { |
|
| 296 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 297 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 298 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 299 | - wp_register_style( |
|
| 300 | - 'espresso_default', |
|
| 301 | - $default_stylesheet_path, |
|
| 302 | - array('dashicons'), |
|
| 303 | - EVENT_ESPRESSO_VERSION |
|
| 304 | - ); |
|
| 305 | - //Load custom style sheet if available |
|
| 306 | - if ($this->template_config->custom_style_sheet !== null) { |
|
| 307 | - wp_register_style( |
|
| 308 | - 'espresso_custom_css', |
|
| 309 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 310 | - array('espresso_default'), |
|
| 311 | - EVENT_ESPRESSO_VERSION |
|
| 312 | - ); |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * registers core default javascript |
|
| 321 | - */ |
|
| 322 | - private function loadCoreJs() |
|
| 323 | - { |
|
| 324 | - // load core js |
|
| 325 | - wp_register_script( |
|
| 326 | - 'espresso_core', |
|
| 327 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 328 | - array('jquery'), |
|
| 329 | - EVENT_ESPRESSO_VERSION, |
|
| 330 | - true |
|
| 331 | - ); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * registers jQuery Validate for form validation |
|
| 338 | - */ |
|
| 339 | - private function loadJqueryValidate() |
|
| 340 | - { |
|
| 341 | - // register jQuery Validate and additional methods |
|
| 342 | - wp_register_script( |
|
| 343 | - 'jquery-validate', |
|
| 344 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 345 | - array('jquery'), |
|
| 346 | - '1.15.0', |
|
| 347 | - true |
|
| 348 | - ); |
|
| 349 | - wp_register_script( |
|
| 350 | - 'jquery-validate-extra-methods', |
|
| 351 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 352 | - array('jquery', 'jquery-validate'), |
|
| 353 | - '1.15.0', |
|
| 354 | - true |
|
| 355 | - ); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * registers accounting.js for performing client-side calculations |
|
| 362 | - */ |
|
| 363 | - private function loadAccountingJs() |
|
| 364 | - { |
|
| 365 | - //accounting.js library |
|
| 366 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 367 | - wp_register_script( |
|
| 368 | - 'ee-accounting-core', |
|
| 369 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 370 | - array('underscore'), |
|
| 371 | - '0.3.2', |
|
| 372 | - true |
|
| 373 | - ); |
|
| 374 | - wp_register_script( |
|
| 375 | - 'ee-accounting', |
|
| 376 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 377 | - array('ee-accounting-core'), |
|
| 378 | - EVENT_ESPRESSO_VERSION, |
|
| 379 | - true |
|
| 380 | - ); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * registers accounting.js for performing client-side calculations |
|
| 387 | - */ |
|
| 388 | - private function localizeAccountingJs() |
|
| 389 | - { |
|
| 390 | - wp_localize_script( |
|
| 391 | - 'ee-accounting', |
|
| 392 | - 'EE_ACCOUNTING_CFG', |
|
| 393 | - array( |
|
| 394 | - 'currency' => array( |
|
| 395 | - 'symbol' => $this->currency_config->sign, |
|
| 396 | - 'format' => array( |
|
| 397 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 398 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 399 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 400 | - ), |
|
| 401 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 402 | - 'thousand' => $this->currency_config->thsnds, |
|
| 403 | - 'precision' => $this->currency_config->dec_plc, |
|
| 404 | - ), |
|
| 405 | - 'number' => array( |
|
| 406 | - 'precision' => $this->currency_config->dec_plc, |
|
| 407 | - 'thousand' => $this->currency_config->thsnds, |
|
| 408 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 409 | - ), |
|
| 410 | - ) |
|
| 411 | - ); |
|
| 412 | - $this->addRegisteredScriptHandlesWithData('ee-accounting'); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * registers assets for cleaning your ears |
|
| 419 | - */ |
|
| 420 | - private function loadQtipJs() |
|
| 421 | - { |
|
| 422 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 423 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 424 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
| 425 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * This is used to set registered script handles that have data. |
|
| 432 | - * @param string $script_handle |
|
| 433 | - */ |
|
| 434 | - private function addRegisteredScriptHandlesWithData($script_handle) |
|
| 435 | - { |
|
| 436 | - $this->script_handles_with_data[$script_handle] = $script_handle; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
|
| 442 | - * Dependency stored in WP_Scripts if its set. |
|
| 443 | - */ |
|
| 444 | - private function removeAlreadyRegisteredDataForScriptHandles() |
|
| 445 | - { |
|
| 446 | - if (empty($this->script_handles_with_data)) { |
|
| 447 | - return; |
|
| 448 | - } |
|
| 449 | - foreach ($this->script_handles_with_data as $script_handle) { |
|
| 450 | - $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * Removes any data dependency registered in WP_Scripts if its set. |
|
| 457 | - * @param string $script_handle |
|
| 458 | - */ |
|
| 459 | - private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
| 460 | - { |
|
| 461 | - if (isset($this->script_handles_with_data[$script_handle])) { |
|
| 462 | - global $wp_scripts; |
|
| 463 | - if ($wp_scripts->get_data($script_handle, 'data')) { |
|
| 464 | - unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
| 465 | - unset($this->script_handles_with_data[$script_handle]); |
|
| 466 | - } |
|
| 467 | - } |
|
| 468 | - } |
|
| 279 | + 'event_espresso' |
|
| 280 | + ), |
|
| 281 | + $key |
|
| 282 | + ) |
|
| 283 | + ); |
|
| 284 | + } |
|
| 285 | + return true; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * registers core default stylesheets |
|
| 292 | + */ |
|
| 293 | + private function loadCoreCss() |
|
| 294 | + { |
|
| 295 | + if ($this->template_config->enable_default_style) { |
|
| 296 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 297 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 298 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 299 | + wp_register_style( |
|
| 300 | + 'espresso_default', |
|
| 301 | + $default_stylesheet_path, |
|
| 302 | + array('dashicons'), |
|
| 303 | + EVENT_ESPRESSO_VERSION |
|
| 304 | + ); |
|
| 305 | + //Load custom style sheet if available |
|
| 306 | + if ($this->template_config->custom_style_sheet !== null) { |
|
| 307 | + wp_register_style( |
|
| 308 | + 'espresso_custom_css', |
|
| 309 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 310 | + array('espresso_default'), |
|
| 311 | + EVENT_ESPRESSO_VERSION |
|
| 312 | + ); |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * registers core default javascript |
|
| 321 | + */ |
|
| 322 | + private function loadCoreJs() |
|
| 323 | + { |
|
| 324 | + // load core js |
|
| 325 | + wp_register_script( |
|
| 326 | + 'espresso_core', |
|
| 327 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 328 | + array('jquery'), |
|
| 329 | + EVENT_ESPRESSO_VERSION, |
|
| 330 | + true |
|
| 331 | + ); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * registers jQuery Validate for form validation |
|
| 338 | + */ |
|
| 339 | + private function loadJqueryValidate() |
|
| 340 | + { |
|
| 341 | + // register jQuery Validate and additional methods |
|
| 342 | + wp_register_script( |
|
| 343 | + 'jquery-validate', |
|
| 344 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 345 | + array('jquery'), |
|
| 346 | + '1.15.0', |
|
| 347 | + true |
|
| 348 | + ); |
|
| 349 | + wp_register_script( |
|
| 350 | + 'jquery-validate-extra-methods', |
|
| 351 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 352 | + array('jquery', 'jquery-validate'), |
|
| 353 | + '1.15.0', |
|
| 354 | + true |
|
| 355 | + ); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * registers accounting.js for performing client-side calculations |
|
| 362 | + */ |
|
| 363 | + private function loadAccountingJs() |
|
| 364 | + { |
|
| 365 | + //accounting.js library |
|
| 366 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 367 | + wp_register_script( |
|
| 368 | + 'ee-accounting-core', |
|
| 369 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 370 | + array('underscore'), |
|
| 371 | + '0.3.2', |
|
| 372 | + true |
|
| 373 | + ); |
|
| 374 | + wp_register_script( |
|
| 375 | + 'ee-accounting', |
|
| 376 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 377 | + array('ee-accounting-core'), |
|
| 378 | + EVENT_ESPRESSO_VERSION, |
|
| 379 | + true |
|
| 380 | + ); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * registers accounting.js for performing client-side calculations |
|
| 387 | + */ |
|
| 388 | + private function localizeAccountingJs() |
|
| 389 | + { |
|
| 390 | + wp_localize_script( |
|
| 391 | + 'ee-accounting', |
|
| 392 | + 'EE_ACCOUNTING_CFG', |
|
| 393 | + array( |
|
| 394 | + 'currency' => array( |
|
| 395 | + 'symbol' => $this->currency_config->sign, |
|
| 396 | + 'format' => array( |
|
| 397 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 398 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 399 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 400 | + ), |
|
| 401 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 402 | + 'thousand' => $this->currency_config->thsnds, |
|
| 403 | + 'precision' => $this->currency_config->dec_plc, |
|
| 404 | + ), |
|
| 405 | + 'number' => array( |
|
| 406 | + 'precision' => $this->currency_config->dec_plc, |
|
| 407 | + 'thousand' => $this->currency_config->thsnds, |
|
| 408 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 409 | + ), |
|
| 410 | + ) |
|
| 411 | + ); |
|
| 412 | + $this->addRegisteredScriptHandlesWithData('ee-accounting'); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * registers assets for cleaning your ears |
|
| 419 | + */ |
|
| 420 | + private function loadQtipJs() |
|
| 421 | + { |
|
| 422 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 423 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 424 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
| 425 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * This is used to set registered script handles that have data. |
|
| 432 | + * @param string $script_handle |
|
| 433 | + */ |
|
| 434 | + private function addRegisteredScriptHandlesWithData($script_handle) |
|
| 435 | + { |
|
| 436 | + $this->script_handles_with_data[$script_handle] = $script_handle; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
|
| 442 | + * Dependency stored in WP_Scripts if its set. |
|
| 443 | + */ |
|
| 444 | + private function removeAlreadyRegisteredDataForScriptHandles() |
|
| 445 | + { |
|
| 446 | + if (empty($this->script_handles_with_data)) { |
|
| 447 | + return; |
|
| 448 | + } |
|
| 449 | + foreach ($this->script_handles_with_data as $script_handle) { |
|
| 450 | + $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * Removes any data dependency registered in WP_Scripts if its set. |
|
| 457 | + * @param string $script_handle |
|
| 458 | + */ |
|
| 459 | + private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
| 460 | + { |
|
| 461 | + if (isset($this->script_handles_with_data[$script_handle])) { |
|
| 462 | + global $wp_scripts; |
|
| 463 | + if ($wp_scripts->get_data($script_handle, 'data')) { |
|
| 464 | + unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
| 465 | + unset($this->script_handles_with_data[$script_handle]); |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | 469 | |
| 470 | 470 | |
| 471 | 471 | } |
@@ -18,92 +18,92 @@ |
||
| 18 | 18 | class PostRelatedCacheManager extends BasicCacheManager |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @type string |
|
| 23 | - */ |
|
| 24 | - const POST_CACHE_PREFIX = 'ee_cache_post_'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * wp-option option_name for tracking post related cache |
|
| 28 | - * |
|
| 29 | - * @type string |
|
| 30 | - */ |
|
| 31 | - const POST_CACHE_OPTIONS_KEY = 'ee_post_cache'; |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * PostRelatedCacheManager constructor. |
|
| 37 | - * |
|
| 38 | - * @param CacheStorageInterface $cache_storage |
|
| 39 | - */ |
|
| 40 | - public function __construct(CacheStorageInterface $cache_storage) |
|
| 41 | - { |
|
| 42 | - parent::__construct($cache_storage); |
|
| 43 | - add_action('save_post', array($this, 'clearPostRelatedCache')); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * returns a string that will be prepended to all cache identifiers |
|
| 50 | - * |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - public function cachePrefix() |
|
| 54 | - { |
|
| 55 | - return PostRelatedCacheManager::POST_CACHE_PREFIX; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * If you are caching content that pertains to a Post of any type, |
|
| 62 | - * then it is recommended to pass the post id and cache id prefix to this method |
|
| 63 | - * so that it can be added to the post related cache tracking. |
|
| 64 | - * Then, whenever that post is updated, the cache will automatically be deleted, |
|
| 65 | - * which helps to ensure that outdated cache content will not be served |
|
| 66 | - * |
|
| 67 | - * @param int $post_ID [required] |
|
| 68 | - * @param string $id_prefix [required] Appended to all cache IDs. Can be helpful in finding specific cache types. |
|
| 69 | - * May also be helpful to include an additional specific identifier, |
|
| 70 | - * such as a post ID as part of the $id_prefix so that individual caches |
|
| 71 | - * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
| 72 | - * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
| 73 | - */ |
|
| 74 | - public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix) |
|
| 75 | - { |
|
| 76 | - $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
| 77 | - // if post is not already being tracked |
|
| 78 | - if ( ! isset($post_related_cache[$post_ID])) { |
|
| 79 | - // add array to add cache ids to |
|
| 80 | - $post_related_cache[$post_ID] = array(); |
|
| 81 | - } |
|
| 82 | - // add cache id to be tracked |
|
| 83 | - $post_related_cache[$post_ID][] = $id_prefix; |
|
| 84 | - update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * callback hooked into the WordPress "save_post" action |
|
| 91 | - * deletes any cache content associated with the post |
|
| 92 | - * |
|
| 93 | - * @param int $post_ID [required] |
|
| 94 | - */ |
|
| 95 | - public function clearPostRelatedCache($post_ID) |
|
| 96 | - { |
|
| 97 | - $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
| 98 | - // if post is not being tracked |
|
| 99 | - if ( ! isset($post_related_cache[$post_ID])) { |
|
| 100 | - return; |
|
| 101 | - } |
|
| 102 | - // get cache id prefixes for post, and delete their corresponding transients |
|
| 103 | - $this->clear($post_related_cache[$post_ID]); |
|
| 104 | - unset($post_related_cache[$post_ID]); |
|
| 105 | - update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache); |
|
| 106 | - } |
|
| 21 | + /** |
|
| 22 | + * @type string |
|
| 23 | + */ |
|
| 24 | + const POST_CACHE_PREFIX = 'ee_cache_post_'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * wp-option option_name for tracking post related cache |
|
| 28 | + * |
|
| 29 | + * @type string |
|
| 30 | + */ |
|
| 31 | + const POST_CACHE_OPTIONS_KEY = 'ee_post_cache'; |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * PostRelatedCacheManager constructor. |
|
| 37 | + * |
|
| 38 | + * @param CacheStorageInterface $cache_storage |
|
| 39 | + */ |
|
| 40 | + public function __construct(CacheStorageInterface $cache_storage) |
|
| 41 | + { |
|
| 42 | + parent::__construct($cache_storage); |
|
| 43 | + add_action('save_post', array($this, 'clearPostRelatedCache')); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * returns a string that will be prepended to all cache identifiers |
|
| 50 | + * |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + public function cachePrefix() |
|
| 54 | + { |
|
| 55 | + return PostRelatedCacheManager::POST_CACHE_PREFIX; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * If you are caching content that pertains to a Post of any type, |
|
| 62 | + * then it is recommended to pass the post id and cache id prefix to this method |
|
| 63 | + * so that it can be added to the post related cache tracking. |
|
| 64 | + * Then, whenever that post is updated, the cache will automatically be deleted, |
|
| 65 | + * which helps to ensure that outdated cache content will not be served |
|
| 66 | + * |
|
| 67 | + * @param int $post_ID [required] |
|
| 68 | + * @param string $id_prefix [required] Appended to all cache IDs. Can be helpful in finding specific cache types. |
|
| 69 | + * May also be helpful to include an additional specific identifier, |
|
| 70 | + * such as a post ID as part of the $id_prefix so that individual caches |
|
| 71 | + * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
| 72 | + * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
| 73 | + */ |
|
| 74 | + public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix) |
|
| 75 | + { |
|
| 76 | + $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
| 77 | + // if post is not already being tracked |
|
| 78 | + if ( ! isset($post_related_cache[$post_ID])) { |
|
| 79 | + // add array to add cache ids to |
|
| 80 | + $post_related_cache[$post_ID] = array(); |
|
| 81 | + } |
|
| 82 | + // add cache id to be tracked |
|
| 83 | + $post_related_cache[$post_ID][] = $id_prefix; |
|
| 84 | + update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * callback hooked into the WordPress "save_post" action |
|
| 91 | + * deletes any cache content associated with the post |
|
| 92 | + * |
|
| 93 | + * @param int $post_ID [required] |
|
| 94 | + */ |
|
| 95 | + public function clearPostRelatedCache($post_ID) |
|
| 96 | + { |
|
| 97 | + $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
| 98 | + // if post is not being tracked |
|
| 99 | + if ( ! isset($post_related_cache[$post_ID])) { |
|
| 100 | + return; |
|
| 101 | + } |
|
| 102 | + // get cache id prefixes for post, and delete their corresponding transients |
|
| 103 | + $this->clear($post_related_cache[$post_ID]); |
|
| 104 | + unset($post_related_cache[$post_ID]); |
|
| 105 | + update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | |
| 109 | 109 | } |
@@ -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 | |
@@ -21,731 +21,731 @@ discard block |
||
| 21 | 21 | class EE_Dependency_Map |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * This means that the requested class dependency is not present in the dependency map |
|
| 26 | - */ |
|
| 27 | - const not_registered = 0; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 31 | - */ |
|
| 32 | - const load_new_object = 1; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 36 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 37 | - */ |
|
| 38 | - const load_from_cache = 2; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * When registering a dependency, |
|
| 42 | - * this indicates to keep any existing dependencies that already exist, |
|
| 43 | - * and simply discard any new dependencies declared in the incoming data |
|
| 44 | - */ |
|
| 45 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * When registering a dependency, |
|
| 49 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 50 | - */ |
|
| 51 | - const OVERWRITE_DEPENDENCIES = 1; |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @type EE_Dependency_Map $_instance |
|
| 57 | - */ |
|
| 58 | - protected static $_instance; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @type EE_Request $request |
|
| 62 | - */ |
|
| 63 | - protected $_request; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @type EE_Response $response |
|
| 67 | - */ |
|
| 68 | - protected $_response; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @type LoaderInterface $loader |
|
| 72 | - */ |
|
| 73 | - protected $loader; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @type array $_dependency_map |
|
| 77 | - */ |
|
| 78 | - protected $_dependency_map = array(); |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @type array $_class_loaders |
|
| 82 | - */ |
|
| 83 | - protected $_class_loaders = array(); |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @type array $_aliases |
|
| 87 | - */ |
|
| 88 | - protected $_aliases = array(); |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * EE_Dependency_Map constructor. |
|
| 94 | - * |
|
| 95 | - * @param EE_Request $request |
|
| 96 | - * @param EE_Response $response |
|
| 97 | - */ |
|
| 98 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
| 99 | - { |
|
| 100 | - $this->_request = $request; |
|
| 101 | - $this->_response = $response; |
|
| 102 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 103 | - do_action('EE_Dependency_Map____construct'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @throws InvalidDataTypeException |
|
| 110 | - * @throws InvalidInterfaceException |
|
| 111 | - * @throws InvalidArgumentException |
|
| 112 | - */ |
|
| 113 | - public function initialize() |
|
| 114 | - { |
|
| 115 | - $this->_register_core_dependencies(); |
|
| 116 | - $this->_register_core_class_loaders(); |
|
| 117 | - $this->_register_core_aliases(); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @singleton method used to instantiate class object |
|
| 124 | - * @access public |
|
| 125 | - * @param EE_Request $request |
|
| 126 | - * @param EE_Response $response |
|
| 127 | - * @return EE_Dependency_Map |
|
| 128 | - */ |
|
| 129 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 130 | - { |
|
| 131 | - // check if class object is instantiated, and instantiated properly |
|
| 132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 133 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 134 | - } |
|
| 135 | - return self::$_instance; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param LoaderInterface $loader |
|
| 142 | - */ |
|
| 143 | - public function setLoader(LoaderInterface $loader) |
|
| 144 | - { |
|
| 145 | - $this->loader = $loader; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @param string $class |
|
| 152 | - * @param array $dependencies |
|
| 153 | - * @param int $overwrite |
|
| 154 | - * @return bool |
|
| 155 | - */ |
|
| 156 | - public static function register_dependencies( |
|
| 157 | - $class, |
|
| 158 | - array $dependencies, |
|
| 159 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 160 | - ) { |
|
| 161 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 168 | - * to the class specified by the first parameter. |
|
| 169 | - * IMPORTANT !!! |
|
| 170 | - * The order of elements in the incoming $dependencies array MUST match |
|
| 171 | - * the order of the constructor parameters for the class in question. |
|
| 172 | - * This is especially important when overriding any existing dependencies that are registered. |
|
| 173 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 174 | - * |
|
| 175 | - * @param string $class |
|
| 176 | - * @param array $dependencies |
|
| 177 | - * @param int $overwrite |
|
| 178 | - * @return bool |
|
| 179 | - */ |
|
| 180 | - public function registerDependencies( |
|
| 181 | - $class, |
|
| 182 | - array $dependencies, |
|
| 183 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 184 | - ) { |
|
| 185 | - $registered = false; |
|
| 186 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 187 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
| 188 | - } |
|
| 189 | - // we need to make sure that any aliases used when registering a dependency |
|
| 190 | - // get resolved to the correct class name |
|
| 191 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 192 | - $alias = self::$_instance->get_alias($dependency); |
|
| 193 | - if ( |
|
| 194 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 195 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 196 | - ) { |
|
| 197 | - unset($dependencies[$dependency]); |
|
| 198 | - $dependencies[$alias] = $load_source; |
|
| 199 | - $registered = true; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - // now add our two lists of dependencies together. |
|
| 203 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
| 204 | - // so $dependencies is NOT overwritten because it is listed first |
|
| 205 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 206 | - // Union is way faster than array_merge() but should be used with caution... |
|
| 207 | - // especially with numerically indexed arrays |
|
| 208 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 209 | - // now we need to ensure that the resulting dependencies |
|
| 210 | - // array only has the entries that are required for the class |
|
| 211 | - // so first count how many dependencies were originally registered for the class |
|
| 212 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 213 | - // if that count is non-zero (meaning dependencies were already registered) |
|
| 214 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 215 | - // then truncate the final array to match that count |
|
| 216 | - ? array_slice($dependencies, 0, $dependency_count) |
|
| 217 | - // otherwise just take the incoming array because nothing previously existed |
|
| 218 | - : $dependencies; |
|
| 219 | - return $registered; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @param string $class_name |
|
| 226 | - * @param string $loader |
|
| 227 | - * @return bool |
|
| 228 | - * @throws DomainException |
|
| 229 | - */ |
|
| 230 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 231 | - { |
|
| 232 | - if (strpos($class_name, '\\') !== false) { |
|
| 233 | - throw new DomainException( |
|
| 234 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 235 | - ); |
|
| 236 | - } |
|
| 237 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 238 | - if ( |
|
| 239 | - ! is_callable($loader) |
|
| 240 | - && ( |
|
| 241 | - strpos($loader, 'load_') !== 0 |
|
| 242 | - || ! method_exists('EE_Registry', $loader) |
|
| 243 | - ) |
|
| 244 | - ) { |
|
| 245 | - throw new DomainException( |
|
| 246 | - sprintf( |
|
| 247 | - esc_html__( |
|
| 248 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 249 | - 'event_espresso' |
|
| 250 | - ), |
|
| 251 | - $loader |
|
| 252 | - ) |
|
| 253 | - ); |
|
| 254 | - } |
|
| 255 | - $class_name = self::$_instance->get_alias($class_name); |
|
| 256 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 257 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 258 | - return true; |
|
| 259 | - } |
|
| 260 | - return false; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * @return array |
|
| 267 | - */ |
|
| 268 | - public function dependency_map() |
|
| 269 | - { |
|
| 270 | - return $this->_dependency_map; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 277 | - * |
|
| 278 | - * @param string $class_name |
|
| 279 | - * @return boolean |
|
| 280 | - */ |
|
| 281 | - public function has($class_name = '') |
|
| 282 | - { |
|
| 283 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 290 | - * |
|
| 291 | - * @param string $class_name |
|
| 292 | - * @param string $dependency |
|
| 293 | - * @return bool |
|
| 294 | - */ |
|
| 295 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 296 | - { |
|
| 297 | - $dependency = $this->get_alias($dependency); |
|
| 298 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 299 | - ? true |
|
| 300 | - : false; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 307 | - * |
|
| 308 | - * @param string $class_name |
|
| 309 | - * @param string $dependency |
|
| 310 | - * @return int |
|
| 311 | - */ |
|
| 312 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 313 | - { |
|
| 314 | - $dependency = $this->get_alias($dependency); |
|
| 315 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 316 | - ? $this->_dependency_map[$class_name][$dependency] |
|
| 317 | - : EE_Dependency_Map::not_registered; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * @param string $class_name |
|
| 324 | - * @return string | Closure |
|
| 325 | - */ |
|
| 326 | - public function class_loader($class_name) |
|
| 327 | - { |
|
| 328 | - // don't use loaders for FQCNs |
|
| 329 | - if(strpos($class_name, '\\') !== false){ |
|
| 330 | - return ''; |
|
| 331 | - } |
|
| 332 | - $class_name = $this->get_alias($class_name); |
|
| 333 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * @return array |
|
| 340 | - */ |
|
| 341 | - public function class_loaders() |
|
| 342 | - { |
|
| 343 | - return $this->_class_loaders; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * adds an alias for a classname |
|
| 350 | - * |
|
| 351 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 352 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 353 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 354 | - */ |
|
| 355 | - public function add_alias($class_name, $alias, $for_class = '') |
|
| 356 | - { |
|
| 357 | - if ($for_class !== '') { |
|
| 358 | - if (! isset($this->_aliases[$for_class])) { |
|
| 359 | - $this->_aliases[$for_class] = array(); |
|
| 360 | - } |
|
| 361 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
| 362 | - } |
|
| 363 | - $this->_aliases[$class_name] = $alias; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * returns TRUE if the provided class name has an alias |
|
| 370 | - * |
|
| 371 | - * @param string $class_name |
|
| 372 | - * @param string $for_class |
|
| 373 | - * @return bool |
|
| 374 | - */ |
|
| 375 | - public function has_alias($class_name = '', $for_class = '') |
|
| 376 | - { |
|
| 377 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 378 | - || ( |
|
| 379 | - isset($this->_aliases[$class_name]) |
|
| 380 | - && ! is_array($this->_aliases[$class_name]) |
|
| 381 | - ); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
| 388 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 389 | - * for example: |
|
| 390 | - * if the following two entries were added to the _aliases array: |
|
| 391 | - * array( |
|
| 392 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 393 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 394 | - * ) |
|
| 395 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 396 | - * to load an instance of 'some\namespace\classname' |
|
| 397 | - * |
|
| 398 | - * @param string $class_name |
|
| 399 | - * @param string $for_class |
|
| 400 | - * @return string |
|
| 401 | - */ |
|
| 402 | - public function get_alias($class_name = '', $for_class = '') |
|
| 403 | - { |
|
| 404 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 405 | - return $class_name; |
|
| 406 | - } |
|
| 407 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 408 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 409 | - } |
|
| 410 | - return $this->get_alias($this->_aliases[$class_name]); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 417 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 418 | - * This is done by using the following class constants: |
|
| 419 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 420 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 421 | - */ |
|
| 422 | - protected function _register_core_dependencies() |
|
| 423 | - { |
|
| 424 | - $this->_dependency_map = array( |
|
| 425 | - 'EE_Request_Handler' => array( |
|
| 426 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 427 | - ), |
|
| 428 | - 'EE_System' => array( |
|
| 429 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 430 | - ), |
|
| 431 | - 'EE_Session' => array( |
|
| 432 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 433 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 434 | - ), |
|
| 435 | - 'EE_Cart' => array( |
|
| 436 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 437 | - ), |
|
| 438 | - 'EE_Front_Controller' => array( |
|
| 439 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 440 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 441 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 442 | - ), |
|
| 443 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 444 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 445 | - ), |
|
| 446 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 447 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 448 | - ), |
|
| 449 | - 'EE_Message_Resource_Manager' => array( |
|
| 450 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 451 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 452 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 453 | - ), |
|
| 454 | - 'EE_Message_Factory' => array( |
|
| 455 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 456 | - ), |
|
| 457 | - 'EE_messages' => array( |
|
| 458 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 459 | - ), |
|
| 460 | - 'EE_Messages_Generator' => array( |
|
| 461 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 462 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 463 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 464 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 465 | - ), |
|
| 466 | - 'EE_Messages_Processor' => array( |
|
| 467 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 468 | - ), |
|
| 469 | - 'EE_Messages_Queue' => array( |
|
| 470 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 471 | - ), |
|
| 472 | - 'EE_Messages_Template_Defaults' => array( |
|
| 473 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 474 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 475 | - ), |
|
| 476 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 477 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 478 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 479 | - ), |
|
| 480 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 481 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 482 | - ), |
|
| 483 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 484 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 485 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 486 | - ), |
|
| 487 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 488 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 489 | - ), |
|
| 490 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 491 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 492 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 493 | - ), |
|
| 494 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 495 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 496 | - ), |
|
| 497 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 498 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 499 | - ), |
|
| 500 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 501 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 502 | - ), |
|
| 503 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 504 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 505 | - ), |
|
| 506 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 507 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 508 | - ), |
|
| 509 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 510 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 511 | - ), |
|
| 512 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 513 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 514 | - ), |
|
| 515 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 516 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 517 | - ), |
|
| 518 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 519 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 520 | - ), |
|
| 521 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 522 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 523 | - ), |
|
| 524 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 525 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 526 | - ), |
|
| 527 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 528 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 529 | - ), |
|
| 530 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 531 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 532 | - ), |
|
| 533 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 534 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 535 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 536 | - ), |
|
| 537 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 538 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 539 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 540 | - ), |
|
| 541 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 542 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 543 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 544 | - ), |
|
| 545 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 546 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 547 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 548 | - ), |
|
| 549 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 550 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 551 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 552 | - ), |
|
| 553 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 554 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 555 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 556 | - ), |
|
| 557 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 558 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 559 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 560 | - ), |
|
| 561 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 562 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 563 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 564 | - ), |
|
| 565 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 566 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 567 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 568 | - ), |
|
| 569 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 570 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 571 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 572 | - ), |
|
| 573 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
| 574 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 575 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 576 | - ), |
|
| 577 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 578 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 579 | - ), |
|
| 580 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 581 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 582 | - ), |
|
| 583 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 584 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 585 | - ), |
|
| 586 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 587 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 588 | - ), |
|
| 589 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 590 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 591 | - ), |
|
| 592 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 593 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 594 | - ), |
|
| 595 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 596 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 597 | - ), |
|
| 598 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 599 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 600 | - ), |
|
| 601 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 602 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 603 | - ), |
|
| 604 | - ); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * Registers how core classes are loaded. |
|
| 611 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 612 | - * 'EE_Request_Handler' => 'load_core' |
|
| 613 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 614 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 615 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 616 | - * 'Some_Class' => function () { |
|
| 617 | - * return new Some_Class(); |
|
| 618 | - * }, |
|
| 619 | - * This is required for instantiating dependencies |
|
| 620 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 621 | - * 'Required_Interface' => function () { |
|
| 622 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 623 | - * }, |
|
| 624 | - */ |
|
| 625 | - protected function _register_core_class_loaders() |
|
| 626 | - { |
|
| 627 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 628 | - //be used in a closure. |
|
| 629 | - $request = &$this->_request; |
|
| 630 | - $response = &$this->_response; |
|
| 631 | - $loader = &$this->loader; |
|
| 632 | - $this->_class_loaders = array( |
|
| 633 | - //load_core |
|
| 634 | - 'EE_Capabilities' => 'load_core', |
|
| 635 | - 'EE_Encryption' => 'load_core', |
|
| 636 | - 'EE_Front_Controller' => 'load_core', |
|
| 637 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 638 | - 'EE_Registry' => 'load_core', |
|
| 639 | - 'EE_Request' => function () use (&$request) { |
|
| 640 | - return $request; |
|
| 641 | - }, |
|
| 642 | - 'EE_Response' => function () use (&$response) { |
|
| 643 | - return $response; |
|
| 644 | - }, |
|
| 645 | - 'EE_Request_Handler' => 'load_core', |
|
| 646 | - 'EE_Session' => 'load_core', |
|
| 647 | - 'EE_System' => 'load_core', |
|
| 648 | - //load_lib |
|
| 649 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 650 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 651 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 652 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 653 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 654 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 655 | - 'EE_Message_Repository' => 'load_lib', |
|
| 656 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 657 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 658 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 659 | - 'EE_Messages_Generator' => function () { |
|
| 660 | - return EE_Registry::instance()->load_lib( |
|
| 661 | - 'Messages_Generator', |
|
| 662 | - array(), |
|
| 663 | - false, |
|
| 664 | - false |
|
| 665 | - ); |
|
| 666 | - }, |
|
| 667 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 668 | - return EE_Registry::instance()->load_lib( |
|
| 669 | - 'Messages_Template_Defaults', |
|
| 670 | - $arguments, |
|
| 671 | - false, |
|
| 672 | - false |
|
| 673 | - ); |
|
| 674 | - }, |
|
| 675 | - //load_model |
|
| 676 | - 'EEM_Message_Template_Group' => 'load_model', |
|
| 677 | - 'EEM_Message_Template' => 'load_model', |
|
| 678 | - //load_helper |
|
| 679 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 680 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 681 | - return new EEH_Parse_Shortcodes(); |
|
| 682 | - } |
|
| 683 | - return null; |
|
| 684 | - }, |
|
| 685 | - 'EE_Template_Config' => function () { |
|
| 686 | - return EE_Config::instance()->template_settings; |
|
| 687 | - }, |
|
| 688 | - 'EE_Currency_Config' => function () { |
|
| 689 | - return EE_Config::instance()->currency; |
|
| 690 | - }, |
|
| 691 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
| 692 | - return $loader; |
|
| 693 | - }, |
|
| 694 | - ); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * can be used for supplying alternate names for classes, |
|
| 701 | - * or for connecting interface names to instantiable classes |
|
| 702 | - */ |
|
| 703 | - protected function _register_core_aliases() |
|
| 704 | - { |
|
| 705 | - $this->_aliases = array( |
|
| 706 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 707 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 708 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 709 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 710 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 711 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 712 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 713 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 714 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 715 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 716 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 717 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 718 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 719 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 720 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 721 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 722 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 723 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 724 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 725 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 726 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 727 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 728 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 729 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 730 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 731 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 732 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 733 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 734 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 735 | - ); |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 742 | - * request Primarily used by unit tests. |
|
| 743 | - */ |
|
| 744 | - public function reset() |
|
| 745 | - { |
|
| 746 | - $this->_register_core_class_loaders(); |
|
| 747 | - $this->_register_core_dependencies(); |
|
| 748 | - } |
|
| 24 | + /** |
|
| 25 | + * This means that the requested class dependency is not present in the dependency map |
|
| 26 | + */ |
|
| 27 | + const not_registered = 0; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 31 | + */ |
|
| 32 | + const load_new_object = 1; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 36 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 37 | + */ |
|
| 38 | + const load_from_cache = 2; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * When registering a dependency, |
|
| 42 | + * this indicates to keep any existing dependencies that already exist, |
|
| 43 | + * and simply discard any new dependencies declared in the incoming data |
|
| 44 | + */ |
|
| 45 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * When registering a dependency, |
|
| 49 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 50 | + */ |
|
| 51 | + const OVERWRITE_DEPENDENCIES = 1; |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @type EE_Dependency_Map $_instance |
|
| 57 | + */ |
|
| 58 | + protected static $_instance; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @type EE_Request $request |
|
| 62 | + */ |
|
| 63 | + protected $_request; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @type EE_Response $response |
|
| 67 | + */ |
|
| 68 | + protected $_response; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @type LoaderInterface $loader |
|
| 72 | + */ |
|
| 73 | + protected $loader; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @type array $_dependency_map |
|
| 77 | + */ |
|
| 78 | + protected $_dependency_map = array(); |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @type array $_class_loaders |
|
| 82 | + */ |
|
| 83 | + protected $_class_loaders = array(); |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @type array $_aliases |
|
| 87 | + */ |
|
| 88 | + protected $_aliases = array(); |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * EE_Dependency_Map constructor. |
|
| 94 | + * |
|
| 95 | + * @param EE_Request $request |
|
| 96 | + * @param EE_Response $response |
|
| 97 | + */ |
|
| 98 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
| 99 | + { |
|
| 100 | + $this->_request = $request; |
|
| 101 | + $this->_response = $response; |
|
| 102 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 103 | + do_action('EE_Dependency_Map____construct'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @throws InvalidDataTypeException |
|
| 110 | + * @throws InvalidInterfaceException |
|
| 111 | + * @throws InvalidArgumentException |
|
| 112 | + */ |
|
| 113 | + public function initialize() |
|
| 114 | + { |
|
| 115 | + $this->_register_core_dependencies(); |
|
| 116 | + $this->_register_core_class_loaders(); |
|
| 117 | + $this->_register_core_aliases(); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @singleton method used to instantiate class object |
|
| 124 | + * @access public |
|
| 125 | + * @param EE_Request $request |
|
| 126 | + * @param EE_Response $response |
|
| 127 | + * @return EE_Dependency_Map |
|
| 128 | + */ |
|
| 129 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 130 | + { |
|
| 131 | + // check if class object is instantiated, and instantiated properly |
|
| 132 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 133 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 134 | + } |
|
| 135 | + return self::$_instance; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param LoaderInterface $loader |
|
| 142 | + */ |
|
| 143 | + public function setLoader(LoaderInterface $loader) |
|
| 144 | + { |
|
| 145 | + $this->loader = $loader; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @param string $class |
|
| 152 | + * @param array $dependencies |
|
| 153 | + * @param int $overwrite |
|
| 154 | + * @return bool |
|
| 155 | + */ |
|
| 156 | + public static function register_dependencies( |
|
| 157 | + $class, |
|
| 158 | + array $dependencies, |
|
| 159 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 160 | + ) { |
|
| 161 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 168 | + * to the class specified by the first parameter. |
|
| 169 | + * IMPORTANT !!! |
|
| 170 | + * The order of elements in the incoming $dependencies array MUST match |
|
| 171 | + * the order of the constructor parameters for the class in question. |
|
| 172 | + * This is especially important when overriding any existing dependencies that are registered. |
|
| 173 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 174 | + * |
|
| 175 | + * @param string $class |
|
| 176 | + * @param array $dependencies |
|
| 177 | + * @param int $overwrite |
|
| 178 | + * @return bool |
|
| 179 | + */ |
|
| 180 | + public function registerDependencies( |
|
| 181 | + $class, |
|
| 182 | + array $dependencies, |
|
| 183 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 184 | + ) { |
|
| 185 | + $registered = false; |
|
| 186 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 187 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
| 188 | + } |
|
| 189 | + // we need to make sure that any aliases used when registering a dependency |
|
| 190 | + // get resolved to the correct class name |
|
| 191 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 192 | + $alias = self::$_instance->get_alias($dependency); |
|
| 193 | + if ( |
|
| 194 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 195 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 196 | + ) { |
|
| 197 | + unset($dependencies[$dependency]); |
|
| 198 | + $dependencies[$alias] = $load_source; |
|
| 199 | + $registered = true; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + // now add our two lists of dependencies together. |
|
| 203 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
| 204 | + // so $dependencies is NOT overwritten because it is listed first |
|
| 205 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 206 | + // Union is way faster than array_merge() but should be used with caution... |
|
| 207 | + // especially with numerically indexed arrays |
|
| 208 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 209 | + // now we need to ensure that the resulting dependencies |
|
| 210 | + // array only has the entries that are required for the class |
|
| 211 | + // so first count how many dependencies were originally registered for the class |
|
| 212 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 213 | + // if that count is non-zero (meaning dependencies were already registered) |
|
| 214 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 215 | + // then truncate the final array to match that count |
|
| 216 | + ? array_slice($dependencies, 0, $dependency_count) |
|
| 217 | + // otherwise just take the incoming array because nothing previously existed |
|
| 218 | + : $dependencies; |
|
| 219 | + return $registered; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @param string $class_name |
|
| 226 | + * @param string $loader |
|
| 227 | + * @return bool |
|
| 228 | + * @throws DomainException |
|
| 229 | + */ |
|
| 230 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 231 | + { |
|
| 232 | + if (strpos($class_name, '\\') !== false) { |
|
| 233 | + throw new DomainException( |
|
| 234 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 235 | + ); |
|
| 236 | + } |
|
| 237 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 238 | + if ( |
|
| 239 | + ! is_callable($loader) |
|
| 240 | + && ( |
|
| 241 | + strpos($loader, 'load_') !== 0 |
|
| 242 | + || ! method_exists('EE_Registry', $loader) |
|
| 243 | + ) |
|
| 244 | + ) { |
|
| 245 | + throw new DomainException( |
|
| 246 | + sprintf( |
|
| 247 | + esc_html__( |
|
| 248 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 249 | + 'event_espresso' |
|
| 250 | + ), |
|
| 251 | + $loader |
|
| 252 | + ) |
|
| 253 | + ); |
|
| 254 | + } |
|
| 255 | + $class_name = self::$_instance->get_alias($class_name); |
|
| 256 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 257 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 258 | + return true; |
|
| 259 | + } |
|
| 260 | + return false; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * @return array |
|
| 267 | + */ |
|
| 268 | + public function dependency_map() |
|
| 269 | + { |
|
| 270 | + return $this->_dependency_map; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 277 | + * |
|
| 278 | + * @param string $class_name |
|
| 279 | + * @return boolean |
|
| 280 | + */ |
|
| 281 | + public function has($class_name = '') |
|
| 282 | + { |
|
| 283 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 290 | + * |
|
| 291 | + * @param string $class_name |
|
| 292 | + * @param string $dependency |
|
| 293 | + * @return bool |
|
| 294 | + */ |
|
| 295 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 296 | + { |
|
| 297 | + $dependency = $this->get_alias($dependency); |
|
| 298 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 299 | + ? true |
|
| 300 | + : false; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 307 | + * |
|
| 308 | + * @param string $class_name |
|
| 309 | + * @param string $dependency |
|
| 310 | + * @return int |
|
| 311 | + */ |
|
| 312 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 313 | + { |
|
| 314 | + $dependency = $this->get_alias($dependency); |
|
| 315 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 316 | + ? $this->_dependency_map[$class_name][$dependency] |
|
| 317 | + : EE_Dependency_Map::not_registered; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * @param string $class_name |
|
| 324 | + * @return string | Closure |
|
| 325 | + */ |
|
| 326 | + public function class_loader($class_name) |
|
| 327 | + { |
|
| 328 | + // don't use loaders for FQCNs |
|
| 329 | + if(strpos($class_name, '\\') !== false){ |
|
| 330 | + return ''; |
|
| 331 | + } |
|
| 332 | + $class_name = $this->get_alias($class_name); |
|
| 333 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * @return array |
|
| 340 | + */ |
|
| 341 | + public function class_loaders() |
|
| 342 | + { |
|
| 343 | + return $this->_class_loaders; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * adds an alias for a classname |
|
| 350 | + * |
|
| 351 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 352 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 353 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 354 | + */ |
|
| 355 | + public function add_alias($class_name, $alias, $for_class = '') |
|
| 356 | + { |
|
| 357 | + if ($for_class !== '') { |
|
| 358 | + if (! isset($this->_aliases[$for_class])) { |
|
| 359 | + $this->_aliases[$for_class] = array(); |
|
| 360 | + } |
|
| 361 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
| 362 | + } |
|
| 363 | + $this->_aliases[$class_name] = $alias; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * returns TRUE if the provided class name has an alias |
|
| 370 | + * |
|
| 371 | + * @param string $class_name |
|
| 372 | + * @param string $for_class |
|
| 373 | + * @return bool |
|
| 374 | + */ |
|
| 375 | + public function has_alias($class_name = '', $for_class = '') |
|
| 376 | + { |
|
| 377 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 378 | + || ( |
|
| 379 | + isset($this->_aliases[$class_name]) |
|
| 380 | + && ! is_array($this->_aliases[$class_name]) |
|
| 381 | + ); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
| 388 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 389 | + * for example: |
|
| 390 | + * if the following two entries were added to the _aliases array: |
|
| 391 | + * array( |
|
| 392 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 393 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 394 | + * ) |
|
| 395 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 396 | + * to load an instance of 'some\namespace\classname' |
|
| 397 | + * |
|
| 398 | + * @param string $class_name |
|
| 399 | + * @param string $for_class |
|
| 400 | + * @return string |
|
| 401 | + */ |
|
| 402 | + public function get_alias($class_name = '', $for_class = '') |
|
| 403 | + { |
|
| 404 | + if (! $this->has_alias($class_name, $for_class)) { |
|
| 405 | + return $class_name; |
|
| 406 | + } |
|
| 407 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 408 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 409 | + } |
|
| 410 | + return $this->get_alias($this->_aliases[$class_name]); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 417 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 418 | + * This is done by using the following class constants: |
|
| 419 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 420 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 421 | + */ |
|
| 422 | + protected function _register_core_dependencies() |
|
| 423 | + { |
|
| 424 | + $this->_dependency_map = array( |
|
| 425 | + 'EE_Request_Handler' => array( |
|
| 426 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 427 | + ), |
|
| 428 | + 'EE_System' => array( |
|
| 429 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 430 | + ), |
|
| 431 | + 'EE_Session' => array( |
|
| 432 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 433 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 434 | + ), |
|
| 435 | + 'EE_Cart' => array( |
|
| 436 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 437 | + ), |
|
| 438 | + 'EE_Front_Controller' => array( |
|
| 439 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 440 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 441 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 442 | + ), |
|
| 443 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 444 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 445 | + ), |
|
| 446 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 447 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 448 | + ), |
|
| 449 | + 'EE_Message_Resource_Manager' => array( |
|
| 450 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 451 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 452 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 453 | + ), |
|
| 454 | + 'EE_Message_Factory' => array( |
|
| 455 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 456 | + ), |
|
| 457 | + 'EE_messages' => array( |
|
| 458 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 459 | + ), |
|
| 460 | + 'EE_Messages_Generator' => array( |
|
| 461 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 462 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 463 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 464 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 465 | + ), |
|
| 466 | + 'EE_Messages_Processor' => array( |
|
| 467 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 468 | + ), |
|
| 469 | + 'EE_Messages_Queue' => array( |
|
| 470 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 471 | + ), |
|
| 472 | + 'EE_Messages_Template_Defaults' => array( |
|
| 473 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 474 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 475 | + ), |
|
| 476 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 477 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 478 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 479 | + ), |
|
| 480 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 481 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 482 | + ), |
|
| 483 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 484 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 485 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 486 | + ), |
|
| 487 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 488 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 489 | + ), |
|
| 490 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 491 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 492 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 493 | + ), |
|
| 494 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 495 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 496 | + ), |
|
| 497 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 498 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 499 | + ), |
|
| 500 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 501 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 502 | + ), |
|
| 503 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 504 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 505 | + ), |
|
| 506 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 507 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 508 | + ), |
|
| 509 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 510 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 511 | + ), |
|
| 512 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 513 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 514 | + ), |
|
| 515 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 516 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 517 | + ), |
|
| 518 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 519 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 520 | + ), |
|
| 521 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 522 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 523 | + ), |
|
| 524 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 525 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 526 | + ), |
|
| 527 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 528 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 529 | + ), |
|
| 530 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 531 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 532 | + ), |
|
| 533 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 534 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 535 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 536 | + ), |
|
| 537 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 538 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 539 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 540 | + ), |
|
| 541 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 542 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 543 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 544 | + ), |
|
| 545 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 546 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 547 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 548 | + ), |
|
| 549 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 550 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 551 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 552 | + ), |
|
| 553 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 554 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 555 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 556 | + ), |
|
| 557 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 558 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 559 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 560 | + ), |
|
| 561 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 562 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 563 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 564 | + ), |
|
| 565 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 566 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 567 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 568 | + ), |
|
| 569 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 570 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 571 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 572 | + ), |
|
| 573 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
| 574 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 575 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 576 | + ), |
|
| 577 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 578 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 579 | + ), |
|
| 580 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 581 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 582 | + ), |
|
| 583 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 584 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 585 | + ), |
|
| 586 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 587 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 588 | + ), |
|
| 589 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 590 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 591 | + ), |
|
| 592 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 593 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 594 | + ), |
|
| 595 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 596 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 597 | + ), |
|
| 598 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 599 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 600 | + ), |
|
| 601 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 602 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 603 | + ), |
|
| 604 | + ); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * Registers how core classes are loaded. |
|
| 611 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 612 | + * 'EE_Request_Handler' => 'load_core' |
|
| 613 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 614 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 615 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 616 | + * 'Some_Class' => function () { |
|
| 617 | + * return new Some_Class(); |
|
| 618 | + * }, |
|
| 619 | + * This is required for instantiating dependencies |
|
| 620 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 621 | + * 'Required_Interface' => function () { |
|
| 622 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 623 | + * }, |
|
| 624 | + */ |
|
| 625 | + protected function _register_core_class_loaders() |
|
| 626 | + { |
|
| 627 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 628 | + //be used in a closure. |
|
| 629 | + $request = &$this->_request; |
|
| 630 | + $response = &$this->_response; |
|
| 631 | + $loader = &$this->loader; |
|
| 632 | + $this->_class_loaders = array( |
|
| 633 | + //load_core |
|
| 634 | + 'EE_Capabilities' => 'load_core', |
|
| 635 | + 'EE_Encryption' => 'load_core', |
|
| 636 | + 'EE_Front_Controller' => 'load_core', |
|
| 637 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 638 | + 'EE_Registry' => 'load_core', |
|
| 639 | + 'EE_Request' => function () use (&$request) { |
|
| 640 | + return $request; |
|
| 641 | + }, |
|
| 642 | + 'EE_Response' => function () use (&$response) { |
|
| 643 | + return $response; |
|
| 644 | + }, |
|
| 645 | + 'EE_Request_Handler' => 'load_core', |
|
| 646 | + 'EE_Session' => 'load_core', |
|
| 647 | + 'EE_System' => 'load_core', |
|
| 648 | + //load_lib |
|
| 649 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 650 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 651 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 652 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 653 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 654 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 655 | + 'EE_Message_Repository' => 'load_lib', |
|
| 656 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 657 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 658 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 659 | + 'EE_Messages_Generator' => function () { |
|
| 660 | + return EE_Registry::instance()->load_lib( |
|
| 661 | + 'Messages_Generator', |
|
| 662 | + array(), |
|
| 663 | + false, |
|
| 664 | + false |
|
| 665 | + ); |
|
| 666 | + }, |
|
| 667 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 668 | + return EE_Registry::instance()->load_lib( |
|
| 669 | + 'Messages_Template_Defaults', |
|
| 670 | + $arguments, |
|
| 671 | + false, |
|
| 672 | + false |
|
| 673 | + ); |
|
| 674 | + }, |
|
| 675 | + //load_model |
|
| 676 | + 'EEM_Message_Template_Group' => 'load_model', |
|
| 677 | + 'EEM_Message_Template' => 'load_model', |
|
| 678 | + //load_helper |
|
| 679 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 680 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 681 | + return new EEH_Parse_Shortcodes(); |
|
| 682 | + } |
|
| 683 | + return null; |
|
| 684 | + }, |
|
| 685 | + 'EE_Template_Config' => function () { |
|
| 686 | + return EE_Config::instance()->template_settings; |
|
| 687 | + }, |
|
| 688 | + 'EE_Currency_Config' => function () { |
|
| 689 | + return EE_Config::instance()->currency; |
|
| 690 | + }, |
|
| 691 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
| 692 | + return $loader; |
|
| 693 | + }, |
|
| 694 | + ); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * can be used for supplying alternate names for classes, |
|
| 701 | + * or for connecting interface names to instantiable classes |
|
| 702 | + */ |
|
| 703 | + protected function _register_core_aliases() |
|
| 704 | + { |
|
| 705 | + $this->_aliases = array( |
|
| 706 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 707 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 708 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 709 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 710 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 711 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 712 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 713 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 714 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 715 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 716 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 717 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 718 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 719 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 720 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 721 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 722 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 723 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 724 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 725 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 726 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 727 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 728 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 729 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 730 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 731 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 732 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 733 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 734 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 735 | + ); |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 742 | + * request Primarily used by unit tests. |
|
| 743 | + */ |
|
| 744 | + public function reset() |
|
| 745 | + { |
|
| 746 | + $this->_register_core_class_loaders(); |
|
| 747 | + $this->_register_core_dependencies(); |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | 750 | |
| 751 | 751 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('ABSPATH')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /* |
| 5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
| 40 | 40 | * @since 4.0 |
| 41 | 41 | */ |
| 42 | 42 | if (function_exists('espresso_version')) { |
| 43 | - /** |
|
| 44 | - * espresso_duplicate_plugin_error |
|
| 45 | - * displays if more than one version of EE is activated at the same time |
|
| 46 | - */ |
|
| 47 | - function espresso_duplicate_plugin_error() |
|
| 48 | - { |
|
| 49 | - ?> |
|
| 43 | + /** |
|
| 44 | + * espresso_duplicate_plugin_error |
|
| 45 | + * displays if more than one version of EE is activated at the same time |
|
| 46 | + */ |
|
| 47 | + function espresso_duplicate_plugin_error() |
|
| 48 | + { |
|
| 49 | + ?> |
|
| 50 | 50 | <div class="error"> |
| 51 | 51 | <p> |
| 52 | 52 | <?php echo esc_html__( |
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - /** |
|
| 97 | - * espresso_version |
|
| 98 | - * Returns the plugin version |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - function espresso_version() |
|
| 103 | - { |
|
| 104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.44.rc.010'); |
|
| 105 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + /** |
|
| 97 | + * espresso_version |
|
| 98 | + * Returns the plugin version |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + function espresso_version() |
|
| 103 | + { |
|
| 104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.44.rc.010'); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - // define versions |
|
| 108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | - if ( ! defined('DS')) { |
|
| 115 | - define('DS', '/'); |
|
| 116 | - } |
|
| 117 | - if ( ! defined('PS')) { |
|
| 118 | - define('PS', PATH_SEPARATOR); |
|
| 119 | - } |
|
| 120 | - if ( ! defined('SP')) { |
|
| 121 | - define('SP', ' '); |
|
| 122 | - } |
|
| 123 | - if ( ! defined('EENL')) { |
|
| 124 | - define('EENL', "\n"); |
|
| 125 | - } |
|
| 126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | - // define the plugin directory and URL |
|
| 128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | - // main root folder paths |
|
| 132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | - // core system paths |
|
| 141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | - // gateways |
|
| 154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | - // asset URL paths |
|
| 157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | - // define upload paths |
|
| 164 | - $uploads = wp_upload_dir(); |
|
| 165 | - // define the uploads directory and URL |
|
| 166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | - // define the templates directory and URL |
|
| 169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | - // define the gateway directory and URL |
|
| 172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | - // languages folder/path |
|
| 175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | - //check for dompdf fonts in uploads |
|
| 178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | - } |
|
| 181 | - //ajax constants |
|
| 182 | - define( |
|
| 183 | - 'EE_FRONT_AJAX', |
|
| 184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | - ); |
|
| 186 | - define( |
|
| 187 | - 'EE_ADMIN_AJAX', |
|
| 188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | - ); |
|
| 190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | - //want to change its default value! or find when -1 means infinity |
|
| 193 | - define('EE_INF_IN_DB', -1); |
|
| 194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | - define('EE_DEBUG', false); |
|
| 196 | - // for older WP versions |
|
| 197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
| 198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 199 | - } |
|
| 200 | - /** |
|
| 201 | - * espresso_plugin_activation |
|
| 202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 203 | - */ |
|
| 204 | - function espresso_plugin_activation() |
|
| 205 | - { |
|
| 206 | - update_option('ee_espresso_activation', true); |
|
| 207 | - } |
|
| 107 | + // define versions |
|
| 108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | + if ( ! defined('DS')) { |
|
| 115 | + define('DS', '/'); |
|
| 116 | + } |
|
| 117 | + if ( ! defined('PS')) { |
|
| 118 | + define('PS', PATH_SEPARATOR); |
|
| 119 | + } |
|
| 120 | + if ( ! defined('SP')) { |
|
| 121 | + define('SP', ' '); |
|
| 122 | + } |
|
| 123 | + if ( ! defined('EENL')) { |
|
| 124 | + define('EENL', "\n"); |
|
| 125 | + } |
|
| 126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | + // define the plugin directory and URL |
|
| 128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | + // main root folder paths |
|
| 132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | + // core system paths |
|
| 141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | + // gateways |
|
| 154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | + // asset URL paths |
|
| 157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | + // define upload paths |
|
| 164 | + $uploads = wp_upload_dir(); |
|
| 165 | + // define the uploads directory and URL |
|
| 166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | + // define the templates directory and URL |
|
| 169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | + // define the gateway directory and URL |
|
| 172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | + // languages folder/path |
|
| 175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | + //check for dompdf fonts in uploads |
|
| 178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | + } |
|
| 181 | + //ajax constants |
|
| 182 | + define( |
|
| 183 | + 'EE_FRONT_AJAX', |
|
| 184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | + ); |
|
| 186 | + define( |
|
| 187 | + 'EE_ADMIN_AJAX', |
|
| 188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | + ); |
|
| 190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | + //want to change its default value! or find when -1 means infinity |
|
| 193 | + define('EE_INF_IN_DB', -1); |
|
| 194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | + define('EE_DEBUG', false); |
|
| 196 | + // for older WP versions |
|
| 197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
| 198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
| 199 | + } |
|
| 200 | + /** |
|
| 201 | + * espresso_plugin_activation |
|
| 202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 203 | + */ |
|
| 204 | + function espresso_plugin_activation() |
|
| 205 | + { |
|
| 206 | + update_option('ee_espresso_activation', true); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 210 | - /** |
|
| 211 | - * espresso_load_error_handling |
|
| 212 | - * this function loads EE's class for handling exceptions and errors |
|
| 213 | - */ |
|
| 214 | - function espresso_load_error_handling() |
|
| 215 | - { |
|
| 216 | - // load debugging tools |
|
| 217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 219 | - EEH_Debug_Tools::instance(); |
|
| 220 | - } |
|
| 221 | - // load error handling |
|
| 222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 224 | - } else { |
|
| 225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 226 | - } |
|
| 227 | - } |
|
| 209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 210 | + /** |
|
| 211 | + * espresso_load_error_handling |
|
| 212 | + * this function loads EE's class for handling exceptions and errors |
|
| 213 | + */ |
|
| 214 | + function espresso_load_error_handling() |
|
| 215 | + { |
|
| 216 | + // load debugging tools |
|
| 217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 219 | + EEH_Debug_Tools::instance(); |
|
| 220 | + } |
|
| 221 | + // load error handling |
|
| 222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 224 | + } else { |
|
| 225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * espresso_load_required |
|
| 231 | - * given a class name and path, this function will load that file or throw an exception |
|
| 232 | - * |
|
| 233 | - * @param string $classname |
|
| 234 | - * @param string $full_path_to_file |
|
| 235 | - * @throws EE_Error |
|
| 236 | - */ |
|
| 237 | - function espresso_load_required($classname, $full_path_to_file) |
|
| 238 | - { |
|
| 239 | - static $error_handling_loaded = false; |
|
| 240 | - if ( ! $error_handling_loaded) { |
|
| 241 | - espresso_load_error_handling(); |
|
| 242 | - $error_handling_loaded = true; |
|
| 243 | - } |
|
| 244 | - if (is_readable($full_path_to_file)) { |
|
| 245 | - require_once($full_path_to_file); |
|
| 246 | - } else { |
|
| 247 | - throw new EE_Error ( |
|
| 248 | - sprintf( |
|
| 249 | - esc_html__( |
|
| 250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 251 | - 'event_espresso' |
|
| 252 | - ), |
|
| 253 | - $classname |
|
| 254 | - ) |
|
| 255 | - ); |
|
| 256 | - } |
|
| 257 | - } |
|
| 229 | + /** |
|
| 230 | + * espresso_load_required |
|
| 231 | + * given a class name and path, this function will load that file or throw an exception |
|
| 232 | + * |
|
| 233 | + * @param string $classname |
|
| 234 | + * @param string $full_path_to_file |
|
| 235 | + * @throws EE_Error |
|
| 236 | + */ |
|
| 237 | + function espresso_load_required($classname, $full_path_to_file) |
|
| 238 | + { |
|
| 239 | + static $error_handling_loaded = false; |
|
| 240 | + if ( ! $error_handling_loaded) { |
|
| 241 | + espresso_load_error_handling(); |
|
| 242 | + $error_handling_loaded = true; |
|
| 243 | + } |
|
| 244 | + if (is_readable($full_path_to_file)) { |
|
| 245 | + require_once($full_path_to_file); |
|
| 246 | + } else { |
|
| 247 | + throw new EE_Error ( |
|
| 248 | + sprintf( |
|
| 249 | + esc_html__( |
|
| 250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 251 | + 'event_espresso' |
|
| 252 | + ), |
|
| 253 | + $classname |
|
| 254 | + ) |
|
| 255 | + ); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 262 | - new EE_Bootstrap(); |
|
| 263 | - } |
|
| 259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 262 | + new EE_Bootstrap(); |
|
| 263 | + } |
|
| 264 | 264 | } |
| 265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
| 266 | - /** |
|
| 267 | - * deactivate_plugin |
|
| 268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 269 | - * |
|
| 270 | - * @access public |
|
| 271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 272 | - * @return void |
|
| 273 | - */ |
|
| 274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 275 | - { |
|
| 276 | - if ( ! function_exists('deactivate_plugins')) { |
|
| 277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 278 | - } |
|
| 279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 280 | - deactivate_plugins($plugin_basename); |
|
| 281 | - } |
|
| 266 | + /** |
|
| 267 | + * deactivate_plugin |
|
| 268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 269 | + * |
|
| 270 | + * @access public |
|
| 271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 272 | + * @return void |
|
| 273 | + */ |
|
| 274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 275 | + { |
|
| 276 | + if ( ! function_exists('deactivate_plugins')) { |
|
| 277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 278 | + } |
|
| 279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 280 | + deactivate_plugins($plugin_basename); |
|
| 281 | + } |
|
| 282 | 282 | } |
| 283 | 283 | \ No newline at end of file |