@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -16,117 +16,117 @@ discard block |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * Constructor. |
|
21 | - * |
|
22 | - * @param EE_Registration[] $data expecting an array of EE_Registration objects. |
|
23 | - * @throws EE_Error |
|
24 | - * @access protected |
|
25 | - */ |
|
26 | - public function __construct($data = array()) |
|
27 | - { |
|
28 | - |
|
29 | - //validate that the first element in the array is an EE_Registration object. |
|
30 | - if (! reset($data) instanceof EE_Registration) { |
|
31 | - throw new EE_Error(__('The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', |
|
32 | - 'event_espresso')); |
|
33 | - } |
|
34 | - parent::__construct($data); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * setup the data. |
|
40 | - * Sets up the expected data object for the messages prep using incoming registration objects. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - * @access protected |
|
44 | - */ |
|
45 | - protected function _setup_data() |
|
46 | - { |
|
47 | - //we'll loop through each contact and setup the data needed. Note that many properties will just be set as empty |
|
48 | - //because this data handler is for a very specific set of data (i.e. just what's related to the registration). |
|
49 | - |
|
50 | - $this->reg_objs = $this->data(); |
|
51 | - $this->txn = $this->_maybe_get_transaction(); |
|
52 | - $this->_assemble_data(); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * If the incoming registrations all share the same transaction then this will return the transaction object shared |
|
58 | - * among the registrations. Otherwise the transaction object is set to null because its intended to only represent |
|
59 | - * one transaction. |
|
60 | - * |
|
61 | - * @return EE_Transaction|null |
|
62 | - */ |
|
63 | - protected function _maybe_get_transaction() |
|
64 | - { |
|
65 | - $transactions = array(); |
|
66 | - foreach ($this->reg_objs as $registration) { |
|
67 | - if ($registration instanceof EE_Registration) { |
|
68 | - $transaction = $registration->transaction(); |
|
69 | - if ($transaction instanceof EE_Transaction) { |
|
70 | - $transactions[$transaction->ID()] = $transaction; |
|
71 | - } |
|
72 | - } |
|
73 | - } |
|
74 | - return count($transactions) === 1 ? reset($transactions) : null; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * Returns database safe representation of the data later used to when instantiating this object. |
|
80 | - * |
|
81 | - * @param array $registrations The incoming data to be prepped. |
|
82 | - * @return EE_Registration[] The data being prepared for the db |
|
83 | - */ |
|
84 | - static public function convert_data_for_persistent_storage($registrations) |
|
85 | - { |
|
86 | - if ( |
|
87 | - ! is_array($registrations) |
|
88 | - || ! reset($registrations) instanceof EE_Registration |
|
89 | - ) { |
|
90 | - return array(); |
|
91 | - } |
|
92 | - |
|
93 | - $registration_ids = array(); |
|
94 | - |
|
95 | - $registration_ids = array_filter( |
|
96 | - array_map( |
|
97 | - function ($registration) { |
|
98 | - if ($registration instanceof EE_Registration) { |
|
99 | - return $registration->ID(); |
|
100 | - } |
|
101 | - return false; |
|
102 | - }, |
|
103 | - $registrations |
|
104 | - ) |
|
105 | - ); |
|
106 | - |
|
107 | - return $registration_ids; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
113 | - * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
114 | - * |
|
115 | - * @param array $data |
|
116 | - * @return EE_Registration[] |
|
117 | - */ |
|
118 | - static public function convert_data_from_persistent_storage($data) |
|
119 | - { |
|
120 | - //since this was added later, we need to account of possible back compat issues where data already queued for generation |
|
121 | - //is in the old format, which is an array of EE_Registration objects. So if that's the case, then let's just return them |
|
122 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10127 |
|
123 | - if (is_array($data) && reset($data) instanceof EE_Registration) { |
|
124 | - return $data; |
|
125 | - } |
|
126 | - |
|
127 | - $registrations = is_array($data) |
|
128 | - ? EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $data)))) |
|
129 | - : array(); |
|
130 | - return $registrations; |
|
131 | - } |
|
19 | + /** |
|
20 | + * Constructor. |
|
21 | + * |
|
22 | + * @param EE_Registration[] $data expecting an array of EE_Registration objects. |
|
23 | + * @throws EE_Error |
|
24 | + * @access protected |
|
25 | + */ |
|
26 | + public function __construct($data = array()) |
|
27 | + { |
|
28 | + |
|
29 | + //validate that the first element in the array is an EE_Registration object. |
|
30 | + if (! reset($data) instanceof EE_Registration) { |
|
31 | + throw new EE_Error(__('The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', |
|
32 | + 'event_espresso')); |
|
33 | + } |
|
34 | + parent::__construct($data); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * setup the data. |
|
40 | + * Sets up the expected data object for the messages prep using incoming registration objects. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + * @access protected |
|
44 | + */ |
|
45 | + protected function _setup_data() |
|
46 | + { |
|
47 | + //we'll loop through each contact and setup the data needed. Note that many properties will just be set as empty |
|
48 | + //because this data handler is for a very specific set of data (i.e. just what's related to the registration). |
|
49 | + |
|
50 | + $this->reg_objs = $this->data(); |
|
51 | + $this->txn = $this->_maybe_get_transaction(); |
|
52 | + $this->_assemble_data(); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * If the incoming registrations all share the same transaction then this will return the transaction object shared |
|
58 | + * among the registrations. Otherwise the transaction object is set to null because its intended to only represent |
|
59 | + * one transaction. |
|
60 | + * |
|
61 | + * @return EE_Transaction|null |
|
62 | + */ |
|
63 | + protected function _maybe_get_transaction() |
|
64 | + { |
|
65 | + $transactions = array(); |
|
66 | + foreach ($this->reg_objs as $registration) { |
|
67 | + if ($registration instanceof EE_Registration) { |
|
68 | + $transaction = $registration->transaction(); |
|
69 | + if ($transaction instanceof EE_Transaction) { |
|
70 | + $transactions[$transaction->ID()] = $transaction; |
|
71 | + } |
|
72 | + } |
|
73 | + } |
|
74 | + return count($transactions) === 1 ? reset($transactions) : null; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * Returns database safe representation of the data later used to when instantiating this object. |
|
80 | + * |
|
81 | + * @param array $registrations The incoming data to be prepped. |
|
82 | + * @return EE_Registration[] The data being prepared for the db |
|
83 | + */ |
|
84 | + static public function convert_data_for_persistent_storage($registrations) |
|
85 | + { |
|
86 | + if ( |
|
87 | + ! is_array($registrations) |
|
88 | + || ! reset($registrations) instanceof EE_Registration |
|
89 | + ) { |
|
90 | + return array(); |
|
91 | + } |
|
92 | + |
|
93 | + $registration_ids = array(); |
|
94 | + |
|
95 | + $registration_ids = array_filter( |
|
96 | + array_map( |
|
97 | + function ($registration) { |
|
98 | + if ($registration instanceof EE_Registration) { |
|
99 | + return $registration->ID(); |
|
100 | + } |
|
101 | + return false; |
|
102 | + }, |
|
103 | + $registrations |
|
104 | + ) |
|
105 | + ); |
|
106 | + |
|
107 | + return $registration_ids; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
113 | + * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
114 | + * |
|
115 | + * @param array $data |
|
116 | + * @return EE_Registration[] |
|
117 | + */ |
|
118 | + static public function convert_data_from_persistent_storage($data) |
|
119 | + { |
|
120 | + //since this was added later, we need to account of possible back compat issues where data already queued for generation |
|
121 | + //is in the old format, which is an array of EE_Registration objects. So if that's the case, then let's just return them |
|
122 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10127 |
|
123 | + if (is_array($data) && reset($data) instanceof EE_Registration) { |
|
124 | + return $data; |
|
125 | + } |
|
126 | + |
|
127 | + $registrations = is_array($data) |
|
128 | + ? EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $data)))) |
|
129 | + : array(); |
|
130 | + return $registrations; |
|
131 | + } |
|
132 | 132 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | { |
28 | 28 | |
29 | 29 | //validate that the first element in the array is an EE_Registration object. |
30 | - if (! reset($data) instanceof EE_Registration) { |
|
30 | + if ( ! reset($data) instanceof EE_Registration) { |
|
31 | 31 | throw new EE_Error(__('The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', |
32 | 32 | 'event_espresso')); |
33 | 33 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | $registration_ids = array_filter( |
96 | 96 | array_map( |
97 | - function ($registration) { |
|
97 | + function($registration) { |
|
98 | 98 | if ($registration instanceof EE_Registration) { |
99 | 99 | return $registration->ID(); |
100 | 100 | } |
@@ -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 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | { |
187 | 187 | //now let's get a list of shortcodes that are found in the given template |
188 | 188 | preg_match_all('/(\[.+?\])/', $this->_template, $matches); |
189 | - $shortcodes = (array)$matches[0]; //this should be an array of shortcodes in the template string. |
|
189 | + $shortcodes = (array) $matches[0]; //this should be an array of shortcodes in the template string. |
|
190 | 190 | |
191 | 191 | $matched_code = array(); |
192 | 192 | $sc_values = array(); |
@@ -220,14 +220,14 @@ discard block |
||
220 | 220 | if ($sc_obj instanceof EE_Shortcodes) { |
221 | 221 | //we need to setup any dynamic shortcodes so that they work with the array_key_exists |
222 | 222 | preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
223 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
223 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0].']' : $shortcode; |
|
224 | 224 | |
225 | - if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
225 | + if ( ! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
226 | 226 | continue; //the given shortcode isn't in this object |
227 | 227 | } |
228 | 228 | |
229 | 229 | //if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
230 | - if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
230 | + if ( ! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
231 | 231 | $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
232 | 232 | } else { |
233 | 233 | $data_send = $this->_data; |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | foreach ($valid_shortcodes as $shortcode_ref) { |
262 | 262 | $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
263 | 263 | $ref = str_replace(' ', '_', $ref); |
264 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
264 | + $classname = 'EE_'.$ref.'_Shortcodes'; |
|
265 | 265 | if (class_exists($classname)) { |
266 | 266 | $this->_shortcode_objs[] = new $classname; |
267 | 267 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('NO direct script access allowed'); |
|
4 | + exit('NO direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -26,269 +26,269 @@ discard block |
||
26 | 26 | { |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * holds the template |
|
31 | - * |
|
32 | - * @access private |
|
33 | - * @var mixed (string|array) |
|
34 | - */ |
|
35 | - private $_template; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * holds the incoming data object |
|
40 | - * |
|
41 | - * @access private |
|
42 | - * @var object |
|
43 | - */ |
|
44 | - private $_data; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * will hold an array of EE_Shortcodes library objects. |
|
49 | - * |
|
50 | - * @access private |
|
51 | - * @var EE_Shortcodes[] |
|
52 | - */ |
|
53 | - private $_shortcode_objs = array(); |
|
54 | - |
|
55 | - |
|
56 | - public function __construct() |
|
57 | - { |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * This kicks off the parsing of shortcodes in message templates |
|
63 | - * |
|
64 | - * @param string $template This is the incoming string to be parsed |
|
65 | - * @param EE_Messages_Addressee $data This is the incoming data object |
|
66 | - * @param array $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries |
|
67 | - * @param EE_message_type $message_type The message type that called the parser |
|
68 | - * @param EE_messenger $messenger The active messenger for this parsing session. |
|
69 | - * @param EE_Message $message |
|
70 | - * @return string The parsed template string |
|
71 | - */ |
|
72 | - public function parse_message_template( |
|
73 | - $template, |
|
74 | - EE_Messages_Addressee $data, |
|
75 | - $valid_shortcodes, |
|
76 | - EE_message_type $message_type, |
|
77 | - EE_messenger $messenger, |
|
78 | - EE_Message $message |
|
79 | - ) { |
|
80 | - $extra_data = array( |
|
81 | - 'messenger' => $messenger, |
|
82 | - 'message_type' => $message_type, |
|
83 | - 'message' => $message, |
|
84 | - ); |
|
85 | - $this->_init_data($template, $data, $valid_shortcodes, $extra_data); |
|
86 | - $this->_template = is_array($template) ? $template['main'] : $template; |
|
87 | - return $this->_parse_message_template(); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - public function parse_attendee_list_template( |
|
92 | - $template, |
|
93 | - EE_Registration $registration, |
|
94 | - $valid_shortcodes, |
|
95 | - $extra_data = array() |
|
96 | - ) { |
|
97 | - $this->_init_data($template, $registration, $valid_shortcodes, $extra_data); |
|
98 | - $this->_template = is_array($template) ? $template['attendee_list'] : $template; |
|
99 | - return $this->_parse_message_template(); |
|
100 | - } |
|
101 | - |
|
102 | - public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array()) |
|
103 | - { |
|
104 | - $this->_init_data($template, $event, $valid_shortcodes, $extra_data); |
|
105 | - $this->_template = is_array($template) ? $template['event_list'] : $template; |
|
106 | - return $this->_parse_message_template(); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array()) |
|
111 | - { |
|
112 | - $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data); |
|
113 | - $this->_template = is_array($template) ? $template['ticket_list'] : $template; |
|
114 | - return $this->_parse_message_template(); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - public function parse_line_item_list_template( |
|
119 | - $template, |
|
120 | - EE_Line_Item $line_item, |
|
121 | - $valid_shortcodes, |
|
122 | - $extra_data = array() |
|
123 | - ) { |
|
124 | - $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data); |
|
125 | - $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template; |
|
126 | - return $this->_parse_message_template(); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - public function parse_payment_list_template( |
|
131 | - $template, |
|
132 | - EE_Payment $payment_item, |
|
133 | - $valid_shortcodes, |
|
134 | - $extra_data = array() |
|
135 | - ) { |
|
136 | - $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data); |
|
137 | - $this->_template = is_array($template) ? $template['payment_list'] : $template; |
|
138 | - return $this->_parse_message_template(); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - public function parse_datetime_list_template( |
|
143 | - $template, |
|
144 | - EE_Datetime $datetime, |
|
145 | - $valid_shortcodes, |
|
146 | - $extra_data = array() |
|
147 | - ) { |
|
148 | - $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data); |
|
149 | - $this->_template = is_array($template) ? $template['datetime_list'] : $template; |
|
150 | - return $this->_parse_message_template(); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array()) |
|
155 | - { |
|
156 | - $this->_init_data($template, $answer, $valid_shortcodes, $extra_data); |
|
157 | - $this->_template = is_array($template) ? $template['question_list'] : $template; |
|
158 | - return $this->_parse_message_template(); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - private function _init_data($template, $data, $valid_shortcodes, $extra_data = array()) |
|
163 | - { |
|
164 | - $this->_reset_props(); |
|
165 | - $this->_data['template'] = $template; |
|
166 | - $this->_data['data'] = $data; |
|
167 | - $this->_data['extra_data'] = $extra_data; |
|
168 | - $this->_set_shortcodes($valid_shortcodes); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - private function _reset_props() |
|
173 | - { |
|
174 | - $this->_template = $this->_data = null; |
|
175 | - $this->_shortcode_objs = array(); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * takes the given template and parses it with the $_shortcodes property |
|
181 | - * |
|
182 | - * @access private |
|
183 | - * @return string |
|
184 | - */ |
|
185 | - private function _parse_message_template() |
|
186 | - { |
|
187 | - //now let's get a list of shortcodes that are found in the given template |
|
188 | - preg_match_all('/(\[.+?\])/', $this->_template, $matches); |
|
189 | - $shortcodes = (array)$matches[0]; //this should be an array of shortcodes in the template string. |
|
190 | - |
|
191 | - $matched_code = array(); |
|
192 | - $sc_values = array(); |
|
193 | - |
|
194 | - $list_type_shortcodes = array( |
|
195 | - '[ATTENDEE_LIST]', |
|
196 | - '[EVENT_LIST]', |
|
197 | - '[TICKET_LIST]', |
|
198 | - '[DATETIME_LIST]', |
|
199 | - '[QUESTION_LIST]', |
|
200 | - '[RECIPIENT_QUESTION_LIST]', |
|
201 | - '[PRIMARY_REGISTRANT_QUESTION_LIST]', |
|
202 | - '[RECIPIENT_TICKET_LIST]', |
|
203 | - '[PRIMARY_REGISTRANT_TICKET_LIST]', |
|
204 | - '[RECIPIENT_DATETIME_LIST]', |
|
205 | - '[PRIMARY_REGISTRANT_DATETIME_LIST]', |
|
206 | - '[TICKET_LINE_ITEM_LIST]', |
|
207 | - '[TAX_LINE_ITEM_LIST]', |
|
208 | - '[ADDITIONAL_LINE_ITEM_LIST]', |
|
209 | - '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
210 | - '[PAYMENT_LIST_*]', |
|
211 | - ); |
|
212 | - |
|
213 | - $list_type_shortcodes = apply_filters('FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
214 | - $list_type_shortcodes); |
|
215 | - |
|
216 | - //now lets go ahead and loop through our parsers for each shortcode and setup the values |
|
217 | - foreach ($shortcodes as $shortcode) { |
|
218 | - |
|
219 | - foreach ($this->_shortcode_objs as $sc_obj) { |
|
220 | - if ($sc_obj instanceof EE_Shortcodes) { |
|
221 | - //we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
222 | - preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
223 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
224 | - |
|
225 | - if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
226 | - continue; //the given shortcode isn't in this object |
|
227 | - } |
|
228 | - |
|
229 | - //if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
|
230 | - if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
231 | - $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
|
232 | - } else { |
|
233 | - $data_send = $this->_data; |
|
234 | - } |
|
235 | - |
|
236 | - //is this a conditional type shortcode? If it is then we actually parse the template here. |
|
237 | - if ($this->_is_conditional_shortcode($shortcode)) { |
|
238 | - //most shortcode parsers are not going to have a match for this shortcode and will return an |
|
239 | - //empty string so we need to make sure that we're only replacing the template when there is a non empty string. |
|
240 | - $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
241 | - if ($parsed) { |
|
242 | - $this->_template = $parsed; |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
247 | - |
|
248 | - $matched_code[] = $shortcode; |
|
249 | - $sc_values[] = $parsed; |
|
250 | - } |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - //now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out. |
|
255 | - $parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template); |
|
256 | - return $parsed; |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * Simply returns whether the given shortcode matches the structure for a conditional shortcode. |
|
262 | - * |
|
263 | - * Does it match this format: `[IF_` |
|
264 | - * |
|
265 | - * @param $shortcode |
|
266 | - */ |
|
267 | - protected function _is_conditional_shortcode($shortcode) |
|
268 | - { |
|
269 | - return strpos($shortcode, '[IF_') === 0; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of |
|
275 | - * various EE_Shortcode library objects |
|
276 | - * |
|
277 | - * @access private |
|
278 | - * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects |
|
279 | - * @return void |
|
280 | - */ |
|
281 | - private function _set_shortcodes($valid_shortcodes) |
|
282 | - { |
|
283 | - foreach ($valid_shortcodes as $shortcode_ref) { |
|
284 | - $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
|
285 | - $ref = str_replace(' ', '_', $ref); |
|
286 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
287 | - if (class_exists($classname)) { |
|
288 | - $this->_shortcode_objs[] = new $classname; |
|
289 | - } |
|
290 | - } |
|
291 | - } |
|
29 | + /** |
|
30 | + * holds the template |
|
31 | + * |
|
32 | + * @access private |
|
33 | + * @var mixed (string|array) |
|
34 | + */ |
|
35 | + private $_template; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * holds the incoming data object |
|
40 | + * |
|
41 | + * @access private |
|
42 | + * @var object |
|
43 | + */ |
|
44 | + private $_data; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * will hold an array of EE_Shortcodes library objects. |
|
49 | + * |
|
50 | + * @access private |
|
51 | + * @var EE_Shortcodes[] |
|
52 | + */ |
|
53 | + private $_shortcode_objs = array(); |
|
54 | + |
|
55 | + |
|
56 | + public function __construct() |
|
57 | + { |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * This kicks off the parsing of shortcodes in message templates |
|
63 | + * |
|
64 | + * @param string $template This is the incoming string to be parsed |
|
65 | + * @param EE_Messages_Addressee $data This is the incoming data object |
|
66 | + * @param array $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries |
|
67 | + * @param EE_message_type $message_type The message type that called the parser |
|
68 | + * @param EE_messenger $messenger The active messenger for this parsing session. |
|
69 | + * @param EE_Message $message |
|
70 | + * @return string The parsed template string |
|
71 | + */ |
|
72 | + public function parse_message_template( |
|
73 | + $template, |
|
74 | + EE_Messages_Addressee $data, |
|
75 | + $valid_shortcodes, |
|
76 | + EE_message_type $message_type, |
|
77 | + EE_messenger $messenger, |
|
78 | + EE_Message $message |
|
79 | + ) { |
|
80 | + $extra_data = array( |
|
81 | + 'messenger' => $messenger, |
|
82 | + 'message_type' => $message_type, |
|
83 | + 'message' => $message, |
|
84 | + ); |
|
85 | + $this->_init_data($template, $data, $valid_shortcodes, $extra_data); |
|
86 | + $this->_template = is_array($template) ? $template['main'] : $template; |
|
87 | + return $this->_parse_message_template(); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + public function parse_attendee_list_template( |
|
92 | + $template, |
|
93 | + EE_Registration $registration, |
|
94 | + $valid_shortcodes, |
|
95 | + $extra_data = array() |
|
96 | + ) { |
|
97 | + $this->_init_data($template, $registration, $valid_shortcodes, $extra_data); |
|
98 | + $this->_template = is_array($template) ? $template['attendee_list'] : $template; |
|
99 | + return $this->_parse_message_template(); |
|
100 | + } |
|
101 | + |
|
102 | + public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array()) |
|
103 | + { |
|
104 | + $this->_init_data($template, $event, $valid_shortcodes, $extra_data); |
|
105 | + $this->_template = is_array($template) ? $template['event_list'] : $template; |
|
106 | + return $this->_parse_message_template(); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array()) |
|
111 | + { |
|
112 | + $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data); |
|
113 | + $this->_template = is_array($template) ? $template['ticket_list'] : $template; |
|
114 | + return $this->_parse_message_template(); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + public function parse_line_item_list_template( |
|
119 | + $template, |
|
120 | + EE_Line_Item $line_item, |
|
121 | + $valid_shortcodes, |
|
122 | + $extra_data = array() |
|
123 | + ) { |
|
124 | + $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data); |
|
125 | + $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template; |
|
126 | + return $this->_parse_message_template(); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + public function parse_payment_list_template( |
|
131 | + $template, |
|
132 | + EE_Payment $payment_item, |
|
133 | + $valid_shortcodes, |
|
134 | + $extra_data = array() |
|
135 | + ) { |
|
136 | + $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data); |
|
137 | + $this->_template = is_array($template) ? $template['payment_list'] : $template; |
|
138 | + return $this->_parse_message_template(); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + public function parse_datetime_list_template( |
|
143 | + $template, |
|
144 | + EE_Datetime $datetime, |
|
145 | + $valid_shortcodes, |
|
146 | + $extra_data = array() |
|
147 | + ) { |
|
148 | + $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data); |
|
149 | + $this->_template = is_array($template) ? $template['datetime_list'] : $template; |
|
150 | + return $this->_parse_message_template(); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array()) |
|
155 | + { |
|
156 | + $this->_init_data($template, $answer, $valid_shortcodes, $extra_data); |
|
157 | + $this->_template = is_array($template) ? $template['question_list'] : $template; |
|
158 | + return $this->_parse_message_template(); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + private function _init_data($template, $data, $valid_shortcodes, $extra_data = array()) |
|
163 | + { |
|
164 | + $this->_reset_props(); |
|
165 | + $this->_data['template'] = $template; |
|
166 | + $this->_data['data'] = $data; |
|
167 | + $this->_data['extra_data'] = $extra_data; |
|
168 | + $this->_set_shortcodes($valid_shortcodes); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + private function _reset_props() |
|
173 | + { |
|
174 | + $this->_template = $this->_data = null; |
|
175 | + $this->_shortcode_objs = array(); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * takes the given template and parses it with the $_shortcodes property |
|
181 | + * |
|
182 | + * @access private |
|
183 | + * @return string |
|
184 | + */ |
|
185 | + private function _parse_message_template() |
|
186 | + { |
|
187 | + //now let's get a list of shortcodes that are found in the given template |
|
188 | + preg_match_all('/(\[.+?\])/', $this->_template, $matches); |
|
189 | + $shortcodes = (array)$matches[0]; //this should be an array of shortcodes in the template string. |
|
190 | + |
|
191 | + $matched_code = array(); |
|
192 | + $sc_values = array(); |
|
193 | + |
|
194 | + $list_type_shortcodes = array( |
|
195 | + '[ATTENDEE_LIST]', |
|
196 | + '[EVENT_LIST]', |
|
197 | + '[TICKET_LIST]', |
|
198 | + '[DATETIME_LIST]', |
|
199 | + '[QUESTION_LIST]', |
|
200 | + '[RECIPIENT_QUESTION_LIST]', |
|
201 | + '[PRIMARY_REGISTRANT_QUESTION_LIST]', |
|
202 | + '[RECIPIENT_TICKET_LIST]', |
|
203 | + '[PRIMARY_REGISTRANT_TICKET_LIST]', |
|
204 | + '[RECIPIENT_DATETIME_LIST]', |
|
205 | + '[PRIMARY_REGISTRANT_DATETIME_LIST]', |
|
206 | + '[TICKET_LINE_ITEM_LIST]', |
|
207 | + '[TAX_LINE_ITEM_LIST]', |
|
208 | + '[ADDITIONAL_LINE_ITEM_LIST]', |
|
209 | + '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
210 | + '[PAYMENT_LIST_*]', |
|
211 | + ); |
|
212 | + |
|
213 | + $list_type_shortcodes = apply_filters('FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
214 | + $list_type_shortcodes); |
|
215 | + |
|
216 | + //now lets go ahead and loop through our parsers for each shortcode and setup the values |
|
217 | + foreach ($shortcodes as $shortcode) { |
|
218 | + |
|
219 | + foreach ($this->_shortcode_objs as $sc_obj) { |
|
220 | + if ($sc_obj instanceof EE_Shortcodes) { |
|
221 | + //we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
222 | + preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
223 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
224 | + |
|
225 | + if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
226 | + continue; //the given shortcode isn't in this object |
|
227 | + } |
|
228 | + |
|
229 | + //if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
|
230 | + if (! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
231 | + $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
|
232 | + } else { |
|
233 | + $data_send = $this->_data; |
|
234 | + } |
|
235 | + |
|
236 | + //is this a conditional type shortcode? If it is then we actually parse the template here. |
|
237 | + if ($this->_is_conditional_shortcode($shortcode)) { |
|
238 | + //most shortcode parsers are not going to have a match for this shortcode and will return an |
|
239 | + //empty string so we need to make sure that we're only replacing the template when there is a non empty string. |
|
240 | + $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
241 | + if ($parsed) { |
|
242 | + $this->_template = $parsed; |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
247 | + |
|
248 | + $matched_code[] = $shortcode; |
|
249 | + $sc_values[] = $parsed; |
|
250 | + } |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + //now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out. |
|
255 | + $parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template); |
|
256 | + return $parsed; |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * Simply returns whether the given shortcode matches the structure for a conditional shortcode. |
|
262 | + * |
|
263 | + * Does it match this format: `[IF_` |
|
264 | + * |
|
265 | + * @param $shortcode |
|
266 | + */ |
|
267 | + protected function _is_conditional_shortcode($shortcode) |
|
268 | + { |
|
269 | + return strpos($shortcode, '[IF_') === 0; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of |
|
275 | + * various EE_Shortcode library objects |
|
276 | + * |
|
277 | + * @access private |
|
278 | + * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects |
|
279 | + * @return void |
|
280 | + */ |
|
281 | + private function _set_shortcodes($valid_shortcodes) |
|
282 | + { |
|
283 | + foreach ($valid_shortcodes as $shortcode_ref) { |
|
284 | + $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
|
285 | + $ref = str_replace(' ', '_', $ref); |
|
286 | + $classname = 'EE_' . $ref . '_Shortcodes'; |
|
287 | + if (class_exists($classname)) { |
|
288 | + $this->_shortcode_objs[] = new $classname; |
|
289 | + } |
|
290 | + } |
|
291 | + } |
|
292 | 292 | |
293 | 293 | |
294 | 294 | } //end EEH_Parse_Shortcodes |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | * date_format and the second value is the time format |
51 | 51 | * @return EE_Line_Item |
52 | 52 | */ |
53 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
54 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
55 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
53 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
54 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
55 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | * the website will be used. |
64 | 64 | * @return EE_Line_Item |
65 | 65 | */ |
66 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
67 | - return new self( $props_n_values, TRUE, $timezone ); |
|
66 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
67 | + return new self($props_n_values, TRUE, $timezone); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | * @param bool $bydb |
76 | 76 | * @param string $timezone |
77 | 77 | */ |
78 | - protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '' ) { |
|
79 | - parent::__construct( $fieldValues, $bydb, $timezone ); |
|
80 | - if ( ! $this->get( 'LIN_code' ) ) { |
|
81 | - $this->set_code( $this->generate_code() ); |
|
78 | + protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '') { |
|
79 | + parent::__construct($fieldValues, $bydb, $timezone); |
|
80 | + if ( ! $this->get('LIN_code')) { |
|
81 | + $this->set_code($this->generate_code()); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @return int |
90 | 90 | */ |
91 | 91 | public function ID() { |
92 | - return $this->get( 'LIN_ID' ); |
|
92 | + return $this->get('LIN_ID'); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @return int |
100 | 100 | */ |
101 | 101 | public function TXN_ID() { |
102 | - return $this->get( 'TXN_ID' ); |
|
102 | + return $this->get('TXN_ID'); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * Sets TXN_ID |
109 | 109 | * @param int $TXN_ID |
110 | 110 | */ |
111 | - public function set_TXN_ID( $TXN_ID ) { |
|
112 | - $this->set( 'TXN_ID', $TXN_ID ); |
|
111 | + public function set_TXN_ID($TXN_ID) { |
|
112 | + $this->set('TXN_ID', $TXN_ID); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * @return string |
120 | 120 | */ |
121 | 121 | public function name() { |
122 | - $name = $this->get( 'LIN_name' ); |
|
123 | - if( ! $name ){ |
|
124 | - $name = ucwords( str_replace( '-', ' ', $this->type() ) ); |
|
122 | + $name = $this->get('LIN_name'); |
|
123 | + if ( ! $name) { |
|
124 | + $name = ucwords(str_replace('-', ' ', $this->type())); |
|
125 | 125 | } |
126 | 126 | return $name; |
127 | 127 | } |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * Sets name |
133 | 133 | * @param string $name |
134 | 134 | */ |
135 | - public function set_name( $name ) { |
|
136 | - $this->set( 'LIN_name', $name ); |
|
135 | + public function set_name($name) { |
|
136 | + $this->set('LIN_name', $name); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @return string |
144 | 144 | */ |
145 | 145 | public function desc() { |
146 | - return $this->get( 'LIN_desc' ); |
|
146 | + return $this->get('LIN_desc'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | * Sets desc |
153 | 153 | * @param string $desc |
154 | 154 | */ |
155 | - public function set_desc( $desc ) { |
|
156 | - $this->set( 'LIN_desc', $desc ); |
|
155 | + public function set_desc($desc) { |
|
156 | + $this->set('LIN_desc', $desc); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @return int |
164 | 164 | */ |
165 | 165 | public function quantity() { |
166 | - return $this->get( 'LIN_quantity' ); |
|
166 | + return $this->get('LIN_quantity'); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | * Sets quantity |
173 | 173 | * @param int $quantity |
174 | 174 | */ |
175 | - public function set_quantity( $quantity ) { |
|
176 | - $this->set( 'LIN_quantity', max( $quantity, 0 ) ); |
|
175 | + public function set_quantity($quantity) { |
|
176 | + $this->set('LIN_quantity', max($quantity, 0)); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * @return string |
184 | 184 | */ |
185 | 185 | public function OBJ_ID() { |
186 | - return $this->get( 'OBJ_ID' ); |
|
186 | + return $this->get('OBJ_ID'); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | * Sets item_id |
193 | 193 | * @param string $item_id |
194 | 194 | */ |
195 | - public function set_OBJ_ID( $item_id ) { |
|
196 | - $this->set( 'OBJ_ID', $item_id ); |
|
195 | + public function set_OBJ_ID($item_id) { |
|
196 | + $this->set('OBJ_ID', $item_id); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @return string |
204 | 204 | */ |
205 | 205 | public function OBJ_type() { |
206 | - return $this->get( 'OBJ_type' ); |
|
206 | + return $this->get('OBJ_type'); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | |
@@ -240,8 +240,8 @@ discard block |
||
240 | 240 | * Sets item_type |
241 | 241 | * @param string $OBJ_type |
242 | 242 | */ |
243 | - public function set_OBJ_type( $OBJ_type ) { |
|
244 | - $this->set( 'OBJ_type', $OBJ_type ); |
|
243 | + public function set_OBJ_type($OBJ_type) { |
|
244 | + $this->set('OBJ_type', $OBJ_type); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @return float |
252 | 252 | */ |
253 | 253 | public function unit_price() { |
254 | - return $this->get( 'LIN_unit_price' ); |
|
254 | + return $this->get('LIN_unit_price'); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | |
@@ -261,8 +261,8 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @param float $unit_price |
263 | 263 | */ |
264 | - public function set_unit_price( $unit_price ) { |
|
265 | - $this->set( 'LIN_unit_price', $unit_price ); |
|
264 | + public function set_unit_price($unit_price) { |
|
265 | + $this->set('LIN_unit_price', $unit_price); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | |
@@ -273,19 +273,19 @@ discard block |
||
273 | 273 | * @return boolean |
274 | 274 | */ |
275 | 275 | public function is_percent() { |
276 | - if( $this->is_tax_sub_total() ) { |
|
276 | + if ($this->is_tax_sub_total()) { |
|
277 | 277 | //tax subtotals HAVE a percent on them, that percentage only applies |
278 | 278 | //to taxable items, so its' an exception. Treat it like a flat line item |
279 | 279 | return false; |
280 | 280 | } |
281 | - $unit_price = abs( $this->get( 'LIN_unit_price' ) ); |
|
282 | - $percent = abs( $this->get( 'LIN_percent' ) ); |
|
283 | - if ( $unit_price < .001 && $percent ) { |
|
281 | + $unit_price = abs($this->get('LIN_unit_price')); |
|
282 | + $percent = abs($this->get('LIN_percent')); |
|
283 | + if ($unit_price < .001 && $percent) { |
|
284 | 284 | return TRUE; |
285 | - } elseif ( $unit_price >= .001 && !$percent ) { |
|
285 | + } elseif ($unit_price >= .001 && ! $percent) { |
|
286 | 286 | return FALSE; |
287 | - } elseif ( $unit_price >= .001 && $percent ) { |
|
288 | - throw new EE_Error( sprintf( __( "A Line Item can not have a unit price of (%s) AND a percent (%s)!", "event_espresso" ), $unit_price, $percent ) ); |
|
287 | + } elseif ($unit_price >= .001 && $percent) { |
|
288 | + throw new EE_Error(sprintf(__("A Line Item can not have a unit price of (%s) AND a percent (%s)!", "event_espresso"), $unit_price, $percent)); |
|
289 | 289 | } else { |
290 | 290 | // if they're both 0, assume its not a percent item |
291 | 291 | return FALSE; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @return float |
300 | 300 | */ |
301 | 301 | public function percent() { |
302 | - return $this->get( 'LIN_percent' ); |
|
302 | + return $this->get('LIN_percent'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | * Sets percent (between 100-0.01) |
309 | 309 | * @param float $percent |
310 | 310 | */ |
311 | - public function set_percent( $percent ) { |
|
312 | - $this->set( 'LIN_percent', $percent ); |
|
311 | + public function set_percent($percent) { |
|
312 | + $this->set('LIN_percent', $percent); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @return float |
320 | 320 | */ |
321 | 321 | public function total() { |
322 | - return $this->get( 'LIN_total' ); |
|
322 | + return $this->get('LIN_total'); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | |
@@ -328,8 +328,8 @@ discard block |
||
328 | 328 | * Sets total |
329 | 329 | * @param float $total |
330 | 330 | */ |
331 | - public function set_total( $total ) { |
|
332 | - $this->set( 'LIN_total', $total ); |
|
331 | + public function set_total($total) { |
|
332 | + $this->set('LIN_total', $total); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * @return int |
340 | 340 | */ |
341 | 341 | public function order() { |
342 | - return $this->get( 'LIN_order' ); |
|
342 | + return $this->get('LIN_order'); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | |
@@ -348,8 +348,8 @@ discard block |
||
348 | 348 | * Sets order |
349 | 349 | * @param int $order |
350 | 350 | */ |
351 | - public function set_order( $order ) { |
|
352 | - $this->set( 'LIN_order', $order ); |
|
351 | + public function set_order($order) { |
|
352 | + $this->set('LIN_order', $order); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | * @return int |
360 | 360 | */ |
361 | 361 | public function parent_ID() { |
362 | - return $this->get( 'LIN_parent' ); |
|
362 | + return $this->get('LIN_parent'); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | |
@@ -368,8 +368,8 @@ discard block |
||
368 | 368 | * Sets parent |
369 | 369 | * @param int $parent |
370 | 370 | */ |
371 | - public function set_parent_ID( $parent ) { |
|
372 | - $this->set( 'LIN_parent', $parent ); |
|
371 | + public function set_parent_ID($parent) { |
|
372 | + $this->set('LIN_parent', $parent); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | * @return string |
380 | 380 | */ |
381 | 381 | public function type() { |
382 | - return $this->get( 'LIN_type' ); |
|
382 | + return $this->get('LIN_type'); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | |
@@ -388,8 +388,8 @@ discard block |
||
388 | 388 | * Sets type |
389 | 389 | * @param string $type |
390 | 390 | */ |
391 | - public function set_type( $type ) { |
|
392 | - $this->set( 'LIN_type', $type ); |
|
391 | + public function set_type($type) { |
|
392 | + $this->set('LIN_type', $type); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | |
@@ -402,8 +402,8 @@ discard block |
||
402 | 402 | * @return EE_Line_Item |
403 | 403 | */ |
404 | 404 | public function parent() { |
405 | - if( $this->ID() ) { |
|
406 | - return $this->get_model()->get_one_by_ID( $this->parent_ID() ); |
|
405 | + if ($this->ID()) { |
|
406 | + return $this->get_model()->get_one_by_ID($this->parent_ID()); |
|
407 | 407 | } else { |
408 | 408 | return $this->_parent; |
409 | 409 | } |
@@ -416,13 +416,13 @@ discard block |
||
416 | 416 | * @return EE_Line_Item[] |
417 | 417 | */ |
418 | 418 | public function children() { |
419 | - if ( $this->ID() ) { |
|
419 | + if ($this->ID()) { |
|
420 | 420 | return $this->get_model()->get_all( |
421 | 421 | array( |
422 | - array( 'LIN_parent' => $this->ID() ), |
|
423 | - 'order_by' => array( 'LIN_order' => 'ASC' ) ) ); |
|
422 | + array('LIN_parent' => $this->ID()), |
|
423 | + 'order_by' => array('LIN_order' => 'ASC') ) ); |
|
424 | 424 | } else { |
425 | - if ( ! is_array( $this->_children ) ) { |
|
425 | + if ( ! is_array($this->_children)) { |
|
426 | 426 | $this->_children = array(); |
427 | 427 | } |
428 | 428 | return $this->_children; |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | * @return string |
437 | 437 | */ |
438 | 438 | public function code() { |
439 | - return $this->get( 'LIN_code' ); |
|
439 | + return $this->get('LIN_code'); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | * Sets code |
446 | 446 | * @param string $code |
447 | 447 | */ |
448 | - public function set_code( $code ) { |
|
449 | - $this->set( 'LIN_code', $code ); |
|
448 | + public function set_code($code) { |
|
449 | + $this->set('LIN_code', $code); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | * @return boolean |
457 | 457 | */ |
458 | 458 | public function is_taxable() { |
459 | - return $this->get( 'LIN_is_taxable' ); |
|
459 | + return $this->get('LIN_is_taxable'); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | |
@@ -465,8 +465,8 @@ discard block |
||
465 | 465 | * Sets is_taxable |
466 | 466 | * @param boolean $is_taxable |
467 | 467 | */ |
468 | - public function set_is_taxable( $is_taxable ) { |
|
469 | - $this->set( 'LIN_is_taxable', $is_taxable ); |
|
468 | + public function set_is_taxable($is_taxable) { |
|
469 | + $this->set('LIN_is_taxable', $is_taxable); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | */ |
482 | 482 | public function get_object() { |
483 | 483 | $model_name_of_related_obj = $this->OBJ_type(); |
484 | - return $this->get_model()->has_relation( $model_name_of_related_obj ) ? $this->get_first_related( $model_name_of_related_obj ) : NULL; |
|
484 | + return $this->get_model()->has_relation($model_name_of_related_obj) ? $this->get_first_related($model_name_of_related_obj) : NULL; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | |
@@ -492,11 +492,11 @@ discard block |
||
492 | 492 | * @param array $query_params |
493 | 493 | * @return EE_Ticket |
494 | 494 | */ |
495 | - public function ticket( $query_params = array() ) { |
|
495 | + public function ticket($query_params = array()) { |
|
496 | 496 | //we're going to assume that when this method is called we always want to receive the attached ticket EVEN if that ticket is archived. This can be overridden via the incoming $query_params argument |
497 | - $remove_defaults = array( 'default_where_conditions' => 'none' ); |
|
498 | - $query_params = array_merge( $remove_defaults, $query_params ); |
|
499 | - return $this->get_first_related( 'Ticket', $query_params ); |
|
497 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
498 | + $query_params = array_merge($remove_defaults, $query_params); |
|
499 | + return $this->get_first_related('Ticket', $query_params); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | |
@@ -506,11 +506,11 @@ discard block |
||
506 | 506 | * @return EE_Datetime | NULL |
507 | 507 | */ |
508 | 508 | public function get_ticket_datetime() { |
509 | - if ( $this->OBJ_type() === 'Ticket' ) { |
|
509 | + if ($this->OBJ_type() === 'Ticket') { |
|
510 | 510 | $ticket = $this->ticket(); |
511 | - if ( $ticket instanceof EE_Ticket ) { |
|
511 | + if ($ticket instanceof EE_Ticket) { |
|
512 | 512 | $datetime = $ticket->first_datetime(); |
513 | - if ( $datetime instanceof EE_Datetime ) { |
|
513 | + if ($datetime instanceof EE_Datetime) { |
|
514 | 514 | return $datetime; |
515 | 515 | } |
516 | 516 | } |
@@ -526,9 +526,9 @@ discard block |
||
526 | 526 | * @return string |
527 | 527 | */ |
528 | 528 | public function ticket_event_name() { |
529 | - $event_name = __( "Unknown", "event_espresso" ); |
|
529 | + $event_name = __("Unknown", "event_espresso"); |
|
530 | 530 | $event = $this->ticket_event(); |
531 | - if ( $event instanceof EE_Event ) { |
|
531 | + if ($event instanceof EE_Event) { |
|
532 | 532 | $event_name = $event->name(); |
533 | 533 | } |
534 | 534 | return $event_name; |
@@ -542,9 +542,9 @@ discard block |
||
542 | 542 | public function ticket_event() { |
543 | 543 | $event = null; |
544 | 544 | $ticket = $this->ticket(); |
545 | - if ( $ticket instanceof EE_Ticket ) { |
|
545 | + if ($ticket instanceof EE_Ticket) { |
|
546 | 546 | $datetime = $ticket->first_datetime(); |
547 | - if ( $datetime instanceof EE_Datetime ) { |
|
547 | + if ($datetime instanceof EE_Datetime) { |
|
548 | 548 | $event = $datetime->event(); |
549 | 549 | } |
550 | 550 | } |
@@ -559,11 +559,11 @@ discard block |
||
559 | 559 | * @param string $time_format |
560 | 560 | * @return string |
561 | 561 | */ |
562 | - public function ticket_datetime_start( $date_format = '', $time_format = '' ) { |
|
563 | - $first_datetime_string = __( "Unknown", "event_espresso" ); |
|
562 | + public function ticket_datetime_start($date_format = '', $time_format = '') { |
|
563 | + $first_datetime_string = __("Unknown", "event_espresso"); |
|
564 | 564 | $datetime = $this->get_ticket_datetime(); |
565 | - if ( $datetime ) { |
|
566 | - $first_datetime_string = $datetime->start_date_and_time( $date_format, $time_format ); |
|
565 | + if ($datetime) { |
|
566 | + $first_datetime_string = $datetime->start_date_and_time($date_format, $time_format); |
|
567 | 567 | } |
568 | 568 | return $first_datetime_string; |
569 | 569 | } |
@@ -578,26 +578,26 @@ discard block |
||
578 | 578 | * @return bool success |
579 | 579 | * @throws \EE_Error |
580 | 580 | */ |
581 | - public function add_child_line_item( EEI_Line_Item $line_item, $set_order = true ) { |
|
581 | + public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true) { |
|
582 | 582 | // should we calculate the LIN_order for this line item ? |
583 | - if ( $set_order || $line_item->order() === null ) { |
|
584 | - $line_item->set_order( count( $this->children() ) ); |
|
583 | + if ($set_order || $line_item->order() === null) { |
|
584 | + $line_item->set_order(count($this->children())); |
|
585 | 585 | } |
586 | - if ( $this->ID() ) { |
|
586 | + if ($this->ID()) { |
|
587 | 587 | //check for any duplicate line items (with the same code), if so, this replaces it |
588 | - $line_item_with_same_code = $this->get_child_line_item( $line_item->code() ); |
|
589 | - if( $line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item ) { |
|
590 | - $this->delete_child_line_item( $line_item_with_same_code->code() ); |
|
588 | + $line_item_with_same_code = $this->get_child_line_item($line_item->code()); |
|
589 | + if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) { |
|
590 | + $this->delete_child_line_item($line_item_with_same_code->code()); |
|
591 | 591 | } |
592 | - $line_item->set_parent_ID( $this->ID() ); |
|
593 | - if( $this->TXN_ID() ){ |
|
594 | - $line_item->set_TXN_ID( $this->TXN_ID() ); |
|
592 | + $line_item->set_parent_ID($this->ID()); |
|
593 | + if ($this->TXN_ID()) { |
|
594 | + $line_item->set_TXN_ID($this->TXN_ID()); |
|
595 | 595 | } |
596 | 596 | return $line_item->save(); |
597 | 597 | } else { |
598 | - $this->_children[ $line_item->code() ] = $line_item; |
|
599 | - if( $line_item->parent() != $this ) { |
|
600 | - $line_item->set_parent( $this ); |
|
598 | + $this->_children[$line_item->code()] = $line_item; |
|
599 | + if ($line_item->parent() != $this) { |
|
600 | + $line_item->set_parent($this); |
|
601 | 601 | } |
602 | 602 | return TRUE; |
603 | 603 | } |
@@ -611,16 +611,16 @@ discard block |
||
611 | 611 | * @param EE_Line_Item $line_item |
612 | 612 | * |
613 | 613 | */ |
614 | - public function set_parent( $line_item ) { |
|
615 | - if ( $this->ID() ) { |
|
616 | - if( ! $line_item->ID() ) { |
|
614 | + public function set_parent($line_item) { |
|
615 | + if ($this->ID()) { |
|
616 | + if ( ! $line_item->ID()) { |
|
617 | 617 | $line_item->save(); |
618 | 618 | } |
619 | - $this->set_parent_ID( $line_item->ID() ); |
|
619 | + $this->set_parent_ID($line_item->ID()); |
|
620 | 620 | $this->save(); |
621 | 621 | } else { |
622 | 622 | $this->_parent = $line_item; |
623 | - $this->set_parent_ID( $line_item->ID() ); |
|
623 | + $this->set_parent_ID($line_item->ID()); |
|
624 | 624 | } |
625 | 625 | } |
626 | 626 | |
@@ -633,11 +633,11 @@ discard block |
||
633 | 633 | * @param string $code |
634 | 634 | * @return EE_Line_Item |
635 | 635 | */ |
636 | - public function get_child_line_item( $code ) { |
|
637 | - if ( $this->ID() ) { |
|
638 | - return $this->get_model()->get_one( array( array( 'LIN_parent' => $this->ID(), 'LIN_code' => $code ) ) ); |
|
636 | + public function get_child_line_item($code) { |
|
637 | + if ($this->ID()) { |
|
638 | + return $this->get_model()->get_one(array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code))); |
|
639 | 639 | } else { |
640 | - return isset( $this->_children[ $code ] ) ? $this->_children[ $code ] : null; |
|
640 | + return isset($this->_children[$code]) ? $this->_children[$code] : null; |
|
641 | 641 | } |
642 | 642 | } |
643 | 643 | |
@@ -648,10 +648,10 @@ discard block |
||
648 | 648 | * @return int |
649 | 649 | */ |
650 | 650 | public function delete_children_line_items() { |
651 | - if ( $this->ID() ) { |
|
652 | - return $this->get_model()->delete( array( array( 'LIN_parent' => $this->ID() ) ) ); |
|
651 | + if ($this->ID()) { |
|
652 | + return $this->get_model()->delete(array(array('LIN_parent' => $this->ID()))); |
|
653 | 653 | } else { |
654 | - $count = count( $this->_children ); |
|
654 | + $count = count($this->_children); |
|
655 | 655 | $this->_children = array(); |
656 | 656 | return $count; |
657 | 657 | } |
@@ -668,25 +668,25 @@ discard block |
||
668 | 668 | * @param bool $stop_search_once_found |
669 | 669 | * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to the DB yet) |
670 | 670 | */ |
671 | - public function delete_child_line_item( $code, $stop_search_once_found = true ) { |
|
672 | - if ( $this->ID() ) { |
|
671 | + public function delete_child_line_item($code, $stop_search_once_found = true) { |
|
672 | + if ($this->ID()) { |
|
673 | 673 | $items_deleted = 0; |
674 | - if( $this->code() == $code ) { |
|
675 | - $items_deleted += EEH_Line_Item::delete_all_child_items( $this ); |
|
674 | + if ($this->code() == $code) { |
|
675 | + $items_deleted += EEH_Line_Item::delete_all_child_items($this); |
|
676 | 676 | $items_deleted += (int) $this->delete(); |
677 | - if( $stop_search_once_found ){ |
|
677 | + if ($stop_search_once_found) { |
|
678 | 678 | return $items_deleted; |
679 | 679 | } |
680 | 680 | } |
681 | - foreach( $this->children() as $child_line_item ) { |
|
682 | - $items_deleted += $child_line_item->delete_child_line_item( $code, $stop_search_once_found ); |
|
681 | + foreach ($this->children() as $child_line_item) { |
|
682 | + $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found); |
|
683 | 683 | } |
684 | 684 | return $items_deleted; |
685 | 685 | } else { |
686 | - if( isset( $this->_children[ $code ] ) ) { |
|
687 | - unset( $this->_children[ $code ] ); |
|
686 | + if (isset($this->_children[$code])) { |
|
687 | + unset($this->_children[$code]); |
|
688 | 688 | return 1; |
689 | - }else{ |
|
689 | + } else { |
|
690 | 690 | return 0; |
691 | 691 | } |
692 | 692 | } |
@@ -699,9 +699,9 @@ discard block |
||
699 | 699 | * @return boolean |
700 | 700 | */ |
701 | 701 | public function delete_if_childless_subtotal() { |
702 | - if( $this->ID() && |
|
702 | + if ($this->ID() && |
|
703 | 703 | $this->type() == EEM_Line_Item::type_sub_total && |
704 | - ! $this->children() ) { |
|
704 | + ! $this->children()) { |
|
705 | 705 | return $this->delete(); |
706 | 706 | } else { |
707 | 707 | return false; |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | */ |
717 | 717 | public function generate_code() { |
718 | 718 | // each line item in the cart requires a unique identifier |
719 | - return md5( $this->get( 'OBJ_type' ) . $this->get( 'OBJ_ID' ) . microtime() ); |
|
719 | + return md5($this->get('OBJ_type').$this->get('OBJ_ID').microtime()); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | * @return string like '2, 004.00', formatted according to the localized currency |
800 | 800 | */ |
801 | 801 | public function unit_price_no_code() { |
802 | - return $this->get_pretty( 'LIN_unit_price', 'no_currency_code' ); |
|
802 | + return $this->get_pretty('LIN_unit_price', 'no_currency_code'); |
|
803 | 803 | } |
804 | 804 | |
805 | 805 | |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | * @return string like '2, 004.00', formatted according to the localized currency |
810 | 810 | */ |
811 | 811 | public function total_no_code() { |
812 | - return $this->get_pretty( 'LIN_total', 'no_currency_code' ); |
|
812 | + return $this->get_pretty('LIN_total', 'no_currency_code'); |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | |
@@ -829,17 +829,17 @@ discard block |
||
829 | 829 | $tax_total = $this->recalculate_taxes_and_tax_total(); |
830 | 830 | $total = $pre_tax_total + $tax_total; |
831 | 831 | // no negative totals plz |
832 | - $total = max( $total, 0 ); |
|
833 | - $this->set_total( $total ); |
|
832 | + $total = max($total, 0); |
|
833 | + $this->set_total($total); |
|
834 | 834 | //only update the related transaction's total |
835 | 835 | //if we intend to save this line item and its a grand total |
836 | - if( |
|
836 | + if ( |
|
837 | 837 | $this->allow_persist() && |
838 | 838 | $this->type() === EEM_Line_Item::type_total && |
839 | 839 | $this->transaction() instanceof EE_Transaction |
840 | - ){ |
|
841 | - $this->transaction()->set_total( $total ); |
|
842 | - if ( $this->transaction()->ID() ) { |
|
840 | + ) { |
|
841 | + $this->transaction()->set_total($total); |
|
842 | + if ($this->transaction()->ID()) { |
|
843 | 843 | $this->transaction()->save(); |
844 | 844 | } |
845 | 845 | } |
@@ -858,47 +858,47 @@ discard block |
||
858 | 858 | public function recalculate_pre_tax_total() { |
859 | 859 | $total = 0; |
860 | 860 | $my_children = $this->children(); |
861 | - $has_children = ! empty( $my_children ); |
|
862 | - if ( $has_children && $this->is_line_item() ) { |
|
863 | - $total = $this->_recalculate_pretax_total_for_line_item( $total, $my_children ); |
|
864 | - } elseif ( ! $has_children && ( $this->is_sub_line_item() || $this->is_line_item() ) ) { |
|
861 | + $has_children = ! empty($my_children); |
|
862 | + if ($has_children && $this->is_line_item()) { |
|
863 | + $total = $this->_recalculate_pretax_total_for_line_item($total, $my_children); |
|
864 | + } elseif ( ! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) { |
|
865 | 865 | $total = $this->unit_price() * $this->quantity(); |
866 | - } elseif( $this->is_sub_total() || $this->is_total() ) { |
|
867 | - $total = $this->_recalculate_pretax_total_for_subtotal( $total, $my_children ); |
|
868 | - } elseif ( $this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled() ) { |
|
866 | + } elseif ($this->is_sub_total() || $this->is_total()) { |
|
867 | + $total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children); |
|
868 | + } elseif ($this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled()) { |
|
869 | 869 | // completely ignore tax totals, tax sub-totals, and cancelled line items, when calculating the pre-tax-total |
870 | 870 | return 0; |
871 | 871 | } |
872 | 872 | // ensure all non-line items and non-sub-line-items have a quantity of 1 (except for Events) |
873 | - if( |
|
873 | + if ( |
|
874 | 874 | ! $this->is_line_item() && |
875 | 875 | ! $this->is_sub_line_item() && |
876 | 876 | ! $this->is_cancellation() |
877 | 877 | ) { |
878 | - if ( $this->OBJ_type() !== 'Event' ) { |
|
879 | - $this->set_quantity( 1 ); |
|
878 | + if ($this->OBJ_type() !== 'Event') { |
|
879 | + $this->set_quantity(1); |
|
880 | 880 | } |
881 | - if( ! $this->is_percent() ) { |
|
882 | - $this->set_unit_price( $this->total() ); |
|
881 | + if ( ! $this->is_percent()) { |
|
882 | + $this->set_unit_price($this->total()); |
|
883 | 883 | } |
884 | 884 | } |
885 | 885 | |
886 | 886 | //we don't want to bother saving grand totals, because that needs to factor in taxes anyways |
887 | 887 | //so it ought to be |
888 | - if( ! $this->is_total() ) { |
|
889 | - $this->set_total( $total ); |
|
888 | + if ( ! $this->is_total()) { |
|
889 | + $this->set_total($total); |
|
890 | 890 | //if not a percent line item, make sure we keep the unit price in sync |
891 | - if( |
|
891 | + if ( |
|
892 | 892 | $has_children |
893 | 893 | && $this->is_line_item() |
894 | 894 | && ! $this->is_percent() |
895 | 895 | ) { |
896 | - if( $this->quantity() === 0 ){ |
|
896 | + if ($this->quantity() === 0) { |
|
897 | 897 | $new_unit_price = 0; |
898 | 898 | } else { |
899 | 899 | $new_unit_price = $this->total() / $this->quantity(); |
900 | 900 | } |
901 | - $this->set_unit_price( $new_unit_price ); |
|
901 | + $this->set_unit_price($new_unit_price); |
|
902 | 902 | } |
903 | 903 | $this->maybe_save(); |
904 | 904 | } |
@@ -918,39 +918,39 @@ discard block |
||
918 | 918 | * @return float |
919 | 919 | * @throws \EE_Error |
920 | 920 | */ |
921 | - protected function _recalculate_pretax_total_for_subtotal( $calculated_total_so_far, $my_children = null ) { |
|
922 | - if( $my_children === null ) { |
|
921 | + protected function _recalculate_pretax_total_for_subtotal($calculated_total_so_far, $my_children = null) { |
|
922 | + if ($my_children === null) { |
|
923 | 923 | $my_children = $this->children(); |
924 | 924 | } |
925 | 925 | //get the total of all its children |
926 | - foreach ( $my_children as $child_line_item ) { |
|
927 | - if ( $child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation() ) { |
|
926 | + foreach ($my_children as $child_line_item) { |
|
927 | + if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) { |
|
928 | 928 | // percentage line items are based on total so far |
929 | - if ( $child_line_item->is_percent() ) { |
|
929 | + if ($child_line_item->is_percent()) { |
|
930 | 930 | //round as we go so that the line items add up ok |
931 | 931 | $percent_total = round( |
932 | 932 | $calculated_total_so_far * $child_line_item->percent() / 100, |
933 | 933 | EE_Registry::instance()->CFG->currency->dec_plc |
934 | 934 | ); |
935 | - $child_line_item->set_total( $percent_total ); |
|
935 | + $child_line_item->set_total($percent_total); |
|
936 | 936 | //so far all percent line items should have a quantity of 1 |
937 | 937 | //(ie, no double percent discounts. Although that might be requested someday) |
938 | - $child_line_item->set_quantity( 1 ); |
|
938 | + $child_line_item->set_quantity(1); |
|
939 | 939 | $child_line_item->maybe_save(); |
940 | 940 | $calculated_total_so_far += $percent_total; |
941 | 941 | } else { |
942 | 942 | //verify flat sub-line-item quantities match their parent |
943 | - if( $child_line_item->is_sub_line_item() ) { |
|
944 | - $child_line_item->set_quantity( $this->quantity() ); |
|
943 | + if ($child_line_item->is_sub_line_item()) { |
|
944 | + $child_line_item->set_quantity($this->quantity()); |
|
945 | 945 | } |
946 | 946 | $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
947 | 947 | } |
948 | 948 | } |
949 | 949 | } |
950 | 950 | |
951 | - if( $this->is_sub_total() ){ |
|
951 | + if ($this->is_sub_total()) { |
|
952 | 952 | // no negative totals plz |
953 | - $calculated_total_so_far = max( $calculated_total_so_far, 0 ); |
|
953 | + $calculated_total_so_far = max($calculated_total_so_far, 0); |
|
954 | 954 | } |
955 | 955 | return $calculated_total_so_far; |
956 | 956 | } |
@@ -968,8 +968,8 @@ discard block |
||
968 | 968 | * @return float |
969 | 969 | * @throws \EE_Error |
970 | 970 | */ |
971 | - protected function _recalculate_pretax_total_for_line_item( $calculated_total_so_far, $my_children = null ) { |
|
972 | - if( $my_children === null ) { |
|
971 | + protected function _recalculate_pretax_total_for_line_item($calculated_total_so_far, $my_children = null) { |
|
972 | + if ($my_children === null) { |
|
973 | 973 | $my_children = $this->children(); |
974 | 974 | } |
975 | 975 | //we need to keep track of the running total for a single item, |
@@ -977,10 +977,10 @@ discard block |
||
977 | 977 | $unit_price_for_total = 0; |
978 | 978 | $quantity_for_total = 1; |
979 | 979 | //get the total of all its children |
980 | - foreach ( $my_children as $child_line_item ) { |
|
981 | - if ( $child_line_item instanceof EE_Line_Item && |
|
980 | + foreach ($my_children as $child_line_item) { |
|
981 | + if ($child_line_item instanceof EE_Line_Item && |
|
982 | 982 | ! $child_line_item->is_cancellation()) { |
983 | - if ( $child_line_item->is_percent() ) { |
|
983 | + if ($child_line_item->is_percent()) { |
|
984 | 984 | //it should be the unit-price-so-far multiplied by teh percent multiplied by the quantity |
985 | 985 | //not total multiplied by percent, because that ignores rounding along-the-way |
986 | 986 | $percent_unit_price = round( |
@@ -988,17 +988,17 @@ discard block |
||
988 | 988 | EE_Registry::instance()->CFG->currency->dec_plc |
989 | 989 | ); |
990 | 990 | $percent_total = $percent_unit_price * $quantity_for_total; |
991 | - $child_line_item->set_total( $percent_total ); |
|
991 | + $child_line_item->set_total($percent_total); |
|
992 | 992 | //so far all percent line items should have a quantity of 1 |
993 | 993 | //(ie, no double percent discounts. Although that might be requested someday) |
994 | - $child_line_item->set_quantity( 1 ); |
|
994 | + $child_line_item->set_quantity(1); |
|
995 | 995 | $child_line_item->maybe_save(); |
996 | 996 | $calculated_total_so_far += $percent_total; |
997 | 997 | $unit_price_for_total += $percent_unit_price; |
998 | 998 | } else { |
999 | 999 | //verify flat sub-line-item quantities match their parent |
1000 | - if( $child_line_item->is_sub_line_item() ) { |
|
1001 | - $child_line_item->set_quantity( $this->quantity() ); |
|
1000 | + if ($child_line_item->is_sub_line_item()) { |
|
1001 | + $child_line_item->set_quantity($this->quantity()); |
|
1002 | 1002 | } |
1003 | 1003 | $quantity_for_total = $child_line_item->quantity(); |
1004 | 1004 | $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
@@ -1022,10 +1022,10 @@ discard block |
||
1022 | 1022 | //calculate the pretax total |
1023 | 1023 | $taxable_total = $this->taxable_total(); |
1024 | 1024 | $tax_total = 0; |
1025 | - foreach ( $taxes as $tax ) { |
|
1025 | + foreach ($taxes as $tax) { |
|
1026 | 1026 | $total_on_this_tax = $taxable_total * $tax->percent() / 100; |
1027 | 1027 | //remember the total on this line item |
1028 | - $tax->set_total( $total_on_this_tax ); |
|
1028 | + $tax->set_total($total_on_this_tax); |
|
1029 | 1029 | $tax_total += $tax->total(); |
1030 | 1030 | } |
1031 | 1031 | $this->_recalculate_tax_sub_total(); |
@@ -1039,21 +1039,21 @@ discard block |
||
1039 | 1039 | * @return void |
1040 | 1040 | */ |
1041 | 1041 | private function _recalculate_tax_sub_total() { |
1042 | - if ( $this->is_tax_sub_total() ) { |
|
1042 | + if ($this->is_tax_sub_total()) { |
|
1043 | 1043 | $total = 0; |
1044 | 1044 | $total_percent = 0; |
1045 | 1045 | //simply loop through all its children (which should be taxes) and sum their total |
1046 | - foreach ( $this->children() as $child_tax ) { |
|
1047 | - if ( $child_tax instanceof EE_Line_Item ) { |
|
1046 | + foreach ($this->children() as $child_tax) { |
|
1047 | + if ($child_tax instanceof EE_Line_Item) { |
|
1048 | 1048 | $total += $child_tax->total(); |
1049 | 1049 | $total_percent += $child_tax->percent(); |
1050 | 1050 | } |
1051 | 1051 | } |
1052 | - $this->set_total( $total ); |
|
1053 | - $this->set_percent( $total_percent ); |
|
1054 | - } elseif ( $this->is_total() ) { |
|
1055 | - foreach ( $this->children() as $maybe_tax_subtotal ) { |
|
1056 | - if ( $maybe_tax_subtotal instanceof EE_Line_Item ) { |
|
1052 | + $this->set_total($total); |
|
1053 | + $this->set_percent($total_percent); |
|
1054 | + } elseif ($this->is_total()) { |
|
1055 | + foreach ($this->children() as $maybe_tax_subtotal) { |
|
1056 | + if ($maybe_tax_subtotal instanceof EE_Line_Item) { |
|
1057 | 1057 | $maybe_tax_subtotal->_recalculate_tax_sub_total(); |
1058 | 1058 | } |
1059 | 1059 | } |
@@ -1069,8 +1069,8 @@ discard block |
||
1069 | 1069 | public function get_total_tax() { |
1070 | 1070 | $this->_recalculate_tax_sub_total(); |
1071 | 1071 | $total = 0; |
1072 | - foreach ( $this->tax_descendants() as $tax_line_item ) { |
|
1073 | - if ( $tax_line_item instanceof EE_Line_Item ) { |
|
1072 | + foreach ($this->tax_descendants() as $tax_line_item) { |
|
1073 | + if ($tax_line_item instanceof EE_Line_Item) { |
|
1074 | 1074 | $total += $tax_line_item->total(); |
1075 | 1075 | } |
1076 | 1076 | } |
@@ -1084,15 +1084,15 @@ discard block |
||
1084 | 1084 | */ |
1085 | 1085 | public function get_items_total() { |
1086 | 1086 | //by default, let's make sure we're consistent with the existing line item |
1087 | - if( $this->is_total() ) { |
|
1088 | - $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal( $this ); |
|
1089 | - if( $pretax_subtotal_li instanceof EE_Line_Item ) { |
|
1087 | + if ($this->is_total()) { |
|
1088 | + $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal($this); |
|
1089 | + if ($pretax_subtotal_li instanceof EE_Line_Item) { |
|
1090 | 1090 | return $pretax_subtotal_li->total(); |
1091 | 1091 | } |
1092 | 1092 | } |
1093 | 1093 | $total = 0; |
1094 | - foreach ( $this->get_items() as $item ) { |
|
1095 | - if ( $item instanceof EE_Line_Item ) { |
|
1094 | + foreach ($this->get_items() as $item) { |
|
1095 | + if ($item instanceof EE_Line_Item) { |
|
1096 | 1096 | $total += $item->total(); |
1097 | 1097 | } |
1098 | 1098 | } |
@@ -1107,7 +1107,7 @@ discard block |
||
1107 | 1107 | * @return EE_Line_Item[] |
1108 | 1108 | */ |
1109 | 1109 | public function tax_descendants() { |
1110 | - return EEH_Line_Item::get_tax_descendants( $this ); |
|
1110 | + return EEH_Line_Item::get_tax_descendants($this); |
|
1111 | 1111 | } |
1112 | 1112 | |
1113 | 1113 | |
@@ -1117,7 +1117,7 @@ discard block |
||
1117 | 1117 | * @return EE_Line_Item[] |
1118 | 1118 | */ |
1119 | 1119 | public function get_items() { |
1120 | - return EEH_Line_Item::get_line_item_descendants( $this ); |
|
1120 | + return EEH_Line_Item::get_line_item_descendants($this); |
|
1121 | 1121 | } |
1122 | 1122 | |
1123 | 1123 | |
@@ -1133,22 +1133,22 @@ discard block |
||
1133 | 1133 | */ |
1134 | 1134 | public function taxable_total() { |
1135 | 1135 | $total = 0; |
1136 | - if ( $this->children() ) { |
|
1137 | - foreach ( $this->children() as $child_line_item ) { |
|
1138 | - if ( $child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) { |
|
1136 | + if ($this->children()) { |
|
1137 | + foreach ($this->children() as $child_line_item) { |
|
1138 | + if ($child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) { |
|
1139 | 1139 | //if it's a percent item, only take into account the percent |
1140 | 1140 | //that's taxable too (the taxable total so far) |
1141 | - if( $child_line_item->is_percent() ) { |
|
1142 | - $total = $total + ( $total * $child_line_item->percent() / 100 ); |
|
1143 | - }else{ |
|
1141 | + if ($child_line_item->is_percent()) { |
|
1142 | + $total = $total + ($total * $child_line_item->percent() / 100); |
|
1143 | + } else { |
|
1144 | 1144 | $total += $child_line_item->total(); |
1145 | 1145 | } |
1146 | - }elseif( $child_line_item->type() === EEM_Line_Item::type_sub_total ){ |
|
1146 | + }elseif ($child_line_item->type() === EEM_Line_Item::type_sub_total) { |
|
1147 | 1147 | $total += $child_line_item->taxable_total(); |
1148 | 1148 | } |
1149 | 1149 | } |
1150 | 1150 | } |
1151 | - return max( $total, 0 ); |
|
1151 | + return max($total, 0); |
|
1152 | 1152 | } |
1153 | 1153 | |
1154 | 1154 | |
@@ -1158,7 +1158,7 @@ discard block |
||
1158 | 1158 | * @return EE_Transaction |
1159 | 1159 | */ |
1160 | 1160 | public function transaction() { |
1161 | - return $this->get_first_related( 'Transaction' ); |
|
1161 | + return $this->get_first_related('Transaction'); |
|
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | |
@@ -1171,18 +1171,18 @@ discard block |
||
1171 | 1171 | * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
1172 | 1172 | * @return int count of items saved |
1173 | 1173 | */ |
1174 | - public function save_this_and_descendants_to_txn( $txn_id = NULL ) { |
|
1174 | + public function save_this_and_descendants_to_txn($txn_id = NULL) { |
|
1175 | 1175 | $count = 0; |
1176 | - if ( ! $txn_id ) { |
|
1176 | + if ( ! $txn_id) { |
|
1177 | 1177 | $txn_id = $this->TXN_ID(); |
1178 | 1178 | } |
1179 | - $this->set_TXN_ID( $txn_id ); |
|
1179 | + $this->set_TXN_ID($txn_id); |
|
1180 | 1180 | $children = $this->children(); |
1181 | 1181 | $count += $this->save() ? 1 : 0; |
1182 | - foreach ( $children as $child_line_item ) { |
|
1183 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1184 | - $child_line_item->set_parent_ID( $this->ID() ); |
|
1185 | - $count += $child_line_item->save_this_and_descendants_to_txn( $txn_id ); |
|
1182 | + foreach ($children as $child_line_item) { |
|
1183 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1184 | + $child_line_item->set_parent_ID($this->ID()); |
|
1185 | + $count += $child_line_item->save_this_and_descendants_to_txn($txn_id); |
|
1186 | 1186 | } |
1187 | 1187 | } |
1188 | 1188 | return $count; |
@@ -1199,9 +1199,9 @@ discard block |
||
1199 | 1199 | $count = 0; |
1200 | 1200 | $children = $this->children(); |
1201 | 1201 | $count += $this->save() ? 1 : 0; |
1202 | - foreach ( $children as $child_line_item ) { |
|
1203 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1204 | - $child_line_item->set_parent_ID( $this->ID() ); |
|
1202 | + foreach ($children as $child_line_item) { |
|
1203 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1204 | + $child_line_item->set_parent_ID($this->ID()); |
|
1205 | 1205 | $count += $child_line_item->save_this_and_descendants(); |
1206 | 1206 | } |
1207 | 1207 | } |
@@ -1215,8 +1215,8 @@ discard block |
||
1215 | 1215 | * @return EE_Line_Item[] |
1216 | 1216 | */ |
1217 | 1217 | public function get_cancellations() { |
1218 | - EE_Registry::instance()->load_helper( 'Line_Item' ); |
|
1219 | - return EEH_Line_Item::get_descendants_of_type( $this, EEM_Line_Item::type_cancellation ); |
|
1218 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
1219 | + return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation); |
|
1220 | 1220 | } |
1221 | 1221 | |
1222 | 1222 | |
@@ -1227,7 +1227,7 @@ discard block |
||
1227 | 1227 | * @return int count of items saved |
1228 | 1228 | */ |
1229 | 1229 | public function maybe_save() { |
1230 | - if ( $this->ID() ) { |
|
1230 | + if ($this->ID()) { |
|
1231 | 1231 | return $this->save(); |
1232 | 1232 | } |
1233 | 1233 | return false; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * Sets quantity |
173 | 173 | * @param int $quantity |
174 | 174 | */ |
175 | - public function set_quantity( $quantity ) { |
|
175 | + public function set_quantity( $quantity ) { |
|
176 | 176 | $this->set( 'LIN_quantity', max( $quantity, 0 ) ); |
177 | 177 | } |
178 | 178 | |
@@ -212,25 +212,25 @@ discard block |
||
212 | 212 | * Gets item_type |
213 | 213 | * @return string |
214 | 214 | */ |
215 | - public function OBJ_type_i18n() { |
|
216 | - $obj_type = $this->OBJ_type(); |
|
217 | - switch ($obj_type) { |
|
218 | - case 'Event': |
|
219 | - $obj_type = __('Event', 'event_espresso'); |
|
220 | - break; |
|
221 | - case 'Price': |
|
222 | - $obj_type = __('Price', 'event_espresso'); |
|
223 | - break; |
|
224 | - case 'Promotion': |
|
225 | - $obj_type = __('Promotion', 'event_espresso'); |
|
226 | - break; |
|
227 | - case 'Ticket': |
|
228 | - $obj_type = __('Ticket', 'event_espresso'); |
|
229 | - break; |
|
230 | - case 'Transaction': |
|
231 | - $obj_type = __('Transaction', 'event_espresso'); |
|
232 | - break; |
|
233 | - } |
|
215 | + public function OBJ_type_i18n() { |
|
216 | + $obj_type = $this->OBJ_type(); |
|
217 | + switch ($obj_type) { |
|
218 | + case 'Event': |
|
219 | + $obj_type = __('Event', 'event_espresso'); |
|
220 | + break; |
|
221 | + case 'Price': |
|
222 | + $obj_type = __('Price', 'event_espresso'); |
|
223 | + break; |
|
224 | + case 'Promotion': |
|
225 | + $obj_type = __('Promotion', 'event_espresso'); |
|
226 | + break; |
|
227 | + case 'Ticket': |
|
228 | + $obj_type = __('Ticket', 'event_espresso'); |
|
229 | + break; |
|
230 | + case 'Transaction': |
|
231 | + $obj_type = __('Transaction', 'event_espresso'); |
|
232 | + break; |
|
233 | + } |
|
234 | 234 | return apply_filters('FHEE__EE_Line_Item__OBJ_type_i18n', $obj_type, $this); |
235 | 235 | } |
236 | 236 | |
@@ -1244,48 +1244,48 @@ discard block |
||
1244 | 1244 | |
1245 | 1245 | |
1246 | 1246 | |
1247 | - /** |
|
1248 | - * @param bool $raw |
|
1249 | - * @return int |
|
1250 | - * @throws \EE_Error |
|
1251 | - */ |
|
1252 | - public function timestamp($raw = false) |
|
1253 | - { |
|
1254 | - return $raw ? $this->get_raw('LIN_timestamp') : $this->get('LIN_timestamp'); |
|
1255 | - } |
|
1247 | + /** |
|
1248 | + * @param bool $raw |
|
1249 | + * @return int |
|
1250 | + * @throws \EE_Error |
|
1251 | + */ |
|
1252 | + public function timestamp($raw = false) |
|
1253 | + { |
|
1254 | + return $raw ? $this->get_raw('LIN_timestamp') : $this->get('LIN_timestamp'); |
|
1255 | + } |
|
1256 | 1256 | |
1257 | 1257 | |
1258 | 1258 | |
1259 | 1259 | |
1260 | - /************************* DEPRECATED *************************/ |
|
1260 | + /************************* DEPRECATED *************************/ |
|
1261 | 1261 | |
1262 | 1262 | |
1263 | 1263 | |
1264 | - /** |
|
1265 | - * @deprecated 4.6.0 |
|
1266 | - * @param string $type one of the constants on EEM_Line_Item |
|
1267 | - * @return EE_Line_Item[] |
|
1268 | - */ |
|
1269 | - protected function _get_descendants_of_type($type) |
|
1270 | - { |
|
1271 | - EE_Error::doing_it_wrong('EE_Line_Item::_get_descendants_of_type()', |
|
1272 | - __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'), '4.6.0'); |
|
1273 | - return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
1274 | - } |
|
1264 | + /** |
|
1265 | + * @deprecated 4.6.0 |
|
1266 | + * @param string $type one of the constants on EEM_Line_Item |
|
1267 | + * @return EE_Line_Item[] |
|
1268 | + */ |
|
1269 | + protected function _get_descendants_of_type($type) |
|
1270 | + { |
|
1271 | + EE_Error::doing_it_wrong('EE_Line_Item::_get_descendants_of_type()', |
|
1272 | + __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'), '4.6.0'); |
|
1273 | + return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
1274 | + } |
|
1275 | 1275 | |
1276 | 1276 | |
1277 | 1277 | |
1278 | - /** |
|
1279 | - * @deprecated 4.6.0 |
|
1280 | - * @param string $type like one of the EEM_Line_Item::type_* |
|
1281 | - * @return EE_Line_Item |
|
1282 | - */ |
|
1283 | - public function get_nearest_descendant_of_type($type) |
|
1284 | - { |
|
1285 | - EE_Error::doing_it_wrong('EE_Line_Item::get_nearest_descendant_of_type()', |
|
1286 | - __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'), '4.6.0'); |
|
1287 | - return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
1288 | - } |
|
1278 | + /** |
|
1279 | + * @deprecated 4.6.0 |
|
1280 | + * @param string $type like one of the EEM_Line_Item::type_* |
|
1281 | + * @return EE_Line_Item |
|
1282 | + */ |
|
1283 | + public function get_nearest_descendant_of_type($type) |
|
1284 | + { |
|
1285 | + EE_Error::doing_it_wrong('EE_Line_Item::get_nearest_descendant_of_type()', |
|
1286 | + __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'), '4.6.0'); |
|
1287 | + return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
1288 | + } |
|
1289 | 1289 | |
1290 | 1290 | |
1291 | 1291 |
@@ -352,7 +352,7 @@ |
||
352 | 352 | * |
353 | 353 | * Note: regex comes in part from the WP `get_shortcode_regex` expression in \wp-includes\shortcodes.php |
354 | 354 | * |
355 | - * @param $shortcode |
|
355 | + * @param string $shortcode |
|
356 | 356 | * @since 4.9.32 |
357 | 357 | * @return string |
358 | 358 | */ |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('NO direct script access allowed'); |
|
4 | + exit('NO direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -30,432 +30,432 @@ discard block |
||
30 | 30 | abstract class EE_Shortcodes extends EE_Base |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * holds label for library |
|
35 | - * This is used for referencing the library label |
|
36 | - * |
|
37 | - * @access public |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - public $label; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * This property is used for referencing a short description of the library |
|
45 | - * |
|
46 | - * @access public |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $description; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * This will hold an array of shortcodes with the key as the shortcode ([shortcode]) and the value as a |
|
54 | - * label/description for the shortcode. |
|
55 | - * |
|
56 | - * @access protected |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - protected $_shortcodes; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * This will hold the incoming data item sent to the parser method |
|
64 | - * |
|
65 | - * @access protected |
|
66 | - * @var mixed (array|object) |
|
67 | - */ |
|
68 | - protected $_data; |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * some shortcodes may require extra data to parse. This property is provided for that. |
|
73 | - * |
|
74 | - * @var array |
|
75 | - */ |
|
76 | - protected $_extra_data; |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * EE_messenger used to generate the template being parsed. |
|
81 | - * |
|
82 | - * @since 4.5.0 |
|
83 | - * @var EE_messenger |
|
84 | - */ |
|
85 | - protected $_messenger; |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * message type used to generate the template being parsed. |
|
90 | - * |
|
91 | - * @since 4.5.0 |
|
92 | - * @var EE_message_type |
|
93 | - */ |
|
94 | - protected $_message_type; |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * context used for the template being parsed |
|
99 | - * |
|
100 | - * @since 4.5.0 |
|
101 | - * @var string |
|
102 | - */ |
|
103 | - protected $_context; |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Specific Message Template Group ID |
|
108 | - * |
|
109 | - * @since 4.5.0 |
|
110 | - * @var int |
|
111 | - */ |
|
112 | - protected $_GRP_ID; |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @since 4.9.0 |
|
117 | - * @type EE_Message |
|
118 | - */ |
|
119 | - protected $_message; |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * This will hold an instance of the EEH_Parse_Shortcodes helper that will be used when handling list type |
|
124 | - * shortcodes |
|
125 | - * |
|
126 | - * @var EEH_Parse_Shortcodes |
|
127 | - */ |
|
128 | - protected $_shortcode_helper; |
|
129 | - |
|
130 | - |
|
131 | - public function __construct() |
|
132 | - { |
|
133 | - $this->_set_defaults(); |
|
134 | - $this->_init_props(); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * This sets the defaults for the properties. Child classes will override these properties in their _init_props |
|
140 | - * method |
|
141 | - */ |
|
142 | - private function _set_defaults() |
|
143 | - { |
|
144 | - $this->name = $this->description = ''; |
|
145 | - $this->_shortcodes = array(); |
|
146 | - $this->_set_shortcode_helper(); |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * loads an instance of the EE_Shortcode_Parser helper when requested |
|
152 | - */ |
|
153 | - protected function _set_shortcode_helper() |
|
154 | - { |
|
155 | - //get shortcode_replace instance- set when _get_messages is called in child... |
|
156 | - $this->_shortcode_helper = new EEH_Parse_Shortcodes(); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - public function get_shortcode_helper() |
|
161 | - { |
|
162 | - if (! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
163 | - $this->_set_shortcode_helper(); |
|
164 | - } |
|
165 | - return $this->_shortcode_helper; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * This is the public method for kicking of the parser included with each child. It can be overridden by child |
|
171 | - * classes if necessary (see EE_Questions_Answers for example) |
|
172 | - * |
|
173 | - * @param string $shortcode incoming shortcode to be parsed |
|
174 | - * @param mixed (object|array) $data incoming data to be be used for parsing |
|
175 | - * @param mixed (object|array) $extra_data extra incoming data (usually EE_Messages_Addressee) |
|
176 | - * @return string parsed shortcode. |
|
177 | - */ |
|
178 | - public function parser($shortcode, $data, $extra_data = array()) |
|
179 | - { |
|
180 | - |
|
181 | - //filter setup shortcodes |
|
182 | - $this->_shortcodes = $this->get_shortcodes(); |
|
183 | - |
|
184 | - //we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
185 | - $sc = preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
186 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
187 | - |
|
188 | - //first we want to make sure this is a valid shortcode |
|
189 | - if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
190 | - return false; |
|
191 | - } //get out, this parser doesn't handle the incoming shortcode. |
|
192 | - $this->_data = $data; |
|
193 | - $this->_extra_data = $extra_data; |
|
194 | - $this->_set_messages_properties(); |
|
195 | - $parsed = apply_filters('FHEE__' . get_class($this) . '__parser_after', $this->_parser($shortcode), $shortcode, |
|
196 | - $data, $extra_data, $this); |
|
197 | - |
|
198 | - //note the below filter applies to ALL shortcode parsers... be careful! |
|
199 | - $parsed = apply_filters('FHEE__EE_Shortcodes__parser_after', $parsed, $shortcode, $data, $extra_data, $this); |
|
200 | - return $parsed; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * This method just returns the shortcodes in the $_shortcodes array property. |
|
206 | - * |
|
207 | - * @access public |
|
208 | - * @return array array of shortcodes => description pairs |
|
209 | - */ |
|
210 | - public function get_shortcodes() |
|
211 | - { |
|
212 | - $this->_shortcodes = apply_filters('FHEE__' . get_class($this) . '__shortcodes', $this->_shortcodes, $this); |
|
213 | - |
|
214 | - //note the below filter applies to ALL shortcode parsers... be careful! |
|
215 | - $this->_shortcodes = apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this); |
|
216 | - |
|
217 | - return $this->_shortcodes; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * Child classes use this method to set the $name, $description, and $_shortcodes properties. |
|
223 | - * |
|
224 | - * @abstract |
|
225 | - * @access protected |
|
226 | - * @return void |
|
227 | - */ |
|
228 | - abstract protected function _init_props(); |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods |
|
233 | - * will have to take care of handling. |
|
234 | - * |
|
235 | - * @abstract |
|
236 | - * @access protected |
|
237 | - * @param string $shortcode the shortcode to be parsed. |
|
238 | - * @param mixed (object|array) $data incoming data for the parser. The data could be either an object or |
|
239 | - * array because there are some shortcodes that might be replaced by prepared data that |
|
240 | - * has multiple items in a list (i.e. list of attendees in an event and we're showing |
|
241 | - * fname/lname for each attendee). In this case data will be in an array. Otherwise |
|
242 | - * the data shoudl be in a properly formatted object. The |
|
243 | - * EEH_Parse_Shortcodes.helper.php describes the data object we're expecting. |
|
244 | - * @return string parsed shortcode |
|
245 | - */ |
|
246 | - abstract protected function _parser($shortcode); |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * This just validates incoming data for list type shortcode parsers (and they call this method) to make sure it |
|
251 | - * meets their requirements |
|
252 | - * |
|
253 | - * @return mixed (void|exception) If validation fails we'll throw an exception. |
|
254 | - */ |
|
255 | - protected function _validate_list_requirements() |
|
256 | - { |
|
257 | - |
|
258 | - //first test to make sure we've got an array! |
|
259 | - if (! is_array($this->_data)) { |
|
260 | - throw new EE_Error(sprintf(__('Expecting an array for the data sent to %s. Instead it was %s', |
|
261 | - 'event_espresso'), get_class($this), gettype($this->_data))); |
|
262 | - } |
|
263 | - |
|
264 | - //next test to make sure we've got the required template in the index! |
|
265 | - if (! isset($this->_data['template'])) { |
|
266 | - throw new EE_Error(sprintf(__('The incoming data does not have the required template index in its array', |
|
267 | - 'event_espresso'))); |
|
268 | - } |
|
269 | - |
|
270 | - //next test to make sure we've got got a data index in the incoming data array |
|
271 | - if (! isset($this->_data['data'])) { |
|
272 | - throw new EE_Error(__('The incoming data does not have the required data index in its array', |
|
273 | - 'event_espresso')); |
|
274 | - } |
|
275 | - |
|
276 | - //all is well let's make sure _extra_data always has the values needed. |
|
277 | - //let's make sure that extra_data includes all templates (for later parsing if necessary) |
|
278 | - if (empty($this->_extra_data) || (empty($this->_extra_data['data']) && empty($this->_extra_data['template']))) { |
|
279 | - $this->_extra_data['data'] = $this->_data['data']; |
|
280 | - $this->_extra_data['template'] = $this->_data['template']; |
|
281 | - } |
|
282 | - |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * This returns any attributes that may be existing on an EE_Shortcode |
|
288 | - * |
|
289 | - * @since 4.5.0 |
|
290 | - * @param string $shortcode incoming shortcode |
|
291 | - * @return array An array with the attributes |
|
292 | - */ |
|
293 | - protected function _get_shortcode_attrs($shortcode) |
|
294 | - { |
|
295 | - //make sure the required wp helper function is present |
|
296 | - //require the shortcode file if necessary |
|
297 | - if (! function_exists('shortcode_parse_atts')) { |
|
298 | - require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
299 | - } |
|
300 | - |
|
301 | - //let's get any attributes that may be present and set the defaults. |
|
302 | - $shortcode_to_parse = str_replace('[', '', str_replace(']', '', $shortcode)); |
|
303 | - return shortcode_parse_atts($shortcode_to_parse); |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * Conditional blocks are shortcode patterns with an opening conditional tag `[IF_*]` and a corresponding |
|
309 | - * closing tag (eg `[/IF_*]`). The content within the tags will be displayed/hidden depending on whatever conditions |
|
310 | - * existed in the opening tag. This method handles parsing the actual template to show/hide this conditional content. |
|
311 | - * |
|
312 | - * @since 4.9.32 |
|
313 | - * |
|
314 | - * @param string $shortcode This should be original shortcode as used in the template and passed to the parser. |
|
315 | - * @param bool $show true means the opening and closing tags are removed and the content is left showing, false |
|
316 | - * means the opening and closing tags and the contained content are removed. |
|
317 | - * @return string The template for the shortcode is returned. |
|
318 | - */ |
|
319 | - protected function _mutate_conditional_block_in_template($shortcode, $show = true) |
|
320 | - { |
|
321 | - //first let's get all the matches in the template for this particular shortcode. |
|
322 | - preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
323 | - |
|
324 | - if ($matches && is_array($matches[0]) && !empty($matches[0])) { |
|
325 | - //we need to hide all instances of the matches |
|
326 | - foreach ($matches[0] as $index => $content_to_show_or_hide) { |
|
327 | - $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
|
328 | - $replacement = $show ? $matches[4][$index] : ''; |
|
329 | - $this->_data['template'] = preg_replace( |
|
330 | - '~' . $content_to_show_or_hide . '~', |
|
331 | - $replacement, |
|
332 | - $this->_data['template'] |
|
333 | - ); |
|
334 | - } |
|
335 | - } |
|
336 | - //return $template |
|
337 | - return $this->_data['template']; |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * This returns the regex pattern to use for conditional shortcodes parsing. |
|
343 | - * |
|
344 | - * Note: regex comes in part from the WP `get_shortcode_regex` expression in \wp-includes\shortcodes.php |
|
345 | - * |
|
346 | - * @param $shortcode |
|
347 | - * @since 4.9.32 |
|
348 | - * @return string |
|
349 | - */ |
|
350 | - private function _get_conditional_block_regex($shortcode) |
|
351 | - { |
|
352 | - //get just the shortcode tag for the match |
|
353 | - preg_match('@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode, $shortcode_tag_matches); |
|
354 | - if (empty($shortcode_tag_matches[1])) { |
|
355 | - return $this->_data['template']; |
|
356 | - } |
|
357 | - |
|
358 | - $shortcode_tag = $shortcode_tag_matches[1]; |
|
359 | - //get attributes_part_of_tag |
|
360 | - $attributes_part = preg_quote(str_replace(array($shortcode_tag,'[',']'), '', $shortcode)); |
|
361 | - //escape |
|
362 | - $shortcode_tag = preg_quote($shortcode_tag); |
|
363 | - |
|
364 | - return |
|
365 | - '\[' //Opening Bracket |
|
366 | - . "($shortcode_tag)$attributes_part" //1: Shortcode Name |
|
367 | - . '(?![\w-])' //Not followed by word character or hyphen |
|
368 | - . '(' //2: Unroll the loop: Inside the opening shortcode tag |
|
369 | - . '[^\]\/]*' //Not a closing bracket or forward slash |
|
370 | - . '(?:' |
|
371 | - . '\/(?!\])' //A forward slash not followed by a closing bracket |
|
372 | - . '[^\]\/]*' //Not a closing bracket or forward slash. |
|
373 | - . ')*?' |
|
374 | - . ')' |
|
375 | - . '(?:' |
|
376 | - . '(\/)' //3. Self closing tag ... |
|
377 | - . '\]' // ... and closing bracket |
|
378 | - . '|' |
|
379 | - . '\]' //Closing bracket |
|
380 | - . '(?:' |
|
381 | - . '(' //4: Unroll the loop: Optionally, anything between the opening and closing brackets |
|
382 | - . '[^\[]*+' //Not an opening bracket |
|
383 | - . '(?:' |
|
384 | - . '\[(?!\/\1\])' //An opening bracket not followed by the closing shortcode tag. |
|
385 | - . '[^\[]*+' //Not an opening bracket |
|
386 | - . ')*+' |
|
387 | - . ')' |
|
388 | - . '\[\/\1\]' //Closing shortcode tag |
|
389 | - . ')?' |
|
390 | - . ')'; |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * This sets the properties related to the messages system |
|
396 | - * |
|
397 | - * @since 4.5.0 |
|
398 | - * @return void |
|
399 | - */ |
|
400 | - protected function _set_messages_properties() |
|
401 | - { |
|
402 | - //should be in _extra_data |
|
403 | - if (isset($this->_extra_data['messenger'])) { |
|
404 | - $this->_messenger = $this->_extra_data['messenger']; |
|
405 | - $this->_message_type = $this->_extra_data['message_type']; |
|
406 | - $this->_context = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message']->context() : ''; |
|
407 | - $this->_GRP_ID = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message']->GRP_ID() : 0; |
|
408 | - $this->_message = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message'] : null; |
|
409 | - } |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * This returns whatever the set message type object is that was set on this shortcode parser. |
|
415 | - * |
|
416 | - * @since 4.5.0 |
|
417 | - * @return EE_message_type |
|
418 | - */ |
|
419 | - public function get_set_message_type() |
|
420 | - { |
|
421 | - return $this->_message_type; |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * This returns whatever the set messenger object is that was set on this shortcode parser |
|
427 | - * |
|
428 | - * @since 4.5.0 |
|
429 | - * @return EE_messenger |
|
430 | - */ |
|
431 | - public function get_set_messenger() |
|
432 | - { |
|
433 | - return $this->_messenger; |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * This returns whatever the set context string is on this shortcode parser. |
|
439 | - * |
|
440 | - * @since 4.5.0 |
|
441 | - * @return string |
|
442 | - */ |
|
443 | - public function get_set_context() |
|
444 | - { |
|
445 | - return $this->_context; |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * This returns whatever the set EE_Message object is on this shortcode. |
|
451 | - * |
|
452 | - * @since 4.9.0 |
|
453 | - * @return EE_Message |
|
454 | - */ |
|
455 | - public function get_set_message() |
|
456 | - { |
|
457 | - return $this->_message; |
|
458 | - } |
|
33 | + /** |
|
34 | + * holds label for library |
|
35 | + * This is used for referencing the library label |
|
36 | + * |
|
37 | + * @access public |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + public $label; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * This property is used for referencing a short description of the library |
|
45 | + * |
|
46 | + * @access public |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $description; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * This will hold an array of shortcodes with the key as the shortcode ([shortcode]) and the value as a |
|
54 | + * label/description for the shortcode. |
|
55 | + * |
|
56 | + * @access protected |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + protected $_shortcodes; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * This will hold the incoming data item sent to the parser method |
|
64 | + * |
|
65 | + * @access protected |
|
66 | + * @var mixed (array|object) |
|
67 | + */ |
|
68 | + protected $_data; |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * some shortcodes may require extra data to parse. This property is provided for that. |
|
73 | + * |
|
74 | + * @var array |
|
75 | + */ |
|
76 | + protected $_extra_data; |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * EE_messenger used to generate the template being parsed. |
|
81 | + * |
|
82 | + * @since 4.5.0 |
|
83 | + * @var EE_messenger |
|
84 | + */ |
|
85 | + protected $_messenger; |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * message type used to generate the template being parsed. |
|
90 | + * |
|
91 | + * @since 4.5.0 |
|
92 | + * @var EE_message_type |
|
93 | + */ |
|
94 | + protected $_message_type; |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * context used for the template being parsed |
|
99 | + * |
|
100 | + * @since 4.5.0 |
|
101 | + * @var string |
|
102 | + */ |
|
103 | + protected $_context; |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Specific Message Template Group ID |
|
108 | + * |
|
109 | + * @since 4.5.0 |
|
110 | + * @var int |
|
111 | + */ |
|
112 | + protected $_GRP_ID; |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @since 4.9.0 |
|
117 | + * @type EE_Message |
|
118 | + */ |
|
119 | + protected $_message; |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * This will hold an instance of the EEH_Parse_Shortcodes helper that will be used when handling list type |
|
124 | + * shortcodes |
|
125 | + * |
|
126 | + * @var EEH_Parse_Shortcodes |
|
127 | + */ |
|
128 | + protected $_shortcode_helper; |
|
129 | + |
|
130 | + |
|
131 | + public function __construct() |
|
132 | + { |
|
133 | + $this->_set_defaults(); |
|
134 | + $this->_init_props(); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * This sets the defaults for the properties. Child classes will override these properties in their _init_props |
|
140 | + * method |
|
141 | + */ |
|
142 | + private function _set_defaults() |
|
143 | + { |
|
144 | + $this->name = $this->description = ''; |
|
145 | + $this->_shortcodes = array(); |
|
146 | + $this->_set_shortcode_helper(); |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * loads an instance of the EE_Shortcode_Parser helper when requested |
|
152 | + */ |
|
153 | + protected function _set_shortcode_helper() |
|
154 | + { |
|
155 | + //get shortcode_replace instance- set when _get_messages is called in child... |
|
156 | + $this->_shortcode_helper = new EEH_Parse_Shortcodes(); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + public function get_shortcode_helper() |
|
161 | + { |
|
162 | + if (! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
163 | + $this->_set_shortcode_helper(); |
|
164 | + } |
|
165 | + return $this->_shortcode_helper; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * This is the public method for kicking of the parser included with each child. It can be overridden by child |
|
171 | + * classes if necessary (see EE_Questions_Answers for example) |
|
172 | + * |
|
173 | + * @param string $shortcode incoming shortcode to be parsed |
|
174 | + * @param mixed (object|array) $data incoming data to be be used for parsing |
|
175 | + * @param mixed (object|array) $extra_data extra incoming data (usually EE_Messages_Addressee) |
|
176 | + * @return string parsed shortcode. |
|
177 | + */ |
|
178 | + public function parser($shortcode, $data, $extra_data = array()) |
|
179 | + { |
|
180 | + |
|
181 | + //filter setup shortcodes |
|
182 | + $this->_shortcodes = $this->get_shortcodes(); |
|
183 | + |
|
184 | + //we need to setup any dynamic shortcodes so that they work with the array_key_exists |
|
185 | + $sc = preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
186 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
187 | + |
|
188 | + //first we want to make sure this is a valid shortcode |
|
189 | + if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
190 | + return false; |
|
191 | + } //get out, this parser doesn't handle the incoming shortcode. |
|
192 | + $this->_data = $data; |
|
193 | + $this->_extra_data = $extra_data; |
|
194 | + $this->_set_messages_properties(); |
|
195 | + $parsed = apply_filters('FHEE__' . get_class($this) . '__parser_after', $this->_parser($shortcode), $shortcode, |
|
196 | + $data, $extra_data, $this); |
|
197 | + |
|
198 | + //note the below filter applies to ALL shortcode parsers... be careful! |
|
199 | + $parsed = apply_filters('FHEE__EE_Shortcodes__parser_after', $parsed, $shortcode, $data, $extra_data, $this); |
|
200 | + return $parsed; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * This method just returns the shortcodes in the $_shortcodes array property. |
|
206 | + * |
|
207 | + * @access public |
|
208 | + * @return array array of shortcodes => description pairs |
|
209 | + */ |
|
210 | + public function get_shortcodes() |
|
211 | + { |
|
212 | + $this->_shortcodes = apply_filters('FHEE__' . get_class($this) . '__shortcodes', $this->_shortcodes, $this); |
|
213 | + |
|
214 | + //note the below filter applies to ALL shortcode parsers... be careful! |
|
215 | + $this->_shortcodes = apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this); |
|
216 | + |
|
217 | + return $this->_shortcodes; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * Child classes use this method to set the $name, $description, and $_shortcodes properties. |
|
223 | + * |
|
224 | + * @abstract |
|
225 | + * @access protected |
|
226 | + * @return void |
|
227 | + */ |
|
228 | + abstract protected function _init_props(); |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods |
|
233 | + * will have to take care of handling. |
|
234 | + * |
|
235 | + * @abstract |
|
236 | + * @access protected |
|
237 | + * @param string $shortcode the shortcode to be parsed. |
|
238 | + * @param mixed (object|array) $data incoming data for the parser. The data could be either an object or |
|
239 | + * array because there are some shortcodes that might be replaced by prepared data that |
|
240 | + * has multiple items in a list (i.e. list of attendees in an event and we're showing |
|
241 | + * fname/lname for each attendee). In this case data will be in an array. Otherwise |
|
242 | + * the data shoudl be in a properly formatted object. The |
|
243 | + * EEH_Parse_Shortcodes.helper.php describes the data object we're expecting. |
|
244 | + * @return string parsed shortcode |
|
245 | + */ |
|
246 | + abstract protected function _parser($shortcode); |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * This just validates incoming data for list type shortcode parsers (and they call this method) to make sure it |
|
251 | + * meets their requirements |
|
252 | + * |
|
253 | + * @return mixed (void|exception) If validation fails we'll throw an exception. |
|
254 | + */ |
|
255 | + protected function _validate_list_requirements() |
|
256 | + { |
|
257 | + |
|
258 | + //first test to make sure we've got an array! |
|
259 | + if (! is_array($this->_data)) { |
|
260 | + throw new EE_Error(sprintf(__('Expecting an array for the data sent to %s. Instead it was %s', |
|
261 | + 'event_espresso'), get_class($this), gettype($this->_data))); |
|
262 | + } |
|
263 | + |
|
264 | + //next test to make sure we've got the required template in the index! |
|
265 | + if (! isset($this->_data['template'])) { |
|
266 | + throw new EE_Error(sprintf(__('The incoming data does not have the required template index in its array', |
|
267 | + 'event_espresso'))); |
|
268 | + } |
|
269 | + |
|
270 | + //next test to make sure we've got got a data index in the incoming data array |
|
271 | + if (! isset($this->_data['data'])) { |
|
272 | + throw new EE_Error(__('The incoming data does not have the required data index in its array', |
|
273 | + 'event_espresso')); |
|
274 | + } |
|
275 | + |
|
276 | + //all is well let's make sure _extra_data always has the values needed. |
|
277 | + //let's make sure that extra_data includes all templates (for later parsing if necessary) |
|
278 | + if (empty($this->_extra_data) || (empty($this->_extra_data['data']) && empty($this->_extra_data['template']))) { |
|
279 | + $this->_extra_data['data'] = $this->_data['data']; |
|
280 | + $this->_extra_data['template'] = $this->_data['template']; |
|
281 | + } |
|
282 | + |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * This returns any attributes that may be existing on an EE_Shortcode |
|
288 | + * |
|
289 | + * @since 4.5.0 |
|
290 | + * @param string $shortcode incoming shortcode |
|
291 | + * @return array An array with the attributes |
|
292 | + */ |
|
293 | + protected function _get_shortcode_attrs($shortcode) |
|
294 | + { |
|
295 | + //make sure the required wp helper function is present |
|
296 | + //require the shortcode file if necessary |
|
297 | + if (! function_exists('shortcode_parse_atts')) { |
|
298 | + require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
299 | + } |
|
300 | + |
|
301 | + //let's get any attributes that may be present and set the defaults. |
|
302 | + $shortcode_to_parse = str_replace('[', '', str_replace(']', '', $shortcode)); |
|
303 | + return shortcode_parse_atts($shortcode_to_parse); |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * Conditional blocks are shortcode patterns with an opening conditional tag `[IF_*]` and a corresponding |
|
309 | + * closing tag (eg `[/IF_*]`). The content within the tags will be displayed/hidden depending on whatever conditions |
|
310 | + * existed in the opening tag. This method handles parsing the actual template to show/hide this conditional content. |
|
311 | + * |
|
312 | + * @since 4.9.32 |
|
313 | + * |
|
314 | + * @param string $shortcode This should be original shortcode as used in the template and passed to the parser. |
|
315 | + * @param bool $show true means the opening and closing tags are removed and the content is left showing, false |
|
316 | + * means the opening and closing tags and the contained content are removed. |
|
317 | + * @return string The template for the shortcode is returned. |
|
318 | + */ |
|
319 | + protected function _mutate_conditional_block_in_template($shortcode, $show = true) |
|
320 | + { |
|
321 | + //first let's get all the matches in the template for this particular shortcode. |
|
322 | + preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
323 | + |
|
324 | + if ($matches && is_array($matches[0]) && !empty($matches[0])) { |
|
325 | + //we need to hide all instances of the matches |
|
326 | + foreach ($matches[0] as $index => $content_to_show_or_hide) { |
|
327 | + $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
|
328 | + $replacement = $show ? $matches[4][$index] : ''; |
|
329 | + $this->_data['template'] = preg_replace( |
|
330 | + '~' . $content_to_show_or_hide . '~', |
|
331 | + $replacement, |
|
332 | + $this->_data['template'] |
|
333 | + ); |
|
334 | + } |
|
335 | + } |
|
336 | + //return $template |
|
337 | + return $this->_data['template']; |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * This returns the regex pattern to use for conditional shortcodes parsing. |
|
343 | + * |
|
344 | + * Note: regex comes in part from the WP `get_shortcode_regex` expression in \wp-includes\shortcodes.php |
|
345 | + * |
|
346 | + * @param $shortcode |
|
347 | + * @since 4.9.32 |
|
348 | + * @return string |
|
349 | + */ |
|
350 | + private function _get_conditional_block_regex($shortcode) |
|
351 | + { |
|
352 | + //get just the shortcode tag for the match |
|
353 | + preg_match('@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode, $shortcode_tag_matches); |
|
354 | + if (empty($shortcode_tag_matches[1])) { |
|
355 | + return $this->_data['template']; |
|
356 | + } |
|
357 | + |
|
358 | + $shortcode_tag = $shortcode_tag_matches[1]; |
|
359 | + //get attributes_part_of_tag |
|
360 | + $attributes_part = preg_quote(str_replace(array($shortcode_tag,'[',']'), '', $shortcode)); |
|
361 | + //escape |
|
362 | + $shortcode_tag = preg_quote($shortcode_tag); |
|
363 | + |
|
364 | + return |
|
365 | + '\[' //Opening Bracket |
|
366 | + . "($shortcode_tag)$attributes_part" //1: Shortcode Name |
|
367 | + . '(?![\w-])' //Not followed by word character or hyphen |
|
368 | + . '(' //2: Unroll the loop: Inside the opening shortcode tag |
|
369 | + . '[^\]\/]*' //Not a closing bracket or forward slash |
|
370 | + . '(?:' |
|
371 | + . '\/(?!\])' //A forward slash not followed by a closing bracket |
|
372 | + . '[^\]\/]*' //Not a closing bracket or forward slash. |
|
373 | + . ')*?' |
|
374 | + . ')' |
|
375 | + . '(?:' |
|
376 | + . '(\/)' //3. Self closing tag ... |
|
377 | + . '\]' // ... and closing bracket |
|
378 | + . '|' |
|
379 | + . '\]' //Closing bracket |
|
380 | + . '(?:' |
|
381 | + . '(' //4: Unroll the loop: Optionally, anything between the opening and closing brackets |
|
382 | + . '[^\[]*+' //Not an opening bracket |
|
383 | + . '(?:' |
|
384 | + . '\[(?!\/\1\])' //An opening bracket not followed by the closing shortcode tag. |
|
385 | + . '[^\[]*+' //Not an opening bracket |
|
386 | + . ')*+' |
|
387 | + . ')' |
|
388 | + . '\[\/\1\]' //Closing shortcode tag |
|
389 | + . ')?' |
|
390 | + . ')'; |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * This sets the properties related to the messages system |
|
396 | + * |
|
397 | + * @since 4.5.0 |
|
398 | + * @return void |
|
399 | + */ |
|
400 | + protected function _set_messages_properties() |
|
401 | + { |
|
402 | + //should be in _extra_data |
|
403 | + if (isset($this->_extra_data['messenger'])) { |
|
404 | + $this->_messenger = $this->_extra_data['messenger']; |
|
405 | + $this->_message_type = $this->_extra_data['message_type']; |
|
406 | + $this->_context = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message']->context() : ''; |
|
407 | + $this->_GRP_ID = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message']->GRP_ID() : 0; |
|
408 | + $this->_message = $this->_extra_data['message'] instanceof EE_Message ? $this->_extra_data['message'] : null; |
|
409 | + } |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * This returns whatever the set message type object is that was set on this shortcode parser. |
|
415 | + * |
|
416 | + * @since 4.5.0 |
|
417 | + * @return EE_message_type |
|
418 | + */ |
|
419 | + public function get_set_message_type() |
|
420 | + { |
|
421 | + return $this->_message_type; |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * This returns whatever the set messenger object is that was set on this shortcode parser |
|
427 | + * |
|
428 | + * @since 4.5.0 |
|
429 | + * @return EE_messenger |
|
430 | + */ |
|
431 | + public function get_set_messenger() |
|
432 | + { |
|
433 | + return $this->_messenger; |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * This returns whatever the set context string is on this shortcode parser. |
|
439 | + * |
|
440 | + * @since 4.5.0 |
|
441 | + * @return string |
|
442 | + */ |
|
443 | + public function get_set_context() |
|
444 | + { |
|
445 | + return $this->_context; |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * This returns whatever the set EE_Message object is on this shortcode. |
|
451 | + * |
|
452 | + * @since 4.9.0 |
|
453 | + * @return EE_Message |
|
454 | + */ |
|
455 | + public function get_set_message() |
|
456 | + { |
|
457 | + return $this->_message; |
|
458 | + } |
|
459 | 459 | |
460 | 460 | |
461 | 461 | } //end EE_Shortcodes |
@@ -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 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | |
160 | 160 | public function get_shortcode_helper() |
161 | 161 | { |
162 | - if (! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
162 | + if ( ! $this->_shortcode_helper instanceof EEH_Parse_Shortcodes) { |
|
163 | 163 | $this->_set_shortcode_helper(); |
164 | 164 | } |
165 | 165 | return $this->_shortcode_helper; |
@@ -183,16 +183,16 @@ discard block |
||
183 | 183 | |
184 | 184 | //we need to setup any dynamic shortcodes so that they work with the array_key_exists |
185 | 185 | $sc = preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
186 | - $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode; |
|
186 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0].']' : $shortcode; |
|
187 | 187 | |
188 | 188 | //first we want to make sure this is a valid shortcode |
189 | - if (! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
189 | + if ( ! array_key_exists($sc_to_verify, $this->_shortcodes)) { |
|
190 | 190 | return false; |
191 | 191 | } //get out, this parser doesn't handle the incoming shortcode. |
192 | 192 | $this->_data = $data; |
193 | 193 | $this->_extra_data = $extra_data; |
194 | 194 | $this->_set_messages_properties(); |
195 | - $parsed = apply_filters('FHEE__' . get_class($this) . '__parser_after', $this->_parser($shortcode), $shortcode, |
|
195 | + $parsed = apply_filters('FHEE__'.get_class($this).'__parser_after', $this->_parser($shortcode), $shortcode, |
|
196 | 196 | $data, $extra_data, $this); |
197 | 197 | |
198 | 198 | //note the below filter applies to ALL shortcode parsers... be careful! |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public function get_shortcodes() |
211 | 211 | { |
212 | - $this->_shortcodes = apply_filters('FHEE__' . get_class($this) . '__shortcodes', $this->_shortcodes, $this); |
|
212 | + $this->_shortcodes = apply_filters('FHEE__'.get_class($this).'__shortcodes', $this->_shortcodes, $this); |
|
213 | 213 | |
214 | 214 | //note the below filter applies to ALL shortcode parsers... be careful! |
215 | 215 | $this->_shortcodes = apply_filters('FHEE__EE_Shortcodes__shortcodes', $this->_shortcodes, $this); |
@@ -256,19 +256,19 @@ discard block |
||
256 | 256 | { |
257 | 257 | |
258 | 258 | //first test to make sure we've got an array! |
259 | - if (! is_array($this->_data)) { |
|
259 | + if ( ! is_array($this->_data)) { |
|
260 | 260 | throw new EE_Error(sprintf(__('Expecting an array for the data sent to %s. Instead it was %s', |
261 | 261 | 'event_espresso'), get_class($this), gettype($this->_data))); |
262 | 262 | } |
263 | 263 | |
264 | 264 | //next test to make sure we've got the required template in the index! |
265 | - if (! isset($this->_data['template'])) { |
|
265 | + if ( ! isset($this->_data['template'])) { |
|
266 | 266 | throw new EE_Error(sprintf(__('The incoming data does not have the required template index in its array', |
267 | 267 | 'event_espresso'))); |
268 | 268 | } |
269 | 269 | |
270 | 270 | //next test to make sure we've got got a data index in the incoming data array |
271 | - if (! isset($this->_data['data'])) { |
|
271 | + if ( ! isset($this->_data['data'])) { |
|
272 | 272 | throw new EE_Error(__('The incoming data does not have the required data index in its array', |
273 | 273 | 'event_espresso')); |
274 | 274 | } |
@@ -294,8 +294,8 @@ discard block |
||
294 | 294 | { |
295 | 295 | //make sure the required wp helper function is present |
296 | 296 | //require the shortcode file if necessary |
297 | - if (! function_exists('shortcode_parse_atts')) { |
|
298 | - require_once(ABSPATH . WPINC . '/shortcodes.php'); |
|
297 | + if ( ! function_exists('shortcode_parse_atts')) { |
|
298 | + require_once(ABSPATH.WPINC.'/shortcodes.php'); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | //let's get any attributes that may be present and set the defaults. |
@@ -319,15 +319,15 @@ discard block |
||
319 | 319 | protected function _mutate_conditional_block_in_template($shortcode, $show = true) |
320 | 320 | { |
321 | 321 | //first let's get all the matches in the template for this particular shortcode. |
322 | - preg_match_all('~' . $this->_get_conditional_block_regex($shortcode) . '~', $this->_data['template'], $matches); |
|
322 | + preg_match_all('~'.$this->_get_conditional_block_regex($shortcode).'~', $this->_data['template'], $matches); |
|
323 | 323 | |
324 | - if ($matches && is_array($matches[0]) && !empty($matches[0])) { |
|
324 | + if ($matches && is_array($matches[0]) && ! empty($matches[0])) { |
|
325 | 325 | //we need to hide all instances of the matches |
326 | 326 | foreach ($matches[0] as $index => $content_to_show_or_hide) { |
327 | 327 | $content_to_show_or_hide = preg_quote($content_to_show_or_hide); |
328 | 328 | $replacement = $show ? $matches[4][$index] : ''; |
329 | 329 | $this->_data['template'] = preg_replace( |
330 | - '~' . $content_to_show_or_hide . '~', |
|
330 | + '~'.$content_to_show_or_hide.'~', |
|
331 | 331 | $replacement, |
332 | 332 | $this->_data['template'] |
333 | 333 | ); |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | |
358 | 358 | $shortcode_tag = $shortcode_tag_matches[1]; |
359 | 359 | //get attributes_part_of_tag |
360 | - $attributes_part = preg_quote(str_replace(array($shortcode_tag,'[',']'), '', $shortcode)); |
|
360 | + $attributes_part = preg_quote(str_replace(array($shortcode_tag, '[', ']'), '', $shortcode)); |
|
361 | 361 | //escape |
362 | 362 | $shortcode_tag = preg_quote($shortcode_tag); |
363 | 363 |
@@ -362,62 +362,62 @@ |
||
362 | 362 | |
363 | 363 | |
364 | 364 | |
365 | - /** |
|
366 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
367 | - * @throws \EE_Error |
|
368 | - */ |
|
369 | - public function get_total_line_items_with_no_transaction() |
|
370 | - { |
|
371 | - return $this->get_total_line_items_for_carts(); |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
378 | - * @throws \EE_Error |
|
379 | - */ |
|
380 | - public function get_total_line_items_for_active_carts() |
|
381 | - { |
|
382 | - return $this->get_total_line_items_for_carts(false); |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
389 | - * @throws \EE_Error |
|
390 | - */ |
|
391 | - public function get_total_line_items_for_expired_carts() |
|
392 | - { |
|
393 | - return $this->get_total_line_items_for_carts(true); |
|
394 | - } |
|
395 | - |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * Returns an array of grand total line items where the TXN_ID is 0. |
|
400 | - * If $expired is set to true, then only line items for expired sessions will be returned. |
|
401 | - * If $expired is set to false, then only line items for active sessions will be returned. |
|
402 | - * |
|
403 | - * @param bool|null $expired |
|
404 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
405 | - * @throws \EE_Error |
|
406 | - */ |
|
407 | - private function get_total_line_items_for_carts($expired = null) |
|
408 | - { |
|
409 | - $where_params = array( |
|
410 | - 'TXN_ID' => 0, |
|
411 | - 'LIN_type' => 'total', |
|
412 | - ); |
|
413 | - if ($expired !== null) { |
|
414 | - $where_params['LIN_timestamp'] = array( |
|
415 | - $expired ? '<=' : '>', |
|
416 | - time() - EE_Registry::instance()->SSN->lifespan(), |
|
417 | - ); |
|
418 | - } |
|
419 | - return $this->get_all(array($where_params)); |
|
420 | - } |
|
365 | + /** |
|
366 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
367 | + * @throws \EE_Error |
|
368 | + */ |
|
369 | + public function get_total_line_items_with_no_transaction() |
|
370 | + { |
|
371 | + return $this->get_total_line_items_for_carts(); |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
378 | + * @throws \EE_Error |
|
379 | + */ |
|
380 | + public function get_total_line_items_for_active_carts() |
|
381 | + { |
|
382 | + return $this->get_total_line_items_for_carts(false); |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
389 | + * @throws \EE_Error |
|
390 | + */ |
|
391 | + public function get_total_line_items_for_expired_carts() |
|
392 | + { |
|
393 | + return $this->get_total_line_items_for_carts(true); |
|
394 | + } |
|
395 | + |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * Returns an array of grand total line items where the TXN_ID is 0. |
|
400 | + * If $expired is set to true, then only line items for expired sessions will be returned. |
|
401 | + * If $expired is set to false, then only line items for active sessions will be returned. |
|
402 | + * |
|
403 | + * @param bool|null $expired |
|
404 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
405 | + * @throws \EE_Error |
|
406 | + */ |
|
407 | + private function get_total_line_items_for_carts($expired = null) |
|
408 | + { |
|
409 | + $where_params = array( |
|
410 | + 'TXN_ID' => 0, |
|
411 | + 'LIN_type' => 'total', |
|
412 | + ); |
|
413 | + if ($expired !== null) { |
|
414 | + $where_params['LIN_timestamp'] = array( |
|
415 | + $expired ? '<=' : '>', |
|
416 | + time() - EE_Registry::instance()->SSN->lifespan(), |
|
417 | + ); |
|
418 | + } |
|
419 | + return $this->get_all(array($where_params)); |
|
420 | + } |
|
421 | 421 | |
422 | 422 | |
423 | 423 |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | } |
104 | 104 | $order = apply_filters( 'FHEE__EEG_Mijireh__set_redirection_info__order_arguments', $order, $payment, $primary_registrant ); |
105 | 105 | do_action( 'AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this)) ); |
106 | - $order = $this->_get_unsupported_character_remover()->formatArray($order); |
|
106 | + $order = $this->_get_unsupported_character_remover()->formatArray($order); |
|
107 | 107 | |
108 | 108 | $args = array( |
109 | 109 | 'headers' => array( |
@@ -113,45 +113,45 @@ discard block |
||
113 | 113 | 'body'=> wp_json_encode($order) |
114 | 114 | ); |
115 | 115 | $response = wp_remote_post( $this->_mijireh_api_orders_url, $args ); |
116 | - $problems_string = false; |
|
116 | + $problems_string = false; |
|
117 | 117 | $this->log(array('get checkout url request_args' => $args, 'response' => $response ), $payment); |
118 | 118 | if( ! $response instanceof WP_Error ){ |
119 | 119 | $response_body = json_decode($response['body']); |
120 | 120 | if($response_body && isset($response_body->checkout_url)){ |
121 | - $payment->set_redirect_url($response_body->checkout_url); |
|
122 | - $payment->set_txn_id_chq_nmbr($response_body->order_number); |
|
123 | - $payment->set_details($response['body']); |
|
121 | + $payment->set_redirect_url($response_body->checkout_url); |
|
122 | + $payment->set_txn_id_chq_nmbr($response_body->order_number); |
|
123 | + $payment->set_details($response['body']); |
|
124 | 124 | } else { |
125 | - if( is_array( $response_body ) || is_object( $response_body)){ |
|
126 | - $response_body_as_array = (array)$response_body; |
|
127 | - foreach($response_body_as_array as $problem_parameter => $problems){ |
|
128 | - $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems)); |
|
129 | - } |
|
130 | - }else{ |
|
131 | - $problems_string = $response['body']; |
|
132 | - } |
|
133 | - if( ! $problems_string ) { |
|
134 | - //no message to show? wack |
|
135 | - if( isset( $response[ 'headers' ][ 'status' ] ) ){ |
|
136 | - $problems_string = $response[ 'headers' ][ 'status' ]; |
|
137 | - }else{ |
|
138 | - $problems_string = __( 'No response from Mijireh', 'event_espresso' ); |
|
139 | - } |
|
140 | - } |
|
141 | - } |
|
125 | + if( is_array( $response_body ) || is_object( $response_body)){ |
|
126 | + $response_body_as_array = (array)$response_body; |
|
127 | + foreach($response_body_as_array as $problem_parameter => $problems){ |
|
128 | + $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems)); |
|
129 | + } |
|
130 | + }else{ |
|
131 | + $problems_string = $response['body']; |
|
132 | + } |
|
133 | + if( ! $problems_string ) { |
|
134 | + //no message to show? wack |
|
135 | + if( isset( $response[ 'headers' ][ 'status' ] ) ){ |
|
136 | + $problems_string = $response[ 'headers' ][ 'status' ]; |
|
137 | + }else{ |
|
138 | + $problems_string = __( 'No response from Mijireh', 'event_espresso' ); |
|
139 | + } |
|
140 | + } |
|
141 | + } |
|
142 | 142 | }else{ |
143 | - $problems_string = implode( ",", $response->get_error_messages() ); |
|
143 | + $problems_string = implode( ",", $response->get_error_messages() ); |
|
144 | 144 | } |
145 | 145 | |
146 | - if( $problems_string ) { |
|
147 | - $payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) ); |
|
148 | - $payment->set_details( $response ); |
|
149 | - $payment->set_redirect_url( null ); |
|
150 | - //even though the payment's status is failed at this point anyways, |
|
151 | - //let's be explicit about it. The fact that the redirect url is null |
|
152 | - //should be enough to client code that they can't redirect the user |
|
153 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
154 | - } |
|
146 | + if( $problems_string ) { |
|
147 | + $payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) ); |
|
148 | + $payment->set_details( $response ); |
|
149 | + $payment->set_redirect_url( null ); |
|
150 | + //even though the payment's status is failed at this point anyways, |
|
151 | + //let's be explicit about it. The fact that the redirect url is null |
|
152 | + //should be enough to client code that they can't redirect the user |
|
153 | + $payment->set_status( $this->_pay_model->failed_status() ); |
|
154 | + } |
|
155 | 155 | return $payment; |
156 | 156 | } |
157 | 157 | |
@@ -188,70 +188,70 @@ discard block |
||
188 | 188 | * @param array $update_info unused. We just use the $transaction |
189 | 189 | * @param EEI_Transaction $transaction |
190 | 190 | * @return \EEI_Payment |
191 | - * @throws EE_Error |
|
191 | + * @throws EE_Error |
|
192 | 192 | */ |
193 | 193 | public function handle_payment_update($update_info, $transaction) { |
194 | - foreach( $transaction->pending_payments() as $payment){ |
|
195 | - $payment = $this->check_payment_in_mijireh($payment); |
|
196 | - if( $payment->status() === $this->_pay_model->approved_status()){ |
|
197 | - return $payment; |
|
198 | - } |
|
199 | - } |
|
200 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
|
194 | + foreach( $transaction->pending_payments() as $payment){ |
|
195 | + $payment = $this->check_payment_in_mijireh($payment); |
|
196 | + if( $payment->status() === $this->_pay_model->approved_status()){ |
|
197 | + return $payment; |
|
198 | + } |
|
199 | + } |
|
200 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
|
201 | 201 | |
202 | - if ( ! $payment instanceof EEI_Payment ){ |
|
203 | - throw new EE_Error( sprintf( __( "Could not find Mijireh payment for transaction %s", 'event_espresso' ), $transaction->ID() ) ); |
|
204 | - } |
|
205 | - return $payment; |
|
202 | + if ( ! $payment instanceof EEI_Payment ){ |
|
203 | + throw new EE_Error( sprintf( __( "Could not find Mijireh payment for transaction %s", 'event_espresso' ), $transaction->ID() ) ); |
|
204 | + } |
|
205 | + return $payment; |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | |
209 | 209 | |
210 | - /** |
|
211 | - * Checks the payment's status in Mijireh for this specific payment |
|
212 | - * @param \EEI_Payment $payment |
|
213 | - * @return \EEI_Payment |
|
214 | - */ |
|
210 | + /** |
|
211 | + * Checks the payment's status in Mijireh for this specific payment |
|
212 | + * @param \EEI_Payment $payment |
|
213 | + * @return \EEI_Payment |
|
214 | + */ |
|
215 | 215 | public function check_payment_in_mijireh( EEI_Payment $payment ){ |
216 | - $request_args = array( |
|
217 | - 'headers' => array( |
|
218 | - 'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ), |
|
219 | - 'Accept'=>'application/json' |
|
220 | - ) |
|
221 | - ); |
|
216 | + $request_args = array( |
|
217 | + 'headers' => array( |
|
218 | + 'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ), |
|
219 | + 'Accept'=>'application/json' |
|
220 | + ) |
|
221 | + ); |
|
222 | 222 | |
223 | - $response = wp_remote_get( |
|
224 | - $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
225 | - $request_args |
|
226 | - ); |
|
223 | + $response = wp_remote_get( |
|
224 | + $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
225 | + $request_args |
|
226 | + ); |
|
227 | 227 | |
228 | - $this->log( |
|
229 | - array( 'get payment status request_args' => $request_args, 'response' => $response ), |
|
230 | - $payment |
|
231 | - ); |
|
232 | - // validate response |
|
233 | - $response_body = isset( $response[ 'body' ] ) ? json_decode( $response[ 'body' ] ) : ''; |
|
234 | - if( $response && $response_body ){ |
|
235 | - switch( $response_body->status ){ |
|
236 | - case 'paid': |
|
237 | - $payment->set_status($this->_pay_model->approved_status()); |
|
238 | - break; |
|
239 | - case 'pending': |
|
240 | - $payment->set_status($this->_pay_model->pending_status()); |
|
241 | - break; |
|
242 | - default: |
|
243 | - $payment->set_status($this->_pay_model->declined_status()); |
|
244 | - } |
|
228 | + $this->log( |
|
229 | + array( 'get payment status request_args' => $request_args, 'response' => $response ), |
|
230 | + $payment |
|
231 | + ); |
|
232 | + // validate response |
|
233 | + $response_body = isset( $response[ 'body' ] ) ? json_decode( $response[ 'body' ] ) : ''; |
|
234 | + if( $response && $response_body ){ |
|
235 | + switch( $response_body->status ){ |
|
236 | + case 'paid': |
|
237 | + $payment->set_status($this->_pay_model->approved_status()); |
|
238 | + break; |
|
239 | + case 'pending': |
|
240 | + $payment->set_status($this->_pay_model->pending_status()); |
|
241 | + break; |
|
242 | + default: |
|
243 | + $payment->set_status($this->_pay_model->declined_status()); |
|
244 | + } |
|
245 | 245 | |
246 | - } else { |
|
247 | - $payment->set_gateway_response( __( 'Response from Mijireh could not be understood.', 'event_espresso' ) ); |
|
248 | - $payment->set_details( $response ); |
|
249 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
250 | - } |
|
251 | - // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage |
|
246 | + } else { |
|
247 | + $payment->set_gateway_response( __( 'Response from Mijireh could not be understood.', 'event_espresso' ) ); |
|
248 | + $payment->set_details( $response ); |
|
249 | + $payment->set_status( $this->_pay_model->failed_status() ); |
|
250 | + } |
|
251 | + // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage |
|
252 | 252 | // $payment->set_status( $this->_pay_model->pending_status() ); |
253 | - return $payment; |
|
254 | - } |
|
253 | + return $payment; |
|
254 | + } |
|
255 | 255 | |
256 | 256 | } |
257 | 257 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @author Mike Nelson |
9 | 9 | * |
10 | 10 | */ |
11 | -class EEG_Mijireh extends EE_Offsite_Gateway{ |
|
11 | +class EEG_Mijireh extends EE_Offsite_Gateway { |
|
12 | 12 | |
13 | 13 | protected $_access_key; |
14 | 14 | |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | $primary_attendee = $primary_registrant->attendee(); |
38 | 38 | $items = array(); |
39 | 39 | //if we're are charging for the full amount, show the normal line items |
40 | - if( $this->_can_easily_itemize_transaction_for( $payment )){ |
|
40 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
41 | 41 | $total_line_item = $transaction->total_line_item(); |
42 | 42 | $tax_total = $total_line_item->get_total_tax(); |
43 | - foreach($total_line_item->get_items() as $line_item){ |
|
43 | + foreach ($total_line_item->get_items() as $line_item) { |
|
44 | 44 | $items[] = array( |
45 | 45 | 'name'=>apply_filters( |
46 | 46 | 'FHEE__EEG_Mijireh__set_redirection_info__full_amount_line_item_name', |
47 | - $this->_format_line_item_name( $line_item, $payment ), |
|
47 | + $this->_format_line_item_name($line_item, $payment), |
|
48 | 48 | $line_item, |
49 | 49 | $payment, |
50 | 50 | $primary_registrant |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | 'quantity'=>$line_item->quantity() |
55 | 55 | ); |
56 | 56 | } |
57 | - }else{//its a partial payment |
|
57 | + } else {//its a partial payment |
|
58 | 58 | $tax_total = 0; |
59 | 59 | //partial payment, so just add 1 item |
60 | 60 | $items[] = array( |
61 | 61 | 'name'=> apply_filters( |
62 | 62 | 'FHEE__EEG_Mijireh__set_redirection_info__partial_amount_line_item_name', |
63 | - $this->_format_partial_payment_line_item_name( $payment ), |
|
63 | + $this->_format_partial_payment_line_item_name($payment), |
|
64 | 64 | $payment, |
65 | 65 | $primary_registrant |
66 | 66 | ), |
@@ -72,18 +72,18 @@ discard block |
||
72 | 72 | $order = array( |
73 | 73 | 'total'=>$this->format_currency($payment->amount()), |
74 | 74 | 'return_url'=>$return_url, |
75 | - 'items'=>$this->_prepare_for_mijireh( $items ), |
|
75 | + 'items'=>$this->_prepare_for_mijireh($items), |
|
76 | 76 | 'email'=>$primary_attendee->email(), |
77 | 77 | 'first_name'=>$primary_attendee->fname(), |
78 | 78 | 'last_name'=>$primary_attendee->lname(), |
79 | 79 | 'tax'=>$this->format_currency($tax_total), |
80 | 80 | 'partner_id'=>'ee'); |
81 | 81 | //setup address? |
82 | - if( $primary_attendee->address() && |
|
83 | - $primary_attendee->city() && |
|
84 | - $primary_attendee->state_ID() && |
|
85 | - $primary_attendee->country_ID() && |
|
86 | - $primary_attendee->zip() ){ |
|
82 | + if ($primary_attendee->address() && |
|
83 | + $primary_attendee->city() && |
|
84 | + $primary_attendee->state_ID() && |
|
85 | + $primary_attendee->country_ID() && |
|
86 | + $primary_attendee->zip()) { |
|
87 | 87 | $shipping_address = array( |
88 | 88 | 'first_name'=>$primary_attendee->fname(), |
89 | 89 | 'last_name'=>$primary_attendee->lname(), |
@@ -93,64 +93,64 @@ discard block |
||
93 | 93 | 'zip_code' => $primary_attendee->zip(), |
94 | 94 | 'country' => $primary_attendee->country_ID() |
95 | 95 | ); |
96 | - if( $primary_attendee->address2() ){ |
|
97 | - $shipping_address[ 'apt_suite' ] = $primary_attendee->address2(); |
|
96 | + if ($primary_attendee->address2()) { |
|
97 | + $shipping_address['apt_suite'] = $primary_attendee->address2(); |
|
98 | 98 | } |
99 | - if( $primary_attendee->phone() ){ |
|
100 | - $shipping_address[ 'phone' ] = $primary_attendee->phone(); |
|
99 | + if ($primary_attendee->phone()) { |
|
100 | + $shipping_address['phone'] = $primary_attendee->phone(); |
|
101 | 101 | } |
102 | - $order[ 'shipping_address' ] = $shipping_address; |
|
102 | + $order['shipping_address'] = $shipping_address; |
|
103 | 103 | } |
104 | - $order = apply_filters( 'FHEE__EEG_Mijireh__set_redirection_info__order_arguments', $order, $payment, $primary_registrant ); |
|
105 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this)) ); |
|
104 | + $order = apply_filters('FHEE__EEG_Mijireh__set_redirection_info__order_arguments', $order, $payment, $primary_registrant); |
|
105 | + do_action('AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this))); |
|
106 | 106 | $order = $this->_get_unsupported_character_remover()->formatArray($order); |
107 | 107 | |
108 | 108 | $args = array( |
109 | 109 | 'headers' => array( |
110 | - 'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ), |
|
110 | + 'Authorization' => 'Basic '.base64_encode($this->_access_key.':'), |
|
111 | 111 | 'Accept'=>'application/json' |
112 | 112 | ), |
113 | 113 | 'body'=> wp_json_encode($order) |
114 | 114 | ); |
115 | - $response = wp_remote_post( $this->_mijireh_api_orders_url, $args ); |
|
115 | + $response = wp_remote_post($this->_mijireh_api_orders_url, $args); |
|
116 | 116 | $problems_string = false; |
117 | - $this->log(array('get checkout url request_args' => $args, 'response' => $response ), $payment); |
|
118 | - if( ! $response instanceof WP_Error ){ |
|
117 | + $this->log(array('get checkout url request_args' => $args, 'response' => $response), $payment); |
|
118 | + if ( ! $response instanceof WP_Error) { |
|
119 | 119 | $response_body = json_decode($response['body']); |
120 | - if($response_body && isset($response_body->checkout_url)){ |
|
120 | + if ($response_body && isset($response_body->checkout_url)) { |
|
121 | 121 | $payment->set_redirect_url($response_body->checkout_url); |
122 | 122 | $payment->set_txn_id_chq_nmbr($response_body->order_number); |
123 | 123 | $payment->set_details($response['body']); |
124 | 124 | } else { |
125 | - if( is_array( $response_body ) || is_object( $response_body)){ |
|
126 | - $response_body_as_array = (array)$response_body; |
|
127 | - foreach($response_body_as_array as $problem_parameter => $problems){ |
|
128 | - $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems)); |
|
125 | + if (is_array($response_body) || is_object($response_body)) { |
|
126 | + $response_body_as_array = (array) $response_body; |
|
127 | + foreach ($response_body_as_array as $problem_parameter => $problems) { |
|
128 | + $problems_string .= sprintf(__('\nProblems with %s: %s', 'event_espresso'), $problem_parameter, implode(", ", $problems)); |
|
129 | 129 | } |
130 | - }else{ |
|
130 | + } else { |
|
131 | 131 | $problems_string = $response['body']; |
132 | 132 | } |
133 | - if( ! $problems_string ) { |
|
133 | + if ( ! $problems_string) { |
|
134 | 134 | //no message to show? wack |
135 | - if( isset( $response[ 'headers' ][ 'status' ] ) ){ |
|
136 | - $problems_string = $response[ 'headers' ][ 'status' ]; |
|
137 | - }else{ |
|
138 | - $problems_string = __( 'No response from Mijireh', 'event_espresso' ); |
|
135 | + if (isset($response['headers']['status'])) { |
|
136 | + $problems_string = $response['headers']['status']; |
|
137 | + } else { |
|
138 | + $problems_string = __('No response from Mijireh', 'event_espresso'); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | } |
142 | - }else{ |
|
143 | - $problems_string = implode( ",", $response->get_error_messages() ); |
|
142 | + } else { |
|
143 | + $problems_string = implode(",", $response->get_error_messages()); |
|
144 | 144 | } |
145 | 145 | |
146 | - if( $problems_string ) { |
|
147 | - $payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) ); |
|
148 | - $payment->set_details( $response ); |
|
149 | - $payment->set_redirect_url( null ); |
|
146 | + if ($problems_string) { |
|
147 | + $payment->set_gateway_response(sprintf(__('Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string)); |
|
148 | + $payment->set_details($response); |
|
149 | + $payment->set_redirect_url(null); |
|
150 | 150 | //even though the payment's status is failed at this point anyways, |
151 | 151 | //let's be explicit about it. The fact that the redirect url is null |
152 | 152 | //should be enough to client code that they can't redirect the user |
153 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
153 | + $payment->set_status($this->_pay_model->failed_status()); |
|
154 | 154 | } |
155 | 155 | return $payment; |
156 | 156 | } |
@@ -163,16 +163,16 @@ discard block |
||
163 | 163 | * @param mixed $data |
164 | 164 | * @return mixed same type as $data |
165 | 165 | */ |
166 | - private function _prepare_for_mijireh( $data ){ |
|
167 | - if( is_array( $data ) ){ |
|
166 | + private function _prepare_for_mijireh($data) { |
|
167 | + if (is_array($data)) { |
|
168 | 168 | $prepared_data = array(); |
169 | - foreach($data as $key => $datum ){ |
|
170 | - $prepared_data[ $key ] = $this->_prepare_for_mijireh( $datum ); |
|
169 | + foreach ($data as $key => $datum) { |
|
170 | + $prepared_data[$key] = $this->_prepare_for_mijireh($datum); |
|
171 | 171 | } |
172 | 172 | return $prepared_data; |
173 | - }elseif(is_string( $data ) ){ |
|
174 | - return str_replace( '%', 'percent', $data ); |
|
175 | - }else{ |
|
173 | + }elseif (is_string($data)) { |
|
174 | + return str_replace('%', 'percent', $data); |
|
175 | + } else { |
|
176 | 176 | return $data; |
177 | 177 | } |
178 | 178 | } |
@@ -191,16 +191,16 @@ discard block |
||
191 | 191 | * @throws EE_Error |
192 | 192 | */ |
193 | 193 | public function handle_payment_update($update_info, $transaction) { |
194 | - foreach( $transaction->pending_payments() as $payment){ |
|
194 | + foreach ($transaction->pending_payments() as $payment) { |
|
195 | 195 | $payment = $this->check_payment_in_mijireh($payment); |
196 | - if( $payment->status() === $this->_pay_model->approved_status()){ |
|
196 | + if ($payment->status() === $this->_pay_model->approved_status()) { |
|
197 | 197 | return $payment; |
198 | 198 | } |
199 | 199 | } |
200 | 200 | $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
201 | 201 | |
202 | - if ( ! $payment instanceof EEI_Payment ){ |
|
203 | - throw new EE_Error( sprintf( __( "Could not find Mijireh payment for transaction %s", 'event_espresso' ), $transaction->ID() ) ); |
|
202 | + if ( ! $payment instanceof EEI_Payment) { |
|
203 | + throw new EE_Error(sprintf(__("Could not find Mijireh payment for transaction %s", 'event_espresso'), $transaction->ID())); |
|
204 | 204 | } |
205 | 205 | return $payment; |
206 | 206 | } |
@@ -212,27 +212,27 @@ discard block |
||
212 | 212 | * @param \EEI_Payment $payment |
213 | 213 | * @return \EEI_Payment |
214 | 214 | */ |
215 | - public function check_payment_in_mijireh( EEI_Payment $payment ){ |
|
215 | + public function check_payment_in_mijireh(EEI_Payment $payment) { |
|
216 | 216 | $request_args = array( |
217 | 217 | 'headers' => array( |
218 | - 'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ), |
|
218 | + 'Authorization' => 'Basic '.base64_encode($this->_access_key.':'), |
|
219 | 219 | 'Accept'=>'application/json' |
220 | 220 | ) |
221 | 221 | ); |
222 | 222 | |
223 | 223 | $response = wp_remote_get( |
224 | - $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
224 | + $this->_mijireh_api_orders_url.'/'.$payment->txn_id_chq_nmbr(), |
|
225 | 225 | $request_args |
226 | 226 | ); |
227 | 227 | |
228 | 228 | $this->log( |
229 | - array( 'get payment status request_args' => $request_args, 'response' => $response ), |
|
229 | + array('get payment status request_args' => $request_args, 'response' => $response), |
|
230 | 230 | $payment |
231 | 231 | ); |
232 | 232 | // validate response |
233 | - $response_body = isset( $response[ 'body' ] ) ? json_decode( $response[ 'body' ] ) : ''; |
|
234 | - if( $response && $response_body ){ |
|
235 | - switch( $response_body->status ){ |
|
233 | + $response_body = isset($response['body']) ? json_decode($response['body']) : ''; |
|
234 | + if ($response && $response_body) { |
|
235 | + switch ($response_body->status) { |
|
236 | 236 | case 'paid': |
237 | 237 | $payment->set_status($this->_pay_model->approved_status()); |
238 | 238 | break; |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | } |
245 | 245 | |
246 | 246 | } else { |
247 | - $payment->set_gateway_response( __( 'Response from Mijireh could not be understood.', 'event_espresso' ) ); |
|
248 | - $payment->set_details( $response ); |
|
249 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
247 | + $payment->set_gateway_response(__('Response from Mijireh could not be understood.', 'event_espresso')); |
|
248 | + $payment->set_details($response); |
|
249 | + $payment->set_status($this->_pay_model->failed_status()); |
|
250 | 250 | } |
251 | 251 | // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage |
252 | 252 | // $payment->set_status( $this->_pay_model->pending_status() ); |
@@ -18,27 +18,27 @@ |
||
18 | 18 | abstract class FormatterBase implements FormatterInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * Recursively applies the formatting to all VALUES in this multi-dimensional array |
|
23 | - * |
|
24 | - * @param array $input |
|
25 | - * @return array |
|
26 | - * @throws InvalidDataTypeException if $input is not an array |
|
27 | - */ |
|
28 | - public function formatArray($input) |
|
29 | - { |
|
30 | - if (! is_array($input)) { |
|
31 | - throw new InvalidDataTypeException('input', $input, 'array'); |
|
32 | - } |
|
33 | - //we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
|
34 | - $formatter = $this; |
|
35 | - array_walk_recursive( |
|
36 | - $input, |
|
37 | - function (&$value, $key) use ($formatter) { |
|
38 | - $value = $formatter->format($value); |
|
39 | - } |
|
40 | - ); |
|
41 | - return $input; |
|
42 | - }} |
|
21 | + /** |
|
22 | + * Recursively applies the formatting to all VALUES in this multi-dimensional array |
|
23 | + * |
|
24 | + * @param array $input |
|
25 | + * @return array |
|
26 | + * @throws InvalidDataTypeException if $input is not an array |
|
27 | + */ |
|
28 | + public function formatArray($input) |
|
29 | + { |
|
30 | + if (! is_array($input)) { |
|
31 | + throw new InvalidDataTypeException('input', $input, 'array'); |
|
32 | + } |
|
33 | + //we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
|
34 | + $formatter = $this; |
|
35 | + array_walk_recursive( |
|
36 | + $input, |
|
37 | + function (&$value, $key) use ($formatter) { |
|
38 | + $value = $formatter->format($value); |
|
39 | + } |
|
40 | + ); |
|
41 | + return $input; |
|
42 | + }} |
|
43 | 43 | // End of file FormatterBase.php |
44 | 44 | // Location: core\services\formatters/FormatterBase.php |
45 | 45 | \ No newline at end of file |
@@ -27,14 +27,14 @@ |
||
27 | 27 | */ |
28 | 28 | public function formatArray($input) |
29 | 29 | { |
30 | - if (! is_array($input)) { |
|
30 | + if ( ! is_array($input)) { |
|
31 | 31 | throw new InvalidDataTypeException('input', $input, 'array'); |
32 | 32 | } |
33 | 33 | //we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
34 | 34 | $formatter = $this; |
35 | 35 | array_walk_recursive( |
36 | 36 | $input, |
37 | - function (&$value, $key) use ($formatter) { |
|
37 | + function(&$value, $key) use ($formatter) { |
|
38 | 38 | $value = $formatter->format($value); |
39 | 39 | } |
40 | 40 | ); |
@@ -18,807 +18,807 @@ |
||
18 | 18 | class EED_Core_Rest_Api extends \EED_Module |
19 | 19 | { |
20 | 20 | |
21 | - const ee_api_namespace = 'ee/v'; |
|
21 | + const ee_api_namespace = 'ee/v'; |
|
22 | 22 | |
23 | - const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
23 | + const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
24 | 24 | |
25 | - const saved_routes_option_names = 'ee_core_routes'; |
|
25 | + const saved_routes_option_names = 'ee_core_routes'; |
|
26 | 26 | |
27 | - /** |
|
28 | - * string used in _links response bodies to make them globally unique. |
|
29 | - * |
|
30 | - * @see http://v2.wp-api.org/extending/linking/ |
|
31 | - */ |
|
32 | - const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
27 | + /** |
|
28 | + * string used in _links response bodies to make them globally unique. |
|
29 | + * |
|
30 | + * @see http://v2.wp-api.org/extending/linking/ |
|
31 | + */ |
|
32 | + const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var Calculated_Model_Fields |
|
36 | - */ |
|
37 | - protected static $_field_calculator = null; |
|
34 | + /** |
|
35 | + * @var Calculated_Model_Fields |
|
36 | + */ |
|
37 | + protected static $_field_calculator = null; |
|
38 | 38 | |
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @return EED_Core_Rest_Api |
|
43 | - */ |
|
44 | - public static function instance() |
|
45 | - { |
|
46 | - self::$_field_calculator = new Calculated_Model_Fields(); |
|
47 | - return parent::get_instance(__CLASS__); |
|
48 | - } |
|
41 | + /** |
|
42 | + * @return EED_Core_Rest_Api |
|
43 | + */ |
|
44 | + public static function instance() |
|
45 | + { |
|
46 | + self::$_field_calculator = new Calculated_Model_Fields(); |
|
47 | + return parent::get_instance(__CLASS__); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
54 | - * |
|
55 | - * @access public |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public static function set_hooks() |
|
59 | - { |
|
60 | - self::set_hooks_both(); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
67 | - * |
|
68 | - * @access public |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public static function set_hooks_admin() |
|
72 | - { |
|
73 | - self::set_hooks_both(); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - public static function set_hooks_both() |
|
79 | - { |
|
80 | - add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10); |
|
81 | - add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5); |
|
82 | - add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2); |
|
83 | - add_filter('rest_index', |
|
84 | - array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index')); |
|
85 | - EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * sets up hooks which only need to be included as part of REST API requests; |
|
92 | - * other requests like to the frontend or admin etc don't need them |
|
93 | - */ |
|
94 | - public static function set_hooks_rest_api() |
|
95 | - { |
|
96 | - //set hooks which account for changes made to the API |
|
97 | - EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * public wrapper of _set_hooks_for_changes. |
|
104 | - * Loads all the hooks which make requests to old versions of the API |
|
105 | - * appear the same as they always did |
|
106 | - */ |
|
107 | - public static function set_hooks_for_changes() |
|
108 | - { |
|
109 | - self::_set_hooks_for_changes(); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * Loads all the hooks which make requests to old versions of the API |
|
120 | - * appear the same as they always did |
|
121 | - */ |
|
122 | - protected static function _set_hooks_for_changes() |
|
123 | - { |
|
124 | - $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false); |
|
125 | - foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
126 | - //ignore the base parent class |
|
127 | - if ($classname_in_namespace === 'Changes_In_Base') { |
|
128 | - continue; |
|
129 | - } |
|
130 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
131 | - if (class_exists($full_classname)) { |
|
132 | - $instance_of_class = new $full_classname; |
|
133 | - if ($instance_of_class instanceof Changes_In_Base) { |
|
134 | - $instance_of_class->set_hooks(); |
|
135 | - } |
|
136 | - } |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
144 | - * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
145 | - */ |
|
146 | - public static function register_routes() |
|
147 | - { |
|
148 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
149 | - foreach ($relative_urls as $endpoint => $routes) { |
|
150 | - foreach ($routes as $route) { |
|
151 | - $route_args = array( |
|
152 | - array( |
|
153 | - 'callback' => $route['callback'], |
|
154 | - 'methods' => $route['methods'], |
|
155 | - 'args' => isset($route['args']) ? $route['args'] : array(), |
|
156 | - ) |
|
157 | - ); |
|
158 | - if (isset($route['schema_callback'])) { |
|
159 | - $model_name = isset($route['schema_callback'][0]) |
|
160 | - ? $route['schema_callback'][0] |
|
161 | - : ''; |
|
162 | - $version = isset( $route['schema_callback'][1]) |
|
163 | - ? $route['schema_callback'][1] |
|
164 | - : ''; |
|
165 | - if (! empty($model_name) && ! empty($version)) { |
|
166 | - $route_args['schema'] = function () use ($model_name, $version) { |
|
167 | - return ModelRead::handle_schema_request( |
|
168 | - $model_name, |
|
169 | - $version |
|
170 | - ); |
|
171 | - }; |
|
172 | - } |
|
173 | - } |
|
174 | - register_rest_route( |
|
175 | - $namespace, |
|
176 | - $endpoint, |
|
177 | - $route_args |
|
178 | - ); |
|
179 | - } |
|
180 | - } |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Checks if there was a version change or something that merits invalidating the cached |
|
188 | - * route data. If so, invalidates the cached route data so that it gets refreshed |
|
189 | - * next time the WP API is used |
|
190 | - */ |
|
191 | - public static function invalidate_cached_route_data_on_version_change() |
|
192 | - { |
|
193 | - if (EE_System::instance()->detect_req_type() != EE_System::req_type_normal) { |
|
194 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
195 | - } |
|
196 | - foreach (EE_Registry::instance()->addons as $addon) { |
|
197 | - if ($addon instanceof EE_Addon && $addon->detect_req_type() != EE_System::req_type_normal) { |
|
198 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * Removes the cached route data so it will get refreshed next time the WP API is used |
|
207 | - */ |
|
208 | - public static function invalidate_cached_route_data() |
|
209 | - { |
|
210 | - //delete the saved EE REST API routes |
|
211 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
212 | - delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * Gets the EE route data |
|
220 | - * |
|
221 | - * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
222 | - * @type string|array $callback |
|
223 | - * @type string $methods |
|
224 | - * @type boolean $hidden_endpoint |
|
225 | - * } |
|
226 | - */ |
|
227 | - public static function get_ee_route_data() |
|
228 | - { |
|
229 | - $ee_routes = array(); |
|
230 | - foreach (self::versions_served() as $version => $hidden_endpoints) { |
|
231 | - $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version($version, |
|
232 | - $hidden_endpoints); |
|
233 | - } |
|
234 | - return $ee_routes; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Gets the EE route data from the wp options if it exists already, |
|
241 | - * otherwise re-generates it and saves it to the option |
|
242 | - * |
|
243 | - * @param string $version |
|
244 | - * @param boolean $hidden_endpoints |
|
245 | - * @return array |
|
246 | - */ |
|
247 | - protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
248 | - { |
|
249 | - $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
250 | - if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
251 | - $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
252 | - } |
|
253 | - return $ee_routes; |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Saves the EE REST API route data to a wp option and returns it |
|
260 | - * |
|
261 | - * @param string $version |
|
262 | - * @param boolean $hidden_endpoints |
|
263 | - * @return mixed|null|void |
|
264 | - */ |
|
265 | - protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
266 | - { |
|
267 | - $instance = self::instance(); |
|
268 | - $routes = apply_filters( |
|
269 | - 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
270 | - array_replace_recursive( |
|
271 | - $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
272 | - $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
273 | - $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
274 | - $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
275 | - ) |
|
276 | - ); |
|
277 | - $option_name = self::saved_routes_option_names . $version; |
|
278 | - if (get_option($option_name)) { |
|
279 | - update_option($option_name, $routes, true); |
|
280 | - } else { |
|
281 | - add_option($option_name, $routes, null, 'no'); |
|
282 | - } |
|
283 | - return $routes; |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * Calculates all the EE routes and saves it to a wordpress option so we don't |
|
290 | - * need to calculate it on every request |
|
291 | - * |
|
292 | - * @deprecated since version 4.9.1 |
|
293 | - * @return void |
|
294 | - */ |
|
295 | - public static function save_ee_routes() |
|
296 | - { |
|
297 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
298 | - $instance = self::instance(); |
|
299 | - $routes = apply_filters( |
|
300 | - 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
301 | - array_replace_recursive( |
|
302 | - $instance->_register_config_routes(), |
|
303 | - $instance->_register_meta_routes(), |
|
304 | - $instance->_register_model_routes(), |
|
305 | - $instance->_register_rpc_routes() |
|
306 | - ) |
|
307 | - ); |
|
308 | - update_option(self::saved_routes_option_names, $routes, true); |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * Gets all the route information relating to EE models |
|
316 | - * |
|
317 | - * @return array @see get_ee_route_data |
|
318 | - * @deprecated since version 4.9.1 |
|
319 | - */ |
|
320 | - protected function _register_model_routes() |
|
321 | - { |
|
322 | - $model_routes = array(); |
|
323 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
324 | - $model_routes[EED_Core_Rest_Api::ee_api_namespace |
|
325 | - . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
326 | - } |
|
327 | - return $model_routes; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * Gets the route data for EE models in the specified version |
|
334 | - * |
|
335 | - * @param string $version |
|
336 | - * @param boolean $hidden_endpoint |
|
337 | - * @return array |
|
338 | - */ |
|
339 | - protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
340 | - { |
|
341 | - $model_version_info = new Model_Version_Info($version); |
|
342 | - $models_to_register = apply_filters( |
|
343 | - 'FHEE__EED_Core_REST_API___register_model_routes', |
|
344 | - $model_version_info->models_for_requested_version() |
|
345 | - ); |
|
346 | - //let's not bother having endpoints for extra metas |
|
347 | - unset($models_to_register['Extra_Meta']); |
|
348 | - unset($models_to_register['Extra_Join']); |
|
349 | - $model_routes = array(); |
|
350 | - foreach ($models_to_register as $model_name => $model_classname) { |
|
351 | - $model = \EE_Registry::instance()->load_model($model_name); |
|
352 | - |
|
353 | - //if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
354 | - if (! $model instanceof EEM_Base) { |
|
355 | - continue; |
|
356 | - } |
|
357 | - |
|
358 | - //yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
359 | - $plural_model_route = EEH_Inflector::pluralize_and_lower($model_name); |
|
360 | - $singular_model_route = $plural_model_route . '/(?P<id>\d+)'; |
|
361 | - $model_routes[$plural_model_route] = array( |
|
362 | - array( |
|
363 | - 'callback' => array( |
|
364 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
365 | - 'handle_request_get_all', |
|
366 | - ), |
|
367 | - 'methods' => WP_REST_Server::READABLE, |
|
368 | - 'hidden_endpoint' => $hidden_endpoint, |
|
369 | - 'args' => $this->_get_read_query_params($model, $version), |
|
370 | - '_links' => array( |
|
371 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
372 | - ), |
|
373 | - 'schema_callback' => array($model_name, $version) |
|
374 | - ), |
|
375 | - // array( |
|
376 | - // 'callback' => array( |
|
377 | - // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
378 | - // 'handle_request_create_one' ), |
|
379 | - // 'methods' => WP_REST_Server::CREATABLE, |
|
380 | - // 'hidden_endpoint' => $hidden_endpoint |
|
381 | - // ) |
|
382 | - ); |
|
383 | - $model_routes[$singular_model_route] = array( |
|
384 | - array( |
|
385 | - 'callback' => array( |
|
386 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
387 | - 'handle_request_get_one', |
|
388 | - ), |
|
389 | - 'methods' => WP_REST_Server::READABLE, |
|
390 | - 'hidden_endpoint' => $hidden_endpoint, |
|
391 | - 'args' => $this->_get_response_selection_query_params($model, $version), |
|
392 | - ), |
|
393 | - // array( |
|
394 | - // 'callback' => array( |
|
395 | - // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
396 | - // 'handle_request_edit_one' ), |
|
397 | - // 'methods' => WP_REST_Server::EDITABLE, |
|
398 | - // 'hidden_endpoint' => $hidden_endpoint |
|
399 | - // ), |
|
400 | - ); |
|
401 | - //@todo: also handle DELETE for a single item |
|
402 | - foreach ($model_version_info->relation_settings($model) as $relation_name => $relation_obj) { |
|
403 | - $related_model_name_endpoint_part = ModelRead::get_related_entity_name( |
|
404 | - $relation_name, |
|
405 | - $relation_obj |
|
406 | - ); |
|
407 | - $model_routes[$singular_model_route . '/' . $related_model_name_endpoint_part] = array( |
|
408 | - array( |
|
409 | - 'callback' => array( |
|
410 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
411 | - 'handle_request_get_related', |
|
412 | - ), |
|
413 | - 'methods' => WP_REST_Server::READABLE, |
|
414 | - 'hidden_endpoint' => $hidden_endpoint, |
|
415 | - 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
416 | - ), |
|
417 | - // array( |
|
418 | - // 'callback' => array( |
|
419 | - // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
420 | - // 'handle_request_create_or_update_related' ), |
|
421 | - // 'methods' => WP_REST_Server::EDITABLE, |
|
422 | - // 'hidden_endpoint' => $hidden_endpoint |
|
423 | - // ) |
|
424 | - ); |
|
425 | - //@todo: handle delete related and possibly remove relation (not sure hwo to distinguish) |
|
426 | - } |
|
427 | - } |
|
428 | - return $model_routes; |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
435 | - * routes that don't conform to the traditional REST CRUD-style). |
|
436 | - * |
|
437 | - * @deprecated since 4.9.1 |
|
438 | - */ |
|
439 | - protected function _register_rpc_routes() |
|
440 | - { |
|
441 | - $routes = array(); |
|
442 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
443 | - $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version($version, |
|
444 | - $hidden_endpoint); |
|
445 | - } |
|
446 | - return $routes; |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * @param string $version |
|
453 | - * @param boolean $hidden_endpoint |
|
454 | - * @return array |
|
455 | - */ |
|
456 | - protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
457 | - { |
|
458 | - $this_versions_routes = array(); |
|
459 | - //checkin endpoint |
|
460 | - $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array( |
|
461 | - array( |
|
462 | - 'callback' => array( |
|
463 | - 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
464 | - 'handle_request_toggle_checkin', |
|
465 | - ), |
|
466 | - 'methods' => WP_REST_Server::CREATABLE, |
|
467 | - 'hidden_endpoint' => $hidden_endpoint, |
|
468 | - 'args' => array( |
|
469 | - 'force' => array( |
|
470 | - 'required' => false, |
|
471 | - 'default' => false, |
|
472 | - 'description' => __('Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
473 | - 'event_espresso'), |
|
474 | - ), |
|
475 | - ), |
|
476 | - ), |
|
477 | - ); |
|
478 | - return apply_filters( |
|
479 | - 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
480 | - $this_versions_routes, |
|
481 | - $version, |
|
482 | - $hidden_endpoint |
|
483 | - ); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * Gets the query params that can be used when request one or many |
|
490 | - * |
|
491 | - * @param EEM_Base $model |
|
492 | - * @param string $version |
|
493 | - * @return array |
|
494 | - */ |
|
495 | - protected function _get_response_selection_query_params(\EEM_Base $model, $version) |
|
496 | - { |
|
497 | - return apply_filters( |
|
498 | - 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
499 | - array( |
|
500 | - 'include' => array( |
|
501 | - 'required' => false, |
|
502 | - 'default' => '*', |
|
503 | - ), |
|
504 | - 'calculate' => array( |
|
505 | - 'required' => false, |
|
506 | - 'default' => '', |
|
507 | - 'enum' => self::$_field_calculator->retrieve_calculated_fields_for_model($model), |
|
508 | - ), |
|
509 | - ), |
|
510 | - $model, |
|
511 | - $version |
|
512 | - ); |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * Gets info about reading query params that are acceptable |
|
519 | - * |
|
520 | - * @param \EEM_Base $model eg 'Event' or 'Venue' |
|
521 | - * @param string $version |
|
522 | - * @return array describing the args acceptable when querying this model |
|
523 | - * @throws \EE_Error |
|
524 | - */ |
|
525 | - protected function _get_read_query_params(\EEM_Base $model, $version) |
|
526 | - { |
|
527 | - $default_orderby = array(); |
|
528 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
529 | - $default_orderby[$key_field->get_name()] = 'ASC'; |
|
530 | - } |
|
531 | - return array_merge( |
|
532 | - $this->_get_response_selection_query_params($model, $version), |
|
533 | - array( |
|
534 | - 'where' => array( |
|
535 | - 'required' => false, |
|
536 | - 'default' => array(), |
|
537 | - ), |
|
538 | - 'limit' => array( |
|
539 | - 'required' => false, |
|
540 | - 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
541 | - ), |
|
542 | - 'order_by' => array( |
|
543 | - 'required' => false, |
|
544 | - 'default' => $default_orderby, |
|
545 | - ), |
|
546 | - 'group_by' => array( |
|
547 | - 'required' => false, |
|
548 | - 'default' => null, |
|
549 | - ), |
|
550 | - 'having' => array( |
|
551 | - 'required' => false, |
|
552 | - 'default' => null, |
|
553 | - ), |
|
554 | - 'caps' => array( |
|
555 | - 'required' => false, |
|
556 | - 'default' => EEM_Base::caps_read, |
|
557 | - ), |
|
558 | - ) |
|
559 | - ); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * Gets routes for the config |
|
566 | - * |
|
567 | - * @return array @see _register_model_routes |
|
568 | - * @deprecated since version 4.9.1 |
|
569 | - */ |
|
570 | - protected function _register_config_routes() |
|
571 | - { |
|
572 | - $config_routes = array(); |
|
573 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
574 | - $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version($version, |
|
575 | - $hidden_endpoint); |
|
576 | - } |
|
577 | - return $config_routes; |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * Gets routes for the config for the specified version |
|
584 | - * |
|
585 | - * @param string $version |
|
586 | - * @param boolean $hidden_endpoint |
|
587 | - * @return array |
|
588 | - */ |
|
589 | - protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
590 | - { |
|
591 | - return array( |
|
592 | - 'config' => array( |
|
593 | - array( |
|
594 | - 'callback' => array( |
|
595 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
596 | - 'handle_request', |
|
597 | - ), |
|
598 | - 'methods' => WP_REST_Server::READABLE, |
|
599 | - 'hidden_endpoint' => $hidden_endpoint, |
|
600 | - ), |
|
601 | - ), |
|
602 | - 'site_info' => array( |
|
603 | - array( |
|
604 | - 'callback' => array( |
|
605 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
606 | - 'handle_request_site_info', |
|
607 | - ), |
|
608 | - 'methods' => WP_REST_Server::READABLE, |
|
609 | - 'hidden_endpoint' => $hidden_endpoint, |
|
610 | - ), |
|
611 | - ), |
|
612 | - ); |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - |
|
617 | - /** |
|
618 | - * Gets the meta info routes |
|
619 | - * |
|
620 | - * @return array @see _register_model_routes |
|
621 | - * @deprecated since version 4.9.1 |
|
622 | - */ |
|
623 | - protected function _register_meta_routes() |
|
624 | - { |
|
625 | - $meta_routes = array(); |
|
626 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
627 | - $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version($version, |
|
628 | - $hidden_endpoint); |
|
629 | - } |
|
630 | - return $meta_routes; |
|
631 | - } |
|
632 | - |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * @param string $version |
|
637 | - * @param boolean $hidden_endpoint |
|
638 | - * @return array |
|
639 | - */ |
|
640 | - protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
641 | - { |
|
642 | - return array( |
|
643 | - 'resources' => array( |
|
644 | - array( |
|
645 | - 'callback' => array( |
|
646 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
647 | - 'handle_request_models_meta', |
|
648 | - ), |
|
649 | - 'methods' => WP_REST_Server::READABLE, |
|
650 | - 'hidden_endpoint' => $hidden_endpoint, |
|
651 | - ), |
|
652 | - ), |
|
653 | - ); |
|
654 | - } |
|
655 | - |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * Tries to hide old 4.6 endpoints from the |
|
660 | - * |
|
661 | - * @param array $route_data |
|
662 | - * @return array |
|
663 | - */ |
|
664 | - public static function hide_old_endpoints($route_data) |
|
665 | - { |
|
666 | - //allow API clients to override which endpoints get hidden, in case |
|
667 | - //they want to discover particular endpoints |
|
668 | - //also, we don't have access to the request so we have to just grab it from the superglobal |
|
669 | - $force_show_ee_namespace = ltrim( |
|
670 | - EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''), |
|
671 | - '/' |
|
672 | - ); |
|
673 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
674 | - foreach ($relative_urls as $endpoint => $routes) { |
|
675 | - foreach ($routes as $route) { |
|
676 | - //by default, hide "hidden_endpoint"s, unless the request indicates |
|
677 | - //to $force_show_ee_namespace, in which case only show that one |
|
678 | - //namespace's endpoints (and hide all others) |
|
679 | - if (($route['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
680 | - || ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
681 | - ) { |
|
682 | - $full_route = '/' . ltrim($namespace, '/') . '/' . ltrim($endpoint, '/'); |
|
683 | - unset($route_data[$full_route]); |
|
684 | - } |
|
685 | - } |
|
686 | - } |
|
687 | - } |
|
688 | - return $route_data; |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * Returns an array describing which versions of core support serving requests for. |
|
695 | - * Keys are core versions' major and minor version, and values are the |
|
696 | - * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
697 | - * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
698 | - * the answers table entirely, in which case it would be very difficult for |
|
699 | - * it to serve 4.6-style responses. |
|
700 | - * Versions of core that are missing from this array are unknowns. |
|
701 | - * previous ver |
|
702 | - * |
|
703 | - * @return array |
|
704 | - */ |
|
705 | - public static function version_compatibilities() |
|
706 | - { |
|
707 | - return apply_filters( |
|
708 | - 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
709 | - array( |
|
710 | - '4.8.29' => '4.8.29', |
|
711 | - '4.8.33' => '4.8.29', |
|
712 | - '4.8.34' => '4.8.29', |
|
713 | - '4.8.36' => '4.8.29', |
|
714 | - ) |
|
715 | - ); |
|
716 | - } |
|
717 | - |
|
718 | - |
|
719 | - |
|
720 | - /** |
|
721 | - * Gets the latest API version served. Eg if there |
|
722 | - * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
723 | - * we are on core version 4.8.34, it will return the string "4.8.32" |
|
724 | - * |
|
725 | - * @return string |
|
726 | - */ |
|
727 | - public static function latest_rest_api_version() |
|
728 | - { |
|
729 | - $versions_served = \EED_Core_Rest_Api::versions_served(); |
|
730 | - $versions_served_keys = array_keys($versions_served); |
|
731 | - return end($versions_served_keys); |
|
732 | - } |
|
733 | - |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
738 | - * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
739 | - * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
740 | - * We also indicate whether or not this version should be put in the index or not |
|
741 | - * |
|
742 | - * @return array keys are API version numbers (just major and minor numbers), and values |
|
743 | - * are whether or not they should be hidden |
|
744 | - */ |
|
745 | - public static function versions_served() |
|
746 | - { |
|
747 | - $versions_served = array(); |
|
748 | - $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
749 | - $lowest_compatible_version = end($possibly_served_versions); |
|
750 | - reset($possibly_served_versions); |
|
751 | - $versions_served_historically = array_keys($possibly_served_versions); |
|
752 | - $latest_version = end($versions_served_historically); |
|
753 | - reset($versions_served_historically); |
|
754 | - //for each version of core we have ever served: |
|
755 | - foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
756 | - //if it's not above the current core version, and it's compatible with the current version of core |
|
757 | - if ($key_versioned_endpoint == $latest_version) { |
|
758 | - //don't hide the latest version in the index |
|
759 | - $versions_served[$key_versioned_endpoint] = false; |
|
760 | - } else if ( |
|
761 | - $key_versioned_endpoint < EED_Core_Rest_Api::core_version() |
|
762 | - && $key_versioned_endpoint >= $lowest_compatible_version |
|
763 | - ) { |
|
764 | - //include, but hide, previous versions which are still supported |
|
765 | - $versions_served[$key_versioned_endpoint] = true; |
|
766 | - } elseif ( |
|
767 | - apply_filters( |
|
768 | - 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
769 | - false, |
|
770 | - $possibly_served_versions |
|
771 | - ) |
|
772 | - ) { |
|
773 | - //if a version is no longer supported, don't include it in index or list of versions served |
|
774 | - $versions_served[$key_versioned_endpoint] = true; |
|
775 | - } |
|
776 | - } |
|
777 | - return $versions_served; |
|
778 | - } |
|
779 | - |
|
780 | - |
|
781 | - |
|
782 | - /** |
|
783 | - * Gets the major and minor version of EE core's version string |
|
784 | - * |
|
785 | - * @return string |
|
786 | - */ |
|
787 | - public static function core_version() |
|
788 | - { |
|
789 | - return apply_filters('FHEE__EED_Core_REST_API__core_version', |
|
790 | - implode('.', array_slice(explode('.', espresso_version()), 0, 3))); |
|
791 | - } |
|
792 | - |
|
793 | - |
|
794 | - |
|
795 | - /** |
|
796 | - * Gets the default limit that should be used when querying for resources |
|
797 | - * |
|
798 | - * @return int |
|
799 | - */ |
|
800 | - public static function get_default_query_limit() |
|
801 | - { |
|
802 | - //we actually don't use a const because we want folks to always use |
|
803 | - //this method, not the const directly |
|
804 | - return apply_filters( |
|
805 | - 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
806 | - 50 |
|
807 | - ); |
|
808 | - } |
|
809 | - |
|
810 | - |
|
811 | - |
|
812 | - /** |
|
813 | - * run - initial module setup |
|
814 | - * |
|
815 | - * @access public |
|
816 | - * @param WP $WP |
|
817 | - * @return void |
|
818 | - */ |
|
819 | - public function run($WP) |
|
820 | - { |
|
821 | - } |
|
52 | + /** |
|
53 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
54 | + * |
|
55 | + * @access public |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public static function set_hooks() |
|
59 | + { |
|
60 | + self::set_hooks_both(); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
67 | + * |
|
68 | + * @access public |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public static function set_hooks_admin() |
|
72 | + { |
|
73 | + self::set_hooks_both(); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + public static function set_hooks_both() |
|
79 | + { |
|
80 | + add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10); |
|
81 | + add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5); |
|
82 | + add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2); |
|
83 | + add_filter('rest_index', |
|
84 | + array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index')); |
|
85 | + EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * sets up hooks which only need to be included as part of REST API requests; |
|
92 | + * other requests like to the frontend or admin etc don't need them |
|
93 | + */ |
|
94 | + public static function set_hooks_rest_api() |
|
95 | + { |
|
96 | + //set hooks which account for changes made to the API |
|
97 | + EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * public wrapper of _set_hooks_for_changes. |
|
104 | + * Loads all the hooks which make requests to old versions of the API |
|
105 | + * appear the same as they always did |
|
106 | + */ |
|
107 | + public static function set_hooks_for_changes() |
|
108 | + { |
|
109 | + self::_set_hooks_for_changes(); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * Loads all the hooks which make requests to old versions of the API |
|
120 | + * appear the same as they always did |
|
121 | + */ |
|
122 | + protected static function _set_hooks_for_changes() |
|
123 | + { |
|
124 | + $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false); |
|
125 | + foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
126 | + //ignore the base parent class |
|
127 | + if ($classname_in_namespace === 'Changes_In_Base') { |
|
128 | + continue; |
|
129 | + } |
|
130 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
131 | + if (class_exists($full_classname)) { |
|
132 | + $instance_of_class = new $full_classname; |
|
133 | + if ($instance_of_class instanceof Changes_In_Base) { |
|
134 | + $instance_of_class->set_hooks(); |
|
135 | + } |
|
136 | + } |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
144 | + * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
145 | + */ |
|
146 | + public static function register_routes() |
|
147 | + { |
|
148 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
149 | + foreach ($relative_urls as $endpoint => $routes) { |
|
150 | + foreach ($routes as $route) { |
|
151 | + $route_args = array( |
|
152 | + array( |
|
153 | + 'callback' => $route['callback'], |
|
154 | + 'methods' => $route['methods'], |
|
155 | + 'args' => isset($route['args']) ? $route['args'] : array(), |
|
156 | + ) |
|
157 | + ); |
|
158 | + if (isset($route['schema_callback'])) { |
|
159 | + $model_name = isset($route['schema_callback'][0]) |
|
160 | + ? $route['schema_callback'][0] |
|
161 | + : ''; |
|
162 | + $version = isset( $route['schema_callback'][1]) |
|
163 | + ? $route['schema_callback'][1] |
|
164 | + : ''; |
|
165 | + if (! empty($model_name) && ! empty($version)) { |
|
166 | + $route_args['schema'] = function () use ($model_name, $version) { |
|
167 | + return ModelRead::handle_schema_request( |
|
168 | + $model_name, |
|
169 | + $version |
|
170 | + ); |
|
171 | + }; |
|
172 | + } |
|
173 | + } |
|
174 | + register_rest_route( |
|
175 | + $namespace, |
|
176 | + $endpoint, |
|
177 | + $route_args |
|
178 | + ); |
|
179 | + } |
|
180 | + } |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Checks if there was a version change or something that merits invalidating the cached |
|
188 | + * route data. If so, invalidates the cached route data so that it gets refreshed |
|
189 | + * next time the WP API is used |
|
190 | + */ |
|
191 | + public static function invalidate_cached_route_data_on_version_change() |
|
192 | + { |
|
193 | + if (EE_System::instance()->detect_req_type() != EE_System::req_type_normal) { |
|
194 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
195 | + } |
|
196 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
197 | + if ($addon instanceof EE_Addon && $addon->detect_req_type() != EE_System::req_type_normal) { |
|
198 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * Removes the cached route data so it will get refreshed next time the WP API is used |
|
207 | + */ |
|
208 | + public static function invalidate_cached_route_data() |
|
209 | + { |
|
210 | + //delete the saved EE REST API routes |
|
211 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
212 | + delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * Gets the EE route data |
|
220 | + * |
|
221 | + * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
222 | + * @type string|array $callback |
|
223 | + * @type string $methods |
|
224 | + * @type boolean $hidden_endpoint |
|
225 | + * } |
|
226 | + */ |
|
227 | + public static function get_ee_route_data() |
|
228 | + { |
|
229 | + $ee_routes = array(); |
|
230 | + foreach (self::versions_served() as $version => $hidden_endpoints) { |
|
231 | + $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version($version, |
|
232 | + $hidden_endpoints); |
|
233 | + } |
|
234 | + return $ee_routes; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Gets the EE route data from the wp options if it exists already, |
|
241 | + * otherwise re-generates it and saves it to the option |
|
242 | + * |
|
243 | + * @param string $version |
|
244 | + * @param boolean $hidden_endpoints |
|
245 | + * @return array |
|
246 | + */ |
|
247 | + protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
248 | + { |
|
249 | + $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
250 | + if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
251 | + $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
252 | + } |
|
253 | + return $ee_routes; |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Saves the EE REST API route data to a wp option and returns it |
|
260 | + * |
|
261 | + * @param string $version |
|
262 | + * @param boolean $hidden_endpoints |
|
263 | + * @return mixed|null|void |
|
264 | + */ |
|
265 | + protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
266 | + { |
|
267 | + $instance = self::instance(); |
|
268 | + $routes = apply_filters( |
|
269 | + 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
270 | + array_replace_recursive( |
|
271 | + $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
272 | + $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
273 | + $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
274 | + $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
275 | + ) |
|
276 | + ); |
|
277 | + $option_name = self::saved_routes_option_names . $version; |
|
278 | + if (get_option($option_name)) { |
|
279 | + update_option($option_name, $routes, true); |
|
280 | + } else { |
|
281 | + add_option($option_name, $routes, null, 'no'); |
|
282 | + } |
|
283 | + return $routes; |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * Calculates all the EE routes and saves it to a wordpress option so we don't |
|
290 | + * need to calculate it on every request |
|
291 | + * |
|
292 | + * @deprecated since version 4.9.1 |
|
293 | + * @return void |
|
294 | + */ |
|
295 | + public static function save_ee_routes() |
|
296 | + { |
|
297 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
298 | + $instance = self::instance(); |
|
299 | + $routes = apply_filters( |
|
300 | + 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
301 | + array_replace_recursive( |
|
302 | + $instance->_register_config_routes(), |
|
303 | + $instance->_register_meta_routes(), |
|
304 | + $instance->_register_model_routes(), |
|
305 | + $instance->_register_rpc_routes() |
|
306 | + ) |
|
307 | + ); |
|
308 | + update_option(self::saved_routes_option_names, $routes, true); |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * Gets all the route information relating to EE models |
|
316 | + * |
|
317 | + * @return array @see get_ee_route_data |
|
318 | + * @deprecated since version 4.9.1 |
|
319 | + */ |
|
320 | + protected function _register_model_routes() |
|
321 | + { |
|
322 | + $model_routes = array(); |
|
323 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
324 | + $model_routes[EED_Core_Rest_Api::ee_api_namespace |
|
325 | + . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
326 | + } |
|
327 | + return $model_routes; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * Gets the route data for EE models in the specified version |
|
334 | + * |
|
335 | + * @param string $version |
|
336 | + * @param boolean $hidden_endpoint |
|
337 | + * @return array |
|
338 | + */ |
|
339 | + protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
340 | + { |
|
341 | + $model_version_info = new Model_Version_Info($version); |
|
342 | + $models_to_register = apply_filters( |
|
343 | + 'FHEE__EED_Core_REST_API___register_model_routes', |
|
344 | + $model_version_info->models_for_requested_version() |
|
345 | + ); |
|
346 | + //let's not bother having endpoints for extra metas |
|
347 | + unset($models_to_register['Extra_Meta']); |
|
348 | + unset($models_to_register['Extra_Join']); |
|
349 | + $model_routes = array(); |
|
350 | + foreach ($models_to_register as $model_name => $model_classname) { |
|
351 | + $model = \EE_Registry::instance()->load_model($model_name); |
|
352 | + |
|
353 | + //if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
354 | + if (! $model instanceof EEM_Base) { |
|
355 | + continue; |
|
356 | + } |
|
357 | + |
|
358 | + //yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
359 | + $plural_model_route = EEH_Inflector::pluralize_and_lower($model_name); |
|
360 | + $singular_model_route = $plural_model_route . '/(?P<id>\d+)'; |
|
361 | + $model_routes[$plural_model_route] = array( |
|
362 | + array( |
|
363 | + 'callback' => array( |
|
364 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
365 | + 'handle_request_get_all', |
|
366 | + ), |
|
367 | + 'methods' => WP_REST_Server::READABLE, |
|
368 | + 'hidden_endpoint' => $hidden_endpoint, |
|
369 | + 'args' => $this->_get_read_query_params($model, $version), |
|
370 | + '_links' => array( |
|
371 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
372 | + ), |
|
373 | + 'schema_callback' => array($model_name, $version) |
|
374 | + ), |
|
375 | + // array( |
|
376 | + // 'callback' => array( |
|
377 | + // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
378 | + // 'handle_request_create_one' ), |
|
379 | + // 'methods' => WP_REST_Server::CREATABLE, |
|
380 | + // 'hidden_endpoint' => $hidden_endpoint |
|
381 | + // ) |
|
382 | + ); |
|
383 | + $model_routes[$singular_model_route] = array( |
|
384 | + array( |
|
385 | + 'callback' => array( |
|
386 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
387 | + 'handle_request_get_one', |
|
388 | + ), |
|
389 | + 'methods' => WP_REST_Server::READABLE, |
|
390 | + 'hidden_endpoint' => $hidden_endpoint, |
|
391 | + 'args' => $this->_get_response_selection_query_params($model, $version), |
|
392 | + ), |
|
393 | + // array( |
|
394 | + // 'callback' => array( |
|
395 | + // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
396 | + // 'handle_request_edit_one' ), |
|
397 | + // 'methods' => WP_REST_Server::EDITABLE, |
|
398 | + // 'hidden_endpoint' => $hidden_endpoint |
|
399 | + // ), |
|
400 | + ); |
|
401 | + //@todo: also handle DELETE for a single item |
|
402 | + foreach ($model_version_info->relation_settings($model) as $relation_name => $relation_obj) { |
|
403 | + $related_model_name_endpoint_part = ModelRead::get_related_entity_name( |
|
404 | + $relation_name, |
|
405 | + $relation_obj |
|
406 | + ); |
|
407 | + $model_routes[$singular_model_route . '/' . $related_model_name_endpoint_part] = array( |
|
408 | + array( |
|
409 | + 'callback' => array( |
|
410 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
411 | + 'handle_request_get_related', |
|
412 | + ), |
|
413 | + 'methods' => WP_REST_Server::READABLE, |
|
414 | + 'hidden_endpoint' => $hidden_endpoint, |
|
415 | + 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
416 | + ), |
|
417 | + // array( |
|
418 | + // 'callback' => array( |
|
419 | + // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
420 | + // 'handle_request_create_or_update_related' ), |
|
421 | + // 'methods' => WP_REST_Server::EDITABLE, |
|
422 | + // 'hidden_endpoint' => $hidden_endpoint |
|
423 | + // ) |
|
424 | + ); |
|
425 | + //@todo: handle delete related and possibly remove relation (not sure hwo to distinguish) |
|
426 | + } |
|
427 | + } |
|
428 | + return $model_routes; |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
435 | + * routes that don't conform to the traditional REST CRUD-style). |
|
436 | + * |
|
437 | + * @deprecated since 4.9.1 |
|
438 | + */ |
|
439 | + protected function _register_rpc_routes() |
|
440 | + { |
|
441 | + $routes = array(); |
|
442 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
443 | + $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version($version, |
|
444 | + $hidden_endpoint); |
|
445 | + } |
|
446 | + return $routes; |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * @param string $version |
|
453 | + * @param boolean $hidden_endpoint |
|
454 | + * @return array |
|
455 | + */ |
|
456 | + protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
457 | + { |
|
458 | + $this_versions_routes = array(); |
|
459 | + //checkin endpoint |
|
460 | + $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array( |
|
461 | + array( |
|
462 | + 'callback' => array( |
|
463 | + 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
464 | + 'handle_request_toggle_checkin', |
|
465 | + ), |
|
466 | + 'methods' => WP_REST_Server::CREATABLE, |
|
467 | + 'hidden_endpoint' => $hidden_endpoint, |
|
468 | + 'args' => array( |
|
469 | + 'force' => array( |
|
470 | + 'required' => false, |
|
471 | + 'default' => false, |
|
472 | + 'description' => __('Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
473 | + 'event_espresso'), |
|
474 | + ), |
|
475 | + ), |
|
476 | + ), |
|
477 | + ); |
|
478 | + return apply_filters( |
|
479 | + 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
480 | + $this_versions_routes, |
|
481 | + $version, |
|
482 | + $hidden_endpoint |
|
483 | + ); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * Gets the query params that can be used when request one or many |
|
490 | + * |
|
491 | + * @param EEM_Base $model |
|
492 | + * @param string $version |
|
493 | + * @return array |
|
494 | + */ |
|
495 | + protected function _get_response_selection_query_params(\EEM_Base $model, $version) |
|
496 | + { |
|
497 | + return apply_filters( |
|
498 | + 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
499 | + array( |
|
500 | + 'include' => array( |
|
501 | + 'required' => false, |
|
502 | + 'default' => '*', |
|
503 | + ), |
|
504 | + 'calculate' => array( |
|
505 | + 'required' => false, |
|
506 | + 'default' => '', |
|
507 | + 'enum' => self::$_field_calculator->retrieve_calculated_fields_for_model($model), |
|
508 | + ), |
|
509 | + ), |
|
510 | + $model, |
|
511 | + $version |
|
512 | + ); |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * Gets info about reading query params that are acceptable |
|
519 | + * |
|
520 | + * @param \EEM_Base $model eg 'Event' or 'Venue' |
|
521 | + * @param string $version |
|
522 | + * @return array describing the args acceptable when querying this model |
|
523 | + * @throws \EE_Error |
|
524 | + */ |
|
525 | + protected function _get_read_query_params(\EEM_Base $model, $version) |
|
526 | + { |
|
527 | + $default_orderby = array(); |
|
528 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
529 | + $default_orderby[$key_field->get_name()] = 'ASC'; |
|
530 | + } |
|
531 | + return array_merge( |
|
532 | + $this->_get_response_selection_query_params($model, $version), |
|
533 | + array( |
|
534 | + 'where' => array( |
|
535 | + 'required' => false, |
|
536 | + 'default' => array(), |
|
537 | + ), |
|
538 | + 'limit' => array( |
|
539 | + 'required' => false, |
|
540 | + 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
541 | + ), |
|
542 | + 'order_by' => array( |
|
543 | + 'required' => false, |
|
544 | + 'default' => $default_orderby, |
|
545 | + ), |
|
546 | + 'group_by' => array( |
|
547 | + 'required' => false, |
|
548 | + 'default' => null, |
|
549 | + ), |
|
550 | + 'having' => array( |
|
551 | + 'required' => false, |
|
552 | + 'default' => null, |
|
553 | + ), |
|
554 | + 'caps' => array( |
|
555 | + 'required' => false, |
|
556 | + 'default' => EEM_Base::caps_read, |
|
557 | + ), |
|
558 | + ) |
|
559 | + ); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * Gets routes for the config |
|
566 | + * |
|
567 | + * @return array @see _register_model_routes |
|
568 | + * @deprecated since version 4.9.1 |
|
569 | + */ |
|
570 | + protected function _register_config_routes() |
|
571 | + { |
|
572 | + $config_routes = array(); |
|
573 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
574 | + $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version($version, |
|
575 | + $hidden_endpoint); |
|
576 | + } |
|
577 | + return $config_routes; |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * Gets routes for the config for the specified version |
|
584 | + * |
|
585 | + * @param string $version |
|
586 | + * @param boolean $hidden_endpoint |
|
587 | + * @return array |
|
588 | + */ |
|
589 | + protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
590 | + { |
|
591 | + return array( |
|
592 | + 'config' => array( |
|
593 | + array( |
|
594 | + 'callback' => array( |
|
595 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
596 | + 'handle_request', |
|
597 | + ), |
|
598 | + 'methods' => WP_REST_Server::READABLE, |
|
599 | + 'hidden_endpoint' => $hidden_endpoint, |
|
600 | + ), |
|
601 | + ), |
|
602 | + 'site_info' => array( |
|
603 | + array( |
|
604 | + 'callback' => array( |
|
605 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
606 | + 'handle_request_site_info', |
|
607 | + ), |
|
608 | + 'methods' => WP_REST_Server::READABLE, |
|
609 | + 'hidden_endpoint' => $hidden_endpoint, |
|
610 | + ), |
|
611 | + ), |
|
612 | + ); |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + |
|
617 | + /** |
|
618 | + * Gets the meta info routes |
|
619 | + * |
|
620 | + * @return array @see _register_model_routes |
|
621 | + * @deprecated since version 4.9.1 |
|
622 | + */ |
|
623 | + protected function _register_meta_routes() |
|
624 | + { |
|
625 | + $meta_routes = array(); |
|
626 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
627 | + $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version($version, |
|
628 | + $hidden_endpoint); |
|
629 | + } |
|
630 | + return $meta_routes; |
|
631 | + } |
|
632 | + |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * @param string $version |
|
637 | + * @param boolean $hidden_endpoint |
|
638 | + * @return array |
|
639 | + */ |
|
640 | + protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
641 | + { |
|
642 | + return array( |
|
643 | + 'resources' => array( |
|
644 | + array( |
|
645 | + 'callback' => array( |
|
646 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
647 | + 'handle_request_models_meta', |
|
648 | + ), |
|
649 | + 'methods' => WP_REST_Server::READABLE, |
|
650 | + 'hidden_endpoint' => $hidden_endpoint, |
|
651 | + ), |
|
652 | + ), |
|
653 | + ); |
|
654 | + } |
|
655 | + |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * Tries to hide old 4.6 endpoints from the |
|
660 | + * |
|
661 | + * @param array $route_data |
|
662 | + * @return array |
|
663 | + */ |
|
664 | + public static function hide_old_endpoints($route_data) |
|
665 | + { |
|
666 | + //allow API clients to override which endpoints get hidden, in case |
|
667 | + //they want to discover particular endpoints |
|
668 | + //also, we don't have access to the request so we have to just grab it from the superglobal |
|
669 | + $force_show_ee_namespace = ltrim( |
|
670 | + EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''), |
|
671 | + '/' |
|
672 | + ); |
|
673 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
674 | + foreach ($relative_urls as $endpoint => $routes) { |
|
675 | + foreach ($routes as $route) { |
|
676 | + //by default, hide "hidden_endpoint"s, unless the request indicates |
|
677 | + //to $force_show_ee_namespace, in which case only show that one |
|
678 | + //namespace's endpoints (and hide all others) |
|
679 | + if (($route['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
680 | + || ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
681 | + ) { |
|
682 | + $full_route = '/' . ltrim($namespace, '/') . '/' . ltrim($endpoint, '/'); |
|
683 | + unset($route_data[$full_route]); |
|
684 | + } |
|
685 | + } |
|
686 | + } |
|
687 | + } |
|
688 | + return $route_data; |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * Returns an array describing which versions of core support serving requests for. |
|
695 | + * Keys are core versions' major and minor version, and values are the |
|
696 | + * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
697 | + * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
698 | + * the answers table entirely, in which case it would be very difficult for |
|
699 | + * it to serve 4.6-style responses. |
|
700 | + * Versions of core that are missing from this array are unknowns. |
|
701 | + * previous ver |
|
702 | + * |
|
703 | + * @return array |
|
704 | + */ |
|
705 | + public static function version_compatibilities() |
|
706 | + { |
|
707 | + return apply_filters( |
|
708 | + 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
709 | + array( |
|
710 | + '4.8.29' => '4.8.29', |
|
711 | + '4.8.33' => '4.8.29', |
|
712 | + '4.8.34' => '4.8.29', |
|
713 | + '4.8.36' => '4.8.29', |
|
714 | + ) |
|
715 | + ); |
|
716 | + } |
|
717 | + |
|
718 | + |
|
719 | + |
|
720 | + /** |
|
721 | + * Gets the latest API version served. Eg if there |
|
722 | + * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
723 | + * we are on core version 4.8.34, it will return the string "4.8.32" |
|
724 | + * |
|
725 | + * @return string |
|
726 | + */ |
|
727 | + public static function latest_rest_api_version() |
|
728 | + { |
|
729 | + $versions_served = \EED_Core_Rest_Api::versions_served(); |
|
730 | + $versions_served_keys = array_keys($versions_served); |
|
731 | + return end($versions_served_keys); |
|
732 | + } |
|
733 | + |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
738 | + * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
739 | + * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
740 | + * We also indicate whether or not this version should be put in the index or not |
|
741 | + * |
|
742 | + * @return array keys are API version numbers (just major and minor numbers), and values |
|
743 | + * are whether or not they should be hidden |
|
744 | + */ |
|
745 | + public static function versions_served() |
|
746 | + { |
|
747 | + $versions_served = array(); |
|
748 | + $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
749 | + $lowest_compatible_version = end($possibly_served_versions); |
|
750 | + reset($possibly_served_versions); |
|
751 | + $versions_served_historically = array_keys($possibly_served_versions); |
|
752 | + $latest_version = end($versions_served_historically); |
|
753 | + reset($versions_served_historically); |
|
754 | + //for each version of core we have ever served: |
|
755 | + foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
756 | + //if it's not above the current core version, and it's compatible with the current version of core |
|
757 | + if ($key_versioned_endpoint == $latest_version) { |
|
758 | + //don't hide the latest version in the index |
|
759 | + $versions_served[$key_versioned_endpoint] = false; |
|
760 | + } else if ( |
|
761 | + $key_versioned_endpoint < EED_Core_Rest_Api::core_version() |
|
762 | + && $key_versioned_endpoint >= $lowest_compatible_version |
|
763 | + ) { |
|
764 | + //include, but hide, previous versions which are still supported |
|
765 | + $versions_served[$key_versioned_endpoint] = true; |
|
766 | + } elseif ( |
|
767 | + apply_filters( |
|
768 | + 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
769 | + false, |
|
770 | + $possibly_served_versions |
|
771 | + ) |
|
772 | + ) { |
|
773 | + //if a version is no longer supported, don't include it in index or list of versions served |
|
774 | + $versions_served[$key_versioned_endpoint] = true; |
|
775 | + } |
|
776 | + } |
|
777 | + return $versions_served; |
|
778 | + } |
|
779 | + |
|
780 | + |
|
781 | + |
|
782 | + /** |
|
783 | + * Gets the major and minor version of EE core's version string |
|
784 | + * |
|
785 | + * @return string |
|
786 | + */ |
|
787 | + public static function core_version() |
|
788 | + { |
|
789 | + return apply_filters('FHEE__EED_Core_REST_API__core_version', |
|
790 | + implode('.', array_slice(explode('.', espresso_version()), 0, 3))); |
|
791 | + } |
|
792 | + |
|
793 | + |
|
794 | + |
|
795 | + /** |
|
796 | + * Gets the default limit that should be used when querying for resources |
|
797 | + * |
|
798 | + * @return int |
|
799 | + */ |
|
800 | + public static function get_default_query_limit() |
|
801 | + { |
|
802 | + //we actually don't use a const because we want folks to always use |
|
803 | + //this method, not the const directly |
|
804 | + return apply_filters( |
|
805 | + 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
806 | + 50 |
|
807 | + ); |
|
808 | + } |
|
809 | + |
|
810 | + |
|
811 | + |
|
812 | + /** |
|
813 | + * run - initial module setup |
|
814 | + * |
|
815 | + * @access public |
|
816 | + * @param WP $WP |
|
817 | + * @return void |
|
818 | + */ |
|
819 | + public function run($WP) |
|
820 | + { |
|
821 | + } |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | // End of file EED_Core_Rest_Api.module.php |
@@ -6,21 +6,21 @@ discard block |
||
6 | 6 | * @subpackage |
7 | 7 | * @author Mike Nelson |
8 | 8 | */ |
9 | -class EE_Datepicker_Input extends EE_Form_Input_Base{ |
|
9 | +class EE_Datepicker_Input extends EE_Form_Input_Base { |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * @param array $input_settings |
13 | 13 | */ |
14 | - function __construct( $input_settings = array() ){ |
|
15 | - $this->_set_display_strategy( new EE_Text_Input_Display_Strategy( 'datepicker' ) ); |
|
16 | - $this->_set_normalization_strategy( new EE_Text_Normalization() ); |
|
14 | + function __construct($input_settings = array()) { |
|
15 | + $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('datepicker')); |
|
16 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
17 | 17 | //we could do better for validation, but at least verify its plaintext |
18 | - $this->_add_validation_strategy( new EE_Plaintext_Validation_Strategy( isset( $input_settings[ 'validation_error_message' ] ) ? $input_settings[ 'validation_error_message' ] : NULL ) ); |
|
19 | - parent::__construct( $input_settings ); |
|
20 | - $this->set_html_class( $this->html_class() . ' datepicker' ); |
|
18 | + $this->_add_validation_strategy(new EE_Plaintext_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : NULL)); |
|
19 | + parent::__construct($input_settings); |
|
20 | + $this->set_html_class($this->html_class().' datepicker'); |
|
21 | 21 | // add some style and make it dance |
22 | - add_action( 'wp_enqueue_scripts', array( 'EE_Datepicker_Input', 'enqueue_styles_and_scripts' )); |
|
23 | - add_action( 'admin_enqueue_scripts', array( 'EE_Datepicker_Input', 'enqueue_styles_and_scripts' )); |
|
22 | + add_action('wp_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
|
23 | + add_action('admin_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public static function enqueue_styles_and_scripts() { |
35 | 35 | // load css |
36 | - wp_register_style( 'espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION ); |
|
37 | - wp_enqueue_style( 'espresso-ui-theme'); |
|
36 | + wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
37 | + wp_enqueue_style('espresso-ui-theme'); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 |