@@ -18,28 +18,28 @@ |
||
| 18 | 18 | class LeaveAlone extends FormatterBase |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Removes the emojis from the inputted string |
|
| 23 | - * |
|
| 24 | - * @param string|int|float $input anything easily cast into a string |
|
| 25 | - * @return string |
|
| 26 | - * @throws InvalidDataTypeException if $input is not a string |
|
| 27 | - */ |
|
| 28 | - public function format($input) |
|
| 29 | - { |
|
| 30 | - return $input; |
|
| 31 | - } |
|
| 21 | + /** |
|
| 22 | + * Removes the emojis from the inputted string |
|
| 23 | + * |
|
| 24 | + * @param string|int|float $input anything easily cast into a string |
|
| 25 | + * @return string |
|
| 26 | + * @throws InvalidDataTypeException if $input is not a string |
|
| 27 | + */ |
|
| 28 | + public function format($input) |
|
| 29 | + { |
|
| 30 | + return $input; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Just returns the inputted $input array |
|
| 35 | - * |
|
| 36 | - * @param array $input |
|
| 37 | - * @return array |
|
| 38 | - */ |
|
| 39 | - public function formatArray($input) |
|
| 40 | - { |
|
| 41 | - return $input; |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * Just returns the inputted $input array |
|
| 35 | + * |
|
| 36 | + * @param array $input |
|
| 37 | + * @return array |
|
| 38 | + */ |
|
| 39 | + public function formatArray($input) |
|
| 40 | + { |
|
| 41 | + return $input; |
|
| 42 | + } |
|
| 43 | 43 | } |
| 44 | 44 | // End of file LeaveAlonel.php |
| 45 | 45 | // Location: core\services\formatters/LeaveAlonel.php |
| 46 | 46 | \ No newline at end of file |
@@ -28,8 +28,8 @@ |
||
| 28 | 28 | public function format($input) |
| 29 | 29 | { |
| 30 | 30 | //in case an int or float etc was passed in |
| 31 | - $input = (string)$input; |
|
| 32 | - $input = iconv('utf-8','cp1252//TRANSLIT', $input); |
|
| 31 | + $input = (string) $input; |
|
| 32 | + $input = iconv('utf-8', 'cp1252//TRANSLIT', $input); |
|
| 33 | 33 | return $input; |
| 34 | 34 | } |
| 35 | 35 | } |
@@ -11,7 +11,6 @@ discard block |
||
| 11 | 11 | * Class Windows1252 |
| 12 | 12 | * Converts from utf8 encoding to windows 1252 (aka cp1252, aka ISO-8859-1, see https://en.wikipedia.org/wiki/Windows-1252). |
| 13 | 13 | * This is useful if you need to send a string to a site using windows 1252 character encoding |
| 14 | - |
|
| 15 | 14 | * |
| 16 | 15 | *@package Event Espresso |
| 17 | 16 | * @author Mike Nelson |
@@ -20,19 +19,19 @@ discard block |
||
| 20 | 19 | class Windows1252 extends FormatterBase |
| 21 | 20 | { |
| 22 | 21 | |
| 23 | - /** |
|
| 24 | - * Converts the string to windows-1252 encoding. |
|
| 25 | - * |
|
| 26 | - * @param string|int|float $input anything easily cast into a string |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function format($input) |
|
| 30 | - { |
|
| 31 | - //in case an int or float etc was passed in |
|
| 32 | - $input = (string)$input; |
|
| 33 | - $input = iconv('utf-8','cp1252//TRANSLIT', $input); |
|
| 34 | - return $input; |
|
| 35 | - } |
|
| 22 | + /** |
|
| 23 | + * Converts the string to windows-1252 encoding. |
|
| 24 | + * |
|
| 25 | + * @param string|int|float $input anything easily cast into a string |
|
| 26 | + * @return string |
|
| 27 | + */ |
|
| 28 | + public function format($input) |
|
| 29 | + { |
|
| 30 | + //in case an int or float etc was passed in |
|
| 31 | + $input = (string)$input; |
|
| 32 | + $input = iconv('utf-8','cp1252//TRANSLIT', $input); |
|
| 33 | + return $input; |
|
| 34 | + } |
|
| 36 | 35 | } |
| 37 | 36 | // End of file EmojiRemoval.php |
| 38 | 37 | // Location: core\services\formatters/EmojiRemoval.php |
| 39 | 38 | \ No newline at end of file |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | public function __construct($pm_instance = NULL) { |
| 23 | 23 | $this->_setup_properties(); |
| 24 | 24 | parent::__construct($pm_instance); |
| 25 | - $this->_gateway->set_unsupported_character_remover(new \EventEspresso\core\services\formatters\Windows1252()); |
|
| 25 | + $this->_gateway->set_unsupported_character_remover(new \EventEspresso\core\services\formatters\Windows1252()); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -106,9 +106,9 @@ discard block |
||
| 106 | 106 | $this->_gateway->set_template_helper( new EEH_Template() ); |
| 107 | 107 | $this->_gateway->set_line_item_helper( new EEH_Line_Item() ); |
| 108 | 108 | $this->_gateway->set_money_helper( new EEH_Money() ); |
| 109 | - $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter()); |
|
| 110 | - $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
|
| 111 | - do_action( 'AHEE__EE_PMT_Base___construct__done_initializing_gateway_class',$this,$this->_gateway); |
|
| 109 | + $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter()); |
|
| 110 | + $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
|
| 111 | + do_action( 'AHEE__EE_PMT_Base___construct__done_initializing_gateway_class',$this,$this->_gateway); |
|
| 112 | 112 | } |
| 113 | 113 | if ( ! isset( $this->_has_billing_form ) ) { |
| 114 | 114 | // by default, On Site gateways have a billing form |
@@ -282,17 +282,17 @@ discard block |
||
| 282 | 282 | //if we know who the attendee is, and this is a billing form |
| 283 | 283 | //that uses attendee info, populate it |
| 284 | 284 | if ( |
| 285 | - apply_filters( |
|
| 286 | - 'FHEE__populate_billing_form_fields_from_attendee', |
|
| 287 | - ( |
|
| 288 | - $this->_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 289 | - && $transaction instanceof EE_Transaction |
|
| 290 | - && $transaction->primary_registration() instanceof EE_Registration |
|
| 291 | - && $transaction->primary_registration()->attendee() instanceof EE_Attendee |
|
| 292 | - ), |
|
| 293 | - $this->_billing_form, |
|
| 294 | - $transaction |
|
| 295 | - ) |
|
| 285 | + apply_filters( |
|
| 286 | + 'FHEE__populate_billing_form_fields_from_attendee', |
|
| 287 | + ( |
|
| 288 | + $this->_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 289 | + && $transaction instanceof EE_Transaction |
|
| 290 | + && $transaction->primary_registration() instanceof EE_Registration |
|
| 291 | + && $transaction->primary_registration()->attendee() instanceof EE_Attendee |
|
| 292 | + ), |
|
| 293 | + $this->_billing_form, |
|
| 294 | + $transaction |
|
| 295 | + ) |
|
| 296 | 296 | ){ |
| 297 | 297 | $this->_billing_form->populate_from_attendee( $transaction->primary_registration()->attendee() ); |
| 298 | 298 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @since $VID:$ |
| 17 | 17 | * |
| 18 | 18 | */ |
| 19 | -abstract class EE_PMT_Base{ |
|
| 19 | +abstract class EE_PMT_Base { |
|
| 20 | 20 | |
| 21 | 21 | const onsite = 'on-site'; |
| 22 | 22 | const offsite = 'off-site'; |
@@ -97,34 +97,34 @@ discard block |
||
| 97 | 97 | * @return EE_PMT_Base |
| 98 | 98 | */ |
| 99 | 99 | function __construct($pm_instance = NULL) { |
| 100 | - if ( $pm_instance instanceof EE_Payment_Method ){ |
|
| 100 | + if ($pm_instance instanceof EE_Payment_Method) { |
|
| 101 | 101 | $this->set_instance($pm_instance); |
| 102 | 102 | } |
| 103 | - if($this->_gateway){ |
|
| 104 | - $this->_gateway->set_payment_model( EEM_Payment::instance() ); |
|
| 105 | - $this->_gateway->set_payment_log( EEM_Change_Log::instance() ); |
|
| 106 | - $this->_gateway->set_template_helper( new EEH_Template() ); |
|
| 107 | - $this->_gateway->set_line_item_helper( new EEH_Line_Item() ); |
|
| 108 | - $this->_gateway->set_money_helper( new EEH_Money() ); |
|
| 103 | + if ($this->_gateway) { |
|
| 104 | + $this->_gateway->set_payment_model(EEM_Payment::instance()); |
|
| 105 | + $this->_gateway->set_payment_log(EEM_Change_Log::instance()); |
|
| 106 | + $this->_gateway->set_template_helper(new EEH_Template()); |
|
| 107 | + $this->_gateway->set_line_item_helper(new EEH_Line_Item()); |
|
| 108 | + $this->_gateway->set_money_helper(new EEH_Money()); |
|
| 109 | 109 | $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter()); |
| 110 | 110 | $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
| 111 | - do_action( 'AHEE__EE_PMT_Base___construct__done_initializing_gateway_class',$this,$this->_gateway); |
|
| 111 | + do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway); |
|
| 112 | 112 | } |
| 113 | - if ( ! isset( $this->_has_billing_form ) ) { |
|
| 113 | + if ( ! isset($this->_has_billing_form)) { |
|
| 114 | 114 | // by default, On Site gateways have a billing form |
| 115 | - if ( $this->payment_occurs() == EE_PMT_Base::onsite ) { |
|
| 116 | - $this->set_has_billing_form( true ); |
|
| 115 | + if ($this->payment_occurs() == EE_PMT_Base::onsite) { |
|
| 116 | + $this->set_has_billing_form(true); |
|
| 117 | 117 | } else { |
| 118 | - $this->set_has_billing_form( false ); |
|
| 118 | + $this->set_has_billing_form(false); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - if( ! $this->_pretty_name){ |
|
| 122 | + if ( ! $this->_pretty_name) { |
|
| 123 | 123 | throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso"))); |
| 124 | 124 | } |
| 125 | 125 | //if the child didn't specify a default button, use the credit card one |
| 126 | - if( $this->_default_button_url === NULL){ |
|
| 127 | - $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png'; |
|
| 126 | + if ($this->_default_button_url === NULL) { |
|
| 127 | + $this->_default_button_url = EE_PLUGIN_DIR_URL.'payment_methods'.DS.'pay-by-credit-card.png'; |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
@@ -133,8 +133,8 @@ discard block |
||
| 133 | 133 | /** |
| 134 | 134 | * @param boolean $has_billing_form |
| 135 | 135 | */ |
| 136 | - public function set_has_billing_form( $has_billing_form ) { |
|
| 137 | - $this->_has_billing_form = filter_var( $has_billing_form, FILTER_VALIDATE_BOOLEAN ); |
|
| 136 | + public function set_has_billing_form($has_billing_form) { |
|
| 137 | + $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | /** |
| 143 | 143 | * sets the file_folder property |
| 144 | 144 | */ |
| 145 | - protected function _set_file_folder(){ |
|
| 145 | + protected function _set_file_folder() { |
|
| 146 | 146 | $reflector = new ReflectionClass(get_class($this)); |
| 147 | 147 | $fn = $reflector->getFileName(); |
| 148 | - $this->_file_folder = dirname($fn).DS; |
|
| 148 | + $this->_file_folder = dirname($fn).DS; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | |
@@ -153,10 +153,10 @@ discard block |
||
| 153 | 153 | /** |
| 154 | 154 | * sets the file URL with a trailing slash for this PMT |
| 155 | 155 | */ |
| 156 | - protected function _set_file_url(){ |
|
| 157 | - $plugins_dir_fixed = str_replace('\\',DS,WP_PLUGIN_DIR); |
|
| 158 | - $file_folder_fixed = str_replace('\\',DS,$this->file_folder()); |
|
| 159 | - $file_path = str_replace($plugins_dir_fixed,WP_PLUGIN_URL,$file_folder_fixed); |
|
| 156 | + protected function _set_file_url() { |
|
| 157 | + $plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR); |
|
| 158 | + $file_folder_fixed = str_replace('\\', DS, $this->file_folder()); |
|
| 159 | + $file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed); |
|
| 160 | 160 | $this->_file_url = $file_path; |
| 161 | 161 | } |
| 162 | 162 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * Gets the default description on all payment methods of this type |
| 165 | 165 | * @return string |
| 166 | 166 | */ |
| 167 | - public function default_description(){ |
|
| 167 | + public function default_description() { |
|
| 168 | 168 | return $this->_default_description; |
| 169 | 169 | } |
| 170 | 170 | |
@@ -174,8 +174,8 @@ discard block |
||
| 174 | 174 | * Returns the folder containing the PMT child class, with a trailing slash |
| 175 | 175 | * @return string |
| 176 | 176 | */ |
| 177 | - public function file_folder(){ |
|
| 178 | - if( ! $this->_file_folder ) { |
|
| 177 | + public function file_folder() { |
|
| 178 | + if ( ! $this->_file_folder) { |
|
| 179 | 179 | $this->_set_file_folder(); |
| 180 | 180 | } |
| 181 | 181 | return $this->_file_folder; |
@@ -186,8 +186,8 @@ discard block |
||
| 186 | 186 | /** |
| 187 | 187 | * @return string |
| 188 | 188 | */ |
| 189 | - public function file_url(){ |
|
| 190 | - if( ! $this->_file_url ) { |
|
| 189 | + public function file_url() { |
|
| 190 | + if ( ! $this->_file_url) { |
|
| 191 | 191 | $this->_set_file_url(); |
| 192 | 192 | } |
| 193 | 193 | return $this->_file_url; |
@@ -200,14 +200,14 @@ discard block |
||
| 200 | 200 | * Its important teh payment method instance is set before |
| 201 | 201 | * @param EE_Payment_Method $payment_method_instance |
| 202 | 202 | */ |
| 203 | - function set_instance($payment_method_instance){ |
|
| 203 | + function set_instance($payment_method_instance) { |
|
| 204 | 204 | $this->_pm_instance = $payment_method_instance; |
| 205 | 205 | //if they have already requested the settings form, make sure its |
| 206 | 206 | //data matches this model object |
| 207 | - if($this->_settings_form){ |
|
| 207 | + if ($this->_settings_form) { |
|
| 208 | 208 | $this->settings_form()->populate_model_obj($payment_method_instance); |
| 209 | 209 | } |
| 210 | - if($this->_gateway && $this->_gateway instanceof EE_Gateway){ |
|
| 210 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
| 211 | 211 | $this->_gateway->set_settings($payment_method_instance->settings_array()); |
| 212 | 212 | } |
| 213 | 213 | } |
@@ -218,13 +218,13 @@ discard block |
||
| 218 | 218 | * Gets teh form for displaying to admins where they setup the payment method |
| 219 | 219 | * @return EE_Payment_Method_Form |
| 220 | 220 | */ |
| 221 | - function settings_form(){ |
|
| 222 | - if( ! $this->_settings_form){ |
|
| 221 | + function settings_form() { |
|
| 222 | + if ( ! $this->_settings_form) { |
|
| 223 | 223 | $this->_settings_form = $this->generate_new_settings_form(); |
| 224 | - $this->_settings_form->set_payment_method_type( $this ); |
|
| 224 | + $this->_settings_form->set_payment_method_type($this); |
|
| 225 | 225 | //if we have already assigned a model object to this pmt, make |
| 226 | 226 | //sure its reflected in teh form we just generated |
| 227 | - if($this->_pm_instance){ |
|
| 227 | + if ($this->_pm_instance) { |
|
| 228 | 228 | $this->_settings_form->populate_model_obj($this->_pm_instance); |
| 229 | 229 | } |
| 230 | 230 | } |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * this payment method type's settings form later in the request |
| 251 | 251 | * @param EE_Payment_Method_Form $form |
| 252 | 252 | */ |
| 253 | - public function set_settings_form($form){ |
|
| 253 | + public function set_settings_form($form) { |
|
| 254 | 254 | $this->_settings_form = $form; |
| 255 | 255 | } |
| 256 | 256 | |
@@ -273,10 +273,10 @@ discard block |
||
| 273 | 273 | * @param array $extra_args |
| 274 | 274 | * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null |
| 275 | 275 | */ |
| 276 | - public function billing_form( EE_Transaction $transaction = NULL, $extra_args = array() ){ |
|
| 276 | + public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array()) { |
|
| 277 | 277 | // has billing form already been regenerated ? or overwrite cache? |
| 278 | - if ( ! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form ){ |
|
| 279 | - $this->_billing_form = $this->generate_new_billing_form( $transaction, $extra_args ); |
|
| 278 | + if ( ! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) { |
|
| 279 | + $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args); |
|
| 280 | 280 | } |
| 281 | 281 | //if we know who the attendee is, and this is a billing form |
| 282 | 282 | //that uses attendee info, populate it |
@@ -292,8 +292,8 @@ discard block |
||
| 292 | 292 | $this->_billing_form, |
| 293 | 293 | $transaction |
| 294 | 294 | ) |
| 295 | - ){ |
|
| 296 | - $this->_billing_form->populate_from_attendee( $transaction->primary_registration()->attendee() ); |
|
| 295 | + ) { |
|
| 296 | + $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee()); |
|
| 297 | 297 | } |
| 298 | 298 | return $this->_billing_form; |
| 299 | 299 | } |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | * @param \EE_Transaction $transaction |
| 305 | 305 | * @return \EE_Billing_Info_Form |
| 306 | 306 | */ |
| 307 | - abstract function generate_new_billing_form( EE_Transaction $transaction = NULL ); |
|
| 307 | + abstract function generate_new_billing_form(EE_Transaction $transaction = NULL); |
|
| 308 | 308 | |
| 309 | 309 | |
| 310 | 310 | |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | * @param \EE_Billing_Info_Form $billing_form |
| 316 | 316 | * @return \EE_Billing_Info_Form |
| 317 | 317 | */ |
| 318 | - public function apply_billing_form_debug_settings( EE_Billing_Info_Form $billing_form ) { |
|
| 318 | + public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) { |
|
| 319 | 319 | return $billing_form; |
| 320 | 320 | } |
| 321 | 321 | |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | * if you have form |
| 327 | 327 | * @param EE_Payment_Method $form |
| 328 | 328 | */ |
| 329 | - public function set_billing_form($form){ |
|
| 329 | + public function set_billing_form($form) { |
|
| 330 | 330 | $this->_billing_form = $form; |
| 331 | 331 | } |
| 332 | 332 | |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | * Returns whether or not this payment method requires HTTPS to be used |
| 337 | 337 | * @return boolean |
| 338 | 338 | */ |
| 339 | - function requires_https(){ |
|
| 339 | + function requires_https() { |
|
| 340 | 340 | return $this->_requires_https; |
| 341 | 341 | } |
| 342 | 342 | |
@@ -354,9 +354,9 @@ discard block |
||
| 354 | 354 | * @return EE_Payment |
| 355 | 355 | * @throws EE_Error |
| 356 | 356 | */ |
| 357 | - function process_payment( EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null,$fail_url = '', $method = 'CART', $by_admin = false ){ |
|
| 357 | + function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false) { |
|
| 358 | 358 | // @todo: add surcharge for the payment method, if any |
| 359 | - if ( $this->_gateway ) { |
|
| 359 | + if ($this->_gateway) { |
|
| 360 | 360 | //there is a gateway, so we're going to make a payment object |
| 361 | 361 | //but wait! do they already have a payment in progress that we thought was failed? |
| 362 | 362 | $duplicate_properties = array( |
@@ -367,10 +367,10 @@ discard block |
||
| 367 | 367 | 'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(), |
| 368 | 368 | 'PAY_gateway_response' => null, |
| 369 | 369 | ); |
| 370 | - $payment = EEM_Payment::instance()->get_one( array( $duplicate_properties )); |
|
| 370 | + $payment = EEM_Payment::instance()->get_one(array($duplicate_properties)); |
|
| 371 | 371 | //if we didn't already have a payment in progress for the same thing, |
| 372 | 372 | //then we actually want to make a new payment |
| 373 | - if ( ! $payment instanceof EE_Payment ){ |
|
| 373 | + if ( ! $payment instanceof EE_Payment) { |
|
| 374 | 374 | $payment = EE_Payment::new_instance( |
| 375 | 375 | array_merge( |
| 376 | 376 | $duplicate_properties, |
@@ -386,10 +386,10 @@ discard block |
||
| 386 | 386 | } |
| 387 | 387 | //make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it |
| 388 | 388 | $payment->save(); |
| 389 | - $billing_values = $this->_get_billing_values_from_form( $billing_info ); |
|
| 389 | + $billing_values = $this->_get_billing_values_from_form($billing_info); |
|
| 390 | 390 | |
| 391 | 391 | // Offsite Gateway |
| 392 | - if( $this->_gateway instanceof EE_Offsite_Gateway ){ |
|
| 392 | + if ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
| 393 | 393 | |
| 394 | 394 | $payment = $this->_gateway->set_redirection_info( |
| 395 | 395 | $payment, |
@@ -405,17 +405,17 @@ discard block |
||
| 405 | 405 | ); |
| 406 | 406 | $payment->save(); |
| 407 | 407 | // Onsite Gateway |
| 408 | - } elseif ( $this->_gateway instanceof EE_Onsite_Gateway ) { |
|
| 408 | + } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
| 409 | 409 | |
| 410 | - $payment = $this->_gateway->do_direct_payment($payment,$billing_values); |
|
| 410 | + $payment = $this->_gateway->do_direct_payment($payment, $billing_values); |
|
| 411 | 411 | $payment->save(); |
| 412 | 412 | |
| 413 | 413 | } else { |
| 414 | 414 | throw new EE_Error( |
| 415 | 415 | sprintf( |
| 416 | - __('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso' ), |
|
| 416 | + __('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'), |
|
| 417 | 417 | get_class($this), |
| 418 | - gettype( $this->_gateway ) |
|
| 418 | + gettype($this->_gateway) |
|
| 419 | 419 | ) |
| 420 | 420 | ); |
| 421 | 421 | } |
@@ -437,8 +437,8 @@ discard block |
||
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | // if there is billing info, clean it and save it now |
| 440 | - if( $billing_info instanceof EE_Billing_Attendee_Info_Form ){ |
|
| 441 | - $this->_save_billing_info_to_attendee( $billing_info, $transaction ); |
|
| 440 | + if ($billing_info instanceof EE_Billing_Attendee_Info_Form) { |
|
| 441 | + $this->_save_billing_info_to_attendee($billing_info, $transaction); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | return $payment; |
@@ -451,10 +451,10 @@ discard block |
||
| 451 | 451 | * @param EE_Billing_Info_Form $billing_form |
| 452 | 452 | * @return array |
| 453 | 453 | */ |
| 454 | - protected function _get_billing_values_from_form( $billing_form ){ |
|
| 455 | - if($billing_form instanceof EE_Form_Section_Proper ){ |
|
| 456 | - return $billing_form->input_pretty_values( true ); |
|
| 457 | - }else{ |
|
| 454 | + protected function _get_billing_values_from_form($billing_form) { |
|
| 455 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 456 | + return $billing_form->input_pretty_values(true); |
|
| 457 | + } else { |
|
| 458 | 458 | return NULL; |
| 459 | 459 | } |
| 460 | 460 | } |
@@ -468,13 +468,13 @@ discard block |
||
| 468 | 468 | * @return EE_Payment |
| 469 | 469 | * @throws EE_Error |
| 470 | 470 | */ |
| 471 | - public function handle_ipn($req_data,$transaction){ |
|
| 471 | + public function handle_ipn($req_data, $transaction) { |
|
| 472 | 472 | $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
| 473 | - if( ! $this->_gateway instanceof EE_Offsite_Gateway){ |
|
| 474 | - throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r( $this->_gateway, TRUE ))); |
|
| 473 | + if ( ! $this->_gateway instanceof EE_Offsite_Gateway) { |
|
| 474 | + throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE))); |
|
| 475 | 475 | |
| 476 | 476 | } |
| 477 | - $payment = $this->_gateway->handle_payment_update( $req_data, $transaction ); |
|
| 477 | + $payment = $this->_gateway->handle_payment_update($req_data, $transaction); |
|
| 478 | 478 | return $payment; |
| 479 | 479 | } |
| 480 | 480 | |
@@ -487,22 +487,22 @@ discard block |
||
| 487 | 487 | * @param EE_Transaction $transaction |
| 488 | 488 | * @return boolean success |
| 489 | 489 | */ |
| 490 | - protected function _save_billing_info_to_attendee($billing_form, $transaction){ |
|
| 491 | - if( ! $transaction || ! $transaction instanceof EE_Transaction){ |
|
| 490 | + protected function _save_billing_info_to_attendee($billing_form, $transaction) { |
|
| 491 | + if ( ! $transaction || ! $transaction instanceof EE_Transaction) { |
|
| 492 | 492 | EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
| 493 | 493 | return false; |
| 494 | 494 | } |
| 495 | 495 | $primary_reg = $transaction->primary_registration(); |
| 496 | - if( ! $primary_reg ){ |
|
| 496 | + if ( ! $primary_reg) { |
|
| 497 | 497 | EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
| 498 | 498 | return false; |
| 499 | 499 | } |
| 500 | 500 | $attendee = $primary_reg->attendee(); |
| 501 | - if( ! $attendee ){ |
|
| 501 | + if ( ! $attendee) { |
|
| 502 | 502 | EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
| 503 | 503 | return false; |
| 504 | 504 | } |
| 505 | - return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method() ); |
|
| 505 | + return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method()); |
|
| 506 | 506 | |
| 507 | 507 | } |
| 508 | 508 | |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | * @param array $req_data |
| 516 | 516 | * @return EE_Payment |
| 517 | 517 | */ |
| 518 | - protected function find_payment_for_ipn( EE_Transaction $transaction, $req_data = array() ){ |
|
| 518 | + protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array()) { |
|
| 519 | 519 | return $transaction->last_payment(); |
| 520 | 520 | } |
| 521 | 521 | |
@@ -532,8 +532,8 @@ discard block |
||
| 532 | 532 | * and identifies the IPN as being for this payment method (not just fo ra payment method of this type) |
| 533 | 533 | * @throws EE_Error |
| 534 | 534 | */ |
| 535 | - public function handle_unclaimed_ipn( $req_data = array() ){ |
|
| 536 | - throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this) )); |
|
| 535 | + public function handle_unclaimed_ipn($req_data = array()) { |
|
| 536 | + throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this))); |
|
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | * @param EE_Transaction $transaction |
| 550 | 550 | * @return EE_Payment |
| 551 | 551 | */ |
| 552 | - public function finalize_payment_for($transaction){ |
|
| 552 | + public function finalize_payment_for($transaction) { |
|
| 553 | 553 | return $transaction->last_payment(); |
| 554 | 554 | } |
| 555 | 555 | |
@@ -559,10 +559,10 @@ discard block |
||
| 559 | 559 | * Whether or not this payment method's gateway supports sending refund requests |
| 560 | 560 | * @return boolean |
| 561 | 561 | */ |
| 562 | - public function supports_sending_refunds(){ |
|
| 563 | - if($this->_gateway && $this->_gateway instanceof EE_Gateway){ |
|
| 562 | + public function supports_sending_refunds() { |
|
| 563 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
| 564 | 564 | return $this->_gateway->supports_sending_refunds(); |
| 565 | - }else{ |
|
| 565 | + } else { |
|
| 566 | 566 | return false; |
| 567 | 567 | } |
| 568 | 568 | } |
@@ -576,14 +576,14 @@ discard block |
||
| 576 | 576 | * @throws EE_Error |
| 577 | 577 | * @return EE_Payment |
| 578 | 578 | */ |
| 579 | - public function process_refund( EE_Payment $payment, $refund_info = array()){ |
|
| 580 | - if ( $this->_gateway && $this->_gateway instanceof EE_Gateway ) { |
|
| 581 | - return $this->_gateway->do_direct_refund( $payment, $refund_info ); |
|
| 579 | + public function process_refund(EE_Payment $payment, $refund_info = array()) { |
|
| 580 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
| 581 | + return $this->_gateway->do_direct_refund($payment, $refund_info); |
|
| 582 | 582 | } else { |
| 583 | 583 | throw new EE_Error( |
| 584 | 584 | sprintf( |
| 585 | - __( 'Payment Method Type "%s" does not support sending refund requests', 'event_espresso' ), |
|
| 586 | - get_class( $this ) |
|
| 585 | + __('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'), |
|
| 586 | + get_class($this) |
|
| 587 | 587 | ) |
| 588 | 588 | ); |
| 589 | 589 | } |
@@ -597,15 +597,15 @@ discard block |
||
| 597 | 597 | * @return string |
| 598 | 598 | * @throws EE_Error |
| 599 | 599 | */ |
| 600 | - public function payment_occurs(){ |
|
| 601 | - if( ! $this->_gateway){ |
|
| 600 | + public function payment_occurs() { |
|
| 601 | + if ( ! $this->_gateway) { |
|
| 602 | 602 | return EE_PMT_Base::offline; |
| 603 | - }elseif($this->_gateway instanceof EE_Onsite_Gateway){ |
|
| 603 | + }elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
| 604 | 604 | return EE_PMT_Base::onsite; |
| 605 | - }elseif($this->_gateway instanceof EE_Offsite_Gateway){ |
|
| 605 | + }elseif ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
| 606 | 606 | return EE_PMT_Base::offsite; |
| 607 | - }else{ |
|
| 608 | - throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"),get_class($this))); |
|
| 607 | + } else { |
|
| 608 | + throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this))); |
|
| 609 | 609 | } |
| 610 | 610 | } |
| 611 | 611 | |
@@ -618,8 +618,8 @@ discard block |
||
| 618 | 618 | * @param EE_Payment $payment |
| 619 | 619 | * @return string |
| 620 | 620 | */ |
| 621 | - public function payment_overview_content(EE_Payment $payment){ |
|
| 622 | - return EEH_Template::display_template(EE_LIBRARIES.'payment_methods'.DS.'templates'.DS.'payment_details_content.template.php', array('payment_method'=>$this->_pm_instance,'payment'=>$payment) , true); |
|
| 621 | + public function payment_overview_content(EE_Payment $payment) { |
|
| 622 | + return EEH_Template::display_template(EE_LIBRARIES.'payment_methods'.DS.'templates'.DS.'payment_details_content.template.php', array('payment_method'=>$this->_pm_instance, 'payment'=>$payment), true); |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | * @type array $template_args any arguments you want passed to the template file while rendering. |
| 633 | 633 | * Keys will be variable names and values with be their values. |
| 634 | 634 | */ |
| 635 | - public function help_tabs_config(){ |
|
| 635 | + public function help_tabs_config() { |
|
| 636 | 636 | return array(); |
| 637 | 637 | } |
| 638 | 638 | |
@@ -643,9 +643,9 @@ discard block |
||
| 643 | 643 | * the payment method's table's PMT_type column) |
| 644 | 644 | * @return string |
| 645 | 645 | */ |
| 646 | - public function system_name(){ |
|
| 646 | + public function system_name() { |
|
| 647 | 647 | $classname = get_class($this); |
| 648 | - return str_replace("EE_PMT_",'',$classname); |
|
| 648 | + return str_replace("EE_PMT_", '', $classname); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | * A pretty i18n version of the PMT name |
| 655 | 655 | * @return string |
| 656 | 656 | */ |
| 657 | - public function pretty_name(){ |
|
| 657 | + public function pretty_name() { |
|
| 658 | 658 | return $this->_pretty_name; |
| 659 | 659 | } |
| 660 | 660 | |
@@ -664,7 +664,7 @@ discard block |
||
| 664 | 664 | * Gets the default absolute URL to the payment method type's button |
| 665 | 665 | * @return string |
| 666 | 666 | */ |
| 667 | - public function default_button_url(){ |
|
| 667 | + public function default_button_url() { |
|
| 668 | 668 | return $this->_default_button_url; |
| 669 | 669 | } |
| 670 | 670 | |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | * Gets the gateway used by this payment method (if any) |
| 675 | 675 | * @return EE_Gateway |
| 676 | 676 | */ |
| 677 | - public function get_gateway(){ |
|
| 677 | + public function get_gateway() { |
|
| 678 | 678 | return $this->_gateway; |
| 679 | 679 | } |
| 680 | 680 | |
@@ -683,8 +683,8 @@ discard block |
||
| 683 | 683 | /** |
| 684 | 684 | * @return string html for the link to a help tab |
| 685 | 685 | */ |
| 686 | - public function get_help_tab_link(){ |
|
| 687 | - return EEH_Template::get_help_tab_link( $this->get_help_tab_name() ); |
|
| 686 | + public function get_help_tab_link() { |
|
| 687 | + return EEH_Template::get_help_tab_link($this->get_help_tab_name()); |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | |
@@ -693,8 +693,8 @@ discard block |
||
| 693 | 693 | * Returns the name of the help tab for this PMT |
| 694 | 694 | * @return string |
| 695 | 695 | */ |
| 696 | - public function get_help_tab_name(){ |
|
| 697 | - return 'ee_' . strtolower( $this->system_name() ) . '_help_tab'; |
|
| 696 | + public function get_help_tab_name() { |
|
| 697 | + return 'ee_'.strtolower($this->system_name()).'_help_tab'; |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | /** |
@@ -702,8 +702,8 @@ discard block |
||
| 702 | 702 | * this PMT by an admin |
| 703 | 703 | * @return string |
| 704 | 704 | */ |
| 705 | - public function cap_name(){ |
|
| 706 | - return 'ee_payment_method_' . strtolower( $this->system_name() ); |
|
| 705 | + public function cap_name() { |
|
| 706 | + return 'ee_payment_method_'.strtolower($this->system_name()); |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | /** |
@@ -715,9 +715,9 @@ discard block |
||
| 715 | 715 | * @param EE_Payment $payment |
| 716 | 716 | * @return void |
| 717 | 717 | */ |
| 718 | - public function update_txn_based_on_payment( $payment ){ |
|
| 719 | - if( $this->_gateway instanceof EE_Gateway ){ |
|
| 720 | - $this->_gateway->update_txn_based_on_payment( $payment ); |
|
| 718 | + public function update_txn_based_on_payment($payment) { |
|
| 719 | + if ($this->_gateway instanceof EE_Gateway) { |
|
| 720 | + $this->_gateway->update_txn_based_on_payment($payment); |
|
| 721 | 721 | } |
| 722 | 722 | } |
| 723 | 723 | |
@@ -732,7 +732,7 @@ discard block |
||
| 732 | 732 | * @return string |
| 733 | 733 | */ |
| 734 | 734 | public function introductory_html() { |
| 735 | - return EEH_Template::locate_template( $this->file_folder() . 'templates' . DS . strtolower( $this->system_name() ) . '_intro.template.php', array( 'pmt_obj' => $this, 'pm_instance' => $this->_pm_instance ) ); |
|
| 735 | + return EEH_Template::locate_template($this->file_folder().'templates'.DS.strtolower($this->system_name()).'_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance)); |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | } |
| 104 | 104 | $order = apply_filters( 'FHEE__EEG_Mijireh__set_redirection_info__order_arguments', $order, $payment, $primary_registrant ); |
| 105 | 105 | do_action( 'AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this)) ); |
| 106 | - $order = $this->_get_unsupported_character_remover()->formatArray($order); |
|
| 106 | + $order = $this->_get_unsupported_character_remover()->formatArray($order); |
|
| 107 | 107 | |
| 108 | 108 | $args = array( |
| 109 | 109 | 'headers' => array( |
@@ -113,45 +113,45 @@ discard block |
||
| 113 | 113 | 'body'=> wp_json_encode($order) |
| 114 | 114 | ); |
| 115 | 115 | $response = wp_remote_post( $this->_mijireh_api_orders_url, $args ); |
| 116 | - $problems_string = false; |
|
| 116 | + $problems_string = false; |
|
| 117 | 117 | $this->log(array('get checkout url request_args' => $args, 'response' => $response ), $payment); |
| 118 | 118 | if( ! $response instanceof WP_Error ){ |
| 119 | 119 | $response_body = json_decode($response['body']); |
| 120 | 120 | if($response_body && isset($response_body->checkout_url)){ |
| 121 | - $payment->set_redirect_url($response_body->checkout_url); |
|
| 122 | - $payment->set_txn_id_chq_nmbr($response_body->order_number); |
|
| 123 | - $payment->set_details($response['body']); |
|
| 121 | + $payment->set_redirect_url($response_body->checkout_url); |
|
| 122 | + $payment->set_txn_id_chq_nmbr($response_body->order_number); |
|
| 123 | + $payment->set_details($response['body']); |
|
| 124 | 124 | } else { |
| 125 | - if( is_array( $response_body ) || is_object( $response_body)){ |
|
| 126 | - $response_body_as_array = (array)$response_body; |
|
| 127 | - foreach($response_body_as_array as $problem_parameter => $problems){ |
|
| 128 | - $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems)); |
|
| 129 | - } |
|
| 130 | - }else{ |
|
| 131 | - $problems_string = $response['body']; |
|
| 132 | - } |
|
| 133 | - if( ! $problems_string ) { |
|
| 134 | - //no message to show? wack |
|
| 135 | - if( isset( $response[ 'headers' ][ 'status' ] ) ){ |
|
| 136 | - $problems_string = $response[ 'headers' ][ 'status' ]; |
|
| 137 | - }else{ |
|
| 138 | - $problems_string = __( 'No response from Mijireh', 'event_espresso' ); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - } |
|
| 125 | + if( is_array( $response_body ) || is_object( $response_body)){ |
|
| 126 | + $response_body_as_array = (array)$response_body; |
|
| 127 | + foreach($response_body_as_array as $problem_parameter => $problems){ |
|
| 128 | + $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems)); |
|
| 129 | + } |
|
| 130 | + }else{ |
|
| 131 | + $problems_string = $response['body']; |
|
| 132 | + } |
|
| 133 | + if( ! $problems_string ) { |
|
| 134 | + //no message to show? wack |
|
| 135 | + if( isset( $response[ 'headers' ][ 'status' ] ) ){ |
|
| 136 | + $problems_string = $response[ 'headers' ][ 'status' ]; |
|
| 137 | + }else{ |
|
| 138 | + $problems_string = __( 'No response from Mijireh', 'event_espresso' ); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | 142 | }else{ |
| 143 | - $problems_string = implode( ",", $response->get_error_messages() ); |
|
| 143 | + $problems_string = implode( ",", $response->get_error_messages() ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if( $problems_string ) { |
|
| 147 | - $payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) ); |
|
| 148 | - $payment->set_details( $response ); |
|
| 149 | - $payment->set_redirect_url( null ); |
|
| 150 | - //even though the payment's status is failed at this point anyways, |
|
| 151 | - //let's be explicit about it. The fact that the redirect url is null |
|
| 152 | - //should be enough to client code that they can't redirect the user |
|
| 153 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
| 154 | - } |
|
| 146 | + if( $problems_string ) { |
|
| 147 | + $payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) ); |
|
| 148 | + $payment->set_details( $response ); |
|
| 149 | + $payment->set_redirect_url( null ); |
|
| 150 | + //even though the payment's status is failed at this point anyways, |
|
| 151 | + //let's be explicit about it. The fact that the redirect url is null |
|
| 152 | + //should be enough to client code that they can't redirect the user |
|
| 153 | + $payment->set_status( $this->_pay_model->failed_status() ); |
|
| 154 | + } |
|
| 155 | 155 | return $payment; |
| 156 | 156 | } |
| 157 | 157 | |
@@ -188,70 +188,70 @@ discard block |
||
| 188 | 188 | * @param array $update_info unused. We just use the $transaction |
| 189 | 189 | * @param EEI_Transaction $transaction |
| 190 | 190 | * @return \EEI_Payment |
| 191 | - * @throws EE_Error |
|
| 191 | + * @throws EE_Error |
|
| 192 | 192 | */ |
| 193 | 193 | public function handle_payment_update($update_info, $transaction) { |
| 194 | - foreach( $transaction->pending_payments() as $payment){ |
|
| 195 | - $payment = $this->check_payment_in_mijireh($payment); |
|
| 196 | - if( $payment->status() === $this->_pay_model->approved_status()){ |
|
| 197 | - return $payment; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
|
| 194 | + foreach( $transaction->pending_payments() as $payment){ |
|
| 195 | + $payment = $this->check_payment_in_mijireh($payment); |
|
| 196 | + if( $payment->status() === $this->_pay_model->approved_status()){ |
|
| 197 | + return $payment; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
|
| 201 | 201 | |
| 202 | - if ( ! $payment instanceof EEI_Payment ){ |
|
| 203 | - throw new EE_Error( sprintf( __( "Could not find Mijireh payment for transaction %s", 'event_espresso' ), $transaction->ID() ) ); |
|
| 204 | - } |
|
| 205 | - return $payment; |
|
| 202 | + if ( ! $payment instanceof EEI_Payment ){ |
|
| 203 | + throw new EE_Error( sprintf( __( "Could not find Mijireh payment for transaction %s", 'event_espresso' ), $transaction->ID() ) ); |
|
| 204 | + } |
|
| 205 | + return $payment; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * Checks the payment's status in Mijireh for this specific payment |
|
| 212 | - * @param \EEI_Payment $payment |
|
| 213 | - * @return \EEI_Payment |
|
| 214 | - */ |
|
| 210 | + /** |
|
| 211 | + * Checks the payment's status in Mijireh for this specific payment |
|
| 212 | + * @param \EEI_Payment $payment |
|
| 213 | + * @return \EEI_Payment |
|
| 214 | + */ |
|
| 215 | 215 | public function check_payment_in_mijireh( EEI_Payment $payment ){ |
| 216 | - $request_args = array( |
|
| 217 | - 'headers' => array( |
|
| 218 | - 'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ), |
|
| 219 | - 'Accept'=>'application/json' |
|
| 220 | - ) |
|
| 221 | - ); |
|
| 216 | + $request_args = array( |
|
| 217 | + 'headers' => array( |
|
| 218 | + 'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ), |
|
| 219 | + 'Accept'=>'application/json' |
|
| 220 | + ) |
|
| 221 | + ); |
|
| 222 | 222 | |
| 223 | - $response = wp_remote_get( |
|
| 224 | - $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
| 225 | - $request_args |
|
| 226 | - ); |
|
| 223 | + $response = wp_remote_get( |
|
| 224 | + $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
| 225 | + $request_args |
|
| 226 | + ); |
|
| 227 | 227 | |
| 228 | - $this->log( |
|
| 229 | - array( 'get payment status request_args' => $request_args, 'response' => $response ), |
|
| 230 | - $payment |
|
| 231 | - ); |
|
| 232 | - // validate response |
|
| 233 | - $response_body = isset( $response[ 'body' ] ) ? json_decode( $response[ 'body' ] ) : ''; |
|
| 234 | - if( $response && $response_body ){ |
|
| 235 | - switch( $response_body->status ){ |
|
| 236 | - case 'paid': |
|
| 237 | - $payment->set_status($this->_pay_model->approved_status()); |
|
| 238 | - break; |
|
| 239 | - case 'pending': |
|
| 240 | - $payment->set_status($this->_pay_model->pending_status()); |
|
| 241 | - break; |
|
| 242 | - default: |
|
| 243 | - $payment->set_status($this->_pay_model->declined_status()); |
|
| 244 | - } |
|
| 228 | + $this->log( |
|
| 229 | + array( 'get payment status request_args' => $request_args, 'response' => $response ), |
|
| 230 | + $payment |
|
| 231 | + ); |
|
| 232 | + // validate response |
|
| 233 | + $response_body = isset( $response[ 'body' ] ) ? json_decode( $response[ 'body' ] ) : ''; |
|
| 234 | + if( $response && $response_body ){ |
|
| 235 | + switch( $response_body->status ){ |
|
| 236 | + case 'paid': |
|
| 237 | + $payment->set_status($this->_pay_model->approved_status()); |
|
| 238 | + break; |
|
| 239 | + case 'pending': |
|
| 240 | + $payment->set_status($this->_pay_model->pending_status()); |
|
| 241 | + break; |
|
| 242 | + default: |
|
| 243 | + $payment->set_status($this->_pay_model->declined_status()); |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - } else { |
|
| 247 | - $payment->set_gateway_response( __( 'Response from Mijireh could not be understood.', 'event_espresso' ) ); |
|
| 248 | - $payment->set_details( $response ); |
|
| 249 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
| 250 | - } |
|
| 251 | - // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage |
|
| 246 | + } else { |
|
| 247 | + $payment->set_gateway_response( __( 'Response from Mijireh could not be understood.', 'event_espresso' ) ); |
|
| 248 | + $payment->set_details( $response ); |
|
| 249 | + $payment->set_status( $this->_pay_model->failed_status() ); |
|
| 250 | + } |
|
| 251 | + // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage |
|
| 252 | 252 | // $payment->set_status( $this->_pay_model->pending_status() ); |
| 253 | - return $payment; |
|
| 254 | - } |
|
| 253 | + return $payment; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | 256 | } |
| 257 | 257 | |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @author Mike Nelson |
| 9 | 9 | * |
| 10 | 10 | */ |
| 11 | -class EEG_Mijireh extends EE_Offsite_Gateway{ |
|
| 11 | +class EEG_Mijireh extends EE_Offsite_Gateway { |
|
| 12 | 12 | |
| 13 | 13 | protected $_access_key; |
| 14 | 14 | |
@@ -37,14 +37,14 @@ discard block |
||
| 37 | 37 | $primary_attendee = $primary_registrant->attendee(); |
| 38 | 38 | $items = array(); |
| 39 | 39 | //if we're are charging for the full amount, show the normal line items |
| 40 | - if( $this->_can_easily_itemize_transaction_for( $payment )){ |
|
| 40 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
| 41 | 41 | $total_line_item = $transaction->total_line_item(); |
| 42 | 42 | $tax_total = $total_line_item->get_total_tax(); |
| 43 | - foreach($total_line_item->get_items() as $line_item){ |
|
| 43 | + foreach ($total_line_item->get_items() as $line_item) { |
|
| 44 | 44 | $items[] = array( |
| 45 | 45 | 'name'=>apply_filters( |
| 46 | 46 | 'FHEE__EEG_Mijireh__set_redirection_info__full_amount_line_item_name', |
| 47 | - $this->_format_line_item_name( $line_item, $payment ), |
|
| 47 | + $this->_format_line_item_name($line_item, $payment), |
|
| 48 | 48 | $line_item, |
| 49 | 49 | $payment, |
| 50 | 50 | $primary_registrant |
@@ -54,13 +54,13 @@ discard block |
||
| 54 | 54 | 'quantity'=>$line_item->quantity() |
| 55 | 55 | ); |
| 56 | 56 | } |
| 57 | - }else{//its a partial payment |
|
| 57 | + } else {//its a partial payment |
|
| 58 | 58 | $tax_total = 0; |
| 59 | 59 | //partial payment, so just add 1 item |
| 60 | 60 | $items[] = array( |
| 61 | 61 | 'name'=> apply_filters( |
| 62 | 62 | 'FHEE__EEG_Mijireh__set_redirection_info__partial_amount_line_item_name', |
| 63 | - $this->_format_partial_payment_line_item_name( $payment ), |
|
| 63 | + $this->_format_partial_payment_line_item_name($payment), |
|
| 64 | 64 | $payment, |
| 65 | 65 | $primary_registrant |
| 66 | 66 | ), |
@@ -72,18 +72,18 @@ discard block |
||
| 72 | 72 | $order = array( |
| 73 | 73 | 'total'=>$this->format_currency($payment->amount()), |
| 74 | 74 | 'return_url'=>$return_url, |
| 75 | - 'items'=>$this->_prepare_for_mijireh( $items ), |
|
| 75 | + 'items'=>$this->_prepare_for_mijireh($items), |
|
| 76 | 76 | 'email'=>$primary_attendee->email(), |
| 77 | 77 | 'first_name'=>$primary_attendee->fname(), |
| 78 | 78 | 'last_name'=>$primary_attendee->lname(), |
| 79 | 79 | 'tax'=>$this->format_currency($tax_total), |
| 80 | 80 | 'partner_id'=>'ee'); |
| 81 | 81 | //setup address? |
| 82 | - if( $primary_attendee->address() && |
|
| 83 | - $primary_attendee->city() && |
|
| 84 | - $primary_attendee->state_ID() && |
|
| 85 | - $primary_attendee->country_ID() && |
|
| 86 | - $primary_attendee->zip() ){ |
|
| 82 | + if ($primary_attendee->address() && |
|
| 83 | + $primary_attendee->city() && |
|
| 84 | + $primary_attendee->state_ID() && |
|
| 85 | + $primary_attendee->country_ID() && |
|
| 86 | + $primary_attendee->zip()) { |
|
| 87 | 87 | $shipping_address = array( |
| 88 | 88 | 'first_name'=>$primary_attendee->fname(), |
| 89 | 89 | 'last_name'=>$primary_attendee->lname(), |
@@ -93,64 +93,64 @@ discard block |
||
| 93 | 93 | 'zip_code' => $primary_attendee->zip(), |
| 94 | 94 | 'country' => $primary_attendee->country_ID() |
| 95 | 95 | ); |
| 96 | - if( $primary_attendee->address2() ){ |
|
| 97 | - $shipping_address[ 'apt_suite' ] = $primary_attendee->address2(); |
|
| 96 | + if ($primary_attendee->address2()) { |
|
| 97 | + $shipping_address['apt_suite'] = $primary_attendee->address2(); |
|
| 98 | 98 | } |
| 99 | - if( $primary_attendee->phone() ){ |
|
| 100 | - $shipping_address[ 'phone' ] = $primary_attendee->phone(); |
|
| 99 | + if ($primary_attendee->phone()) { |
|
| 100 | + $shipping_address['phone'] = $primary_attendee->phone(); |
|
| 101 | 101 | } |
| 102 | - $order[ 'shipping_address' ] = $shipping_address; |
|
| 102 | + $order['shipping_address'] = $shipping_address; |
|
| 103 | 103 | } |
| 104 | - $order = apply_filters( 'FHEE__EEG_Mijireh__set_redirection_info__order_arguments', $order, $payment, $primary_registrant ); |
|
| 105 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this)) ); |
|
| 104 | + $order = apply_filters('FHEE__EEG_Mijireh__set_redirection_info__order_arguments', $order, $payment, $primary_registrant); |
|
| 105 | + do_action('AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this))); |
|
| 106 | 106 | $order = $this->_get_unsupported_character_remover()->formatArray($order); |
| 107 | 107 | |
| 108 | 108 | $args = array( |
| 109 | 109 | 'headers' => array( |
| 110 | - 'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ), |
|
| 110 | + 'Authorization' => 'Basic '.base64_encode($this->_access_key.':'), |
|
| 111 | 111 | 'Accept'=>'application/json' |
| 112 | 112 | ), |
| 113 | 113 | 'body'=> wp_json_encode($order) |
| 114 | 114 | ); |
| 115 | - $response = wp_remote_post( $this->_mijireh_api_orders_url, $args ); |
|
| 115 | + $response = wp_remote_post($this->_mijireh_api_orders_url, $args); |
|
| 116 | 116 | $problems_string = false; |
| 117 | - $this->log(array('get checkout url request_args' => $args, 'response' => $response ), $payment); |
|
| 118 | - if( ! $response instanceof WP_Error ){ |
|
| 117 | + $this->log(array('get checkout url request_args' => $args, 'response' => $response), $payment); |
|
| 118 | + if ( ! $response instanceof WP_Error) { |
|
| 119 | 119 | $response_body = json_decode($response['body']); |
| 120 | - if($response_body && isset($response_body->checkout_url)){ |
|
| 120 | + if ($response_body && isset($response_body->checkout_url)) { |
|
| 121 | 121 | $payment->set_redirect_url($response_body->checkout_url); |
| 122 | 122 | $payment->set_txn_id_chq_nmbr($response_body->order_number); |
| 123 | 123 | $payment->set_details($response['body']); |
| 124 | 124 | } else { |
| 125 | - if( is_array( $response_body ) || is_object( $response_body)){ |
|
| 126 | - $response_body_as_array = (array)$response_body; |
|
| 127 | - foreach($response_body_as_array as $problem_parameter => $problems){ |
|
| 128 | - $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems)); |
|
| 125 | + if (is_array($response_body) || is_object($response_body)) { |
|
| 126 | + $response_body_as_array = (array) $response_body; |
|
| 127 | + foreach ($response_body_as_array as $problem_parameter => $problems) { |
|
| 128 | + $problems_string .= sprintf(__('\nProblems with %s: %s', 'event_espresso'), $problem_parameter, implode(", ", $problems)); |
|
| 129 | 129 | } |
| 130 | - }else{ |
|
| 130 | + } else { |
|
| 131 | 131 | $problems_string = $response['body']; |
| 132 | 132 | } |
| 133 | - if( ! $problems_string ) { |
|
| 133 | + if ( ! $problems_string) { |
|
| 134 | 134 | //no message to show? wack |
| 135 | - if( isset( $response[ 'headers' ][ 'status' ] ) ){ |
|
| 136 | - $problems_string = $response[ 'headers' ][ 'status' ]; |
|
| 137 | - }else{ |
|
| 138 | - $problems_string = __( 'No response from Mijireh', 'event_espresso' ); |
|
| 135 | + if (isset($response['headers']['status'])) { |
|
| 136 | + $problems_string = $response['headers']['status']; |
|
| 137 | + } else { |
|
| 138 | + $problems_string = __('No response from Mijireh', 'event_espresso'); |
|
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | - }else{ |
|
| 143 | - $problems_string = implode( ",", $response->get_error_messages() ); |
|
| 142 | + } else { |
|
| 143 | + $problems_string = implode(",", $response->get_error_messages()); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if( $problems_string ) { |
|
| 147 | - $payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) ); |
|
| 148 | - $payment->set_details( $response ); |
|
| 149 | - $payment->set_redirect_url( null ); |
|
| 146 | + if ($problems_string) { |
|
| 147 | + $payment->set_gateway_response(sprintf(__('Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string)); |
|
| 148 | + $payment->set_details($response); |
|
| 149 | + $payment->set_redirect_url(null); |
|
| 150 | 150 | //even though the payment's status is failed at this point anyways, |
| 151 | 151 | //let's be explicit about it. The fact that the redirect url is null |
| 152 | 152 | //should be enough to client code that they can't redirect the user |
| 153 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
| 153 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 154 | 154 | } |
| 155 | 155 | return $payment; |
| 156 | 156 | } |
@@ -163,16 +163,16 @@ discard block |
||
| 163 | 163 | * @param mixed $data |
| 164 | 164 | * @return mixed same type as $data |
| 165 | 165 | */ |
| 166 | - private function _prepare_for_mijireh( $data ){ |
|
| 167 | - if( is_array( $data ) ){ |
|
| 166 | + private function _prepare_for_mijireh($data) { |
|
| 167 | + if (is_array($data)) { |
|
| 168 | 168 | $prepared_data = array(); |
| 169 | - foreach($data as $key => $datum ){ |
|
| 170 | - $prepared_data[ $key ] = $this->_prepare_for_mijireh( $datum ); |
|
| 169 | + foreach ($data as $key => $datum) { |
|
| 170 | + $prepared_data[$key] = $this->_prepare_for_mijireh($datum); |
|
| 171 | 171 | } |
| 172 | 172 | return $prepared_data; |
| 173 | - }elseif(is_string( $data ) ){ |
|
| 174 | - return str_replace( '%', 'percent', $data ); |
|
| 175 | - }else{ |
|
| 173 | + }elseif (is_string($data)) { |
|
| 174 | + return str_replace('%', 'percent', $data); |
|
| 175 | + } else { |
|
| 176 | 176 | return $data; |
| 177 | 177 | } |
| 178 | 178 | } |
@@ -191,16 +191,16 @@ discard block |
||
| 191 | 191 | * @throws EE_Error |
| 192 | 192 | */ |
| 193 | 193 | public function handle_payment_update($update_info, $transaction) { |
| 194 | - foreach( $transaction->pending_payments() as $payment){ |
|
| 194 | + foreach ($transaction->pending_payments() as $payment) { |
|
| 195 | 195 | $payment = $this->check_payment_in_mijireh($payment); |
| 196 | - if( $payment->status() === $this->_pay_model->approved_status()){ |
|
| 196 | + if ($payment->status() === $this->_pay_model->approved_status()) { |
|
| 197 | 197 | return $payment; |
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
| 201 | 201 | |
| 202 | - if ( ! $payment instanceof EEI_Payment ){ |
|
| 203 | - throw new EE_Error( sprintf( __( "Could not find Mijireh payment for transaction %s", 'event_espresso' ), $transaction->ID() ) ); |
|
| 202 | + if ( ! $payment instanceof EEI_Payment) { |
|
| 203 | + throw new EE_Error(sprintf(__("Could not find Mijireh payment for transaction %s", 'event_espresso'), $transaction->ID())); |
|
| 204 | 204 | } |
| 205 | 205 | return $payment; |
| 206 | 206 | } |
@@ -212,27 +212,27 @@ discard block |
||
| 212 | 212 | * @param \EEI_Payment $payment |
| 213 | 213 | * @return \EEI_Payment |
| 214 | 214 | */ |
| 215 | - public function check_payment_in_mijireh( EEI_Payment $payment ){ |
|
| 215 | + public function check_payment_in_mijireh(EEI_Payment $payment) { |
|
| 216 | 216 | $request_args = array( |
| 217 | 217 | 'headers' => array( |
| 218 | - 'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ), |
|
| 218 | + 'Authorization' => 'Basic '.base64_encode($this->_access_key.':'), |
|
| 219 | 219 | 'Accept'=>'application/json' |
| 220 | 220 | ) |
| 221 | 221 | ); |
| 222 | 222 | |
| 223 | 223 | $response = wp_remote_get( |
| 224 | - $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
| 224 | + $this->_mijireh_api_orders_url.'/'.$payment->txn_id_chq_nmbr(), |
|
| 225 | 225 | $request_args |
| 226 | 226 | ); |
| 227 | 227 | |
| 228 | 228 | $this->log( |
| 229 | - array( 'get payment status request_args' => $request_args, 'response' => $response ), |
|
| 229 | + array('get payment status request_args' => $request_args, 'response' => $response), |
|
| 230 | 230 | $payment |
| 231 | 231 | ); |
| 232 | 232 | // validate response |
| 233 | - $response_body = isset( $response[ 'body' ] ) ? json_decode( $response[ 'body' ] ) : ''; |
|
| 234 | - if( $response && $response_body ){ |
|
| 235 | - switch( $response_body->status ){ |
|
| 233 | + $response_body = isset($response['body']) ? json_decode($response['body']) : ''; |
|
| 234 | + if ($response && $response_body) { |
|
| 235 | + switch ($response_body->status) { |
|
| 236 | 236 | case 'paid': |
| 237 | 237 | $payment->set_status($this->_pay_model->approved_status()); |
| 238 | 238 | break; |
@@ -244,9 +244,9 @@ discard block |
||
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | } else { |
| 247 | - $payment->set_gateway_response( __( 'Response from Mijireh could not be understood.', 'event_espresso' ) ); |
|
| 248 | - $payment->set_details( $response ); |
|
| 249 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
| 247 | + $payment->set_gateway_response(__('Response from Mijireh could not be understood.', 'event_espresso')); |
|
| 248 | + $payment->set_details($response); |
|
| 249 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 250 | 250 | } |
| 251 | 251 | // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage |
| 252 | 252 | // $payment->set_status( $this->_pay_model->pending_status() ); |
@@ -18,27 +18,27 @@ |
||
| 18 | 18 | abstract class FormatterBase implements FormatterInterface |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Recursively applies the formatting to all VALUES in this multi-dimensional array |
|
| 23 | - * |
|
| 24 | - * @param array $input |
|
| 25 | - * @return array |
|
| 26 | - * @throws InvalidDataTypeException if $input is not an array |
|
| 27 | - */ |
|
| 28 | - public function formatArray($input) |
|
| 29 | - { |
|
| 30 | - if (! is_array($input)) { |
|
| 31 | - throw new InvalidDataTypeException('input', $input, 'array'); |
|
| 32 | - } |
|
| 33 | - //we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
|
| 34 | - $formatter = $this; |
|
| 35 | - array_walk_recursive( |
|
| 36 | - $input, |
|
| 37 | - function (&$value, $key) use ($formatter) { |
|
| 38 | - $value = $formatter->format($value); |
|
| 39 | - } |
|
| 40 | - ); |
|
| 41 | - return $input; |
|
| 42 | - }} |
|
| 21 | + /** |
|
| 22 | + * Recursively applies the formatting to all VALUES in this multi-dimensional array |
|
| 23 | + * |
|
| 24 | + * @param array $input |
|
| 25 | + * @return array |
|
| 26 | + * @throws InvalidDataTypeException if $input is not an array |
|
| 27 | + */ |
|
| 28 | + public function formatArray($input) |
|
| 29 | + { |
|
| 30 | + if (! is_array($input)) { |
|
| 31 | + throw new InvalidDataTypeException('input', $input, 'array'); |
|
| 32 | + } |
|
| 33 | + //we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
|
| 34 | + $formatter = $this; |
|
| 35 | + array_walk_recursive( |
|
| 36 | + $input, |
|
| 37 | + function (&$value, $key) use ($formatter) { |
|
| 38 | + $value = $formatter->format($value); |
|
| 39 | + } |
|
| 40 | + ); |
|
| 41 | + return $input; |
|
| 42 | + }} |
|
| 43 | 43 | // End of file FormatterBase.php |
| 44 | 44 | // Location: core\services\formatters/FormatterBase.php |
| 45 | 45 | \ No newline at end of file |
@@ -27,14 +27,14 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | public function formatArray($input) |
| 29 | 29 | { |
| 30 | - if (! is_array($input)) { |
|
| 30 | + if ( ! is_array($input)) { |
|
| 31 | 31 | throw new InvalidDataTypeException('input', $input, 'array'); |
| 32 | 32 | } |
| 33 | 33 | //we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
| 34 | 34 | $formatter = $this; |
| 35 | 35 | array_walk_recursive( |
| 36 | 36 | $input, |
| 37 | - function (&$value, $key) use ($formatter) { |
|
| 37 | + function(&$value, $key) use ($formatter) { |
|
| 38 | 38 | $value = $formatter->format($value); |
| 39 | 39 | } |
| 40 | 40 | ); |
@@ -18,807 +18,807 @@ |
||
| 18 | 18 | class EED_Core_Rest_Api extends \EED_Module |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - const ee_api_namespace = 'ee/v'; |
|
| 21 | + const ee_api_namespace = 'ee/v'; |
|
| 22 | 22 | |
| 23 | - const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
| 23 | + const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
| 24 | 24 | |
| 25 | - const saved_routes_option_names = 'ee_core_routes'; |
|
| 25 | + const saved_routes_option_names = 'ee_core_routes'; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * string used in _links response bodies to make them globally unique. |
|
| 29 | - * |
|
| 30 | - * @see http://v2.wp-api.org/extending/linking/ |
|
| 31 | - */ |
|
| 32 | - const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
| 27 | + /** |
|
| 28 | + * string used in _links response bodies to make them globally unique. |
|
| 29 | + * |
|
| 30 | + * @see http://v2.wp-api.org/extending/linking/ |
|
| 31 | + */ |
|
| 32 | + const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var Calculated_Model_Fields |
|
| 36 | - */ |
|
| 37 | - protected static $_field_calculator = null; |
|
| 34 | + /** |
|
| 35 | + * @var Calculated_Model_Fields |
|
| 36 | + */ |
|
| 37 | + protected static $_field_calculator = null; |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @return EED_Core_Rest_Api |
|
| 43 | - */ |
|
| 44 | - public static function instance() |
|
| 45 | - { |
|
| 46 | - self::$_field_calculator = new Calculated_Model_Fields(); |
|
| 47 | - return parent::get_instance(__CLASS__); |
|
| 48 | - } |
|
| 41 | + /** |
|
| 42 | + * @return EED_Core_Rest_Api |
|
| 43 | + */ |
|
| 44 | + public static function instance() |
|
| 45 | + { |
|
| 46 | + self::$_field_calculator = new Calculated_Model_Fields(); |
|
| 47 | + return parent::get_instance(__CLASS__); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 54 | - * |
|
| 55 | - * @access public |
|
| 56 | - * @return void |
|
| 57 | - */ |
|
| 58 | - public static function set_hooks() |
|
| 59 | - { |
|
| 60 | - self::set_hooks_both(); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 67 | - * |
|
| 68 | - * @access public |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - public static function set_hooks_admin() |
|
| 72 | - { |
|
| 73 | - self::set_hooks_both(); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - public static function set_hooks_both() |
|
| 79 | - { |
|
| 80 | - add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10); |
|
| 81 | - add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5); |
|
| 82 | - add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2); |
|
| 83 | - add_filter('rest_index', |
|
| 84 | - array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index')); |
|
| 85 | - EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * sets up hooks which only need to be included as part of REST API requests; |
|
| 92 | - * other requests like to the frontend or admin etc don't need them |
|
| 93 | - */ |
|
| 94 | - public static function set_hooks_rest_api() |
|
| 95 | - { |
|
| 96 | - //set hooks which account for changes made to the API |
|
| 97 | - EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * public wrapper of _set_hooks_for_changes. |
|
| 104 | - * Loads all the hooks which make requests to old versions of the API |
|
| 105 | - * appear the same as they always did |
|
| 106 | - */ |
|
| 107 | - public static function set_hooks_for_changes() |
|
| 108 | - { |
|
| 109 | - self::_set_hooks_for_changes(); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Loads all the hooks which make requests to old versions of the API |
|
| 120 | - * appear the same as they always did |
|
| 121 | - */ |
|
| 122 | - protected static function _set_hooks_for_changes() |
|
| 123 | - { |
|
| 124 | - $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false); |
|
| 125 | - foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
| 126 | - //ignore the base parent class |
|
| 127 | - if ($classname_in_namespace === 'Changes_In_Base') { |
|
| 128 | - continue; |
|
| 129 | - } |
|
| 130 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
| 131 | - if (class_exists($full_classname)) { |
|
| 132 | - $instance_of_class = new $full_classname; |
|
| 133 | - if ($instance_of_class instanceof Changes_In_Base) { |
|
| 134 | - $instance_of_class->set_hooks(); |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
| 144 | - * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
| 145 | - */ |
|
| 146 | - public static function register_routes() |
|
| 147 | - { |
|
| 148 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
| 149 | - foreach ($relative_urls as $endpoint => $routes) { |
|
| 150 | - foreach ($routes as $route) { |
|
| 151 | - $route_args = array( |
|
| 152 | - array( |
|
| 153 | - 'callback' => $route['callback'], |
|
| 154 | - 'methods' => $route['methods'], |
|
| 155 | - 'args' => isset($route['args']) ? $route['args'] : array(), |
|
| 156 | - ) |
|
| 157 | - ); |
|
| 158 | - if (isset($route['schema_callback'])) { |
|
| 159 | - $model_name = isset($route['schema_callback'][0]) |
|
| 160 | - ? $route['schema_callback'][0] |
|
| 161 | - : ''; |
|
| 162 | - $version = isset( $route['schema_callback'][1]) |
|
| 163 | - ? $route['schema_callback'][1] |
|
| 164 | - : ''; |
|
| 165 | - if (! empty($model_name) && ! empty($version)) { |
|
| 166 | - $route_args['schema'] = function () use ($model_name, $version) { |
|
| 167 | - return ModelRead::handle_schema_request( |
|
| 168 | - $model_name, |
|
| 169 | - $version |
|
| 170 | - ); |
|
| 171 | - }; |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - register_rest_route( |
|
| 175 | - $namespace, |
|
| 176 | - $endpoint, |
|
| 177 | - $route_args |
|
| 178 | - ); |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Checks if there was a version change or something that merits invalidating the cached |
|
| 188 | - * route data. If so, invalidates the cached route data so that it gets refreshed |
|
| 189 | - * next time the WP API is used |
|
| 190 | - */ |
|
| 191 | - public static function invalidate_cached_route_data_on_version_change() |
|
| 192 | - { |
|
| 193 | - if (EE_System::instance()->detect_req_type() != EE_System::req_type_normal) { |
|
| 194 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
| 195 | - } |
|
| 196 | - foreach (EE_Registry::instance()->addons as $addon) { |
|
| 197 | - if ($addon instanceof EE_Addon && $addon->detect_req_type() != EE_System::req_type_normal) { |
|
| 198 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Removes the cached route data so it will get refreshed next time the WP API is used |
|
| 207 | - */ |
|
| 208 | - public static function invalidate_cached_route_data() |
|
| 209 | - { |
|
| 210 | - //delete the saved EE REST API routes |
|
| 211 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
| 212 | - delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Gets the EE route data |
|
| 220 | - * |
|
| 221 | - * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
| 222 | - * @type string|array $callback |
|
| 223 | - * @type string $methods |
|
| 224 | - * @type boolean $hidden_endpoint |
|
| 225 | - * } |
|
| 226 | - */ |
|
| 227 | - public static function get_ee_route_data() |
|
| 228 | - { |
|
| 229 | - $ee_routes = array(); |
|
| 230 | - foreach (self::versions_served() as $version => $hidden_endpoints) { |
|
| 231 | - $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version($version, |
|
| 232 | - $hidden_endpoints); |
|
| 233 | - } |
|
| 234 | - return $ee_routes; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Gets the EE route data from the wp options if it exists already, |
|
| 241 | - * otherwise re-generates it and saves it to the option |
|
| 242 | - * |
|
| 243 | - * @param string $version |
|
| 244 | - * @param boolean $hidden_endpoints |
|
| 245 | - * @return array |
|
| 246 | - */ |
|
| 247 | - protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 248 | - { |
|
| 249 | - $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
| 250 | - if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
| 251 | - $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
| 252 | - } |
|
| 253 | - return $ee_routes; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Saves the EE REST API route data to a wp option and returns it |
|
| 260 | - * |
|
| 261 | - * @param string $version |
|
| 262 | - * @param boolean $hidden_endpoints |
|
| 263 | - * @return mixed|null|void |
|
| 264 | - */ |
|
| 265 | - protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 266 | - { |
|
| 267 | - $instance = self::instance(); |
|
| 268 | - $routes = apply_filters( |
|
| 269 | - 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
| 270 | - array_replace_recursive( |
|
| 271 | - $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
| 272 | - $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
| 273 | - $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
| 274 | - $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
| 275 | - ) |
|
| 276 | - ); |
|
| 277 | - $option_name = self::saved_routes_option_names . $version; |
|
| 278 | - if (get_option($option_name)) { |
|
| 279 | - update_option($option_name, $routes, true); |
|
| 280 | - } else { |
|
| 281 | - add_option($option_name, $routes, null, 'no'); |
|
| 282 | - } |
|
| 283 | - return $routes; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Calculates all the EE routes and saves it to a wordpress option so we don't |
|
| 290 | - * need to calculate it on every request |
|
| 291 | - * |
|
| 292 | - * @deprecated since version 4.9.1 |
|
| 293 | - * @return void |
|
| 294 | - */ |
|
| 295 | - public static function save_ee_routes() |
|
| 296 | - { |
|
| 297 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 298 | - $instance = self::instance(); |
|
| 299 | - $routes = apply_filters( |
|
| 300 | - 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
| 301 | - array_replace_recursive( |
|
| 302 | - $instance->_register_config_routes(), |
|
| 303 | - $instance->_register_meta_routes(), |
|
| 304 | - $instance->_register_model_routes(), |
|
| 305 | - $instance->_register_rpc_routes() |
|
| 306 | - ) |
|
| 307 | - ); |
|
| 308 | - update_option(self::saved_routes_option_names, $routes, true); |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Gets all the route information relating to EE models |
|
| 316 | - * |
|
| 317 | - * @return array @see get_ee_route_data |
|
| 318 | - * @deprecated since version 4.9.1 |
|
| 319 | - */ |
|
| 320 | - protected function _register_model_routes() |
|
| 321 | - { |
|
| 322 | - $model_routes = array(); |
|
| 323 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 324 | - $model_routes[EED_Core_Rest_Api::ee_api_namespace |
|
| 325 | - . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
| 326 | - } |
|
| 327 | - return $model_routes; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Gets the route data for EE models in the specified version |
|
| 334 | - * |
|
| 335 | - * @param string $version |
|
| 336 | - * @param boolean $hidden_endpoint |
|
| 337 | - * @return array |
|
| 338 | - */ |
|
| 339 | - protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
| 340 | - { |
|
| 341 | - $model_version_info = new Model_Version_Info($version); |
|
| 342 | - $models_to_register = apply_filters( |
|
| 343 | - 'FHEE__EED_Core_REST_API___register_model_routes', |
|
| 344 | - $model_version_info->models_for_requested_version() |
|
| 345 | - ); |
|
| 346 | - //let's not bother having endpoints for extra metas |
|
| 347 | - unset($models_to_register['Extra_Meta']); |
|
| 348 | - unset($models_to_register['Extra_Join']); |
|
| 349 | - $model_routes = array(); |
|
| 350 | - foreach ($models_to_register as $model_name => $model_classname) { |
|
| 351 | - $model = \EE_Registry::instance()->load_model($model_name); |
|
| 352 | - |
|
| 353 | - //if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
| 354 | - if (! $model instanceof EEM_Base) { |
|
| 355 | - continue; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - //yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
| 359 | - $plural_model_route = EEH_Inflector::pluralize_and_lower($model_name); |
|
| 360 | - $singular_model_route = $plural_model_route . '/(?P<id>\d+)'; |
|
| 361 | - $model_routes[$plural_model_route] = array( |
|
| 362 | - array( |
|
| 363 | - 'callback' => array( |
|
| 364 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 365 | - 'handle_request_get_all', |
|
| 366 | - ), |
|
| 367 | - 'methods' => WP_REST_Server::READABLE, |
|
| 368 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 369 | - 'args' => $this->_get_read_query_params($model, $version), |
|
| 370 | - '_links' => array( |
|
| 371 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
| 372 | - ), |
|
| 373 | - 'schema_callback' => array($model_name, $version) |
|
| 374 | - ), |
|
| 375 | - // array( |
|
| 376 | - // 'callback' => array( |
|
| 377 | - // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 378 | - // 'handle_request_create_one' ), |
|
| 379 | - // 'methods' => WP_REST_Server::CREATABLE, |
|
| 380 | - // 'hidden_endpoint' => $hidden_endpoint |
|
| 381 | - // ) |
|
| 382 | - ); |
|
| 383 | - $model_routes[$singular_model_route] = array( |
|
| 384 | - array( |
|
| 385 | - 'callback' => array( |
|
| 386 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 387 | - 'handle_request_get_one', |
|
| 388 | - ), |
|
| 389 | - 'methods' => WP_REST_Server::READABLE, |
|
| 390 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 391 | - 'args' => $this->_get_response_selection_query_params($model, $version), |
|
| 392 | - ), |
|
| 393 | - // array( |
|
| 394 | - // 'callback' => array( |
|
| 395 | - // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 396 | - // 'handle_request_edit_one' ), |
|
| 397 | - // 'methods' => WP_REST_Server::EDITABLE, |
|
| 398 | - // 'hidden_endpoint' => $hidden_endpoint |
|
| 399 | - // ), |
|
| 400 | - ); |
|
| 401 | - //@todo: also handle DELETE for a single item |
|
| 402 | - foreach ($model_version_info->relation_settings($model) as $relation_name => $relation_obj) { |
|
| 403 | - $related_model_name_endpoint_part = ModelRead::get_related_entity_name( |
|
| 404 | - $relation_name, |
|
| 405 | - $relation_obj |
|
| 406 | - ); |
|
| 407 | - $model_routes[$singular_model_route . '/' . $related_model_name_endpoint_part] = array( |
|
| 408 | - array( |
|
| 409 | - 'callback' => array( |
|
| 410 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 411 | - 'handle_request_get_related', |
|
| 412 | - ), |
|
| 413 | - 'methods' => WP_REST_Server::READABLE, |
|
| 414 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 415 | - 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
| 416 | - ), |
|
| 417 | - // array( |
|
| 418 | - // 'callback' => array( |
|
| 419 | - // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 420 | - // 'handle_request_create_or_update_related' ), |
|
| 421 | - // 'methods' => WP_REST_Server::EDITABLE, |
|
| 422 | - // 'hidden_endpoint' => $hidden_endpoint |
|
| 423 | - // ) |
|
| 424 | - ); |
|
| 425 | - //@todo: handle delete related and possibly remove relation (not sure hwo to distinguish) |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - return $model_routes; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
| 435 | - * routes that don't conform to the traditional REST CRUD-style). |
|
| 436 | - * |
|
| 437 | - * @deprecated since 4.9.1 |
|
| 438 | - */ |
|
| 439 | - protected function _register_rpc_routes() |
|
| 440 | - { |
|
| 441 | - $routes = array(); |
|
| 442 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 443 | - $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version($version, |
|
| 444 | - $hidden_endpoint); |
|
| 445 | - } |
|
| 446 | - return $routes; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @param string $version |
|
| 453 | - * @param boolean $hidden_endpoint |
|
| 454 | - * @return array |
|
| 455 | - */ |
|
| 456 | - protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
| 457 | - { |
|
| 458 | - $this_versions_routes = array(); |
|
| 459 | - //checkin endpoint |
|
| 460 | - $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array( |
|
| 461 | - array( |
|
| 462 | - 'callback' => array( |
|
| 463 | - 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
| 464 | - 'handle_request_toggle_checkin', |
|
| 465 | - ), |
|
| 466 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 467 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 468 | - 'args' => array( |
|
| 469 | - 'force' => array( |
|
| 470 | - 'required' => false, |
|
| 471 | - 'default' => false, |
|
| 472 | - 'description' => __('Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
| 473 | - 'event_espresso'), |
|
| 474 | - ), |
|
| 475 | - ), |
|
| 476 | - ), |
|
| 477 | - ); |
|
| 478 | - return apply_filters( |
|
| 479 | - 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
| 480 | - $this_versions_routes, |
|
| 481 | - $version, |
|
| 482 | - $hidden_endpoint |
|
| 483 | - ); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * Gets the query params that can be used when request one or many |
|
| 490 | - * |
|
| 491 | - * @param EEM_Base $model |
|
| 492 | - * @param string $version |
|
| 493 | - * @return array |
|
| 494 | - */ |
|
| 495 | - protected function _get_response_selection_query_params(\EEM_Base $model, $version) |
|
| 496 | - { |
|
| 497 | - return apply_filters( |
|
| 498 | - 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
| 499 | - array( |
|
| 500 | - 'include' => array( |
|
| 501 | - 'required' => false, |
|
| 502 | - 'default' => '*', |
|
| 503 | - ), |
|
| 504 | - 'calculate' => array( |
|
| 505 | - 'required' => false, |
|
| 506 | - 'default' => '', |
|
| 507 | - 'enum' => self::$_field_calculator->retrieve_calculated_fields_for_model($model), |
|
| 508 | - ), |
|
| 509 | - ), |
|
| 510 | - $model, |
|
| 511 | - $version |
|
| 512 | - ); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * Gets info about reading query params that are acceptable |
|
| 519 | - * |
|
| 520 | - * @param \EEM_Base $model eg 'Event' or 'Venue' |
|
| 521 | - * @param string $version |
|
| 522 | - * @return array describing the args acceptable when querying this model |
|
| 523 | - * @throws \EE_Error |
|
| 524 | - */ |
|
| 525 | - protected function _get_read_query_params(\EEM_Base $model, $version) |
|
| 526 | - { |
|
| 527 | - $default_orderby = array(); |
|
| 528 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
| 529 | - $default_orderby[$key_field->get_name()] = 'ASC'; |
|
| 530 | - } |
|
| 531 | - return array_merge( |
|
| 532 | - $this->_get_response_selection_query_params($model, $version), |
|
| 533 | - array( |
|
| 534 | - 'where' => array( |
|
| 535 | - 'required' => false, |
|
| 536 | - 'default' => array(), |
|
| 537 | - ), |
|
| 538 | - 'limit' => array( |
|
| 539 | - 'required' => false, |
|
| 540 | - 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
| 541 | - ), |
|
| 542 | - 'order_by' => array( |
|
| 543 | - 'required' => false, |
|
| 544 | - 'default' => $default_orderby, |
|
| 545 | - ), |
|
| 546 | - 'group_by' => array( |
|
| 547 | - 'required' => false, |
|
| 548 | - 'default' => null, |
|
| 549 | - ), |
|
| 550 | - 'having' => array( |
|
| 551 | - 'required' => false, |
|
| 552 | - 'default' => null, |
|
| 553 | - ), |
|
| 554 | - 'caps' => array( |
|
| 555 | - 'required' => false, |
|
| 556 | - 'default' => EEM_Base::caps_read, |
|
| 557 | - ), |
|
| 558 | - ) |
|
| 559 | - ); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * Gets routes for the config |
|
| 566 | - * |
|
| 567 | - * @return array @see _register_model_routes |
|
| 568 | - * @deprecated since version 4.9.1 |
|
| 569 | - */ |
|
| 570 | - protected function _register_config_routes() |
|
| 571 | - { |
|
| 572 | - $config_routes = array(); |
|
| 573 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 574 | - $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version($version, |
|
| 575 | - $hidden_endpoint); |
|
| 576 | - } |
|
| 577 | - return $config_routes; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * Gets routes for the config for the specified version |
|
| 584 | - * |
|
| 585 | - * @param string $version |
|
| 586 | - * @param boolean $hidden_endpoint |
|
| 587 | - * @return array |
|
| 588 | - */ |
|
| 589 | - protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
| 590 | - { |
|
| 591 | - return array( |
|
| 592 | - 'config' => array( |
|
| 593 | - array( |
|
| 594 | - 'callback' => array( |
|
| 595 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 596 | - 'handle_request', |
|
| 597 | - ), |
|
| 598 | - 'methods' => WP_REST_Server::READABLE, |
|
| 599 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 600 | - ), |
|
| 601 | - ), |
|
| 602 | - 'site_info' => array( |
|
| 603 | - array( |
|
| 604 | - 'callback' => array( |
|
| 605 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 606 | - 'handle_request_site_info', |
|
| 607 | - ), |
|
| 608 | - 'methods' => WP_REST_Server::READABLE, |
|
| 609 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 610 | - ), |
|
| 611 | - ), |
|
| 612 | - ); |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Gets the meta info routes |
|
| 619 | - * |
|
| 620 | - * @return array @see _register_model_routes |
|
| 621 | - * @deprecated since version 4.9.1 |
|
| 622 | - */ |
|
| 623 | - protected function _register_meta_routes() |
|
| 624 | - { |
|
| 625 | - $meta_routes = array(); |
|
| 626 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 627 | - $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version($version, |
|
| 628 | - $hidden_endpoint); |
|
| 629 | - } |
|
| 630 | - return $meta_routes; |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * @param string $version |
|
| 637 | - * @param boolean $hidden_endpoint |
|
| 638 | - * @return array |
|
| 639 | - */ |
|
| 640 | - protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
| 641 | - { |
|
| 642 | - return array( |
|
| 643 | - 'resources' => array( |
|
| 644 | - array( |
|
| 645 | - 'callback' => array( |
|
| 646 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
| 647 | - 'handle_request_models_meta', |
|
| 648 | - ), |
|
| 649 | - 'methods' => WP_REST_Server::READABLE, |
|
| 650 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 651 | - ), |
|
| 652 | - ), |
|
| 653 | - ); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - |
|
| 658 | - /** |
|
| 659 | - * Tries to hide old 4.6 endpoints from the |
|
| 660 | - * |
|
| 661 | - * @param array $route_data |
|
| 662 | - * @return array |
|
| 663 | - */ |
|
| 664 | - public static function hide_old_endpoints($route_data) |
|
| 665 | - { |
|
| 666 | - //allow API clients to override which endpoints get hidden, in case |
|
| 667 | - //they want to discover particular endpoints |
|
| 668 | - //also, we don't have access to the request so we have to just grab it from the superglobal |
|
| 669 | - $force_show_ee_namespace = ltrim( |
|
| 670 | - EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''), |
|
| 671 | - '/' |
|
| 672 | - ); |
|
| 673 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
| 674 | - foreach ($relative_urls as $endpoint => $routes) { |
|
| 675 | - foreach ($routes as $route) { |
|
| 676 | - //by default, hide "hidden_endpoint"s, unless the request indicates |
|
| 677 | - //to $force_show_ee_namespace, in which case only show that one |
|
| 678 | - //namespace's endpoints (and hide all others) |
|
| 679 | - if (($route['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
| 680 | - || ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
| 681 | - ) { |
|
| 682 | - $full_route = '/' . ltrim($namespace, '/') . '/' . ltrim($endpoint, '/'); |
|
| 683 | - unset($route_data[$full_route]); |
|
| 684 | - } |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - return $route_data; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * Returns an array describing which versions of core support serving requests for. |
|
| 695 | - * Keys are core versions' major and minor version, and values are the |
|
| 696 | - * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
| 697 | - * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
| 698 | - * the answers table entirely, in which case it would be very difficult for |
|
| 699 | - * it to serve 4.6-style responses. |
|
| 700 | - * Versions of core that are missing from this array are unknowns. |
|
| 701 | - * previous ver |
|
| 702 | - * |
|
| 703 | - * @return array |
|
| 704 | - */ |
|
| 705 | - public static function version_compatibilities() |
|
| 706 | - { |
|
| 707 | - return apply_filters( |
|
| 708 | - 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
| 709 | - array( |
|
| 710 | - '4.8.29' => '4.8.29', |
|
| 711 | - '4.8.33' => '4.8.29', |
|
| 712 | - '4.8.34' => '4.8.29', |
|
| 713 | - '4.8.36' => '4.8.29', |
|
| 714 | - ) |
|
| 715 | - ); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - |
|
| 719 | - |
|
| 720 | - /** |
|
| 721 | - * Gets the latest API version served. Eg if there |
|
| 722 | - * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
| 723 | - * we are on core version 4.8.34, it will return the string "4.8.32" |
|
| 724 | - * |
|
| 725 | - * @return string |
|
| 726 | - */ |
|
| 727 | - public static function latest_rest_api_version() |
|
| 728 | - { |
|
| 729 | - $versions_served = \EED_Core_Rest_Api::versions_served(); |
|
| 730 | - $versions_served_keys = array_keys($versions_served); |
|
| 731 | - return end($versions_served_keys); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - |
|
| 736 | - /** |
|
| 737 | - * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
| 738 | - * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
| 739 | - * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
| 740 | - * We also indicate whether or not this version should be put in the index or not |
|
| 741 | - * |
|
| 742 | - * @return array keys are API version numbers (just major and minor numbers), and values |
|
| 743 | - * are whether or not they should be hidden |
|
| 744 | - */ |
|
| 745 | - public static function versions_served() |
|
| 746 | - { |
|
| 747 | - $versions_served = array(); |
|
| 748 | - $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
| 749 | - $lowest_compatible_version = end($possibly_served_versions); |
|
| 750 | - reset($possibly_served_versions); |
|
| 751 | - $versions_served_historically = array_keys($possibly_served_versions); |
|
| 752 | - $latest_version = end($versions_served_historically); |
|
| 753 | - reset($versions_served_historically); |
|
| 754 | - //for each version of core we have ever served: |
|
| 755 | - foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
| 756 | - //if it's not above the current core version, and it's compatible with the current version of core |
|
| 757 | - if ($key_versioned_endpoint == $latest_version) { |
|
| 758 | - //don't hide the latest version in the index |
|
| 759 | - $versions_served[$key_versioned_endpoint] = false; |
|
| 760 | - } else if ( |
|
| 761 | - $key_versioned_endpoint < EED_Core_Rest_Api::core_version() |
|
| 762 | - && $key_versioned_endpoint >= $lowest_compatible_version |
|
| 763 | - ) { |
|
| 764 | - //include, but hide, previous versions which are still supported |
|
| 765 | - $versions_served[$key_versioned_endpoint] = true; |
|
| 766 | - } elseif ( |
|
| 767 | - apply_filters( |
|
| 768 | - 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
| 769 | - false, |
|
| 770 | - $possibly_served_versions |
|
| 771 | - ) |
|
| 772 | - ) { |
|
| 773 | - //if a version is no longer supported, don't include it in index or list of versions served |
|
| 774 | - $versions_served[$key_versioned_endpoint] = true; |
|
| 775 | - } |
|
| 776 | - } |
|
| 777 | - return $versions_served; |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - |
|
| 781 | - |
|
| 782 | - /** |
|
| 783 | - * Gets the major and minor version of EE core's version string |
|
| 784 | - * |
|
| 785 | - * @return string |
|
| 786 | - */ |
|
| 787 | - public static function core_version() |
|
| 788 | - { |
|
| 789 | - return apply_filters('FHEE__EED_Core_REST_API__core_version', |
|
| 790 | - implode('.', array_slice(explode('.', espresso_version()), 0, 3))); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - |
|
| 795 | - /** |
|
| 796 | - * Gets the default limit that should be used when querying for resources |
|
| 797 | - * |
|
| 798 | - * @return int |
|
| 799 | - */ |
|
| 800 | - public static function get_default_query_limit() |
|
| 801 | - { |
|
| 802 | - //we actually don't use a const because we want folks to always use |
|
| 803 | - //this method, not the const directly |
|
| 804 | - return apply_filters( |
|
| 805 | - 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
| 806 | - 50 |
|
| 807 | - ); |
|
| 808 | - } |
|
| 809 | - |
|
| 810 | - |
|
| 811 | - |
|
| 812 | - /** |
|
| 813 | - * run - initial module setup |
|
| 814 | - * |
|
| 815 | - * @access public |
|
| 816 | - * @param WP $WP |
|
| 817 | - * @return void |
|
| 818 | - */ |
|
| 819 | - public function run($WP) |
|
| 820 | - { |
|
| 821 | - } |
|
| 52 | + /** |
|
| 53 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 54 | + * |
|
| 55 | + * @access public |
|
| 56 | + * @return void |
|
| 57 | + */ |
|
| 58 | + public static function set_hooks() |
|
| 59 | + { |
|
| 60 | + self::set_hooks_both(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 67 | + * |
|
| 68 | + * @access public |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + public static function set_hooks_admin() |
|
| 72 | + { |
|
| 73 | + self::set_hooks_both(); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + public static function set_hooks_both() |
|
| 79 | + { |
|
| 80 | + add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10); |
|
| 81 | + add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5); |
|
| 82 | + add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2); |
|
| 83 | + add_filter('rest_index', |
|
| 84 | + array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index')); |
|
| 85 | + EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * sets up hooks which only need to be included as part of REST API requests; |
|
| 92 | + * other requests like to the frontend or admin etc don't need them |
|
| 93 | + */ |
|
| 94 | + public static function set_hooks_rest_api() |
|
| 95 | + { |
|
| 96 | + //set hooks which account for changes made to the API |
|
| 97 | + EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * public wrapper of _set_hooks_for_changes. |
|
| 104 | + * Loads all the hooks which make requests to old versions of the API |
|
| 105 | + * appear the same as they always did |
|
| 106 | + */ |
|
| 107 | + public static function set_hooks_for_changes() |
|
| 108 | + { |
|
| 109 | + self::_set_hooks_for_changes(); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Loads all the hooks which make requests to old versions of the API |
|
| 120 | + * appear the same as they always did |
|
| 121 | + */ |
|
| 122 | + protected static function _set_hooks_for_changes() |
|
| 123 | + { |
|
| 124 | + $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false); |
|
| 125 | + foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
| 126 | + //ignore the base parent class |
|
| 127 | + if ($classname_in_namespace === 'Changes_In_Base') { |
|
| 128 | + continue; |
|
| 129 | + } |
|
| 130 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
| 131 | + if (class_exists($full_classname)) { |
|
| 132 | + $instance_of_class = new $full_classname; |
|
| 133 | + if ($instance_of_class instanceof Changes_In_Base) { |
|
| 134 | + $instance_of_class->set_hooks(); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
| 144 | + * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
| 145 | + */ |
|
| 146 | + public static function register_routes() |
|
| 147 | + { |
|
| 148 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
| 149 | + foreach ($relative_urls as $endpoint => $routes) { |
|
| 150 | + foreach ($routes as $route) { |
|
| 151 | + $route_args = array( |
|
| 152 | + array( |
|
| 153 | + 'callback' => $route['callback'], |
|
| 154 | + 'methods' => $route['methods'], |
|
| 155 | + 'args' => isset($route['args']) ? $route['args'] : array(), |
|
| 156 | + ) |
|
| 157 | + ); |
|
| 158 | + if (isset($route['schema_callback'])) { |
|
| 159 | + $model_name = isset($route['schema_callback'][0]) |
|
| 160 | + ? $route['schema_callback'][0] |
|
| 161 | + : ''; |
|
| 162 | + $version = isset( $route['schema_callback'][1]) |
|
| 163 | + ? $route['schema_callback'][1] |
|
| 164 | + : ''; |
|
| 165 | + if (! empty($model_name) && ! empty($version)) { |
|
| 166 | + $route_args['schema'] = function () use ($model_name, $version) { |
|
| 167 | + return ModelRead::handle_schema_request( |
|
| 168 | + $model_name, |
|
| 169 | + $version |
|
| 170 | + ); |
|
| 171 | + }; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + register_rest_route( |
|
| 175 | + $namespace, |
|
| 176 | + $endpoint, |
|
| 177 | + $route_args |
|
| 178 | + ); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Checks if there was a version change or something that merits invalidating the cached |
|
| 188 | + * route data. If so, invalidates the cached route data so that it gets refreshed |
|
| 189 | + * next time the WP API is used |
|
| 190 | + */ |
|
| 191 | + public static function invalidate_cached_route_data_on_version_change() |
|
| 192 | + { |
|
| 193 | + if (EE_System::instance()->detect_req_type() != EE_System::req_type_normal) { |
|
| 194 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
| 195 | + } |
|
| 196 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
| 197 | + if ($addon instanceof EE_Addon && $addon->detect_req_type() != EE_System::req_type_normal) { |
|
| 198 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Removes the cached route data so it will get refreshed next time the WP API is used |
|
| 207 | + */ |
|
| 208 | + public static function invalidate_cached_route_data() |
|
| 209 | + { |
|
| 210 | + //delete the saved EE REST API routes |
|
| 211 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
| 212 | + delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Gets the EE route data |
|
| 220 | + * |
|
| 221 | + * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
| 222 | + * @type string|array $callback |
|
| 223 | + * @type string $methods |
|
| 224 | + * @type boolean $hidden_endpoint |
|
| 225 | + * } |
|
| 226 | + */ |
|
| 227 | + public static function get_ee_route_data() |
|
| 228 | + { |
|
| 229 | + $ee_routes = array(); |
|
| 230 | + foreach (self::versions_served() as $version => $hidden_endpoints) { |
|
| 231 | + $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version($version, |
|
| 232 | + $hidden_endpoints); |
|
| 233 | + } |
|
| 234 | + return $ee_routes; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Gets the EE route data from the wp options if it exists already, |
|
| 241 | + * otherwise re-generates it and saves it to the option |
|
| 242 | + * |
|
| 243 | + * @param string $version |
|
| 244 | + * @param boolean $hidden_endpoints |
|
| 245 | + * @return array |
|
| 246 | + */ |
|
| 247 | + protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 248 | + { |
|
| 249 | + $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
| 250 | + if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
| 251 | + $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
| 252 | + } |
|
| 253 | + return $ee_routes; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Saves the EE REST API route data to a wp option and returns it |
|
| 260 | + * |
|
| 261 | + * @param string $version |
|
| 262 | + * @param boolean $hidden_endpoints |
|
| 263 | + * @return mixed|null|void |
|
| 264 | + */ |
|
| 265 | + protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 266 | + { |
|
| 267 | + $instance = self::instance(); |
|
| 268 | + $routes = apply_filters( |
|
| 269 | + 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
| 270 | + array_replace_recursive( |
|
| 271 | + $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
| 272 | + $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
| 273 | + $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
| 274 | + $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
| 275 | + ) |
|
| 276 | + ); |
|
| 277 | + $option_name = self::saved_routes_option_names . $version; |
|
| 278 | + if (get_option($option_name)) { |
|
| 279 | + update_option($option_name, $routes, true); |
|
| 280 | + } else { |
|
| 281 | + add_option($option_name, $routes, null, 'no'); |
|
| 282 | + } |
|
| 283 | + return $routes; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Calculates all the EE routes and saves it to a wordpress option so we don't |
|
| 290 | + * need to calculate it on every request |
|
| 291 | + * |
|
| 292 | + * @deprecated since version 4.9.1 |
|
| 293 | + * @return void |
|
| 294 | + */ |
|
| 295 | + public static function save_ee_routes() |
|
| 296 | + { |
|
| 297 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 298 | + $instance = self::instance(); |
|
| 299 | + $routes = apply_filters( |
|
| 300 | + 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
| 301 | + array_replace_recursive( |
|
| 302 | + $instance->_register_config_routes(), |
|
| 303 | + $instance->_register_meta_routes(), |
|
| 304 | + $instance->_register_model_routes(), |
|
| 305 | + $instance->_register_rpc_routes() |
|
| 306 | + ) |
|
| 307 | + ); |
|
| 308 | + update_option(self::saved_routes_option_names, $routes, true); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Gets all the route information relating to EE models |
|
| 316 | + * |
|
| 317 | + * @return array @see get_ee_route_data |
|
| 318 | + * @deprecated since version 4.9.1 |
|
| 319 | + */ |
|
| 320 | + protected function _register_model_routes() |
|
| 321 | + { |
|
| 322 | + $model_routes = array(); |
|
| 323 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 324 | + $model_routes[EED_Core_Rest_Api::ee_api_namespace |
|
| 325 | + . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
| 326 | + } |
|
| 327 | + return $model_routes; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Gets the route data for EE models in the specified version |
|
| 334 | + * |
|
| 335 | + * @param string $version |
|
| 336 | + * @param boolean $hidden_endpoint |
|
| 337 | + * @return array |
|
| 338 | + */ |
|
| 339 | + protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
| 340 | + { |
|
| 341 | + $model_version_info = new Model_Version_Info($version); |
|
| 342 | + $models_to_register = apply_filters( |
|
| 343 | + 'FHEE__EED_Core_REST_API___register_model_routes', |
|
| 344 | + $model_version_info->models_for_requested_version() |
|
| 345 | + ); |
|
| 346 | + //let's not bother having endpoints for extra metas |
|
| 347 | + unset($models_to_register['Extra_Meta']); |
|
| 348 | + unset($models_to_register['Extra_Join']); |
|
| 349 | + $model_routes = array(); |
|
| 350 | + foreach ($models_to_register as $model_name => $model_classname) { |
|
| 351 | + $model = \EE_Registry::instance()->load_model($model_name); |
|
| 352 | + |
|
| 353 | + //if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
| 354 | + if (! $model instanceof EEM_Base) { |
|
| 355 | + continue; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + //yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
| 359 | + $plural_model_route = EEH_Inflector::pluralize_and_lower($model_name); |
|
| 360 | + $singular_model_route = $plural_model_route . '/(?P<id>\d+)'; |
|
| 361 | + $model_routes[$plural_model_route] = array( |
|
| 362 | + array( |
|
| 363 | + 'callback' => array( |
|
| 364 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 365 | + 'handle_request_get_all', |
|
| 366 | + ), |
|
| 367 | + 'methods' => WP_REST_Server::READABLE, |
|
| 368 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 369 | + 'args' => $this->_get_read_query_params($model, $version), |
|
| 370 | + '_links' => array( |
|
| 371 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
| 372 | + ), |
|
| 373 | + 'schema_callback' => array($model_name, $version) |
|
| 374 | + ), |
|
| 375 | + // array( |
|
| 376 | + // 'callback' => array( |
|
| 377 | + // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 378 | + // 'handle_request_create_one' ), |
|
| 379 | + // 'methods' => WP_REST_Server::CREATABLE, |
|
| 380 | + // 'hidden_endpoint' => $hidden_endpoint |
|
| 381 | + // ) |
|
| 382 | + ); |
|
| 383 | + $model_routes[$singular_model_route] = array( |
|
| 384 | + array( |
|
| 385 | + 'callback' => array( |
|
| 386 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 387 | + 'handle_request_get_one', |
|
| 388 | + ), |
|
| 389 | + 'methods' => WP_REST_Server::READABLE, |
|
| 390 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 391 | + 'args' => $this->_get_response_selection_query_params($model, $version), |
|
| 392 | + ), |
|
| 393 | + // array( |
|
| 394 | + // 'callback' => array( |
|
| 395 | + // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 396 | + // 'handle_request_edit_one' ), |
|
| 397 | + // 'methods' => WP_REST_Server::EDITABLE, |
|
| 398 | + // 'hidden_endpoint' => $hidden_endpoint |
|
| 399 | + // ), |
|
| 400 | + ); |
|
| 401 | + //@todo: also handle DELETE for a single item |
|
| 402 | + foreach ($model_version_info->relation_settings($model) as $relation_name => $relation_obj) { |
|
| 403 | + $related_model_name_endpoint_part = ModelRead::get_related_entity_name( |
|
| 404 | + $relation_name, |
|
| 405 | + $relation_obj |
|
| 406 | + ); |
|
| 407 | + $model_routes[$singular_model_route . '/' . $related_model_name_endpoint_part] = array( |
|
| 408 | + array( |
|
| 409 | + 'callback' => array( |
|
| 410 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 411 | + 'handle_request_get_related', |
|
| 412 | + ), |
|
| 413 | + 'methods' => WP_REST_Server::READABLE, |
|
| 414 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 415 | + 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
| 416 | + ), |
|
| 417 | + // array( |
|
| 418 | + // 'callback' => array( |
|
| 419 | + // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 420 | + // 'handle_request_create_or_update_related' ), |
|
| 421 | + // 'methods' => WP_REST_Server::EDITABLE, |
|
| 422 | + // 'hidden_endpoint' => $hidden_endpoint |
|
| 423 | + // ) |
|
| 424 | + ); |
|
| 425 | + //@todo: handle delete related and possibly remove relation (not sure hwo to distinguish) |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + return $model_routes; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
| 435 | + * routes that don't conform to the traditional REST CRUD-style). |
|
| 436 | + * |
|
| 437 | + * @deprecated since 4.9.1 |
|
| 438 | + */ |
|
| 439 | + protected function _register_rpc_routes() |
|
| 440 | + { |
|
| 441 | + $routes = array(); |
|
| 442 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 443 | + $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version($version, |
|
| 444 | + $hidden_endpoint); |
|
| 445 | + } |
|
| 446 | + return $routes; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @param string $version |
|
| 453 | + * @param boolean $hidden_endpoint |
|
| 454 | + * @return array |
|
| 455 | + */ |
|
| 456 | + protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
| 457 | + { |
|
| 458 | + $this_versions_routes = array(); |
|
| 459 | + //checkin endpoint |
|
| 460 | + $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array( |
|
| 461 | + array( |
|
| 462 | + 'callback' => array( |
|
| 463 | + 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
| 464 | + 'handle_request_toggle_checkin', |
|
| 465 | + ), |
|
| 466 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 467 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 468 | + 'args' => array( |
|
| 469 | + 'force' => array( |
|
| 470 | + 'required' => false, |
|
| 471 | + 'default' => false, |
|
| 472 | + 'description' => __('Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
| 473 | + 'event_espresso'), |
|
| 474 | + ), |
|
| 475 | + ), |
|
| 476 | + ), |
|
| 477 | + ); |
|
| 478 | + return apply_filters( |
|
| 479 | + 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
| 480 | + $this_versions_routes, |
|
| 481 | + $version, |
|
| 482 | + $hidden_endpoint |
|
| 483 | + ); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * Gets the query params that can be used when request one or many |
|
| 490 | + * |
|
| 491 | + * @param EEM_Base $model |
|
| 492 | + * @param string $version |
|
| 493 | + * @return array |
|
| 494 | + */ |
|
| 495 | + protected function _get_response_selection_query_params(\EEM_Base $model, $version) |
|
| 496 | + { |
|
| 497 | + return apply_filters( |
|
| 498 | + 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
| 499 | + array( |
|
| 500 | + 'include' => array( |
|
| 501 | + 'required' => false, |
|
| 502 | + 'default' => '*', |
|
| 503 | + ), |
|
| 504 | + 'calculate' => array( |
|
| 505 | + 'required' => false, |
|
| 506 | + 'default' => '', |
|
| 507 | + 'enum' => self::$_field_calculator->retrieve_calculated_fields_for_model($model), |
|
| 508 | + ), |
|
| 509 | + ), |
|
| 510 | + $model, |
|
| 511 | + $version |
|
| 512 | + ); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * Gets info about reading query params that are acceptable |
|
| 519 | + * |
|
| 520 | + * @param \EEM_Base $model eg 'Event' or 'Venue' |
|
| 521 | + * @param string $version |
|
| 522 | + * @return array describing the args acceptable when querying this model |
|
| 523 | + * @throws \EE_Error |
|
| 524 | + */ |
|
| 525 | + protected function _get_read_query_params(\EEM_Base $model, $version) |
|
| 526 | + { |
|
| 527 | + $default_orderby = array(); |
|
| 528 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
| 529 | + $default_orderby[$key_field->get_name()] = 'ASC'; |
|
| 530 | + } |
|
| 531 | + return array_merge( |
|
| 532 | + $this->_get_response_selection_query_params($model, $version), |
|
| 533 | + array( |
|
| 534 | + 'where' => array( |
|
| 535 | + 'required' => false, |
|
| 536 | + 'default' => array(), |
|
| 537 | + ), |
|
| 538 | + 'limit' => array( |
|
| 539 | + 'required' => false, |
|
| 540 | + 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
| 541 | + ), |
|
| 542 | + 'order_by' => array( |
|
| 543 | + 'required' => false, |
|
| 544 | + 'default' => $default_orderby, |
|
| 545 | + ), |
|
| 546 | + 'group_by' => array( |
|
| 547 | + 'required' => false, |
|
| 548 | + 'default' => null, |
|
| 549 | + ), |
|
| 550 | + 'having' => array( |
|
| 551 | + 'required' => false, |
|
| 552 | + 'default' => null, |
|
| 553 | + ), |
|
| 554 | + 'caps' => array( |
|
| 555 | + 'required' => false, |
|
| 556 | + 'default' => EEM_Base::caps_read, |
|
| 557 | + ), |
|
| 558 | + ) |
|
| 559 | + ); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * Gets routes for the config |
|
| 566 | + * |
|
| 567 | + * @return array @see _register_model_routes |
|
| 568 | + * @deprecated since version 4.9.1 |
|
| 569 | + */ |
|
| 570 | + protected function _register_config_routes() |
|
| 571 | + { |
|
| 572 | + $config_routes = array(); |
|
| 573 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 574 | + $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version($version, |
|
| 575 | + $hidden_endpoint); |
|
| 576 | + } |
|
| 577 | + return $config_routes; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * Gets routes for the config for the specified version |
|
| 584 | + * |
|
| 585 | + * @param string $version |
|
| 586 | + * @param boolean $hidden_endpoint |
|
| 587 | + * @return array |
|
| 588 | + */ |
|
| 589 | + protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
| 590 | + { |
|
| 591 | + return array( |
|
| 592 | + 'config' => array( |
|
| 593 | + array( |
|
| 594 | + 'callback' => array( |
|
| 595 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 596 | + 'handle_request', |
|
| 597 | + ), |
|
| 598 | + 'methods' => WP_REST_Server::READABLE, |
|
| 599 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 600 | + ), |
|
| 601 | + ), |
|
| 602 | + 'site_info' => array( |
|
| 603 | + array( |
|
| 604 | + 'callback' => array( |
|
| 605 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 606 | + 'handle_request_site_info', |
|
| 607 | + ), |
|
| 608 | + 'methods' => WP_REST_Server::READABLE, |
|
| 609 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 610 | + ), |
|
| 611 | + ), |
|
| 612 | + ); |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Gets the meta info routes |
|
| 619 | + * |
|
| 620 | + * @return array @see _register_model_routes |
|
| 621 | + * @deprecated since version 4.9.1 |
|
| 622 | + */ |
|
| 623 | + protected function _register_meta_routes() |
|
| 624 | + { |
|
| 625 | + $meta_routes = array(); |
|
| 626 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 627 | + $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version($version, |
|
| 628 | + $hidden_endpoint); |
|
| 629 | + } |
|
| 630 | + return $meta_routes; |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * @param string $version |
|
| 637 | + * @param boolean $hidden_endpoint |
|
| 638 | + * @return array |
|
| 639 | + */ |
|
| 640 | + protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
| 641 | + { |
|
| 642 | + return array( |
|
| 643 | + 'resources' => array( |
|
| 644 | + array( |
|
| 645 | + 'callback' => array( |
|
| 646 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
| 647 | + 'handle_request_models_meta', |
|
| 648 | + ), |
|
| 649 | + 'methods' => WP_REST_Server::READABLE, |
|
| 650 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 651 | + ), |
|
| 652 | + ), |
|
| 653 | + ); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + |
|
| 658 | + /** |
|
| 659 | + * Tries to hide old 4.6 endpoints from the |
|
| 660 | + * |
|
| 661 | + * @param array $route_data |
|
| 662 | + * @return array |
|
| 663 | + */ |
|
| 664 | + public static function hide_old_endpoints($route_data) |
|
| 665 | + { |
|
| 666 | + //allow API clients to override which endpoints get hidden, in case |
|
| 667 | + //they want to discover particular endpoints |
|
| 668 | + //also, we don't have access to the request so we have to just grab it from the superglobal |
|
| 669 | + $force_show_ee_namespace = ltrim( |
|
| 670 | + EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''), |
|
| 671 | + '/' |
|
| 672 | + ); |
|
| 673 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
| 674 | + foreach ($relative_urls as $endpoint => $routes) { |
|
| 675 | + foreach ($routes as $route) { |
|
| 676 | + //by default, hide "hidden_endpoint"s, unless the request indicates |
|
| 677 | + //to $force_show_ee_namespace, in which case only show that one |
|
| 678 | + //namespace's endpoints (and hide all others) |
|
| 679 | + if (($route['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
| 680 | + || ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
| 681 | + ) { |
|
| 682 | + $full_route = '/' . ltrim($namespace, '/') . '/' . ltrim($endpoint, '/'); |
|
| 683 | + unset($route_data[$full_route]); |
|
| 684 | + } |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + return $route_data; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * Returns an array describing which versions of core support serving requests for. |
|
| 695 | + * Keys are core versions' major and minor version, and values are the |
|
| 696 | + * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
| 697 | + * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
| 698 | + * the answers table entirely, in which case it would be very difficult for |
|
| 699 | + * it to serve 4.6-style responses. |
|
| 700 | + * Versions of core that are missing from this array are unknowns. |
|
| 701 | + * previous ver |
|
| 702 | + * |
|
| 703 | + * @return array |
|
| 704 | + */ |
|
| 705 | + public static function version_compatibilities() |
|
| 706 | + { |
|
| 707 | + return apply_filters( |
|
| 708 | + 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
| 709 | + array( |
|
| 710 | + '4.8.29' => '4.8.29', |
|
| 711 | + '4.8.33' => '4.8.29', |
|
| 712 | + '4.8.34' => '4.8.29', |
|
| 713 | + '4.8.36' => '4.8.29', |
|
| 714 | + ) |
|
| 715 | + ); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + |
|
| 719 | + |
|
| 720 | + /** |
|
| 721 | + * Gets the latest API version served. Eg if there |
|
| 722 | + * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
| 723 | + * we are on core version 4.8.34, it will return the string "4.8.32" |
|
| 724 | + * |
|
| 725 | + * @return string |
|
| 726 | + */ |
|
| 727 | + public static function latest_rest_api_version() |
|
| 728 | + { |
|
| 729 | + $versions_served = \EED_Core_Rest_Api::versions_served(); |
|
| 730 | + $versions_served_keys = array_keys($versions_served); |
|
| 731 | + return end($versions_served_keys); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + |
|
| 736 | + /** |
|
| 737 | + * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
| 738 | + * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
| 739 | + * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
| 740 | + * We also indicate whether or not this version should be put in the index or not |
|
| 741 | + * |
|
| 742 | + * @return array keys are API version numbers (just major and minor numbers), and values |
|
| 743 | + * are whether or not they should be hidden |
|
| 744 | + */ |
|
| 745 | + public static function versions_served() |
|
| 746 | + { |
|
| 747 | + $versions_served = array(); |
|
| 748 | + $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
| 749 | + $lowest_compatible_version = end($possibly_served_versions); |
|
| 750 | + reset($possibly_served_versions); |
|
| 751 | + $versions_served_historically = array_keys($possibly_served_versions); |
|
| 752 | + $latest_version = end($versions_served_historically); |
|
| 753 | + reset($versions_served_historically); |
|
| 754 | + //for each version of core we have ever served: |
|
| 755 | + foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
| 756 | + //if it's not above the current core version, and it's compatible with the current version of core |
|
| 757 | + if ($key_versioned_endpoint == $latest_version) { |
|
| 758 | + //don't hide the latest version in the index |
|
| 759 | + $versions_served[$key_versioned_endpoint] = false; |
|
| 760 | + } else if ( |
|
| 761 | + $key_versioned_endpoint < EED_Core_Rest_Api::core_version() |
|
| 762 | + && $key_versioned_endpoint >= $lowest_compatible_version |
|
| 763 | + ) { |
|
| 764 | + //include, but hide, previous versions which are still supported |
|
| 765 | + $versions_served[$key_versioned_endpoint] = true; |
|
| 766 | + } elseif ( |
|
| 767 | + apply_filters( |
|
| 768 | + 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
| 769 | + false, |
|
| 770 | + $possibly_served_versions |
|
| 771 | + ) |
|
| 772 | + ) { |
|
| 773 | + //if a version is no longer supported, don't include it in index or list of versions served |
|
| 774 | + $versions_served[$key_versioned_endpoint] = true; |
|
| 775 | + } |
|
| 776 | + } |
|
| 777 | + return $versions_served; |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + |
|
| 781 | + |
|
| 782 | + /** |
|
| 783 | + * Gets the major and minor version of EE core's version string |
|
| 784 | + * |
|
| 785 | + * @return string |
|
| 786 | + */ |
|
| 787 | + public static function core_version() |
|
| 788 | + { |
|
| 789 | + return apply_filters('FHEE__EED_Core_REST_API__core_version', |
|
| 790 | + implode('.', array_slice(explode('.', espresso_version()), 0, 3))); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + |
|
| 795 | + /** |
|
| 796 | + * Gets the default limit that should be used when querying for resources |
|
| 797 | + * |
|
| 798 | + * @return int |
|
| 799 | + */ |
|
| 800 | + public static function get_default_query_limit() |
|
| 801 | + { |
|
| 802 | + //we actually don't use a const because we want folks to always use |
|
| 803 | + //this method, not the const directly |
|
| 804 | + return apply_filters( |
|
| 805 | + 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
| 806 | + 50 |
|
| 807 | + ); |
|
| 808 | + } |
|
| 809 | + |
|
| 810 | + |
|
| 811 | + |
|
| 812 | + /** |
|
| 813 | + * run - initial module setup |
|
| 814 | + * |
|
| 815 | + * @access public |
|
| 816 | + * @param WP $WP |
|
| 817 | + * @return void |
|
| 818 | + */ |
|
| 819 | + public function run($WP) |
|
| 820 | + { |
|
| 821 | + } |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | // End of file EED_Core_Rest_Api.module.php |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\exceptions\EntityNotFoundException; |
| 2 | 2 | |
| 3 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 4 | - exit( 'No direct script access allowed' ); |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | /** |
| 7 | 7 | * EE_Registration class |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | * date_format and the second value is the time format |
| 60 | 60 | * @return EE_Registration |
| 61 | 61 | */ |
| 62 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
| 63 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
| 64 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
| 62 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
| 63 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 64 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | * the website will be used. |
| 73 | 73 | * @return EE_Registration |
| 74 | 74 | */ |
| 75 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
| 76 | - return new self( $props_n_values, TRUE, $timezone ); |
|
| 75 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
| 76 | + return new self($props_n_values, TRUE, $timezone); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -83,8 +83,8 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * @param int $EVT_ID Event ID |
| 85 | 85 | */ |
| 86 | - public function set_event( $EVT_ID = 0 ) { |
|
| 87 | - $this->set( 'EVT_ID', $EVT_ID ); |
|
| 86 | + public function set_event($EVT_ID = 0) { |
|
| 87 | + $this->set('EVT_ID', $EVT_ID); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | |
@@ -98,18 +98,18 @@ discard block |
||
| 98 | 98 | * @throws \EE_Error |
| 99 | 99 | * @throws \RuntimeException |
| 100 | 100 | */ |
| 101 | - public function set( $field_name, $field_value, $use_default = FALSE ) { |
|
| 102 | - switch( $field_name ) { |
|
| 101 | + public function set($field_name, $field_value, $use_default = FALSE) { |
|
| 102 | + switch ($field_name) { |
|
| 103 | 103 | case 'REG_code' : |
| 104 | - if ( ! empty( $field_value ) && $this->reg_code() === null ) { |
|
| 105 | - $this->set_reg_code( $field_value, $use_default ); |
|
| 104 | + if ( ! empty($field_value) && $this->reg_code() === null) { |
|
| 105 | + $this->set_reg_code($field_value, $use_default); |
|
| 106 | 106 | } |
| 107 | 107 | break; |
| 108 | 108 | case 'STS_ID' : |
| 109 | - $this->set_status( $field_value, $use_default ); |
|
| 109 | + $this->set_status($field_value, $use_default); |
|
| 110 | 110 | break; |
| 111 | 111 | default : |
| 112 | - parent::set( $field_name, $field_value, $use_default ); |
|
| 112 | + parent::set($field_name, $field_value, $use_default); |
|
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | |
@@ -127,40 +127,40 @@ discard block |
||
| 127 | 127 | * @throws \RuntimeException |
| 128 | 128 | * @throws \EE_Error |
| 129 | 129 | */ |
| 130 | - public function set_status( $new_STS_ID = NULL, $use_default = FALSE ) { |
|
| 130 | + public function set_status($new_STS_ID = NULL, $use_default = FALSE) { |
|
| 131 | 131 | // get current REG_Status |
| 132 | 132 | $old_STS_ID = $this->status_ID(); |
| 133 | 133 | // if status has changed |
| 134 | 134 | if ( |
| 135 | 135 | $old_STS_ID !== $new_STS_ID // and that status has actually changed |
| 136 | - && ! empty( $old_STS_ID ) // and that old status is actually set |
|
| 137 | - && ! empty( $new_STS_ID ) // as well as the new status |
|
| 136 | + && ! empty($old_STS_ID) // and that old status is actually set |
|
| 137 | + && ! empty($new_STS_ID) // as well as the new status |
|
| 138 | 138 | && $this->ID() // ensure registration is in the db |
| 139 | 139 | ) { |
| 140 | 140 | // TO approved |
| 141 | - if ( $new_STS_ID === EEM_Registration::status_id_approved ) { |
|
| 141 | + if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
| 142 | 142 | // reserve a space by incrementing ticket and datetime sold values |
| 143 | 143 | $this->_reserve_registration_space(); |
| 144 | - do_action( 'AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID ); |
|
| 144 | + do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID); |
|
| 145 | 145 | // OR FROM approved |
| 146 | - } else if ( $old_STS_ID === EEM_Registration::status_id_approved ) { |
|
| 146 | + } else if ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
| 147 | 147 | // release a space by decrementing ticket and datetime sold values |
| 148 | 148 | $this->_release_registration_space(); |
| 149 | - do_action( 'AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID ); |
|
| 149 | + do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID); |
|
| 150 | 150 | } |
| 151 | 151 | // update status |
| 152 | 152 | parent::set('STS_ID', $new_STS_ID, $use_default); |
| 153 | 153 | $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID); |
| 154 | 154 | /** @type EE_Transaction_Payments $transaction_payments */ |
| 155 | 155 | $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
| 156 | - $transaction_payments->recalculate_transaction_total( $this->transaction(), false ); |
|
| 157 | - $this->transaction()->update_status_based_on_total_paid( true ); |
|
| 158 | - do_action( 'AHEE__EE_Registration__set_status__after_update', $this ); |
|
| 156 | + $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
| 157 | + $this->transaction()->update_status_based_on_total_paid(true); |
|
| 158 | + do_action('AHEE__EE_Registration__set_status__after_update', $this); |
|
| 159 | 159 | return TRUE; |
| 160 | 160 | } else { |
| 161 | 161 | //even though the old value matches the new value, it's still good to |
| 162 | 162 | //allow the parent set method to have a say |
| 163 | - parent::set( 'STS_ID', $new_STS_ID, $use_default ); |
|
| 163 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
| 164 | 164 | return TRUE; |
| 165 | 165 | } |
| 166 | 166 | } |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | * get Status ID |
| 229 | 229 | */ |
| 230 | 230 | public function status_ID() { |
| 231 | - return $this->get( 'STS_ID' ); |
|
| 231 | + return $this->get('STS_ID'); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | |
@@ -259,12 +259,12 @@ discard block |
||
| 259 | 259 | * @return EE_Ticket|EE_Base_Class |
| 260 | 260 | * @throws \EE_Error |
| 261 | 261 | */ |
| 262 | - public function ticket( $include_archived = TRUE ) { |
|
| 262 | + public function ticket($include_archived = TRUE) { |
|
| 263 | 263 | $query_params = array(); |
| 264 | - if ( $include_archived ) { |
|
| 265 | - $query_params[ 'default_where_conditions' ] = 'none'; |
|
| 264 | + if ($include_archived) { |
|
| 265 | + $query_params['default_where_conditions'] = 'none'; |
|
| 266 | 266 | } |
| 267 | - return $this->get_first_related( 'Ticket', $query_params ); |
|
| 267 | + return $this->get_first_related('Ticket', $query_params); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | */ |
| 293 | 293 | public function wp_user() { |
| 294 | 294 | $event = $this->event(); |
| 295 | - if ( $event instanceof EE_Event ) { |
|
| 295 | + if ($event instanceof EE_Event) { |
|
| 296 | 296 | return $event->wp_user(); |
| 297 | 297 | } |
| 298 | 298 | return 0; |
@@ -363,8 +363,8 @@ discard block |
||
| 363 | 363 | * |
| 364 | 364 | * @param int $ATT_ID Attendee ID |
| 365 | 365 | */ |
| 366 | - public function set_attendee_id( $ATT_ID = 0 ) { |
|
| 367 | - $this->set( 'ATT_ID', $ATT_ID ); |
|
| 366 | + public function set_attendee_id($ATT_ID = 0) { |
|
| 367 | + $this->set('ATT_ID', $ATT_ID); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | |
@@ -374,8 +374,8 @@ discard block |
||
| 374 | 374 | * |
| 375 | 375 | * @param int $TXN_ID Transaction ID |
| 376 | 376 | */ |
| 377 | - public function set_transaction_id( $TXN_ID = 0 ) { |
|
| 378 | - $this->set( 'TXN_ID', $TXN_ID ); |
|
| 377 | + public function set_transaction_id($TXN_ID = 0) { |
|
| 378 | + $this->set('TXN_ID', $TXN_ID); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | |
@@ -385,8 +385,8 @@ discard block |
||
| 385 | 385 | * |
| 386 | 386 | * @param string $REG_session PHP Session ID |
| 387 | 387 | */ |
| 388 | - public function set_session( $REG_session = '' ) { |
|
| 389 | - $this->set( 'REG_session', $REG_session ); |
|
| 388 | + public function set_session($REG_session = '') { |
|
| 389 | + $this->set('REG_session', $REG_session); |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | |
@@ -396,8 +396,8 @@ discard block |
||
| 396 | 396 | * |
| 397 | 397 | * @param string $REG_url_link Registration URL Link |
| 398 | 398 | */ |
| 399 | - public function set_reg_url_link( $REG_url_link = '' ) { |
|
| 400 | - $this->set( 'REG_url_link', $REG_url_link ); |
|
| 399 | + public function set_reg_url_link($REG_url_link = '') { |
|
| 400 | + $this->set('REG_url_link', $REG_url_link); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | |
@@ -407,8 +407,8 @@ discard block |
||
| 407 | 407 | * |
| 408 | 408 | * @param int $REG_count Primary Attendee |
| 409 | 409 | */ |
| 410 | - public function set_count( $REG_count = 1 ) { |
|
| 411 | - $this->set( 'REG_count', $REG_count ); |
|
| 410 | + public function set_count($REG_count = 1) { |
|
| 411 | + $this->set('REG_count', $REG_count); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | |
@@ -418,8 +418,8 @@ discard block |
||
| 418 | 418 | * |
| 419 | 419 | * @param boolean $REG_group_size Group Registration |
| 420 | 420 | */ |
| 421 | - public function set_group_size( $REG_group_size = FALSE ) { |
|
| 422 | - $this->set( 'REG_group_size', $REG_group_size ); |
|
| 421 | + public function set_group_size($REG_group_size = FALSE) { |
|
| 422 | + $this->set('REG_group_size', $REG_group_size); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | |
@@ -495,8 +495,8 @@ discard block |
||
| 495 | 495 | * |
| 496 | 496 | * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of Date |
| 497 | 497 | */ |
| 498 | - public function set_reg_date( $REG_date = FALSE ) { |
|
| 499 | - $this->set( 'REG_date', $REG_date ); |
|
| 498 | + public function set_reg_date($REG_date = FALSE) { |
|
| 499 | + $this->set('REG_date', $REG_date); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | |
@@ -507,8 +507,8 @@ discard block |
||
| 507 | 507 | * @access public |
| 508 | 508 | * @param float $REG_final_price |
| 509 | 509 | */ |
| 510 | - public function set_final_price( $REG_final_price = 0.00 ) { |
|
| 511 | - $this->set( 'REG_final_price', $REG_final_price ); |
|
| 510 | + public function set_final_price($REG_final_price = 0.00) { |
|
| 511 | + $this->set('REG_final_price', $REG_final_price); |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | |
@@ -519,8 +519,8 @@ discard block |
||
| 519 | 519 | * @access public |
| 520 | 520 | * @param float $REG_paid |
| 521 | 521 | */ |
| 522 | - public function set_paid( $REG_paid = 0.00 ) { |
|
| 523 | - $this->set( 'REG_paid', $REG_paid ); |
|
| 522 | + public function set_paid($REG_paid = 0.00) { |
|
| 523 | + $this->set('REG_paid', $REG_paid); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | |
@@ -530,8 +530,8 @@ discard block |
||
| 530 | 530 | * |
| 531 | 531 | * @param boolean $REG_att_is_going Attendee Is Going |
| 532 | 532 | */ |
| 533 | - public function set_att_is_going( $REG_att_is_going = FALSE ) { |
|
| 534 | - $this->set( 'REG_att_is_going', $REG_att_is_going ); |
|
| 533 | + public function set_att_is_going($REG_att_is_going = FALSE) { |
|
| 534 | + $this->set('REG_att_is_going', $REG_att_is_going); |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | * @return EE_Attendee |
| 542 | 542 | */ |
| 543 | 543 | public function attendee() { |
| 544 | - return $this->get_first_related( 'Attendee' ); |
|
| 544 | + return $this->get_first_related('Attendee'); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | * get Event ID |
| 551 | 551 | */ |
| 552 | 552 | public function event_ID() { |
| 553 | - return $this->get( 'EVT_ID' ); |
|
| 553 | + return $this->get('EVT_ID'); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | */ |
| 561 | 561 | public function event_name() { |
| 562 | 562 | $event = $this->event_obj(); |
| 563 | - if ( $event ) { |
|
| 563 | + if ($event) { |
|
| 564 | 564 | return $event->name(); |
| 565 | 565 | } else { |
| 566 | 566 | return NULL; |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | * @return EE_Event |
| 575 | 575 | */ |
| 576 | 576 | public function event_obj() { |
| 577 | - return $this->get_first_related( 'Event' ); |
|
| 577 | + return $this->get_first_related('Event'); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | |
@@ -583,7 +583,7 @@ discard block |
||
| 583 | 583 | * get Attendee ID |
| 584 | 584 | */ |
| 585 | 585 | public function attendee_ID() { |
| 586 | - return $this->get( 'ATT_ID' ); |
|
| 586 | + return $this->get('ATT_ID'); |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | |
@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | * get PHP Session ID |
| 593 | 593 | */ |
| 594 | 594 | public function session_ID() { |
| 595 | - return $this->get( 'REG_session' ); |
|
| 595 | + return $this->get('REG_session'); |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | * @param string $messenger 'pdf' or 'html'. Default 'html'. |
| 603 | 603 | * @return string |
| 604 | 604 | */ |
| 605 | - public function receipt_url( $messenger = 'html' ) { |
|
| 605 | + public function receipt_url($messenger = 'html') { |
|
| 606 | 606 | |
| 607 | 607 | /** |
| 608 | 608 | * The below will be deprecated one version after this. We check first if there is a custom receipt template already in use on old system. If there is then we just return the standard url for it. |
@@ -610,12 +610,12 @@ discard block |
||
| 610 | 610 | * @since 4.5.0 |
| 611 | 611 | */ |
| 612 | 612 | $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
| 613 | - $has_custom = EEH_Template::locate_template( $template_relative_path , array(), TRUE, TRUE, TRUE ); |
|
| 613 | + $has_custom = EEH_Template::locate_template($template_relative_path, array(), TRUE, TRUE, TRUE); |
|
| 614 | 614 | |
| 615 | - if ( $has_custom ) { |
|
| 616 | - return add_query_arg( array( 'receipt' => 'true' ), $this->invoice_url( 'launch' ) ); |
|
| 615 | + if ($has_custom) { |
|
| 616 | + return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
| 617 | 617 | } |
| 618 | - return apply_filters( 'FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt' ); |
|
| 618 | + return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | |
@@ -626,28 +626,28 @@ discard block |
||
| 626 | 626 | * @param string $messenger 'pdf' or 'html'. Default 'html'. |
| 627 | 627 | * @return string |
| 628 | 628 | */ |
| 629 | - public function invoice_url( $messenger = 'html' ) { |
|
| 629 | + public function invoice_url($messenger = 'html') { |
|
| 630 | 630 | /** |
| 631 | 631 | * The below will be deprecated one version after this. We check first if there is a custom invoice template already in use on old system. If there is then we just return the standard url for it. |
| 632 | 632 | * |
| 633 | 633 | * @since 4.5.0 |
| 634 | 634 | */ |
| 635 | 635 | $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
| 636 | - $has_custom = EEH_Template::locate_template( $template_relative_path , array(), TRUE, TRUE, TRUE ); |
|
| 636 | + $has_custom = EEH_Template::locate_template($template_relative_path, array(), TRUE, TRUE, TRUE); |
|
| 637 | 637 | |
| 638 | - if ( $has_custom ) { |
|
| 639 | - if ( $messenger == 'html' ) { |
|
| 640 | - return $this->invoice_url( 'launch' ); |
|
| 638 | + if ($has_custom) { |
|
| 639 | + if ($messenger == 'html') { |
|
| 640 | + return $this->invoice_url('launch'); |
|
| 641 | 641 | } |
| 642 | 642 | $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
| 643 | 643 | |
| 644 | - $query_args = array( 'ee' => $route, 'id' => $this->reg_url_link() ); |
|
| 645 | - if ( $messenger == 'html' ) { |
|
| 644 | + $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
| 645 | + if ($messenger == 'html') { |
|
| 646 | 646 | $query_args['html'] = TRUE; |
| 647 | 647 | } |
| 648 | - return add_query_arg( $query_args, get_permalink( EE_Registry::instance()->CFG->core->thank_you_page_id ) ); |
|
| 648 | + return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
| 649 | 649 | } |
| 650 | - return apply_filters( 'FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice' ); |
|
| 650 | + return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | |
@@ -660,7 +660,7 @@ discard block |
||
| 660 | 660 | * @throws \EE_Error |
| 661 | 661 | */ |
| 662 | 662 | public function reg_url_link() { |
| 663 | - return (string)$this->get( 'REG_url_link' ); |
|
| 663 | + return (string) $this->get('REG_url_link'); |
|
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | |
@@ -670,8 +670,8 @@ discard block |
||
| 670 | 670 | * @param string $type 'download','launch', or 'html' (default is 'launch') |
| 671 | 671 | * @return void |
| 672 | 672 | */ |
| 673 | - public function e_invoice_url( $type = 'launch' ) { |
|
| 674 | - echo $this->invoice_url( $type ); |
|
| 673 | + public function e_invoice_url($type = 'launch') { |
|
| 674 | + echo $this->invoice_url($type); |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | * @return string |
| 692 | 692 | */ |
| 693 | 693 | public function payment_overview_url() { |
| 694 | - return add_query_arg( array( 'e_reg_url_link' => $this->reg_url_link(), 'step' => 'payment_options', 'revisit' => TRUE ), EE_Registry::instance()->CFG->core->reg_page_url() ); |
|
| 694 | + return add_query_arg(array('e_reg_url_link' => $this->reg_url_link(), 'step' => 'payment_options', 'revisit' => TRUE), EE_Registry::instance()->CFG->core->reg_page_url()); |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | * @return string |
| 703 | 703 | */ |
| 704 | 704 | public function edit_attendee_information_url() { |
| 705 | - return add_query_arg( array( 'e_reg_url_link' => $this->reg_url_link(), 'step' => 'attendee_information', 'revisit' => TRUE ), EE_Registry::instance()->CFG->core->reg_page_url() ); |
|
| 705 | + return add_query_arg(array('e_reg_url_link' => $this->reg_url_link(), 'step' => 'attendee_information', 'revisit' => TRUE), EE_Registry::instance()->CFG->core->reg_page_url()); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | |
@@ -712,7 +712,7 @@ discard block |
||
| 712 | 712 | * @return string |
| 713 | 713 | */ |
| 714 | 714 | public function get_admin_edit_url() { |
| 715 | - return EEH_URL::add_query_args_and_nonce( array( 'page' => 'espresso_registrations', 'action' => 'view_registration', '_REG_ID' => $this->ID() ), admin_url( 'admin.php' ) ); |
|
| 715 | + return EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_registrations', 'action' => 'view_registration', '_REG_ID' => $this->ID()), admin_url('admin.php')); |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | |
@@ -721,7 +721,7 @@ discard block |
||
| 721 | 721 | * is_primary_registrant? |
| 722 | 722 | */ |
| 723 | 723 | public function is_primary_registrant() { |
| 724 | - return $this->get( 'REG_count' ) == 1 ? TRUE : FALSE; |
|
| 724 | + return $this->get('REG_count') == 1 ? TRUE : FALSE; |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | |
@@ -730,12 +730,12 @@ discard block |
||
| 730 | 730 | * This returns the primary registration object for this registration group (which may be this object). |
| 731 | 731 | * @return EE_Registration |
| 732 | 732 | */ |
| 733 | - public function get_primary_registration() { |
|
| 734 | - if ( $this->is_primary_registrant() ) |
|
| 733 | + public function get_primary_registration() { |
|
| 734 | + if ($this->is_primary_registrant()) |
|
| 735 | 735 | return $this; |
| 736 | 736 | |
| 737 | 737 | //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
| 738 | - $primary_registrant = EEM_Registration::instance()->get_one( array( array('TXN_ID' => $this->transaction_ID(), 'REG_count' => 1 ) ) ); |
|
| 738 | + $primary_registrant = EEM_Registration::instance()->get_one(array(array('TXN_ID' => $this->transaction_ID(), 'REG_count' => 1))); |
|
| 739 | 739 | return $primary_registrant; |
| 740 | 740 | } |
| 741 | 741 | |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | * @access public |
| 747 | 747 | */ |
| 748 | 748 | public function count() { |
| 749 | - return $this->get( 'REG_count' ); |
|
| 749 | + return $this->get('REG_count'); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | |
@@ -755,7 +755,7 @@ discard block |
||
| 755 | 755 | * get Group Size |
| 756 | 756 | */ |
| 757 | 757 | public function group_size() { |
| 758 | - return $this->get( 'REG_group_size' ); |
|
| 758 | + return $this->get('REG_group_size'); |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | |
@@ -764,7 +764,7 @@ discard block |
||
| 764 | 764 | * get Registration Date |
| 765 | 765 | */ |
| 766 | 766 | public function date() { |
| 767 | - return $this->get( 'REG_date' ); |
|
| 767 | + return $this->get('REG_date'); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | |
@@ -775,8 +775,8 @@ discard block |
||
| 775 | 775 | * @param string $time_format |
| 776 | 776 | * @return string |
| 777 | 777 | */ |
| 778 | - public function pretty_date( $date_format = NULL, $time_format = NULL ) { |
|
| 779 | - return $this->get_datetime( 'REG_date', $date_format, $time_format ); |
|
| 778 | + public function pretty_date($date_format = NULL, $time_format = NULL) { |
|
| 779 | + return $this->get_datetime('REG_date', $date_format, $time_format); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | * @return float |
| 789 | 789 | */ |
| 790 | 790 | public function final_price() { |
| 791 | - return $this->get( 'REG_final_price' ); |
|
| 791 | + return $this->get('REG_final_price'); |
|
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | |
@@ -799,7 +799,7 @@ discard block |
||
| 799 | 799 | * @return string |
| 800 | 800 | */ |
| 801 | 801 | public function pretty_final_price() { |
| 802 | - return $this->get_pretty( 'REG_final_price' ); |
|
| 802 | + return $this->get_pretty('REG_final_price'); |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | * @return float |
| 810 | 810 | */ |
| 811 | 811 | public function paid() { |
| 812 | - return $this->get( 'REG_paid' ); |
|
| 812 | + return $this->get('REG_paid'); |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | |
@@ -819,7 +819,7 @@ discard block |
||
| 819 | 819 | * @return float |
| 820 | 820 | */ |
| 821 | 821 | public function pretty_paid() { |
| 822 | - return $this->get_pretty( 'REG_paid' ); |
|
| 822 | + return $this->get_pretty('REG_paid'); |
|
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | |
@@ -830,11 +830,11 @@ discard block |
||
| 830 | 830 | * @param array $requires_payment |
| 831 | 831 | * @return bool |
| 832 | 832 | */ |
| 833 | - public function owes_monies_and_can_pay( $requires_payment = array()) { |
|
| 833 | + public function owes_monies_and_can_pay($requires_payment = array()) { |
|
| 834 | 834 | // these reg statuses require payment (if event is not free) |
| 835 | - $requires_payment = ! empty( $requires_payment ) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment(); |
|
| 835 | + $requires_payment = ! empty($requires_payment) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment(); |
|
| 836 | 836 | if ( |
| 837 | - in_array( $this->status_ID(), $requires_payment ) && |
|
| 837 | + in_array($this->status_ID(), $requires_payment) && |
|
| 838 | 838 | $this->final_price() != 0 && |
| 839 | 839 | $this->final_price() != $this->paid() |
| 840 | 840 | ) { |
@@ -851,8 +851,8 @@ discard block |
||
| 851 | 851 | * @param bool $show_icons |
| 852 | 852 | * @return void |
| 853 | 853 | */ |
| 854 | - public function e_pretty_status( $show_icons = FALSE ) { |
|
| 855 | - echo $this->pretty_status( $show_icons ); |
|
| 854 | + public function e_pretty_status($show_icons = FALSE) { |
|
| 855 | + echo $this->pretty_status($show_icons); |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | |
@@ -863,10 +863,10 @@ discard block |
||
| 863 | 863 | * @param bool $show_icons |
| 864 | 864 | * @return string |
| 865 | 865 | */ |
| 866 | - public function pretty_status( $show_icons = FALSE ) { |
|
| 867 | - $status = EEM_Status::instance()->localized_status( array( $this->status_ID() => __( 'unknown', 'event_espresso' ) ), FALSE, 'sentence' ); |
|
| 866 | + public function pretty_status($show_icons = FALSE) { |
|
| 867 | + $status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')), FALSE, 'sentence'); |
|
| 868 | 868 | $icon = ''; |
| 869 | - switch ( $this->status_ID() ) { |
|
| 869 | + switch ($this->status_ID()) { |
|
| 870 | 870 | case EEM_Registration::status_id_approved: |
| 871 | 871 | $icon = $show_icons ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' : ''; |
| 872 | 872 | break; |
@@ -889,7 +889,7 @@ discard block |
||
| 889 | 889 | $icon = $show_icons ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' : ''; |
| 890 | 890 | break; |
| 891 | 891 | } |
| 892 | - return $icon . $status[ $this->status_ID() ]; |
|
| 892 | + return $icon.$status[$this->status_ID()]; |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | |
@@ -898,7 +898,7 @@ discard block |
||
| 898 | 898 | * get Attendee Is Going |
| 899 | 899 | */ |
| 900 | 900 | public function att_is_going() { |
| 901 | - return $this->get( 'REG_att_is_going' ); |
|
| 901 | + return $this->get('REG_att_is_going'); |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | |
@@ -908,8 +908,8 @@ discard block |
||
| 908 | 908 | * @param array $query_params like EEM_Base::get_all |
| 909 | 909 | * @return EE_Answer[] |
| 910 | 910 | */ |
| 911 | - public function answers( $query_params = NULL ) { |
|
| 912 | - return $this->get_many_related( 'Answer', $query_params ); |
|
| 911 | + public function answers($query_params = NULL) { |
|
| 912 | + return $this->get_many_related('Answer', $query_params); |
|
| 913 | 913 | } |
| 914 | 914 | |
| 915 | 915 | |
@@ -923,9 +923,9 @@ discard block |
||
| 923 | 923 | * (because the answer might be an array of answer values, so passing pretty_value=true |
| 924 | 924 | * will convert it into some kind of string) |
| 925 | 925 | */ |
| 926 | - public function answer_value_to_question( $question, $pretty_value=true ) { |
|
| 926 | + public function answer_value_to_question($question, $pretty_value = true) { |
|
| 927 | 927 | $question_id = EEM_Question::instance()->ensure_is_ID($question); |
| 928 | - return EEM_Answer::instance()->get_answer_value_to_question($this,$question_id,$pretty_value); |
|
| 928 | + return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | |
@@ -938,13 +938,13 @@ discard block |
||
| 938 | 938 | */ |
| 939 | 939 | public function question_groups() { |
| 940 | 940 | $question_groups = array(); |
| 941 | - if ( $this->event() instanceof EE_Event ) { |
|
| 941 | + if ($this->event() instanceof EE_Event) { |
|
| 942 | 942 | $question_groups = $this->event()->question_groups( |
| 943 | 943 | array( |
| 944 | 944 | array( |
| 945 | 945 | 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false |
| 946 | 946 | ), |
| 947 | - 'order_by' => array( 'QSG_order' => 'ASC' ) |
|
| 947 | + 'order_by' => array('QSG_order' => 'ASC') |
|
| 948 | 948 | ) |
| 949 | 949 | ); |
| 950 | 950 | } |
@@ -961,7 +961,7 @@ discard block |
||
| 961 | 961 | */ |
| 962 | 962 | public function count_question_groups() { |
| 963 | 963 | $qg_count = 0; |
| 964 | - if ( $this->event() instanceof EE_Event ) { |
|
| 964 | + if ($this->event() instanceof EE_Event) { |
|
| 965 | 965 | $qg_count = $this->event()->count_related( |
| 966 | 966 | 'Question_Group', |
| 967 | 967 | array( |
@@ -982,7 +982,7 @@ discard block |
||
| 982 | 982 | * @return string |
| 983 | 983 | */ |
| 984 | 984 | public function reg_date() { |
| 985 | - return $this->get_datetime( 'REG_date' ); |
|
| 985 | + return $this->get_datetime('REG_date'); |
|
| 986 | 986 | } |
| 987 | 987 | |
| 988 | 988 | |
@@ -994,7 +994,7 @@ discard block |
||
| 994 | 994 | * @return EE_Datetime_Ticket |
| 995 | 995 | */ |
| 996 | 996 | public function datetime_ticket() { |
| 997 | - return $this->get_first_related( 'Datetime_Ticket' ); |
|
| 997 | + return $this->get_first_related('Datetime_Ticket'); |
|
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | 1000 | |
@@ -1004,15 +1004,15 @@ discard block |
||
| 1004 | 1004 | * @param EE_Datetime_Ticket $datetime_ticket |
| 1005 | 1005 | * @return EE_Datetime_Ticket |
| 1006 | 1006 | */ |
| 1007 | - public function set_datetime_ticket( $datetime_ticket ) { |
|
| 1008 | - return $this->_add_relation_to( $datetime_ticket, 'Datetime_Ticket' ); |
|
| 1007 | + public function set_datetime_ticket($datetime_ticket) { |
|
| 1008 | + return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
| 1009 | 1009 | } |
| 1010 | 1010 | /** |
| 1011 | 1011 | * Gets deleted |
| 1012 | 1012 | * @return boolean |
| 1013 | 1013 | */ |
| 1014 | 1014 | public function deleted() { |
| 1015 | - return $this->get( 'REG_deleted' ); |
|
| 1015 | + return $this->get('REG_deleted'); |
|
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | 1018 | /** |
@@ -1021,7 +1021,7 @@ discard block |
||
| 1021 | 1021 | * @return boolean |
| 1022 | 1022 | */ |
| 1023 | 1023 | public function set_deleted($deleted) { |
| 1024 | - if ( $deleted ) { |
|
| 1024 | + if ($deleted) { |
|
| 1025 | 1025 | $this->delete(); |
| 1026 | 1026 | } else { |
| 1027 | 1027 | $this->restore(); |
@@ -1035,7 +1035,7 @@ discard block |
||
| 1035 | 1035 | * @return EE_Status |
| 1036 | 1036 | */ |
| 1037 | 1037 | public function status_obj() { |
| 1038 | - return $this->get_first_related( 'Status' ); |
|
| 1038 | + return $this->get_first_related('Status'); |
|
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | |
@@ -1046,7 +1046,7 @@ discard block |
||
| 1046 | 1046 | * @return int |
| 1047 | 1047 | */ |
| 1048 | 1048 | public function count_checkins() { |
| 1049 | - return $this->get_model()->count_related( $this, 'Checkin' ); |
|
| 1049 | + return $this->get_model()->count_related($this, 'Checkin'); |
|
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | 1052 | |
@@ -1056,7 +1056,7 @@ discard block |
||
| 1056 | 1056 | * @return int |
| 1057 | 1057 | */ |
| 1058 | 1058 | public function count_checkins_not_checkedout() { |
| 1059 | - return $this->get_model()->count_related( $this, 'Checkin', array( array( 'CHK_in' => 1 ) ) ); |
|
| 1059 | + return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | 1062 | |
@@ -1069,20 +1069,20 @@ discard block |
||
| 1069 | 1069 | * |
| 1070 | 1070 | * @return bool |
| 1071 | 1071 | */ |
| 1072 | - public function can_checkin( $DTT_OR_ID, $check_approved = TRUE ) { |
|
| 1073 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID( $DTT_OR_ID ); |
|
| 1072 | + public function can_checkin($DTT_OR_ID, $check_approved = TRUE) { |
|
| 1073 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
| 1074 | 1074 | |
| 1075 | 1075 | //first check registration status |
| 1076 | - if ( ( $check_approved && ! $this->is_approved() ) || ! $DTT_ID ) { |
|
| 1076 | + if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
| 1077 | 1077 | return false; |
| 1078 | 1078 | } |
| 1079 | 1079 | //is there a datetime ticket that matches this dtt_ID? |
| 1080 | - if ( ! ( EEM_Datetime_Ticket::instance()->exists( array( array( 'TKT_ID' => $this->get('TKT_ID' ), 'DTT_ID' => $DTT_ID ) ) ) ) ) { |
|
| 1080 | + if ( ! (EEM_Datetime_Ticket::instance()->exists(array(array('TKT_ID' => $this->get('TKT_ID'), 'DTT_ID' => $DTT_ID))))) { |
|
| 1081 | 1081 | return false; |
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | 1084 | //final check is against TKT_uses |
| 1085 | - return $this->verify_can_checkin_against_TKT_uses( $DTT_ID ); |
|
| 1085 | + return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | |
@@ -1095,10 +1095,10 @@ discard block |
||
| 1095 | 1095 | * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
| 1096 | 1096 | * @return bool true means can checkin. false means cannot checkin. |
| 1097 | 1097 | */ |
| 1098 | - public function verify_can_checkin_against_TKT_uses( $DTT_OR_ID ) { |
|
| 1099 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID( $DTT_OR_ID ); |
|
| 1098 | + public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) { |
|
| 1099 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
| 1100 | 1100 | |
| 1101 | - if ( ! $DTT_ID ) { |
|
| 1101 | + if ( ! $DTT_ID) { |
|
| 1102 | 1102 | return false; |
| 1103 | 1103 | } |
| 1104 | 1104 | |
@@ -1106,23 +1106,23 @@ discard block |
||
| 1106 | 1106 | |
| 1107 | 1107 | // if max uses is not set or equals infinity then return true cause its not a factor for whether user can check-in |
| 1108 | 1108 | // or not. |
| 1109 | - if ( ! $max_uses || $max_uses === EE_INF ) { |
|
| 1109 | + if ( ! $max_uses || $max_uses === EE_INF) { |
|
| 1110 | 1110 | return true; |
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | 1113 | //does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
| 1114 | 1114 | //go ahead and toggle. |
| 1115 | - if ( EEM_Checkin::instance()->exists( array( array( 'REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID ) ) ) ) { |
|
| 1115 | + if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
| 1116 | 1116 | return true; |
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | 1119 | //made it here so the last check is whether the number of checkins per unique datetime on this registration |
| 1120 | 1120 | //disallows further check-ins. |
| 1121 | - $count_unique_dtt_checkins = EEM_Checkin::instance()->count( array( array( 'REG_ID' => $this->ID(), 'CHK_in' => true ) ), 'DTT_ID', true ); |
|
| 1121 | + $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array(array('REG_ID' => $this->ID(), 'CHK_in' => true)), 'DTT_ID', true); |
|
| 1122 | 1122 | // checkins have already reached their max number of uses |
| 1123 | 1123 | // so registrant can NOT checkin |
| 1124 | - if ( $count_unique_dtt_checkins >= $max_uses ) { |
|
| 1125 | - EE_Error::add_error( __( 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1124 | + if ($count_unique_dtt_checkins >= $max_uses) { |
|
| 1125 | + EE_Error::add_error(__('Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1126 | 1126 | return false; |
| 1127 | 1127 | } |
| 1128 | 1128 | return true; |
@@ -1144,15 +1144,15 @@ discard block |
||
| 1144 | 1144 | * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
| 1145 | 1145 | * @throws EE_Error |
| 1146 | 1146 | */ |
| 1147 | - public function toggle_checkin_status( $DTT_ID = null, $verify = false ) { |
|
| 1148 | - if ( empty( $DTT_ID ) ) { |
|
| 1147 | + public function toggle_checkin_status($DTT_ID = null, $verify = false) { |
|
| 1148 | + if (empty($DTT_ID)) { |
|
| 1149 | 1149 | $datetime = $this->get_latest_related_datetime(); |
| 1150 | 1150 | $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
| 1151 | 1151 | // verify the registration can checkin for the given DTT_ID |
| 1152 | - } elseif ( ! $this->can_checkin( $DTT_ID, $verify ) ) { |
|
| 1152 | + } elseif ( ! $this->can_checkin($DTT_ID, $verify)) { |
|
| 1153 | 1153 | EE_Error::add_error( |
| 1154 | 1154 | sprintf( |
| 1155 | - __( 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', 'event_espresso'), |
|
| 1155 | + __('The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', 'event_espresso'), |
|
| 1156 | 1156 | $this->ID(), |
| 1157 | 1157 | $DTT_ID |
| 1158 | 1158 | ), |
@@ -1166,8 +1166,8 @@ discard block |
||
| 1166 | 1166 | EE_Registration::checkin_status_out => EE_Registration::checkin_status_in |
| 1167 | 1167 | ); |
| 1168 | 1168 | //start by getting the current status so we know what status we'll be changing to. |
| 1169 | - $cur_status = $this->check_in_status_for_datetime( $DTT_ID, NULL ); |
|
| 1170 | - $status_to = $status_paths[ $cur_status ]; |
|
| 1169 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID, NULL); |
|
| 1170 | + $status_to = $status_paths[$cur_status]; |
|
| 1171 | 1171 | // database only records true for checked IN or false for checked OUT |
| 1172 | 1172 | // no record ( null ) means checked in NEVER, but we obviously don't save that |
| 1173 | 1173 | $new_status = $status_to === EE_Registration::checkin_status_in ? true : false; |
@@ -1175,24 +1175,24 @@ discard block |
||
| 1175 | 1175 | // because we are keeping track of Check-ins over time. |
| 1176 | 1176 | // Eventually we'll probably want to show a list table |
| 1177 | 1177 | // for the individual Check-ins so that they can be managed. |
| 1178 | - $checkin = EE_Checkin::new_instance( array( |
|
| 1178 | + $checkin = EE_Checkin::new_instance(array( |
|
| 1179 | 1179 | 'REG_ID' => $this->ID(), |
| 1180 | 1180 | 'DTT_ID' => $DTT_ID, |
| 1181 | 1181 | 'CHK_in' => $new_status |
| 1182 | - ) ); |
|
| 1182 | + )); |
|
| 1183 | 1183 | // if the record could not be saved then return false |
| 1184 | - if ( $checkin->save() === 0 ) { |
|
| 1185 | - if ( WP_DEBUG ) { |
|
| 1184 | + if ($checkin->save() === 0) { |
|
| 1185 | + if (WP_DEBUG) { |
|
| 1186 | 1186 | global $wpdb; |
| 1187 | 1187 | $error = sprintf( |
| 1188 | - __( 'Registration check in update failed because of the following database error: %1$s%2$s', 'event_espresso' ), |
|
| 1188 | + __('Registration check in update failed because of the following database error: %1$s%2$s', 'event_espresso'), |
|
| 1189 | 1189 | '<br />', |
| 1190 | 1190 | $wpdb->last_error |
| 1191 | 1191 | ); |
| 1192 | 1192 | } else { |
| 1193 | - $error = __( 'Registration check in update failed because of an unknown database error', 'event_espresso' ); |
|
| 1193 | + $error = __('Registration check in update failed because of an unknown database error', 'event_espresso'); |
|
| 1194 | 1194 | } |
| 1195 | - EE_Error::add_error( $error, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1195 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 1196 | 1196 | return false; |
| 1197 | 1197 | } |
| 1198 | 1198 | return $status_to; |
@@ -1213,7 +1213,7 @@ discard block |
||
| 1213 | 1213 | array( |
| 1214 | 1214 | 'Ticket.Registration.REG_ID' => $this->ID() |
| 1215 | 1215 | ), |
| 1216 | - 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) |
|
| 1216 | + 'order_by' => array('DTT_EVT_start' => 'DESC') |
|
| 1217 | 1217 | ) |
| 1218 | 1218 | ); |
| 1219 | 1219 | } |
@@ -1232,7 +1232,7 @@ discard block |
||
| 1232 | 1232 | array( |
| 1233 | 1233 | 'Ticket.Registration.REG_ID' => $this->ID() |
| 1234 | 1234 | ), |
| 1235 | - 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) |
|
| 1235 | + 'order_by' => array('DTT_EVT_start' => 'ASC') |
|
| 1236 | 1236 | ) |
| 1237 | 1237 | ); |
| 1238 | 1238 | } |
@@ -1251,21 +1251,21 @@ discard block |
||
| 1251 | 1251 | * @return int Integer representing Check-in status. |
| 1252 | 1252 | * @throws \EE_Error |
| 1253 | 1253 | */ |
| 1254 | - public function check_in_status_for_datetime( $DTT_ID = 0, $checkin = null ) { |
|
| 1254 | + public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) { |
|
| 1255 | 1255 | $checkin_query_params = array( |
| 1256 | - 'order_by' => array( 'CHK_timestamp' => 'DESC' ) |
|
| 1256 | + 'order_by' => array('CHK_timestamp' => 'DESC') |
|
| 1257 | 1257 | ); |
| 1258 | 1258 | |
| 1259 | - if ( $DTT_ID > 0 ) { |
|
| 1260 | - $checkin_query_params[0] = array( 'DTT_ID' => $DTT_ID ); |
|
| 1259 | + if ($DTT_ID > 0) { |
|
| 1260 | + $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | 1263 | //get checkin object (if exists) |
| 1264 | 1264 | $checkin = $checkin instanceof EE_Checkin |
| 1265 | 1265 | ? $checkin |
| 1266 | - : $this->get_first_related( 'Checkin', $checkin_query_params ); |
|
| 1267 | - if ( $checkin instanceof EE_Checkin ) { |
|
| 1268 | - if ( $checkin->get( 'CHK_in' ) ) { |
|
| 1266 | + : $this->get_first_related('Checkin', $checkin_query_params); |
|
| 1267 | + if ($checkin instanceof EE_Checkin) { |
|
| 1268 | + if ($checkin->get('CHK_in')) { |
|
| 1269 | 1269 | return EE_Registration::checkin_status_in; //checked in |
| 1270 | 1270 | } |
| 1271 | 1271 | return EE_Registration::checkin_status_out; //had checked in but is now checked out. |
@@ -1281,28 +1281,28 @@ discard block |
||
| 1281 | 1281 | * @param bool $error This just flags that you want an error message returned. This is put in so that the error message can be customized with the attendee name. |
| 1282 | 1282 | * @return string internationalized message |
| 1283 | 1283 | */ |
| 1284 | - public function get_checkin_msg( $DTT_ID, $error = FALSE ) { |
|
| 1284 | + public function get_checkin_msg($DTT_ID, $error = FALSE) { |
|
| 1285 | 1285 | //let's get the attendee first so we can include the name of the attendee |
| 1286 | - $attendee = $this->get_first_related( 'Attendee' ); |
|
| 1287 | - if ( $attendee instanceof EE_Attendee ) { |
|
| 1288 | - if ( $error ) { |
|
| 1289 | - return sprintf( __( "%s's check-in status was not changed.", "event_espresso" ), $attendee->full_name() ); |
|
| 1286 | + $attendee = $this->get_first_related('Attendee'); |
|
| 1287 | + if ($attendee instanceof EE_Attendee) { |
|
| 1288 | + if ($error) { |
|
| 1289 | + return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
| 1290 | 1290 | } |
| 1291 | - $cur_status = $this->check_in_status_for_datetime( $DTT_ID ); |
|
| 1291 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
| 1292 | 1292 | //what is the status message going to be? |
| 1293 | - switch ( $cur_status ) { |
|
| 1293 | + switch ($cur_status) { |
|
| 1294 | 1294 | case EE_Registration::checkin_status_never : |
| 1295 | - return sprintf( __( "%s has been removed from Check-in records", "event_espresso" ), $attendee->full_name() ); |
|
| 1295 | + return sprintf(__("%s has been removed from Check-in records", "event_espresso"), $attendee->full_name()); |
|
| 1296 | 1296 | break; |
| 1297 | 1297 | case EE_Registration::checkin_status_in : |
| 1298 | - return sprintf( __( '%s has been checked in', 'event_espresso' ), $attendee->full_name() ); |
|
| 1298 | + return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
| 1299 | 1299 | break; |
| 1300 | 1300 | case EE_Registration::checkin_status_out : |
| 1301 | - return sprintf( __( '%s has been checked out', 'event_espresso' ), $attendee->full_name() ); |
|
| 1301 | + return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
| 1302 | 1302 | break; |
| 1303 | 1303 | } |
| 1304 | 1304 | } |
| 1305 | - return __( "The check-in status could not be determined.", "event_espresso" ); |
|
| 1305 | + return __("The check-in status could not be determined.", "event_espresso"); |
|
| 1306 | 1306 | } |
| 1307 | 1307 | |
| 1308 | 1308 | |
@@ -1326,7 +1326,7 @@ discard block |
||
| 1326 | 1326 | * get Registration Code |
| 1327 | 1327 | */ |
| 1328 | 1328 | public function reg_code() { |
| 1329 | - return $this->get( 'REG_code' ); |
|
| 1329 | + return $this->get('REG_code'); |
|
| 1330 | 1330 | } |
| 1331 | 1331 | |
| 1332 | 1332 | |
@@ -1335,7 +1335,7 @@ discard block |
||
| 1335 | 1335 | * get Transaction ID |
| 1336 | 1336 | */ |
| 1337 | 1337 | public function transaction_ID() { |
| 1338 | - return $this->get( 'TXN_ID' ); |
|
| 1338 | + return $this->get('TXN_ID'); |
|
| 1339 | 1339 | } |
| 1340 | 1340 | |
| 1341 | 1341 | |
@@ -1344,7 +1344,7 @@ discard block |
||
| 1344 | 1344 | * @return int |
| 1345 | 1345 | */ |
| 1346 | 1346 | public function ticket_ID() { |
| 1347 | - return $this->get( 'TKT_ID' ); |
|
| 1347 | + return $this->get('TKT_ID'); |
|
| 1348 | 1348 | } |
| 1349 | 1349 | |
| 1350 | 1350 | |
@@ -1356,17 +1356,17 @@ discard block |
||
| 1356 | 1356 | * @param string $REG_code Registration Code |
| 1357 | 1357 | * @param boolean $use_default |
| 1358 | 1358 | */ |
| 1359 | - public function set_reg_code( $REG_code, $use_default = FALSE ) { |
|
| 1360 | - if ( empty( $REG_code )) { |
|
| 1361 | - EE_Error::add_error( __( 'REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1359 | + public function set_reg_code($REG_code, $use_default = FALSE) { |
|
| 1360 | + if (empty($REG_code)) { |
|
| 1361 | + EE_Error::add_error(__('REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1362 | 1362 | return; |
| 1363 | 1363 | } |
| 1364 | - if ( ! $this->reg_code() ) { |
|
| 1365 | - parent::set( 'REG_code', $REG_code, $use_default ); |
|
| 1364 | + if ( ! $this->reg_code()) { |
|
| 1365 | + parent::set('REG_code', $REG_code, $use_default); |
|
| 1366 | 1366 | } else { |
| 1367 | 1367 | EE_Error::doing_it_wrong( |
| 1368 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 1369 | - __( 'Can not change a registration REG_code once it has been set.', 'event_espresso' ), |
|
| 1368 | + __CLASS__.'::'.__FUNCTION__, |
|
| 1369 | + __('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
| 1370 | 1370 | '4.6.0' |
| 1371 | 1371 | ); |
| 1372 | 1372 | } |
@@ -1386,17 +1386,17 @@ discard block |
||
| 1386 | 1386 | * @return EE_Registration[] or empty array if this isn't a group registration. |
| 1387 | 1387 | */ |
| 1388 | 1388 | public function get_all_other_registrations_in_group() { |
| 1389 | - if ( $this->group_size() < 2 ) { |
|
| 1389 | + if ($this->group_size() < 2) { |
|
| 1390 | 1390 | return array(); |
| 1391 | 1391 | } |
| 1392 | 1392 | |
| 1393 | 1393 | $query[0] = array( |
| 1394 | 1394 | 'TXN_ID' => $this->transaction_ID(), |
| 1395 | - 'REG_ID' => array( '!=', $this->ID() ), |
|
| 1395 | + 'REG_ID' => array('!=', $this->ID()), |
|
| 1396 | 1396 | 'TKT_ID' => $this->ticket_ID() |
| 1397 | 1397 | ); |
| 1398 | 1398 | |
| 1399 | - $registrations = $this->get_model()->get_all( $query ); |
|
| 1399 | + $registrations = $this->get_model()->get_all($query); |
|
| 1400 | 1400 | return $registrations; |
| 1401 | 1401 | } |
| 1402 | 1402 | |
@@ -1405,14 +1405,14 @@ discard block |
||
| 1405 | 1405 | * @return string |
| 1406 | 1406 | */ |
| 1407 | 1407 | public function get_admin_details_link() { |
| 1408 | - EE_Registry::instance()->load_helper( 'URL' ); |
|
| 1408 | + EE_Registry::instance()->load_helper('URL'); |
|
| 1409 | 1409 | return EEH_URL::add_query_args_and_nonce( |
| 1410 | 1410 | array( |
| 1411 | 1411 | 'page' => 'espresso_registrations', |
| 1412 | 1412 | 'action' => 'view_registration', |
| 1413 | 1413 | '_REG_ID' => $this->ID() |
| 1414 | 1414 | ), |
| 1415 | - admin_url( 'admin.php' ) |
|
| 1415 | + admin_url('admin.php') |
|
| 1416 | 1416 | ); |
| 1417 | 1417 | } |
| 1418 | 1418 | |
@@ -1437,12 +1437,12 @@ discard block |
||
| 1437 | 1437 | * @return string |
| 1438 | 1438 | */ |
| 1439 | 1439 | public function get_admin_overview_link() { |
| 1440 | - EE_Registry::instance()->load_helper( 'URL' ); |
|
| 1440 | + EE_Registry::instance()->load_helper('URL'); |
|
| 1441 | 1441 | return EEH_URL::add_query_args_and_nonce( |
| 1442 | 1442 | array( |
| 1443 | 1443 | 'page' => 'espresso_registrations' |
| 1444 | 1444 | ), |
| 1445 | - admin_url( 'admin.php' ) |
|
| 1445 | + admin_url('admin.php') |
|
| 1446 | 1446 | ); |
| 1447 | 1447 | } |
| 1448 | 1448 | |
@@ -1453,8 +1453,8 @@ discard block |
||
| 1453 | 1453 | * @return \EE_Registration[] |
| 1454 | 1454 | * @throws \EE_Error |
| 1455 | 1455 | */ |
| 1456 | - public function payments( $query_params = array() ) { |
|
| 1457 | - return $this->get_many_related( 'Payment', $query_params ); |
|
| 1456 | + public function payments($query_params = array()) { |
|
| 1457 | + return $this->get_many_related('Payment', $query_params); |
|
| 1458 | 1458 | } |
| 1459 | 1459 | |
| 1460 | 1460 | |
@@ -1464,8 +1464,8 @@ discard block |
||
| 1464 | 1464 | * @return \EE_Registration_Payment[] |
| 1465 | 1465 | * @throws \EE_Error |
| 1466 | 1466 | */ |
| 1467 | - public function registration_payments( $query_params = array() ) { |
|
| 1468 | - return $this->get_many_related( 'Registration_Payment', $query_params ); |
|
| 1467 | + public function registration_payments($query_params = array()) { |
|
| 1468 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
| 1469 | 1469 | } |
| 1470 | 1470 | |
| 1471 | 1471 | |
@@ -1478,7 +1478,7 @@ discard block |
||
| 1478 | 1478 | * @return EE_Payment_Method|null |
| 1479 | 1479 | */ |
| 1480 | 1480 | public function payment_method() { |
| 1481 | - return EEM_Payment_Method::instance()->get_last_used_for_registration( $this ); |
|
| 1481 | + return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
| 1482 | 1482 | } |
| 1483 | 1483 | |
| 1484 | 1484 | |
@@ -1525,7 +1525,7 @@ discard block |
||
| 1525 | 1525 | */ |
| 1526 | 1526 | public function delete() |
| 1527 | 1527 | { |
| 1528 | - if($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
| 1528 | + if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
| 1529 | 1529 | $this->set_status(EEM_Registration::status_id_cancelled); |
| 1530 | 1530 | } |
| 1531 | 1531 | return parent::delete(); |
@@ -6,21 +6,21 @@ discard block |
||
| 6 | 6 | * @subpackage |
| 7 | 7 | * @author Mike Nelson |
| 8 | 8 | */ |
| 9 | -class EE_Datepicker_Input extends EE_Form_Input_Base{ |
|
| 9 | +class EE_Datepicker_Input extends EE_Form_Input_Base { |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * @param array $input_settings |
| 13 | 13 | */ |
| 14 | - function __construct( $input_settings = array() ){ |
|
| 15 | - $this->_set_display_strategy( new EE_Text_Input_Display_Strategy( 'datepicker' ) ); |
|
| 16 | - $this->_set_normalization_strategy( new EE_Text_Normalization() ); |
|
| 14 | + function __construct($input_settings = array()) { |
|
| 15 | + $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('datepicker')); |
|
| 16 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
| 17 | 17 | //we could do better for validation, but at least verify its plaintext |
| 18 | - $this->_add_validation_strategy( new EE_Plaintext_Validation_Strategy( isset( $input_settings[ 'validation_error_message' ] ) ? $input_settings[ 'validation_error_message' ] : NULL ) ); |
|
| 19 | - parent::__construct( $input_settings ); |
|
| 20 | - $this->set_html_class( $this->html_class() . ' datepicker' ); |
|
| 18 | + $this->_add_validation_strategy(new EE_Plaintext_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : NULL)); |
|
| 19 | + parent::__construct($input_settings); |
|
| 20 | + $this->set_html_class($this->html_class().' datepicker'); |
|
| 21 | 21 | // add some style and make it dance |
| 22 | - add_action( 'wp_enqueue_scripts', array( 'EE_Datepicker_Input', 'enqueue_styles_and_scripts' )); |
|
| 23 | - add_action( 'admin_enqueue_scripts', array( 'EE_Datepicker_Input', 'enqueue_styles_and_scripts' )); |
|
| 22 | + add_action('wp_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
|
| 23 | + add_action('admin_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | public static function enqueue_styles_and_scripts() { |
| 35 | 35 | // load css |
| 36 | - wp_register_style( 'espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION ); |
|
| 37 | - wp_enqueue_style( 'espresso-ui-theme'); |
|
| 36 | + wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 37 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |