@@ -16,23 +16,23 @@ |
||
16 | 16 | interface FormatterInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Applies the formatting to all items in the array |
|
21 | - * |
|
22 | - * @param array $input accepts a multi-dimensional array, but all "leaf nodes" are easily cast to a string |
|
23 | - * @return array |
|
24 | - */ |
|
25 | - public function formatArray($input); |
|
26 | - |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * Formats the string |
|
31 | - * |
|
32 | - * @param string|int|float $input anything easily cast into a string |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function format($input); |
|
19 | + /** |
|
20 | + * Applies the formatting to all items in the array |
|
21 | + * |
|
22 | + * @param array $input accepts a multi-dimensional array, but all "leaf nodes" are easily cast to a string |
|
23 | + * @return array |
|
24 | + */ |
|
25 | + public function formatArray($input); |
|
26 | + |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * Formats the string |
|
31 | + * |
|
32 | + * @param string|int|float $input anything easily cast into a string |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function format($input); |
|
36 | 36 | } |
37 | 37 | // End of file FormatterInterface.php |
38 | 38 | // Location: core\services\formatters/FormatterInterface.php |
39 | 39 | \ No newline at end of file |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | * |
471 | 471 | * @access protected |
472 | 472 | * @param \EE_Payment_Method $payment_method |
473 | - * @return \EE_Form_Section_Proper |
|
473 | + * @return EE_Form_Section_HTML |
|
474 | 474 | */ |
475 | 475 | protected function _pci_dss_compliance(EE_Payment_Method $payment_method) |
476 | 476 | { |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | * |
507 | 507 | * @access protected |
508 | 508 | * @param \EE_Payment_Method $payment_method |
509 | - * @return \EE_Form_Section_Proper |
|
509 | + * @return EE_Form_Section_HTML |
|
510 | 510 | */ |
511 | 511 | protected function _currency_support(EE_Payment_Method $payment_method) |
512 | 512 | { |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | * |
542 | 542 | * @access protected |
543 | 543 | * @param \EE_Payment_Method $payment_method |
544 | - * @return \EE_Form_Section_HTML |
|
544 | + * @return EE_Payment_Method_Form |
|
545 | 545 | */ |
546 | 546 | protected function _payment_method_settings(EE_Payment_Method $payment_method) |
547 | 547 | { |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | * |
616 | 616 | * @access protected |
617 | 617 | * @param \EE_Payment_Method $payment_method |
618 | - * @return \EE_Form_Section_Proper |
|
618 | + * @return EE_Form_Section_HTML |
|
619 | 619 | */ |
620 | 620 | protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method) |
621 | 621 | { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types(); |
190 | 190 | $all_pmt_help_tabs_config = array(); |
191 | 191 | foreach ($payment_method_types as $payment_method_type) { |
192 | - if (! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(), |
|
192 | + if ( ! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(), |
|
193 | 193 | 'specific_payment_method_type_access') |
194 | 194 | ) { |
195 | 195 | continue; |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $all_pmt_help_tabs_config[$help_tab_name] = array( |
201 | 201 | 'title' => $config['title'], |
202 | 202 | 'content' => EEH_Template::display_template( |
203 | - $payment_method_type->file_folder() . 'help_tabs' . DS . $config['filename'] . '.help_tab.php', |
|
203 | + $payment_method_type->file_folder().'help_tabs'.DS.$config['filename'].'.help_tab.php', |
|
204 | 204 | $template_args, |
205 | 205 | true), |
206 | 206 | ); |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | { |
247 | 247 | wp_enqueue_script('ee_admin_js'); |
248 | 248 | wp_enqueue_script('ee-text-links'); |
249 | - wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js', |
|
249 | + wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL.'espresso_payments_admin.js', |
|
250 | 250 | array('espresso-ui-theme', 'ee-datepicker'), EVENT_ESPRESSO_VERSION, true); |
251 | 251 | } |
252 | 252 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | public function load_scripts_styles_default() |
256 | 256 | { |
257 | 257 | //styles |
258 | - wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', array(), |
|
258 | + wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL.'ee-payments.css', array(), |
|
259 | 259 | EVENT_ESPRESSO_VERSION); |
260 | 260 | wp_enqueue_style('espresso_payments'); |
261 | 261 | wp_enqueue_style('ee-text-links'); |
@@ -283,14 +283,14 @@ discard block |
||
283 | 283 | continue; |
284 | 284 | } |
285 | 285 | //check access |
286 | - if (! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(), |
|
286 | + if ( ! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(), |
|
287 | 287 | 'specific_payment_method_type_access') |
288 | 288 | ) { |
289 | 289 | continue; |
290 | 290 | } |
291 | 291 | //check for any active pms of that type |
292 | 292 | $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name()); |
293 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
293 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
294 | 294 | $payment_method = EE_Payment_Method::new_instance( |
295 | 295 | array( |
296 | 296 | 'PMD_slug' => sanitize_key($pmt_obj->system_name()), |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | if ($payment_method instanceof EE_Payment_Method) { |
309 | 309 | add_meta_box( |
310 | 310 | //html id |
311 | - 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
311 | + 'espresso_'.$payment_method->slug().'_payment_settings', |
|
312 | 312 | //title |
313 | 313 | sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()), |
314 | 314 | //callback |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | $tabs[$payment_method->slug()] = array( |
327 | 327 | 'label' => $payment_method->admin_name(), |
328 | 328 | 'class' => $payment_method->active() ? 'gateway-active' : '', |
329 | - 'href' => 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
329 | + 'href' => 'espresso_'.$payment_method->slug().'_payment_settings', |
|
330 | 330 | 'title' => __('Modify this Payment Method', 'event_espresso'), |
331 | 331 | 'slug' => $payment_method->slug(), |
332 | 332 | ); |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | } |
355 | 355 | $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug))); |
356 | 356 | // if that didn't work or wasn't provided, find another way to select the current pm |
357 | - if (! $this->_verify_payment_method($payment_method)) { |
|
357 | + if ( ! $this->_verify_payment_method($payment_method)) { |
|
358 | 358 | // like, looking for an active one |
359 | 359 | $payment_method = EEM_Payment_Method::instance()->get_one_active('CART'); |
360 | 360 | // test that one as well |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | { |
405 | 405 | $payment_method = isset($metabox['args'], $metabox['args']['payment_method']) |
406 | 406 | ? $metabox['args']['payment_method'] : null; |
407 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
407 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
408 | 408 | throw new EE_Error(sprintf(__('Payment method metabox setup incorrectly. No Payment method object was supplied', |
409 | 409 | 'event_espresso'))); |
410 | 410 | } |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | if ($form->form_data_present_in($this->_req_data)) { |
416 | 416 | $form->receive_form_submission($this->_req_data); |
417 | 417 | } |
418 | - echo $form->form_open() . $form->get_html_and_js() . $form->form_close(); |
|
418 | + echo $form->form_open().$form->get_html_and_js().$form->form_close(); |
|
419 | 419 | } else { |
420 | 420 | echo $this->_activate_payment_method_button($payment_method)->get_html_and_js(); |
421 | 421 | } |
@@ -432,13 +432,13 @@ discard block |
||
432 | 432 | */ |
433 | 433 | protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method) |
434 | 434 | { |
435 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
435 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
436 | 436 | return new EE_Form_Section_Proper(); |
437 | 437 | } |
438 | 438 | return new EE_Form_Section_Proper( |
439 | 439 | array( |
440 | - 'name' => $payment_method->slug() . '_settings_form', |
|
441 | - 'html_id' => $payment_method->slug() . '_settings_form', |
|
440 | + 'name' => $payment_method->slug().'_settings_form', |
|
441 | + 'html_id' => $payment_method->slug().'_settings_form', |
|
442 | 442 | 'action' => EE_Admin_Page::add_query_args_and_nonce( |
443 | 443 | array( |
444 | 444 | 'action' => 'update_payment_method', |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | EEH_HTML::label( |
482 | 482 | EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
483 | 483 | ) |
484 | - ) . |
|
484 | + ). |
|
485 | 485 | EEH_HTML::td( |
486 | 486 | EEH_HTML::strong(__('You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.', |
487 | 487 | 'event_espresso')) |
@@ -510,14 +510,14 @@ discard block |
||
510 | 510 | */ |
511 | 511 | protected function _currency_support(EE_Payment_Method $payment_method) |
512 | 512 | { |
513 | - if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) { |
|
513 | + if ( ! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) { |
|
514 | 514 | return new EE_Form_Section_HTML( |
515 | 515 | EEH_HTML::tr( |
516 | 516 | EEH_HTML::th( |
517 | 517 | EEH_HTML::label( |
518 | 518 | EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
519 | 519 | ) |
520 | - ) . |
|
520 | + ). |
|
521 | 521 | EEH_HTML::td( |
522 | 522 | EEH_HTML::strong( |
523 | 523 | sprintf( |
@@ -591,16 +591,16 @@ discard block |
||
591 | 591 | $update_button = new EE_Submit_Input( |
592 | 592 | array( |
593 | 593 | 'name' => 'submit', |
594 | - 'html_id' => 'save_' . $payment_method->slug() . '_settings', |
|
594 | + 'html_id' => 'save_'.$payment_method->slug().'_settings', |
|
595 | 595 | 'default' => sprintf(__('Update %s Payment Settings', 'event_espresso'), |
596 | 596 | $payment_method->admin_name()), |
597 | 597 | 'html_label' => EEH_HTML::nbsp(), |
598 | 598 | ) |
599 | 599 | ); |
600 | 600 | return new EE_Form_Section_HTML( |
601 | - EEH_HTML::no_row(EEH_HTML::br(2)) . |
|
601 | + EEH_HTML::no_row(EEH_HTML::br(2)). |
|
602 | 602 | EEH_HTML::tr( |
603 | - EEH_HTML::th(__('Update Settings', 'event_espresso')) . |
|
603 | + EEH_HTML::th(__('Update Settings', 'event_espresso')). |
|
604 | 604 | EEH_HTML::td( |
605 | 605 | $update_button->get_html_for_input() |
606 | 606 | ) |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | $payment_method->admin_name()); |
624 | 624 | return new EE_Form_Section_HTML( |
625 | 625 | EEH_HTML::tr( |
626 | - EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) . |
|
626 | + EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')). |
|
627 | 627 | EEH_HTML::td( |
628 | 628 | EEH_HTML::link( |
629 | 629 | EE_Admin_Page::add_query_args_and_nonce( |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | ), |
636 | 636 | $link_text_and_title, |
637 | 637 | $link_text_and_title, |
638 | - 'deactivate_' . $payment_method->slug(), |
|
638 | + 'deactivate_'.$payment_method->slug(), |
|
639 | 639 | 'espresso-button button-secondary' |
640 | 640 | ) |
641 | 641 | ) |
@@ -658,8 +658,8 @@ discard block |
||
658 | 658 | $payment_method->admin_name()); |
659 | 659 | return new EE_Form_Section_Proper( |
660 | 660 | array( |
661 | - 'name' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
662 | - 'html_id' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
661 | + 'name' => 'activate_'.$payment_method->slug().'_settings_form', |
|
662 | + 'html_id' => 'activate_'.$payment_method->slug().'_settings_form', |
|
663 | 663 | 'action' => '#', |
664 | 664 | 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
665 | 665 | 'subsections' => apply_filters( |
@@ -673,11 +673,11 @@ discard block |
||
673 | 673 | '', |
674 | 674 | 'colspan="2"' |
675 | 675 | ) |
676 | - ) . |
|
676 | + ). |
|
677 | 677 | EEH_HTML::tr( |
678 | 678 | EEH_HTML::th( |
679 | 679 | EEH_HTML::label(__('Click to Activate ', 'event_espresso')) |
680 | - ) . |
|
680 | + ). |
|
681 | 681 | EEH_HTML::td( |
682 | 682 | EEH_HTML::link( |
683 | 683 | EE_Admin_Page::add_query_args_and_nonce( |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | ), |
690 | 690 | $link_text_and_title, |
691 | 691 | $link_text_and_title, |
692 | - 'activate_' . $payment_method->slug(), |
|
692 | + 'activate_'.$payment_method->slug(), |
|
693 | 693 | 'espresso-button-green button-primary' |
694 | 694 | ) |
695 | 695 | ) |
@@ -714,7 +714,7 @@ discard block |
||
714 | 714 | { |
715 | 715 | return new EE_Form_Section_HTML( |
716 | 716 | EEH_HTML::tr( |
717 | - EEH_HTML::th() . |
|
717 | + EEH_HTML::th(). |
|
718 | 718 | EEH_HTML::td( |
719 | 719 | EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text') |
720 | 720 | ) |
@@ -792,7 +792,7 @@ discard block |
||
792 | 792 | } |
793 | 793 | } |
794 | 794 | //if we couldn't find the correct payment method type... |
795 | - if (! $correct_pmt_form_to_use) { |
|
795 | + if ( ! $correct_pmt_form_to_use) { |
|
796 | 796 | EE_Error::add_error(__("We could not find which payment method type your form submission related to. Please contact support", |
797 | 797 | 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
798 | 798 | $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default')); |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | $correct_pmt_form_to_use->receive_form_submission($this->_req_data); |
801 | 801 | if ($correct_pmt_form_to_use->is_valid()) { |
802 | 802 | $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings'); |
803 | - if (! $payment_settings_subform instanceof EE_Payment_Method_Form) { |
|
803 | + if ( ! $payment_settings_subform instanceof EE_Payment_Method_Form) { |
|
804 | 804 | throw new EE_Error( |
805 | 805 | sprintf( |
806 | 806 | __('The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.', |
@@ -926,7 +926,7 @@ discard block |
||
926 | 926 | } |
927 | 927 | //take into account search |
928 | 928 | if (isset($this->_req_data['s']) && $this->_req_data['s']) { |
929 | - $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%'); |
|
929 | + $similarity_string = array('LIKE', '%'.str_replace("", "%", $this->_req_data['s']).'%'); |
|
930 | 930 | $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string; |
931 | 931 | $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string; |
932 | 932 | $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string; |
@@ -946,8 +946,8 @@ discard block |
||
946 | 946 | $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']); |
947 | 947 | $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']); |
948 | 948 | //make sure our timestamps start and end right at the boundaries for each day |
949 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
950 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
949 | + $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00'; |
|
950 | + $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59'; |
|
951 | 951 | //convert to timestamps |
952 | 952 | $start_date = strtotime($start_date); |
953 | 953 | $end_date = strtotime($end_date); |
@@ -974,15 +974,15 @@ discard block |
||
974 | 974 | $query_params['order_by'] = array('LOG_time' => 'DESC'); |
975 | 975 | } |
976 | 976 | $offset = ($current_page - 1) * $per_page; |
977 | - if (! isset($this->_req_data['download_results'])) { |
|
977 | + if ( ! isset($this->_req_data['download_results'])) { |
|
978 | 978 | $query_params['limit'] = array($offset, $per_page); |
979 | 979 | } |
980 | 980 | //now they've requested to instead just download the file instead of viewing it. |
981 | 981 | if (isset($this->_req_data['download_results'])) { |
982 | 982 | $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params); |
983 | 983 | header('Content-Disposition: attachment'); |
984 | - header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url())); |
|
985 | - echo "<h1>Payment Logs for " . site_url() . "</h1>"; |
|
984 | + header("Content-Disposition: attachment; filename=ee_payment_logs_for_".sanitize_key(site_url())); |
|
985 | + echo "<h1>Payment Logs for ".site_url()."</h1>"; |
|
986 | 986 | echo "<h3>Query:</h3>"; |
987 | 987 | var_dump($query_params); |
988 | 988 | echo "<h3>Results:</h3>"; |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | } |
1037 | 1037 | } |
1038 | 1038 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
1039 | - EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php', |
|
1039 | + EE_PAYMENTS_TEMPLATE_PATH.'payment_log_details.template.php', |
|
1040 | 1040 | array( |
1041 | 1041 | 'payment_log' => $payment_log, |
1042 | 1042 | 'payment_method' => $payment_method, |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -27,838 +27,838 @@ discard block |
||
27 | 27 | class Payments_Admin_Page extends EE_Admin_Page |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Variables used for when we're re-sorting the logs results, in case |
|
32 | - * we needed to do two queries and we need to resort |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - private $_sort_logs_again_direction; |
|
37 | - |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * @Constructor |
|
42 | - * @access public |
|
43 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
44 | - * @return \Payments_Admin_Page |
|
45 | - */ |
|
46 | - public function __construct($routing = true) |
|
47 | - { |
|
48 | - parent::__construct($routing); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - |
|
53 | - protected function _init_page_props() |
|
54 | - { |
|
55 | - $this->page_slug = EE_PAYMENTS_PG_SLUG; |
|
56 | - $this->page_label = __('Payment Methods', 'event_espresso'); |
|
57 | - $this->_admin_base_url = EE_PAYMENTS_ADMIN_URL; |
|
58 | - $this->_admin_base_path = EE_PAYMENTS_ADMIN; |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - protected function _ajax_hooks() |
|
64 | - { |
|
65 | - //todo: all hooks for ajax goes here. |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - protected function _define_page_props() |
|
71 | - { |
|
72 | - $this->_admin_page_title = $this->page_label; |
|
73 | - $this->_labels = array( |
|
74 | - 'publishbox' => __('Update Settings', 'event_espresso'), |
|
75 | - ); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - |
|
80 | - protected function _set_page_routes() |
|
81 | - { |
|
82 | - /** |
|
83 | - * note that with payment method capabilities, although we've implemented |
|
84 | - * capability mapping which will be used for accessing payment methods owned by |
|
85 | - * other users. This is not fully implemented yet in the payment method ui. |
|
86 | - * Currently only the "plural" caps are in active use. |
|
87 | - * When cap mapping is implemented, some routes will need to use the singular form of |
|
88 | - * capability method and also include the $id of the payment method for the route. |
|
89 | - **/ |
|
90 | - $this->_page_routes = array( |
|
91 | - 'default' => array( |
|
92 | - 'func' => '_payment_methods_list', |
|
93 | - 'capability' => 'ee_edit_payment_methods', |
|
94 | - ), |
|
95 | - 'payment_settings' => array( |
|
96 | - 'func' => '_payment_settings', |
|
97 | - 'capability' => 'ee_manage_gateways', |
|
98 | - ), |
|
99 | - 'activate_payment_method' => array( |
|
100 | - 'func' => '_activate_payment_method', |
|
101 | - 'noheader' => true, |
|
102 | - 'capability' => 'ee_edit_payment_methods', |
|
103 | - ), |
|
104 | - 'deactivate_payment_method' => array( |
|
105 | - 'func' => '_deactivate_payment_method', |
|
106 | - 'noheader' => true, |
|
107 | - 'capability' => 'ee_delete_payment_methods', |
|
108 | - ), |
|
109 | - 'update_payment_method' => array( |
|
110 | - 'func' => '_update_payment_method', |
|
111 | - 'noheader' => true, |
|
112 | - 'headers_sent_route' => 'default', |
|
113 | - 'capability' => 'ee_edit_payment_methods', |
|
114 | - ), |
|
115 | - 'update_payment_settings' => array( |
|
116 | - 'func' => '_update_payment_settings', |
|
117 | - 'noheader' => true, |
|
118 | - 'capability' => 'ee_manage_gateways', |
|
119 | - ), |
|
120 | - 'payment_log' => array( |
|
121 | - 'func' => '_payment_log_overview_list_table', |
|
122 | - 'capability' => 'ee_read_payment_methods', |
|
123 | - ), |
|
124 | - 'payment_log_details' => array( |
|
125 | - 'func' => '_payment_log_details', |
|
126 | - 'capability' => 'ee_read_payment_methods', |
|
127 | - ), |
|
128 | - ); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - protected function _set_page_config() |
|
134 | - { |
|
135 | - $payment_method_list_config = array( |
|
136 | - 'nav' => array( |
|
137 | - 'label' => __('Payment Methods', 'event_espresso'), |
|
138 | - 'order' => 10, |
|
139 | - ), |
|
140 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
141 | - 'help_tabs' => array_merge( |
|
142 | - array( |
|
143 | - 'payment_methods_overview_help_tab' => array( |
|
144 | - 'title' => __('Payment Methods Overview', 'event_espresso'), |
|
145 | - 'filename' => 'payment_methods_overview', |
|
146 | - ), |
|
147 | - ), |
|
148 | - $this->_add_payment_method_help_tabs()), |
|
149 | - 'help_tour' => array('Payment_Methods_Selection_Help_Tour'), |
|
150 | - 'require_nonce' => false, |
|
151 | - ); |
|
152 | - $this->_page_config = array( |
|
153 | - 'default' => $payment_method_list_config, |
|
154 | - 'payment_settings' => array( |
|
155 | - 'nav' => array( |
|
156 | - 'label' => __('Settings', 'event_espresso'), |
|
157 | - 'order' => 20, |
|
158 | - ), |
|
159 | - 'help_tabs' => array( |
|
160 | - 'payment_methods_settings_help_tab' => array( |
|
161 | - 'title' => __('Payment Method Settings', 'event_espresso'), |
|
162 | - 'filename' => 'payment_methods_settings', |
|
163 | - ), |
|
164 | - ), |
|
165 | - //'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ), |
|
166 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
167 | - 'require_nonce' => false, |
|
168 | - ), |
|
169 | - 'payment_log' => array( |
|
170 | - 'nav' => array( |
|
171 | - 'label' => __("Logs", 'event_espresso'), |
|
172 | - 'order' => 30, |
|
173 | - ), |
|
174 | - 'list_table' => 'Payment_Log_Admin_List_Table', |
|
175 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
176 | - 'require_nonce' => false, |
|
177 | - ), |
|
178 | - ); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - protected function _add_payment_method_help_tabs() |
|
187 | - { |
|
188 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
189 | - $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types(); |
|
190 | - $all_pmt_help_tabs_config = array(); |
|
191 | - foreach ($payment_method_types as $payment_method_type) { |
|
192 | - if (! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(), |
|
193 | - 'specific_payment_method_type_access') |
|
194 | - ) { |
|
195 | - continue; |
|
196 | - } |
|
197 | - foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) { |
|
198 | - $template_args = isset($config['template_args']) ? $config['template_args'] : array(); |
|
199 | - $template_args['admin_page_obj'] = $this; |
|
200 | - $all_pmt_help_tabs_config[$help_tab_name] = array( |
|
201 | - 'title' => $config['title'], |
|
202 | - 'content' => EEH_Template::display_template( |
|
203 | - $payment_method_type->file_folder() . 'help_tabs' . DS . $config['filename'] . '.help_tab.php', |
|
204 | - $template_args, |
|
205 | - true), |
|
206 | - ); |
|
207 | - } |
|
208 | - } |
|
209 | - return $all_pmt_help_tabs_config; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - //none of the below group are currently used for Gateway Settings |
|
215 | - protected function _add_screen_options() |
|
216 | - { |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - |
|
221 | - protected function _add_feature_pointers() |
|
222 | - { |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - |
|
227 | - public function admin_init() |
|
228 | - { |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - public function admin_notices() |
|
234 | - { |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - public function admin_footer_scripts() |
|
240 | - { |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - public function load_scripts_styles() |
|
246 | - { |
|
247 | - wp_enqueue_script('ee_admin_js'); |
|
248 | - wp_enqueue_script('ee-text-links'); |
|
249 | - wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js', |
|
250 | - array('espresso-ui-theme', 'ee-datepicker'), EVENT_ESPRESSO_VERSION, true); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - public function load_scripts_styles_default() |
|
256 | - { |
|
257 | - //styles |
|
258 | - wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', array(), |
|
259 | - EVENT_ESPRESSO_VERSION); |
|
260 | - wp_enqueue_style('espresso_payments'); |
|
261 | - wp_enqueue_style('ee-text-links'); |
|
262 | - //scripts |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - |
|
267 | - protected function _payment_methods_list() |
|
268 | - { |
|
269 | - /** |
|
270 | - * first let's ensure payment methods have been setup. We do this here because when people activate a |
|
271 | - * payment method for the first time (as an addon), it may not setup its capabilities or get registered correctly due |
|
272 | - * to the loading process. However, people MUST setup the details for the payment method so its safe to do a |
|
273 | - * recheck here. |
|
274 | - */ |
|
275 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
276 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
277 | - //setup tabs, one for each payment method type |
|
278 | - $tabs = array(); |
|
279 | - $payment_methods = array(); |
|
280 | - foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) { |
|
281 | - // we don't want to show admin-only PMTs for now |
|
282 | - if ($pmt_obj instanceof EE_PMT_Admin_Only) { |
|
283 | - continue; |
|
284 | - } |
|
285 | - //check access |
|
286 | - if (! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(), |
|
287 | - 'specific_payment_method_type_access') |
|
288 | - ) { |
|
289 | - continue; |
|
290 | - } |
|
291 | - //check for any active pms of that type |
|
292 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name()); |
|
293 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
294 | - $payment_method = EE_Payment_Method::new_instance( |
|
295 | - array( |
|
296 | - 'PMD_slug' => sanitize_key($pmt_obj->system_name()), |
|
297 | - 'PMD_type' => $pmt_obj->system_name(), |
|
298 | - 'PMD_name' => $pmt_obj->pretty_name(), |
|
299 | - 'PMD_admin_name' => $pmt_obj->pretty_name(), |
|
300 | - ) |
|
301 | - ); |
|
302 | - } |
|
303 | - $payment_methods[$payment_method->slug()] = $payment_method; |
|
304 | - } |
|
305 | - $payment_methods = apply_filters('FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', |
|
306 | - $payment_methods); |
|
307 | - foreach ($payment_methods as $payment_method) { |
|
308 | - if ($payment_method instanceof EE_Payment_Method) { |
|
309 | - add_meta_box( |
|
310 | - //html id |
|
311 | - 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
312 | - //title |
|
313 | - sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()), |
|
314 | - //callback |
|
315 | - array($this, 'payment_method_settings_meta_box'), |
|
316 | - //post type |
|
317 | - null, |
|
318 | - //context |
|
319 | - 'normal', |
|
320 | - //priority |
|
321 | - 'default', |
|
322 | - //callback args |
|
323 | - array('payment_method' => $payment_method) |
|
324 | - ); |
|
325 | - //setup for tabbed content |
|
326 | - $tabs[$payment_method->slug()] = array( |
|
327 | - 'label' => $payment_method->admin_name(), |
|
328 | - 'class' => $payment_method->active() ? 'gateway-active' : '', |
|
329 | - 'href' => 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
330 | - 'title' => __('Modify this Payment Method', 'event_espresso'), |
|
331 | - 'slug' => $payment_method->slug(), |
|
332 | - ); |
|
333 | - } |
|
334 | - } |
|
335 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($tabs, 'payment_method_links', |
|
336 | - '|', $this->_get_active_payment_method_slug()); |
|
337 | - $this->display_admin_page_with_sidebar(); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * _get_active_payment_method_slug |
|
344 | - * |
|
345 | - * @return string |
|
346 | - */ |
|
347 | - protected function _get_active_payment_method_slug() |
|
348 | - { |
|
349 | - $payment_method_slug = false; |
|
350 | - //decide which payment method tab to open first, as dictated by the request's 'payment_method' |
|
351 | - if (isset($this->_req_data['payment_method'])) { |
|
352 | - // if they provided the current payment method, use it |
|
353 | - $payment_method_slug = sanitize_key($this->_req_data['payment_method']); |
|
354 | - } |
|
355 | - $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug))); |
|
356 | - // if that didn't work or wasn't provided, find another way to select the current pm |
|
357 | - if (! $this->_verify_payment_method($payment_method)) { |
|
358 | - // like, looking for an active one |
|
359 | - $payment_method = EEM_Payment_Method::instance()->get_one_active('CART'); |
|
360 | - // test that one as well |
|
361 | - if ($this->_verify_payment_method($payment_method)) { |
|
362 | - $payment_method_slug = $payment_method->slug(); |
|
363 | - } else { |
|
364 | - $payment_method_slug = 'paypal_standard'; |
|
365 | - } |
|
366 | - } |
|
367 | - return $payment_method_slug; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * payment_method_settings_meta_box |
|
374 | - * returns TRUE if the passed payment method is properly constructed and the logged in user has the correct |
|
375 | - * capabilities to access it |
|
376 | - * |
|
377 | - * @param \EE_Payment_Method $payment_method |
|
378 | - * @return boolean |
|
379 | - */ |
|
380 | - protected function _verify_payment_method($payment_method) |
|
381 | - { |
|
382 | - if ( |
|
383 | - $payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base |
|
384 | - && EE_Registry::instance()->CAP->current_user_can($payment_method->type_obj()->cap_name(), |
|
385 | - 'specific_payment_method_type_access') |
|
386 | - ) { |
|
387 | - return true; |
|
388 | - } |
|
389 | - return false; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * payment_method_settings_meta_box |
|
396 | - * |
|
397 | - * @param NULL $post_obj_which_is_null is an object containing the current post (as a $post object) |
|
398 | - * @param array $metabox is an array with metabox id, title, callback, and args elements. the value |
|
399 | - * at 'args' has key 'payment_method', as set within _payment_methods_list |
|
400 | - * @return string |
|
401 | - * @throws EE_Error |
|
402 | - */ |
|
403 | - public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox) |
|
404 | - { |
|
405 | - $payment_method = isset($metabox['args'], $metabox['args']['payment_method']) |
|
406 | - ? $metabox['args']['payment_method'] : null; |
|
407 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
408 | - throw new EE_Error(sprintf(__('Payment method metabox setup incorrectly. No Payment method object was supplied', |
|
409 | - 'event_espresso'))); |
|
410 | - } |
|
411 | - $payment_method_scopes = $payment_method->active(); |
|
412 | - // if the payment method really exists show its form, otherwise the activation template |
|
413 | - if ($payment_method->ID() && ! empty($payment_method_scopes)) { |
|
414 | - $form = $this->_generate_payment_method_settings_form($payment_method); |
|
415 | - if ($form->form_data_present_in($this->_req_data)) { |
|
416 | - $form->receive_form_submission($this->_req_data); |
|
417 | - } |
|
418 | - echo $form->form_open() . $form->get_html_and_js() . $form->form_close(); |
|
419 | - } else { |
|
420 | - echo $this->_activate_payment_method_button($payment_method)->get_html_and_js(); |
|
421 | - } |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * Gets the form for all the settings related to this payment method type |
|
428 | - * |
|
429 | - * @access protected |
|
430 | - * @param \EE_Payment_Method $payment_method |
|
431 | - * @return \EE_Form_Section_Proper |
|
432 | - */ |
|
433 | - protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method) |
|
434 | - { |
|
435 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
436 | - return new EE_Form_Section_Proper(); |
|
437 | - } |
|
438 | - return new EE_Form_Section_Proper( |
|
439 | - array( |
|
440 | - 'name' => $payment_method->slug() . '_settings_form', |
|
441 | - 'html_id' => $payment_method->slug() . '_settings_form', |
|
442 | - 'action' => EE_Admin_Page::add_query_args_and_nonce( |
|
443 | - array( |
|
444 | - 'action' => 'update_payment_method', |
|
445 | - 'payment_method' => $payment_method->slug(), |
|
446 | - ), |
|
447 | - EE_PAYMENTS_ADMIN_URL |
|
448 | - ), |
|
449 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
450 | - 'subsections' => apply_filters( |
|
451 | - 'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections', |
|
452 | - array( |
|
453 | - 'pci_dss_compliance' => $this->_pci_dss_compliance($payment_method), |
|
454 | - 'currency_support' => $this->_currency_support($payment_method), |
|
455 | - 'payment_method_settings' => $this->_payment_method_settings($payment_method), |
|
456 | - 'update' => $this->_update_payment_method_button($payment_method), |
|
457 | - 'deactivate' => $this->_deactivate_payment_method_button($payment_method), |
|
458 | - 'fine_print' => $this->_fine_print(), |
|
459 | - ), |
|
460 | - $payment_method |
|
461 | - ), |
|
462 | - ) |
|
463 | - ); |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - |
|
468 | - /** |
|
469 | - * _pci_dss_compliance |
|
470 | - * |
|
471 | - * @access protected |
|
472 | - * @param \EE_Payment_Method $payment_method |
|
473 | - * @return \EE_Form_Section_Proper |
|
474 | - */ |
|
475 | - protected function _pci_dss_compliance(EE_Payment_Method $payment_method) |
|
476 | - { |
|
477 | - if ($payment_method->type_obj()->requires_https()) { |
|
478 | - return new EE_Form_Section_HTML( |
|
479 | - EEH_HTML::tr( |
|
480 | - EEH_HTML::th( |
|
481 | - EEH_HTML::label( |
|
482 | - EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
|
483 | - ) |
|
484 | - ) . |
|
485 | - EEH_HTML::td( |
|
486 | - EEH_HTML::strong(__('You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.', |
|
487 | - 'event_espresso')) |
|
488 | - . |
|
489 | - EEH_HTML::br() |
|
490 | - . |
|
491 | - __('Learn more about ', 'event_espresso') |
|
492 | - . EEH_HTML::link('https://www.pcisecuritystandards.org/merchants/index.php', |
|
493 | - __('PCI DSS compliance', 'event_espresso')) |
|
494 | - ) |
|
495 | - ) |
|
496 | - ); |
|
497 | - } else { |
|
498 | - return new EE_Form_Section_HTML(''); |
|
499 | - } |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * _currency_support |
|
506 | - * |
|
507 | - * @access protected |
|
508 | - * @param \EE_Payment_Method $payment_method |
|
509 | - * @return \EE_Form_Section_Proper |
|
510 | - */ |
|
511 | - protected function _currency_support(EE_Payment_Method $payment_method) |
|
512 | - { |
|
513 | - if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) { |
|
514 | - return new EE_Form_Section_HTML( |
|
515 | - EEH_HTML::tr( |
|
516 | - EEH_HTML::th( |
|
517 | - EEH_HTML::label( |
|
518 | - EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
|
519 | - ) |
|
520 | - ) . |
|
521 | - EEH_HTML::td( |
|
522 | - EEH_HTML::strong( |
|
523 | - sprintf( |
|
524 | - __('This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.', |
|
525 | - 'event_espresso'), |
|
526 | - EE_Config::instance()->currency->code |
|
527 | - ) |
|
528 | - ) |
|
529 | - ) |
|
530 | - ) |
|
531 | - ); |
|
532 | - } else { |
|
533 | - return new EE_Form_Section_HTML(''); |
|
534 | - } |
|
535 | - } |
|
536 | - |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * _update_payment_method_button |
|
541 | - * |
|
542 | - * @access protected |
|
543 | - * @param \EE_Payment_Method $payment_method |
|
544 | - * @return \EE_Form_Section_HTML |
|
545 | - */ |
|
546 | - protected function _payment_method_settings(EE_Payment_Method $payment_method) |
|
547 | - { |
|
548 | - //modify the form so we only have/show fields that will be implemented for this version |
|
549 | - return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name()); |
|
550 | - } |
|
551 | - |
|
552 | - |
|
553 | - |
|
554 | - /** |
|
555 | - * Simplifies the form to merely reproduce 4.1's gateway settings functionality |
|
556 | - * |
|
557 | - * @param EE_Form_Section_Proper $form_section |
|
558 | - * @param string $payment_method_name |
|
559 | - * @return \EE_Payment_Method_Form |
|
560 | - * @throws \EE_Error |
|
561 | - */ |
|
562 | - protected function _simplify_form($form_section, $payment_method_name = '') |
|
563 | - { |
|
564 | - if ($form_section instanceof EE_Payment_Method_Form) { |
|
565 | - $form_section->exclude( |
|
566 | - array( |
|
567 | - 'PMD_type', //dont want them changing the type |
|
568 | - 'PMD_slug', //or the slug (probably never) |
|
569 | - 'PMD_wp_user', //or the user's ID |
|
570 | - 'Currency' //or the currency, until the rest of EE supports simultaneous currencies |
|
571 | - ) |
|
572 | - ); |
|
573 | - return $form_section; |
|
574 | - } else { |
|
575 | - throw new EE_Error(sprintf(__('The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.', |
|
576 | - 'event_espresso'), $payment_method_name)); |
|
577 | - } |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * _update_payment_method_button |
|
584 | - * |
|
585 | - * @access protected |
|
586 | - * @param \EE_Payment_Method $payment_method |
|
587 | - * @return \EE_Form_Section_HTML |
|
588 | - */ |
|
589 | - protected function _update_payment_method_button(EE_Payment_Method $payment_method) |
|
590 | - { |
|
591 | - $update_button = new EE_Submit_Input( |
|
592 | - array( |
|
593 | - 'name' => 'submit', |
|
594 | - 'html_id' => 'save_' . $payment_method->slug() . '_settings', |
|
595 | - 'default' => sprintf(__('Update %s Payment Settings', 'event_espresso'), |
|
596 | - $payment_method->admin_name()), |
|
597 | - 'html_label' => EEH_HTML::nbsp(), |
|
598 | - ) |
|
599 | - ); |
|
600 | - return new EE_Form_Section_HTML( |
|
601 | - EEH_HTML::no_row(EEH_HTML::br(2)) . |
|
602 | - EEH_HTML::tr( |
|
603 | - EEH_HTML::th(__('Update Settings', 'event_espresso')) . |
|
604 | - EEH_HTML::td( |
|
605 | - $update_button->get_html_for_input() |
|
606 | - ) |
|
607 | - ) |
|
608 | - ); |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * _deactivate_payment_method_button |
|
615 | - * |
|
616 | - * @access protected |
|
617 | - * @param \EE_Payment_Method $payment_method |
|
618 | - * @return \EE_Form_Section_Proper |
|
619 | - */ |
|
620 | - protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method) |
|
621 | - { |
|
622 | - $link_text_and_title = sprintf(__('Deactivate %1$s Payments?', 'event_espresso'), |
|
623 | - $payment_method->admin_name()); |
|
624 | - return new EE_Form_Section_HTML( |
|
625 | - EEH_HTML::tr( |
|
626 | - EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) . |
|
627 | - EEH_HTML::td( |
|
628 | - EEH_HTML::link( |
|
629 | - EE_Admin_Page::add_query_args_and_nonce( |
|
630 | - array( |
|
631 | - 'action' => 'deactivate_payment_method', |
|
632 | - 'payment_method' => $payment_method->slug(), |
|
633 | - ), |
|
634 | - EE_PAYMENTS_ADMIN_URL |
|
635 | - ), |
|
636 | - $link_text_and_title, |
|
637 | - $link_text_and_title, |
|
638 | - 'deactivate_' . $payment_method->slug(), |
|
639 | - 'espresso-button button-secondary' |
|
640 | - ) |
|
641 | - ) |
|
642 | - ) |
|
643 | - ); |
|
644 | - } |
|
645 | - |
|
646 | - |
|
647 | - |
|
648 | - /** |
|
649 | - * _activate_payment_method_button |
|
650 | - * |
|
651 | - * @access protected |
|
652 | - * @param \EE_Payment_Method $payment_method |
|
653 | - * @return \EE_Form_Section_Proper |
|
654 | - */ |
|
655 | - protected function _activate_payment_method_button(EE_Payment_Method $payment_method) |
|
656 | - { |
|
657 | - $link_text_and_title = sprintf(__('Activate %1$s Payment Method?', 'event_espresso'), |
|
658 | - $payment_method->admin_name()); |
|
659 | - return new EE_Form_Section_Proper( |
|
660 | - array( |
|
661 | - 'name' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
662 | - 'html_id' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
663 | - 'action' => '#', |
|
664 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
665 | - 'subsections' => apply_filters( |
|
666 | - 'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections', |
|
667 | - array( |
|
668 | - new EE_Form_Section_HTML( |
|
669 | - EEH_HTML::tr( |
|
670 | - EEH_HTML::td($payment_method->type_obj()->introductory_html(), |
|
671 | - '', |
|
672 | - '', |
|
673 | - '', |
|
674 | - 'colspan="2"' |
|
675 | - ) |
|
676 | - ) . |
|
677 | - EEH_HTML::tr( |
|
678 | - EEH_HTML::th( |
|
679 | - EEH_HTML::label(__('Click to Activate ', 'event_espresso')) |
|
680 | - ) . |
|
681 | - EEH_HTML::td( |
|
682 | - EEH_HTML::link( |
|
683 | - EE_Admin_Page::add_query_args_and_nonce( |
|
684 | - array( |
|
685 | - 'action' => 'activate_payment_method', |
|
686 | - 'payment_method_type' => $payment_method->type(), |
|
687 | - ), |
|
688 | - EE_PAYMENTS_ADMIN_URL |
|
689 | - ), |
|
690 | - $link_text_and_title, |
|
691 | - $link_text_and_title, |
|
692 | - 'activate_' . $payment_method->slug(), |
|
693 | - 'espresso-button-green button-primary' |
|
694 | - ) |
|
695 | - ) |
|
696 | - ) |
|
697 | - ), |
|
698 | - ), |
|
699 | - $payment_method |
|
700 | - ), |
|
701 | - ) |
|
702 | - ); |
|
703 | - } |
|
704 | - |
|
705 | - |
|
706 | - |
|
707 | - /** |
|
708 | - * _fine_print |
|
709 | - * |
|
710 | - * @access protected |
|
711 | - * @return \EE_Form_Section_HTML |
|
712 | - */ |
|
713 | - protected function _fine_print() |
|
714 | - { |
|
715 | - return new EE_Form_Section_HTML( |
|
716 | - EEH_HTML::tr( |
|
717 | - EEH_HTML::th() . |
|
718 | - EEH_HTML::td( |
|
719 | - EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text') |
|
720 | - ) |
|
721 | - ) |
|
722 | - ); |
|
723 | - } |
|
724 | - |
|
725 | - |
|
726 | - |
|
727 | - /** |
|
728 | - * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far) |
|
729 | - * |
|
730 | - * @global WP_User $current_user |
|
731 | - */ |
|
732 | - protected function _activate_payment_method() |
|
733 | - { |
|
734 | - if (isset($this->_req_data['payment_method_type'])) { |
|
735 | - $payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']); |
|
736 | - //see if one exists |
|
737 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
738 | - $payment_method = EE_Payment_Method_Manager::instance() |
|
739 | - ->activate_a_payment_method_of_type($payment_method_type); |
|
740 | - $this->_redirect_after_action(1, 'Payment Method', 'activated', |
|
741 | - array('action' => 'default', 'payment_method' => $payment_method->slug())); |
|
742 | - } else { |
|
743 | - $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default')); |
|
744 | - } |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * Deactivates the payment method with the specified slug, and redirects. |
|
751 | - */ |
|
752 | - protected function _deactivate_payment_method() |
|
753 | - { |
|
754 | - if (isset($this->_req_data['payment_method'])) { |
|
755 | - $payment_method_slug = sanitize_key($this->_req_data['payment_method']); |
|
756 | - //deactivate it |
|
757 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
758 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug); |
|
759 | - $this->_redirect_after_action($count_updated, 'Payment Method', 'deactivated', |
|
760 | - array('action' => 'default', 'payment_method' => $payment_method_slug)); |
|
761 | - } else { |
|
762 | - $this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default')); |
|
763 | - } |
|
764 | - } |
|
765 | - |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * Processes the payment method form that was submitted. This is slightly trickier than usual form |
|
770 | - * processing because we first need to identify WHICH form was processed and which payment method |
|
771 | - * it corresponds to. Once we have done that, we see if the form is valid. If it is, the |
|
772 | - * form's data is saved and we redirect to the default payment methods page, setting the updated payment method |
|
773 | - * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the |
|
774 | - * subsequently called 'headers_sent_func' which is _payment_methods_list) |
|
775 | - * |
|
776 | - * @return void |
|
777 | - */ |
|
778 | - protected function _update_payment_method() |
|
779 | - { |
|
780 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
781 | - //ok let's find which gateway form to use based on the form input |
|
782 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
783 | - /** @var $correct_pmt_form_to_use EE_Payment_Method_Form */ |
|
784 | - $correct_pmt_form_to_use = null; |
|
785 | - $payment_method = null; |
|
786 | - foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) { |
|
787 | - //get the form and simplify it, like what we do when we display it |
|
788 | - $pmt_form = $this->_generate_payment_method_settings_form($payment_method); |
|
789 | - if ($pmt_form->form_data_present_in($this->_req_data)) { |
|
790 | - $correct_pmt_form_to_use = $pmt_form; |
|
791 | - break; |
|
792 | - } |
|
793 | - } |
|
794 | - //if we couldn't find the correct payment method type... |
|
795 | - if (! $correct_pmt_form_to_use) { |
|
796 | - EE_Error::add_error(__("We could not find which payment method type your form submission related to. Please contact support", |
|
797 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
798 | - $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default')); |
|
799 | - } |
|
800 | - $correct_pmt_form_to_use->receive_form_submission($this->_req_data); |
|
801 | - if ($correct_pmt_form_to_use->is_valid()) { |
|
802 | - $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings'); |
|
803 | - if (! $payment_settings_subform instanceof EE_Payment_Method_Form) { |
|
804 | - throw new EE_Error( |
|
805 | - sprintf( |
|
806 | - __('The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.', |
|
807 | - 'event_espresso'), |
|
808 | - 'payment_method_settings' |
|
809 | - ) |
|
810 | - ); |
|
811 | - } |
|
812 | - $payment_settings_subform->save(); |
|
813 | - /** @var $pm EE_Payment_Method */ |
|
814 | - $this->_redirect_after_action(true, 'Payment Method', 'updated', |
|
815 | - array('action' => 'default', 'payment_method' => $payment_method->slug())); |
|
816 | - } else { |
|
817 | - EE_Error::add_error( |
|
818 | - sprintf( |
|
819 | - __('Payment method of type %s was not saved because there were validation errors. They have been marked in the form', |
|
820 | - 'event_espresso'), |
|
821 | - $payment_method instanceof EE_Payment_Method ? $payment_method->type_obj()->pretty_name() |
|
822 | - : __('"(unknown)"', 'event_espresso') |
|
823 | - ), |
|
824 | - __FILE__, |
|
825 | - __FUNCTION__, |
|
826 | - __LINE__ |
|
827 | - ); |
|
828 | - } |
|
829 | - } |
|
830 | - return; |
|
831 | - } |
|
832 | - |
|
833 | - |
|
834 | - |
|
835 | - protected function _payment_settings() |
|
836 | - { |
|
837 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
838 | - $this->_template_args['show_pending_payment_options'] = isset(EE_Registry::instance()->CFG->registration->show_pending_payment_options) |
|
839 | - ? absint(EE_Registry::instance()->CFG->registration->show_pending_payment_options) : false; |
|
840 | - $this->_set_add_edit_form_tags('update_payment_settings'); |
|
841 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
842 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(EE_PAYMENTS_TEMPLATE_PATH |
|
843 | - . 'payment_settings.template.php', |
|
844 | - $this->_template_args, true); |
|
845 | - $this->display_admin_page_with_sidebar(); |
|
846 | - } |
|
847 | - |
|
848 | - |
|
849 | - |
|
850 | - /** |
|
851 | - * _update_payment_settings |
|
852 | - * |
|
853 | - * @access protected |
|
854 | - * @return array |
|
855 | - */ |
|
856 | - protected function _update_payment_settings() |
|
857 | - { |
|
858 | - EE_Registry::instance()->CFG->registration->show_pending_payment_options = isset($this->_req_data['show_pending_payment_options']) |
|
859 | - ? $this->_req_data['show_pending_payment_options'] : false; |
|
860 | - EE_Registry::instance()->CFG = apply_filters('FHEE__Payments_Admin_Page___update_payment_settings__CFG', |
|
861 | - EE_Registry::instance()->CFG); |
|
30 | + /** |
|
31 | + * Variables used for when we're re-sorting the logs results, in case |
|
32 | + * we needed to do two queries and we need to resort |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + private $_sort_logs_again_direction; |
|
37 | + |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * @Constructor |
|
42 | + * @access public |
|
43 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
44 | + * @return \Payments_Admin_Page |
|
45 | + */ |
|
46 | + public function __construct($routing = true) |
|
47 | + { |
|
48 | + parent::__construct($routing); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + |
|
53 | + protected function _init_page_props() |
|
54 | + { |
|
55 | + $this->page_slug = EE_PAYMENTS_PG_SLUG; |
|
56 | + $this->page_label = __('Payment Methods', 'event_espresso'); |
|
57 | + $this->_admin_base_url = EE_PAYMENTS_ADMIN_URL; |
|
58 | + $this->_admin_base_path = EE_PAYMENTS_ADMIN; |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + protected function _ajax_hooks() |
|
64 | + { |
|
65 | + //todo: all hooks for ajax goes here. |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + protected function _define_page_props() |
|
71 | + { |
|
72 | + $this->_admin_page_title = $this->page_label; |
|
73 | + $this->_labels = array( |
|
74 | + 'publishbox' => __('Update Settings', 'event_espresso'), |
|
75 | + ); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + |
|
80 | + protected function _set_page_routes() |
|
81 | + { |
|
82 | + /** |
|
83 | + * note that with payment method capabilities, although we've implemented |
|
84 | + * capability mapping which will be used for accessing payment methods owned by |
|
85 | + * other users. This is not fully implemented yet in the payment method ui. |
|
86 | + * Currently only the "plural" caps are in active use. |
|
87 | + * When cap mapping is implemented, some routes will need to use the singular form of |
|
88 | + * capability method and also include the $id of the payment method for the route. |
|
89 | + **/ |
|
90 | + $this->_page_routes = array( |
|
91 | + 'default' => array( |
|
92 | + 'func' => '_payment_methods_list', |
|
93 | + 'capability' => 'ee_edit_payment_methods', |
|
94 | + ), |
|
95 | + 'payment_settings' => array( |
|
96 | + 'func' => '_payment_settings', |
|
97 | + 'capability' => 'ee_manage_gateways', |
|
98 | + ), |
|
99 | + 'activate_payment_method' => array( |
|
100 | + 'func' => '_activate_payment_method', |
|
101 | + 'noheader' => true, |
|
102 | + 'capability' => 'ee_edit_payment_methods', |
|
103 | + ), |
|
104 | + 'deactivate_payment_method' => array( |
|
105 | + 'func' => '_deactivate_payment_method', |
|
106 | + 'noheader' => true, |
|
107 | + 'capability' => 'ee_delete_payment_methods', |
|
108 | + ), |
|
109 | + 'update_payment_method' => array( |
|
110 | + 'func' => '_update_payment_method', |
|
111 | + 'noheader' => true, |
|
112 | + 'headers_sent_route' => 'default', |
|
113 | + 'capability' => 'ee_edit_payment_methods', |
|
114 | + ), |
|
115 | + 'update_payment_settings' => array( |
|
116 | + 'func' => '_update_payment_settings', |
|
117 | + 'noheader' => true, |
|
118 | + 'capability' => 'ee_manage_gateways', |
|
119 | + ), |
|
120 | + 'payment_log' => array( |
|
121 | + 'func' => '_payment_log_overview_list_table', |
|
122 | + 'capability' => 'ee_read_payment_methods', |
|
123 | + ), |
|
124 | + 'payment_log_details' => array( |
|
125 | + 'func' => '_payment_log_details', |
|
126 | + 'capability' => 'ee_read_payment_methods', |
|
127 | + ), |
|
128 | + ); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + protected function _set_page_config() |
|
134 | + { |
|
135 | + $payment_method_list_config = array( |
|
136 | + 'nav' => array( |
|
137 | + 'label' => __('Payment Methods', 'event_espresso'), |
|
138 | + 'order' => 10, |
|
139 | + ), |
|
140 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
141 | + 'help_tabs' => array_merge( |
|
142 | + array( |
|
143 | + 'payment_methods_overview_help_tab' => array( |
|
144 | + 'title' => __('Payment Methods Overview', 'event_espresso'), |
|
145 | + 'filename' => 'payment_methods_overview', |
|
146 | + ), |
|
147 | + ), |
|
148 | + $this->_add_payment_method_help_tabs()), |
|
149 | + 'help_tour' => array('Payment_Methods_Selection_Help_Tour'), |
|
150 | + 'require_nonce' => false, |
|
151 | + ); |
|
152 | + $this->_page_config = array( |
|
153 | + 'default' => $payment_method_list_config, |
|
154 | + 'payment_settings' => array( |
|
155 | + 'nav' => array( |
|
156 | + 'label' => __('Settings', 'event_espresso'), |
|
157 | + 'order' => 20, |
|
158 | + ), |
|
159 | + 'help_tabs' => array( |
|
160 | + 'payment_methods_settings_help_tab' => array( |
|
161 | + 'title' => __('Payment Method Settings', 'event_espresso'), |
|
162 | + 'filename' => 'payment_methods_settings', |
|
163 | + ), |
|
164 | + ), |
|
165 | + //'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ), |
|
166 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
167 | + 'require_nonce' => false, |
|
168 | + ), |
|
169 | + 'payment_log' => array( |
|
170 | + 'nav' => array( |
|
171 | + 'label' => __("Logs", 'event_espresso'), |
|
172 | + 'order' => 30, |
|
173 | + ), |
|
174 | + 'list_table' => 'Payment_Log_Admin_List_Table', |
|
175 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
176 | + 'require_nonce' => false, |
|
177 | + ), |
|
178 | + ); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + protected function _add_payment_method_help_tabs() |
|
187 | + { |
|
188 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
189 | + $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types(); |
|
190 | + $all_pmt_help_tabs_config = array(); |
|
191 | + foreach ($payment_method_types as $payment_method_type) { |
|
192 | + if (! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(), |
|
193 | + 'specific_payment_method_type_access') |
|
194 | + ) { |
|
195 | + continue; |
|
196 | + } |
|
197 | + foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) { |
|
198 | + $template_args = isset($config['template_args']) ? $config['template_args'] : array(); |
|
199 | + $template_args['admin_page_obj'] = $this; |
|
200 | + $all_pmt_help_tabs_config[$help_tab_name] = array( |
|
201 | + 'title' => $config['title'], |
|
202 | + 'content' => EEH_Template::display_template( |
|
203 | + $payment_method_type->file_folder() . 'help_tabs' . DS . $config['filename'] . '.help_tab.php', |
|
204 | + $template_args, |
|
205 | + true), |
|
206 | + ); |
|
207 | + } |
|
208 | + } |
|
209 | + return $all_pmt_help_tabs_config; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + //none of the below group are currently used for Gateway Settings |
|
215 | + protected function _add_screen_options() |
|
216 | + { |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + |
|
221 | + protected function _add_feature_pointers() |
|
222 | + { |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + |
|
227 | + public function admin_init() |
|
228 | + { |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + public function admin_notices() |
|
234 | + { |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + public function admin_footer_scripts() |
|
240 | + { |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + public function load_scripts_styles() |
|
246 | + { |
|
247 | + wp_enqueue_script('ee_admin_js'); |
|
248 | + wp_enqueue_script('ee-text-links'); |
|
249 | + wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js', |
|
250 | + array('espresso-ui-theme', 'ee-datepicker'), EVENT_ESPRESSO_VERSION, true); |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + public function load_scripts_styles_default() |
|
256 | + { |
|
257 | + //styles |
|
258 | + wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', array(), |
|
259 | + EVENT_ESPRESSO_VERSION); |
|
260 | + wp_enqueue_style('espresso_payments'); |
|
261 | + wp_enqueue_style('ee-text-links'); |
|
262 | + //scripts |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + |
|
267 | + protected function _payment_methods_list() |
|
268 | + { |
|
269 | + /** |
|
270 | + * first let's ensure payment methods have been setup. We do this here because when people activate a |
|
271 | + * payment method for the first time (as an addon), it may not setup its capabilities or get registered correctly due |
|
272 | + * to the loading process. However, people MUST setup the details for the payment method so its safe to do a |
|
273 | + * recheck here. |
|
274 | + */ |
|
275 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
276 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
277 | + //setup tabs, one for each payment method type |
|
278 | + $tabs = array(); |
|
279 | + $payment_methods = array(); |
|
280 | + foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) { |
|
281 | + // we don't want to show admin-only PMTs for now |
|
282 | + if ($pmt_obj instanceof EE_PMT_Admin_Only) { |
|
283 | + continue; |
|
284 | + } |
|
285 | + //check access |
|
286 | + if (! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(), |
|
287 | + 'specific_payment_method_type_access') |
|
288 | + ) { |
|
289 | + continue; |
|
290 | + } |
|
291 | + //check for any active pms of that type |
|
292 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name()); |
|
293 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
294 | + $payment_method = EE_Payment_Method::new_instance( |
|
295 | + array( |
|
296 | + 'PMD_slug' => sanitize_key($pmt_obj->system_name()), |
|
297 | + 'PMD_type' => $pmt_obj->system_name(), |
|
298 | + 'PMD_name' => $pmt_obj->pretty_name(), |
|
299 | + 'PMD_admin_name' => $pmt_obj->pretty_name(), |
|
300 | + ) |
|
301 | + ); |
|
302 | + } |
|
303 | + $payment_methods[$payment_method->slug()] = $payment_method; |
|
304 | + } |
|
305 | + $payment_methods = apply_filters('FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', |
|
306 | + $payment_methods); |
|
307 | + foreach ($payment_methods as $payment_method) { |
|
308 | + if ($payment_method instanceof EE_Payment_Method) { |
|
309 | + add_meta_box( |
|
310 | + //html id |
|
311 | + 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
312 | + //title |
|
313 | + sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()), |
|
314 | + //callback |
|
315 | + array($this, 'payment_method_settings_meta_box'), |
|
316 | + //post type |
|
317 | + null, |
|
318 | + //context |
|
319 | + 'normal', |
|
320 | + //priority |
|
321 | + 'default', |
|
322 | + //callback args |
|
323 | + array('payment_method' => $payment_method) |
|
324 | + ); |
|
325 | + //setup for tabbed content |
|
326 | + $tabs[$payment_method->slug()] = array( |
|
327 | + 'label' => $payment_method->admin_name(), |
|
328 | + 'class' => $payment_method->active() ? 'gateway-active' : '', |
|
329 | + 'href' => 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
330 | + 'title' => __('Modify this Payment Method', 'event_espresso'), |
|
331 | + 'slug' => $payment_method->slug(), |
|
332 | + ); |
|
333 | + } |
|
334 | + } |
|
335 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($tabs, 'payment_method_links', |
|
336 | + '|', $this->_get_active_payment_method_slug()); |
|
337 | + $this->display_admin_page_with_sidebar(); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * _get_active_payment_method_slug |
|
344 | + * |
|
345 | + * @return string |
|
346 | + */ |
|
347 | + protected function _get_active_payment_method_slug() |
|
348 | + { |
|
349 | + $payment_method_slug = false; |
|
350 | + //decide which payment method tab to open first, as dictated by the request's 'payment_method' |
|
351 | + if (isset($this->_req_data['payment_method'])) { |
|
352 | + // if they provided the current payment method, use it |
|
353 | + $payment_method_slug = sanitize_key($this->_req_data['payment_method']); |
|
354 | + } |
|
355 | + $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug))); |
|
356 | + // if that didn't work or wasn't provided, find another way to select the current pm |
|
357 | + if (! $this->_verify_payment_method($payment_method)) { |
|
358 | + // like, looking for an active one |
|
359 | + $payment_method = EEM_Payment_Method::instance()->get_one_active('CART'); |
|
360 | + // test that one as well |
|
361 | + if ($this->_verify_payment_method($payment_method)) { |
|
362 | + $payment_method_slug = $payment_method->slug(); |
|
363 | + } else { |
|
364 | + $payment_method_slug = 'paypal_standard'; |
|
365 | + } |
|
366 | + } |
|
367 | + return $payment_method_slug; |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * payment_method_settings_meta_box |
|
374 | + * returns TRUE if the passed payment method is properly constructed and the logged in user has the correct |
|
375 | + * capabilities to access it |
|
376 | + * |
|
377 | + * @param \EE_Payment_Method $payment_method |
|
378 | + * @return boolean |
|
379 | + */ |
|
380 | + protected function _verify_payment_method($payment_method) |
|
381 | + { |
|
382 | + if ( |
|
383 | + $payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base |
|
384 | + && EE_Registry::instance()->CAP->current_user_can($payment_method->type_obj()->cap_name(), |
|
385 | + 'specific_payment_method_type_access') |
|
386 | + ) { |
|
387 | + return true; |
|
388 | + } |
|
389 | + return false; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * payment_method_settings_meta_box |
|
396 | + * |
|
397 | + * @param NULL $post_obj_which_is_null is an object containing the current post (as a $post object) |
|
398 | + * @param array $metabox is an array with metabox id, title, callback, and args elements. the value |
|
399 | + * at 'args' has key 'payment_method', as set within _payment_methods_list |
|
400 | + * @return string |
|
401 | + * @throws EE_Error |
|
402 | + */ |
|
403 | + public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox) |
|
404 | + { |
|
405 | + $payment_method = isset($metabox['args'], $metabox['args']['payment_method']) |
|
406 | + ? $metabox['args']['payment_method'] : null; |
|
407 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
408 | + throw new EE_Error(sprintf(__('Payment method metabox setup incorrectly. No Payment method object was supplied', |
|
409 | + 'event_espresso'))); |
|
410 | + } |
|
411 | + $payment_method_scopes = $payment_method->active(); |
|
412 | + // if the payment method really exists show its form, otherwise the activation template |
|
413 | + if ($payment_method->ID() && ! empty($payment_method_scopes)) { |
|
414 | + $form = $this->_generate_payment_method_settings_form($payment_method); |
|
415 | + if ($form->form_data_present_in($this->_req_data)) { |
|
416 | + $form->receive_form_submission($this->_req_data); |
|
417 | + } |
|
418 | + echo $form->form_open() . $form->get_html_and_js() . $form->form_close(); |
|
419 | + } else { |
|
420 | + echo $this->_activate_payment_method_button($payment_method)->get_html_and_js(); |
|
421 | + } |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * Gets the form for all the settings related to this payment method type |
|
428 | + * |
|
429 | + * @access protected |
|
430 | + * @param \EE_Payment_Method $payment_method |
|
431 | + * @return \EE_Form_Section_Proper |
|
432 | + */ |
|
433 | + protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method) |
|
434 | + { |
|
435 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
436 | + return new EE_Form_Section_Proper(); |
|
437 | + } |
|
438 | + return new EE_Form_Section_Proper( |
|
439 | + array( |
|
440 | + 'name' => $payment_method->slug() . '_settings_form', |
|
441 | + 'html_id' => $payment_method->slug() . '_settings_form', |
|
442 | + 'action' => EE_Admin_Page::add_query_args_and_nonce( |
|
443 | + array( |
|
444 | + 'action' => 'update_payment_method', |
|
445 | + 'payment_method' => $payment_method->slug(), |
|
446 | + ), |
|
447 | + EE_PAYMENTS_ADMIN_URL |
|
448 | + ), |
|
449 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
450 | + 'subsections' => apply_filters( |
|
451 | + 'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections', |
|
452 | + array( |
|
453 | + 'pci_dss_compliance' => $this->_pci_dss_compliance($payment_method), |
|
454 | + 'currency_support' => $this->_currency_support($payment_method), |
|
455 | + 'payment_method_settings' => $this->_payment_method_settings($payment_method), |
|
456 | + 'update' => $this->_update_payment_method_button($payment_method), |
|
457 | + 'deactivate' => $this->_deactivate_payment_method_button($payment_method), |
|
458 | + 'fine_print' => $this->_fine_print(), |
|
459 | + ), |
|
460 | + $payment_method |
|
461 | + ), |
|
462 | + ) |
|
463 | + ); |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + |
|
468 | + /** |
|
469 | + * _pci_dss_compliance |
|
470 | + * |
|
471 | + * @access protected |
|
472 | + * @param \EE_Payment_Method $payment_method |
|
473 | + * @return \EE_Form_Section_Proper |
|
474 | + */ |
|
475 | + protected function _pci_dss_compliance(EE_Payment_Method $payment_method) |
|
476 | + { |
|
477 | + if ($payment_method->type_obj()->requires_https()) { |
|
478 | + return new EE_Form_Section_HTML( |
|
479 | + EEH_HTML::tr( |
|
480 | + EEH_HTML::th( |
|
481 | + EEH_HTML::label( |
|
482 | + EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
|
483 | + ) |
|
484 | + ) . |
|
485 | + EEH_HTML::td( |
|
486 | + EEH_HTML::strong(__('You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.', |
|
487 | + 'event_espresso')) |
|
488 | + . |
|
489 | + EEH_HTML::br() |
|
490 | + . |
|
491 | + __('Learn more about ', 'event_espresso') |
|
492 | + . EEH_HTML::link('https://www.pcisecuritystandards.org/merchants/index.php', |
|
493 | + __('PCI DSS compliance', 'event_espresso')) |
|
494 | + ) |
|
495 | + ) |
|
496 | + ); |
|
497 | + } else { |
|
498 | + return new EE_Form_Section_HTML(''); |
|
499 | + } |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * _currency_support |
|
506 | + * |
|
507 | + * @access protected |
|
508 | + * @param \EE_Payment_Method $payment_method |
|
509 | + * @return \EE_Form_Section_Proper |
|
510 | + */ |
|
511 | + protected function _currency_support(EE_Payment_Method $payment_method) |
|
512 | + { |
|
513 | + if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) { |
|
514 | + return new EE_Form_Section_HTML( |
|
515 | + EEH_HTML::tr( |
|
516 | + EEH_HTML::th( |
|
517 | + EEH_HTML::label( |
|
518 | + EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
|
519 | + ) |
|
520 | + ) . |
|
521 | + EEH_HTML::td( |
|
522 | + EEH_HTML::strong( |
|
523 | + sprintf( |
|
524 | + __('This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.', |
|
525 | + 'event_espresso'), |
|
526 | + EE_Config::instance()->currency->code |
|
527 | + ) |
|
528 | + ) |
|
529 | + ) |
|
530 | + ) |
|
531 | + ); |
|
532 | + } else { |
|
533 | + return new EE_Form_Section_HTML(''); |
|
534 | + } |
|
535 | + } |
|
536 | + |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * _update_payment_method_button |
|
541 | + * |
|
542 | + * @access protected |
|
543 | + * @param \EE_Payment_Method $payment_method |
|
544 | + * @return \EE_Form_Section_HTML |
|
545 | + */ |
|
546 | + protected function _payment_method_settings(EE_Payment_Method $payment_method) |
|
547 | + { |
|
548 | + //modify the form so we only have/show fields that will be implemented for this version |
|
549 | + return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name()); |
|
550 | + } |
|
551 | + |
|
552 | + |
|
553 | + |
|
554 | + /** |
|
555 | + * Simplifies the form to merely reproduce 4.1's gateway settings functionality |
|
556 | + * |
|
557 | + * @param EE_Form_Section_Proper $form_section |
|
558 | + * @param string $payment_method_name |
|
559 | + * @return \EE_Payment_Method_Form |
|
560 | + * @throws \EE_Error |
|
561 | + */ |
|
562 | + protected function _simplify_form($form_section, $payment_method_name = '') |
|
563 | + { |
|
564 | + if ($form_section instanceof EE_Payment_Method_Form) { |
|
565 | + $form_section->exclude( |
|
566 | + array( |
|
567 | + 'PMD_type', //dont want them changing the type |
|
568 | + 'PMD_slug', //or the slug (probably never) |
|
569 | + 'PMD_wp_user', //or the user's ID |
|
570 | + 'Currency' //or the currency, until the rest of EE supports simultaneous currencies |
|
571 | + ) |
|
572 | + ); |
|
573 | + return $form_section; |
|
574 | + } else { |
|
575 | + throw new EE_Error(sprintf(__('The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.', |
|
576 | + 'event_espresso'), $payment_method_name)); |
|
577 | + } |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * _update_payment_method_button |
|
584 | + * |
|
585 | + * @access protected |
|
586 | + * @param \EE_Payment_Method $payment_method |
|
587 | + * @return \EE_Form_Section_HTML |
|
588 | + */ |
|
589 | + protected function _update_payment_method_button(EE_Payment_Method $payment_method) |
|
590 | + { |
|
591 | + $update_button = new EE_Submit_Input( |
|
592 | + array( |
|
593 | + 'name' => 'submit', |
|
594 | + 'html_id' => 'save_' . $payment_method->slug() . '_settings', |
|
595 | + 'default' => sprintf(__('Update %s Payment Settings', 'event_espresso'), |
|
596 | + $payment_method->admin_name()), |
|
597 | + 'html_label' => EEH_HTML::nbsp(), |
|
598 | + ) |
|
599 | + ); |
|
600 | + return new EE_Form_Section_HTML( |
|
601 | + EEH_HTML::no_row(EEH_HTML::br(2)) . |
|
602 | + EEH_HTML::tr( |
|
603 | + EEH_HTML::th(__('Update Settings', 'event_espresso')) . |
|
604 | + EEH_HTML::td( |
|
605 | + $update_button->get_html_for_input() |
|
606 | + ) |
|
607 | + ) |
|
608 | + ); |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * _deactivate_payment_method_button |
|
615 | + * |
|
616 | + * @access protected |
|
617 | + * @param \EE_Payment_Method $payment_method |
|
618 | + * @return \EE_Form_Section_Proper |
|
619 | + */ |
|
620 | + protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method) |
|
621 | + { |
|
622 | + $link_text_and_title = sprintf(__('Deactivate %1$s Payments?', 'event_espresso'), |
|
623 | + $payment_method->admin_name()); |
|
624 | + return new EE_Form_Section_HTML( |
|
625 | + EEH_HTML::tr( |
|
626 | + EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) . |
|
627 | + EEH_HTML::td( |
|
628 | + EEH_HTML::link( |
|
629 | + EE_Admin_Page::add_query_args_and_nonce( |
|
630 | + array( |
|
631 | + 'action' => 'deactivate_payment_method', |
|
632 | + 'payment_method' => $payment_method->slug(), |
|
633 | + ), |
|
634 | + EE_PAYMENTS_ADMIN_URL |
|
635 | + ), |
|
636 | + $link_text_and_title, |
|
637 | + $link_text_and_title, |
|
638 | + 'deactivate_' . $payment_method->slug(), |
|
639 | + 'espresso-button button-secondary' |
|
640 | + ) |
|
641 | + ) |
|
642 | + ) |
|
643 | + ); |
|
644 | + } |
|
645 | + |
|
646 | + |
|
647 | + |
|
648 | + /** |
|
649 | + * _activate_payment_method_button |
|
650 | + * |
|
651 | + * @access protected |
|
652 | + * @param \EE_Payment_Method $payment_method |
|
653 | + * @return \EE_Form_Section_Proper |
|
654 | + */ |
|
655 | + protected function _activate_payment_method_button(EE_Payment_Method $payment_method) |
|
656 | + { |
|
657 | + $link_text_and_title = sprintf(__('Activate %1$s Payment Method?', 'event_espresso'), |
|
658 | + $payment_method->admin_name()); |
|
659 | + return new EE_Form_Section_Proper( |
|
660 | + array( |
|
661 | + 'name' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
662 | + 'html_id' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
663 | + 'action' => '#', |
|
664 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
665 | + 'subsections' => apply_filters( |
|
666 | + 'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections', |
|
667 | + array( |
|
668 | + new EE_Form_Section_HTML( |
|
669 | + EEH_HTML::tr( |
|
670 | + EEH_HTML::td($payment_method->type_obj()->introductory_html(), |
|
671 | + '', |
|
672 | + '', |
|
673 | + '', |
|
674 | + 'colspan="2"' |
|
675 | + ) |
|
676 | + ) . |
|
677 | + EEH_HTML::tr( |
|
678 | + EEH_HTML::th( |
|
679 | + EEH_HTML::label(__('Click to Activate ', 'event_espresso')) |
|
680 | + ) . |
|
681 | + EEH_HTML::td( |
|
682 | + EEH_HTML::link( |
|
683 | + EE_Admin_Page::add_query_args_and_nonce( |
|
684 | + array( |
|
685 | + 'action' => 'activate_payment_method', |
|
686 | + 'payment_method_type' => $payment_method->type(), |
|
687 | + ), |
|
688 | + EE_PAYMENTS_ADMIN_URL |
|
689 | + ), |
|
690 | + $link_text_and_title, |
|
691 | + $link_text_and_title, |
|
692 | + 'activate_' . $payment_method->slug(), |
|
693 | + 'espresso-button-green button-primary' |
|
694 | + ) |
|
695 | + ) |
|
696 | + ) |
|
697 | + ), |
|
698 | + ), |
|
699 | + $payment_method |
|
700 | + ), |
|
701 | + ) |
|
702 | + ); |
|
703 | + } |
|
704 | + |
|
705 | + |
|
706 | + |
|
707 | + /** |
|
708 | + * _fine_print |
|
709 | + * |
|
710 | + * @access protected |
|
711 | + * @return \EE_Form_Section_HTML |
|
712 | + */ |
|
713 | + protected function _fine_print() |
|
714 | + { |
|
715 | + return new EE_Form_Section_HTML( |
|
716 | + EEH_HTML::tr( |
|
717 | + EEH_HTML::th() . |
|
718 | + EEH_HTML::td( |
|
719 | + EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text') |
|
720 | + ) |
|
721 | + ) |
|
722 | + ); |
|
723 | + } |
|
724 | + |
|
725 | + |
|
726 | + |
|
727 | + /** |
|
728 | + * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far) |
|
729 | + * |
|
730 | + * @global WP_User $current_user |
|
731 | + */ |
|
732 | + protected function _activate_payment_method() |
|
733 | + { |
|
734 | + if (isset($this->_req_data['payment_method_type'])) { |
|
735 | + $payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']); |
|
736 | + //see if one exists |
|
737 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
738 | + $payment_method = EE_Payment_Method_Manager::instance() |
|
739 | + ->activate_a_payment_method_of_type($payment_method_type); |
|
740 | + $this->_redirect_after_action(1, 'Payment Method', 'activated', |
|
741 | + array('action' => 'default', 'payment_method' => $payment_method->slug())); |
|
742 | + } else { |
|
743 | + $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default')); |
|
744 | + } |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * Deactivates the payment method with the specified slug, and redirects. |
|
751 | + */ |
|
752 | + protected function _deactivate_payment_method() |
|
753 | + { |
|
754 | + if (isset($this->_req_data['payment_method'])) { |
|
755 | + $payment_method_slug = sanitize_key($this->_req_data['payment_method']); |
|
756 | + //deactivate it |
|
757 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
758 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug); |
|
759 | + $this->_redirect_after_action($count_updated, 'Payment Method', 'deactivated', |
|
760 | + array('action' => 'default', 'payment_method' => $payment_method_slug)); |
|
761 | + } else { |
|
762 | + $this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default')); |
|
763 | + } |
|
764 | + } |
|
765 | + |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * Processes the payment method form that was submitted. This is slightly trickier than usual form |
|
770 | + * processing because we first need to identify WHICH form was processed and which payment method |
|
771 | + * it corresponds to. Once we have done that, we see if the form is valid. If it is, the |
|
772 | + * form's data is saved and we redirect to the default payment methods page, setting the updated payment method |
|
773 | + * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the |
|
774 | + * subsequently called 'headers_sent_func' which is _payment_methods_list) |
|
775 | + * |
|
776 | + * @return void |
|
777 | + */ |
|
778 | + protected function _update_payment_method() |
|
779 | + { |
|
780 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
781 | + //ok let's find which gateway form to use based on the form input |
|
782 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
783 | + /** @var $correct_pmt_form_to_use EE_Payment_Method_Form */ |
|
784 | + $correct_pmt_form_to_use = null; |
|
785 | + $payment_method = null; |
|
786 | + foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) { |
|
787 | + //get the form and simplify it, like what we do when we display it |
|
788 | + $pmt_form = $this->_generate_payment_method_settings_form($payment_method); |
|
789 | + if ($pmt_form->form_data_present_in($this->_req_data)) { |
|
790 | + $correct_pmt_form_to_use = $pmt_form; |
|
791 | + break; |
|
792 | + } |
|
793 | + } |
|
794 | + //if we couldn't find the correct payment method type... |
|
795 | + if (! $correct_pmt_form_to_use) { |
|
796 | + EE_Error::add_error(__("We could not find which payment method type your form submission related to. Please contact support", |
|
797 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
798 | + $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default')); |
|
799 | + } |
|
800 | + $correct_pmt_form_to_use->receive_form_submission($this->_req_data); |
|
801 | + if ($correct_pmt_form_to_use->is_valid()) { |
|
802 | + $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings'); |
|
803 | + if (! $payment_settings_subform instanceof EE_Payment_Method_Form) { |
|
804 | + throw new EE_Error( |
|
805 | + sprintf( |
|
806 | + __('The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.', |
|
807 | + 'event_espresso'), |
|
808 | + 'payment_method_settings' |
|
809 | + ) |
|
810 | + ); |
|
811 | + } |
|
812 | + $payment_settings_subform->save(); |
|
813 | + /** @var $pm EE_Payment_Method */ |
|
814 | + $this->_redirect_after_action(true, 'Payment Method', 'updated', |
|
815 | + array('action' => 'default', 'payment_method' => $payment_method->slug())); |
|
816 | + } else { |
|
817 | + EE_Error::add_error( |
|
818 | + sprintf( |
|
819 | + __('Payment method of type %s was not saved because there were validation errors. They have been marked in the form', |
|
820 | + 'event_espresso'), |
|
821 | + $payment_method instanceof EE_Payment_Method ? $payment_method->type_obj()->pretty_name() |
|
822 | + : __('"(unknown)"', 'event_espresso') |
|
823 | + ), |
|
824 | + __FILE__, |
|
825 | + __FUNCTION__, |
|
826 | + __LINE__ |
|
827 | + ); |
|
828 | + } |
|
829 | + } |
|
830 | + return; |
|
831 | + } |
|
832 | + |
|
833 | + |
|
834 | + |
|
835 | + protected function _payment_settings() |
|
836 | + { |
|
837 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
838 | + $this->_template_args['show_pending_payment_options'] = isset(EE_Registry::instance()->CFG->registration->show_pending_payment_options) |
|
839 | + ? absint(EE_Registry::instance()->CFG->registration->show_pending_payment_options) : false; |
|
840 | + $this->_set_add_edit_form_tags('update_payment_settings'); |
|
841 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
842 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(EE_PAYMENTS_TEMPLATE_PATH |
|
843 | + . 'payment_settings.template.php', |
|
844 | + $this->_template_args, true); |
|
845 | + $this->display_admin_page_with_sidebar(); |
|
846 | + } |
|
847 | + |
|
848 | + |
|
849 | + |
|
850 | + /** |
|
851 | + * _update_payment_settings |
|
852 | + * |
|
853 | + * @access protected |
|
854 | + * @return array |
|
855 | + */ |
|
856 | + protected function _update_payment_settings() |
|
857 | + { |
|
858 | + EE_Registry::instance()->CFG->registration->show_pending_payment_options = isset($this->_req_data['show_pending_payment_options']) |
|
859 | + ? $this->_req_data['show_pending_payment_options'] : false; |
|
860 | + EE_Registry::instance()->CFG = apply_filters('FHEE__Payments_Admin_Page___update_payment_settings__CFG', |
|
861 | + EE_Registry::instance()->CFG); |
|
862 | 862 | // $superform = new EE_Form_Section_Proper( |
863 | 863 | // array( |
864 | 864 | // 'subsections' => array( |
@@ -876,176 +876,176 @@ discard block |
||
876 | 876 | // ); |
877 | 877 | // $this->_redirect_after_action( 0, 'settings', 'updated', array( 'action' => 'payment_settings' ) ); |
878 | 878 | // } |
879 | - $what = __('Payment Settings', 'event_espresso'); |
|
880 | - $success = $this->_update_espresso_configuration($what, EE_Registry::instance()->CFG, __FILE__, __FUNCTION__, |
|
881 | - __LINE__); |
|
882 | - $this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), |
|
883 | - array('action' => 'payment_settings')); |
|
884 | - } |
|
879 | + $what = __('Payment Settings', 'event_espresso'); |
|
880 | + $success = $this->_update_espresso_configuration($what, EE_Registry::instance()->CFG, __FILE__, __FUNCTION__, |
|
881 | + __LINE__); |
|
882 | + $this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), |
|
883 | + array('action' => 'payment_settings')); |
|
884 | + } |
|
885 | 885 | |
886 | 886 | |
887 | 887 | |
888 | - protected function _payment_log_overview_list_table() |
|
889 | - { |
|
888 | + protected function _payment_log_overview_list_table() |
|
889 | + { |
|
890 | 890 | // $this->_search_btn_label = __('Payment Log', 'event_espresso'); |
891 | - $this->display_admin_list_table_page_with_sidebar(); |
|
892 | - } |
|
893 | - |
|
894 | - |
|
895 | - |
|
896 | - protected function _set_list_table_views_payment_log() |
|
897 | - { |
|
898 | - $this->_views = array( |
|
899 | - 'all' => array( |
|
900 | - 'slug' => 'all', |
|
901 | - 'label' => __('View All Logs', 'event_espresso'), |
|
902 | - 'count' => 0, |
|
903 | - ), |
|
904 | - ); |
|
905 | - } |
|
906 | - |
|
907 | - |
|
908 | - |
|
909 | - /** |
|
910 | - * @param int $per_page |
|
911 | - * @param int $current_page |
|
912 | - * @param bool $count |
|
913 | - * @return array |
|
914 | - */ |
|
915 | - public function get_payment_logs($per_page = 50, $current_page = 0, $count = false) |
|
916 | - { |
|
917 | - EE_Registry::instance()->load_model('Change_Log'); |
|
918 | - //we may need to do multiple queries (joining differently), so we actually wan tan array of query params |
|
919 | - $query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway)); |
|
920 | - //check if they've selected a specific payment method |
|
921 | - if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') { |
|
922 | - $query_params[0]['OR*pm_or_pay_pm'] = array( |
|
923 | - 'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'], |
|
924 | - 'Payment_Method.PMD_ID' => $this->_req_data['_payment_method'], |
|
925 | - ); |
|
926 | - } |
|
927 | - //take into account search |
|
928 | - if (isset($this->_req_data['s']) && $this->_req_data['s']) { |
|
929 | - $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%'); |
|
930 | - $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string; |
|
931 | - $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string; |
|
932 | - $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string; |
|
933 | - $query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string; |
|
934 | - $query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string; |
|
935 | - $query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string; |
|
936 | - $query_params[0]['OR*s']['LOG_message'] = $similarity_string; |
|
937 | - $query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string; |
|
938 | - $query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string; |
|
939 | - $query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string; |
|
940 | - $query_params[0]['OR*s']['LOG_message'] = $similarity_string; |
|
941 | - } |
|
942 | - if (isset($this->_req_data['payment-filter-start-date']) |
|
943 | - && isset($this->_req_data['payment-filter-end-date']) |
|
944 | - ) { |
|
945 | - //add date |
|
946 | - $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']); |
|
947 | - $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']); |
|
948 | - //make sure our timestamps start and end right at the boundaries for each day |
|
949 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
950 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
951 | - //convert to timestamps |
|
952 | - $start_date = strtotime($start_date); |
|
953 | - $end_date = strtotime($end_date); |
|
954 | - //makes sure start date is the lowest value and vice versa |
|
955 | - $start_date = min($start_date, $end_date); |
|
956 | - $end_date = max($start_date, $end_date); |
|
957 | - //convert for query |
|
958 | - $start_date = EEM_Change_Log::instance() |
|
959 | - ->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $start_date), |
|
960 | - 'Y-m-d H:i:s'); |
|
961 | - $end_date = EEM_Change_Log::instance() |
|
962 | - ->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $end_date), |
|
963 | - 'Y-m-d H:i:s'); |
|
964 | - $query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date)); |
|
965 | - } |
|
966 | - if ($count) { |
|
967 | - return EEM_Change_Log::instance()->count($query_params); |
|
968 | - } |
|
969 | - if (isset($this->_req_data['order'])) { |
|
970 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
971 | - : 'DESC'; |
|
972 | - $query_params['order_by'] = array('LOG_time' => $sort); |
|
973 | - } else { |
|
974 | - $query_params['order_by'] = array('LOG_time' => 'DESC'); |
|
975 | - } |
|
976 | - $offset = ($current_page - 1) * $per_page; |
|
977 | - if (! isset($this->_req_data['download_results'])) { |
|
978 | - $query_params['limit'] = array($offset, $per_page); |
|
979 | - } |
|
980 | - //now they've requested to instead just download the file instead of viewing it. |
|
981 | - if (isset($this->_req_data['download_results'])) { |
|
982 | - $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params); |
|
983 | - header('Content-Disposition: attachment'); |
|
984 | - header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url())); |
|
985 | - echo "<h1>Payment Logs for " . site_url() . "</h1>"; |
|
986 | - echo "<h3>Query:</h3>"; |
|
987 | - var_dump($query_params); |
|
988 | - echo "<h3>Results:</h3>"; |
|
989 | - var_dump($wpdb_results); |
|
990 | - die; |
|
991 | - } |
|
992 | - $results = EEM_Change_Log::instance()->get_all($query_params); |
|
993 | - return $results; |
|
994 | - } |
|
995 | - |
|
996 | - |
|
997 | - |
|
998 | - /** |
|
999 | - * Used by usort to RE-sort log query results, because we lose the ordering |
|
1000 | - * because we're possibly combining the results from two queries |
|
1001 | - * |
|
1002 | - * @param EE_Change_Log $logA |
|
1003 | - * @param EE_Change_Log $logB |
|
1004 | - * @return int |
|
1005 | - */ |
|
1006 | - protected function _sort_logs_again($logA, $logB) |
|
1007 | - { |
|
1008 | - $timeA = $logA->get_raw('LOG_time'); |
|
1009 | - $timeB = $logB->get_raw('LOG_time'); |
|
1010 | - if ($timeA == $timeB) { |
|
1011 | - return 0; |
|
1012 | - } |
|
1013 | - $comparison = $timeA < $timeB ? -1 : 1; |
|
1014 | - if (strtoupper($this->_sort_logs_again_direction) == 'DESC') { |
|
1015 | - return $comparison * -1; |
|
1016 | - } else { |
|
1017 | - return $comparison; |
|
1018 | - } |
|
1019 | - } |
|
1020 | - |
|
1021 | - |
|
1022 | - |
|
1023 | - protected function _payment_log_details() |
|
1024 | - { |
|
1025 | - EE_Registry::instance()->load_model('Change_Log'); |
|
1026 | - /** @var $payment_log EE_Change_Log */ |
|
1027 | - $payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']); |
|
1028 | - $payment_method = null; |
|
1029 | - $transaction = null; |
|
1030 | - if ($payment_log instanceof EE_Change_Log) { |
|
1031 | - if ($payment_log->object() instanceof EE_Payment) { |
|
1032 | - $payment_method = $payment_log->object()->payment_method(); |
|
1033 | - $transaction = $payment_log->object()->transaction(); |
|
1034 | - } elseif ($payment_log->object() instanceof EE_Payment_Method) { |
|
1035 | - $payment_method = $payment_log->object(); |
|
1036 | - } |
|
1037 | - } |
|
1038 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
1039 | - EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php', |
|
1040 | - array( |
|
1041 | - 'payment_log' => $payment_log, |
|
1042 | - 'payment_method' => $payment_method, |
|
1043 | - 'transaction' => $transaction, |
|
1044 | - ), |
|
1045 | - true |
|
1046 | - ); |
|
1047 | - $this->display_admin_page_with_sidebar(); |
|
1048 | - } |
|
891 | + $this->display_admin_list_table_page_with_sidebar(); |
|
892 | + } |
|
893 | + |
|
894 | + |
|
895 | + |
|
896 | + protected function _set_list_table_views_payment_log() |
|
897 | + { |
|
898 | + $this->_views = array( |
|
899 | + 'all' => array( |
|
900 | + 'slug' => 'all', |
|
901 | + 'label' => __('View All Logs', 'event_espresso'), |
|
902 | + 'count' => 0, |
|
903 | + ), |
|
904 | + ); |
|
905 | + } |
|
906 | + |
|
907 | + |
|
908 | + |
|
909 | + /** |
|
910 | + * @param int $per_page |
|
911 | + * @param int $current_page |
|
912 | + * @param bool $count |
|
913 | + * @return array |
|
914 | + */ |
|
915 | + public function get_payment_logs($per_page = 50, $current_page = 0, $count = false) |
|
916 | + { |
|
917 | + EE_Registry::instance()->load_model('Change_Log'); |
|
918 | + //we may need to do multiple queries (joining differently), so we actually wan tan array of query params |
|
919 | + $query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway)); |
|
920 | + //check if they've selected a specific payment method |
|
921 | + if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') { |
|
922 | + $query_params[0]['OR*pm_or_pay_pm'] = array( |
|
923 | + 'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'], |
|
924 | + 'Payment_Method.PMD_ID' => $this->_req_data['_payment_method'], |
|
925 | + ); |
|
926 | + } |
|
927 | + //take into account search |
|
928 | + if (isset($this->_req_data['s']) && $this->_req_data['s']) { |
|
929 | + $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%'); |
|
930 | + $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string; |
|
931 | + $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string; |
|
932 | + $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string; |
|
933 | + $query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string; |
|
934 | + $query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string; |
|
935 | + $query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string; |
|
936 | + $query_params[0]['OR*s']['LOG_message'] = $similarity_string; |
|
937 | + $query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string; |
|
938 | + $query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string; |
|
939 | + $query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string; |
|
940 | + $query_params[0]['OR*s']['LOG_message'] = $similarity_string; |
|
941 | + } |
|
942 | + if (isset($this->_req_data['payment-filter-start-date']) |
|
943 | + && isset($this->_req_data['payment-filter-end-date']) |
|
944 | + ) { |
|
945 | + //add date |
|
946 | + $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']); |
|
947 | + $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']); |
|
948 | + //make sure our timestamps start and end right at the boundaries for each day |
|
949 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
950 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
951 | + //convert to timestamps |
|
952 | + $start_date = strtotime($start_date); |
|
953 | + $end_date = strtotime($end_date); |
|
954 | + //makes sure start date is the lowest value and vice versa |
|
955 | + $start_date = min($start_date, $end_date); |
|
956 | + $end_date = max($start_date, $end_date); |
|
957 | + //convert for query |
|
958 | + $start_date = EEM_Change_Log::instance() |
|
959 | + ->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $start_date), |
|
960 | + 'Y-m-d H:i:s'); |
|
961 | + $end_date = EEM_Change_Log::instance() |
|
962 | + ->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $end_date), |
|
963 | + 'Y-m-d H:i:s'); |
|
964 | + $query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date)); |
|
965 | + } |
|
966 | + if ($count) { |
|
967 | + return EEM_Change_Log::instance()->count($query_params); |
|
968 | + } |
|
969 | + if (isset($this->_req_data['order'])) { |
|
970 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
971 | + : 'DESC'; |
|
972 | + $query_params['order_by'] = array('LOG_time' => $sort); |
|
973 | + } else { |
|
974 | + $query_params['order_by'] = array('LOG_time' => 'DESC'); |
|
975 | + } |
|
976 | + $offset = ($current_page - 1) * $per_page; |
|
977 | + if (! isset($this->_req_data['download_results'])) { |
|
978 | + $query_params['limit'] = array($offset, $per_page); |
|
979 | + } |
|
980 | + //now they've requested to instead just download the file instead of viewing it. |
|
981 | + if (isset($this->_req_data['download_results'])) { |
|
982 | + $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params); |
|
983 | + header('Content-Disposition: attachment'); |
|
984 | + header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url())); |
|
985 | + echo "<h1>Payment Logs for " . site_url() . "</h1>"; |
|
986 | + echo "<h3>Query:</h3>"; |
|
987 | + var_dump($query_params); |
|
988 | + echo "<h3>Results:</h3>"; |
|
989 | + var_dump($wpdb_results); |
|
990 | + die; |
|
991 | + } |
|
992 | + $results = EEM_Change_Log::instance()->get_all($query_params); |
|
993 | + return $results; |
|
994 | + } |
|
995 | + |
|
996 | + |
|
997 | + |
|
998 | + /** |
|
999 | + * Used by usort to RE-sort log query results, because we lose the ordering |
|
1000 | + * because we're possibly combining the results from two queries |
|
1001 | + * |
|
1002 | + * @param EE_Change_Log $logA |
|
1003 | + * @param EE_Change_Log $logB |
|
1004 | + * @return int |
|
1005 | + */ |
|
1006 | + protected function _sort_logs_again($logA, $logB) |
|
1007 | + { |
|
1008 | + $timeA = $logA->get_raw('LOG_time'); |
|
1009 | + $timeB = $logB->get_raw('LOG_time'); |
|
1010 | + if ($timeA == $timeB) { |
|
1011 | + return 0; |
|
1012 | + } |
|
1013 | + $comparison = $timeA < $timeB ? -1 : 1; |
|
1014 | + if (strtoupper($this->_sort_logs_again_direction) == 'DESC') { |
|
1015 | + return $comparison * -1; |
|
1016 | + } else { |
|
1017 | + return $comparison; |
|
1018 | + } |
|
1019 | + } |
|
1020 | + |
|
1021 | + |
|
1022 | + |
|
1023 | + protected function _payment_log_details() |
|
1024 | + { |
|
1025 | + EE_Registry::instance()->load_model('Change_Log'); |
|
1026 | + /** @var $payment_log EE_Change_Log */ |
|
1027 | + $payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']); |
|
1028 | + $payment_method = null; |
|
1029 | + $transaction = null; |
|
1030 | + if ($payment_log instanceof EE_Change_Log) { |
|
1031 | + if ($payment_log->object() instanceof EE_Payment) { |
|
1032 | + $payment_method = $payment_log->object()->payment_method(); |
|
1033 | + $transaction = $payment_log->object()->transaction(); |
|
1034 | + } elseif ($payment_log->object() instanceof EE_Payment_Method) { |
|
1035 | + $payment_method = $payment_log->object(); |
|
1036 | + } |
|
1037 | + } |
|
1038 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
1039 | + EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php', |
|
1040 | + array( |
|
1041 | + 'payment_log' => $payment_log, |
|
1042 | + 'payment_method' => $payment_method, |
|
1043 | + 'transaction' => $transaction, |
|
1044 | + ), |
|
1045 | + true |
|
1046 | + ); |
|
1047 | + $this->display_admin_page_with_sidebar(); |
|
1048 | + } |
|
1049 | 1049 | |
1050 | 1050 | |
1051 | 1051 | } //end Payments_Admin_Page class |
@@ -372,6 +372,7 @@ |
||
372 | 372 | * save the relations indicated |
373 | 373 | * |
374 | 374 | * @type string $relation_name |
375 | + * @param integer $relation_name |
|
375 | 376 | * @return bool |
376 | 377 | * @throws EE_Error |
377 | 378 | */ |
@@ -14,439 +14,439 @@ |
||
14 | 14 | class EE_Model_Form_Section extends EE_Form_Section_Proper |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @var EEM_Base |
|
19 | - */ |
|
20 | - protected $_model = null; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var EE_Base_Class |
|
24 | - */ |
|
25 | - protected $_model_object = null; |
|
26 | - |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @param array $options_array keys: { |
|
31 | - * @type EEM_Base $model |
|
32 | - * @type EE_Base_Class $model_object |
|
33 | - * @type array $subsection_args array keys should be subsection names (that either do or will exist), and |
|
34 | - * values are the arrays as you would pass them to that subsection |
|
35 | - * } |
|
36 | - * @throws EE_Error |
|
37 | - */ |
|
38 | - public function __construct($options_array = array()) |
|
39 | - { |
|
40 | - if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) { |
|
41 | - $this->_model = $options_array['model']; |
|
42 | - } |
|
43 | - if (! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
44 | - throw new EE_Error(sprintf(__("Model Form Sections must first specify the _model property to be a subclass of EEM_Base", |
|
45 | - "event_espresso"))); |
|
46 | - } |
|
47 | - if (isset($options_array['subsection_args'])) { |
|
48 | - $subsection_args = $options_array['subsection_args']; |
|
49 | - } else { |
|
50 | - $subsection_args = array(); |
|
51 | - } |
|
52 | - //gather fields and relations to convert to inputs |
|
53 | - //but if they're just going to exclude a field anyways, don't bother converting it to an input |
|
54 | - $exclude = $this->_subsections; |
|
55 | - if (isset($options_array['exclude'])) { |
|
56 | - $exclude = array_merge($exclude, array_flip($options_array['exclude'])); |
|
57 | - } |
|
58 | - $model_fields = array_diff_key($this->_model->field_settings(), $exclude); |
|
59 | - $model_relations = array_diff_key($this->_model->relation_settings(), $exclude); |
|
60 | - //convert fields and relations to inputs |
|
61 | - $this->_subsections = array_merge( |
|
62 | - $this->_convert_model_fields_to_inputs($model_fields), |
|
63 | - $this->_convert_model_relations_to_inputs($model_relations, $subsection_args), |
|
64 | - $this->_subsections |
|
65 | - ); |
|
66 | - parent::__construct($options_array); |
|
67 | - if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) { |
|
68 | - $this->populate_model_obj($options_array['model_object']); |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * For now, just makes inputs for only HABTM relations |
|
76 | - * |
|
77 | - * @param EE_Model_Relation_Base[] $relations |
|
78 | - * @param array $subsection_args keys should be existing or soon-to-be-existing input names, and |
|
79 | - * their values are { |
|
80 | - * @type array { |
|
81 | - * @type EE_Base_Class[] $model_objects if the subsection is an EE_Select_Multi_Model_Input |
|
82 | - * } |
|
83 | - * } |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - protected function _convert_model_relations_to_inputs($relations, $subsection_args = array()) |
|
87 | - { |
|
88 | - $inputs = array(); |
|
89 | - foreach ($relations as $relation_name => $relation_obj) { |
|
90 | - $input_constructor_args = array( |
|
91 | - array_merge( |
|
92 | - array( |
|
93 | - 'required' => $relation_obj instanceof EE_Belongs_To_Relation, |
|
94 | - 'html_label_text' => $relation_obj instanceof EE_Belongs_To_Relation |
|
95 | - ? $relation_obj->get_other_model()->item_name(1) |
|
96 | - : $relation_obj->get_other_model() |
|
97 | - ->item_name(2), |
|
98 | - ), |
|
99 | - $subsection_args |
|
100 | - ), |
|
101 | - ); |
|
102 | - $input = null; |
|
103 | - switch (get_class($relation_obj)) { |
|
104 | - case 'EE_HABTM_Relation': |
|
105 | - if (isset($subsection_args[$relation_name]) |
|
106 | - && isset($subsection_args[$relation_name]['model_objects']) |
|
107 | - ) { |
|
108 | - $model_objects = $subsection_args[$relation_name]['model_objects']; |
|
109 | - } else { |
|
110 | - $model_objects = $relation_obj->get_other_model()->get_all(); |
|
111 | - } |
|
112 | - $input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args); |
|
113 | - break; |
|
114 | - default: |
|
115 | - } |
|
116 | - if ($input) { |
|
117 | - $inputs[$relation_name] = $input; |
|
118 | - } |
|
119 | - } |
|
120 | - return $inputs; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Changes model fields into form section inputs |
|
127 | - * |
|
128 | - * @param EE_Model_Field_Base[] $model_fields keys are the model's name |
|
129 | - * @throws EE_Error |
|
130 | - * @return EE_Form_Input_Base[] |
|
131 | - */ |
|
132 | - protected function _convert_model_fields_to_inputs($model_fields = array()) |
|
133 | - { |
|
134 | - $inputs = array(); |
|
135 | - foreach ($model_fields as $field_name => $model_field) { |
|
136 | - if ($model_field instanceof EE_Model_Field_Base) { |
|
137 | - $input_constructor_args = array( |
|
138 | - array( |
|
139 | - 'required' => ! $model_field->is_nullable() |
|
140 | - && $model_field->get_default_value() |
|
141 | - === null, |
|
142 | - 'html_label_text' => $model_field->get_nicename(), |
|
143 | - 'default' => $model_field->get_default_value(), |
|
144 | - ), |
|
145 | - ); |
|
146 | - switch (get_class($model_field)) { |
|
147 | - case 'EE_All_Caps_Text_Field': |
|
148 | - case 'EE_Any_Foreign_Model_Name_Field': |
|
149 | - $input_class = 'EE_Text_Input'; |
|
150 | - break; |
|
151 | - case 'EE_Boolean_Field': |
|
152 | - $input_class = 'EE_Yes_No_Input'; |
|
153 | - break; |
|
154 | - case 'EE_Datetime_Field': |
|
155 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
156 | - "event_espresso"), get_class($model_field))); |
|
157 | - break; |
|
158 | - case 'EE_Email_Field': |
|
159 | - $input_class = 'EE_Email_Input'; |
|
160 | - break; |
|
161 | - case 'EE_Enum_Integer_Field': |
|
162 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
163 | - "event_espresso"), get_class($model_field))); |
|
164 | - break; |
|
165 | - case 'EE_Enum_Text_Field': |
|
166 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
167 | - "event_espresso"), get_class($model_field))); |
|
168 | - break; |
|
169 | - case 'EE_Float_Field': |
|
170 | - $input_class = 'EE_Float_Input'; |
|
171 | - break; |
|
172 | - case 'EE_Foreign_Key_Int_Field': |
|
173 | - case 'EE_Foreign_Key_String_Field': |
|
174 | - case 'EE_WP_User_Field': |
|
175 | - $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name |
|
176 | - ? $model_field->get_model_class_names_pointed_to() : array(); |
|
177 | - if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) { |
|
178 | - $input_class = 'EE_Text_Input'; |
|
179 | - } else { |
|
180 | - //so its just one model |
|
181 | - $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to; |
|
182 | - $model = EE_Registry::instance()->load_model($model_name); |
|
183 | - $model_names = $model->get_all_names(array('limit' => 10)); |
|
184 | - if ($model_field->is_nullable()) { |
|
185 | - array_unshift($model_names, __("Please Select", 'event_espresso')); |
|
186 | - } |
|
187 | - $input_constructor_args[1] = $input_constructor_args[0]; |
|
188 | - $input_constructor_args[0] = $model_names; |
|
189 | - $input_class = 'EE_Select_Input'; |
|
190 | - } |
|
191 | - break; |
|
192 | - case 'EE_Full_HTML_Field': |
|
193 | - $input_class = 'EE_Text_Area_Input'; |
|
194 | - $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
195 | - break; |
|
196 | - case 'EE_Infinite_Integer': |
|
197 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
198 | - "event_espresso"), get_class($model_field))); |
|
199 | - break; |
|
200 | - case 'EE_Integer_Field': |
|
201 | - $input_class = 'EE_Text_Input'; |
|
202 | - break; |
|
203 | - case 'EE_Maybe_Serialized_Text_Field': |
|
204 | - $input_class = 'EE_Text_Area_Input'; |
|
205 | - break; |
|
206 | - case 'EE_Money_Field': |
|
207 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
208 | - "event_espresso"), get_class($model_field))); |
|
209 | - break; |
|
210 | - case 'EE_Post_Content_Field': |
|
211 | - $input_class = 'EE_Text_Area_Input'; |
|
212 | - $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
213 | - break; |
|
214 | - case 'EE_Plain_Text_Field': |
|
215 | - $input_class = 'EE_Text_Input'; |
|
216 | - break; |
|
217 | - case 'EE_Primary_Key_Int_Field': |
|
218 | - $input_class = 'EE_Hidden_Input'; |
|
219 | - $input_constructor_args['normalization_strategy'] = new EE_Int_Normalization(); |
|
220 | - break; |
|
221 | - case 'EE_Primary_Key_String_Field': |
|
222 | - $input_class = 'EE_Hidden_Input'; |
|
223 | - break; |
|
224 | - case 'EE_Serialized_Text_Field': |
|
225 | - $input_class = 'EE_Text_Area_Input'; |
|
226 | - break; |
|
227 | - case 'EE_Simple_HTML_Field': |
|
228 | - $input_class = 'EE_Text_Area_Input'; |
|
229 | - $input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy()); |
|
230 | - break; |
|
231 | - case 'EE_Slug_Field': |
|
232 | - $input_class = 'EE_Text_Input'; |
|
233 | - break; |
|
234 | - case 'EE_Trashed_Flag_Field': |
|
235 | - $input_class = 'EE_Yes_No_Input'; |
|
236 | - break; |
|
237 | - case 'EE_WP_Post_Status_Field': |
|
238 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
239 | - "event_espresso"), get_class($model_field))); |
|
240 | - break; |
|
241 | - case 'EE_WP_Post_Type_Field': |
|
242 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
243 | - "event_espresso"), get_class($model_field))); |
|
244 | - break; |
|
245 | - default: |
|
246 | - throw new EE_Error(sprintf(__("Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement", |
|
247 | - "event_espresso"), get_class($model_field))); |
|
248 | - } |
|
249 | - $reflection = new ReflectionClass($input_class); |
|
250 | - $input = $reflection->newInstanceArgs($input_constructor_args); |
|
251 | - $inputs[$field_name] = $input; |
|
252 | - } |
|
253 | - } |
|
254 | - return $inputs; |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * Mostly the same as populate_defaults , except takes a model object as input, not an array, |
|
261 | - * and also sets the form's _model_object |
|
262 | - * |
|
263 | - * @param EE_Base_Class $model_obj |
|
264 | - * @return void |
|
265 | - */ |
|
266 | - public function populate_model_obj($model_obj) |
|
267 | - { |
|
268 | - $model_obj = $this->_model->ensure_is_obj($model_obj); |
|
269 | - $this->_model_object = $model_obj; |
|
270 | - $defaults = $model_obj->model_field_array(); |
|
271 | - foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
272 | - $subsection = $this->get_subsection($relation_name, false); |
|
273 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
274 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
275 | - //then we only expect there to be one |
|
276 | - $related_item = $this->_model_object->get_first_related($relation_name); |
|
277 | - $defaults[$relation_name] = $related_item->ID(); |
|
278 | - } else { |
|
279 | - $related_items = $this->_model_object->get_many_related($relation_name); |
|
280 | - $ids = array(); |
|
281 | - foreach ($related_items as $related_item) { |
|
282 | - $ids[] = $related_item->ID(); |
|
283 | - } |
|
284 | - $defaults[$relation_name] = $ids; |
|
285 | - } |
|
286 | - } |
|
287 | - } |
|
288 | - $defaults = apply_filters( |
|
289 | - 'FHEE__EE_Model_Form_Section__populate_model_obj', |
|
290 | - $defaults, |
|
291 | - $this |
|
292 | - ); |
|
293 | - $this->populate_defaults($defaults); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * Gets all the input values that correspond to model fields. Keys are the input/field names, |
|
300 | - * values are their normalized values |
|
301 | - * |
|
302 | - * @return array |
|
303 | - */ |
|
304 | - public function inputs_values_corresponding_to_model_fields() |
|
305 | - { |
|
306 | - return array_intersect_key($this->input_values(), $this->_model->field_settings()); |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * After we've normalized the data as normal, set the corresponding model object |
|
313 | - * on the form. |
|
314 | - * |
|
315 | - * @param array $req_data should usually be $_REQUEST (the default). |
|
316 | - * @return void |
|
317 | - */ |
|
318 | - public function _normalize($req_data) |
|
319 | - { |
|
320 | - parent::_normalize($req_data); |
|
321 | - //create or set the model object, if it isn't already |
|
322 | - if (! $this->_model_object) { |
|
323 | - //check to see if the form indicates a PK, in which case we want to only retrieve it and update it |
|
324 | - $pk_name = $this->_model->primary_key_name(); |
|
325 | - $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
|
326 | - if ($model_obj) { |
|
327 | - $this->_model_object = $model_obj; |
|
328 | - } else { |
|
329 | - $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name()); |
|
330 | - } |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * After this form has been initialized and is verified to be valid, |
|
338 | - * either creates a model object from its data and saves it, or updates |
|
339 | - * the model object its data represents |
|
340 | - * |
|
341 | - * @throws EE_Error |
|
342 | - * @return int, 1 on a successful update, the ID of |
|
343 | - * the new entry on insert; 0 on failure |
|
344 | - */ |
|
345 | - public function save() |
|
346 | - { |
|
347 | - if (! $this->_model_object) { |
|
348 | - throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically", |
|
349 | - "event_espresso"), get_class($this->_model))); |
|
350 | - } |
|
351 | - //ok so the model object is set. Just set it with the submitted form data |
|
352 | - foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name => $field_value) { |
|
353 | - //only set the non-primary key |
|
354 | - if ($field_name != $this->_model->primary_key_name()) { |
|
355 | - $this->_model_object->set($field_name, $field_value); |
|
356 | - } |
|
357 | - } |
|
358 | - $success = $this->_model_object->save(); |
|
359 | - foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
360 | - if (isset($this->_subsections[$relation_name])) { |
|
361 | - $success = $this->_save_related_info($relation_name); |
|
362 | - } |
|
363 | - } |
|
364 | - do_action('AHEE__EE_Model_Form_Section__save__done', $this, $success); |
|
365 | - return $success; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * Automatically finds the related model info from the form, if present, and |
|
372 | - * save the relations indicated |
|
373 | - * |
|
374 | - * @type string $relation_name |
|
375 | - * @return bool |
|
376 | - * @throws EE_Error |
|
377 | - */ |
|
378 | - protected function _save_related_info($relation_name) |
|
379 | - { |
|
380 | - $relation_obj = $this->_model->related_settings_for($relation_name); |
|
381 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
382 | - //there is just a foreign key on this model pointing to that one |
|
383 | - $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); |
|
384 | - } elseif ($relation_obj instanceof EE_Has_Many_Relation) { |
|
385 | - //then we want to consider all of its currently-related things. |
|
386 | - //if they're in this list, keep them |
|
387 | - //if they're not in this list, remove them |
|
388 | - //and lastly add all the new items |
|
389 | - throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported', |
|
390 | - "event_espresso"))); |
|
391 | - } elseif ($relation_obj instanceof EE_HABTM_Relation) { |
|
392 | - //delete everything NOT in this list |
|
393 | - $normalized_input_value = $this->get_input_value($relation_name); |
|
394 | - if ($normalized_input_value && is_array($normalized_input_value)) { |
|
395 | - $where_query_params = array( |
|
396 | - $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value), |
|
397 | - ); |
|
398 | - } else { |
|
399 | - $where_query_params = array(); |
|
400 | - } |
|
401 | - $this->_model_object->_remove_relations($relation_name, $where_query_params); |
|
402 | - foreach ($normalized_input_value as $id) { |
|
403 | - $this->_model_object->_add_relation_to($id, $relation_name); |
|
404 | - } |
|
405 | - } |
|
406 | - return true; |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * Gets the model of this model form |
|
413 | - * |
|
414 | - * @return EEM_Base |
|
415 | - */ |
|
416 | - public function get_model() |
|
417 | - { |
|
418 | - return $this->_model; |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * Gets the model object for this model form, which was either set |
|
425 | - * upon construction (using the $options_array arg 'model_object'), by using |
|
426 | - * set_model_object($model_obj), or implicitly |
|
427 | - * when receive_form_submission($req_data) was called. |
|
428 | - * |
|
429 | - * @return EE_Base_Class |
|
430 | - */ |
|
431 | - public function get_model_object() |
|
432 | - { |
|
433 | - return $this->_model_object; |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * gets teh default name of this form section if none is specified |
|
440 | - * |
|
441 | - * @return string |
|
442 | - */ |
|
443 | - protected function _set_default_name_if_empty() |
|
444 | - { |
|
445 | - if (! $this->_name) { |
|
446 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
447 | - $this->_name = $default_name; |
|
448 | - } |
|
449 | - } |
|
17 | + /** |
|
18 | + * @var EEM_Base |
|
19 | + */ |
|
20 | + protected $_model = null; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var EE_Base_Class |
|
24 | + */ |
|
25 | + protected $_model_object = null; |
|
26 | + |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @param array $options_array keys: { |
|
31 | + * @type EEM_Base $model |
|
32 | + * @type EE_Base_Class $model_object |
|
33 | + * @type array $subsection_args array keys should be subsection names (that either do or will exist), and |
|
34 | + * values are the arrays as you would pass them to that subsection |
|
35 | + * } |
|
36 | + * @throws EE_Error |
|
37 | + */ |
|
38 | + public function __construct($options_array = array()) |
|
39 | + { |
|
40 | + if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) { |
|
41 | + $this->_model = $options_array['model']; |
|
42 | + } |
|
43 | + if (! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
44 | + throw new EE_Error(sprintf(__("Model Form Sections must first specify the _model property to be a subclass of EEM_Base", |
|
45 | + "event_espresso"))); |
|
46 | + } |
|
47 | + if (isset($options_array['subsection_args'])) { |
|
48 | + $subsection_args = $options_array['subsection_args']; |
|
49 | + } else { |
|
50 | + $subsection_args = array(); |
|
51 | + } |
|
52 | + //gather fields and relations to convert to inputs |
|
53 | + //but if they're just going to exclude a field anyways, don't bother converting it to an input |
|
54 | + $exclude = $this->_subsections; |
|
55 | + if (isset($options_array['exclude'])) { |
|
56 | + $exclude = array_merge($exclude, array_flip($options_array['exclude'])); |
|
57 | + } |
|
58 | + $model_fields = array_diff_key($this->_model->field_settings(), $exclude); |
|
59 | + $model_relations = array_diff_key($this->_model->relation_settings(), $exclude); |
|
60 | + //convert fields and relations to inputs |
|
61 | + $this->_subsections = array_merge( |
|
62 | + $this->_convert_model_fields_to_inputs($model_fields), |
|
63 | + $this->_convert_model_relations_to_inputs($model_relations, $subsection_args), |
|
64 | + $this->_subsections |
|
65 | + ); |
|
66 | + parent::__construct($options_array); |
|
67 | + if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) { |
|
68 | + $this->populate_model_obj($options_array['model_object']); |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * For now, just makes inputs for only HABTM relations |
|
76 | + * |
|
77 | + * @param EE_Model_Relation_Base[] $relations |
|
78 | + * @param array $subsection_args keys should be existing or soon-to-be-existing input names, and |
|
79 | + * their values are { |
|
80 | + * @type array { |
|
81 | + * @type EE_Base_Class[] $model_objects if the subsection is an EE_Select_Multi_Model_Input |
|
82 | + * } |
|
83 | + * } |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + protected function _convert_model_relations_to_inputs($relations, $subsection_args = array()) |
|
87 | + { |
|
88 | + $inputs = array(); |
|
89 | + foreach ($relations as $relation_name => $relation_obj) { |
|
90 | + $input_constructor_args = array( |
|
91 | + array_merge( |
|
92 | + array( |
|
93 | + 'required' => $relation_obj instanceof EE_Belongs_To_Relation, |
|
94 | + 'html_label_text' => $relation_obj instanceof EE_Belongs_To_Relation |
|
95 | + ? $relation_obj->get_other_model()->item_name(1) |
|
96 | + : $relation_obj->get_other_model() |
|
97 | + ->item_name(2), |
|
98 | + ), |
|
99 | + $subsection_args |
|
100 | + ), |
|
101 | + ); |
|
102 | + $input = null; |
|
103 | + switch (get_class($relation_obj)) { |
|
104 | + case 'EE_HABTM_Relation': |
|
105 | + if (isset($subsection_args[$relation_name]) |
|
106 | + && isset($subsection_args[$relation_name]['model_objects']) |
|
107 | + ) { |
|
108 | + $model_objects = $subsection_args[$relation_name]['model_objects']; |
|
109 | + } else { |
|
110 | + $model_objects = $relation_obj->get_other_model()->get_all(); |
|
111 | + } |
|
112 | + $input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args); |
|
113 | + break; |
|
114 | + default: |
|
115 | + } |
|
116 | + if ($input) { |
|
117 | + $inputs[$relation_name] = $input; |
|
118 | + } |
|
119 | + } |
|
120 | + return $inputs; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Changes model fields into form section inputs |
|
127 | + * |
|
128 | + * @param EE_Model_Field_Base[] $model_fields keys are the model's name |
|
129 | + * @throws EE_Error |
|
130 | + * @return EE_Form_Input_Base[] |
|
131 | + */ |
|
132 | + protected function _convert_model_fields_to_inputs($model_fields = array()) |
|
133 | + { |
|
134 | + $inputs = array(); |
|
135 | + foreach ($model_fields as $field_name => $model_field) { |
|
136 | + if ($model_field instanceof EE_Model_Field_Base) { |
|
137 | + $input_constructor_args = array( |
|
138 | + array( |
|
139 | + 'required' => ! $model_field->is_nullable() |
|
140 | + && $model_field->get_default_value() |
|
141 | + === null, |
|
142 | + 'html_label_text' => $model_field->get_nicename(), |
|
143 | + 'default' => $model_field->get_default_value(), |
|
144 | + ), |
|
145 | + ); |
|
146 | + switch (get_class($model_field)) { |
|
147 | + case 'EE_All_Caps_Text_Field': |
|
148 | + case 'EE_Any_Foreign_Model_Name_Field': |
|
149 | + $input_class = 'EE_Text_Input'; |
|
150 | + break; |
|
151 | + case 'EE_Boolean_Field': |
|
152 | + $input_class = 'EE_Yes_No_Input'; |
|
153 | + break; |
|
154 | + case 'EE_Datetime_Field': |
|
155 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
156 | + "event_espresso"), get_class($model_field))); |
|
157 | + break; |
|
158 | + case 'EE_Email_Field': |
|
159 | + $input_class = 'EE_Email_Input'; |
|
160 | + break; |
|
161 | + case 'EE_Enum_Integer_Field': |
|
162 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
163 | + "event_espresso"), get_class($model_field))); |
|
164 | + break; |
|
165 | + case 'EE_Enum_Text_Field': |
|
166 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
167 | + "event_espresso"), get_class($model_field))); |
|
168 | + break; |
|
169 | + case 'EE_Float_Field': |
|
170 | + $input_class = 'EE_Float_Input'; |
|
171 | + break; |
|
172 | + case 'EE_Foreign_Key_Int_Field': |
|
173 | + case 'EE_Foreign_Key_String_Field': |
|
174 | + case 'EE_WP_User_Field': |
|
175 | + $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name |
|
176 | + ? $model_field->get_model_class_names_pointed_to() : array(); |
|
177 | + if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) { |
|
178 | + $input_class = 'EE_Text_Input'; |
|
179 | + } else { |
|
180 | + //so its just one model |
|
181 | + $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to; |
|
182 | + $model = EE_Registry::instance()->load_model($model_name); |
|
183 | + $model_names = $model->get_all_names(array('limit' => 10)); |
|
184 | + if ($model_field->is_nullable()) { |
|
185 | + array_unshift($model_names, __("Please Select", 'event_espresso')); |
|
186 | + } |
|
187 | + $input_constructor_args[1] = $input_constructor_args[0]; |
|
188 | + $input_constructor_args[0] = $model_names; |
|
189 | + $input_class = 'EE_Select_Input'; |
|
190 | + } |
|
191 | + break; |
|
192 | + case 'EE_Full_HTML_Field': |
|
193 | + $input_class = 'EE_Text_Area_Input'; |
|
194 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
195 | + break; |
|
196 | + case 'EE_Infinite_Integer': |
|
197 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
198 | + "event_espresso"), get_class($model_field))); |
|
199 | + break; |
|
200 | + case 'EE_Integer_Field': |
|
201 | + $input_class = 'EE_Text_Input'; |
|
202 | + break; |
|
203 | + case 'EE_Maybe_Serialized_Text_Field': |
|
204 | + $input_class = 'EE_Text_Area_Input'; |
|
205 | + break; |
|
206 | + case 'EE_Money_Field': |
|
207 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
208 | + "event_espresso"), get_class($model_field))); |
|
209 | + break; |
|
210 | + case 'EE_Post_Content_Field': |
|
211 | + $input_class = 'EE_Text_Area_Input'; |
|
212 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
213 | + break; |
|
214 | + case 'EE_Plain_Text_Field': |
|
215 | + $input_class = 'EE_Text_Input'; |
|
216 | + break; |
|
217 | + case 'EE_Primary_Key_Int_Field': |
|
218 | + $input_class = 'EE_Hidden_Input'; |
|
219 | + $input_constructor_args['normalization_strategy'] = new EE_Int_Normalization(); |
|
220 | + break; |
|
221 | + case 'EE_Primary_Key_String_Field': |
|
222 | + $input_class = 'EE_Hidden_Input'; |
|
223 | + break; |
|
224 | + case 'EE_Serialized_Text_Field': |
|
225 | + $input_class = 'EE_Text_Area_Input'; |
|
226 | + break; |
|
227 | + case 'EE_Simple_HTML_Field': |
|
228 | + $input_class = 'EE_Text_Area_Input'; |
|
229 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy()); |
|
230 | + break; |
|
231 | + case 'EE_Slug_Field': |
|
232 | + $input_class = 'EE_Text_Input'; |
|
233 | + break; |
|
234 | + case 'EE_Trashed_Flag_Field': |
|
235 | + $input_class = 'EE_Yes_No_Input'; |
|
236 | + break; |
|
237 | + case 'EE_WP_Post_Status_Field': |
|
238 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
239 | + "event_espresso"), get_class($model_field))); |
|
240 | + break; |
|
241 | + case 'EE_WP_Post_Type_Field': |
|
242 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
243 | + "event_espresso"), get_class($model_field))); |
|
244 | + break; |
|
245 | + default: |
|
246 | + throw new EE_Error(sprintf(__("Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement", |
|
247 | + "event_espresso"), get_class($model_field))); |
|
248 | + } |
|
249 | + $reflection = new ReflectionClass($input_class); |
|
250 | + $input = $reflection->newInstanceArgs($input_constructor_args); |
|
251 | + $inputs[$field_name] = $input; |
|
252 | + } |
|
253 | + } |
|
254 | + return $inputs; |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * Mostly the same as populate_defaults , except takes a model object as input, not an array, |
|
261 | + * and also sets the form's _model_object |
|
262 | + * |
|
263 | + * @param EE_Base_Class $model_obj |
|
264 | + * @return void |
|
265 | + */ |
|
266 | + public function populate_model_obj($model_obj) |
|
267 | + { |
|
268 | + $model_obj = $this->_model->ensure_is_obj($model_obj); |
|
269 | + $this->_model_object = $model_obj; |
|
270 | + $defaults = $model_obj->model_field_array(); |
|
271 | + foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
272 | + $subsection = $this->get_subsection($relation_name, false); |
|
273 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
274 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
275 | + //then we only expect there to be one |
|
276 | + $related_item = $this->_model_object->get_first_related($relation_name); |
|
277 | + $defaults[$relation_name] = $related_item->ID(); |
|
278 | + } else { |
|
279 | + $related_items = $this->_model_object->get_many_related($relation_name); |
|
280 | + $ids = array(); |
|
281 | + foreach ($related_items as $related_item) { |
|
282 | + $ids[] = $related_item->ID(); |
|
283 | + } |
|
284 | + $defaults[$relation_name] = $ids; |
|
285 | + } |
|
286 | + } |
|
287 | + } |
|
288 | + $defaults = apply_filters( |
|
289 | + 'FHEE__EE_Model_Form_Section__populate_model_obj', |
|
290 | + $defaults, |
|
291 | + $this |
|
292 | + ); |
|
293 | + $this->populate_defaults($defaults); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * Gets all the input values that correspond to model fields. Keys are the input/field names, |
|
300 | + * values are their normalized values |
|
301 | + * |
|
302 | + * @return array |
|
303 | + */ |
|
304 | + public function inputs_values_corresponding_to_model_fields() |
|
305 | + { |
|
306 | + return array_intersect_key($this->input_values(), $this->_model->field_settings()); |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * After we've normalized the data as normal, set the corresponding model object |
|
313 | + * on the form. |
|
314 | + * |
|
315 | + * @param array $req_data should usually be $_REQUEST (the default). |
|
316 | + * @return void |
|
317 | + */ |
|
318 | + public function _normalize($req_data) |
|
319 | + { |
|
320 | + parent::_normalize($req_data); |
|
321 | + //create or set the model object, if it isn't already |
|
322 | + if (! $this->_model_object) { |
|
323 | + //check to see if the form indicates a PK, in which case we want to only retrieve it and update it |
|
324 | + $pk_name = $this->_model->primary_key_name(); |
|
325 | + $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
|
326 | + if ($model_obj) { |
|
327 | + $this->_model_object = $model_obj; |
|
328 | + } else { |
|
329 | + $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name()); |
|
330 | + } |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * After this form has been initialized and is verified to be valid, |
|
338 | + * either creates a model object from its data and saves it, or updates |
|
339 | + * the model object its data represents |
|
340 | + * |
|
341 | + * @throws EE_Error |
|
342 | + * @return int, 1 on a successful update, the ID of |
|
343 | + * the new entry on insert; 0 on failure |
|
344 | + */ |
|
345 | + public function save() |
|
346 | + { |
|
347 | + if (! $this->_model_object) { |
|
348 | + throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically", |
|
349 | + "event_espresso"), get_class($this->_model))); |
|
350 | + } |
|
351 | + //ok so the model object is set. Just set it with the submitted form data |
|
352 | + foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name => $field_value) { |
|
353 | + //only set the non-primary key |
|
354 | + if ($field_name != $this->_model->primary_key_name()) { |
|
355 | + $this->_model_object->set($field_name, $field_value); |
|
356 | + } |
|
357 | + } |
|
358 | + $success = $this->_model_object->save(); |
|
359 | + foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
360 | + if (isset($this->_subsections[$relation_name])) { |
|
361 | + $success = $this->_save_related_info($relation_name); |
|
362 | + } |
|
363 | + } |
|
364 | + do_action('AHEE__EE_Model_Form_Section__save__done', $this, $success); |
|
365 | + return $success; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * Automatically finds the related model info from the form, if present, and |
|
372 | + * save the relations indicated |
|
373 | + * |
|
374 | + * @type string $relation_name |
|
375 | + * @return bool |
|
376 | + * @throws EE_Error |
|
377 | + */ |
|
378 | + protected function _save_related_info($relation_name) |
|
379 | + { |
|
380 | + $relation_obj = $this->_model->related_settings_for($relation_name); |
|
381 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
382 | + //there is just a foreign key on this model pointing to that one |
|
383 | + $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); |
|
384 | + } elseif ($relation_obj instanceof EE_Has_Many_Relation) { |
|
385 | + //then we want to consider all of its currently-related things. |
|
386 | + //if they're in this list, keep them |
|
387 | + //if they're not in this list, remove them |
|
388 | + //and lastly add all the new items |
|
389 | + throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported', |
|
390 | + "event_espresso"))); |
|
391 | + } elseif ($relation_obj instanceof EE_HABTM_Relation) { |
|
392 | + //delete everything NOT in this list |
|
393 | + $normalized_input_value = $this->get_input_value($relation_name); |
|
394 | + if ($normalized_input_value && is_array($normalized_input_value)) { |
|
395 | + $where_query_params = array( |
|
396 | + $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value), |
|
397 | + ); |
|
398 | + } else { |
|
399 | + $where_query_params = array(); |
|
400 | + } |
|
401 | + $this->_model_object->_remove_relations($relation_name, $where_query_params); |
|
402 | + foreach ($normalized_input_value as $id) { |
|
403 | + $this->_model_object->_add_relation_to($id, $relation_name); |
|
404 | + } |
|
405 | + } |
|
406 | + return true; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * Gets the model of this model form |
|
413 | + * |
|
414 | + * @return EEM_Base |
|
415 | + */ |
|
416 | + public function get_model() |
|
417 | + { |
|
418 | + return $this->_model; |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * Gets the model object for this model form, which was either set |
|
425 | + * upon construction (using the $options_array arg 'model_object'), by using |
|
426 | + * set_model_object($model_obj), or implicitly |
|
427 | + * when receive_form_submission($req_data) was called. |
|
428 | + * |
|
429 | + * @return EE_Base_Class |
|
430 | + */ |
|
431 | + public function get_model_object() |
|
432 | + { |
|
433 | + return $this->_model_object; |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * gets teh default name of this form section if none is specified |
|
440 | + * |
|
441 | + * @return string |
|
442 | + */ |
|
443 | + protected function _set_default_name_if_empty() |
|
444 | + { |
|
445 | + if (! $this->_name) { |
|
446 | + $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
447 | + $this->_name = $default_name; |
|
448 | + } |
|
449 | + } |
|
450 | 450 | |
451 | 451 | |
452 | 452 |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) { |
41 | 41 | $this->_model = $options_array['model']; |
42 | 42 | } |
43 | - if (! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
43 | + if ( ! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
44 | 44 | throw new EE_Error(sprintf(__("Model Form Sections must first specify the _model property to be a subclass of EEM_Base", |
45 | 45 | "event_espresso"))); |
46 | 46 | } |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | { |
320 | 320 | parent::_normalize($req_data); |
321 | 321 | //create or set the model object, if it isn't already |
322 | - if (! $this->_model_object) { |
|
322 | + if ( ! $this->_model_object) { |
|
323 | 323 | //check to see if the form indicates a PK, in which case we want to only retrieve it and update it |
324 | 324 | $pk_name = $this->_model->primary_key_name(); |
325 | 325 | $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | */ |
345 | 345 | public function save() |
346 | 346 | { |
347 | - if (! $this->_model_object) { |
|
347 | + if ( ! $this->_model_object) { |
|
348 | 348 | throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically", |
349 | 349 | "event_espresso"), get_class($this->_model))); |
350 | 350 | } |
@@ -442,8 +442,8 @@ discard block |
||
442 | 442 | */ |
443 | 443 | protected function _set_default_name_if_empty() |
444 | 444 | { |
445 | - if (! $this->_name) { |
|
446 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
445 | + if ( ! $this->_name) { |
|
446 | + $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form"; |
|
447 | 447 | $this->_name = $default_name; |
448 | 448 | } |
449 | 449 | } |
@@ -119,7 +119,7 @@ |
||
119 | 119 | |
120 | 120 | |
121 | 121 | /** |
122 | - * @param $payment_method_type |
|
122 | + * @param EE_PMT_Base $payment_method_type |
|
123 | 123 | * @throws EE_Error |
124 | 124 | */ |
125 | 125 | public function set_payment_method_type($payment_method_type) |
@@ -9,189 +9,189 @@ |
||
9 | 9 | class EE_Payment_Method_Form extends EE_Model_Form_Section |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * All the subsection inputs that correspond ot extra meta rows |
|
14 | - * for this payment method |
|
15 | - * |
|
16 | - * @var EE_Form_Input_Base[] |
|
17 | - */ |
|
18 | - protected $_extra_meta_inputs = array(); |
|
19 | - |
|
20 | - /** |
|
21 | - * Because payment method form might DELAY part of construction, we want to remember |
|
22 | - * what options were passed in |
|
23 | - * |
|
24 | - * @var array |
|
25 | - */ |
|
26 | - protected $_options_array = array(); |
|
27 | - |
|
28 | - /** |
|
29 | - * The payment method type for this form |
|
30 | - * |
|
31 | - * @var EE_PMT_Base |
|
32 | - */ |
|
33 | - protected $_payment_method_type; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @param array $options_array { |
|
39 | - * @type string $extra_meta_inputs should be EE_Form_Section_Validatable[] which |
|
40 | - * will be _subsections and will be saved as extra meta on the payment |
|
41 | - * method object; |
|
42 | - * @type EE_PMT_Base $payment_method_type the payment method type this form is for |
|
43 | - * @see EE_Model_Form_Section::__construct() for more |
|
44 | - * } |
|
45 | - */ |
|
46 | - public function __construct($options_array = array()) |
|
47 | - { |
|
48 | - $this->_model = EEM_Payment_Method::instance(); |
|
49 | - $this->_options_array = $options_array; |
|
50 | - if (isset($options_array['payment_method_type'])) { |
|
51 | - $this->_payment_method_type = $options_array['payment_method_type']; |
|
52 | - } |
|
53 | - $options_array = $this->_options_array; |
|
54 | - if (isset($options_array['extra_meta_inputs'])) { |
|
55 | - $this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $options_array['extra_meta_inputs']); |
|
56 | - } |
|
57 | - if ($this->_extra_meta_inputs) { |
|
58 | - $this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs); |
|
59 | - } |
|
60 | - $this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input( |
|
61 | - array('html_label_text' => __('Button URL', 'event_espresso')) |
|
62 | - ); |
|
63 | - $this->_subsections['PMD_scope'] = new EE_Checkbox_Multi_Input( |
|
64 | - EEM_Payment_Method::instance()->scopes(), |
|
65 | - array( |
|
66 | - 'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename() |
|
67 | - . EEH_Template::get_help_tab_link('payment_methods_overview'), |
|
68 | - ) |
|
69 | - ); |
|
70 | - //setup the currency options |
|
71 | - $this->_subsections['Currency'] = new EE_Select_Multi_Model_Input( |
|
72 | - EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type), |
|
73 | - array( |
|
74 | - 'html_label_text' => __('Currencies Supported', 'event_espresso'), |
|
75 | - 'required' => true, |
|
76 | - ) |
|
77 | - ); |
|
78 | - $this->_subsections['PMD_order'] = new EE_Text_Input(array( |
|
79 | - 'html_label_text' => __('Order', 'event_espresso'), |
|
80 | - 'html_help_text' => __('Lowest numbers will be shown first', 'event_espresso'), |
|
81 | - 'normalization_strategy' => new EE_Int_Normalization(), |
|
82 | - 'validation_strategies' => array( |
|
83 | - new EE_Int_Validation_Strategy(), |
|
84 | - ), |
|
85 | - 'default' => 0, |
|
86 | - )); |
|
87 | - $this->_layout_strategy = new EE_Admin_Two_Column_Layout(); |
|
88 | - parent::__construct($options_array); |
|
89 | - $debug_mode = isset($this->_subsections['PMD_debug_mode']) ? $this->_subsections['PMD_debug_mode'] : null; |
|
90 | - if ($debug_mode instanceof EE_Form_Input_Base) { |
|
91 | - $debug_mode->set_html_help_text(__('This payment method has a Sandbox Server (also known as Testing Server, Development Server, Quality Assurance Server, etc). While in debug mode and using this sandbox server, real payments will not be processed.', |
|
92 | - 'event_espresso')); |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * Finishes construction given the parent form section and this form section's name |
|
100 | - * |
|
101 | - * @param EE_Form_Section_Proper $parent_form_section |
|
102 | - * @param string $name |
|
103 | - * @throws EE_Error |
|
104 | - */ |
|
105 | - public function _construct_finalize($parent_form_section, $name) |
|
106 | - { |
|
107 | - if (! $this->_payment_method_type instanceof EE_PMT_Base) { |
|
108 | - throw new EE_Error(sprintf(__('Payment Method forms must have set their payment method type BEFORE calling _construct_finalize', |
|
109 | - 'event_espresso'))); |
|
110 | - } |
|
111 | - //set the name of this form based on the payment method type |
|
112 | - if (! $this->_name && ! $name) { |
|
113 | - $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name())))) |
|
114 | - . "_Settings_Form"; |
|
115 | - } |
|
116 | - parent::_construct_finalize($parent_form_section, $name); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @param $payment_method_type |
|
123 | - * @throws EE_Error |
|
124 | - */ |
|
125 | - public function set_payment_method_type($payment_method_type) |
|
126 | - { |
|
127 | - if (! $payment_method_type instanceof EE_PMT_Base) { |
|
128 | - throw new EE_Error(sprintf(__("Payment Method forms MUST set a payment method type by using _set_payment_method_type", |
|
129 | - "event_espresso"))); |
|
130 | - } |
|
131 | - $this->_payment_method_type = $payment_method_type; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * extends the model form section's save method to also save the extra meta field values |
|
138 | - * |
|
139 | - * @return int ID of the payment method inserted, or true on update |
|
140 | - */ |
|
141 | - public function save() |
|
142 | - { |
|
143 | - $parent_save_val = parent::save(); |
|
144 | - if ($this->_model_object && $this->_model_object->ID()) { |
|
145 | - foreach ($this->_extra_meta_inputs as $input_name => $input) { |
|
146 | - $this->_model_object->update_extra_meta($input_name, $input->normalized_value()); |
|
147 | - } |
|
148 | - } |
|
149 | - return $parent_save_val; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * Overrides parent's populate_model_obj to also populate the extra meta fields |
|
156 | - * |
|
157 | - * @param EE_Base_Class $model_obj |
|
158 | - */ |
|
159 | - public function populate_model_obj($model_obj) |
|
160 | - { |
|
161 | - $model_obj = $this->_model->ensure_is_obj($model_obj); |
|
162 | - parent::populate_model_obj($model_obj); |
|
163 | - $extra_meta = $model_obj->all_extra_meta_array(); |
|
164 | - foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) { |
|
165 | - if (isset($extra_meta[$input_name])) { |
|
166 | - $extra_meta_input->set_default($extra_meta[$input_name]); |
|
167 | - } |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * gets the default name of this form section if none is specified |
|
175 | - * |
|
176 | - * @return string |
|
177 | - */ |
|
178 | - protected function _set_default_name_if_empty() |
|
179 | - { |
|
180 | - if (! $this->_name) { |
|
181 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
182 | - $this->_name = $default_name; |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Gets all the extra meta inputs in this form |
|
190 | - * |
|
191 | - * @return EE_Form_Input_Base[] |
|
192 | - */ |
|
193 | - public function extra_meta_inputs() |
|
194 | - { |
|
195 | - return $this->_extra_meta_inputs; |
|
196 | - } |
|
12 | + /** |
|
13 | + * All the subsection inputs that correspond ot extra meta rows |
|
14 | + * for this payment method |
|
15 | + * |
|
16 | + * @var EE_Form_Input_Base[] |
|
17 | + */ |
|
18 | + protected $_extra_meta_inputs = array(); |
|
19 | + |
|
20 | + /** |
|
21 | + * Because payment method form might DELAY part of construction, we want to remember |
|
22 | + * what options were passed in |
|
23 | + * |
|
24 | + * @var array |
|
25 | + */ |
|
26 | + protected $_options_array = array(); |
|
27 | + |
|
28 | + /** |
|
29 | + * The payment method type for this form |
|
30 | + * |
|
31 | + * @var EE_PMT_Base |
|
32 | + */ |
|
33 | + protected $_payment_method_type; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @param array $options_array { |
|
39 | + * @type string $extra_meta_inputs should be EE_Form_Section_Validatable[] which |
|
40 | + * will be _subsections and will be saved as extra meta on the payment |
|
41 | + * method object; |
|
42 | + * @type EE_PMT_Base $payment_method_type the payment method type this form is for |
|
43 | + * @see EE_Model_Form_Section::__construct() for more |
|
44 | + * } |
|
45 | + */ |
|
46 | + public function __construct($options_array = array()) |
|
47 | + { |
|
48 | + $this->_model = EEM_Payment_Method::instance(); |
|
49 | + $this->_options_array = $options_array; |
|
50 | + if (isset($options_array['payment_method_type'])) { |
|
51 | + $this->_payment_method_type = $options_array['payment_method_type']; |
|
52 | + } |
|
53 | + $options_array = $this->_options_array; |
|
54 | + if (isset($options_array['extra_meta_inputs'])) { |
|
55 | + $this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $options_array['extra_meta_inputs']); |
|
56 | + } |
|
57 | + if ($this->_extra_meta_inputs) { |
|
58 | + $this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs); |
|
59 | + } |
|
60 | + $this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input( |
|
61 | + array('html_label_text' => __('Button URL', 'event_espresso')) |
|
62 | + ); |
|
63 | + $this->_subsections['PMD_scope'] = new EE_Checkbox_Multi_Input( |
|
64 | + EEM_Payment_Method::instance()->scopes(), |
|
65 | + array( |
|
66 | + 'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename() |
|
67 | + . EEH_Template::get_help_tab_link('payment_methods_overview'), |
|
68 | + ) |
|
69 | + ); |
|
70 | + //setup the currency options |
|
71 | + $this->_subsections['Currency'] = new EE_Select_Multi_Model_Input( |
|
72 | + EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type), |
|
73 | + array( |
|
74 | + 'html_label_text' => __('Currencies Supported', 'event_espresso'), |
|
75 | + 'required' => true, |
|
76 | + ) |
|
77 | + ); |
|
78 | + $this->_subsections['PMD_order'] = new EE_Text_Input(array( |
|
79 | + 'html_label_text' => __('Order', 'event_espresso'), |
|
80 | + 'html_help_text' => __('Lowest numbers will be shown first', 'event_espresso'), |
|
81 | + 'normalization_strategy' => new EE_Int_Normalization(), |
|
82 | + 'validation_strategies' => array( |
|
83 | + new EE_Int_Validation_Strategy(), |
|
84 | + ), |
|
85 | + 'default' => 0, |
|
86 | + )); |
|
87 | + $this->_layout_strategy = new EE_Admin_Two_Column_Layout(); |
|
88 | + parent::__construct($options_array); |
|
89 | + $debug_mode = isset($this->_subsections['PMD_debug_mode']) ? $this->_subsections['PMD_debug_mode'] : null; |
|
90 | + if ($debug_mode instanceof EE_Form_Input_Base) { |
|
91 | + $debug_mode->set_html_help_text(__('This payment method has a Sandbox Server (also known as Testing Server, Development Server, Quality Assurance Server, etc). While in debug mode and using this sandbox server, real payments will not be processed.', |
|
92 | + 'event_espresso')); |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * Finishes construction given the parent form section and this form section's name |
|
100 | + * |
|
101 | + * @param EE_Form_Section_Proper $parent_form_section |
|
102 | + * @param string $name |
|
103 | + * @throws EE_Error |
|
104 | + */ |
|
105 | + public function _construct_finalize($parent_form_section, $name) |
|
106 | + { |
|
107 | + if (! $this->_payment_method_type instanceof EE_PMT_Base) { |
|
108 | + throw new EE_Error(sprintf(__('Payment Method forms must have set their payment method type BEFORE calling _construct_finalize', |
|
109 | + 'event_espresso'))); |
|
110 | + } |
|
111 | + //set the name of this form based on the payment method type |
|
112 | + if (! $this->_name && ! $name) { |
|
113 | + $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name())))) |
|
114 | + . "_Settings_Form"; |
|
115 | + } |
|
116 | + parent::_construct_finalize($parent_form_section, $name); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @param $payment_method_type |
|
123 | + * @throws EE_Error |
|
124 | + */ |
|
125 | + public function set_payment_method_type($payment_method_type) |
|
126 | + { |
|
127 | + if (! $payment_method_type instanceof EE_PMT_Base) { |
|
128 | + throw new EE_Error(sprintf(__("Payment Method forms MUST set a payment method type by using _set_payment_method_type", |
|
129 | + "event_espresso"))); |
|
130 | + } |
|
131 | + $this->_payment_method_type = $payment_method_type; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * extends the model form section's save method to also save the extra meta field values |
|
138 | + * |
|
139 | + * @return int ID of the payment method inserted, or true on update |
|
140 | + */ |
|
141 | + public function save() |
|
142 | + { |
|
143 | + $parent_save_val = parent::save(); |
|
144 | + if ($this->_model_object && $this->_model_object->ID()) { |
|
145 | + foreach ($this->_extra_meta_inputs as $input_name => $input) { |
|
146 | + $this->_model_object->update_extra_meta($input_name, $input->normalized_value()); |
|
147 | + } |
|
148 | + } |
|
149 | + return $parent_save_val; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * Overrides parent's populate_model_obj to also populate the extra meta fields |
|
156 | + * |
|
157 | + * @param EE_Base_Class $model_obj |
|
158 | + */ |
|
159 | + public function populate_model_obj($model_obj) |
|
160 | + { |
|
161 | + $model_obj = $this->_model->ensure_is_obj($model_obj); |
|
162 | + parent::populate_model_obj($model_obj); |
|
163 | + $extra_meta = $model_obj->all_extra_meta_array(); |
|
164 | + foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) { |
|
165 | + if (isset($extra_meta[$input_name])) { |
|
166 | + $extra_meta_input->set_default($extra_meta[$input_name]); |
|
167 | + } |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * gets the default name of this form section if none is specified |
|
175 | + * |
|
176 | + * @return string |
|
177 | + */ |
|
178 | + protected function _set_default_name_if_empty() |
|
179 | + { |
|
180 | + if (! $this->_name) { |
|
181 | + $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
182 | + $this->_name = $default_name; |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Gets all the extra meta inputs in this form |
|
190 | + * |
|
191 | + * @return EE_Form_Input_Base[] |
|
192 | + */ |
|
193 | + public function extra_meta_inputs() |
|
194 | + { |
|
195 | + return $this->_extra_meta_inputs; |
|
196 | + } |
|
197 | 197 | } |
@@ -104,12 +104,12 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function _construct_finalize($parent_form_section, $name) |
106 | 106 | { |
107 | - if (! $this->_payment_method_type instanceof EE_PMT_Base) { |
|
107 | + if ( ! $this->_payment_method_type instanceof EE_PMT_Base) { |
|
108 | 108 | throw new EE_Error(sprintf(__('Payment Method forms must have set their payment method type BEFORE calling _construct_finalize', |
109 | 109 | 'event_espresso'))); |
110 | 110 | } |
111 | 111 | //set the name of this form based on the payment method type |
112 | - if (! $this->_name && ! $name) { |
|
112 | + if ( ! $this->_name && ! $name) { |
|
113 | 113 | $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name())))) |
114 | 114 | . "_Settings_Form"; |
115 | 115 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function set_payment_method_type($payment_method_type) |
126 | 126 | { |
127 | - if (! $payment_method_type instanceof EE_PMT_Base) { |
|
127 | + if ( ! $payment_method_type instanceof EE_PMT_Base) { |
|
128 | 128 | throw new EE_Error(sprintf(__("Payment Method forms MUST set a payment method type by using _set_payment_method_type", |
129 | 129 | "event_espresso"))); |
130 | 130 | } |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | */ |
178 | 178 | protected function _set_default_name_if_empty() |
179 | 179 | { |
180 | - if (! $this->_name) { |
|
181 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
180 | + if ( ! $this->_name) { |
|
181 | + $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form"; |
|
182 | 182 | $this->_name = $default_name; |
183 | 183 | } |
184 | 184 | } |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | } |
5 | 5 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -35,150 +35,150 @@ discard block |
||
35 | 35 | abstract class EE_Form_Section_Validatable extends EE_Form_Section_Base |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * Array of validation errors in this section. Does not contain validation errors in subsections, however. |
|
40 | - * Those are stored individually on each subsection. |
|
41 | - * |
|
42 | - * @var EE_Validation_Error[] |
|
43 | - */ |
|
44 | - protected $_validation_errors = array(); |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Errors on this form section. Note: EE_Form_Section_Proper |
|
50 | - * has another function for getting all errors in this form section and subsections |
|
51 | - * called get_validation_errors_accumulated |
|
52 | - * |
|
53 | - * @return EE_Validation_Error[] |
|
54 | - */ |
|
55 | - public function get_validation_errors() |
|
56 | - { |
|
57 | - return $this->_validation_errors; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * returns a comma-separated list of all the validation errors in it. |
|
64 | - * If we want this to be customizable, we may decide to create a strategy for displaying it |
|
65 | - * |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function get_validation_error_string() |
|
69 | - { |
|
70 | - $validation_error_messages = array(); |
|
71 | - if ($this->get_validation_errors()) { |
|
72 | - foreach ($this->get_validation_errors() as $validation_error) { |
|
73 | - if ($validation_error instanceof EE_Validation_Error) { |
|
74 | - $validation_error_messages[] = $validation_error->getMessage(); |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
78 | - return implode(", ", $validation_error_messages); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * Performs validation on this form section (and subsections). Should be called after _normalize() |
|
85 | - * |
|
86 | - * @return boolean of whether or not the form section is valid |
|
87 | - */ |
|
88 | - abstract protected function _validate(); |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Checks if this field has any validation errors |
|
94 | - * |
|
95 | - * @return boolean |
|
96 | - */ |
|
97 | - public function is_valid() |
|
98 | - { |
|
99 | - if (count($this->_validation_errors)) { |
|
100 | - return false; |
|
101 | - } else { |
|
102 | - return true; |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Sanitizes input for this form section |
|
110 | - * |
|
111 | - * @param array $req_data is the full request data like $_POST |
|
112 | - * @return boolean of whether a normalization error occurred |
|
113 | - */ |
|
114 | - abstract protected function _normalize($req_data); |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * Creates a validation error from the arguments provided, and adds it to the form section's list. |
|
120 | - * If such an EE_Validation_Error object is passed in as the first arg, simply sets this as its form section, and |
|
121 | - * adds it to the list of validation errors of errors |
|
122 | - * |
|
123 | - * @param mixed $message_or_object internationalized string describing the validation error; or it could be a |
|
124 | - * proper EE_Validation_Error object |
|
125 | - * @param string $error_code a short key which can be used to uniquely identify the error |
|
126 | - * @param Exception $previous_exception if there was an exception that caused the error, that exception |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - public function add_validation_error($message_or_object, $error_code = null, $previous_exception = null) |
|
130 | - { |
|
131 | - if ($message_or_object instanceof EE_Validation_Error) { |
|
132 | - $validation_error = $message_or_object; |
|
133 | - $validation_error->set_form_section($this); |
|
134 | - } else { |
|
135 | - $validation_error = new EE_Validation_Error($message_or_object, $error_code, $this, $previous_exception); |
|
136 | - } |
|
137 | - $this->_validation_errors[] = $validation_error; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * When generating the JS for the jquery validation rules like<br> |
|
144 | - * <code>$( "#myform" ).validate({ |
|
145 | - * rules: { |
|
146 | - * password: "required", |
|
147 | - * password_again: { |
|
148 | - * equalTo: "#password" |
|
149 | - * } |
|
150 | - * } |
|
151 | - * });</code> |
|
152 | - * gets the sections like |
|
153 | - * <br><code>password: "required", |
|
154 | - * password_again: { |
|
155 | - * equalTo: "#password" |
|
156 | - * }</code> |
|
157 | - * except we leave it as a PHP object, and leave wp_localize_script to |
|
158 | - * turn it into a JSON object which can be used by the js |
|
159 | - * |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - abstract public function get_jquery_validation_rules(); |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Checks if this form section's data is present in the req data specified |
|
168 | - * |
|
169 | - * @param array $req_data usually $_POST, if null that's what's used |
|
170 | - * @return boolean |
|
171 | - */ |
|
172 | - abstract public function form_data_present_in($req_data = null); |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * Removes teh sensitive data from this form section (usually done after |
|
178 | - * utilizing the data business function, but before saving it somewhere. Eg, |
|
179 | - * may remove a password from the form after verifying it was correct) |
|
180 | - * |
|
181 | - * @return void |
|
182 | - */ |
|
183 | - abstract public function clean_sensitive_data(); |
|
38 | + /** |
|
39 | + * Array of validation errors in this section. Does not contain validation errors in subsections, however. |
|
40 | + * Those are stored individually on each subsection. |
|
41 | + * |
|
42 | + * @var EE_Validation_Error[] |
|
43 | + */ |
|
44 | + protected $_validation_errors = array(); |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Errors on this form section. Note: EE_Form_Section_Proper |
|
50 | + * has another function for getting all errors in this form section and subsections |
|
51 | + * called get_validation_errors_accumulated |
|
52 | + * |
|
53 | + * @return EE_Validation_Error[] |
|
54 | + */ |
|
55 | + public function get_validation_errors() |
|
56 | + { |
|
57 | + return $this->_validation_errors; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * returns a comma-separated list of all the validation errors in it. |
|
64 | + * If we want this to be customizable, we may decide to create a strategy for displaying it |
|
65 | + * |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function get_validation_error_string() |
|
69 | + { |
|
70 | + $validation_error_messages = array(); |
|
71 | + if ($this->get_validation_errors()) { |
|
72 | + foreach ($this->get_validation_errors() as $validation_error) { |
|
73 | + if ($validation_error instanceof EE_Validation_Error) { |
|
74 | + $validation_error_messages[] = $validation_error->getMessage(); |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | + return implode(", ", $validation_error_messages); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * Performs validation on this form section (and subsections). Should be called after _normalize() |
|
85 | + * |
|
86 | + * @return boolean of whether or not the form section is valid |
|
87 | + */ |
|
88 | + abstract protected function _validate(); |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Checks if this field has any validation errors |
|
94 | + * |
|
95 | + * @return boolean |
|
96 | + */ |
|
97 | + public function is_valid() |
|
98 | + { |
|
99 | + if (count($this->_validation_errors)) { |
|
100 | + return false; |
|
101 | + } else { |
|
102 | + return true; |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Sanitizes input for this form section |
|
110 | + * |
|
111 | + * @param array $req_data is the full request data like $_POST |
|
112 | + * @return boolean of whether a normalization error occurred |
|
113 | + */ |
|
114 | + abstract protected function _normalize($req_data); |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * Creates a validation error from the arguments provided, and adds it to the form section's list. |
|
120 | + * If such an EE_Validation_Error object is passed in as the first arg, simply sets this as its form section, and |
|
121 | + * adds it to the list of validation errors of errors |
|
122 | + * |
|
123 | + * @param mixed $message_or_object internationalized string describing the validation error; or it could be a |
|
124 | + * proper EE_Validation_Error object |
|
125 | + * @param string $error_code a short key which can be used to uniquely identify the error |
|
126 | + * @param Exception $previous_exception if there was an exception that caused the error, that exception |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + public function add_validation_error($message_or_object, $error_code = null, $previous_exception = null) |
|
130 | + { |
|
131 | + if ($message_or_object instanceof EE_Validation_Error) { |
|
132 | + $validation_error = $message_or_object; |
|
133 | + $validation_error->set_form_section($this); |
|
134 | + } else { |
|
135 | + $validation_error = new EE_Validation_Error($message_or_object, $error_code, $this, $previous_exception); |
|
136 | + } |
|
137 | + $this->_validation_errors[] = $validation_error; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * When generating the JS for the jquery validation rules like<br> |
|
144 | + * <code>$( "#myform" ).validate({ |
|
145 | + * rules: { |
|
146 | + * password: "required", |
|
147 | + * password_again: { |
|
148 | + * equalTo: "#password" |
|
149 | + * } |
|
150 | + * } |
|
151 | + * });</code> |
|
152 | + * gets the sections like |
|
153 | + * <br><code>password: "required", |
|
154 | + * password_again: { |
|
155 | + * equalTo: "#password" |
|
156 | + * }</code> |
|
157 | + * except we leave it as a PHP object, and leave wp_localize_script to |
|
158 | + * turn it into a JSON object which can be used by the js |
|
159 | + * |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + abstract public function get_jquery_validation_rules(); |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Checks if this form section's data is present in the req data specified |
|
168 | + * |
|
169 | + * @param array $req_data usually $_POST, if null that's what's used |
|
170 | + * @return boolean |
|
171 | + */ |
|
172 | + abstract public function form_data_present_in($req_data = null); |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * Removes teh sensitive data from this form section (usually done after |
|
178 | + * utilizing the data business function, but before saving it somewhere. Eg, |
|
179 | + * may remove a password from the form after verifying it was correct) |
|
180 | + * |
|
181 | + * @return void |
|
182 | + */ |
|
183 | + abstract public function clean_sensitive_data(); |
|
184 | 184 | } |
185 | 185 | \ No newline at end of file |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\libraries\iframe_display\Iframe; |
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,57 +21,57 @@ discard block |
||
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * EventsArchiveIframe constructor. |
|
26 | - * |
|
27 | - * @param \EED_Events_Archive $EED_Events_Archive |
|
28 | - * @throws \DomainException |
|
29 | - */ |
|
30 | - public function __construct( $EED_Events_Archive ) |
|
31 | - { |
|
32 | - \EE_Registry::instance()->REQ->set_espresso_page( true ); |
|
33 | - add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true'); |
|
34 | - $EED_Events_Archive->event_list(); |
|
35 | - /** @var \EventEspresso\core\domain\entities\shortcodes\EspressoEvents $event_list */ |
|
36 | - $event_list = \EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents'); |
|
37 | - parent::__construct( |
|
38 | - esc_html__( 'Event List', 'event_espresso' ), |
|
39 | - $event_list->processShortcode() |
|
40 | - ); |
|
41 | - $this->addStylesheets( |
|
42 | - apply_filters( |
|
43 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
44 | - array( |
|
45 | - 'espresso_default' => is_readable( EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css' ) |
|
46 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION |
|
47 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
48 | - ), |
|
49 | - $this |
|
50 | - ) |
|
51 | - ); |
|
52 | - $this->addScripts( |
|
53 | - apply_filters( |
|
54 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
55 | - array( |
|
56 | - 'gmap_api' => sprintf( |
|
57 | - 'https://maps.googleapis.com/maps/api/js?key=%s', |
|
58 | - apply_filters( |
|
59 | - 'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
|
60 | - \EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
61 | - ) |
|
62 | - ), |
|
63 | - 'ee_gmap' => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0', |
|
64 | - ), |
|
65 | - $this |
|
66 | - ) |
|
67 | - ); |
|
68 | - $this->addLocalizedVars( |
|
69 | - array( |
|
70 | - 'ee_gmap' => \EEH_Maps::$gmap_vars, |
|
71 | - ), |
|
72 | - 'ee_gmap_vars' |
|
73 | - ); |
|
74 | - } |
|
24 | + /** |
|
25 | + * EventsArchiveIframe constructor. |
|
26 | + * |
|
27 | + * @param \EED_Events_Archive $EED_Events_Archive |
|
28 | + * @throws \DomainException |
|
29 | + */ |
|
30 | + public function __construct( $EED_Events_Archive ) |
|
31 | + { |
|
32 | + \EE_Registry::instance()->REQ->set_espresso_page( true ); |
|
33 | + add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true'); |
|
34 | + $EED_Events_Archive->event_list(); |
|
35 | + /** @var \EventEspresso\core\domain\entities\shortcodes\EspressoEvents $event_list */ |
|
36 | + $event_list = \EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents'); |
|
37 | + parent::__construct( |
|
38 | + esc_html__( 'Event List', 'event_espresso' ), |
|
39 | + $event_list->processShortcode() |
|
40 | + ); |
|
41 | + $this->addStylesheets( |
|
42 | + apply_filters( |
|
43 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
44 | + array( |
|
45 | + 'espresso_default' => is_readable( EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css' ) |
|
46 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION |
|
47 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
48 | + ), |
|
49 | + $this |
|
50 | + ) |
|
51 | + ); |
|
52 | + $this->addScripts( |
|
53 | + apply_filters( |
|
54 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
55 | + array( |
|
56 | + 'gmap_api' => sprintf( |
|
57 | + 'https://maps.googleapis.com/maps/api/js?key=%s', |
|
58 | + apply_filters( |
|
59 | + 'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
|
60 | + \EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
61 | + ) |
|
62 | + ), |
|
63 | + 'ee_gmap' => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0', |
|
64 | + ), |
|
65 | + $this |
|
66 | + ) |
|
67 | + ); |
|
68 | + $this->addLocalizedVars( |
|
69 | + array( |
|
70 | + 'ee_gmap' => \EEH_Maps::$gmap_vars, |
|
71 | + ), |
|
72 | + 'ee_gmap_vars' |
|
73 | + ); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | 77 |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | |
4 | 4 | use EventEspresso\core\libraries\iframe_display\Iframe; |
5 | 5 | |
6 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
7 | - exit( 'No direct script access allowed' ); |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -27,24 +27,24 @@ discard block |
||
27 | 27 | * @param \EED_Events_Archive $EED_Events_Archive |
28 | 28 | * @throws \DomainException |
29 | 29 | */ |
30 | - public function __construct( $EED_Events_Archive ) |
|
30 | + public function __construct($EED_Events_Archive) |
|
31 | 31 | { |
32 | - \EE_Registry::instance()->REQ->set_espresso_page( true ); |
|
32 | + \EE_Registry::instance()->REQ->set_espresso_page(true); |
|
33 | 33 | add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true'); |
34 | 34 | $EED_Events_Archive->event_list(); |
35 | 35 | /** @var \EventEspresso\core\domain\entities\shortcodes\EspressoEvents $event_list */ |
36 | 36 | $event_list = \EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents'); |
37 | 37 | parent::__construct( |
38 | - esc_html__( 'Event List', 'event_espresso' ), |
|
38 | + esc_html__('Event List', 'event_espresso'), |
|
39 | 39 | $event_list->processShortcode() |
40 | 40 | ); |
41 | 41 | $this->addStylesheets( |
42 | 42 | apply_filters( |
43 | 43 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
44 | 44 | array( |
45 | - 'espresso_default' => is_readable( EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css' ) |
|
46 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION |
|
47 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
45 | + 'espresso_default' => is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
46 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION |
|
47 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION, |
|
48 | 48 | ), |
49 | 49 | $this |
50 | 50 | ) |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | \EE_Registry::instance()->CFG->map_settings->google_map_api_key |
61 | 61 | ) |
62 | 62 | ), |
63 | - 'ee_gmap' => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0', |
|
63 | + 'ee_gmap' => EE_HELPERS_ASSETS.'ee_gmap.js?ver=1.0', |
|
64 | 64 | ), |
65 | 65 | $this |
66 | 66 | ) |
@@ -18,43 +18,43 @@ |
||
18 | 18 | interface CacheManagerInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * returns a string that will be prepended to all cache identifiers |
|
23 | - * |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function cachePrefix(); |
|
27 | - |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
|
32 | - * May also be helpful to include an additional specific identifier, |
|
33 | - * such as a post ID as part of the $id_prefix so that individual caches |
|
34 | - * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
35 | - * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
36 | - * @param string $cache_id [required] Additional identifying details that make this cache unique. |
|
37 | - * It is advisable to use some of the actual data |
|
38 | - * that is used to generate the content being cached, |
|
39 | - * in order to guarantee that the cache id is unique for that content. |
|
40 | - * The cache id will be md5'd before usage to make it more db friendly, |
|
41 | - * and the entire cache id string will be truncated to 190 characters. |
|
42 | - * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
|
43 | - * necessary, |
|
44 | - * we wrap our content creation in a Closure so that it is not executed until needed. |
|
45 | - * @param int $expiration |
|
46 | - * @return Closure|mixed |
|
47 | - */ |
|
48 | - public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS); |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
54 | - * or a specific ID targeting a single cache item |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - public function clear($cache_id); |
|
21 | + /** |
|
22 | + * returns a string that will be prepended to all cache identifiers |
|
23 | + * |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function cachePrefix(); |
|
27 | + |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
|
32 | + * May also be helpful to include an additional specific identifier, |
|
33 | + * such as a post ID as part of the $id_prefix so that individual caches |
|
34 | + * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
35 | + * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
36 | + * @param string $cache_id [required] Additional identifying details that make this cache unique. |
|
37 | + * It is advisable to use some of the actual data |
|
38 | + * that is used to generate the content being cached, |
|
39 | + * in order to guarantee that the cache id is unique for that content. |
|
40 | + * The cache id will be md5'd before usage to make it more db friendly, |
|
41 | + * and the entire cache id string will be truncated to 190 characters. |
|
42 | + * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
|
43 | + * necessary, |
|
44 | + * we wrap our content creation in a Closure so that it is not executed until needed. |
|
45 | + * @param int $expiration |
|
46 | + * @return Closure|mixed |
|
47 | + */ |
|
48 | + public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS); |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
54 | + * or a specific ID targeting a single cache item |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + public function clear($cache_id); |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | // End of file CacheManagerInterface.php |
@@ -16,115 +16,115 @@ |
||
16 | 16 | abstract class TicketSelector |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var \EE_Event $event |
|
21 | - */ |
|
22 | - protected $event; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var \EE_Ticket[] $tickets |
|
26 | - */ |
|
27 | - protected $tickets; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var int max_attendees |
|
31 | - */ |
|
32 | - protected $max_attendees; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var array $template_args |
|
36 | - */ |
|
37 | - protected $template_args; |
|
38 | - |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * TicketSelectorSimple constructor. |
|
43 | - * |
|
44 | - * @param \EE_Event $event |
|
45 | - * @param \EE_Ticket[] $tickets |
|
46 | - * @param int $max_attendees |
|
47 | - * @param array $template_args |
|
48 | - * @throws \EE_Error |
|
49 | - */ |
|
50 | - public function __construct(\EE_Event $event, array $tickets, $max_attendees, array $template_args) |
|
51 | - { |
|
52 | - $this->event = $event; |
|
53 | - $this->tickets = $tickets; |
|
54 | - $this->max_attendees = $max_attendees; |
|
55 | - $this->template_args = $template_args; |
|
56 | - $this->template_args['hidden_inputs'] = $this->getHiddenInputs(); |
|
57 | - $this->addTemplateArgs(); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * sets any and all template args that are required for this Ticket Selector |
|
64 | - * |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - abstract protected function addTemplateArgs(); |
|
68 | - |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * loadTicketSelectorTemplate |
|
73 | - * |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - protected function loadTicketSelectorTemplate() |
|
77 | - { |
|
78 | - try { |
|
79 | - return \EEH_Template::locate_template( |
|
80 | - apply_filters( |
|
81 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', |
|
82 | - $this->template_args['template_path'], |
|
83 | - $this->event |
|
84 | - ), |
|
85 | - $this->template_args |
|
86 | - ); |
|
87 | - } catch (\Exception $e) { |
|
88 | - \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
89 | - } |
|
90 | - return ''; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * The __toString method allows a class to decide how it will react when it is converted to a string. |
|
97 | - * |
|
98 | - * @return string |
|
99 | - * @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring |
|
100 | - */ |
|
101 | - public function __toString() |
|
102 | - { |
|
103 | - return $this->loadTicketSelectorTemplate(); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * getHiddenInputs |
|
111 | - * |
|
112 | - * @return string |
|
113 | - * @throws \EE_Error |
|
114 | - */ |
|
115 | - public function getHiddenInputs() |
|
116 | - { |
|
117 | - // $rows = count($this->tickets); |
|
118 | - $html = '<input type="hidden" name="noheader" value="true"/>'; |
|
119 | - $html .= '<input type="hidden" name="tkt-slctr-return-url-' . $this->event->ID() . '"'; |
|
120 | - $html .= ' value="' . \EEH_URL::current_url() . $this->template_args['anchor_id'] . '"/>'; |
|
121 | - $html .= '<input type="hidden" name="tkt-slctr-rows-' . $this->event->ID(); |
|
122 | - $html .= '" value="' . count($this->tickets) . '"/>'; |
|
123 | - $html .= '<input type="hidden" name="tkt-slctr-max-atndz-' . $this->event->ID(); |
|
124 | - $html .= '" value="' . $this->template_args['max_atndz'] . '"/>'; |
|
125 | - $html .= '<input type="hidden" name="tkt-slctr-event-id" value="' . $this->event->ID() . '"/>'; |
|
126 | - return $html; |
|
127 | - } |
|
19 | + /** |
|
20 | + * @var \EE_Event $event |
|
21 | + */ |
|
22 | + protected $event; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var \EE_Ticket[] $tickets |
|
26 | + */ |
|
27 | + protected $tickets; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var int max_attendees |
|
31 | + */ |
|
32 | + protected $max_attendees; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var array $template_args |
|
36 | + */ |
|
37 | + protected $template_args; |
|
38 | + |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * TicketSelectorSimple constructor. |
|
43 | + * |
|
44 | + * @param \EE_Event $event |
|
45 | + * @param \EE_Ticket[] $tickets |
|
46 | + * @param int $max_attendees |
|
47 | + * @param array $template_args |
|
48 | + * @throws \EE_Error |
|
49 | + */ |
|
50 | + public function __construct(\EE_Event $event, array $tickets, $max_attendees, array $template_args) |
|
51 | + { |
|
52 | + $this->event = $event; |
|
53 | + $this->tickets = $tickets; |
|
54 | + $this->max_attendees = $max_attendees; |
|
55 | + $this->template_args = $template_args; |
|
56 | + $this->template_args['hidden_inputs'] = $this->getHiddenInputs(); |
|
57 | + $this->addTemplateArgs(); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * sets any and all template args that are required for this Ticket Selector |
|
64 | + * |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + abstract protected function addTemplateArgs(); |
|
68 | + |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * loadTicketSelectorTemplate |
|
73 | + * |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + protected function loadTicketSelectorTemplate() |
|
77 | + { |
|
78 | + try { |
|
79 | + return \EEH_Template::locate_template( |
|
80 | + apply_filters( |
|
81 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', |
|
82 | + $this->template_args['template_path'], |
|
83 | + $this->event |
|
84 | + ), |
|
85 | + $this->template_args |
|
86 | + ); |
|
87 | + } catch (\Exception $e) { |
|
88 | + \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
89 | + } |
|
90 | + return ''; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * The __toString method allows a class to decide how it will react when it is converted to a string. |
|
97 | + * |
|
98 | + * @return string |
|
99 | + * @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring |
|
100 | + */ |
|
101 | + public function __toString() |
|
102 | + { |
|
103 | + return $this->loadTicketSelectorTemplate(); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * getHiddenInputs |
|
111 | + * |
|
112 | + * @return string |
|
113 | + * @throws \EE_Error |
|
114 | + */ |
|
115 | + public function getHiddenInputs() |
|
116 | + { |
|
117 | + // $rows = count($this->tickets); |
|
118 | + $html = '<input type="hidden" name="noheader" value="true"/>'; |
|
119 | + $html .= '<input type="hidden" name="tkt-slctr-return-url-' . $this->event->ID() . '"'; |
|
120 | + $html .= ' value="' . \EEH_URL::current_url() . $this->template_args['anchor_id'] . '"/>'; |
|
121 | + $html .= '<input type="hidden" name="tkt-slctr-rows-' . $this->event->ID(); |
|
122 | + $html .= '" value="' . count($this->tickets) . '"/>'; |
|
123 | + $html .= '<input type="hidden" name="tkt-slctr-max-atndz-' . $this->event->ID(); |
|
124 | + $html .= '" value="' . $this->template_args['max_atndz'] . '"/>'; |
|
125 | + $html .= '<input type="hidden" name="tkt-slctr-event-id" value="' . $this->event->ID() . '"/>'; |
|
126 | + return $html; |
|
127 | + } |
|
128 | 128 | |
129 | 129 | } |
130 | 130 | // End of file TicketSelector.php |
@@ -116,13 +116,13 @@ |
||
116 | 116 | { |
117 | 117 | // $rows = count($this->tickets); |
118 | 118 | $html = '<input type="hidden" name="noheader" value="true"/>'; |
119 | - $html .= '<input type="hidden" name="tkt-slctr-return-url-' . $this->event->ID() . '"'; |
|
120 | - $html .= ' value="' . \EEH_URL::current_url() . $this->template_args['anchor_id'] . '"/>'; |
|
121 | - $html .= '<input type="hidden" name="tkt-slctr-rows-' . $this->event->ID(); |
|
122 | - $html .= '" value="' . count($this->tickets) . '"/>'; |
|
123 | - $html .= '<input type="hidden" name="tkt-slctr-max-atndz-' . $this->event->ID(); |
|
124 | - $html .= '" value="' . $this->template_args['max_atndz'] . '"/>'; |
|
125 | - $html .= '<input type="hidden" name="tkt-slctr-event-id" value="' . $this->event->ID() . '"/>'; |
|
119 | + $html .= '<input type="hidden" name="tkt-slctr-return-url-'.$this->event->ID().'"'; |
|
120 | + $html .= ' value="'.\EEH_URL::current_url().$this->template_args['anchor_id'].'"/>'; |
|
121 | + $html .= '<input type="hidden" name="tkt-slctr-rows-'.$this->event->ID(); |
|
122 | + $html .= '" value="'.count($this->tickets).'"/>'; |
|
123 | + $html .= '<input type="hidden" name="tkt-slctr-max-atndz-'.$this->event->ID(); |
|
124 | + $html .= '" value="'.$this->template_args['max_atndz'].'"/>'; |
|
125 | + $html .= '<input type="hidden" name="tkt-slctr-event-id" value="'.$this->event->ID().'"/>'; |
|
126 | 126 | return $html; |
127 | 127 | } |
128 | 128 |
@@ -36,7 +36,7 @@ |
||
36 | 36 | |
37 | 37 | /** |
38 | 38 | * Taken from https://gist.github.com/jaywilliams/119517 |
39 | - * @param $string |
|
39 | + * @param string $string |
|
40 | 40 | * @return string |
41 | 41 | */ |
42 | 42 | protected function convertAscii($string) |
@@ -1,8 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\services\formatters; |
3 | 3 | |
4 | -use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
5 | - |
|
6 | 4 | defined('EVENT_ESPRESSO_VERSION') || exit; |
7 | 5 | |
8 | 6 |
@@ -18,60 +18,60 @@ |
||
18 | 18 | class AsciiOnly extends FormatterBase |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * Removes all non Ascii characters from string |
|
23 | - * |
|
24 | - * @param string|int|float $input anything easily cast into a string |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public function format($input) |
|
28 | - { |
|
29 | - //in case an int or float etc was passed in |
|
30 | - $input = (string)$input; |
|
31 | - $input = $this->convertAscii($input); |
|
32 | - return $input; |
|
33 | - } |
|
21 | + /** |
|
22 | + * Removes all non Ascii characters from string |
|
23 | + * |
|
24 | + * @param string|int|float $input anything easily cast into a string |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public function format($input) |
|
28 | + { |
|
29 | + //in case an int or float etc was passed in |
|
30 | + $input = (string)$input; |
|
31 | + $input = $this->convertAscii($input); |
|
32 | + return $input; |
|
33 | + } |
|
34 | 34 | |
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Taken from https://gist.github.com/jaywilliams/119517 |
|
39 | - * @param $string |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - protected function convertAscii($string) |
|
43 | - { |
|
44 | - // Replace Single Curly Quotes |
|
45 | - $search[] = chr(226).chr(128).chr(152); |
|
46 | - $replace[] = "'"; |
|
47 | - $search[] = chr(226).chr(128).chr(153); |
|
48 | - $replace[] = "'"; |
|
49 | - // Replace Smart Double Curly Quotes |
|
50 | - $search[] = chr(226).chr(128).chr(156); |
|
51 | - $replace[] = '"'; |
|
52 | - $search[] = chr(226).chr(128).chr(157); |
|
53 | - $replace[] = '"'; |
|
54 | - // Replace En Dash |
|
55 | - $search[] = chr(226).chr(128).chr(147); |
|
56 | - $replace[] = '--'; |
|
57 | - // Replace Em Dash |
|
58 | - $search[] = chr(226).chr(128).chr(148); |
|
59 | - $replace[] = '---'; |
|
60 | - // Replace Bullet |
|
61 | - $search[] = chr(226).chr(128).chr(162); |
|
62 | - $replace[] = '*'; |
|
63 | - // Replace Middle Dot |
|
64 | - $search[] = chr(194).chr(183); |
|
65 | - $replace[] = '*'; |
|
66 | - // Replace Ellipsis with three consecutive dots |
|
67 | - $search[] = chr(226).chr(128).chr(166); |
|
68 | - $replace[] = '...'; |
|
69 | - // Apply Replacements |
|
70 | - $string = str_replace($search, $replace, $string); |
|
71 | - // Remove any non-ASCII Characters |
|
72 | - $string = preg_replace("/[^\x01-\x7F]/","", $string); |
|
73 | - return $string; |
|
74 | - } |
|
37 | + /** |
|
38 | + * Taken from https://gist.github.com/jaywilliams/119517 |
|
39 | + * @param $string |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + protected function convertAscii($string) |
|
43 | + { |
|
44 | + // Replace Single Curly Quotes |
|
45 | + $search[] = chr(226).chr(128).chr(152); |
|
46 | + $replace[] = "'"; |
|
47 | + $search[] = chr(226).chr(128).chr(153); |
|
48 | + $replace[] = "'"; |
|
49 | + // Replace Smart Double Curly Quotes |
|
50 | + $search[] = chr(226).chr(128).chr(156); |
|
51 | + $replace[] = '"'; |
|
52 | + $search[] = chr(226).chr(128).chr(157); |
|
53 | + $replace[] = '"'; |
|
54 | + // Replace En Dash |
|
55 | + $search[] = chr(226).chr(128).chr(147); |
|
56 | + $replace[] = '--'; |
|
57 | + // Replace Em Dash |
|
58 | + $search[] = chr(226).chr(128).chr(148); |
|
59 | + $replace[] = '---'; |
|
60 | + // Replace Bullet |
|
61 | + $search[] = chr(226).chr(128).chr(162); |
|
62 | + $replace[] = '*'; |
|
63 | + // Replace Middle Dot |
|
64 | + $search[] = chr(194).chr(183); |
|
65 | + $replace[] = '*'; |
|
66 | + // Replace Ellipsis with three consecutive dots |
|
67 | + $search[] = chr(226).chr(128).chr(166); |
|
68 | + $replace[] = '...'; |
|
69 | + // Apply Replacements |
|
70 | + $string = str_replace($search, $replace, $string); |
|
71 | + // Remove any non-ASCII Characters |
|
72 | + $string = preg_replace("/[^\x01-\x7F]/","", $string); |
|
73 | + return $string; |
|
74 | + } |
|
75 | 75 | } |
76 | 76 | // End of file EmojiRemoval.php |
77 | 77 | // Location: core\services\formatters/EmojiRemoval.php |
78 | 78 | \ No newline at end of file |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | public function format($input) |
28 | 28 | { |
29 | 29 | //in case an int or float etc was passed in |
30 | - $input = (string)$input; |
|
30 | + $input = (string) $input; |
|
31 | 31 | $input = $this->convertAscii($input); |
32 | 32 | return $input; |
33 | 33 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | // Apply Replacements |
70 | 70 | $string = str_replace($search, $replace, $string); |
71 | 71 | // Remove any non-ASCII Characters |
72 | - $string = preg_replace("/[^\x01-\x7F]/","", $string); |
|
72 | + $string = preg_replace("/[^\x01-\x7F]/", "", $string); |
|
73 | 73 | return $string; |
74 | 74 | } |
75 | 75 | } |