@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @return EED_Bot_Trap |
19 | 19 | */ |
20 | 20 | public static function instance() { |
21 | - return parent::get_instance( __CLASS__ ); |
|
21 | + return parent::get_instance(__CLASS__); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public static function set_hooks() { |
33 | 33 | if ( |
34 | - apply_filters( 'FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true ) && |
|
34 | + apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) && |
|
35 | 35 | \EE_Registry::instance()->CFG->registration->use_bot_trap |
36 | 36 | ) { |
37 | 37 | \EED_Bot_Trap::set_trap(); |
38 | 38 | // redirect bots to bogus success page |
39 | - \EE_Config::register_route( 'ticket_selection_received', 'EED_Bot_Trap', 'display_bot_trap_success' ); |
|
39 | + \EE_Config::register_route('ticket_selection_received', 'EED_Bot_Trap', 'display_bot_trap_success'); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @return void |
50 | 50 | */ |
51 | 51 | public static function set_trap() { |
52 | - define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . DS); |
|
52 | + define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__).DS); |
|
53 | 53 | add_action( |
54 | 54 | 'AHEE__ticket_selector_chart__template__after_ticket_selector', |
55 | 55 | array('EED_Bot_Trap', 'generate_bot_trap'), |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | } |
82 | 82 | add_action( |
83 | 83 | 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
84 | - array( 'EED_Bot_Trap', 'bot_trap_settings_form' ), |
|
84 | + array('EED_Bot_Trap', 'bot_trap_settings_form'), |
|
85 | 85 | 10 |
86 | 86 | ); |
87 | 87 | add_filter( |
88 | 88 | 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
89 | - array( 'EED_Bot_Trap', 'update_bot_trap_settings_form' ), |
|
89 | + array('EED_Bot_Trap', 'update_bot_trap_settings_form'), |
|
90 | 90 | 10, 1 |
91 | 91 | ); |
92 | 92 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * @param WP $WP |
101 | 101 | * @return void |
102 | 102 | */ |
103 | - public function run( $WP ) {} |
|
103 | + public function run($WP) {} |
|
104 | 104 | |
105 | 105 | |
106 | 106 | |
@@ -111,15 +111,15 @@ discard block |
||
111 | 111 | * @return void |
112 | 112 | */ |
113 | 113 | public static function generate_bot_trap() { |
114 | - $do_not_enter = esc_html__( 'please do not enter anything in this input', 'event_espresso' ); |
|
114 | + $do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso'); |
|
115 | 115 | $time = microtime(true); |
116 | 116 | $html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">'; |
117 | - $html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>'; |
|
118 | - $html .= '<input type="email" id="tkt-slctr-request-processor-email-' . $time .'" name="tkt-slctr-request-processor-email" value=""/>'; |
|
117 | + $html .= '<label for="tkt-slctr-request-processor-email-'.$time.'">'.$do_not_enter.'</label>'; |
|
118 | + $html .= '<input type="email" id="tkt-slctr-request-processor-email-'.$time.'" name="tkt-slctr-request-processor-email" value=""/>'; |
|
119 | 119 | $html .= '<input type="hidden" name="tkt-slctr-request-processor-token" value="'; |
120 | - if ( EE_Registry::instance()->CFG->registration->use_encryption ) { |
|
121 | - EE_Registry::instance()->load_core( 'EE_Encryption' ); |
|
122 | - $html .= EE_Encryption::instance()->encrypt( $time ); |
|
120 | + if (EE_Registry::instance()->CFG->registration->use_encryption) { |
|
121 | + EE_Registry::instance()->load_core('EE_Encryption'); |
|
122 | + $html .= EE_Encryption::instance()->encrypt($time); |
|
123 | 123 | } else { |
124 | 124 | $html .= $time; |
125 | 125 | } |
@@ -137,38 +137,38 @@ discard block |
||
137 | 137 | * It should receive one argument: a boolean indicating |
138 | 138 | * whether the trap was triggered by suspicious timing or not. |
139 | 139 | */ |
140 | - public static function process_bot_trap( $triggered_trap_callback = array() ) { |
|
140 | + public static function process_bot_trap($triggered_trap_callback = array()) { |
|
141 | 141 | // what's your email address Mr. Bot ? |
142 | - $empty_trap = isset( $_REQUEST[ 'tkt-slctr-request-processor-email' ] ) |
|
143 | - && $_REQUEST[ 'tkt-slctr-request-processor-email' ] === '' |
|
142 | + $empty_trap = isset($_REQUEST['tkt-slctr-request-processor-email']) |
|
143 | + && $_REQUEST['tkt-slctr-request-processor-email'] === '' |
|
144 | 144 | ? true |
145 | 145 | : false; |
146 | 146 | // get encrypted timestamp for when the form was originally displayed |
147 | - $bot_trap_timestamp = isset( $_REQUEST[ 'tkt-slctr-request-processor-token' ] ) |
|
148 | - ? sanitize_text_field( $_REQUEST[ 'tkt-slctr-request-processor-token' ] ) |
|
147 | + $bot_trap_timestamp = isset($_REQUEST['tkt-slctr-request-processor-token']) |
|
148 | + ? sanitize_text_field($_REQUEST['tkt-slctr-request-processor-token']) |
|
149 | 149 | : ''; |
150 | 150 | // decrypt and convert to absolute integer |
151 | - if ( EE_Registry::instance()->CFG->registration->use_encryption ) { |
|
152 | - EE_Registry::instance()->load_core( 'EE_Encryption' ); |
|
153 | - $bot_trap_timestamp = absint( EE_Encryption::instance()->decrypt( $bot_trap_timestamp ) ); |
|
151 | + if (EE_Registry::instance()->CFG->registration->use_encryption) { |
|
152 | + EE_Registry::instance()->load_core('EE_Encryption'); |
|
153 | + $bot_trap_timestamp = absint(EE_Encryption::instance()->decrypt($bot_trap_timestamp)); |
|
154 | 154 | } else { |
155 | - $bot_trap_timestamp = absint( $bot_trap_timestamp ); |
|
155 | + $bot_trap_timestamp = absint($bot_trap_timestamp); |
|
156 | 156 | } |
157 | 157 | // ticket form submitted too impossibly fast ( after now ) or more than an hour later ??? |
158 | - $suspicious_timing = $bot_trap_timestamp > time() || $bot_trap_timestamp < ( time() - HOUR_IN_SECONDS ) |
|
158 | + $suspicious_timing = $bot_trap_timestamp > time() || $bot_trap_timestamp < (time() - HOUR_IN_SECONDS) |
|
159 | 159 | ? true |
160 | 160 | : false; |
161 | 161 | // are we human ? |
162 | - if ( $empty_trap && ! $suspicious_timing ) { |
|
162 | + if ($empty_trap && ! $suspicious_timing) { |
|
163 | 163 | do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered'); |
164 | 164 | return; |
165 | 165 | } |
166 | 166 | // check the given callback is valid first before executing |
167 | - if ( ! is_callable($triggered_trap_callback ) ) { |
|
167 | + if ( ! is_callable($triggered_trap_callback)) { |
|
168 | 168 | // invalid callback so lets just sub in our default. |
169 | - $triggered_trap_callback = array( 'EED_Bot_Trap', 'triggered_trap_response' ); |
|
169 | + $triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response'); |
|
170 | 170 | } |
171 | - call_user_func_array($triggered_trap_callback, array( $suspicious_timing ) ); |
|
171 | + call_user_func_array($triggered_trap_callback, array($suspicious_timing)); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | |
@@ -179,15 +179,15 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @param bool $suspicious_timing If true, then the bot trap was triggered due to the suspicious timing test. |
181 | 181 | */ |
182 | - public static function triggered_trap_response( $suspicious_timing ) { |
|
182 | + public static function triggered_trap_response($suspicious_timing) { |
|
183 | 183 | // UH OH... |
184 | 184 | $redirect_url = add_query_arg( |
185 | - array( 'ee' => 'ticket_selection_received' ), |
|
185 | + array('ee' => 'ticket_selection_received'), |
|
186 | 186 | EE_Registry::instance()->CFG->core->reg_page_url() |
187 | 187 | ); |
188 | - if ( $suspicious_timing ) { |
|
188 | + if ($suspicious_timing) { |
|
189 | 189 | $redirect_url = add_query_arg( |
190 | - array( 'ee-notice' => urlencode( esc_html__( 'We\'re sorry, but your ticket selections could not be processed due to a server timing error. Please hit the back button on your browser and try again.', 'event_espresso' ) ) ), |
|
190 | + array('ee-notice' => urlencode(esc_html__('We\'re sorry, but your ticket selections could not be processed due to a server timing error. Please hit the back button on your browser and try again.', 'event_espresso'))), |
|
191 | 191 | $redirect_url |
192 | 192 | ); |
193 | 193 | } |
@@ -218,10 +218,10 @@ discard block |
||
218 | 218 | * @return void |
219 | 219 | */ |
220 | 220 | public static function display_bot_trap_success() { |
221 | - add_filter( 'FHEE__EED_Single_Page_Checkout__run', '__return_false' ); |
|
222 | - $bot_notice = esc_html__( 'Thank you so much. Your ticket selections have been received for consideration.', 'event_espresso' ); |
|
223 | - $bot_notice = isset( $_REQUEST[ 'ee-notice' ] ) && $_REQUEST[ 'ee-notice' ] !== '' ? sanitize_text_field( stripslashes( $_REQUEST[ 'ee-notice' ] ) ) : $bot_notice; |
|
224 | - EE_Registry::instance()->REQ->add_output( EEH_HTML::div( $bot_notice, '', 'ee-attention' ) ); |
|
221 | + add_filter('FHEE__EED_Single_Page_Checkout__run', '__return_false'); |
|
222 | + $bot_notice = esc_html__('Thank you so much. Your ticket selections have been received for consideration.', 'event_espresso'); |
|
223 | + $bot_notice = isset($_REQUEST['ee-notice']) && $_REQUEST['ee-notice'] !== '' ? sanitize_text_field(stripslashes($_REQUEST['ee-notice'])) : $bot_notice; |
|
224 | + EE_Registry::instance()->REQ->add_output(EEH_HTML::div($bot_notice, '', 'ee-attention')); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | |
@@ -256,20 +256,20 @@ discard block |
||
256 | 256 | 'html_id' => 'bot_trap_settings', |
257 | 257 | 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
258 | 258 | 'subsections' => array( |
259 | - 'bot_trap_hdr' => new EE_Form_Section_HTML( EEH_HTML::h2( esc_html__( 'Bot Trap Settings', 'event_espresso' ) ) ), |
|
259 | + 'bot_trap_hdr' => new EE_Form_Section_HTML(EEH_HTML::h2(esc_html__('Bot Trap Settings', 'event_espresso'))), |
|
260 | 260 | 'use_bot_trap' => new EE_Yes_No_Input( |
261 | 261 | array( |
262 | - 'html_label_text' => esc_html__( 'Enable Bot Trap', 'event_espresso' ), |
|
263 | - 'html_help_text' => esc_html__( 'The Event Espresso Bot Trap will insert a fake input into your Ticket Selector forms that is hidden from regular site visitors, but visible to spam bots. Because the input asks for an email address, it is irresistible to spam bots who will of course enter text into it. Since regular site visitors can not see this input, any value detected during form submission means a bot has been detected, which will then be blocked from submitting the form.', 'event_espresso' ), |
|
264 | - 'default' => isset( EE_Registry::instance()->CFG->registration->use_bot_trap ) ? EE_Registry::instance()->CFG->registration->use_bot_trap : true, |
|
262 | + 'html_label_text' => esc_html__('Enable Bot Trap', 'event_espresso'), |
|
263 | + 'html_help_text' => esc_html__('The Event Espresso Bot Trap will insert a fake input into your Ticket Selector forms that is hidden from regular site visitors, but visible to spam bots. Because the input asks for an email address, it is irresistible to spam bots who will of course enter text into it. Since regular site visitors can not see this input, any value detected during form submission means a bot has been detected, which will then be blocked from submitting the form.', 'event_espresso'), |
|
264 | + 'default' => isset(EE_Registry::instance()->CFG->registration->use_bot_trap) ? EE_Registry::instance()->CFG->registration->use_bot_trap : true, |
|
265 | 265 | 'required' => false |
266 | 266 | ) |
267 | 267 | ), |
268 | 268 | 'use_encryption' => new EE_Yes_No_Input( |
269 | 269 | array( |
270 | - 'html_label_text' => esc_html__( 'Encrypt Bot Trap Data', 'event_espresso' ), |
|
271 | - 'html_help_text' => esc_html__( 'One way to detect spam bots is by looking at how long it takes them to submit a form. They are often inhumanly fast, or will submit forms hours, days, or even weeks after the form was first scraped off the web. The Event Espresso Bot Trap will send a timestamp with the Ticket Selector form when it is submitted. By default, this timestamp is encrypted so that the spam bots can not change it, but encryption may cause issues on some servers due to configuration "conflicts". If you continuously get caught in the bot trap, then try setting this option to "No". This may increase the number of spam submissions you receive, but increases server compatibility.', 'event_espresso' ), |
|
272 | - 'default' => isset( EE_Registry::instance()->CFG->registration->use_encryption ) ? EE_Registry::instance()->CFG->registration->use_encryption : true, |
|
270 | + 'html_label_text' => esc_html__('Encrypt Bot Trap Data', 'event_espresso'), |
|
271 | + 'html_help_text' => esc_html__('One way to detect spam bots is by looking at how long it takes them to submit a form. They are often inhumanly fast, or will submit forms hours, days, or even weeks after the form was first scraped off the web. The Event Espresso Bot Trap will send a timestamp with the Ticket Selector form when it is submitted. By default, this timestamp is encrypted so that the spam bots can not change it, but encryption may cause issues on some servers due to configuration "conflicts". If you continuously get caught in the bot trap, then try setting this option to "No". This may increase the number of spam submissions you receive, but increases server compatibility.', 'event_espresso'), |
|
272 | + 'default' => isset(EE_Registry::instance()->CFG->registration->use_encryption) ? EE_Registry::instance()->CFG->registration->use_encryption : true, |
|
273 | 273 | 'required' => false |
274 | 274 | ) |
275 | 275 | ), |
@@ -287,30 +287,30 @@ discard block |
||
287 | 287 | * @param \EE_Registration_Config $EE_Registration_Config |
288 | 288 | * @return \EE_Registration_Config |
289 | 289 | */ |
290 | - public static function update_bot_trap_settings_form( EE_Registration_Config $EE_Registration_Config ) { |
|
290 | + public static function update_bot_trap_settings_form(EE_Registration_Config $EE_Registration_Config) { |
|
291 | 291 | try { |
292 | 292 | $bot_trap_settings_form = EED_Bot_Trap::_bot_trap_settings_form(); |
293 | 293 | // if not displaying a form, then check for form submission |
294 | - if ( $bot_trap_settings_form->was_submitted() ) { |
|
294 | + if ($bot_trap_settings_form->was_submitted()) { |
|
295 | 295 | // capture form data |
296 | 296 | $bot_trap_settings_form->receive_form_submission(); |
297 | 297 | // validate form data |
298 | - if ( $bot_trap_settings_form->is_valid() ) { |
|
298 | + if ($bot_trap_settings_form->is_valid()) { |
|
299 | 299 | // grab validated data from form |
300 | 300 | $valid_data = $bot_trap_settings_form->valid_data(); |
301 | - if ( isset( $valid_data[ 'use_bot_trap' ], $valid_data[ 'use_encryption' ] ) ) { |
|
302 | - $EE_Registration_Config->use_bot_trap = $valid_data[ 'use_bot_trap' ]; |
|
303 | - $EE_Registration_Config->use_encryption = $valid_data[ 'use_encryption' ]; |
|
301 | + if (isset($valid_data['use_bot_trap'], $valid_data['use_encryption'])) { |
|
302 | + $EE_Registration_Config->use_bot_trap = $valid_data['use_bot_trap']; |
|
303 | + $EE_Registration_Config->use_encryption = $valid_data['use_encryption']; |
|
304 | 304 | } else { |
305 | - EE_Error::add_error( esc_html__( 'Invalid or missing Bot Trap settings. Please refresh the form and try again.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
305 | + EE_Error::add_error(esc_html__('Invalid or missing Bot Trap settings. Please refresh the form and try again.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
306 | 306 | } |
307 | 307 | } else { |
308 | - if ( $bot_trap_settings_form->submission_error_message() != '' ) { |
|
309 | - EE_Error::add_error( $bot_trap_settings_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__ ); |
|
308 | + if ($bot_trap_settings_form->submission_error_message() != '') { |
|
309 | + EE_Error::add_error($bot_trap_settings_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | } |
313 | - } catch ( EE_Error $e ) { |
|
313 | + } catch (EE_Error $e) { |
|
314 | 314 | $e->get_error(); |
315 | 315 | } |
316 | 316 | return $EE_Registration_Config; |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | * @access public |
51 | 51 | * @param \WP $WP |
52 | 52 | */ |
53 | - public function run( WP $WP ) { |
|
54 | - add_filter( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' ); |
|
53 | + public function run(WP $WP) { |
|
54 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | * @param array $attributes |
63 | 63 | * @return string |
64 | 64 | */ |
65 | - public function process_shortcode( $attributes = array() ) { |
|
66 | - extract( $attributes ); |
|
67 | - $event_id = isset( $event_id ) ? $event_id : 0; |
|
68 | - $event = EE_Registry::instance()->load_model( 'Event' )->get_one_by_ID( $event_id ); |
|
65 | + public function process_shortcode($attributes = array()) { |
|
66 | + extract($attributes); |
|
67 | + $event_id = isset($event_id) ? $event_id : 0; |
|
68 | + $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id); |
|
69 | 69 | ob_start(); |
70 | - do_action( 'AHEE_event_details_before_post', $event_id ); |
|
71 | - espresso_ticket_selector( $event ); |
|
72 | - do_action( 'AHEE_event_details_after_post' ); |
|
70 | + do_action('AHEE_event_details_before_post', $event_id); |
|
71 | + espresso_ticket_selector($event); |
|
72 | + do_action('AHEE_event_details_after_post'); |
|
73 | 73 | return ob_get_clean(); |
74 | 74 | } |
75 | 75 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * |
26 | 26 | * ------------------------------------------------------------------------ |
27 | 27 | */ |
28 | -class EEG_Paypal_Pro extends EE_Onsite_Gateway{ |
|
28 | +class EEG_Paypal_Pro extends EE_Onsite_Gateway { |
|
29 | 29 | /** |
30 | 30 | * |
31 | 31 | * @var $_paypal_api_username string |
@@ -88,30 +88,30 @@ discard block |
||
88 | 88 | * } @see parent::do_direct_payment for more info |
89 | 89 | * @return \EE_Payment|\EEI_Payment |
90 | 90 | */ |
91 | - public function do_direct_payment($payment,$billing_info = null){ |
|
91 | + public function do_direct_payment($payment, $billing_info = null) { |
|
92 | 92 | $transaction = $payment->transaction(); |
93 | 93 | $primary_registrant = $transaction->primary_registration(); |
94 | - $order_description = $this->_format_order_description( $payment ); |
|
94 | + $order_description = $this->_format_order_description($payment); |
|
95 | 95 | //charge for the full amount. Show itemized list |
96 | - if( $this->_can_easily_itemize_transaction_for( $payment ) ){ |
|
96 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
97 | 97 | $item_num = 1; |
98 | 98 | $total_line_item = $transaction->total_line_item(); |
99 | 99 | $order_items = array(); |
100 | 100 | foreach ($total_line_item->get_items() as $line_item) { |
101 | 101 | //ignore line items with a quantity of 0 |
102 | - if( $line_item->quantity() == 0 ) { |
|
102 | + if ($line_item->quantity() == 0) { |
|
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | $item = array( |
106 | 106 | // Item Name. 127 char max. |
107 | 107 | 'l_name' => substr( |
108 | - $this->_format_line_item_name( $line_item, $payment ), |
|
108 | + $this->_format_line_item_name($line_item, $payment), |
|
109 | 109 | 0, |
110 | 110 | 127 |
111 | 111 | ), |
112 | 112 | // Item description. 127 char max. |
113 | 113 | 'l_desc' => substr( |
114 | - $this->_format_line_item_desc( $line_item, $payment ), |
|
114 | + $this->_format_line_item_desc($line_item, $payment), |
|
115 | 115 | 0, |
116 | 116 | 127 |
117 | 117 | ), |
@@ -135,20 +135,20 @@ discard block |
||
135 | 135 | } |
136 | 136 | $item_amount = $total_line_item->get_items_total(); |
137 | 137 | $tax_amount = $total_line_item->get_total_tax(); |
138 | - }else{ |
|
138 | + } else { |
|
139 | 139 | $order_items = array(); |
140 | 140 | $item_amount = $payment->amount(); |
141 | 141 | $tax_amount = 0; |
142 | - array_push($order_items,array( |
|
142 | + array_push($order_items, array( |
|
143 | 143 | // Item Name. 127 char max. |
144 | 144 | 'l_name' => substr( |
145 | - $this->_format_partial_payment_line_item_name( $payment ), |
|
145 | + $this->_format_partial_payment_line_item_name($payment), |
|
146 | 146 | 0, |
147 | 147 | 127 |
148 | 148 | ), |
149 | 149 | // Item description. 127 char max. |
150 | 150 | 'l_desc' => substr( |
151 | - $this->_format_partial_payment_line_item_desc( $payment ), |
|
151 | + $this->_format_partial_payment_line_item_desc($payment), |
|
152 | 152 | 0, |
153 | 153 | 127 |
154 | 154 | ), |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | // Payer's salutation. 20 char max. |
197 | 197 | 'salutation' => '', |
198 | 198 | // Payer's first name. 25 char max. |
199 | - 'firstname' => substr($billing_info['first_name'],0,25), |
|
199 | + 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
200 | 200 | // Payer's middle name. 25 char max. |
201 | 201 | 'middlename' => '', |
202 | 202 | // Payer's last name. 25 char max. |
203 | - 'lastname' => substr($billing_info['last_name'],0,25), |
|
203 | + 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
204 | 204 | // Payer's suffix. 12 char max. |
205 | 205 | 'suffix' => '' |
206 | 206 | ); |
@@ -213,13 +213,13 @@ discard block |
||
213 | 213 | // Required. Name of City. |
214 | 214 | 'city' => $billing_info['city'], |
215 | 215 | // Required. Name of State or Province. |
216 | - 'state' => substr( $billing_info['state'], 0, 40 ), |
|
216 | + 'state' => substr($billing_info['state'], 0, 40), |
|
217 | 217 | // Required. Country code. |
218 | 218 | 'countrycode' => $billing_info['country'], |
219 | 219 | // Required. Postal code of payer. |
220 | 220 | 'zip' => $billing_info['zip'], |
221 | 221 | // Phone Number of payer. 20 char max. |
222 | - 'shiptophonenum' => substr($billing_info['phone'],0,20) |
|
222 | + 'shiptophonenum' => substr($billing_info['phone'], 0, 20) |
|
223 | 223 | ); |
224 | 224 | |
225 | 225 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | // Required. Three-letter currency code. Default is USD. |
230 | 230 | 'currencycode' => $payment->currency_code(), |
231 | 231 | // Required if you include itemized cart details. (L_AMTn, etc.) Subtotal of items not including S&H, or tax. |
232 | - 'itemamt' => $this->format_currency($item_amount),// |
|
232 | + 'itemamt' => $this->format_currency($item_amount), // |
|
233 | 233 | // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
234 | 234 | 'shippingamt' => '', |
235 | 235 | // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
@@ -241,10 +241,10 @@ discard block |
||
241 | 241 | // Free-form field for your own use. 256 char max. |
242 | 242 | 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
243 | 243 | // Your own invoice or tracking number |
244 | - 'invnum' => wp_generate_password(12,false),//$transaction->ID(), |
|
244 | + 'invnum' => wp_generate_password(12, false), //$transaction->ID(), |
|
245 | 245 | // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
246 | 246 | 'notifyurl' => '', |
247 | - 'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this |
|
247 | + 'buttonsource' => 'EventEspresso_SP', //EE will blow up if you change this |
|
248 | 248 | ); |
249 | 249 | // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
250 | 250 | $PayPalRequestData = array( |
@@ -257,32 +257,32 @@ discard block |
||
257 | 257 | 'OrderItems' => $order_items, |
258 | 258 | ); |
259 | 259 | $this->_log_clean_request($PayPalRequestData, $payment); |
260 | - try{ |
|
260 | + try { |
|
261 | 261 | $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
262 | 262 | //remove PCI-sensitive data so it doesn't get stored |
263 | - $PayPalResult = $this->_log_clean_response($PayPalResult,$payment); |
|
263 | + $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
264 | 264 | |
265 | 265 | $message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK']; |
266 | - if( empty($PayPalResult[ 'RAWRESPONSE' ] ) ) { |
|
267 | - $payment->set_status( $this->_pay_model->failed_status() ) ; |
|
268 | - $payment->set_gateway_response( __( 'No response received from Paypal Pro', 'event_espresso' ) ); |
|
266 | + if (empty($PayPalResult['RAWRESPONSE'])) { |
|
267 | + $payment->set_status($this->_pay_model->failed_status()); |
|
268 | + $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
269 | 269 | $payment->set_details($PayPalResult); |
270 | - }else{ |
|
271 | - if($this->_APICallSuccessful($PayPalResult)){ |
|
270 | + } else { |
|
271 | + if ($this->_APICallSuccessful($PayPalResult)) { |
|
272 | 272 | $payment->set_status($this->_pay_model->approved_status()); |
273 | - }else{ |
|
273 | + } else { |
|
274 | 274 | $payment->set_status($this->_pay_model->declined_status()); |
275 | 275 | } |
276 | 276 | //make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
277 | - $payment->set_amount(isset($PayPalResult['AMT']) ? floatval( $PayPalResult['AMT'] ) : 0); |
|
277 | + $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
278 | 278 | $payment->set_gateway_response($message); |
279 | - $payment->set_txn_id_chq_nmbr(isset( $PayPalResult['TRANSACTIONID'] )? $PayPalResult['TRANSACTIONID'] : null); |
|
279 | + $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) ? $PayPalResult['TRANSACTIONID'] : null); |
|
280 | 280 | |
281 | 281 | $primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : ''; |
282 | 282 | $payment->set_extra_accntng($primary_registration_code); |
283 | 283 | $payment->set_details($PayPalResult); |
284 | 284 | } |
285 | - }catch(Exception $e){ |
|
285 | + } catch (Exception $e) { |
|
286 | 286 | $payment->set_status($this->_pay_model->failed_status()); |
287 | 287 | $payment->set_gateway_response($e->getMessage()); |
288 | 288 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @param EEI_Payment $payment |
300 | 300 | * @return array |
301 | 301 | */ |
302 | - private function _log_clean_request($request,$payment){ |
|
302 | + private function _log_clean_request($request, $payment) { |
|
303 | 303 | $cleaned_request_data = $request; |
304 | 304 | unset($cleaned_request_data['CCDetails']['acct']); |
305 | 305 | unset($cleaned_request_data['CCDetails']['cvv2']); |
@@ -315,13 +315,13 @@ discard block |
||
315 | 315 | * @param EEI_Payment $payment |
316 | 316 | * @return array cleaned |
317 | 317 | */ |
318 | - private function _log_clean_response($response,$payment){ |
|
318 | + private function _log_clean_response($response, $payment) { |
|
319 | 319 | unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
320 | 320 | unset($response['REQUESTDATA']['ACCT']); |
321 | 321 | unset($response['REQUESTDATA']['EXPDATE']); |
322 | 322 | unset($response['REQUESTDATA']['CVV2']); |
323 | 323 | unset($response['RAWREQUEST']); |
324 | - $this->log(array('Paypal Response'=>$response),$payment); |
|
324 | + $this->log(array('Paypal Response'=>$response), $payment); |
|
325 | 325 | return $response; |
326 | 326 | } |
327 | 327 | |
@@ -346,32 +346,32 @@ discard block |
||
346 | 346 | // DP Fields |
347 | 347 | $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
348 | 348 | foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) |
349 | - $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
349 | + $DPFieldsNVP .= '&'.strtoupper($DPFieldsVar).'='.urlencode($DPFieldsVal); |
|
350 | 350 | |
351 | 351 | // CC Details Fields |
352 | 352 | $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
353 | 353 | foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) |
354 | - $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
354 | + $CCDetailsNVP .= '&'.strtoupper($CCDetailsVar).'='.urlencode($CCDetailsVal); |
|
355 | 355 | |
356 | 356 | // PayerInfo Type Fields |
357 | 357 | $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
358 | 358 | foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) |
359 | - $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
359 | + $PayerInfoNVP .= '&'.strtoupper($PayerInfoVar).'='.urlencode($PayerInfoVal); |
|
360 | 360 | |
361 | 361 | // Payer Name Fields |
362 | 362 | $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
363 | 363 | foreach ($PayerName as $PayerNameVar => $PayerNameVal) |
364 | - $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
364 | + $PayerNameNVP .= '&'.strtoupper($PayerNameVar).'='.urlencode($PayerNameVal); |
|
365 | 365 | |
366 | 366 | // Address Fields (Billing) |
367 | 367 | $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
368 | 368 | foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) |
369 | - $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
369 | + $BillingAddressNVP .= '&'.strtoupper($BillingAddressVar).'='.urlencode($BillingAddressVal); |
|
370 | 370 | |
371 | 371 | // Payment Details Type Fields |
372 | 372 | $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
373 | 373 | foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) |
374 | - $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
374 | + $PaymentDetailsNVP .= '&'.strtoupper($PaymentDetailsVar).'='.urlencode($PaymentDetailsVal); |
|
375 | 375 | |
376 | 376 | // Payment Details Item Type Fields |
377 | 377 | $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
@@ -379,22 +379,22 @@ discard block |
||
379 | 379 | foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
380 | 380 | $CurrentItem = $OrderItems[$OrderItemsVar]; |
381 | 381 | foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) |
382 | - $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
382 | + $OrderItemsNVP .= '&'.strtoupper($CurrentItemVar).$n.'='.urlencode($CurrentItemVal); |
|
383 | 383 | $n++; |
384 | 384 | } |
385 | 385 | |
386 | 386 | // Ship To Address Fields |
387 | 387 | $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
388 | 388 | foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) |
389 | - $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
389 | + $ShippingAddressNVP .= '&'.strtoupper($ShippingAddressVar).'='.urlencode($ShippingAddressVal); |
|
390 | 390 | |
391 | 391 | // 3D Secure Fields |
392 | 392 | $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
393 | 393 | foreach ($Secure3D as $Secure3DVar => $Secure3DVal) |
394 | - $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
394 | + $Secure3DNVP .= '&'.strtoupper($Secure3DVar).'='.urlencode($Secure3DVal); |
|
395 | 395 | |
396 | 396 | // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
397 | - $NVPRequest = 'USER=' . $this->_username . '&PWD=' . $this->_password . '&VERSION=64.0' . '&SIGNATURE=' . $this->_signature . $DPFieldsNVP . $CCDetailsNVP . $PayerInfoNVP . $PayerNameNVP . $BillingAddressNVP . $PaymentDetailsNVP . $OrderItemsNVP . $ShippingAddressNVP . $Secure3DNVP; |
|
397 | + $NVPRequest = 'USER='.$this->_username.'&PWD='.$this->_password.'&VERSION=64.0'.'&SIGNATURE='.$this->_signature.$DPFieldsNVP.$CCDetailsNVP.$PayerInfoNVP.$PayerNameNVP.$BillingAddressNVP.$PaymentDetailsNVP.$OrderItemsNVP.$ShippingAddressNVP.$Secure3DNVP; |
|
398 | 398 | $NVPResponse = $this->_CURLRequest($NVPRequest); |
399 | 399 | $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
400 | 400 | $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | private function _CURLRequest($Request) { |
419 | 419 | $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
420 | 420 | $curl = curl_init(); |
421 | - curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', TRUE ) ); |
|
421 | + curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', TRUE)); |
|
422 | 422 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); |
423 | 423 | curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
424 | 424 | curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
@@ -468,9 +468,9 @@ discard block |
||
468 | 468 | private function _APICallSuccessful($PayPalResult) { |
469 | 469 | $approved = false; |
470 | 470 | // check main response message from PayPal |
471 | - if (isset($PayPalResult['ACK']) && !empty($PayPalResult['ACK'])) { |
|
471 | + if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
472 | 472 | $ack = strtoupper($PayPalResult['ACK']); |
473 | - $approved = ( $ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS' ) ? true : false; |
|
473 | + $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | return $approved; |
@@ -486,11 +486,11 @@ discard block |
||
486 | 486 | |
487 | 487 | $Errors = array(); |
488 | 488 | $n = 0; |
489 | - while (isset($DataArray['L_ERRORCODE' . $n . ''])) { |
|
490 | - $LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : ''; |
|
491 | - $LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . '']) ? $DataArray['L_SHORTMESSAGE' . $n . ''] : ''; |
|
492 | - $LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . '']) ? $DataArray['L_LONGMESSAGE' . $n . ''] : ''; |
|
493 | - $LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . '']) ? $DataArray['L_SEVERITYCODE' . $n . ''] : ''; |
|
489 | + while (isset($DataArray['L_ERRORCODE'.$n.''])) { |
|
490 | + $LErrorCode = isset($DataArray['L_ERRORCODE'.$n.'']) ? $DataArray['L_ERRORCODE'.$n.''] : ''; |
|
491 | + $LShortMessage = isset($DataArray['L_SHORTMESSAGE'.$n.'']) ? $DataArray['L_SHORTMESSAGE'.$n.''] : ''; |
|
492 | + $LLongMessage = isset($DataArray['L_LONGMESSAGE'.$n.'']) ? $DataArray['L_LONGMESSAGE'.$n.''] : ''; |
|
493 | + $LSeverityCode = isset($DataArray['L_SEVERITYCODE'.$n.'']) ? $DataArray['L_SEVERITYCODE'.$n.''] : ''; |
|
494 | 494 | |
495 | 495 | $CurrentItem = array( |
496 | 496 | 'L_ERRORCODE' => $LErrorCode, |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | elseif ($CurrentErrorVar == 'L_SEVERITYCODE') |
531 | 531 | $CurrentVarName = 'Severity Code'; |
532 | 532 | |
533 | - $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
533 | + $error .= '<br />'.$CurrentVarName.': '.$CurrentErrorVal; |
|
534 | 534 | } |
535 | 535 | } |
536 | 536 | return $error; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @return EED_Ticket_Selector_Caff |
17 | 17 | */ |
18 | 18 | public static function instance() { |
19 | - return parent::get_instance( __CLASS__ ); |
|
19 | + return parent::get_instance(__CLASS__); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | * @return void |
38 | 38 | */ |
39 | 39 | public static function set_hooks_admin() { |
40 | - define( 'TICKET_SELECTOR_CAFF_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS ); |
|
41 | - add_action( 'AHEE__template_settings__template__before_settings_form', array( 'EED_Ticket_Selector_Caff', 'template_settings_form' ), 10 ); |
|
42 | - add_filter( 'FHEE__General_Settings_Admin_Page__update_template_settings__data', array( 'EED_Ticket_Selector_Caff', 'update_template_settings' ), 10, 2 ); |
|
40 | + define('TICKET_SELECTOR_CAFF_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS); |
|
41 | + add_action('AHEE__template_settings__template__before_settings_form', array('EED_Ticket_Selector_Caff', 'template_settings_form'), 10); |
|
42 | + add_filter('FHEE__General_Settings_Admin_Page__update_template_settings__data', array('EED_Ticket_Selector_Caff', 'update_template_settings'), 10, 2); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
46 | 46 | //just required because of abstract declaration |
47 | - public function run( $WP ) { |
|
47 | + public function run($WP) { |
|
48 | 48 | $this->set_config(); |
49 | 49 | } |
50 | 50 | |
51 | 51 | |
52 | 52 | |
53 | 53 | |
54 | - protected function set_config(){ |
|
55 | - $this->set_config_section( 'template_settings' ); |
|
56 | - $this->set_config_class( 'EE_Ticket_Selector_Config' ); |
|
57 | - $this->set_config_name( 'EED_Ticket_Selector' ); |
|
54 | + protected function set_config() { |
|
55 | + $this->set_config_section('template_settings'); |
|
56 | + $this->set_config_class('EE_Ticket_Selector_Config'); |
|
57 | + $this->set_config_name('EED_Ticket_Selector'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | 'FHEE__EED_Ticket_Selector_Caff___ticket_selector_settings_form__form_subsections', |
88 | 88 | array( |
89 | 89 | 'appearance_settings_hdr' => new EE_Form_Section_HTML( |
90 | - EEH_HTML::br(2) . |
|
91 | - EEH_HTML::h2( __( 'Ticket Selector Template Settings', 'event_espresso' )) |
|
90 | + EEH_HTML::br(2). |
|
91 | + EEH_HTML::h2(__('Ticket Selector Template Settings', 'event_espresso')) |
|
92 | 92 | ), |
93 | 93 | 'appearance_settings' => EED_Ticket_Selector_Caff::_ticket_selector_appearance_settings() |
94 | 94 | ) |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | array( |
114 | 114 | 'show_ticket_details' => new EE_Yes_No_Input( |
115 | 115 | array( |
116 | - 'html_label_text' => __('Show Ticket Details?', 'event_espresso' ), |
|
117 | - 'html_help_text' => __( 'This lets you choose whether the extra ticket details section is displayed with the ticket selector.', 'event_espresso'), |
|
118 | - 'default' => isset( EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_ticket_details ) |
|
116 | + 'html_label_text' => __('Show Ticket Details?', 'event_espresso'), |
|
117 | + 'html_help_text' => __('This lets you choose whether the extra ticket details section is displayed with the ticket selector.', 'event_espresso'), |
|
118 | + 'default' => isset(EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_ticket_details) |
|
119 | 119 | ? EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_ticket_details |
120 | 120 | : true, |
121 | 121 | 'display_html_label_text' => false |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | ), |
124 | 124 | 'show_ticket_sale_columns' => new EE_Yes_No_Input( |
125 | 125 | array( |
126 | - 'html_label_text' => __('Show Ticket Sale Info?', 'event_espresso' ), |
|
127 | - 'html_help_text' => __( 'This lets you indicate whether information about ticket sales is shown with ticket details in the ticket selector.', 'event_espresso'), |
|
128 | - 'default' => isset( EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_ticket_sale_columns ) |
|
126 | + 'html_label_text' => __('Show Ticket Sale Info?', 'event_espresso'), |
|
127 | + 'html_help_text' => __('This lets you indicate whether information about ticket sales is shown with ticket details in the ticket selector.', 'event_espresso'), |
|
128 | + 'default' => isset(EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_ticket_sale_columns) |
|
129 | 129 | ? EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_ticket_sale_columns |
130 | 130 | : true, |
131 | 131 | 'display_html_label_text' => false |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | ), |
134 | 134 | 'show_expired_tickets' => new EE_Yes_No_Input( |
135 | 135 | array( |
136 | - 'html_label_text' => __( 'Show Expired Tickets?', 'event_espresso' ), |
|
137 | - 'html_help_text' => __( 'Indicate whether to show expired tickets in the ticket selector', 'event_espresso' ), |
|
138 | - 'default' => isset( EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets ) |
|
136 | + 'html_label_text' => __('Show Expired Tickets?', 'event_espresso'), |
|
137 | + 'html_help_text' => __('Indicate whether to show expired tickets in the ticket selector', 'event_espresso'), |
|
138 | + 'default' => isset(EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) |
|
139 | 139 | ? EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets |
140 | 140 | : true, |
141 | 141 | 'display_html_label_text' => false |
@@ -158,21 +158,21 @@ discard block |
||
158 | 158 | * @param array $REQ incoming request |
159 | 159 | * @return EE_Template_Config |
160 | 160 | */ |
161 | - public static function update_template_settings( EE_Template_Config $CFG, $REQ ) { |
|
162 | - if ( ! isset( $CFG->EED_Ticket_Selector ) ) { |
|
161 | + public static function update_template_settings(EE_Template_Config $CFG, $REQ) { |
|
162 | + if ( ! isset($CFG->EED_Ticket_Selector)) { |
|
163 | 163 | $CFG->EED_Ticket_Selector = new EE_Ticket_Selector_Config(); |
164 | 164 | } |
165 | 165 | try { |
166 | 166 | $ticket_selector_form = EED_Ticket_Selector_Caff::_ticket_selector_settings_form(); |
167 | 167 | |
168 | 168 | //check for form submission |
169 | - if ( $ticket_selector_form->was_submitted() ) { |
|
169 | + if ($ticket_selector_form->was_submitted()) { |
|
170 | 170 | |
171 | 171 | //capture form data |
172 | 172 | $ticket_selector_form->receive_form_submission(); |
173 | 173 | |
174 | 174 | //validate form data |
175 | - if ( $ticket_selector_form->is_valid() ) { |
|
175 | + if ($ticket_selector_form->is_valid()) { |
|
176 | 176 | |
177 | 177 | //grab validated data from form |
178 | 178 | $valid_data = $ticket_selector_form->valid_data(); |
@@ -182,13 +182,13 @@ discard block |
||
182 | 182 | $CFG->EED_Ticket_Selector->show_ticket_details = $valid_data['appearance_settings']['show_ticket_details']; |
183 | 183 | $CFG->EED_Ticket_Selector->show_expired_tickets = $valid_data['appearance_settings']['show_expired_tickets']; |
184 | 184 | } else { |
185 | - if ( $ticket_selector_form->submission_error_message() !== '' ) { |
|
186 | - EE_Error::add_error( $ticket_selector_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__ ); |
|
185 | + if ($ticket_selector_form->submission_error_message() !== '') { |
|
186 | + EE_Error::add_error($ticket_selector_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | } |
191 | - } catch( EE_Error $e ) { |
|
191 | + } catch (EE_Error $e) { |
|
192 | 192 | $e->get_error(); |
193 | 193 | } |
194 | 194 |
@@ -21,8 +21,8 @@ |
||
21 | 21 | |
22 | 22 | |
23 | 23 | <div id="postbox-container-2" class="postbox-container"> |
24 | - <?php do_meta_boxes( $current_page, 'normal', NULL ); ?> |
|
25 | - <?php do_meta_boxes( $current_page, 'advanced', NULL ); ?> |
|
24 | + <?php do_meta_boxes($current_page, 'normal', NULL); ?> |
|
25 | + <?php do_meta_boxes($current_page, 'advanced', NULL); ?> |
|
26 | 26 | </div> |
27 | 27 | <!-- postbox-container-2 --> |
28 | 28 | <div class="clear"></div> |
@@ -259,7 +259,7 @@ |
||
259 | 259 | * @param int $ID |
260 | 260 | * @param $shortcode_class |
261 | 261 | * @param $shortcode_posts |
262 | - * @param $page_for_posts |
|
262 | + * @param string $page_for_posts |
|
263 | 263 | * @param bool $update_post_shortcodes |
264 | 264 | * @return bool |
265 | 265 | */ |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | namespace EventEspresso\core\admin; |
3 | 3 | |
4 | 4 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
5 | - exit( 'No direct script access allowed' ); |
|
5 | + exit( 'No direct script access allowed' ); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -19,450 +19,450 @@ discard block |
||
19 | 19 | class PostShortcodeTracking |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * set_hooks_admin |
|
24 | - * |
|
25 | - * @access public |
|
26 | - */ |
|
27 | - public static function set_hooks_admin() |
|
28 | - { |
|
29 | - add_action( |
|
30 | - 'save_post', |
|
31 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'parse_post_content_on_save' ), |
|
32 | - 100, |
|
33 | - 2 |
|
34 | - ); |
|
35 | - add_action( |
|
36 | - 'delete_post', |
|
37 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'unset_post_shortcodes_on_delete' ), |
|
38 | - 100, |
|
39 | - 1 |
|
40 | - ); |
|
41 | - add_action( |
|
42 | - 'add_option_page_for_posts', |
|
43 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_initial_set' ), |
|
44 | - 100, |
|
45 | - 2 |
|
46 | - ); |
|
47 | - add_action( |
|
48 | - 'update_option', |
|
49 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_change' ), |
|
50 | - 100, |
|
51 | - 3 |
|
52 | - ); |
|
53 | - add_action( |
|
54 | - 'delete_option', |
|
55 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_delete' ), |
|
56 | - 100, |
|
57 | - 1 |
|
58 | - ); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * parse_post_content_on_save |
|
65 | - * any time a post is saved, we need to check for any EE shortcodes that may be embedded in the content, |
|
66 | - * and then track what posts those shortcodes are on, so that we can initialize shortcodes well before |
|
67 | - * the_content() runs. this allows us to do things like enqueue scripts for shortcodes ONLY on the pages the |
|
68 | - * shortcodes are actually used on |
|
69 | - * |
|
70 | - * @access public |
|
71 | - * @param int $post_ID |
|
72 | - * @param \WP_Post $post |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public static function parse_post_content_on_save( $post_ID, $post ) |
|
76 | - { |
|
77 | - // if the post is trashed, then let's remove our post shortcode tracking |
|
78 | - if ( $post instanceof \WP_Post && $post->post_status === 'trash' ) { |
|
79 | - PostShortcodeTracking::unset_post_shortcodes_on_delete( $post_ID ); |
|
80 | - return; |
|
81 | - } |
|
82 | - // default post types |
|
83 | - $post_types = array( 'post' => 0, 'page' => 1 ); |
|
84 | - // add CPTs |
|
85 | - $CPTs = \EE_Register_CPTs::get_CPTs(); |
|
86 | - $post_types = array_merge( $post_types, $CPTs ); |
|
87 | - // for default or CPT posts... |
|
88 | - if ( isset( $post_types[ $post->post_type ] ) ) { |
|
89 | - // post on frontpage ? |
|
90 | - $page_for_posts = \EE_Config::get_page_for_posts(); |
|
91 | - if ( $post->post_name === $page_for_posts ) { |
|
92 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( $page_for_posts ); |
|
93 | - return; |
|
94 | - } |
|
95 | - // array of shortcodes indexed by post name |
|
96 | - \EE_Registry::CFG()->core->post_shortcodes = isset( \EE_Registry::CFG()->core->post_shortcodes ) |
|
97 | - ? \EE_Registry::CFG()->core->post_shortcodes |
|
98 | - : array(); |
|
99 | - // whether to proceed with update |
|
100 | - $update_post_shortcodes = false; |
|
101 | - // empty both arrays |
|
102 | - \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ] = array(); |
|
103 | - // check that posts page is already being tracked |
|
104 | - if ( ! isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] ) ) { |
|
105 | - // if not, then ensure that it is properly added |
|
106 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
107 | - } |
|
108 | - // loop thru shortcodes |
|
109 | - foreach ( \EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir ) { |
|
110 | - // convert to UPPERCASE to get actual shortcode |
|
111 | - $EES_Shortcode = strtoupper( $EES_Shortcode ); |
|
112 | - // is the shortcode in the post_content ? |
|
113 | - if ( strpos( $post->post_content, $EES_Shortcode ) !== false ) { |
|
114 | - // map shortcode to post names and post IDs |
|
115 | - \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] = $post_ID; |
|
116 | - // and add this shortcode to the tracking for the blog page |
|
117 | - PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, |
|
118 | - $post_ID ); |
|
119 | - $update_post_shortcodes = true; |
|
120 | - } else { |
|
121 | - // shortcode is not present in post content, so check if we were tracking it previously |
|
122 | - // stop tracking if shortcode is not used in this specific post |
|
123 | - if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ) ) { |
|
124 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ); |
|
125 | - $update_post_shortcodes = true; |
|
126 | - } |
|
127 | - // make sure that something is set for the shortcode posts (even though we may remove this) |
|
128 | - $shortcode_posts = isset( |
|
129 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
130 | - ) |
|
131 | - ? \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
132 | - : array(); |
|
133 | - // and stop tracking for this shortcode on the blog page if it is not used |
|
134 | - $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
|
135 | - $post_ID, |
|
136 | - $EES_Shortcode, |
|
137 | - $shortcode_posts, |
|
138 | - $page_for_posts, |
|
139 | - $update_post_shortcodes |
|
140 | - ) |
|
141 | - ? true |
|
142 | - : $update_post_shortcodes; |
|
143 | - } |
|
144 | - } |
|
145 | - if ( $update_post_shortcodes ) { |
|
146 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
147 | - } |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * set_post_shortcodes_for_posts_page (plz note: shortcodes is plural) |
|
155 | - * called when updating the WordPress Posts Page, |
|
156 | - * and adds shortcode tracking for the Posts Page, for all shortcodes currently tracked on individual posts |
|
157 | - * |
|
158 | - * @access protected |
|
159 | - * @param string $page_for_posts |
|
160 | - * @return void |
|
161 | - */ |
|
162 | - protected static function set_post_shortcodes_for_posts_page( $page_for_posts ) |
|
163 | - { |
|
164 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
165 | - // loop thru shortcodes |
|
166 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
167 | - foreach ( $post_shortcodes as $EES_Shortcode => $post_ID ) { |
|
168 | - PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ); |
|
169 | - } |
|
170 | - } |
|
171 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * set_post_shortcode_for_posts_page (plz note: shortcode is singular) |
|
178 | - * adds Posts Page shortcode tracking for the supplied shortcode for an individual post |
|
179 | - * |
|
180 | - * @access protected |
|
181 | - * @param string $page_for_posts |
|
182 | - * @param $EES_Shortcode |
|
183 | - * @param $post_ID |
|
184 | - */ |
|
185 | - protected static function set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ) |
|
186 | - { |
|
187 | - // critical page shortcodes that we do NOT want added to the Posts page (blog) |
|
188 | - $critical_shortcodes = \EE_Registry::CFG()->core->get_critical_pages_shortcodes_array(); |
|
189 | - // if the shortcode is NOT one of the critical page shortcodes like ESPRESSO_TXN_PAGE |
|
190 | - if ( in_array( $EES_Shortcode, $critical_shortcodes ) ) { |
|
191 | - return; |
|
192 | - } |
|
193 | - // add shortcode to "Posts page" tracking |
|
194 | - if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
195 | - // make sure tracking is in form of an array |
|
196 | - if ( ! is_array( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
197 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( |
|
198 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] => true, |
|
199 | - ); |
|
200 | - } |
|
201 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] += array( $post_ID => true ); |
|
202 | - } else { |
|
203 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( $post_ID => true ); |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * unset_post_shortcodes_on_delete |
|
211 | - * |
|
212 | - * @access protected |
|
213 | - * @param int $ID |
|
214 | - * @return void |
|
215 | - */ |
|
216 | - public static function unset_post_shortcodes_on_delete( $ID ) |
|
217 | - { |
|
218 | - $update_post_shortcodes = false; |
|
219 | - // post on frontpage ? |
|
220 | - $page_for_posts = \EE_Config::get_page_for_posts(); |
|
221 | - // looking for any references to this post |
|
222 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
223 | - // is this the "Posts Page" (blog) ? |
|
224 | - if ( $post_name === $page_for_posts ) { |
|
225 | - // loop thru shortcodes registered for the posts page |
|
226 | - foreach ( $post_shortcodes as $shortcode_class => $shortcode_posts ) { |
|
227 | - $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
|
228 | - $ID, |
|
229 | - $shortcode_class, |
|
230 | - $shortcode_posts, |
|
231 | - $page_for_posts, |
|
232 | - $update_post_shortcodes |
|
233 | - ) |
|
234 | - ? true |
|
235 | - : $update_post_shortcodes; |
|
236 | - } |
|
237 | - } else { |
|
238 | - // loop thru shortcodes registered for each page |
|
239 | - foreach ( $post_shortcodes as $shortcode_class => $post_ID ) { |
|
240 | - // if this is page is being deleted, then don't track any post shortcodes for it |
|
241 | - if ( $post_ID === $ID ) { |
|
242 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $post_name ] ); |
|
243 | - $update_post_shortcodes = true; |
|
244 | - } |
|
245 | - } |
|
246 | - } |
|
247 | - } |
|
248 | - if ( $update_post_shortcodes ) { |
|
249 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * unset_post_shortcodes_on_delete |
|
257 | - * |
|
258 | - * @access protected |
|
259 | - * @param int $ID |
|
260 | - * @param $shortcode_class |
|
261 | - * @param $shortcode_posts |
|
262 | - * @param $page_for_posts |
|
263 | - * @param bool $update_post_shortcodes |
|
264 | - * @return bool |
|
265 | - */ |
|
266 | - protected static function unset_posts_page_shortcode_for_post( |
|
267 | - $ID, |
|
268 | - $shortcode_class, |
|
269 | - $shortcode_posts, |
|
270 | - $page_for_posts, |
|
271 | - $update_post_shortcodes = false |
|
272 | - ) { |
|
273 | - // make sure that an array of post IDs is being tracked for each shortcode |
|
274 | - if ( ! is_array( $shortcode_posts ) ) { |
|
275 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] = array( |
|
276 | - $shortcode_posts => true, |
|
277 | - ); |
|
278 | - $update_post_shortcodes = true; |
|
279 | - } |
|
280 | - // now if the ID of the post being deleted is in the $shortcode_posts array |
|
281 | - if ( is_array( $shortcode_posts ) && isset( $shortcode_posts[ $ID ] ) ) { |
|
282 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ][ $ID ] ); |
|
283 | - $update_post_shortcodes = true; |
|
284 | - } |
|
285 | - // if nothing is registered for that shortcode anymore, then delete the shortcode altogether |
|
286 | - if ( empty( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ) ) { |
|
287 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ); |
|
288 | - $update_post_shortcodes = true; |
|
289 | - } |
|
290 | - return $update_post_shortcodes; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * update_post_shortcodes |
|
297 | - * |
|
298 | - * @access public |
|
299 | - * @param $page_for_posts |
|
300 | - * @return void |
|
301 | - */ |
|
302 | - public static function update_post_shortcodes( $page_for_posts = '' ) |
|
303 | - { |
|
304 | - // make sure page_for_posts is set |
|
305 | - $page_for_posts = ! empty( $page_for_posts ) |
|
306 | - ? $page_for_posts |
|
307 | - : \EE_Config::get_page_for_posts(); |
|
308 | - // allow others to mess stuff up :D |
|
309 | - do_action( |
|
310 | - 'AHEE__\EventEspresso\core\admin\PostShortcodeTracking__update_post_shortcodes', |
|
311 | - \EE_Config::instance()->core->post_shortcodes, |
|
312 | - $page_for_posts |
|
313 | - ); |
|
314 | - // keep old hookpoint for now, will deprecate later |
|
315 | - do_action( |
|
316 | - 'AHEE__EE_Config__update_post_shortcodes', |
|
317 | - \EE_Config::instance()->core->post_shortcodes, |
|
318 | - $page_for_posts |
|
319 | - ); |
|
320 | - // verify that post_shortcodes is set |
|
321 | - \EE_Config::instance()->core->post_shortcodes = isset( \EE_Config::instance()->core->post_shortcodes ) |
|
322 | - && is_array( \EE_Config::instance()->core->post_shortcodes ) |
|
323 | - ? \EE_Config::instance()->core->post_shortcodes |
|
324 | - : array(); |
|
325 | - // cycle thru post_shortcodes |
|
326 | - foreach ( \EE_Config::instance()->core->post_shortcodes as $post_name => $shortcodes ) { |
|
327 | - // are there any shortcodes to track ? |
|
328 | - if ( ! empty( $shortcodes ) ) { |
|
329 | - // skip the posts page, because we want all shortcodes registered for it |
|
330 | - if ( $post_name === $page_for_posts ) { |
|
331 | - continue; |
|
332 | - } |
|
333 | - // loop thru list of tracked shortcodes |
|
334 | - foreach ( $shortcodes as $shortcode => $post_id ) { |
|
335 | - // make sure post still exists |
|
336 | - $post = get_post( $post_id ); |
|
337 | - // check that the post name matches what we have saved |
|
338 | - if ( $post && $post->post_name === $post_name ) { |
|
339 | - // if so, then break before hitting the unset below |
|
340 | - continue; |
|
341 | - } |
|
342 | - // we don't like missing posts around here >:( |
|
343 | - unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
344 | - } |
|
345 | - } else { |
|
346 | - // you got no shortcodes to keep track of ! |
|
347 | - unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
348 | - } |
|
349 | - } |
|
350 | - // critical page shortcodes that we do NOT want added to the Posts page (blog) |
|
351 | - $critical_shortcodes = \EE_Config::instance()->core->get_critical_pages_shortcodes_array(); |
|
352 | - $critical_shortcodes = array_flip( $critical_shortcodes ); |
|
353 | - foreach ( $critical_shortcodes as $critical_shortcode ) { |
|
354 | - unset( \EE_Config::instance()->core->post_shortcodes[ $page_for_posts ][ $critical_shortcode ] ); |
|
355 | - } |
|
356 | - //only show errors |
|
357 | - \EE_Config::instance()->update_espresso_config(); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * reset_page_for_posts_on_initial_set |
|
364 | - * if an admin is on the WP Reading Settings page and sets the option for "Posts page", |
|
365 | - * when it had previously been unset, |
|
366 | - * then we need to attribute any actively used shortcodes to the new blog page |
|
367 | - * |
|
368 | - * @access public |
|
369 | - * @param string $option |
|
370 | - * @param string $value |
|
371 | - * @return void |
|
372 | - */ |
|
373 | - public static function reset_page_for_posts_on_initial_set( $option, $value ) |
|
374 | - { |
|
375 | - PostShortcodeTracking::reset_page_for_posts_on_change( $option, '', $value ); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * reset_page_for_posts_on_change |
|
382 | - * if an admin is on the WP Reading Settings page and changes the option for "Posts page", |
|
383 | - * then we need to attribute any actively used shortcodes for the previous blog page to the new blog page |
|
384 | - * |
|
385 | - * @access public |
|
386 | - * @param string $option |
|
387 | - * @param string $old_value |
|
388 | - * @param string $value |
|
389 | - * @return void |
|
390 | - */ |
|
391 | - public static function reset_page_for_posts_on_change( $option, $old_value = '', $value = '' ) |
|
392 | - { |
|
393 | - if ( $option === 'page_for_posts' ) { |
|
394 | - global $wpdb; |
|
395 | - $table = $wpdb->posts; |
|
396 | - $SQL = "SELECT post_name from $table WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
397 | - $new_page_for_posts = $value ? $wpdb->get_var( $wpdb->prepare( $SQL, $value ) ) : 'posts'; |
|
398 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( $new_page_for_posts ); |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * reset_page_for_posts_on_delete |
|
406 | - * if an admin deletes a page designated as the WP "Posts page", |
|
407 | - * then we need to attribute any actively used shortcodes for that blog page to a generic 'posts' page |
|
408 | - * |
|
409 | - * @access public |
|
410 | - * @param string $option |
|
411 | - * @return void |
|
412 | - */ |
|
413 | - public static function reset_page_for_posts_on_delete( $option ) |
|
414 | - { |
|
415 | - if ( $option === 'page_for_posts' ) { |
|
416 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( 'posts' ); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * @param array|string $shortcodes |
|
424 | - * @param bool $index_results if passing more than one shortcode for the $shortcodes parameter above, |
|
425 | - * then setting this to true, will return as associative array indexed by |
|
426 | - * the shortcodes. If false, then the returned array will be unindexed |
|
427 | - * @return array |
|
428 | - */ |
|
429 | - public static function get_post_ids_for_shortcode( $shortcodes, $index_results = true ) |
|
430 | - { |
|
431 | - $post_ids = array(); |
|
432 | - if ( is_array( $shortcodes ) ) { |
|
433 | - foreach ( $shortcodes as $shortcode ) { |
|
434 | - $new_post_ids = PostShortcodeTracking::get_post_ids_for_shortcode( |
|
435 | - $shortcode, |
|
436 | - $index_results |
|
437 | - ); |
|
438 | - foreach ( $new_post_ids as $new_post_id ) { |
|
439 | - if ( $index_results ) { |
|
440 | - $post_ids[ $shortcode ][ $new_post_id ] = $new_post_id; |
|
441 | - } else { |
|
442 | - $post_ids[ $new_post_id ] = $new_post_id; |
|
443 | - } |
|
444 | - } |
|
445 | - } |
|
446 | - } else { |
|
447 | - $shortcode = strtoupper( $shortcodes ); |
|
448 | - $shortcode = strpos( $shortcode, 'ESPRESSO_' ) !== 0 ? "ESPRESSO_{$shortcode}" : $shortcode; |
|
449 | - $page_for_posts = \EE_Config::get_page_for_posts(); |
|
450 | - // looking for any references to this post |
|
451 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
452 | - // if this is the "Posts Page" (blog), then skip it |
|
453 | - if ( $post_name === $page_for_posts ) { |
|
454 | - continue; |
|
455 | - } |
|
456 | - // loop thru shortcodes registered for each page, and grab post id for matches |
|
457 | - foreach ( (array) $post_shortcodes as $post_shortcode => $post_ID ) { |
|
458 | - if ( $post_shortcode === $shortcode ) { |
|
459 | - $post_ids[ $post_ID ] = $post_ID; |
|
460 | - } |
|
461 | - } |
|
462 | - } |
|
463 | - } |
|
464 | - return $post_ids; |
|
465 | - } |
|
22 | + /** |
|
23 | + * set_hooks_admin |
|
24 | + * |
|
25 | + * @access public |
|
26 | + */ |
|
27 | + public static function set_hooks_admin() |
|
28 | + { |
|
29 | + add_action( |
|
30 | + 'save_post', |
|
31 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'parse_post_content_on_save' ), |
|
32 | + 100, |
|
33 | + 2 |
|
34 | + ); |
|
35 | + add_action( |
|
36 | + 'delete_post', |
|
37 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'unset_post_shortcodes_on_delete' ), |
|
38 | + 100, |
|
39 | + 1 |
|
40 | + ); |
|
41 | + add_action( |
|
42 | + 'add_option_page_for_posts', |
|
43 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_initial_set' ), |
|
44 | + 100, |
|
45 | + 2 |
|
46 | + ); |
|
47 | + add_action( |
|
48 | + 'update_option', |
|
49 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_change' ), |
|
50 | + 100, |
|
51 | + 3 |
|
52 | + ); |
|
53 | + add_action( |
|
54 | + 'delete_option', |
|
55 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_delete' ), |
|
56 | + 100, |
|
57 | + 1 |
|
58 | + ); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * parse_post_content_on_save |
|
65 | + * any time a post is saved, we need to check for any EE shortcodes that may be embedded in the content, |
|
66 | + * and then track what posts those shortcodes are on, so that we can initialize shortcodes well before |
|
67 | + * the_content() runs. this allows us to do things like enqueue scripts for shortcodes ONLY on the pages the |
|
68 | + * shortcodes are actually used on |
|
69 | + * |
|
70 | + * @access public |
|
71 | + * @param int $post_ID |
|
72 | + * @param \WP_Post $post |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public static function parse_post_content_on_save( $post_ID, $post ) |
|
76 | + { |
|
77 | + // if the post is trashed, then let's remove our post shortcode tracking |
|
78 | + if ( $post instanceof \WP_Post && $post->post_status === 'trash' ) { |
|
79 | + PostShortcodeTracking::unset_post_shortcodes_on_delete( $post_ID ); |
|
80 | + return; |
|
81 | + } |
|
82 | + // default post types |
|
83 | + $post_types = array( 'post' => 0, 'page' => 1 ); |
|
84 | + // add CPTs |
|
85 | + $CPTs = \EE_Register_CPTs::get_CPTs(); |
|
86 | + $post_types = array_merge( $post_types, $CPTs ); |
|
87 | + // for default or CPT posts... |
|
88 | + if ( isset( $post_types[ $post->post_type ] ) ) { |
|
89 | + // post on frontpage ? |
|
90 | + $page_for_posts = \EE_Config::get_page_for_posts(); |
|
91 | + if ( $post->post_name === $page_for_posts ) { |
|
92 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page( $page_for_posts ); |
|
93 | + return; |
|
94 | + } |
|
95 | + // array of shortcodes indexed by post name |
|
96 | + \EE_Registry::CFG()->core->post_shortcodes = isset( \EE_Registry::CFG()->core->post_shortcodes ) |
|
97 | + ? \EE_Registry::CFG()->core->post_shortcodes |
|
98 | + : array(); |
|
99 | + // whether to proceed with update |
|
100 | + $update_post_shortcodes = false; |
|
101 | + // empty both arrays |
|
102 | + \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ] = array(); |
|
103 | + // check that posts page is already being tracked |
|
104 | + if ( ! isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] ) ) { |
|
105 | + // if not, then ensure that it is properly added |
|
106 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
107 | + } |
|
108 | + // loop thru shortcodes |
|
109 | + foreach ( \EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir ) { |
|
110 | + // convert to UPPERCASE to get actual shortcode |
|
111 | + $EES_Shortcode = strtoupper( $EES_Shortcode ); |
|
112 | + // is the shortcode in the post_content ? |
|
113 | + if ( strpos( $post->post_content, $EES_Shortcode ) !== false ) { |
|
114 | + // map shortcode to post names and post IDs |
|
115 | + \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] = $post_ID; |
|
116 | + // and add this shortcode to the tracking for the blog page |
|
117 | + PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, |
|
118 | + $post_ID ); |
|
119 | + $update_post_shortcodes = true; |
|
120 | + } else { |
|
121 | + // shortcode is not present in post content, so check if we were tracking it previously |
|
122 | + // stop tracking if shortcode is not used in this specific post |
|
123 | + if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ) ) { |
|
124 | + unset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ); |
|
125 | + $update_post_shortcodes = true; |
|
126 | + } |
|
127 | + // make sure that something is set for the shortcode posts (even though we may remove this) |
|
128 | + $shortcode_posts = isset( |
|
129 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
130 | + ) |
|
131 | + ? \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
132 | + : array(); |
|
133 | + // and stop tracking for this shortcode on the blog page if it is not used |
|
134 | + $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
|
135 | + $post_ID, |
|
136 | + $EES_Shortcode, |
|
137 | + $shortcode_posts, |
|
138 | + $page_for_posts, |
|
139 | + $update_post_shortcodes |
|
140 | + ) |
|
141 | + ? true |
|
142 | + : $update_post_shortcodes; |
|
143 | + } |
|
144 | + } |
|
145 | + if ( $update_post_shortcodes ) { |
|
146 | + PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
147 | + } |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * set_post_shortcodes_for_posts_page (plz note: shortcodes is plural) |
|
155 | + * called when updating the WordPress Posts Page, |
|
156 | + * and adds shortcode tracking for the Posts Page, for all shortcodes currently tracked on individual posts |
|
157 | + * |
|
158 | + * @access protected |
|
159 | + * @param string $page_for_posts |
|
160 | + * @return void |
|
161 | + */ |
|
162 | + protected static function set_post_shortcodes_for_posts_page( $page_for_posts ) |
|
163 | + { |
|
164 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
165 | + // loop thru shortcodes |
|
166 | + foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
167 | + foreach ( $post_shortcodes as $EES_Shortcode => $post_ID ) { |
|
168 | + PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ); |
|
169 | + } |
|
170 | + } |
|
171 | + PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * set_post_shortcode_for_posts_page (plz note: shortcode is singular) |
|
178 | + * adds Posts Page shortcode tracking for the supplied shortcode for an individual post |
|
179 | + * |
|
180 | + * @access protected |
|
181 | + * @param string $page_for_posts |
|
182 | + * @param $EES_Shortcode |
|
183 | + * @param $post_ID |
|
184 | + */ |
|
185 | + protected static function set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ) |
|
186 | + { |
|
187 | + // critical page shortcodes that we do NOT want added to the Posts page (blog) |
|
188 | + $critical_shortcodes = \EE_Registry::CFG()->core->get_critical_pages_shortcodes_array(); |
|
189 | + // if the shortcode is NOT one of the critical page shortcodes like ESPRESSO_TXN_PAGE |
|
190 | + if ( in_array( $EES_Shortcode, $critical_shortcodes ) ) { |
|
191 | + return; |
|
192 | + } |
|
193 | + // add shortcode to "Posts page" tracking |
|
194 | + if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
195 | + // make sure tracking is in form of an array |
|
196 | + if ( ! is_array( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
197 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( |
|
198 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] => true, |
|
199 | + ); |
|
200 | + } |
|
201 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] += array( $post_ID => true ); |
|
202 | + } else { |
|
203 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( $post_ID => true ); |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * unset_post_shortcodes_on_delete |
|
211 | + * |
|
212 | + * @access protected |
|
213 | + * @param int $ID |
|
214 | + * @return void |
|
215 | + */ |
|
216 | + public static function unset_post_shortcodes_on_delete( $ID ) |
|
217 | + { |
|
218 | + $update_post_shortcodes = false; |
|
219 | + // post on frontpage ? |
|
220 | + $page_for_posts = \EE_Config::get_page_for_posts(); |
|
221 | + // looking for any references to this post |
|
222 | + foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
223 | + // is this the "Posts Page" (blog) ? |
|
224 | + if ( $post_name === $page_for_posts ) { |
|
225 | + // loop thru shortcodes registered for the posts page |
|
226 | + foreach ( $post_shortcodes as $shortcode_class => $shortcode_posts ) { |
|
227 | + $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
|
228 | + $ID, |
|
229 | + $shortcode_class, |
|
230 | + $shortcode_posts, |
|
231 | + $page_for_posts, |
|
232 | + $update_post_shortcodes |
|
233 | + ) |
|
234 | + ? true |
|
235 | + : $update_post_shortcodes; |
|
236 | + } |
|
237 | + } else { |
|
238 | + // loop thru shortcodes registered for each page |
|
239 | + foreach ( $post_shortcodes as $shortcode_class => $post_ID ) { |
|
240 | + // if this is page is being deleted, then don't track any post shortcodes for it |
|
241 | + if ( $post_ID === $ID ) { |
|
242 | + unset( \EE_Registry::CFG()->core->post_shortcodes[ $post_name ] ); |
|
243 | + $update_post_shortcodes = true; |
|
244 | + } |
|
245 | + } |
|
246 | + } |
|
247 | + } |
|
248 | + if ( $update_post_shortcodes ) { |
|
249 | + PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * unset_post_shortcodes_on_delete |
|
257 | + * |
|
258 | + * @access protected |
|
259 | + * @param int $ID |
|
260 | + * @param $shortcode_class |
|
261 | + * @param $shortcode_posts |
|
262 | + * @param $page_for_posts |
|
263 | + * @param bool $update_post_shortcodes |
|
264 | + * @return bool |
|
265 | + */ |
|
266 | + protected static function unset_posts_page_shortcode_for_post( |
|
267 | + $ID, |
|
268 | + $shortcode_class, |
|
269 | + $shortcode_posts, |
|
270 | + $page_for_posts, |
|
271 | + $update_post_shortcodes = false |
|
272 | + ) { |
|
273 | + // make sure that an array of post IDs is being tracked for each shortcode |
|
274 | + if ( ! is_array( $shortcode_posts ) ) { |
|
275 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] = array( |
|
276 | + $shortcode_posts => true, |
|
277 | + ); |
|
278 | + $update_post_shortcodes = true; |
|
279 | + } |
|
280 | + // now if the ID of the post being deleted is in the $shortcode_posts array |
|
281 | + if ( is_array( $shortcode_posts ) && isset( $shortcode_posts[ $ID ] ) ) { |
|
282 | + unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ][ $ID ] ); |
|
283 | + $update_post_shortcodes = true; |
|
284 | + } |
|
285 | + // if nothing is registered for that shortcode anymore, then delete the shortcode altogether |
|
286 | + if ( empty( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ) ) { |
|
287 | + unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ); |
|
288 | + $update_post_shortcodes = true; |
|
289 | + } |
|
290 | + return $update_post_shortcodes; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * update_post_shortcodes |
|
297 | + * |
|
298 | + * @access public |
|
299 | + * @param $page_for_posts |
|
300 | + * @return void |
|
301 | + */ |
|
302 | + public static function update_post_shortcodes( $page_for_posts = '' ) |
|
303 | + { |
|
304 | + // make sure page_for_posts is set |
|
305 | + $page_for_posts = ! empty( $page_for_posts ) |
|
306 | + ? $page_for_posts |
|
307 | + : \EE_Config::get_page_for_posts(); |
|
308 | + // allow others to mess stuff up :D |
|
309 | + do_action( |
|
310 | + 'AHEE__\EventEspresso\core\admin\PostShortcodeTracking__update_post_shortcodes', |
|
311 | + \EE_Config::instance()->core->post_shortcodes, |
|
312 | + $page_for_posts |
|
313 | + ); |
|
314 | + // keep old hookpoint for now, will deprecate later |
|
315 | + do_action( |
|
316 | + 'AHEE__EE_Config__update_post_shortcodes', |
|
317 | + \EE_Config::instance()->core->post_shortcodes, |
|
318 | + $page_for_posts |
|
319 | + ); |
|
320 | + // verify that post_shortcodes is set |
|
321 | + \EE_Config::instance()->core->post_shortcodes = isset( \EE_Config::instance()->core->post_shortcodes ) |
|
322 | + && is_array( \EE_Config::instance()->core->post_shortcodes ) |
|
323 | + ? \EE_Config::instance()->core->post_shortcodes |
|
324 | + : array(); |
|
325 | + // cycle thru post_shortcodes |
|
326 | + foreach ( \EE_Config::instance()->core->post_shortcodes as $post_name => $shortcodes ) { |
|
327 | + // are there any shortcodes to track ? |
|
328 | + if ( ! empty( $shortcodes ) ) { |
|
329 | + // skip the posts page, because we want all shortcodes registered for it |
|
330 | + if ( $post_name === $page_for_posts ) { |
|
331 | + continue; |
|
332 | + } |
|
333 | + // loop thru list of tracked shortcodes |
|
334 | + foreach ( $shortcodes as $shortcode => $post_id ) { |
|
335 | + // make sure post still exists |
|
336 | + $post = get_post( $post_id ); |
|
337 | + // check that the post name matches what we have saved |
|
338 | + if ( $post && $post->post_name === $post_name ) { |
|
339 | + // if so, then break before hitting the unset below |
|
340 | + continue; |
|
341 | + } |
|
342 | + // we don't like missing posts around here >:( |
|
343 | + unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
344 | + } |
|
345 | + } else { |
|
346 | + // you got no shortcodes to keep track of ! |
|
347 | + unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
348 | + } |
|
349 | + } |
|
350 | + // critical page shortcodes that we do NOT want added to the Posts page (blog) |
|
351 | + $critical_shortcodes = \EE_Config::instance()->core->get_critical_pages_shortcodes_array(); |
|
352 | + $critical_shortcodes = array_flip( $critical_shortcodes ); |
|
353 | + foreach ( $critical_shortcodes as $critical_shortcode ) { |
|
354 | + unset( \EE_Config::instance()->core->post_shortcodes[ $page_for_posts ][ $critical_shortcode ] ); |
|
355 | + } |
|
356 | + //only show errors |
|
357 | + \EE_Config::instance()->update_espresso_config(); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * reset_page_for_posts_on_initial_set |
|
364 | + * if an admin is on the WP Reading Settings page and sets the option for "Posts page", |
|
365 | + * when it had previously been unset, |
|
366 | + * then we need to attribute any actively used shortcodes to the new blog page |
|
367 | + * |
|
368 | + * @access public |
|
369 | + * @param string $option |
|
370 | + * @param string $value |
|
371 | + * @return void |
|
372 | + */ |
|
373 | + public static function reset_page_for_posts_on_initial_set( $option, $value ) |
|
374 | + { |
|
375 | + PostShortcodeTracking::reset_page_for_posts_on_change( $option, '', $value ); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * reset_page_for_posts_on_change |
|
382 | + * if an admin is on the WP Reading Settings page and changes the option for "Posts page", |
|
383 | + * then we need to attribute any actively used shortcodes for the previous blog page to the new blog page |
|
384 | + * |
|
385 | + * @access public |
|
386 | + * @param string $option |
|
387 | + * @param string $old_value |
|
388 | + * @param string $value |
|
389 | + * @return void |
|
390 | + */ |
|
391 | + public static function reset_page_for_posts_on_change( $option, $old_value = '', $value = '' ) |
|
392 | + { |
|
393 | + if ( $option === 'page_for_posts' ) { |
|
394 | + global $wpdb; |
|
395 | + $table = $wpdb->posts; |
|
396 | + $SQL = "SELECT post_name from $table WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
397 | + $new_page_for_posts = $value ? $wpdb->get_var( $wpdb->prepare( $SQL, $value ) ) : 'posts'; |
|
398 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page( $new_page_for_posts ); |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * reset_page_for_posts_on_delete |
|
406 | + * if an admin deletes a page designated as the WP "Posts page", |
|
407 | + * then we need to attribute any actively used shortcodes for that blog page to a generic 'posts' page |
|
408 | + * |
|
409 | + * @access public |
|
410 | + * @param string $option |
|
411 | + * @return void |
|
412 | + */ |
|
413 | + public static function reset_page_for_posts_on_delete( $option ) |
|
414 | + { |
|
415 | + if ( $option === 'page_for_posts' ) { |
|
416 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page( 'posts' ); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * @param array|string $shortcodes |
|
424 | + * @param bool $index_results if passing more than one shortcode for the $shortcodes parameter above, |
|
425 | + * then setting this to true, will return as associative array indexed by |
|
426 | + * the shortcodes. If false, then the returned array will be unindexed |
|
427 | + * @return array |
|
428 | + */ |
|
429 | + public static function get_post_ids_for_shortcode( $shortcodes, $index_results = true ) |
|
430 | + { |
|
431 | + $post_ids = array(); |
|
432 | + if ( is_array( $shortcodes ) ) { |
|
433 | + foreach ( $shortcodes as $shortcode ) { |
|
434 | + $new_post_ids = PostShortcodeTracking::get_post_ids_for_shortcode( |
|
435 | + $shortcode, |
|
436 | + $index_results |
|
437 | + ); |
|
438 | + foreach ( $new_post_ids as $new_post_id ) { |
|
439 | + if ( $index_results ) { |
|
440 | + $post_ids[ $shortcode ][ $new_post_id ] = $new_post_id; |
|
441 | + } else { |
|
442 | + $post_ids[ $new_post_id ] = $new_post_id; |
|
443 | + } |
|
444 | + } |
|
445 | + } |
|
446 | + } else { |
|
447 | + $shortcode = strtoupper( $shortcodes ); |
|
448 | + $shortcode = strpos( $shortcode, 'ESPRESSO_' ) !== 0 ? "ESPRESSO_{$shortcode}" : $shortcode; |
|
449 | + $page_for_posts = \EE_Config::get_page_for_posts(); |
|
450 | + // looking for any references to this post |
|
451 | + foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
452 | + // if this is the "Posts Page" (blog), then skip it |
|
453 | + if ( $post_name === $page_for_posts ) { |
|
454 | + continue; |
|
455 | + } |
|
456 | + // loop thru shortcodes registered for each page, and grab post id for matches |
|
457 | + foreach ( (array) $post_shortcodes as $post_shortcode => $post_ID ) { |
|
458 | + if ( $post_shortcode === $shortcode ) { |
|
459 | + $post_ids[ $post_ID ] = $post_ID; |
|
460 | + } |
|
461 | + } |
|
462 | + } |
|
463 | + } |
|
464 | + return $post_ids; |
|
465 | + } |
|
466 | 466 | |
467 | 467 | |
468 | 468 |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\admin; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -28,31 +28,31 @@ discard block |
||
28 | 28 | { |
29 | 29 | add_action( |
30 | 30 | 'save_post', |
31 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'parse_post_content_on_save' ), |
|
31 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'parse_post_content_on_save'), |
|
32 | 32 | 100, |
33 | 33 | 2 |
34 | 34 | ); |
35 | 35 | add_action( |
36 | 36 | 'delete_post', |
37 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'unset_post_shortcodes_on_delete' ), |
|
37 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'unset_post_shortcodes_on_delete'), |
|
38 | 38 | 100, |
39 | 39 | 1 |
40 | 40 | ); |
41 | 41 | add_action( |
42 | 42 | 'add_option_page_for_posts', |
43 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_initial_set' ), |
|
43 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_initial_set'), |
|
44 | 44 | 100, |
45 | 45 | 2 |
46 | 46 | ); |
47 | 47 | add_action( |
48 | 48 | 'update_option', |
49 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_change' ), |
|
49 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_change'), |
|
50 | 50 | 100, |
51 | 51 | 3 |
52 | 52 | ); |
53 | 53 | add_action( |
54 | 54 | 'delete_option', |
55 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_delete' ), |
|
55 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_delete'), |
|
56 | 56 | 100, |
57 | 57 | 1 |
58 | 58 | ); |
@@ -72,63 +72,63 @@ discard block |
||
72 | 72 | * @param \WP_Post $post |
73 | 73 | * @return void |
74 | 74 | */ |
75 | - public static function parse_post_content_on_save( $post_ID, $post ) |
|
75 | + public static function parse_post_content_on_save($post_ID, $post) |
|
76 | 76 | { |
77 | 77 | // if the post is trashed, then let's remove our post shortcode tracking |
78 | - if ( $post instanceof \WP_Post && $post->post_status === 'trash' ) { |
|
79 | - PostShortcodeTracking::unset_post_shortcodes_on_delete( $post_ID ); |
|
78 | + if ($post instanceof \WP_Post && $post->post_status === 'trash') { |
|
79 | + PostShortcodeTracking::unset_post_shortcodes_on_delete($post_ID); |
|
80 | 80 | return; |
81 | 81 | } |
82 | 82 | // default post types |
83 | - $post_types = array( 'post' => 0, 'page' => 1 ); |
|
83 | + $post_types = array('post' => 0, 'page' => 1); |
|
84 | 84 | // add CPTs |
85 | 85 | $CPTs = \EE_Register_CPTs::get_CPTs(); |
86 | - $post_types = array_merge( $post_types, $CPTs ); |
|
86 | + $post_types = array_merge($post_types, $CPTs); |
|
87 | 87 | // for default or CPT posts... |
88 | - if ( isset( $post_types[ $post->post_type ] ) ) { |
|
88 | + if (isset($post_types[$post->post_type])) { |
|
89 | 89 | // post on frontpage ? |
90 | 90 | $page_for_posts = \EE_Config::get_page_for_posts(); |
91 | - if ( $post->post_name === $page_for_posts ) { |
|
92 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( $page_for_posts ); |
|
91 | + if ($post->post_name === $page_for_posts) { |
|
92 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page($page_for_posts); |
|
93 | 93 | return; |
94 | 94 | } |
95 | 95 | // array of shortcodes indexed by post name |
96 | - \EE_Registry::CFG()->core->post_shortcodes = isset( \EE_Registry::CFG()->core->post_shortcodes ) |
|
96 | + \EE_Registry::CFG()->core->post_shortcodes = isset(\EE_Registry::CFG()->core->post_shortcodes) |
|
97 | 97 | ? \EE_Registry::CFG()->core->post_shortcodes |
98 | 98 | : array(); |
99 | 99 | // whether to proceed with update |
100 | 100 | $update_post_shortcodes = false; |
101 | 101 | // empty both arrays |
102 | - \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ] = array(); |
|
102 | + \EE_Registry::CFG()->core->post_shortcodes[$post->post_name] = array(); |
|
103 | 103 | // check that posts page is already being tracked |
104 | - if ( ! isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] ) ) { |
|
104 | + if ( ! isset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts])) { |
|
105 | 105 | // if not, then ensure that it is properly added |
106 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
106 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts] = array(); |
|
107 | 107 | } |
108 | 108 | // loop thru shortcodes |
109 | - foreach ( \EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir ) { |
|
109 | + foreach (\EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir) { |
|
110 | 110 | // convert to UPPERCASE to get actual shortcode |
111 | - $EES_Shortcode = strtoupper( $EES_Shortcode ); |
|
111 | + $EES_Shortcode = strtoupper($EES_Shortcode); |
|
112 | 112 | // is the shortcode in the post_content ? |
113 | - if ( strpos( $post->post_content, $EES_Shortcode ) !== false ) { |
|
113 | + if (strpos($post->post_content, $EES_Shortcode) !== false) { |
|
114 | 114 | // map shortcode to post names and post IDs |
115 | - \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] = $post_ID; |
|
115 | + \EE_Registry::CFG()->core->post_shortcodes[$post->post_name][$EES_Shortcode] = $post_ID; |
|
116 | 116 | // and add this shortcode to the tracking for the blog page |
117 | - PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, |
|
118 | - $post_ID ); |
|
117 | + PostShortcodeTracking::set_post_shortcode_for_posts_page($page_for_posts, $EES_Shortcode, |
|
118 | + $post_ID); |
|
119 | 119 | $update_post_shortcodes = true; |
120 | 120 | } else { |
121 | 121 | // shortcode is not present in post content, so check if we were tracking it previously |
122 | 122 | // stop tracking if shortcode is not used in this specific post |
123 | - if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ) ) { |
|
124 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ); |
|
123 | + if (isset(\EE_Registry::CFG()->core->post_shortcodes[$post->post_name][$EES_Shortcode])) { |
|
124 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$post->post_name][$EES_Shortcode]); |
|
125 | 125 | $update_post_shortcodes = true; |
126 | 126 | } |
127 | 127 | // make sure that something is set for the shortcode posts (even though we may remove this) |
128 | 128 | $shortcode_posts = isset( |
129 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
129 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] |
|
130 | 130 | ) |
131 | - ? \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
131 | + ? \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] |
|
132 | 132 | : array(); |
133 | 133 | // and stop tracking for this shortcode on the blog page if it is not used |
134 | 134 | $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | : $update_post_shortcodes; |
143 | 143 | } |
144 | 144 | } |
145 | - if ( $update_post_shortcodes ) { |
|
146 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
145 | + if ($update_post_shortcodes) { |
|
146 | + PostShortcodeTracking::update_post_shortcodes($page_for_posts); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | } |
@@ -159,16 +159,16 @@ discard block |
||
159 | 159 | * @param string $page_for_posts |
160 | 160 | * @return void |
161 | 161 | */ |
162 | - protected static function set_post_shortcodes_for_posts_page( $page_for_posts ) |
|
162 | + protected static function set_post_shortcodes_for_posts_page($page_for_posts) |
|
163 | 163 | { |
164 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
164 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts] = array(); |
|
165 | 165 | // loop thru shortcodes |
166 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
167 | - foreach ( $post_shortcodes as $EES_Shortcode => $post_ID ) { |
|
168 | - PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ); |
|
166 | + foreach (\EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
167 | + foreach ($post_shortcodes as $EES_Shortcode => $post_ID) { |
|
168 | + PostShortcodeTracking::set_post_shortcode_for_posts_page($page_for_posts, $EES_Shortcode, $post_ID); |
|
169 | 169 | } |
170 | 170 | } |
171 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
171 | + PostShortcodeTracking::update_post_shortcodes($page_for_posts); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | |
@@ -182,25 +182,25 @@ discard block |
||
182 | 182 | * @param $EES_Shortcode |
183 | 183 | * @param $post_ID |
184 | 184 | */ |
185 | - protected static function set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ) |
|
185 | + protected static function set_post_shortcode_for_posts_page($page_for_posts, $EES_Shortcode, $post_ID) |
|
186 | 186 | { |
187 | 187 | // critical page shortcodes that we do NOT want added to the Posts page (blog) |
188 | 188 | $critical_shortcodes = \EE_Registry::CFG()->core->get_critical_pages_shortcodes_array(); |
189 | 189 | // if the shortcode is NOT one of the critical page shortcodes like ESPRESSO_TXN_PAGE |
190 | - if ( in_array( $EES_Shortcode, $critical_shortcodes ) ) { |
|
190 | + if (in_array($EES_Shortcode, $critical_shortcodes)) { |
|
191 | 191 | return; |
192 | 192 | } |
193 | 193 | // add shortcode to "Posts page" tracking |
194 | - if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
194 | + if (isset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode])) { |
|
195 | 195 | // make sure tracking is in form of an array |
196 | - if ( ! is_array( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
197 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( |
|
198 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] => true, |
|
196 | + if ( ! is_array(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode])) { |
|
197 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] = array( |
|
198 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] => true, |
|
199 | 199 | ); |
200 | 200 | } |
201 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] += array( $post_ID => true ); |
|
201 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] += array($post_ID => true); |
|
202 | 202 | } else { |
203 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( $post_ID => true ); |
|
203 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] = array($post_ID => true); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
@@ -213,17 +213,17 @@ discard block |
||
213 | 213 | * @param int $ID |
214 | 214 | * @return void |
215 | 215 | */ |
216 | - public static function unset_post_shortcodes_on_delete( $ID ) |
|
216 | + public static function unset_post_shortcodes_on_delete($ID) |
|
217 | 217 | { |
218 | 218 | $update_post_shortcodes = false; |
219 | 219 | // post on frontpage ? |
220 | 220 | $page_for_posts = \EE_Config::get_page_for_posts(); |
221 | 221 | // looking for any references to this post |
222 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
222 | + foreach (\EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
223 | 223 | // is this the "Posts Page" (blog) ? |
224 | - if ( $post_name === $page_for_posts ) { |
|
224 | + if ($post_name === $page_for_posts) { |
|
225 | 225 | // loop thru shortcodes registered for the posts page |
226 | - foreach ( $post_shortcodes as $shortcode_class => $shortcode_posts ) { |
|
226 | + foreach ($post_shortcodes as $shortcode_class => $shortcode_posts) { |
|
227 | 227 | $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
228 | 228 | $ID, |
229 | 229 | $shortcode_class, |
@@ -236,17 +236,17 @@ discard block |
||
236 | 236 | } |
237 | 237 | } else { |
238 | 238 | // loop thru shortcodes registered for each page |
239 | - foreach ( $post_shortcodes as $shortcode_class => $post_ID ) { |
|
239 | + foreach ($post_shortcodes as $shortcode_class => $post_ID) { |
|
240 | 240 | // if this is page is being deleted, then don't track any post shortcodes for it |
241 | - if ( $post_ID === $ID ) { |
|
242 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $post_name ] ); |
|
241 | + if ($post_ID === $ID) { |
|
242 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$post_name]); |
|
243 | 243 | $update_post_shortcodes = true; |
244 | 244 | } |
245 | 245 | } |
246 | 246 | } |
247 | 247 | } |
248 | - if ( $update_post_shortcodes ) { |
|
249 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
248 | + if ($update_post_shortcodes) { |
|
249 | + PostShortcodeTracking::update_post_shortcodes($page_for_posts); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
@@ -271,20 +271,20 @@ discard block |
||
271 | 271 | $update_post_shortcodes = false |
272 | 272 | ) { |
273 | 273 | // make sure that an array of post IDs is being tracked for each shortcode |
274 | - if ( ! is_array( $shortcode_posts ) ) { |
|
275 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] = array( |
|
274 | + if ( ! is_array($shortcode_posts)) { |
|
275 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class] = array( |
|
276 | 276 | $shortcode_posts => true, |
277 | 277 | ); |
278 | 278 | $update_post_shortcodes = true; |
279 | 279 | } |
280 | 280 | // now if the ID of the post being deleted is in the $shortcode_posts array |
281 | - if ( is_array( $shortcode_posts ) && isset( $shortcode_posts[ $ID ] ) ) { |
|
282 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ][ $ID ] ); |
|
281 | + if (is_array($shortcode_posts) && isset($shortcode_posts[$ID])) { |
|
282 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class][$ID]); |
|
283 | 283 | $update_post_shortcodes = true; |
284 | 284 | } |
285 | 285 | // if nothing is registered for that shortcode anymore, then delete the shortcode altogether |
286 | - if ( empty( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ) ) { |
|
287 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ); |
|
286 | + if (empty(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class])) { |
|
287 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class]); |
|
288 | 288 | $update_post_shortcodes = true; |
289 | 289 | } |
290 | 290 | return $update_post_shortcodes; |
@@ -299,10 +299,10 @@ discard block |
||
299 | 299 | * @param $page_for_posts |
300 | 300 | * @return void |
301 | 301 | */ |
302 | - public static function update_post_shortcodes( $page_for_posts = '' ) |
|
302 | + public static function update_post_shortcodes($page_for_posts = '') |
|
303 | 303 | { |
304 | 304 | // make sure page_for_posts is set |
305 | - $page_for_posts = ! empty( $page_for_posts ) |
|
305 | + $page_for_posts = ! empty($page_for_posts) |
|
306 | 306 | ? $page_for_posts |
307 | 307 | : \EE_Config::get_page_for_posts(); |
308 | 308 | // allow others to mess stuff up :D |
@@ -318,40 +318,40 @@ discard block |
||
318 | 318 | $page_for_posts |
319 | 319 | ); |
320 | 320 | // verify that post_shortcodes is set |
321 | - \EE_Config::instance()->core->post_shortcodes = isset( \EE_Config::instance()->core->post_shortcodes ) |
|
322 | - && is_array( \EE_Config::instance()->core->post_shortcodes ) |
|
321 | + \EE_Config::instance()->core->post_shortcodes = isset(\EE_Config::instance()->core->post_shortcodes) |
|
322 | + && is_array(\EE_Config::instance()->core->post_shortcodes) |
|
323 | 323 | ? \EE_Config::instance()->core->post_shortcodes |
324 | 324 | : array(); |
325 | 325 | // cycle thru post_shortcodes |
326 | - foreach ( \EE_Config::instance()->core->post_shortcodes as $post_name => $shortcodes ) { |
|
326 | + foreach (\EE_Config::instance()->core->post_shortcodes as $post_name => $shortcodes) { |
|
327 | 327 | // are there any shortcodes to track ? |
328 | - if ( ! empty( $shortcodes ) ) { |
|
328 | + if ( ! empty($shortcodes)) { |
|
329 | 329 | // skip the posts page, because we want all shortcodes registered for it |
330 | - if ( $post_name === $page_for_posts ) { |
|
330 | + if ($post_name === $page_for_posts) { |
|
331 | 331 | continue; |
332 | 332 | } |
333 | 333 | // loop thru list of tracked shortcodes |
334 | - foreach ( $shortcodes as $shortcode => $post_id ) { |
|
334 | + foreach ($shortcodes as $shortcode => $post_id) { |
|
335 | 335 | // make sure post still exists |
336 | - $post = get_post( $post_id ); |
|
336 | + $post = get_post($post_id); |
|
337 | 337 | // check that the post name matches what we have saved |
338 | - if ( $post && $post->post_name === $post_name ) { |
|
338 | + if ($post && $post->post_name === $post_name) { |
|
339 | 339 | // if so, then break before hitting the unset below |
340 | 340 | continue; |
341 | 341 | } |
342 | 342 | // we don't like missing posts around here >:( |
343 | - unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
343 | + unset(\EE_Config::instance()->core->post_shortcodes[$post_name]); |
|
344 | 344 | } |
345 | 345 | } else { |
346 | 346 | // you got no shortcodes to keep track of ! |
347 | - unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
347 | + unset(\EE_Config::instance()->core->post_shortcodes[$post_name]); |
|
348 | 348 | } |
349 | 349 | } |
350 | 350 | // critical page shortcodes that we do NOT want added to the Posts page (blog) |
351 | 351 | $critical_shortcodes = \EE_Config::instance()->core->get_critical_pages_shortcodes_array(); |
352 | - $critical_shortcodes = array_flip( $critical_shortcodes ); |
|
353 | - foreach ( $critical_shortcodes as $critical_shortcode ) { |
|
354 | - unset( \EE_Config::instance()->core->post_shortcodes[ $page_for_posts ][ $critical_shortcode ] ); |
|
352 | + $critical_shortcodes = array_flip($critical_shortcodes); |
|
353 | + foreach ($critical_shortcodes as $critical_shortcode) { |
|
354 | + unset(\EE_Config::instance()->core->post_shortcodes[$page_for_posts][$critical_shortcode]); |
|
355 | 355 | } |
356 | 356 | //only show errors |
357 | 357 | \EE_Config::instance()->update_espresso_config(); |
@@ -370,9 +370,9 @@ discard block |
||
370 | 370 | * @param string $value |
371 | 371 | * @return void |
372 | 372 | */ |
373 | - public static function reset_page_for_posts_on_initial_set( $option, $value ) |
|
373 | + public static function reset_page_for_posts_on_initial_set($option, $value) |
|
374 | 374 | { |
375 | - PostShortcodeTracking::reset_page_for_posts_on_change( $option, '', $value ); |
|
375 | + PostShortcodeTracking::reset_page_for_posts_on_change($option, '', $value); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | |
@@ -388,14 +388,14 @@ discard block |
||
388 | 388 | * @param string $value |
389 | 389 | * @return void |
390 | 390 | */ |
391 | - public static function reset_page_for_posts_on_change( $option, $old_value = '', $value = '' ) |
|
391 | + public static function reset_page_for_posts_on_change($option, $old_value = '', $value = '') |
|
392 | 392 | { |
393 | - if ( $option === 'page_for_posts' ) { |
|
393 | + if ($option === 'page_for_posts') { |
|
394 | 394 | global $wpdb; |
395 | 395 | $table = $wpdb->posts; |
396 | 396 | $SQL = "SELECT post_name from $table WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
397 | - $new_page_for_posts = $value ? $wpdb->get_var( $wpdb->prepare( $SQL, $value ) ) : 'posts'; |
|
398 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( $new_page_for_posts ); |
|
397 | + $new_page_for_posts = $value ? $wpdb->get_var($wpdb->prepare($SQL, $value)) : 'posts'; |
|
398 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page($new_page_for_posts); |
|
399 | 399 | } |
400 | 400 | } |
401 | 401 | |
@@ -410,10 +410,10 @@ discard block |
||
410 | 410 | * @param string $option |
411 | 411 | * @return void |
412 | 412 | */ |
413 | - public static function reset_page_for_posts_on_delete( $option ) |
|
413 | + public static function reset_page_for_posts_on_delete($option) |
|
414 | 414 | { |
415 | - if ( $option === 'page_for_posts' ) { |
|
416 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( 'posts' ); |
|
415 | + if ($option === 'page_for_posts') { |
|
416 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page('posts'); |
|
417 | 417 | } |
418 | 418 | } |
419 | 419 | |
@@ -426,37 +426,37 @@ discard block |
||
426 | 426 | * the shortcodes. If false, then the returned array will be unindexed |
427 | 427 | * @return array |
428 | 428 | */ |
429 | - public static function get_post_ids_for_shortcode( $shortcodes, $index_results = true ) |
|
429 | + public static function get_post_ids_for_shortcode($shortcodes, $index_results = true) |
|
430 | 430 | { |
431 | 431 | $post_ids = array(); |
432 | - if ( is_array( $shortcodes ) ) { |
|
433 | - foreach ( $shortcodes as $shortcode ) { |
|
432 | + if (is_array($shortcodes)) { |
|
433 | + foreach ($shortcodes as $shortcode) { |
|
434 | 434 | $new_post_ids = PostShortcodeTracking::get_post_ids_for_shortcode( |
435 | 435 | $shortcode, |
436 | 436 | $index_results |
437 | 437 | ); |
438 | - foreach ( $new_post_ids as $new_post_id ) { |
|
439 | - if ( $index_results ) { |
|
440 | - $post_ids[ $shortcode ][ $new_post_id ] = $new_post_id; |
|
438 | + foreach ($new_post_ids as $new_post_id) { |
|
439 | + if ($index_results) { |
|
440 | + $post_ids[$shortcode][$new_post_id] = $new_post_id; |
|
441 | 441 | } else { |
442 | - $post_ids[ $new_post_id ] = $new_post_id; |
|
442 | + $post_ids[$new_post_id] = $new_post_id; |
|
443 | 443 | } |
444 | 444 | } |
445 | 445 | } |
446 | 446 | } else { |
447 | - $shortcode = strtoupper( $shortcodes ); |
|
448 | - $shortcode = strpos( $shortcode, 'ESPRESSO_' ) !== 0 ? "ESPRESSO_{$shortcode}" : $shortcode; |
|
447 | + $shortcode = strtoupper($shortcodes); |
|
448 | + $shortcode = strpos($shortcode, 'ESPRESSO_') !== 0 ? "ESPRESSO_{$shortcode}" : $shortcode; |
|
449 | 449 | $page_for_posts = \EE_Config::get_page_for_posts(); |
450 | 450 | // looking for any references to this post |
451 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
451 | + foreach (\EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
452 | 452 | // if this is the "Posts Page" (blog), then skip it |
453 | - if ( $post_name === $page_for_posts ) { |
|
453 | + if ($post_name === $page_for_posts) { |
|
454 | 454 | continue; |
455 | 455 | } |
456 | 456 | // loop thru shortcodes registered for each page, and grab post id for matches |
457 | - foreach ( (array) $post_shortcodes as $post_shortcode => $post_ID ) { |
|
458 | - if ( $post_shortcode === $shortcode ) { |
|
459 | - $post_ids[ $post_ID ] = $post_ID; |
|
457 | + foreach ((array) $post_shortcodes as $post_shortcode => $post_ID) { |
|
458 | + if ($post_shortcode === $shortcode) { |
|
459 | + $post_ids[$post_ID] = $post_ID; |
|
460 | 460 | } |
461 | 461 | } |
462 | 462 | } |
@@ -5,10 +5,10 @@ discard block |
||
5 | 5 | ?> |
6 | 6 | <div class="padding"> |
7 | 7 | |
8 | - <h2 class="ee-admin-settings-hdr"><?php _e('Countries and States/Provinces', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_select_info');?></h2> |
|
8 | + <h2 class="ee-admin-settings-hdr"><?php _e('Countries and States/Provinces', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_select_info'); ?></h2> |
|
9 | 9 | <table class="form-table"> |
10 | 10 | <tbody> |
11 | - <?php echo EEH_Form_Fields::generate_form_input( $countries ); ?> |
|
11 | + <?php echo EEH_Form_Fields::generate_form_input($countries); ?> |
|
12 | 12 | </tbody> |
13 | 13 | </table> |
14 | 14 | <br/> |
@@ -16,12 +16,12 @@ discard block |
||
16 | 16 | <?php _e('The country that is selected above will populate the Country Details settings and the options for States/Provinces. This information will be used throughout Event Espresso including for registration purposes and how currency is displayed. If you make a change to the country on this page, it is important that you also update your Contact Information on the Your Organization tab.', 'event_espresso'); ?> |
17 | 17 | </p> |
18 | 18 | <div id="country-details-settings-dv"> |
19 | - <h2 class="ee-admin-settings-hdr"><?php _e('Country Details', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_details_info');?></h2> |
|
19 | + <h2 class="ee-admin-settings-hdr"><?php _e('Country Details', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_details_info'); ?></h2> |
|
20 | 20 | <div id="country-details-dv"><?php echo $country_details_settings; ?></div> |
21 | 21 | </div> |
22 | 22 | |
23 | 23 | <div id="country-states-settings-dv"> |
24 | - <h2 class="ee-admin-settings-hdr"><?php _e( 'States/Provinces', 'event_espresso' );?> <?php echo EEH_Template::get_help_tab_link('country_states_info');?></h2> |
|
24 | + <h2 class="ee-admin-settings-hdr"><?php _e('States/Provinces', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_states_info'); ?></h2> |
|
25 | 25 | <div id="country-states-dv"><?php echo $country_states_settings; ?></div> |
26 | 26 | </div> |
27 | 27 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | ?> |
7 | 7 | <div class="padding"> |
8 | 8 | |
9 | - <?php do_action( 'AHEE__admin_option_settings__template__before', $template_args ); ?> |
|
9 | + <?php do_action('AHEE__admin_option_settings__template__before', $template_args); ?> |
|
10 | 10 | |
11 | 11 | <?php /* @todo put back once we have a dashboard widget to use |
12 | 12 | <h2 class="ee-admin-settings-hdr"> |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | </table> |
72 | 72 | <?php endif; */ ?> |
73 | 73 | |
74 | - <?php if ( EE_Registry::instance()->CAP->current_user_can( 'manage_options', 'display_admin_settings_options_promote_and_affiliate' ) ) : ?> |
|
74 | + <?php if (EE_Registry::instance()->CAP->current_user_can('manage_options', 'display_admin_settings_options_promote_and_affiliate')) : ?> |
|
75 | 75 | <h2 class="ee-admin-settings-hdr"> |
76 | 76 | <?php _e('Promote Event Espresso', 'event_espresso'); ?> <span id="affiliate_info"><?php echo EEH_Template::get_help_tab_link('affiliate_info'); ?></span> |
77 | 77 | </h2> |
@@ -86,14 +86,14 @@ discard block |
||
86 | 86 | </label> |
87 | 87 | </th> |
88 | 88 | <td> |
89 | - <?php echo EEH_Form_Fields::select_input('show_reg_footer', $values, $show_reg_footer ); ?> |
|
89 | + <?php echo EEH_Form_Fields::select_input('show_reg_footer', $values, $show_reg_footer); ?> |
|
90 | 90 | </td> |
91 | 91 | </tr> |
92 | 92 | |
93 | 93 | <tr> |
94 | 94 | <th> |
95 | 95 | <label for="affiliate_id"> |
96 | - <?php printf( __('Event Espresso %sAffiliate%s ID', 'event_espresso'), '<a href="http://eventespresso.com/affiliates/" target="_blank">', '</a>' ); ?> |
|
96 | + <?php printf(__('Event Espresso %sAffiliate%s ID', 'event_espresso'), '<a href="http://eventespresso.com/affiliates/" target="_blank">', '</a>'); ?> |
|
97 | 97 | </label> |
98 | 98 | </th> |
99 | 99 | <td> |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | </label> |
124 | 124 | </th> |
125 | 125 | <td> |
126 | - <?php echo EEH_Form_Fields::select_input('help_tour_activation', $values, $help_tour_activation ); ?> |
|
126 | + <?php echo EEH_Form_Fields::select_input('help_tour_activation', $values, $help_tour_activation); ?> |
|
127 | 127 | </td> |
128 | 128 | </tr> |
129 | 129 | </tbody> |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');} |
|
2 | -do_action( 'AHEE_log', __FILE__, ' FILE LOADED', '' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); } |
|
2 | +do_action('AHEE_log', __FILE__, ' FILE LOADED', ''); |
|
3 | 3 | /** |
4 | 4 | * |
5 | 5 | * Event Espresso |
@@ -117,59 +117,59 @@ discard block |
||
117 | 117 | * @throws EE_Error |
118 | 118 | * @return \EE_Base_Class |
119 | 119 | */ |
120 | - protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '', $date_formats = array() ){ |
|
120 | + protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '', $date_formats = array()) { |
|
121 | 121 | |
122 | - $className=get_class($this); |
|
122 | + $className = get_class($this); |
|
123 | 123 | |
124 | - do_action("AHEE__{$className}__construct",$this,$fieldValues); |
|
125 | - $model=$this->get_model(); |
|
126 | - $model_fields = $model->field_settings( FALSE ); |
|
124 | + do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
125 | + $model = $this->get_model(); |
|
126 | + $model_fields = $model->field_settings(FALSE); |
|
127 | 127 | // ensure $fieldValues is an array |
128 | - $fieldValues = is_array( $fieldValues ) ? $fieldValues : array( $fieldValues ); |
|
128 | + $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
129 | 129 | // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
130 | 130 | // verify client code has not passed any invalid field names |
131 | - foreach($fieldValues as $field_name=> $field_value){ |
|
132 | - if( ! isset( $model_fields[ $field_name] ) ){ |
|
133 | - throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"),$field_name,get_class($this),implode(", ",array_keys($model_fields)))); |
|
131 | + foreach ($fieldValues as $field_name=> $field_value) { |
|
132 | + if ( ! isset($model_fields[$field_name])) { |
|
133 | + throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
137 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone ); |
|
137 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
138 | 138 | |
139 | - if ( ! empty( $date_formats ) && is_array( $date_formats ) ) { |
|
139 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
140 | 140 | $this->_dt_frmt = $date_formats[0]; |
141 | 141 | $this->_tm_frmt = $date_formats[1]; |
142 | 142 | } else { |
143 | 143 | //set default formats for date and time |
144 | - $this->_dt_frmt = get_option( 'date_format' ); |
|
145 | - $this->_tm_frmt = get_option( 'time_format' ); |
|
144 | + $this->_dt_frmt = get_option('date_format'); |
|
145 | + $this->_tm_frmt = get_option('time_format'); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | //if db model is instantiating |
149 | - if ( $bydb ){ |
|
149 | + if ($bydb) { |
|
150 | 150 | //client code has indicated these field values are from the database |
151 | - foreach( $model_fields as $fieldName => $field ){ |
|
152 | - $this->set_from_db( $fieldName, isset( $fieldValues[ $fieldName] ) ? $fieldValues[ $fieldName ] : null ); |
|
151 | + foreach ($model_fields as $fieldName => $field) { |
|
152 | + $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
153 | 153 | } |
154 | 154 | } else { |
155 | 155 | //we're constructing a brand |
156 | 156 | //new instance of the model object. Generally, this means we'll need to do more field validation |
157 | - foreach( $model_fields as $fieldName => $field ){ |
|
158 | - $this->set( $fieldName, isset( $fieldValues[ $fieldName ] ) ? $fieldValues[ $fieldName ] : null, true ); |
|
157 | + foreach ($model_fields as $fieldName => $field) { |
|
158 | + $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
159 | 159 | } |
160 | 160 | } |
161 | 161 | |
162 | 162 | //remember what values were passed to this constructor |
163 | 163 | $this->_props_n_values_provided_in_constructor = $fieldValues; |
164 | 164 | //remember in entity mapper |
165 | - if( ! $bydb && $model->has_primary_key_field() && $this->ID() ){ |
|
165 | + if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) { |
|
166 | 166 | $model->add_to_entity_map($this); |
167 | 167 | } |
168 | 168 | //setup all the relations |
169 | - foreach($this->get_model()->relation_settings() as $relation_name=>$relation_obj){ |
|
170 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
169 | + foreach ($this->get_model()->relation_settings() as $relation_name=>$relation_obj) { |
|
170 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
171 | 171 | $this->_model_relations[$relation_name] = NULL; |
172 | - }else{ |
|
172 | + } else { |
|
173 | 173 | $this->_model_relations[$relation_name] = array(); |
174 | 174 | } |
175 | 175 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * Action done at the end of each model object construction |
178 | 178 | * @param EE_Base_Class $this the model object just created |
179 | 179 | */ |
180 | - do_action( 'AHEE__EE_Base_Class__construct__finished', $this ); |
|
180 | + do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * @param boolean $allow_persist |
198 | 198 | * @return boolean |
199 | 199 | */ |
200 | - public function set_allow_persist( $allow_persist ) { |
|
200 | + public function set_allow_persist($allow_persist) { |
|
201 | 201 | return $this->_allow_persist = $allow_persist; |
202 | 202 | } |
203 | 203 | |
@@ -211,11 +211,11 @@ discard block |
||
211 | 211 | * @return mixed|null |
212 | 212 | * @throws \EE_Error |
213 | 213 | */ |
214 | - public function get_original( $field_name ){ |
|
215 | - if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
|
216 | - $field_settings = $this->get_model()->field_settings_for( $field_name )){ |
|
217 | - return $field_settings->prepare_for_get( $this->_props_n_values_provided_in_constructor[ $field_name ] ); |
|
218 | - }else{ |
|
214 | + public function get_original($field_name) { |
|
215 | + if (isset($this->_props_n_values_provided_in_constructor[$field_name]) && |
|
216 | + $field_settings = $this->get_model()->field_settings_for($field_name)) { |
|
217 | + return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
218 | + } else { |
|
219 | 219 | return NULL; |
220 | 220 | } |
221 | 221 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @param EE_Base_Class $obj |
226 | 226 | * @return string |
227 | 227 | */ |
228 | - public function get_class($obj){ |
|
228 | + public function get_class($obj) { |
|
229 | 229 | return get_class($obj); |
230 | 230 | } |
231 | 231 | |
@@ -240,19 +240,19 @@ discard block |
||
240 | 240 | * @param bool $use_default |
241 | 241 | * @throws \EE_Error |
242 | 242 | */ |
243 | - public function set( $field_name, $field_value, $use_default = FALSE ){ |
|
244 | - $field_obj = $this->get_model()->field_settings_for( $field_name ); |
|
245 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
243 | + public function set($field_name, $field_value, $use_default = FALSE) { |
|
244 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
245 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
246 | 246 | // if ( method_exists( $field_obj, 'set_timezone' )) { |
247 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
248 | - $field_obj->set_timezone( $this->_timezone ); |
|
249 | - $field_obj->set_date_format( $this->_dt_frmt ); |
|
250 | - $field_obj->set_time_format( $this->_tm_frmt ); |
|
247 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
248 | + $field_obj->set_timezone($this->_timezone); |
|
249 | + $field_obj->set_date_format($this->_dt_frmt); |
|
250 | + $field_obj->set_time_format($this->_tm_frmt); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | $holder_of_value = $field_obj->prepare_for_set($field_value); |
254 | 254 | //should the value be null? |
255 | - if( ($field_value === NULL || $holder_of_value === NULL || $holder_of_value ==='') && $use_default){ |
|
255 | + if (($field_value === NULL || $holder_of_value === NULL || $holder_of_value === '') && $use_default) { |
|
256 | 256 | $this->_fields[$field_name] = $field_obj->get_default_value(); |
257 | 257 | |
258 | 258 | /** |
@@ -264,26 +264,26 @@ discard block |
||
264 | 264 | */ |
265 | 265 | if ( |
266 | 266 | $field_obj instanceof EE_Datetime_Field |
267 | - && $this->_fields[ $field_name ] !== null |
|
267 | + && $this->_fields[$field_name] !== null |
|
268 | 268 | && ! $this->_fields[$field_name] instanceof DateTime |
269 | 269 | ) { |
270 | - empty( $this->_fields[$field_name] ) |
|
271 | - ? $this->set( $field_name, time() ) |
|
272 | - : $this->set( $field_name, $this->_fields[$field_name] ); |
|
270 | + empty($this->_fields[$field_name]) |
|
271 | + ? $this->set($field_name, time()) |
|
272 | + : $this->set($field_name, $this->_fields[$field_name]); |
|
273 | 273 | } |
274 | 274 | |
275 | - }else{ |
|
275 | + } else { |
|
276 | 276 | $this->_fields[$field_name] = $holder_of_value; |
277 | 277 | } |
278 | 278 | |
279 | 279 | //if we're not in the constructor... |
280 | 280 | //now check if what we set was a primary key |
281 | - if( |
|
281 | + if ( |
|
282 | 282 | //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
283 | 283 | $this->_props_n_values_provided_in_constructor |
284 | 284 | && $field_value |
285 | - && $field_name === self::_get_primary_key_name( get_class( $this ) ) |
|
286 | - ){ |
|
285 | + && $field_name === self::_get_primary_key_name(get_class($this)) |
|
286 | + ) { |
|
287 | 287 | //if so, we want all this object's fields to be filled either with |
288 | 288 | //what we've explicitly set on this model |
289 | 289 | //or what we have in the db |
@@ -291,20 +291,20 @@ discard block |
||
291 | 291 | $fields_on_model = self::_get_model(get_class($this))->field_settings(); |
292 | 292 | |
293 | 293 | $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value); |
294 | - foreach($fields_on_model as $field_obj){ |
|
295 | - if( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
296 | - && $field_obj->get_name() !== $field_name ){ |
|
294 | + foreach ($fields_on_model as $field_obj) { |
|
295 | + if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
296 | + && $field_obj->get_name() !== $field_name) { |
|
297 | 297 | |
298 | - $this->set($field_obj->get_name(),$obj_in_db->get($field_obj->get_name())); |
|
298 | + $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
299 | 299 | } |
300 | 300 | } |
301 | 301 | //oh this model object has an ID? well make sure its in the entity mapper |
302 | 302 | $this->get_model()->add_to_entity_map($this); |
303 | 303 | } |
304 | 304 | //let's unset any cache for this field_name from the $_cached_properties property. |
305 | - $this->_clear_cached_property( $field_name ); |
|
306 | - }else{ |
|
307 | - throw new EE_Error( sprintf( __( "A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso" ), $field_name ) ); |
|
305 | + $this->_clear_cached_property($field_name); |
|
306 | + } else { |
|
307 | + throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso"), $field_name)); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | } |
@@ -321,14 +321,14 @@ discard block |
||
321 | 321 | * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
322 | 322 | * @throws \EE_Error |
323 | 323 | */ |
324 | - public function set_field_or_extra_meta( $field_name, $field_value ) { |
|
325 | - if ( $this->get_model()->has_field( $field_name ) ) { |
|
326 | - $this->set( $field_name, $field_value ); |
|
324 | + public function set_field_or_extra_meta($field_name, $field_value) { |
|
325 | + if ($this->get_model()->has_field($field_name)) { |
|
326 | + $this->set($field_name, $field_value); |
|
327 | 327 | return true; |
328 | 328 | } else { |
329 | 329 | //ensure this object is saved first so that extra meta can be properly related. |
330 | 330 | $this->save(); |
331 | - return $this->update_extra_meta( $field_name, $field_value ); |
|
331 | + return $this->update_extra_meta($field_name, $field_value); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
@@ -349,12 +349,12 @@ discard block |
||
349 | 349 | * @return mixed|null value for the field if found. null if not found. |
350 | 350 | * @throws \EE_Error |
351 | 351 | */ |
352 | - public function get_field_or_extra_meta( $field_name ) { |
|
353 | - if ( $this->get_model()->has_field( $field_name ) ) { |
|
354 | - $column_value = $this->get( $field_name ); |
|
352 | + public function get_field_or_extra_meta($field_name) { |
|
353 | + if ($this->get_model()->has_field($field_name)) { |
|
354 | + $column_value = $this->get($field_name); |
|
355 | 355 | } else { |
356 | 356 | //This isn't a column in the main table, let's see if it is in the extra meta. |
357 | - $column_value = $this->get_extra_meta( $field_name, true, null ); |
|
357 | + $column_value = $this->get_extra_meta($field_name, true, null); |
|
358 | 358 | } |
359 | 359 | return $column_value; |
360 | 360 | } |
@@ -370,18 +370,18 @@ discard block |
||
370 | 370 | * @return void |
371 | 371 | * @throws \EE_Error |
372 | 372 | */ |
373 | - public function set_timezone( $timezone = '' ) { |
|
374 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone ); |
|
373 | + public function set_timezone($timezone = '') { |
|
374 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
375 | 375 | //make sure we clear all cached properties because they won't be relevant now |
376 | 376 | $this->_clear_cached_properties(); |
377 | 377 | |
378 | 378 | //make sure we update field settings and the date for all EE_Datetime_Fields |
379 | - $model_fields = $this->get_model()->field_settings( false ); |
|
380 | - foreach ( $model_fields as $field_name => $field_obj ) { |
|
381 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
382 | - $field_obj->set_timezone( $this->_timezone ); |
|
383 | - if ( isset( $this->_fields[$field_name] ) && $this->_fields[$field_name] instanceof DateTime ) { |
|
384 | - $this->_fields[$field_name]->setTimezone( new DateTimeZone( $this->_timezone ) ); |
|
379 | + $model_fields = $this->get_model()->field_settings(false); |
|
380 | + foreach ($model_fields as $field_name => $field_obj) { |
|
381 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
382 | + $field_obj->set_timezone($this->_timezone); |
|
383 | + if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
384 | + $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
385 | 385 | } |
386 | 386 | } |
387 | 387 | } |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * |
411 | 411 | * @param string $format should be a format recognizable by PHP date() functions. |
412 | 412 | */ |
413 | - public function set_date_format( $format ) { |
|
413 | + public function set_date_format($format) { |
|
414 | 414 | $this->_dt_frmt = $format; |
415 | 415 | //clear cached_properties because they won't be relevant now. |
416 | 416 | $this->_clear_cached_properties(); |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | * @since 4.6 |
427 | 427 | * @param string $format should be a format recognizable by PHP date() functions. |
428 | 428 | */ |
429 | - public function set_time_format( $format ) { |
|
429 | + public function set_time_format($format) { |
|
430 | 430 | $this->_tm_frmt = $format; |
431 | 431 | //clear cached_properties because they won't be relevant now. |
432 | 432 | $this->_clear_cached_properties(); |
@@ -443,8 +443,8 @@ discard block |
||
443 | 443 | * |
444 | 444 | * @return mixed string|array |
445 | 445 | */ |
446 | - public function get_format( $full = true ) { |
|
447 | - return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array( $this->_dt_frmt, $this->_tm_frmt ); |
|
446 | + public function get_format($full = true) { |
|
447 | + return $full ? $this->_dt_frmt.' '.$this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | |
@@ -462,17 +462,17 @@ discard block |
||
462 | 462 | * @throws EE_Error |
463 | 463 | * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one related thing, no array) |
464 | 464 | */ |
465 | - public function cache( $relationName = '', $object_to_cache = NULL, $cache_id = NULL ){ |
|
465 | + public function cache($relationName = '', $object_to_cache = NULL, $cache_id = NULL) { |
|
466 | 466 | // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
467 | - if ( ! $object_to_cache instanceof EE_Base_Class ) { |
|
467 | + if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
468 | 468 | return FALSE; |
469 | 469 | } |
470 | 470 | // also get "how" the object is related, or throw an error |
471 | - if( ! $relationship_to_model = $this->get_model()->related_settings_for( $relationName )) { |
|
472 | - throw new EE_Error( sprintf( __( 'There is no relationship to %s on a %s. Cannot cache it', 'event_espresso' ), $relationName, get_class( $this ))); |
|
471 | + if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
472 | + throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), $relationName, get_class($this))); |
|
473 | 473 | } |
474 | 474 | // how many things are related ? |
475 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ){ |
|
475 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
476 | 476 | // if it's a "belongs to" relationship, then there's only one related model object eg, if this is a registration, there's only 1 attendee for it |
477 | 477 | // so for these model objects just set it to be cached |
478 | 478 | $this->_model_relations[$relationName] = $object_to_cache; |
@@ -480,26 +480,26 @@ discard block |
||
480 | 480 | } else { |
481 | 481 | // otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type. |
482 | 482 | // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
483 | - if( ! is_array( $this->_model_relations[$relationName] )) { |
|
483 | + if ( ! is_array($this->_model_relations[$relationName])) { |
|
484 | 484 | // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
485 | - $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array( $this->_model_relations[$relationName] ) : array(); |
|
485 | + $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array($this->_model_relations[$relationName]) : array(); |
|
486 | 486 | } |
487 | 487 | // first check for a cache_id which is normally empty |
488 | - if ( ! empty( $cache_id )) { |
|
488 | + if ( ! empty($cache_id)) { |
|
489 | 489 | // if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on |
490 | - $this->_model_relations[$relationName][ $cache_id ] = $object_to_cache; |
|
490 | + $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
491 | 491 | $return = $cache_id; |
492 | - } elseif ( $object_to_cache->ID() ) { |
|
492 | + } elseif ($object_to_cache->ID()) { |
|
493 | 493 | // OR the cached object originally came from the db, so let's just use it's PK for an ID |
494 | - $this->_model_relations[$relationName][ $object_to_cache->ID() ] = $object_to_cache; |
|
494 | + $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
495 | 495 | $return = $object_to_cache->ID(); |
496 | 496 | } else { |
497 | 497 | // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
498 | 498 | $this->_model_relations[$relationName][] = $object_to_cache; |
499 | 499 | // move the internal pointer to the end of the array |
500 | - end( $this->_model_relations[$relationName] ); |
|
500 | + end($this->_model_relations[$relationName]); |
|
501 | 501 | // and grab the key so that we can return it |
502 | - $return = key( $this->_model_relations[$relationName] ); |
|
502 | + $return = key($this->_model_relations[$relationName]); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | } |
@@ -518,11 +518,11 @@ discard block |
||
518 | 518 | * @return void |
519 | 519 | * @throws \EE_Error |
520 | 520 | */ |
521 | - protected function _set_cached_property( $fieldname, $value, $cache_type = NULL ) { |
|
521 | + protected function _set_cached_property($fieldname, $value, $cache_type = NULL) { |
|
522 | 522 | //first make sure this property exists |
523 | 523 | $this->get_model()->field_settings_for($fieldname); |
524 | 524 | |
525 | - $cache_type = empty( $cache_type ) ? 'standard' : $cache_type; |
|
525 | + $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
526 | 526 | $this->_cached_properties[$fieldname][$cache_type] = $value; |
527 | 527 | } |
528 | 528 | |
@@ -543,36 +543,36 @@ discard block |
||
543 | 543 | * @return mixed whatever the value for the property is we're retrieving |
544 | 544 | * @throws \EE_Error |
545 | 545 | */ |
546 | - protected function _get_cached_property( $fieldname, $pretty = FALSE, $extra_cache_ref = NULL ) { |
|
546 | + protected function _get_cached_property($fieldname, $pretty = FALSE, $extra_cache_ref = NULL) { |
|
547 | 547 | //verify the field exists |
548 | 548 | $this->get_model()->field_settings_for($fieldname); |
549 | 549 | |
550 | 550 | $cache_type = $pretty ? 'pretty' : 'standard'; |
551 | - $cache_type .= !empty( $extra_cache_ref ) ? '_' . $extra_cache_ref : ''; |
|
551 | + $cache_type .= ! empty($extra_cache_ref) ? '_'.$extra_cache_ref : ''; |
|
552 | 552 | |
553 | - if ( isset( $this->_cached_properties[$fieldname][$cache_type] ) ) { |
|
553 | + if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
554 | 554 | return $this->_cached_properties[$fieldname][$cache_type]; |
555 | 555 | } |
556 | 556 | |
557 | 557 | $field_obj = $this->get_model()->field_settings_for($fieldname); |
558 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
558 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
559 | 559 | /** |
560 | 560 | * maybe this is EE_Datetime_Field. If so we need to make sure timezone and |
561 | 561 | * formats are correct. |
562 | 562 | */ |
563 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
564 | - $field_obj->set_timezone( $this->_timezone ); |
|
565 | - $field_obj->set_date_format( $this->_dt_frmt, $pretty ); |
|
566 | - $field_obj->set_time_format( $this->_tm_frmt, $pretty ); |
|
563 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
564 | + $field_obj->set_timezone($this->_timezone); |
|
565 | + $field_obj->set_date_format($this->_dt_frmt, $pretty); |
|
566 | + $field_obj->set_time_format($this->_tm_frmt, $pretty); |
|
567 | 567 | } |
568 | 568 | |
569 | - if( ! isset($this->_fields[$fieldname])){ |
|
569 | + if ( ! isset($this->_fields[$fieldname])) { |
|
570 | 570 | $this->_fields[$fieldname] = NULL; |
571 | 571 | } |
572 | 572 | $value = $pretty |
573 | 573 | ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) |
574 | - : $field_obj->prepare_for_get($this->_fields[$fieldname] ); |
|
575 | - $this->_set_cached_property( $fieldname, $value, $cache_type ); |
|
574 | + : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
575 | + $this->_set_cached_property($fieldname, $value, $cache_type); |
|
576 | 576 | return $value; |
577 | 577 | } |
578 | 578 | return null; |
@@ -598,9 +598,9 @@ discard block |
||
598 | 598 | * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
599 | 599 | * @return void |
600 | 600 | */ |
601 | - protected function _clear_cached_property( $property_name ) { |
|
602 | - if ( isset( $this->_cached_properties[ $property_name ] ) ) { |
|
603 | - unset( $this->_cached_properties[ $property_name ] ); |
|
601 | + protected function _clear_cached_property($property_name) { |
|
602 | + if (isset($this->_cached_properties[$property_name])) { |
|
603 | + unset($this->_cached_properties[$property_name]); |
|
604 | 604 | } |
605 | 605 | } |
606 | 606 | |
@@ -614,12 +614,12 @@ discard block |
||
614 | 614 | * @return EE_Base_Class |
615 | 615 | * @throws \EE_Error |
616 | 616 | */ |
617 | - protected function ensure_related_thing_is_model_obj($object_or_id,$model_name){ |
|
617 | + protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) { |
|
618 | 618 | $other_model_instance = self::_get_model_instance_with_name( |
619 | - self::_get_model_classname( $model_name ), |
|
619 | + self::_get_model_classname($model_name), |
|
620 | 620 | $this->_timezone |
621 | 621 | ); |
622 | - return $other_model_instance->ensure_is_obj( $object_or_id ); |
|
622 | + return $other_model_instance->ensure_is_obj($object_or_id); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | |
@@ -636,32 +636,32 @@ discard block |
||
636 | 636 | * @throws EE_Error |
637 | 637 | * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all |
638 | 638 | */ |
639 | - public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE){ |
|
639 | + public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE) { |
|
640 | 640 | $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
641 | 641 | $index_in_cache = ''; |
642 | - if( ! $relationship_to_model){ |
|
642 | + if ( ! $relationship_to_model) { |
|
643 | 643 | throw new EE_Error( |
644 | 644 | sprintf( |
645 | - __( "There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso' ), |
|
645 | + __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), |
|
646 | 646 | $relationName, |
647 | - get_class( $this ) |
|
647 | + get_class($this) |
|
648 | 648 | ) |
649 | 649 | ); |
650 | 650 | } |
651 | - if($clear_all){ |
|
651 | + if ($clear_all) { |
|
652 | 652 | $obj_removed = true; |
653 | 653 | $this->_model_relations[$relationName] = null; |
654 | - }elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
654 | + }elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
655 | 655 | $obj_removed = $this->_model_relations[$relationName]; |
656 | 656 | $this->_model_relations[$relationName] = null; |
657 | - }else{ |
|
658 | - if($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()){ |
|
657 | + } else { |
|
658 | + if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) { |
|
659 | 659 | $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
660 | - if( is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])){ |
|
660 | + if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
661 | 661 | $index_found_at = NULL; |
662 | 662 | //find this object in the array even though it has a different key |
663 | - foreach($this->_model_relations[$relationName] as $index=>$obj){ |
|
664 | - if( |
|
663 | + foreach ($this->_model_relations[$relationName] as $index=>$obj) { |
|
664 | + if ( |
|
665 | 665 | $obj instanceof EE_Base_Class |
666 | 666 | && ( |
667 | 667 | $obj == $object_to_remove_or_index_into_array |
@@ -672,34 +672,34 @@ discard block |
||
672 | 672 | break; |
673 | 673 | } |
674 | 674 | } |
675 | - if($index_found_at){ |
|
675 | + if ($index_found_at) { |
|
676 | 676 | $index_in_cache = $index_found_at; |
677 | - }else{ |
|
677 | + } else { |
|
678 | 678 | //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
679 | 679 | //if it wasn't in it to begin with. So we're done |
680 | 680 | return $object_to_remove_or_index_into_array; |
681 | 681 | } |
682 | 682 | } |
683 | - }elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
683 | + }elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
684 | 684 | //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
685 | - foreach($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want){ |
|
686 | - if($potentially_obj_we_want == $object_to_remove_or_index_into_array){ |
|
685 | + foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
686 | + if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
687 | 687 | $index_in_cache = $index; |
688 | 688 | } |
689 | 689 | } |
690 | - }else{ |
|
690 | + } else { |
|
691 | 691 | $index_in_cache = $object_to_remove_or_index_into_array; |
692 | 692 | } |
693 | 693 | //supposedly we've found it. But it could just be that the client code |
694 | 694 | //provided a bad index/object |
695 | 695 | if ( |
696 | 696 | isset( |
697 | - $this->_model_relations[ $relationName ], |
|
698 | - $this->_model_relations[ $relationName ][ $index_in_cache ] |
|
697 | + $this->_model_relations[$relationName], |
|
698 | + $this->_model_relations[$relationName][$index_in_cache] |
|
699 | 699 | ) |
700 | 700 | ) { |
701 | - $obj_removed = $this->_model_relations[ $relationName ][ $index_in_cache ]; |
|
702 | - unset( $this->_model_relations[ $relationName ][ $index_in_cache ] ); |
|
701 | + $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
|
702 | + unset($this->_model_relations[$relationName][$index_in_cache]); |
|
703 | 703 | } else { |
704 | 704 | //that thing was never cached anyways. |
705 | 705 | $obj_removed = null; |
@@ -720,24 +720,24 @@ discard block |
||
720 | 720 | * @return boolean TRUE on success, FALSE on fail |
721 | 721 | * @throws \EE_Error |
722 | 722 | */ |
723 | - public function update_cache_after_object_save( $relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
723 | + public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
724 | 724 | // verify that incoming object is of the correct type |
725 | - $obj_class = 'EE_' . $relationName; |
|
726 | - if ( $newly_saved_object instanceof $obj_class ) { |
|
725 | + $obj_class = 'EE_'.$relationName; |
|
726 | + if ($newly_saved_object instanceof $obj_class) { |
|
727 | 727 | /* @type EE_Base_Class $newly_saved_object*/ |
728 | 728 | // now get the type of relation |
729 | - $relationship_to_model = $this->get_model()->related_settings_for( $relationName ); |
|
729 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
730 | 730 | // if this is a 1:1 relationship |
731 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ) { |
|
731 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
732 | 732 | // then just replace the cached object with the newly saved object |
733 | 733 | $this->_model_relations[$relationName] = $newly_saved_object; |
734 | 734 | return TRUE; |
735 | 735 | // or if it's some kind of sordid feral polyamorous relationship... |
736 | - } elseif ( is_array( $this->_model_relations[$relationName] ) && isset( $this->_model_relations[$relationName][ $current_cache_id ] )) { |
|
736 | + } elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) { |
|
737 | 737 | // then remove the current cached item |
738 | - unset( $this->_model_relations[$relationName][ $current_cache_id ] ); |
|
738 | + unset($this->_model_relations[$relationName][$current_cache_id]); |
|
739 | 739 | // and cache the newly saved object using it's new ID |
740 | - $this->_model_relations[$relationName][ $newly_saved_object->ID() ] = $newly_saved_object; |
|
740 | + $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
741 | 741 | return TRUE; |
742 | 742 | } |
743 | 743 | } |
@@ -753,11 +753,11 @@ discard block |
||
753 | 753 | * @param string $relationName |
754 | 754 | * @return EE_Base_Class |
755 | 755 | */ |
756 | - public function get_one_from_cache($relationName){ |
|
757 | - $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : null; |
|
758 | - if(is_array($cached_array_or_object)){ |
|
756 | + public function get_one_from_cache($relationName) { |
|
757 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : null; |
|
758 | + if (is_array($cached_array_or_object)) { |
|
759 | 759 | return array_shift($cached_array_or_object); |
760 | - }else{ |
|
760 | + } else { |
|
761 | 761 | return $cached_array_or_object; |
762 | 762 | } |
763 | 763 | } |
@@ -772,23 +772,23 @@ discard block |
||
772 | 772 | * @throws \EE_Error |
773 | 773 | * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
774 | 774 | */ |
775 | - public function get_all_from_cache($relationName){ |
|
776 | - $objects = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : array(); |
|
775 | + public function get_all_from_cache($relationName) { |
|
776 | + $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
777 | 777 | // if the result is not an array, but exists, make it an array |
778 | - $objects = is_array( $objects ) ? $objects : array( $objects ); |
|
778 | + $objects = is_array($objects) ? $objects : array($objects); |
|
779 | 779 | //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143 |
780 | 780 | //basically, if this model object was stored in the session, and these cached model objects |
781 | 781 | //already have IDs, let's make sure they're in their model's entity mapper |
782 | 782 | //otherwise we will have duplicates next time we call |
783 | 783 | // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
784 | - $model = EE_Registry::instance()->load_model( $relationName ); |
|
785 | - foreach( $objects as $model_object ){ |
|
786 | - if( $model instanceof EEM_Base && $model_object instanceof EE_Base_Class ){ |
|
784 | + $model = EE_Registry::instance()->load_model($relationName); |
|
785 | + foreach ($objects as $model_object) { |
|
786 | + if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
787 | 787 | //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
788 | - if( $model_object->ID() ){ |
|
789 | - $model->add_to_entity_map( $model_object ); |
|
788 | + if ($model_object->ID()) { |
|
789 | + $model->add_to_entity_map($model_object); |
|
790 | 790 | } |
791 | - }else{ |
|
791 | + } else { |
|
792 | 792 | throw new EE_Error( |
793 | 793 | sprintf( |
794 | 794 | __( |
@@ -796,7 +796,7 @@ discard block |
||
796 | 796 | 'event_espresso' |
797 | 797 | ), |
798 | 798 | $relationName, |
799 | - gettype( $model_object ) |
|
799 | + gettype($model_object) |
|
800 | 800 | ) |
801 | 801 | ); |
802 | 802 | } |
@@ -818,15 +818,15 @@ discard block |
||
818 | 818 | * @return array|EE_Base_Class[] |
819 | 819 | * @throws \EE_Error |
820 | 820 | */ |
821 | - public function next_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
822 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() |
|
821 | + public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
822 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
823 | 823 | ? $this->get_model()->get_primary_key_field()->get_name() |
824 | 824 | : $field_to_order_by; |
825 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
826 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
825 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
826 | + if (empty($field) || empty($current_value)) { |
|
827 | 827 | return array(); |
828 | 828 | } |
829 | - return $this->get_model()->next_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
829 | + return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | |
@@ -843,15 +843,15 @@ discard block |
||
843 | 843 | * @return array|EE_Base_Class[] |
844 | 844 | * @throws \EE_Error |
845 | 845 | */ |
846 | - public function previous_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
847 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() |
|
846 | + public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
847 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
848 | 848 | ? $this->get_model()->get_primary_key_field()->get_name() |
849 | 849 | : $field_to_order_by; |
850 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
851 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
850 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
851 | + if (empty($field) || empty($current_value)) { |
|
852 | 852 | return array(); |
853 | 853 | } |
854 | - return $this->get_model()->previous_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
854 | + return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | |
@@ -867,15 +867,15 @@ discard block |
||
867 | 867 | * @return array|EE_Base_Class |
868 | 868 | * @throws \EE_Error |
869 | 869 | */ |
870 | - public function next( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
871 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() |
|
870 | + public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
871 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
872 | 872 | ? $this->get_model()->get_primary_key_field()->get_name() |
873 | 873 | : $field_to_order_by; |
874 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
875 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
874 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
875 | + if (empty($field) || empty($current_value)) { |
|
876 | 876 | return array(); |
877 | 877 | } |
878 | - return $this->get_model()->next( $current_value, $field, $query_params, $columns_to_select ); |
|
878 | + return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select); |
|
879 | 879 | } |
880 | 880 | |
881 | 881 | |
@@ -891,15 +891,15 @@ discard block |
||
891 | 891 | * @return array|EE_Base_Class |
892 | 892 | * @throws \EE_Error |
893 | 893 | */ |
894 | - public function previous( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
895 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() |
|
894 | + public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
895 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
896 | 896 | ? $this->get_model()->get_primary_key_field()->get_name() |
897 | 897 | : $field_to_order_by; |
898 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
899 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
898 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
899 | + if (empty($field) || empty($current_value)) { |
|
900 | 900 | return array(); |
901 | 901 | } |
902 | - return $this->get_model()->previous( $current_value, $field, $query_params, $columns_to_select ); |
|
902 | + return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select); |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | |
@@ -912,25 +912,25 @@ discard block |
||
912 | 912 | * @param mixed $field_value_from_db |
913 | 913 | * @throws \EE_Error |
914 | 914 | */ |
915 | - public function set_from_db($field_name,$field_value_from_db){ |
|
915 | + public function set_from_db($field_name, $field_value_from_db) { |
|
916 | 916 | $field_obj = $this->get_model()->field_settings_for($field_name); |
917 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
917 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
918 | 918 | //you would think the DB has no NULLs for non-null label fields right? wrong! |
919 | 919 | //eg, a CPT model object could have an entry in the posts table, but no |
920 | 920 | //entry in the meta table. Meaning that all its columns in the meta table |
921 | 921 | //are null! yikes! so when we find one like that, use defaults for its meta columns |
922 | - if($field_value_from_db === NULL ){ |
|
923 | - if( $field_obj->is_nullable()){ |
|
922 | + if ($field_value_from_db === NULL) { |
|
923 | + if ($field_obj->is_nullable()) { |
|
924 | 924 | //if the field allows nulls, then let it be null |
925 | 925 | $field_value = NULL; |
926 | - }else{ |
|
926 | + } else { |
|
927 | 927 | $field_value = $field_obj->get_default_value(); |
928 | 928 | } |
929 | - }else{ |
|
930 | - $field_value = $field_obj->prepare_for_set_from_db( $field_value_from_db ); |
|
929 | + } else { |
|
930 | + $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
931 | 931 | } |
932 | 932 | $this->_fields[$field_name] = $field_value; |
933 | - $this->_clear_cached_property( $field_name ); |
|
933 | + $this->_clear_cached_property($field_name); |
|
934 | 934 | } |
935 | 935 | } |
936 | 936 | |
@@ -946,8 +946,8 @@ discard block |
||
946 | 946 | * @return mixed |
947 | 947 | * @throws \EE_Error |
948 | 948 | */ |
949 | - public function get($field_name, $extra_cache_ref = NULL ){ |
|
950 | - return $this->_get_cached_property( $field_name, FALSE, $extra_cache_ref ); |
|
949 | + public function get($field_name, $extra_cache_ref = NULL) { |
|
950 | + return $this->_get_cached_property($field_name, FALSE, $extra_cache_ref); |
|
951 | 951 | } |
952 | 952 | |
953 | 953 | |
@@ -980,10 +980,10 @@ discard block |
||
980 | 980 | * just null is returned (because that indicates that likely |
981 | 981 | * this field is nullable). |
982 | 982 | */ |
983 | - public function get_DateTime_object( $field_name ) { |
|
984 | - $field_settings = $this->get_model()->field_settings_for( $field_name ); |
|
983 | + public function get_DateTime_object($field_name) { |
|
984 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
985 | 985 | |
986 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
986 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
987 | 987 | EE_Error::add_error( |
988 | 988 | sprintf( |
989 | 989 | __( |
@@ -1015,7 +1015,7 @@ discard block |
||
1015 | 1015 | * @return void |
1016 | 1016 | * @throws \EE_Error |
1017 | 1017 | */ |
1018 | - public function e($field_name, $extra_cache_ref = NULL){ |
|
1018 | + public function e($field_name, $extra_cache_ref = NULL) { |
|
1019 | 1019 | echo $this->get_pretty($field_name, $extra_cache_ref); |
1020 | 1020 | } |
1021 | 1021 | |
@@ -1029,8 +1029,8 @@ discard block |
||
1029 | 1029 | * @return void |
1030 | 1030 | * @throws \EE_Error |
1031 | 1031 | */ |
1032 | - public function f($field_name){ |
|
1033 | - $this->e($field_name,'form_input'); |
|
1032 | + public function f($field_name) { |
|
1033 | + $this->e($field_name, 'form_input'); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | |
@@ -1043,8 +1043,8 @@ discard block |
||
1043 | 1043 | * @return mixed |
1044 | 1044 | * @throws \EE_Error |
1045 | 1045 | */ |
1046 | - public function get_pretty($field_name, $extra_cache_ref = NULL){ |
|
1047 | - return $this->_get_cached_property( $field_name, TRUE, $extra_cache_ref ); |
|
1046 | + public function get_pretty($field_name, $extra_cache_ref = NULL) { |
|
1047 | + return $this->_get_cached_property($field_name, TRUE, $extra_cache_ref); |
|
1048 | 1048 | } |
1049 | 1049 | |
1050 | 1050 | |
@@ -1062,36 +1062,36 @@ discard block |
||
1062 | 1062 | * @return void | string | bool | EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown if field is not a valid dtt field, or void if echoing |
1063 | 1063 | * @throws \EE_Error |
1064 | 1064 | */ |
1065 | - protected function _get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE ) { |
|
1065 | + protected function _get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE) { |
|
1066 | 1066 | |
1067 | - $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt; |
|
1067 | + $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt; |
|
1068 | 1068 | $in_tm_frmt = empty($tm_frmt) ? $this->_tm_frmt : $tm_frmt; |
1069 | 1069 | |
1070 | 1070 | //validate field for datetime and returns field settings if valid. |
1071 | - $field = $this->_get_dtt_field_settings( $field_name ); |
|
1071 | + $field = $this->_get_dtt_field_settings($field_name); |
|
1072 | 1072 | |
1073 | 1073 | //clear cached property if either formats are not null. |
1074 | - if( $dt_frmt !== null || $tm_frmt !== null ) { |
|
1075 | - $this->_clear_cached_property( $field_name ); |
|
1074 | + if ($dt_frmt !== null || $tm_frmt !== null) { |
|
1075 | + $this->_clear_cached_property($field_name); |
|
1076 | 1076 | //reset format properties because they are used in get() |
1077 | 1077 | $this->_dt_frmt = $in_dt_frmt; |
1078 | 1078 | $this->_tm_frmt = $in_tm_frmt; |
1079 | 1079 | } |
1080 | - if ( $echo ) { |
|
1081 | - $field->set_pretty_date_format( $in_dt_frmt ); |
|
1080 | + if ($echo) { |
|
1081 | + $field->set_pretty_date_format($in_dt_frmt); |
|
1082 | 1082 | } else { |
1083 | - $field->set_date_format( $in_dt_frmt ); |
|
1083 | + $field->set_date_format($in_dt_frmt); |
|
1084 | 1084 | } |
1085 | - if ( $echo ) { |
|
1086 | - $field->set_pretty_time_format( $in_tm_frmt ); |
|
1085 | + if ($echo) { |
|
1086 | + $field->set_pretty_time_format($in_tm_frmt); |
|
1087 | 1087 | } else { |
1088 | - $field->set_time_format( $in_tm_frmt ); |
|
1088 | + $field->set_time_format($in_tm_frmt); |
|
1089 | 1089 | } |
1090 | 1090 | //set timezone in field object |
1091 | - $field->set_timezone( $this->_timezone ); |
|
1091 | + $field->set_timezone($this->_timezone); |
|
1092 | 1092 | |
1093 | 1093 | //set the output returned |
1094 | - switch ( $date_or_time ) { |
|
1094 | + switch ($date_or_time) { |
|
1095 | 1095 | |
1096 | 1096 | case 'D' : |
1097 | 1097 | $field->set_date_time_output('date'); |
@@ -1106,11 +1106,11 @@ discard block |
||
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | |
1109 | - if ( $echo ) { |
|
1110 | - $this->e( $field_name, $date_or_time ); |
|
1109 | + if ($echo) { |
|
1110 | + $this->e($field_name, $date_or_time); |
|
1111 | 1111 | return ''; |
1112 | 1112 | } |
1113 | - return $this->get( $field_name, $date_or_time ); |
|
1113 | + return $this->get($field_name, $date_or_time); |
|
1114 | 1114 | } |
1115 | 1115 | |
1116 | 1116 | |
@@ -1123,8 +1123,8 @@ discard block |
||
1123 | 1123 | * @return string datetime value formatted |
1124 | 1124 | * @throws \EE_Error |
1125 | 1125 | */ |
1126 | - public function get_date( $field_name, $format = NULL ) { |
|
1127 | - return $this->_get_datetime( $field_name, $format, NULL, 'D' ); |
|
1126 | + public function get_date($field_name, $format = NULL) { |
|
1127 | + return $this->_get_datetime($field_name, $format, NULL, 'D'); |
|
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | |
@@ -1134,8 +1134,8 @@ discard block |
||
1134 | 1134 | * @param null $format |
1135 | 1135 | * @throws \EE_Error |
1136 | 1136 | */ |
1137 | - public function e_date( $field_name, $format = NULL ) { |
|
1138 | - $this->_get_datetime( $field_name, $format, NULL, 'D', TRUE ); |
|
1137 | + public function e_date($field_name, $format = NULL) { |
|
1138 | + $this->_get_datetime($field_name, $format, NULL, 'D', TRUE); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | |
@@ -1148,8 +1148,8 @@ discard block |
||
1148 | 1148 | * @return string datetime value formatted |
1149 | 1149 | * @throws \EE_Error |
1150 | 1150 | */ |
1151 | - public function get_time( $field_name, $format = NULL ) { |
|
1152 | - return $this->_get_datetime( $field_name, NULL, $format, 'T' ); |
|
1151 | + public function get_time($field_name, $format = NULL) { |
|
1152 | + return $this->_get_datetime($field_name, NULL, $format, 'T'); |
|
1153 | 1153 | } |
1154 | 1154 | |
1155 | 1155 | |
@@ -1159,8 +1159,8 @@ discard block |
||
1159 | 1159 | * @param null $format |
1160 | 1160 | * @throws \EE_Error |
1161 | 1161 | */ |
1162 | - public function e_time( $field_name, $format = NULL ) { |
|
1163 | - $this->_get_datetime( $field_name, NULL, $format, 'T', TRUE ); |
|
1162 | + public function e_time($field_name, $format = NULL) { |
|
1163 | + $this->_get_datetime($field_name, NULL, $format, 'T', TRUE); |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | |
@@ -1174,8 +1174,8 @@ discard block |
||
1174 | 1174 | * @return string datetime value formatted |
1175 | 1175 | * @throws \EE_Error |
1176 | 1176 | */ |
1177 | - public function get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
1178 | - return $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt ); |
|
1177 | + public function get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
1178 | + return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
1179 | 1179 | } |
1180 | 1180 | |
1181 | 1181 | |
@@ -1186,8 +1186,8 @@ discard block |
||
1186 | 1186 | * @param null $tm_frmt |
1187 | 1187 | * @throws \EE_Error |
1188 | 1188 | */ |
1189 | - public function e_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
1190 | - $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
1189 | + public function e_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
1190 | + $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
1191 | 1191 | } |
1192 | 1192 | |
1193 | 1193 | |
@@ -1201,11 +1201,11 @@ discard block |
||
1201 | 1201 | * @throws \EE_Error |
1202 | 1202 | * field name. |
1203 | 1203 | */ |
1204 | - public function get_i18n_datetime( $field_name, $format = NULL ) { |
|
1205 | - $format = empty( $format ) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
1204 | + public function get_i18n_datetime($field_name, $format = NULL) { |
|
1205 | + $format = empty($format) ? $this->_dt_frmt.' '.$this->_tm_frmt : $format; |
|
1206 | 1206 | return date_i18n( |
1207 | 1207 | $format, |
1208 | - EEH_DTT_Helper::get_timestamp_with_offset( $this->get_raw( $field_name ), $this->_timezone ) |
|
1208 | + EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone) |
|
1209 | 1209 | ); |
1210 | 1210 | } |
1211 | 1211 | |
@@ -1218,14 +1218,14 @@ discard block |
||
1218 | 1218 | * @throws EE_Error |
1219 | 1219 | * @return EE_Datetime_Field |
1220 | 1220 | */ |
1221 | - protected function _get_dtt_field_settings( $field_name ) { |
|
1221 | + protected function _get_dtt_field_settings($field_name) { |
|
1222 | 1222 | $field = $this->get_model()->field_settings_for($field_name); |
1223 | 1223 | |
1224 | 1224 | //check if field is dtt |
1225 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1225 | + if ($field instanceof EE_Datetime_Field) { |
|
1226 | 1226 | return $field; |
1227 | 1227 | } else { |
1228 | - throw new EE_Error( sprintf( __('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', 'event_espresso'), $field_name, self::_get_model_classname( get_class($this) ) ) ); |
|
1228 | + throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
1229 | 1229 | } |
1230 | 1230 | } |
1231 | 1231 | |
@@ -1246,8 +1246,8 @@ discard block |
||
1246 | 1246 | * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
1247 | 1247 | * @throws \EE_Error |
1248 | 1248 | */ |
1249 | - protected function _set_time_for( $time, $fieldname ) { |
|
1250 | - $this->_set_date_time( 'T', $time, $fieldname ); |
|
1249 | + protected function _set_time_for($time, $fieldname) { |
|
1250 | + $this->_set_date_time('T', $time, $fieldname); |
|
1251 | 1251 | } |
1252 | 1252 | |
1253 | 1253 | |
@@ -1260,8 +1260,8 @@ discard block |
||
1260 | 1260 | * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
1261 | 1261 | * @throws \EE_Error |
1262 | 1262 | */ |
1263 | - protected function _set_date_for( $date, $fieldname ) { |
|
1264 | - $this->_set_date_time( 'D', $date, $fieldname ); |
|
1263 | + protected function _set_date_for($date, $fieldname) { |
|
1264 | + $this->_set_date_time('D', $date, $fieldname); |
|
1265 | 1265 | } |
1266 | 1266 | |
1267 | 1267 | |
@@ -1275,26 +1275,26 @@ discard block |
||
1275 | 1275 | * @param string $fieldname the name of the field the date OR time is being set on (must match a EE_Datetime_Field property) |
1276 | 1276 | * @throws \EE_Error |
1277 | 1277 | */ |
1278 | - protected function _set_date_time( $what = 'T', $datetime_value, $fieldname ) { |
|
1279 | - $field = $this->_get_dtt_field_settings( $fieldname ); |
|
1280 | - $field->set_timezone( $this->_timezone ); |
|
1281 | - $field->set_date_format( $this->_dt_frmt ); |
|
1282 | - $field->set_time_format( $this->_tm_frmt ); |
|
1283 | - switch ( $what ) { |
|
1278 | + protected function _set_date_time($what = 'T', $datetime_value, $fieldname) { |
|
1279 | + $field = $this->_get_dtt_field_settings($fieldname); |
|
1280 | + $field->set_timezone($this->_timezone); |
|
1281 | + $field->set_date_format($this->_dt_frmt); |
|
1282 | + $field->set_time_format($this->_tm_frmt); |
|
1283 | + switch ($what) { |
|
1284 | 1284 | case 'T' : |
1285 | - $this->_fields[ $fieldname ] = $field->prepare_for_set_with_new_time( |
|
1285 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( |
|
1286 | 1286 | $datetime_value, |
1287 | - $this->_fields[ $fieldname ] |
|
1287 | + $this->_fields[$fieldname] |
|
1288 | 1288 | ); |
1289 | 1289 | break; |
1290 | 1290 | case 'D' : |
1291 | - $this->_fields[ $fieldname ] = $field->prepare_for_set_with_new_date( |
|
1291 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( |
|
1292 | 1292 | $datetime_value, |
1293 | - $this->_fields[ $fieldname ] |
|
1293 | + $this->_fields[$fieldname] |
|
1294 | 1294 | ); |
1295 | 1295 | break; |
1296 | 1296 | case 'B' : |
1297 | - $this->_fields[ $fieldname ] = $field->prepare_for_set( $datetime_value ); |
|
1297 | + $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
1298 | 1298 | break; |
1299 | 1299 | } |
1300 | 1300 | $this->_clear_cached_property($fieldname); |
@@ -1316,17 +1316,17 @@ discard block |
||
1316 | 1316 | * @throws EE_Error |
1317 | 1317 | * @return string timestamp |
1318 | 1318 | */ |
1319 | - public function display_in_my_timezone( $field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '' ) { |
|
1319 | + public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '') { |
|
1320 | 1320 | $timezone = EEH_DTT_Helper::get_timezone(); |
1321 | - if ( $timezone === $this->_timezone ) { |
|
1321 | + if ($timezone === $this->_timezone) { |
|
1322 | 1322 | return ''; |
1323 | 1323 | } |
1324 | 1324 | $original_timezone = $this->_timezone; |
1325 | - $this->set_timezone( $timezone ); |
|
1325 | + $this->set_timezone($timezone); |
|
1326 | 1326 | |
1327 | 1327 | $fn = (array) $field_name; |
1328 | - $args = array_merge( $fn, (array) $args ); |
|
1329 | - if ( ! method_exists( $this, $callback ) ) { |
|
1328 | + $args = array_merge($fn, (array) $args); |
|
1329 | + if ( ! method_exists($this, $callback)) { |
|
1330 | 1330 | throw new EE_Error( |
1331 | 1331 | sprintf( |
1332 | 1332 | __( |
@@ -1338,9 +1338,9 @@ discard block |
||
1338 | 1338 | ); |
1339 | 1339 | } |
1340 | 1340 | $args = (array) $args; |
1341 | - $return = $prepend . call_user_func_array( array( $this, $callback ), $args ) . $append; |
|
1341 | + $return = $prepend.call_user_func_array(array($this, $callback), $args).$append; |
|
1342 | 1342 | |
1343 | - $this->set_timezone( $original_timezone ); |
|
1343 | + $this->set_timezone($original_timezone); |
|
1344 | 1344 | return $return; |
1345 | 1345 | } |
1346 | 1346 | |
@@ -1354,7 +1354,7 @@ discard block |
||
1354 | 1354 | * @return boolean | int |
1355 | 1355 | * @throws \EE_Error |
1356 | 1356 | */ |
1357 | - public function delete(){ |
|
1357 | + public function delete() { |
|
1358 | 1358 | /** |
1359 | 1359 | * Called just before the `EE_Base_Class::_delete` method call. |
1360 | 1360 | * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
@@ -1363,7 +1363,7 @@ discard block |
||
1363 | 1363 | * |
1364 | 1364 | * @param EE_Base_Class $model_object about to be 'deleted' |
1365 | 1365 | */ |
1366 | - do_action( 'AHEE__EE_Base_Class__delete__before', $this ); |
|
1366 | + do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
1367 | 1367 | $result = $this->_delete(); |
1368 | 1368 | /** |
1369 | 1369 | * Called just after the `EE_Base_Class::_delete` method call. |
@@ -1373,7 +1373,7 @@ discard block |
||
1373 | 1373 | * @param EE_Base_Class $model_object that was just 'deleted' |
1374 | 1374 | * @param boolean $result |
1375 | 1375 | */ |
1376 | - do_action( 'AHEE__EE_Base_Class__delete__end', $this, $result ); |
|
1376 | + do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
1377 | 1377 | return $result; |
1378 | 1378 | } |
1379 | 1379 | |
@@ -1399,22 +1399,22 @@ discard block |
||
1399 | 1399 | * @return bool | int |
1400 | 1400 | * @throws \EE_Error |
1401 | 1401 | */ |
1402 | - public function delete_permanently(){ |
|
1402 | + public function delete_permanently() { |
|
1403 | 1403 | /** |
1404 | 1404 | * Called just before HARD deleting a model object |
1405 | 1405 | * |
1406 | 1406 | * @param EE_Base_Class $model_object about to be 'deleted' |
1407 | 1407 | */ |
1408 | - do_action( 'AHEE__EE_Base_Class__delete_permanently__before', $this ); |
|
1409 | - $model=$this->get_model(); |
|
1410 | - $result=$model->delete_permanently_by_ID($this->ID()); |
|
1408 | + do_action('AHEE__EE_Base_Class__delete_permanently__before', $this); |
|
1409 | + $model = $this->get_model(); |
|
1410 | + $result = $model->delete_permanently_by_ID($this->ID()); |
|
1411 | 1411 | $this->refresh_cache_of_related_objects(); |
1412 | 1412 | /** |
1413 | 1413 | * Called just after HARD deleting a model object |
1414 | 1414 | * @param EE_Base_Class $model_object that was just 'deleted' |
1415 | 1415 | * @param boolean $result |
1416 | 1416 | */ |
1417 | - do_action( 'AHEE__EE_Base_Class__delete_permanently__end', $this, $result ); |
|
1417 | + do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result); |
|
1418 | 1418 | return $result; |
1419 | 1419 | } |
1420 | 1420 | |
@@ -1427,18 +1427,18 @@ discard block |
||
1427 | 1427 | * @throws \EE_Error |
1428 | 1428 | */ |
1429 | 1429 | public function refresh_cache_of_related_objects() { |
1430 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
1431 | - if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
1432 | - $related_objects = $this->_model_relations[ $relation_name ]; |
|
1433 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
1430 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
1431 | + if ( ! empty($this->_model_relations[$relation_name])) { |
|
1432 | + $related_objects = $this->_model_relations[$relation_name]; |
|
1433 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
1434 | 1434 | //this relation only stores a single model object, not an array |
1435 | 1435 | //but let's make it consistent |
1436 | - $related_objects = array( $related_objects ); |
|
1436 | + $related_objects = array($related_objects); |
|
1437 | 1437 | } |
1438 | - foreach( $related_objects as $related_object ) { |
|
1438 | + foreach ($related_objects as $related_object) { |
|
1439 | 1439 | //only refresh their cache if they're in memory |
1440 | - if( $related_object instanceof EE_Base_Class ) { |
|
1441 | - $related_object->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1440 | + if ($related_object instanceof EE_Base_Class) { |
|
1441 | + $related_object->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1442 | 1442 | } |
1443 | 1443 | } |
1444 | 1444 | } |
@@ -1458,17 +1458,17 @@ discard block |
||
1458 | 1458 | * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
1459 | 1459 | * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
1460 | 1460 | */ |
1461 | - public function save($set_cols_n_values=array()) { |
|
1461 | + public function save($set_cols_n_values = array()) { |
|
1462 | 1462 | /** |
1463 | 1463 | * Filters the fields we're about to save on the model object |
1464 | 1464 | * |
1465 | 1465 | * @param array $set_cols_n_values |
1466 | 1466 | * @param EE_Base_Class $model_object |
1467 | 1467 | */ |
1468 | - $set_cols_n_values = (array)apply_filters( 'FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this ); |
|
1468 | + $set_cols_n_values = (array) apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this); |
|
1469 | 1469 | //set attributes as provided in $set_cols_n_values |
1470 | - foreach($set_cols_n_values as $column=>$value){ |
|
1471 | - $this->set($column,$value); |
|
1470 | + foreach ($set_cols_n_values as $column=>$value) { |
|
1471 | + $this->set($column, $value); |
|
1472 | 1472 | } |
1473 | 1473 | /** |
1474 | 1474 | * Saving a model object. |
@@ -1476,8 +1476,8 @@ discard block |
||
1476 | 1476 | * Before we perform a save, this action is fired. |
1477 | 1477 | * @param EE_Base_Class $model_object the model object about to be saved. |
1478 | 1478 | */ |
1479 | - do_action( 'AHEE__EE_Base_Class__save__begin', $this ); |
|
1480 | - if( ! $this->allow_persist() ) { |
|
1479 | + do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
1480 | + if ( ! $this->allow_persist()) { |
|
1481 | 1481 | return 0; |
1482 | 1482 | } |
1483 | 1483 | //now get current attribute values |
@@ -1487,61 +1487,61 @@ discard block |
||
1487 | 1487 | $old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object(); |
1488 | 1488 | $this->get_model()->assume_values_already_prepared_by_model_object(true); |
1489 | 1489 | //does this model have an autoincrement PK? |
1490 | - if($this->get_model()->has_primary_key_field()){ |
|
1491 | - if($this->get_model()->get_primary_key_field()->is_auto_increment()){ |
|
1490 | + if ($this->get_model()->has_primary_key_field()) { |
|
1491 | + if ($this->get_model()->get_primary_key_field()->is_auto_increment()) { |
|
1492 | 1492 | //ok check if it's set, if so: update; if not, insert |
1493 | - if ( ! empty( $save_cols_n_values[self::_get_primary_key_name( get_class($this) )] ) ){ |
|
1494 | - $results = $this->get_model()->update_by_ID ( $save_cols_n_values, $this->ID() ); |
|
1493 | + if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) { |
|
1494 | + $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
1495 | 1495 | } else { |
1496 | - unset($save_cols_n_values[self::_get_primary_key_name( get_class( $this) )]); |
|
1497 | - $results = $this->get_model()->insert( $save_cols_n_values ); |
|
1498 | - if($results){ |
|
1496 | + unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]); |
|
1497 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
1498 | + if ($results) { |
|
1499 | 1499 | //if successful, set the primary key |
1500 | 1500 | //but don't use the normal SET method, because it will check if |
1501 | 1501 | //an item with the same ID exists in the mapper & db, then |
1502 | 1502 | //will find it in the db (because we just added it) and THAT object |
1503 | 1503 | //will get added to the mapper before we can add this one! |
1504 | 1504 | //but if we just avoid using the SET method, all that headache can be avoided |
1505 | - $pk_field_name =self::_get_primary_key_name( get_class($this)); |
|
1505 | + $pk_field_name = self::_get_primary_key_name(get_class($this)); |
|
1506 | 1506 | $this->_fields[$pk_field_name] = $results; |
1507 | 1507 | $this->_clear_cached_property($pk_field_name); |
1508 | - $this->get_model()->add_to_entity_map( $this ); |
|
1508 | + $this->get_model()->add_to_entity_map($this); |
|
1509 | 1509 | $this->_update_cached_related_model_objs_fks(); |
1510 | 1510 | } |
1511 | 1511 | } |
1512 | - }else{//PK is NOT auto-increment |
|
1512 | + } else {//PK is NOT auto-increment |
|
1513 | 1513 | //so check if one like it already exists in the db |
1514 | - if( $this->get_model()->exists_by_ID( $this->ID() ) ){ |
|
1515 | - if( WP_DEBUG && ! $this->in_entity_map() ){ |
|
1514 | + if ($this->get_model()->exists_by_ID($this->ID())) { |
|
1515 | + if (WP_DEBUG && ! $this->in_entity_map()) { |
|
1516 | 1516 | throw new EE_Error( |
1517 | 1517 | sprintf( |
1518 | - __( 'Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', 'event_espresso' ), |
|
1518 | + __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', 'event_espresso'), |
|
1519 | 1519 | get_class($this), |
1520 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
1521 | - get_class( $this->get_model() ) . '::instance()->get_one_by_ID()', |
|
1520 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
1521 | + get_class($this->get_model()).'::instance()->get_one_by_ID()', |
|
1522 | 1522 | '<br />' |
1523 | 1523 | ) |
1524 | 1524 | ); |
1525 | 1525 | } |
1526 | 1526 | $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
1527 | - }else{ |
|
1527 | + } else { |
|
1528 | 1528 | $results = $this->get_model()->insert($save_cols_n_values); |
1529 | 1529 | $this->_update_cached_related_model_objs_fks(); |
1530 | 1530 | } |
1531 | 1531 | } |
1532 | - }else{//there is NO primary key |
|
1532 | + } else {//there is NO primary key |
|
1533 | 1533 | $already_in_db = false; |
1534 | - foreach($this->get_model()->unique_indexes() as $index){ |
|
1534 | + foreach ($this->get_model()->unique_indexes() as $index) { |
|
1535 | 1535 | $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
1536 | - if($this->get_model()->exists(array($uniqueness_where_params))){ |
|
1536 | + if ($this->get_model()->exists(array($uniqueness_where_params))) { |
|
1537 | 1537 | $already_in_db = true; |
1538 | 1538 | } |
1539 | 1539 | } |
1540 | - if( $already_in_db ){ |
|
1541 | - $combined_pk_fields_n_values = array_intersect_key( $save_cols_n_values, $this->get_model()->get_combined_primary_key_fields() ); |
|
1542 | - $results = $this->get_model()->update( $save_cols_n_values,$combined_pk_fields_n_values ); |
|
1543 | - }else{ |
|
1544 | - $results = $this->get_model()->insert( $save_cols_n_values ); |
|
1540 | + if ($already_in_db) { |
|
1541 | + $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields()); |
|
1542 | + $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
1543 | + } else { |
|
1544 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
1545 | 1545 | } |
1546 | 1546 | } |
1547 | 1547 | //restore the old assumption about values being prepared by the model object |
@@ -1554,7 +1554,7 @@ discard block |
||
1554 | 1554 | * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
1555 | 1555 | * the new ID (or 0 if an error occurred and it wasn't updated) |
1556 | 1556 | */ |
1557 | - do_action( 'AHEE__EE_Base_Class__save__end', $this, $results ); |
|
1557 | + do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
1558 | 1558 | return $results; |
1559 | 1559 | } |
1560 | 1560 | |
@@ -1569,15 +1569,15 @@ discard block |
||
1569 | 1569 | * @return void |
1570 | 1570 | * @throws \EE_Error |
1571 | 1571 | */ |
1572 | - protected function _update_cached_related_model_objs_fks(){ |
|
1573 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ){ |
|
1574 | - if( $relation_obj instanceof EE_Has_Many_Relation ){ |
|
1575 | - foreach( $this->get_all_from_cache( $relation_name ) as $related_model_obj_in_cache) { |
|
1572 | + protected function _update_cached_related_model_objs_fks() { |
|
1573 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
1574 | + if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
1575 | + foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
1576 | 1576 | $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( |
1577 | 1577 | $this->get_model()->get_this_model_name() |
1578 | 1578 | ); |
1579 | - $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID() ); |
|
1580 | - if( $related_model_obj_in_cache->ID() ){ |
|
1579 | + $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
1580 | + if ($related_model_obj_in_cache->ID()) { |
|
1581 | 1581 | $related_model_obj_in_cache->save(); |
1582 | 1582 | } |
1583 | 1583 | } |
@@ -1598,21 +1598,21 @@ discard block |
||
1598 | 1598 | * @return int ID of new model object on save; 0 on failure+ |
1599 | 1599 | * @throws \EE_Error |
1600 | 1600 | */ |
1601 | - public function save_new_cached_related_model_objs(){ |
|
1601 | + public function save_new_cached_related_model_objs() { |
|
1602 | 1602 | //make sure this has been saved |
1603 | - if( ! $this->ID()){ |
|
1603 | + if ( ! $this->ID()) { |
|
1604 | 1604 | $id = $this->save(); |
1605 | - }else{ |
|
1605 | + } else { |
|
1606 | 1606 | $id = $this->ID(); |
1607 | 1607 | } |
1608 | 1608 | //now save all the NEW cached model objects (ie they don't exist in the DB) |
1609 | - foreach($this->get_model()->relation_settings() as $relationName => $relationObj){ |
|
1609 | + foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
1610 | 1610 | |
1611 | 1611 | |
1612 | - if($this->_model_relations[$relationName]){ |
|
1612 | + if ($this->_model_relations[$relationName]) { |
|
1613 | 1613 | //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
1614 | 1614 | //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
1615 | - if($relationObj instanceof EE_Belongs_To_Relation){ |
|
1615 | + if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
1616 | 1616 | //add a relation to that relation type (which saves the appropriate thing in the process) |
1617 | 1617 | //but ONLY if it DOES NOT exist in the DB |
1618 | 1618 | /* @var $related_model_obj EE_Base_Class */ |
@@ -1621,8 +1621,8 @@ discard block |
||
1621 | 1621 | $this->_add_relation_to($related_model_obj, $relationName); |
1622 | 1622 | $related_model_obj->save_new_cached_related_model_objs(); |
1623 | 1623 | // } |
1624 | - }else{ |
|
1625 | - foreach($this->_model_relations[$relationName] as $related_model_obj){ |
|
1624 | + } else { |
|
1625 | + foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
1626 | 1626 | //add a relation to that relation type (which saves the appropriate thing in the process) |
1627 | 1627 | //but ONLY if it DOES NOT exist in the DB |
1628 | 1628 | // if( ! $related_model_obj->ID()){ |
@@ -1643,8 +1643,8 @@ discard block |
||
1643 | 1643 | * @return \EEM_Base | \EEM_CPT_Base |
1644 | 1644 | */ |
1645 | 1645 | public function get_model() { |
1646 | - $modelName = self::_get_model_classname( get_class($this) ); |
|
1647 | - return self::_get_model_instance_with_name($modelName, $this->_timezone ); |
|
1646 | + $modelName = self::_get_model_classname(get_class($this)); |
|
1647 | + return self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
1648 | 1648 | } |
1649 | 1649 | |
1650 | 1650 | |
@@ -1655,10 +1655,10 @@ discard block |
||
1655 | 1655 | * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
1656 | 1656 | * @throws \EE_Error |
1657 | 1657 | */ |
1658 | - protected static function _get_object_from_entity_mapper($props_n_values, $classname){ |
|
1658 | + protected static function _get_object_from_entity_mapper($props_n_values, $classname) { |
|
1659 | 1659 | //TODO: will not work for Term_Relationships because they have no PK! |
1660 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
1661 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
|
1660 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
1661 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
1662 | 1662 | $id = $props_n_values[$primary_id_ref]; |
1663 | 1663 | return self::_get_model($classname)->get_from_entity_map($id); |
1664 | 1664 | } |
@@ -1679,37 +1679,37 @@ discard block |
||
1679 | 1679 | * @return mixed (EE_Base_Class|bool) |
1680 | 1680 | * @throws \EE_Error |
1681 | 1681 | */ |
1682 | - protected static function _check_for_object( $props_n_values, $classname, $timezone = NULL, $date_formats = array() ) { |
|
1682 | + protected static function _check_for_object($props_n_values, $classname, $timezone = NULL, $date_formats = array()) { |
|
1683 | 1683 | $existing = null; |
1684 | - if ( self::_get_model( $classname )->has_primary_key_field() ) { |
|
1685 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
1686 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) |
|
1687 | - && ! empty( $props_n_values[ $primary_id_ref ] ) |
|
1684 | + if (self::_get_model($classname)->has_primary_key_field()) { |
|
1685 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
1686 | + if (array_key_exists($primary_id_ref, $props_n_values) |
|
1687 | + && ! empty($props_n_values[$primary_id_ref]) |
|
1688 | 1688 | ) { |
1689 | - $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( |
|
1690 | - $props_n_values[ $primary_id_ref ] |
|
1689 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
1690 | + $props_n_values[$primary_id_ref] |
|
1691 | 1691 | ); |
1692 | 1692 | } |
1693 | - } elseif ( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ) { |
|
1693 | + } elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) { |
|
1694 | 1694 | //no primary key on this model, but there's still a matching item in the DB |
1695 | - $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( |
|
1696 | - self::_get_model( $classname, $timezone )->get_index_primary_key_string( $props_n_values ) |
|
1695 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
1696 | + self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values) |
|
1697 | 1697 | ); |
1698 | 1698 | } |
1699 | - if ( $existing ) { |
|
1699 | + if ($existing) { |
|
1700 | 1700 | |
1701 | 1701 | //set date formats if present before setting values |
1702 | - if ( ! empty( $date_formats ) && is_array( $date_formats ) ) { |
|
1703 | - $existing->set_date_format( $date_formats[0] ); |
|
1704 | - $existing->set_time_format( $date_formats[1] ); |
|
1702 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
1703 | + $existing->set_date_format($date_formats[0]); |
|
1704 | + $existing->set_time_format($date_formats[1]); |
|
1705 | 1705 | } else { |
1706 | 1706 | //set default formats for date and time |
1707 | - $existing->set_date_format( get_option( 'date_format' ) ); |
|
1708 | - $existing->set_time_format( get_option( 'time_format' ) ); |
|
1707 | + $existing->set_date_format(get_option('date_format')); |
|
1708 | + $existing->set_time_format(get_option('time_format')); |
|
1709 | 1709 | } |
1710 | 1710 | |
1711 | - foreach ( $props_n_values as $property => $field_value ) { |
|
1712 | - $existing->set( $property, $field_value ); |
|
1711 | + foreach ($props_n_values as $property => $field_value) { |
|
1712 | + $existing->set($property, $field_value); |
|
1713 | 1713 | } |
1714 | 1714 | return $existing; |
1715 | 1715 | } else { |
@@ -1727,9 +1727,9 @@ discard block |
||
1727 | 1727 | * @throws EE_Error |
1728 | 1728 | * @return EEM_Base |
1729 | 1729 | */ |
1730 | - protected static function _get_model( $classname, $timezone = NULL ){ |
|
1730 | + protected static function _get_model($classname, $timezone = NULL) { |
|
1731 | 1731 | //find model for this class |
1732 | - if( ! $classname ){ |
|
1732 | + if ( ! $classname) { |
|
1733 | 1733 | throw new EE_Error( |
1734 | 1734 | sprintf( |
1735 | 1735 | __( |
@@ -1740,8 +1740,8 @@ discard block |
||
1740 | 1740 | ) |
1741 | 1741 | ); |
1742 | 1742 | } |
1743 | - $modelName=self::_get_model_classname($classname); |
|
1744 | - return self::_get_model_instance_with_name($modelName, $timezone ); |
|
1743 | + $modelName = self::_get_model_classname($classname); |
|
1744 | + return self::_get_model_instance_with_name($modelName, $timezone); |
|
1745 | 1745 | } |
1746 | 1746 | |
1747 | 1747 | |
@@ -1752,10 +1752,10 @@ discard block |
||
1752 | 1752 | * @param null $timezone |
1753 | 1753 | * @return EEM_Base |
1754 | 1754 | */ |
1755 | - protected static function _get_model_instance_with_name($model_classname, $timezone = NULL){ |
|
1756 | - $model_classname = str_replace( 'EEM_', '', $model_classname ); |
|
1757 | - $model = EE_Registry::instance()->load_model( $model_classname ); |
|
1758 | - $model->set_timezone( $timezone ); |
|
1755 | + protected static function _get_model_instance_with_name($model_classname, $timezone = NULL) { |
|
1756 | + $model_classname = str_replace('EEM_', '', $model_classname); |
|
1757 | + $model = EE_Registry::instance()->load_model($model_classname); |
|
1758 | + $model->set_timezone($timezone); |
|
1759 | 1759 | return $model; |
1760 | 1760 | } |
1761 | 1761 | |
@@ -1767,10 +1767,10 @@ discard block |
||
1767 | 1767 | * @param null $model_name |
1768 | 1768 | * @return string like EEM_Attendee |
1769 | 1769 | */ |
1770 | - private static function _get_model_classname( $model_name = null){ |
|
1771 | - if(strpos($model_name,"EE_")===0){ |
|
1772 | - $model_classname=str_replace("EE_","EEM_",$model_name); |
|
1773 | - }else{ |
|
1770 | + private static function _get_model_classname($model_name = null) { |
|
1771 | + if (strpos($model_name, "EE_") === 0) { |
|
1772 | + $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
1773 | + } else { |
|
1774 | 1774 | $model_classname = "EEM_".$model_name; |
1775 | 1775 | } |
1776 | 1776 | return $model_classname; |
@@ -1784,16 +1784,16 @@ discard block |
||
1784 | 1784 | * @throws EE_Error |
1785 | 1785 | * @return string |
1786 | 1786 | */ |
1787 | - protected static function _get_primary_key_name( $classname = NULL ){ |
|
1788 | - if( ! $classname){ |
|
1787 | + protected static function _get_primary_key_name($classname = NULL) { |
|
1788 | + if ( ! $classname) { |
|
1789 | 1789 | throw new EE_Error( |
1790 | 1790 | sprintf( |
1791 | - __( "What were you thinking calling _get_primary_key_name(%s)", "event_espresso" ), |
|
1791 | + __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), |
|
1792 | 1792 | $classname |
1793 | 1793 | ) |
1794 | 1794 | ); |
1795 | 1795 | } |
1796 | - return self::_get_model( $classname )->get_primary_key_field()->get_name(); |
|
1796 | + return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
1797 | 1797 | } |
1798 | 1798 | |
1799 | 1799 | |
@@ -1807,12 +1807,12 @@ discard block |
||
1807 | 1807 | * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
1808 | 1808 | * @throws \EE_Error |
1809 | 1809 | */ |
1810 | - public function ID(){ |
|
1810 | + public function ID() { |
|
1811 | 1811 | //now that we know the name of the variable, use a variable variable to get its value and return its |
1812 | - if( $this->get_model()->has_primary_key_field() ) { |
|
1813 | - return $this->_fields[ self::_get_primary_key_name( get_class($this) ) ]; |
|
1814 | - }else{ |
|
1815 | - return $this->get_model()->get_index_primary_key_string( $this->_fields ); |
|
1812 | + if ($this->get_model()->has_primary_key_field()) { |
|
1813 | + return $this->_fields[self::_get_primary_key_name(get_class($this))]; |
|
1814 | + } else { |
|
1815 | + return $this->get_model()->get_index_primary_key_string($this->_fields); |
|
1816 | 1816 | } |
1817 | 1817 | } |
1818 | 1818 | |
@@ -1830,38 +1830,38 @@ discard block |
||
1830 | 1830 | * @throws EE_Error |
1831 | 1831 | * @return EE_Base_Class the object the relation was added to |
1832 | 1832 | */ |
1833 | - public function _add_relation_to( $otherObjectModelObjectOrID,$relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL ){ |
|
1833 | + public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL) { |
|
1834 | 1834 | //if this thing exists in the DB, save the relation to the DB |
1835 | - if( $this->ID() ){ |
|
1836 | - $otherObject = $this->get_model()->add_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values ); |
|
1835 | + if ($this->ID()) { |
|
1836 | + $otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values); |
|
1837 | 1837 | //clear cache so future get_many_related and get_first_related() return new results. |
1838 | - $this->clear_cache( $relationName, $otherObject, TRUE ); |
|
1839 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1840 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1838 | + $this->clear_cache($relationName, $otherObject, TRUE); |
|
1839 | + if ($otherObject instanceof EE_Base_Class) { |
|
1840 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1841 | 1841 | } |
1842 | 1842 | } else { |
1843 | 1843 | //this thing doesn't exist in the DB, so just cache it |
1844 | - if( ! $otherObjectModelObjectOrID instanceof EE_Base_Class){ |
|
1845 | - throw new EE_Error( sprintf( |
|
1846 | - __( 'Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso' ), |
|
1844 | + if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
1845 | + throw new EE_Error(sprintf( |
|
1846 | + __('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso'), |
|
1847 | 1847 | $otherObjectModelObjectOrID, |
1848 | - get_class( $this ) |
|
1848 | + get_class($this) |
|
1849 | 1849 | )); |
1850 | 1850 | } else { |
1851 | 1851 | $otherObject = $otherObjectModelObjectOrID; |
1852 | 1852 | } |
1853 | - $this->cache( $relationName, $otherObjectModelObjectOrID, $cache_id ); |
|
1853 | + $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
1854 | 1854 | } |
1855 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1855 | + if ($otherObject instanceof EE_Base_Class) { |
|
1856 | 1856 | //fix the reciprocal relation too |
1857 | - if( $otherObject->ID() ) { |
|
1857 | + if ($otherObject->ID()) { |
|
1858 | 1858 | //its saved so assumed relations exist in the DB, so we can just |
1859 | 1859 | //clear the cache so future queries use the updated info in the DB |
1860 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
1860 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true); |
|
1861 | 1861 | } else { |
1862 | 1862 | |
1863 | 1863 | //it's not saved, so it caches relations like this |
1864 | - $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
1864 | + $otherObject->cache($this->get_model()->get_this_model_name(), $this); |
|
1865 | 1865 | } |
1866 | 1866 | } |
1867 | 1867 | return $otherObject; |
@@ -1885,17 +1885,17 @@ discard block |
||
1885 | 1885 | * @return EE_Base_Class the relation was removed from |
1886 | 1886 | * @throws \EE_Error |
1887 | 1887 | */ |
1888 | - public function _remove_relation_to($otherObjectModelObjectOrID,$relationName, $where_query = array() ){ |
|
1889 | - if ( $this->ID() ) { |
|
1888 | + public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) { |
|
1889 | + if ($this->ID()) { |
|
1890 | 1890 | //if this exists in the DB, save the relation change to the DB too |
1891 | - $otherObject = $this->get_model()->remove_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $where_query ); |
|
1892 | - $this->clear_cache( $relationName, $otherObject ); |
|
1891 | + $otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query); |
|
1892 | + $this->clear_cache($relationName, $otherObject); |
|
1893 | 1893 | } else { |
1894 | 1894 | //this doesn't exist in the DB, just remove it from the cache |
1895 | - $otherObject = $this->clear_cache( $relationName, $otherObjectModelObjectOrID ); |
|
1895 | + $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
1896 | 1896 | } |
1897 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1898 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1897 | + if ($otherObject instanceof EE_Base_Class) { |
|
1898 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1899 | 1899 | } |
1900 | 1900 | return $otherObject; |
1901 | 1901 | } |
@@ -1910,18 +1910,18 @@ discard block |
||
1910 | 1910 | * @return EE_Base_Class |
1911 | 1911 | * @throws \EE_Error |
1912 | 1912 | */ |
1913 | - public function _remove_relations($relationName,$where_query_params = array()){ |
|
1914 | - if ( $this->ID() ) { |
|
1913 | + public function _remove_relations($relationName, $where_query_params = array()) { |
|
1914 | + if ($this->ID()) { |
|
1915 | 1915 | //if this exists in the DB, save the relation change to the DB too |
1916 | - $otherObjects = $this->get_model()->remove_relations( $this, $relationName, $where_query_params ); |
|
1917 | - $this->clear_cache( $relationName, null, true ); |
|
1916 | + $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
1917 | + $this->clear_cache($relationName, null, true); |
|
1918 | 1918 | } else { |
1919 | 1919 | //this doesn't exist in the DB, just remove it from the cache |
1920 | - $otherObjects = $this->clear_cache( $relationName, null, true ); |
|
1920 | + $otherObjects = $this->clear_cache($relationName, null, true); |
|
1921 | 1921 | } |
1922 | - if( is_array( $otherObjects ) ) { |
|
1923 | - foreach ( $otherObjects as $otherObject ) { |
|
1924 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1922 | + if (is_array($otherObjects)) { |
|
1923 | + foreach ($otherObjects as $otherObject) { |
|
1924 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1925 | 1925 | } |
1926 | 1926 | } |
1927 | 1927 | return $otherObjects; |
@@ -1941,27 +1941,27 @@ discard block |
||
1941 | 1941 | * @throws \EE_Error |
1942 | 1942 | * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if you want IDs |
1943 | 1943 | */ |
1944 | - public function get_many_related($relationName,$query_params = array()){ |
|
1945 | - if($this->ID()){ |
|
1944 | + public function get_many_related($relationName, $query_params = array()) { |
|
1945 | + if ($this->ID()) { |
|
1946 | 1946 | //this exists in the DB, so get the related things from either the cache or the DB |
1947 | 1947 | //if there are query parameters, forget about caching the related model objects. |
1948 | - if( $query_params ){ |
|
1948 | + if ($query_params) { |
|
1949 | 1949 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
1950 | - }else{ |
|
1950 | + } else { |
|
1951 | 1951 | //did we already cache the result of this query? |
1952 | 1952 | $cached_results = $this->get_all_from_cache($relationName); |
1953 | - if ( ! $cached_results ){ |
|
1953 | + if ( ! $cached_results) { |
|
1954 | 1954 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
1955 | 1955 | //if no query parameters were passed, then we got all the related model objects |
1956 | 1956 | //for that relation. We can cache them then. |
1957 | - foreach($related_model_objects as $related_model_object){ |
|
1957 | + foreach ($related_model_objects as $related_model_object) { |
|
1958 | 1958 | $this->cache($relationName, $related_model_object); |
1959 | 1959 | } |
1960 | - }else{ |
|
1960 | + } else { |
|
1961 | 1961 | $related_model_objects = $cached_results; |
1962 | 1962 | } |
1963 | 1963 | } |
1964 | - }else{ |
|
1964 | + } else { |
|
1965 | 1965 | //this doesn't exist in the DB, so just get the related things from the cache |
1966 | 1966 | $related_model_objects = $this->get_all_from_cache($relationName); |
1967 | 1967 | } |
@@ -1979,8 +1979,8 @@ discard block |
||
1979 | 1979 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
1980 | 1980 | * @return int |
1981 | 1981 | */ |
1982 | - public function count_related($relation_name, $query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
1983 | - return $this->get_model()->count_related($this,$relation_name,$query_params,$field_to_count,$distinct); |
|
1982 | + public function count_related($relation_name, $query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
1983 | + return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
1984 | 1984 | } |
1985 | 1985 | |
1986 | 1986 | |
@@ -1994,7 +1994,7 @@ discard block |
||
1994 | 1994 | * By default, uses primary key (which doesn't make much sense, so you should probably change it) |
1995 | 1995 | * @return int |
1996 | 1996 | */ |
1997 | - public function sum_related($relation_name, $query_params = array(), $field_to_sum = null){ |
|
1997 | + public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) { |
|
1998 | 1998 | return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
1999 | 1999 | } |
2000 | 2000 | |
@@ -2008,33 +2008,33 @@ discard block |
||
2008 | 2008 | * @return EE_Base_Class (not an array, a single object) |
2009 | 2009 | * @throws \EE_Error |
2010 | 2010 | */ |
2011 | - public function get_first_related($relationName,$query_params = array()){ |
|
2012 | - if($this->ID()){//this exists in the DB, get from the cache OR the DB |
|
2011 | + public function get_first_related($relationName, $query_params = array()) { |
|
2012 | + if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
2013 | 2013 | |
2014 | 2014 | //if they've provided some query parameters, don't bother trying to cache the result |
2015 | 2015 | //also make sure we're not caching the result of get_first_related |
2016 | 2016 | //on a relation which should have an array of objects (because the cache might have an array of objects) |
2017 | - if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
2018 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
2019 | - }else{ |
|
2017 | + if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
2018 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
2019 | + } else { |
|
2020 | 2020 | //first, check if we've already cached the result of this query |
2021 | 2021 | $cached_result = $this->get_one_from_cache($relationName); |
2022 | - if ( ! $cached_result ){ |
|
2022 | + if ( ! $cached_result) { |
|
2023 | 2023 | |
2024 | 2024 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
2025 | - $this->cache($relationName,$related_model_object); |
|
2026 | - }else{ |
|
2025 | + $this->cache($relationName, $related_model_object); |
|
2026 | + } else { |
|
2027 | 2027 | $related_model_object = $cached_result; |
2028 | 2028 | } |
2029 | 2029 | } |
2030 | - }else{ |
|
2030 | + } else { |
|
2031 | 2031 | $related_model_object = null; |
2032 | 2032 | //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
2033 | - if( $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
2034 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
2033 | + if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
2034 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
2035 | 2035 | } |
2036 | 2036 | //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
2037 | - if( ! $related_model_object){ |
|
2037 | + if ( ! $related_model_object) { |
|
2038 | 2038 | $related_model_object = $this->get_one_from_cache($relationName); |
2039 | 2039 | } |
2040 | 2040 | |
@@ -2056,12 +2056,12 @@ discard block |
||
2056 | 2056 | * @return int how many deleted |
2057 | 2057 | * @throws \EE_Error |
2058 | 2058 | */ |
2059 | - public function delete_related($relationName,$query_params = array()){ |
|
2060 | - if($this->ID()){ |
|
2061 | - $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
2062 | - }else{ |
|
2059 | + public function delete_related($relationName, $query_params = array()) { |
|
2060 | + if ($this->ID()) { |
|
2061 | + $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
2062 | + } else { |
|
2063 | 2063 | $count = count($this->get_all_from_cache($relationName)); |
2064 | - $this->clear_cache($relationName,NULL,TRUE); |
|
2064 | + $this->clear_cache($relationName, NULL, TRUE); |
|
2065 | 2065 | } |
2066 | 2066 | return $count; |
2067 | 2067 | } |
@@ -2080,13 +2080,13 @@ discard block |
||
2080 | 2080 | * @return int how many deleted (including those soft deleted) |
2081 | 2081 | * @throws \EE_Error |
2082 | 2082 | */ |
2083 | - public function delete_related_permanently($relationName,$query_params = array()){ |
|
2084 | - if($this->ID()){ |
|
2085 | - $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
2086 | - }else{ |
|
2083 | + public function delete_related_permanently($relationName, $query_params = array()) { |
|
2084 | + if ($this->ID()) { |
|
2085 | + $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
2086 | + } else { |
|
2087 | 2087 | $count = count($this->get_all_from_cache($relationName)); |
2088 | 2088 | } |
2089 | - $this->clear_cache($relationName,NULL,TRUE); |
|
2089 | + $this->clear_cache($relationName, NULL, TRUE); |
|
2090 | 2090 | return $count; |
2091 | 2091 | } |
2092 | 2092 | |
@@ -2102,7 +2102,7 @@ discard block |
||
2102 | 2102 | * @param string $field_name property to check |
2103 | 2103 | * @return bool TRUE if existing,FALSE if not. |
2104 | 2104 | */ |
2105 | - public function is_set( $field_name ) { |
|
2105 | + public function is_set($field_name) { |
|
2106 | 2106 | return isset($this->_fields[$field_name]); |
2107 | 2107 | } |
2108 | 2108 | |
@@ -2114,11 +2114,11 @@ discard block |
||
2114 | 2114 | * @throws EE_Error |
2115 | 2115 | * @return bool TRUE if existing, throw EE_Error if not. |
2116 | 2116 | */ |
2117 | - protected function _property_exists( $properties ) { |
|
2117 | + protected function _property_exists($properties) { |
|
2118 | 2118 | |
2119 | - foreach ( (array) $properties as $property_name ) { |
|
2119 | + foreach ((array) $properties as $property_name) { |
|
2120 | 2120 | //first make sure this property exists |
2121 | - if ( ! $this->_fields[ $property_name ] ) { |
|
2121 | + if ( ! $this->_fields[$property_name]) { |
|
2122 | 2122 | throw new EE_Error( |
2123 | 2123 | sprintf( |
2124 | 2124 | __( |
@@ -2146,7 +2146,7 @@ discard block |
||
2146 | 2146 | $fields = $this->get_model()->field_settings(FALSE); |
2147 | 2147 | $properties = array(); |
2148 | 2148 | //remove prepended underscore |
2149 | - foreach ( $fields as $field_name => $settings ) { |
|
2149 | + foreach ($fields as $field_name => $settings) { |
|
2150 | 2150 | $properties[$field_name] = $this->get($field_name); |
2151 | 2151 | } |
2152 | 2152 | return $properties; |
@@ -2176,10 +2176,10 @@ discard block |
||
2176 | 2176 | * @throws EE_Error |
2177 | 2177 | * @return mixed whatever the plugin which calls add_filter decides |
2178 | 2178 | */ |
2179 | - public function __call($methodName,$args){ |
|
2180 | - $className=get_class($this); |
|
2181 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
2182 | - if ( ! has_filter( $tagName ) ) { |
|
2179 | + public function __call($methodName, $args) { |
|
2180 | + $className = get_class($this); |
|
2181 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
2182 | + if ( ! has_filter($tagName)) { |
|
2183 | 2183 | throw new EE_Error( |
2184 | 2184 | sprintf( |
2185 | 2185 | __( |
@@ -2192,7 +2192,7 @@ discard block |
||
2192 | 2192 | ) |
2193 | 2193 | ); |
2194 | 2194 | } |
2195 | - return apply_filters($tagName,null,$this,$args); |
|
2195 | + return apply_filters($tagName, null, $this, $args); |
|
2196 | 2196 | } |
2197 | 2197 | |
2198 | 2198 | |
@@ -2208,7 +2208,7 @@ discard block |
||
2208 | 2208 | * @throws \EE_Error |
2209 | 2209 | * NOTE: if the values haven't changed, returns 0 |
2210 | 2210 | */ |
2211 | - public function update_extra_meta($meta_key,$meta_value,$previous_value = NULL){ |
|
2211 | + public function update_extra_meta($meta_key, $meta_value, $previous_value = NULL) { |
|
2212 | 2212 | $query_params = array( |
2213 | 2213 | array( |
2214 | 2214 | 'EXM_key' => $meta_key, |
@@ -2216,17 +2216,17 @@ discard block |
||
2216 | 2216 | 'EXM_type' => $this->get_model()->get_this_model_name() |
2217 | 2217 | ) |
2218 | 2218 | ); |
2219 | - if ( $previous_value !== null ) { |
|
2219 | + if ($previous_value !== null) { |
|
2220 | 2220 | $query_params[0]['EXM_value'] = $meta_value; |
2221 | 2221 | } |
2222 | - $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all( $query_params ); |
|
2223 | - if ( ! $existing_rows_like_that ) { |
|
2224 | - return $this->add_extra_meta( $meta_key, $meta_value ); |
|
2222 | + $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
|
2223 | + if ( ! $existing_rows_like_that) { |
|
2224 | + return $this->add_extra_meta($meta_key, $meta_value); |
|
2225 | 2225 | } else { |
2226 | - foreach ( $existing_rows_like_that as $existing_row ) { |
|
2227 | - $existing_row->save( array( 'EXM_value' => $meta_value ) ); |
|
2226 | + foreach ($existing_rows_like_that as $existing_row) { |
|
2227 | + $existing_row->save(array('EXM_value' => $meta_value)); |
|
2228 | 2228 | } |
2229 | - return count( $existing_rows_like_that ); |
|
2229 | + return count($existing_rows_like_that); |
|
2230 | 2230 | } |
2231 | 2231 | } |
2232 | 2232 | |
@@ -2243,8 +2243,8 @@ discard block |
||
2243 | 2243 | * @return boolean |
2244 | 2244 | * @throws \EE_Error |
2245 | 2245 | */ |
2246 | - public function add_extra_meta($meta_key,$meta_value,$unique = false){ |
|
2247 | - if ( $unique ) { |
|
2246 | + public function add_extra_meta($meta_key, $meta_value, $unique = false) { |
|
2247 | + if ($unique) { |
|
2248 | 2248 | $existing_extra_meta = EEM_Extra_Meta::instance()->get_one( |
2249 | 2249 | array( |
2250 | 2250 | array( |
@@ -2254,7 +2254,7 @@ discard block |
||
2254 | 2254 | ) |
2255 | 2255 | ) |
2256 | 2256 | ); |
2257 | - if ( $existing_extra_meta ) { |
|
2257 | + if ($existing_extra_meta) { |
|
2258 | 2258 | return false; |
2259 | 2259 | } |
2260 | 2260 | } |
@@ -2281,7 +2281,7 @@ discard block |
||
2281 | 2281 | * @return int number of extra meta rows deleted |
2282 | 2282 | * @throws \EE_Error |
2283 | 2283 | */ |
2284 | - public function delete_extra_meta($meta_key,$meta_value = NULL){ |
|
2284 | + public function delete_extra_meta($meta_key, $meta_value = NULL) { |
|
2285 | 2285 | $query_params = array( |
2286 | 2286 | array( |
2287 | 2287 | 'EXM_key' => $meta_key, |
@@ -2289,10 +2289,10 @@ discard block |
||
2289 | 2289 | 'EXM_type' => $this->get_model()->get_this_model_name() |
2290 | 2290 | ) |
2291 | 2291 | ); |
2292 | - if ( $meta_value !== null ) { |
|
2292 | + if ($meta_value !== null) { |
|
2293 | 2293 | $query_params[0]['EXM_value'] = $meta_value; |
2294 | 2294 | } |
2295 | - return EEM_Extra_Meta::instance()->delete( $query_params ); |
|
2295 | + return EEM_Extra_Meta::instance()->delete($query_params); |
|
2296 | 2296 | } |
2297 | 2297 | |
2298 | 2298 | |
@@ -2308,25 +2308,25 @@ discard block |
||
2308 | 2308 | * @return mixed single value if $single; array if ! $single |
2309 | 2309 | * @throws \EE_Error |
2310 | 2310 | */ |
2311 | - public function get_extra_meta($meta_key,$single = FALSE,$default = NULL){ |
|
2312 | - if($single){ |
|
2313 | - $result = $this->get_first_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
2314 | - if ( $result instanceof EE_Extra_Meta ){ |
|
2311 | + public function get_extra_meta($meta_key, $single = FALSE, $default = NULL) { |
|
2312 | + if ($single) { |
|
2313 | + $result = $this->get_first_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
2314 | + if ($result instanceof EE_Extra_Meta) { |
|
2315 | 2315 | return $result->value(); |
2316 | - }else{ |
|
2316 | + } else { |
|
2317 | 2317 | return $default; |
2318 | 2318 | } |
2319 | - }else{ |
|
2320 | - $results = $this->get_many_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
2321 | - if($results){ |
|
2319 | + } else { |
|
2320 | + $results = $this->get_many_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
2321 | + if ($results) { |
|
2322 | 2322 | $values = array(); |
2323 | - foreach($results as $result){ |
|
2324 | - if ( $result instanceof EE_Extra_Meta ){ |
|
2323 | + foreach ($results as $result) { |
|
2324 | + if ($result instanceof EE_Extra_Meta) { |
|
2325 | 2325 | $values[$result->ID()] = $result->value(); |
2326 | 2326 | } |
2327 | 2327 | } |
2328 | 2328 | return $values; |
2329 | - }else{ |
|
2329 | + } else { |
|
2330 | 2330 | return $default; |
2331 | 2331 | } |
2332 | 2332 | } |
@@ -2348,20 +2348,20 @@ discard block |
||
2348 | 2348 | * @return array |
2349 | 2349 | * @throws \EE_Error |
2350 | 2350 | */ |
2351 | - public function all_extra_meta_array($one_of_each_key = true){ |
|
2351 | + public function all_extra_meta_array($one_of_each_key = true) { |
|
2352 | 2352 | $return_array = array(); |
2353 | - if($one_of_each_key){ |
|
2353 | + if ($one_of_each_key) { |
|
2354 | 2354 | $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by'=>'EXM_key')); |
2355 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
2356 | - if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
|
2355 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
2356 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
2357 | 2357 | $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
2358 | 2358 | } |
2359 | 2359 | } |
2360 | - }else{ |
|
2360 | + } else { |
|
2361 | 2361 | $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
2362 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
2363 | - if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
|
2364 | - if( ! isset($return_array[$extra_meta_obj->key()])){ |
|
2362 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
2363 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
2364 | + if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
2365 | 2365 | $return_array[$extra_meta_obj->key()] = array(); |
2366 | 2366 | } |
2367 | 2367 | $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
@@ -2379,19 +2379,19 @@ discard block |
||
2379 | 2379 | * @return string |
2380 | 2380 | * @throws \EE_Error |
2381 | 2381 | */ |
2382 | - public function name(){ |
|
2382 | + public function name() { |
|
2383 | 2383 | //find a field that's not a text field |
2384 | 2384 | $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
2385 | - if($field_we_can_use){ |
|
2385 | + if ($field_we_can_use) { |
|
2386 | 2386 | return $this->get($field_we_can_use->get_name()); |
2387 | - }else{ |
|
2387 | + } else { |
|
2388 | 2388 | $first_few_properties = $this->model_field_array(); |
2389 | - $first_few_properties = array_slice($first_few_properties,0,3); |
|
2389 | + $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
2390 | 2390 | $name_parts = array(); |
2391 | - foreach( $first_few_properties as $name=> $value ){ |
|
2391 | + foreach ($first_few_properties as $name=> $value) { |
|
2392 | 2392 | $name_parts[] = "$name:$value"; |
2393 | 2393 | } |
2394 | - return implode(",",$name_parts); |
|
2394 | + return implode(",", $name_parts); |
|
2395 | 2395 | } |
2396 | 2396 | } |
2397 | 2397 | |
@@ -2404,11 +2404,11 @@ discard block |
||
2404 | 2404 | * @return boolean |
2405 | 2405 | * @throws \EE_Error |
2406 | 2406 | */ |
2407 | - public function in_entity_map(){ |
|
2408 | - if( $this->ID() && $this->get_model()->get_from_entity_map( $this->ID() ) === $this ) { |
|
2407 | + public function in_entity_map() { |
|
2408 | + if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
2409 | 2409 | //well, if we looked, did we find it in the entity map? |
2410 | 2410 | return TRUE; |
2411 | - }else{ |
|
2411 | + } else { |
|
2412 | 2412 | return FALSE; |
2413 | 2413 | } |
2414 | 2414 | } |
@@ -2419,21 +2419,21 @@ discard block |
||
2419 | 2419 | * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
2420 | 2420 | * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
2421 | 2421 | */ |
2422 | - public function refresh_from_db(){ |
|
2423 | - if( $this->ID() && $this->in_entity_map() ){ |
|
2424 | - $this->get_model()->refresh_entity_map_from_db( $this->ID() ); |
|
2425 | - }else{ |
|
2422 | + public function refresh_from_db() { |
|
2423 | + if ($this->ID() && $this->in_entity_map()) { |
|
2424 | + $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
2425 | + } else { |
|
2426 | 2426 | //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
2427 | 2427 | //if it has an ID but it's not in the map, and you're asking me to refresh it |
2428 | 2428 | //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
2429 | 2429 | //absolutely nothing in it for this ID |
2430 | - if( WP_DEBUG ) { |
|
2430 | + if (WP_DEBUG) { |
|
2431 | 2431 | throw new EE_Error( |
2432 | 2432 | sprintf( |
2433 | - __( 'Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', 'event_espresso' ), |
|
2433 | + __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', 'event_espresso'), |
|
2434 | 2434 | $this->ID(), |
2435 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
2436 | - get_class( $this->get_model() ) . '::instance()->refresh_entity_map()' |
|
2435 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
2436 | + get_class($this->get_model()).'::instance()->refresh_entity_map()' |
|
2437 | 2437 | ) |
2438 | 2438 | ); |
2439 | 2439 | } |
@@ -2447,11 +2447,11 @@ discard block |
||
2447 | 2447 | * (probably a bad assumption they have made, oh well) |
2448 | 2448 | * @return string |
2449 | 2449 | */ |
2450 | - public function __toString(){ |
|
2450 | + public function __toString() { |
|
2451 | 2451 | try { |
2452 | - return sprintf( '%s (%s)', $this->name(), $this->ID() ); |
|
2453 | - } catch ( Exception $e ) { |
|
2454 | - EE_Error::add_error( $e->getMessage(), __FILE__, __FUNCTION__, __LINE__ ); |
|
2452 | + return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
2453 | + } catch (Exception $e) { |
|
2454 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
2455 | 2455 | return ''; |
2456 | 2456 | } |
2457 | 2457 | } |
@@ -2487,16 +2487,16 @@ discard block |
||
2487 | 2487 | * @throws \EE_Error |
2488 | 2488 | */ |
2489 | 2489 | public function __sleep() { |
2490 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
2491 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
2492 | - $classname = 'EE_' . $this->get_model()->get_this_model_name(); |
|
2493 | - if( $this->get_one_from_cache( $relation_name ) instanceof $classname && |
|
2494 | - $this->get_one_from_cache( $relation_name )->ID() ) { |
|
2495 | - $this->clear_cache( $relation_name, $this->get_one_from_cache( $relation_name )->ID() ); |
|
2490 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
2491 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
2492 | + $classname = 'EE_'.$this->get_model()->get_this_model_name(); |
|
2493 | + if ($this->get_one_from_cache($relation_name) instanceof $classname && |
|
2494 | + $this->get_one_from_cache($relation_name)->ID()) { |
|
2495 | + $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
2496 | 2496 | } |
2497 | 2497 | } |
2498 | 2498 | } |
2499 | - return array_keys( get_object_vars( $this ) ); |
|
2499 | + return array_keys(get_object_vars($this)); |
|
2500 | 2500 | } |
2501 | 2501 | |
2502 | 2502 |