@@ -71,10 +71,10 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @access protected |
73 | 73 | * @var array $_question_type_categories { |
74 | - * @type string $text |
|
75 | - * @type string $single-answer-enum |
|
76 | - * @type string $multi-answer-enum |
|
77 | - * } |
|
74 | + * @type string $text |
|
75 | + * @type string $single-answer-enum |
|
76 | + * @type string $multi-answer-enum |
|
77 | + * } |
|
78 | 78 | */ |
79 | 79 | protected $_question_type_categories = array(); |
80 | 80 | |
@@ -156,14 +156,14 @@ discard block |
||
156 | 156 | 'text' => array( |
157 | 157 | EEM_Question::QST_type_text, |
158 | 158 | EEM_Question::QST_type_textarea, |
159 | - EEM_Question::QST_type_date, |
|
159 | + EEM_Question::QST_type_date, |
|
160 | 160 | EEM_Question::QST_type_html_textarea, |
161 | 161 | EEM_Question::QST_type_email, |
162 | 162 | EEM_Question::QST_type_us_phone, |
163 | 163 | EEM_Question::QST_type_decimal, |
164 | - EEM_Question::QST_type_int, |
|
164 | + EEM_Question::QST_type_int, |
|
165 | 165 | EEM_Question::QST_type_url, |
166 | - EEM_Question::QST_type_year |
|
166 | + EEM_Question::QST_type_year |
|
167 | 167 | ), |
168 | 168 | 'single-answer-enum' => array( |
169 | 169 | EEM_Question::QST_type_radio, |
@@ -251,32 +251,32 @@ discard block |
||
251 | 251 | |
252 | 252 | |
253 | 253 | |
254 | - /** |
|
255 | - * Returns all the question types in the given category |
|
256 | - * @param string $category |
|
257 | - * @return array|mixed |
|
258 | - */ |
|
254 | + /** |
|
255 | + * Returns all the question types in the given category |
|
256 | + * @param string $category |
|
257 | + * @return array|mixed |
|
258 | + */ |
|
259 | 259 | public function question_types_in_category($category) |
260 | - { |
|
261 | - if( isset($this->_question_type_categories[$category])) { |
|
262 | - return $this->_question_type_categories[$category]; |
|
263 | - } |
|
264 | - return array(); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * Returns all the question types that should have question options |
|
271 | - * @return array |
|
272 | - */ |
|
273 | - public function question_types_with_options() |
|
274 | - { |
|
275 | - return array_merge( |
|
276 | - $this->question_types_in_category('single-answer-enum'), |
|
277 | - $this->question_types_in_category('multi-answer-enum') |
|
278 | - ); |
|
279 | - } |
|
260 | + { |
|
261 | + if( isset($this->_question_type_categories[$category])) { |
|
262 | + return $this->_question_type_categories[$category]; |
|
263 | + } |
|
264 | + return array(); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * Returns all the question types that should have question options |
|
271 | + * @return array |
|
272 | + */ |
|
273 | + public function question_types_with_options() |
|
274 | + { |
|
275 | + return array_merge( |
|
276 | + $this->question_types_in_category('single-answer-enum'), |
|
277 | + $this->question_types_in_category('multi-answer-enum') |
|
278 | + ); |
|
279 | + } |
|
280 | 280 | |
281 | 281 | /** |
282 | 282 | * Returns the question type categories 2d array |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | -require_once( EE_MODELS . 'EEM_Soft_Delete_Base.model.php' ); |
|
5 | -require_once( EE_CLASSES . 'EE_Question.class.php' ); |
|
4 | +require_once(EE_MODELS.'EEM_Soft_Delete_Base.model.php'); |
|
5 | +require_once(EE_CLASSES.'EE_Question.class.php'); |
|
6 | 6 | |
7 | 7 | |
8 | 8 | |
@@ -105,52 +105,52 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @param null $timezone |
107 | 107 | */ |
108 | - protected function __construct( $timezone = NULL ) { |
|
109 | - $this->singular_item = __('Question','event_espresso'); |
|
110 | - $this->plural_item = __('Questions','event_espresso'); |
|
111 | - $this->_allowed_question_types=apply_filters( |
|
108 | + protected function __construct($timezone = NULL) { |
|
109 | + $this->singular_item = __('Question', 'event_espresso'); |
|
110 | + $this->plural_item = __('Questions', 'event_espresso'); |
|
111 | + $this->_allowed_question_types = apply_filters( |
|
112 | 112 | 'FHEE__EEM_Question__construct__allowed_question_types', |
113 | 113 | array( |
114 | - EEM_Question::QST_type_text =>__('Text','event_espresso'), |
|
115 | - EEM_Question::QST_type_textarea =>__('Textarea','event_espresso'), |
|
116 | - EEM_Question::QST_type_checkbox =>__('Checkboxes','event_espresso'), |
|
117 | - EEM_Question::QST_type_radio =>__('Radio Buttons','event_espresso'), |
|
118 | - EEM_Question::QST_type_dropdown =>__('Dropdown','event_espresso'), |
|
119 | - EEM_Question::QST_type_state =>__('State/Province Dropdown','event_espresso'), |
|
120 | - EEM_Question::QST_type_country =>__('Country Dropdown','event_espresso'), |
|
121 | - EEM_Question::QST_type_date =>__('Date Picker','event_espresso'), |
|
122 | - EEM_Question::QST_type_html_textarea => __( 'HTML Textarea', 'event_espresso' ), |
|
123 | - EEM_Question::QST_type_email => __( 'Email', 'event_espresso' ), |
|
124 | - EEM_Question::QST_type_us_phone => __( 'USA - Format Phone', 'event_espresso' ), |
|
125 | - EEM_Question::QST_type_decimal => __( 'Number', 'event_espresso' ), |
|
126 | - EEM_Question::QST_type_int => __( 'Whole Number', 'event_espresso' ), |
|
127 | - EEM_Question::QST_type_url => __( 'URL', 'event_espresso' ), |
|
128 | - EEM_Question::QST_type_year => __( 'Year', 'event_espresso' ), |
|
129 | - EEM_Question::QST_type_multi_select => __( 'Multi Select', 'event_espresso' ) |
|
114 | + EEM_Question::QST_type_text =>__('Text', 'event_espresso'), |
|
115 | + EEM_Question::QST_type_textarea =>__('Textarea', 'event_espresso'), |
|
116 | + EEM_Question::QST_type_checkbox =>__('Checkboxes', 'event_espresso'), |
|
117 | + EEM_Question::QST_type_radio =>__('Radio Buttons', 'event_espresso'), |
|
118 | + EEM_Question::QST_type_dropdown =>__('Dropdown', 'event_espresso'), |
|
119 | + EEM_Question::QST_type_state =>__('State/Province Dropdown', 'event_espresso'), |
|
120 | + EEM_Question::QST_type_country =>__('Country Dropdown', 'event_espresso'), |
|
121 | + EEM_Question::QST_type_date =>__('Date Picker', 'event_espresso'), |
|
122 | + EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'), |
|
123 | + EEM_Question::QST_type_email => __('Email', 'event_espresso'), |
|
124 | + EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'), |
|
125 | + EEM_Question::QST_type_decimal => __('Number', 'event_espresso'), |
|
126 | + EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'), |
|
127 | + EEM_Question::QST_type_url => __('URL', 'event_espresso'), |
|
128 | + EEM_Question::QST_type_year => __('Year', 'event_espresso'), |
|
129 | + EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso') |
|
130 | 130 | ) |
131 | 131 | ); |
132 | 132 | $this->_question_descriptions = apply_filters( |
133 | 133 | 'FHEE__EEM_Question__construct__allowed_question_types', |
134 | 134 | array( |
135 | - EEM_Question::QST_type_text => __( 'A single line text input field', 'event_espresso' ), |
|
136 | - EEM_Question::QST_type_textarea => __( 'A multi line text input field', 'event_espresso' ), |
|
137 | - EEM_Question::QST_type_checkbox => __( 'Allows multiple preset options to be selected', 'event_espresso' ), |
|
138 | - EEM_Question::QST_type_radio => __( 'Allows a single preset option to be selected', 'event_espresso' ), |
|
139 | - EEM_Question::QST_type_dropdown => __( 'A dropdown that allows a single selection', 'event_espresso' ), |
|
140 | - EEM_Question::QST_type_state => __( 'A dropdown that lists states/provinces', 'event_espresso' ), |
|
141 | - EEM_Question::QST_type_country => __( 'A dropdown that lists countries', 'event_espresso' ), |
|
142 | - EEM_Question::QST_type_date => __( 'A popup calendar that allows date selections', 'event_espresso' ), |
|
143 | - EEM_Question::QST_type_html_textarea => __( 'A multi line text input field that allows HTML', 'event_espresso' ), |
|
144 | - EEM_Question::QST_type_email => __( 'A text field that must contain a valid Email address', 'event_espresso' ), |
|
145 | - EEM_Question::QST_type_us_phone => __( 'A text field that must contain a valid US phone number', 'event_espresso' ), |
|
146 | - EEM_Question::QST_type_decimal => __( 'A text field that allows number values with decimals', 'event_espresso' ), |
|
147 | - EEM_Question::QST_type_int => __( 'A text field that only allows whole numbers (no decimals)', 'event_espresso' ), |
|
148 | - EEM_Question::QST_type_url => __( 'A text field that must contain a valid URL', 'event_espresso' ), |
|
149 | - EEM_Question::QST_type_year => __( 'A dropdown that lists the last 100 years', 'event_espresso' ), |
|
150 | - EEM_Question::QST_type_multi_select => __( 'A dropdown that allows multiple selections', 'event_espresso' ) |
|
135 | + EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'), |
|
136 | + EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'), |
|
137 | + EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'), |
|
138 | + EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'), |
|
139 | + EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'), |
|
140 | + EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'), |
|
141 | + EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'), |
|
142 | + EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'), |
|
143 | + EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'), |
|
144 | + EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'), |
|
145 | + EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'), |
|
146 | + EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'), |
|
147 | + EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
148 | + EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'), |
|
149 | + EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'), |
|
150 | + EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
|
151 | 151 | ) |
152 | 152 | ); |
153 | - $this->_question_type_categories = (array)apply_filters( |
|
153 | + $this->_question_type_categories = (array) apply_filters( |
|
154 | 154 | 'FHEE__EEM_Question__construct__question_type_categories', |
155 | 155 | array( |
156 | 156 | 'text' => array( |
@@ -177,22 +177,22 @@ discard block |
||
177 | 177 | ); |
178 | 178 | |
179 | 179 | $this->_tables = array( |
180 | - 'Question'=>new EE_Primary_Table('esp_question','QST_ID') |
|
180 | + 'Question'=>new EE_Primary_Table('esp_question', 'QST_ID') |
|
181 | 181 | ); |
182 | 182 | $this->_fields = array( |
183 | 183 | 'Question'=>array( |
184 | - 'QST_ID'=>new EE_Primary_Key_Int_Field('QST_ID', __('Question ID','event_espresso')), |
|
185 | - 'QST_display_text'=>new EE_Post_Content_Field('QST_display_text', __('Question Text','event_espresso'), true, ''), |
|
186 | - 'QST_admin_label'=>new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)','event_espresso'), true, ''), |
|
187 | - 'QST_system'=>new EE_Plain_Text_Field('QST_system', __('Internal string ID for question','event_espresso'), false, '' ), |
|
188 | - 'QST_type'=>new EE_Enum_Text_Field('QST_type', __('Question Type','event_espresso'),false, 'TEXT',$this->_allowed_question_types), |
|
189 | - 'QST_required'=>new EE_Boolean_Field('QST_required', __('Required Question?','event_espresso'), false, false), |
|
190 | - 'QST_required_text'=>new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided','event_espresso'), true, ''), |
|
191 | - 'QST_order'=>new EE_Integer_Field('QST_order', __('Question Order','event_espresso'), false, 0), |
|
192 | - 'QST_admin_only'=>new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?','event_espresso'), false, false), |
|
193 | - 'QST_max' => new EE_Infinite_Integer_Field( 'QST_max', __( 'Max Size', 'event_espresso' ), false, EE_INF ), |
|
194 | - 'QST_wp_user'=>new EE_WP_User_Field('QST_wp_user', __('Question Creator ID','event_espresso'), false ), |
|
195 | - 'QST_deleted'=>new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted','event_espresso'), false, false) |
|
184 | + 'QST_ID'=>new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')), |
|
185 | + 'QST_display_text'=>new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''), |
|
186 | + 'QST_admin_label'=>new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
187 | + 'QST_system'=>new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''), |
|
188 | + 'QST_type'=>new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
189 | + 'QST_required'=>new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false), |
|
190 | + 'QST_required_text'=>new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
191 | + 'QST_order'=>new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0), |
|
192 | + 'QST_admin_only'=>new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false), |
|
193 | + 'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF), |
|
194 | + 'QST_wp_user'=>new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false), |
|
195 | + 'QST_deleted'=>new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
196 | 196 | ) |
197 | 197 | ); |
198 | 198 | $this->_model_relations = array( |
@@ -204,11 +204,11 @@ discard block |
||
204 | 204 | 'Question_Group_Question'=>new EE_Has_Many_Relation() |
205 | 205 | ); |
206 | 206 | //this model is generally available for reading |
207 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
208 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
209 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
210 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
211 | - parent::__construct( $timezone ); |
|
207 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
208 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
209 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
210 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
211 | + parent::__construct($timezone); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * but they can be extended |
217 | 217 | * @return string[] |
218 | 218 | */ |
219 | - public function allowed_question_types(){ |
|
219 | + public function allowed_question_types() { |
|
220 | 220 | return $this->_allowed_question_types; |
221 | 221 | } |
222 | 222 | /** |
@@ -224,16 +224,16 @@ discard block |
||
224 | 224 | * @param string $question_type one of EEM_Question::allowed_question_types( |
225 | 225 | * @return string[] like EEM_Question::allowed_question_types() |
226 | 226 | */ |
227 | - public function question_types_in_same_category( $question_type ) { |
|
228 | - $question_types = array( $question_type ); |
|
229 | - foreach( $this->_question_type_categories as $category => $question_types_in_category ) { |
|
230 | - if( in_array( $question_type, $question_types_in_category ) ) { |
|
227 | + public function question_types_in_same_category($question_type) { |
|
228 | + $question_types = array($question_type); |
|
229 | + foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
230 | + if (in_array($question_type, $question_types_in_category)) { |
|
231 | 231 | $question_types = $question_types_in_category; |
232 | 232 | break; |
233 | 233 | } |
234 | 234 | } |
235 | 235 | |
236 | - return array_intersect_key( $this->allowed_question_types(), array_flip( $question_types ) ); |
|
236 | + return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
243 | 243 | * @return boolean |
244 | 244 | */ |
245 | - public function question_type_is_in_category( $question_type, $category ) { |
|
246 | - if( ! isset( $this->_question_type_categories[ $category ] ) ) { |
|
245 | + public function question_type_is_in_category($question_type, $category) { |
|
246 | + if ( ! isset($this->_question_type_categories[$category])) { |
|
247 | 247 | return false; |
248 | 248 | } |
249 | - return in_array( $question_type, $this->_question_type_categories[ $category ] ); |
|
249 | + return in_array($question_type, $this->_question_type_categories[$category]); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | */ |
259 | 259 | public function question_types_in_category($category) |
260 | 260 | { |
261 | - if( isset($this->_question_type_categories[$category])) { |
|
261 | + if (isset($this->_question_type_categories[$category])) { |
|
262 | 262 | return $this->_question_type_categories[$category]; |
263 | 263 | } |
264 | 264 | return array(); |
@@ -292,9 +292,9 @@ discard block |
||
292 | 292 | * @param string $system_question_group_id QSG_system |
293 | 293 | * @return array of system question names (QST_system) |
294 | 294 | */ |
295 | - public function allowed_system_questions_in_system_question_group( $system_question_group_id ) { |
|
295 | + public function allowed_system_questions_in_system_question_group($system_question_group_id) { |
|
296 | 296 | $question_system_ids = array(); |
297 | - switch( $system_question_group_id ) { |
|
297 | + switch ($system_question_group_id) { |
|
298 | 298 | case EEM_Question_Group::system_personal: |
299 | 299 | $question_system_ids = array( |
300 | 300 | EEM_Attendee::system_question_fname, |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | ); |
316 | 316 | break; |
317 | 317 | } |
318 | - return apply_filters( 'FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id ); |
|
318 | + return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -324,11 +324,11 @@ discard block |
||
324 | 324 | * @param string $system_question_group_id QSG_system |
325 | 325 | * @return array of system question names (QST_system) |
326 | 326 | */ |
327 | - public function required_system_questions_in_system_question_group( $system_question_group_id ) { |
|
327 | + public function required_system_questions_in_system_question_group($system_question_group_id) { |
|
328 | 328 | $question_system_ids = null; |
329 | - switch( $system_question_group_id ) { |
|
329 | + switch ($system_question_group_id) { |
|
330 | 330 | case EEM_Question_Group::system_personal: |
331 | - $question_system_ids = array( |
|
331 | + $question_system_ids = array( |
|
332 | 332 | EEM_Attendee::system_question_fname, |
333 | 333 | EEM_Attendee::system_question_email, |
334 | 334 | ); |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | default: |
337 | 337 | $question_system_ids = array(); |
338 | 338 | } |
339 | - return apply_filters( 'FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id ); |
|
339 | + return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | |
@@ -347,8 +347,8 @@ discard block |
||
347 | 347 | * @param $QST_system |
348 | 348 | * @return int of QST_ID for the question that corresponds to that QST_system |
349 | 349 | */ |
350 | - public function get_Question_ID_from_system_string( $QST_system ){ |
|
351 | - return $this->get_var( array( array( 'QST_system' => $QST_system ) ) ); |
|
350 | + public function get_Question_ID_from_system_string($QST_system) { |
|
351 | + return $this->get_var(array(array('QST_system' => $QST_system))); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | |
@@ -360,10 +360,10 @@ discard block |
||
360 | 360 | */ |
361 | 361 | public function get_latest_question_order() { |
362 | 362 | $columns_to_select = array( |
363 | - 'max_order' => array("MAX(QST_order)","%d") |
|
363 | + 'max_order' => array("MAX(QST_order)", "%d") |
|
364 | 364 | ); |
365 | - $max = $this->_get_all_wpdb_results( array(), ARRAY_A, $columns_to_select ); |
|
366 | - return isset( $max[0], $max[0]['max_order'] ) ? $max[0]['max_order'] : 0; |
|
365 | + $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
366 | + return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | /** |
@@ -392,10 +392,10 @@ discard block |
||
392 | 392 | * @param string $system_question_value |
393 | 393 | * @return int|float |
394 | 394 | */ |
395 | - public function absolute_max_for_system_question( $system_question_value ) { |
|
395 | + public function absolute_max_for_system_question($system_question_value) { |
|
396 | 396 | $maxes = $this->system_question_maxes(); |
397 | - if( isset( $maxes[ $system_question_value ] ) ) { |
|
398 | - return $maxes[ $system_question_value ]; |
|
397 | + if (isset($maxes[$system_question_value])) { |
|
398 | + return $maxes[$system_question_value]; |
|
399 | 399 | } else { |
400 | 400 | return EE_INF; |
401 | 401 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -17,157 +17,157 @@ discard block |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * enqueues css and js, so that this can be called statically |
|
22 | - */ |
|
23 | - public static function enqueue_styles_and_scripts() |
|
24 | - { |
|
25 | - wp_register_style( |
|
26 | - 'checkbox_dropdown_selector', |
|
27 | - EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css', |
|
28 | - array('espresso_default'), |
|
29 | - EVENT_ESPRESSO_VERSION |
|
30 | - ); |
|
31 | - wp_register_style( |
|
32 | - 'espresso_default', |
|
33 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
34 | - array('dashicons'), |
|
35 | - EVENT_ESPRESSO_VERSION |
|
36 | - ); |
|
37 | - wp_enqueue_style('checkbox_dropdown_selector'); |
|
38 | - wp_register_script( |
|
39 | - 'checkbox_dropdown_selector', |
|
40 | - EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js', |
|
41 | - array('jquery'), |
|
42 | - EVENT_ESPRESSO_VERSION, |
|
43 | - true |
|
44 | - ); |
|
45 | - wp_enqueue_script('checkbox_dropdown_selector'); |
|
46 | - } |
|
47 | - |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
52 | - */ |
|
53 | - public function enqueue_js(){ |
|
54 | - EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * callback for Iframe::addStylesheets() child class methods |
|
61 | - * |
|
62 | - * @param array $iframe_css |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - public function iframe_css(array $iframe_css){ |
|
66 | - $iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css'; |
|
67 | - return $iframe_css; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * callback for Iframe::addScripts() child class methods |
|
74 | - * |
|
75 | - * @param array $iframe_js |
|
76 | - * @return array |
|
77 | - */ |
|
78 | - public function iframe_js(array $iframe_js){ |
|
79 | - $iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js'; |
|
80 | - return $iframe_js; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * @throws EE_Error |
|
86 | - * @return string of html to display the field |
|
87 | - */ |
|
88 | - public function display() |
|
89 | - { |
|
90 | - $input = $this->get_input(); |
|
91 | - $select_button_text = $input instanceof EE_Checkbox_Dropdown_Selector_Input ? $input->select_button_text() : ''; |
|
92 | - // $multi = count( $input->options() ) > 1 ? TRUE : FALSE; |
|
93 | - $input->set_label_sizes(); |
|
94 | - $label_size_class = $input->get_label_size_class(); |
|
95 | - if ( ! is_array($input->raw_value()) && $input->raw_value() !== null) { |
|
96 | - EE_Error::doing_it_wrong( |
|
97 | - 'EE_Checkbox_Display_Strategy::display()', |
|
98 | - sprintf( |
|
99 | - esc_html__( |
|
100 | - 'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"', |
|
101 | - 'event_espresso' |
|
102 | - ), |
|
103 | - $input->html_id(), |
|
104 | - var_export($input->raw_value(), true), |
|
105 | - $input->html_name() . '[]' |
|
106 | - ), |
|
107 | - '4.8.1' |
|
108 | - ); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - $html = \EEH_HTML::div('', '', 'checkbox-dropdown-selector-wrap-dv'); |
|
113 | - $html .= '<button id="' . $input->html_id() . '-btn"'; |
|
114 | - // $html .= ' name="' . $input->html_name() . '"'; |
|
115 | - $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"'; |
|
116 | - $html .= ' style="' . $input->html_style() . '"'; |
|
117 | - $html .= ' data-target="' . $input->html_id() . '-options-dv"'; |
|
118 | - $html .= ' ' . $input->html_other_attributes() . '>'; |
|
119 | - $html .= '<span class="checkbox-dropdown-selector-selected-spn">'; |
|
120 | - $html .= $select_button_text; |
|
121 | - $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>'; |
|
122 | - $html .= '</button>'; |
|
123 | - $html .= EEH_HTML::div( |
|
124 | - '', |
|
125 | - $input->html_id() . '-options-dv', |
|
126 | - 'checkbox-dropdown-selector' |
|
127 | - ); |
|
128 | - $html .= EEH_HTML::link( |
|
129 | - '', |
|
130 | - '<span class="dashicons dashicons-no"></span>', |
|
131 | - esc_html__('close datetime selector', 'event_espresso'), |
|
132 | - '', |
|
133 | - 'close-espresso-notice' |
|
134 | - ); |
|
135 | - $html .= EEH_HTML::ul(); |
|
136 | - $input_raw_value = (array)$input->raw_value(); |
|
137 | - foreach ($input->options() as $value => $display_text) { |
|
138 | - $html .= EEH_HTML::li(); |
|
139 | - $value = $input->get_normalization_strategy()->unnormalize_one($value); |
|
140 | - $html_id = $this->get_sub_input_id($value); |
|
141 | - $html .= EEH_HTML::nl(0, 'checkbox'); |
|
142 | - $html .= '<label for="' |
|
143 | - . $html_id |
|
144 | - . '" id="' |
|
145 | - . $html_id |
|
146 | - . '-lbl" class="ee-checkbox-label-after' |
|
147 | - . $label_size_class |
|
148 | - . '">'; |
|
149 | - $html .= EEH_HTML::nl(1, 'checkbox'); |
|
150 | - $html .= '<input type="checkbox"'; |
|
151 | - $html .= ' name="' . $input->html_name() . '[]"'; |
|
152 | - $html .= ' id="' . $html_id . '"'; |
|
153 | - $html .= ' class="' . $input->html_class() . '-option"'; |
|
154 | - $html .= ' style="' . $input->html_style() . '"'; |
|
155 | - $html .= ' value="' . esc_attr($value) . '"'; |
|
156 | - $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
|
157 | - ? ' checked="checked"' |
|
158 | - : ''; |
|
159 | - $html .= ' ' . $this->_input->other_html_attributes(); |
|
160 | - $html .= '>'; |
|
161 | - $html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>'; |
|
162 | - $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
163 | - $html .= EEH_HTML::lix(); |
|
164 | - } |
|
165 | - $html .= EEH_HTML::ulx(); |
|
166 | - $html .= EEH_HTML::divx(); |
|
167 | - $html .= EEH_HTML::divx(); |
|
168 | - $html .= \EEH_HTML::br(); |
|
169 | - return $html; |
|
170 | - } |
|
20 | + /** |
|
21 | + * enqueues css and js, so that this can be called statically |
|
22 | + */ |
|
23 | + public static function enqueue_styles_and_scripts() |
|
24 | + { |
|
25 | + wp_register_style( |
|
26 | + 'checkbox_dropdown_selector', |
|
27 | + EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css', |
|
28 | + array('espresso_default'), |
|
29 | + EVENT_ESPRESSO_VERSION |
|
30 | + ); |
|
31 | + wp_register_style( |
|
32 | + 'espresso_default', |
|
33 | + EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
34 | + array('dashicons'), |
|
35 | + EVENT_ESPRESSO_VERSION |
|
36 | + ); |
|
37 | + wp_enqueue_style('checkbox_dropdown_selector'); |
|
38 | + wp_register_script( |
|
39 | + 'checkbox_dropdown_selector', |
|
40 | + EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js', |
|
41 | + array('jquery'), |
|
42 | + EVENT_ESPRESSO_VERSION, |
|
43 | + true |
|
44 | + ); |
|
45 | + wp_enqueue_script('checkbox_dropdown_selector'); |
|
46 | + } |
|
47 | + |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
52 | + */ |
|
53 | + public function enqueue_js(){ |
|
54 | + EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * callback for Iframe::addStylesheets() child class methods |
|
61 | + * |
|
62 | + * @param array $iframe_css |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + public function iframe_css(array $iframe_css){ |
|
66 | + $iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css'; |
|
67 | + return $iframe_css; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * callback for Iframe::addScripts() child class methods |
|
74 | + * |
|
75 | + * @param array $iframe_js |
|
76 | + * @return array |
|
77 | + */ |
|
78 | + public function iframe_js(array $iframe_js){ |
|
79 | + $iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js'; |
|
80 | + return $iframe_js; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * @throws EE_Error |
|
86 | + * @return string of html to display the field |
|
87 | + */ |
|
88 | + public function display() |
|
89 | + { |
|
90 | + $input = $this->get_input(); |
|
91 | + $select_button_text = $input instanceof EE_Checkbox_Dropdown_Selector_Input ? $input->select_button_text() : ''; |
|
92 | + // $multi = count( $input->options() ) > 1 ? TRUE : FALSE; |
|
93 | + $input->set_label_sizes(); |
|
94 | + $label_size_class = $input->get_label_size_class(); |
|
95 | + if ( ! is_array($input->raw_value()) && $input->raw_value() !== null) { |
|
96 | + EE_Error::doing_it_wrong( |
|
97 | + 'EE_Checkbox_Display_Strategy::display()', |
|
98 | + sprintf( |
|
99 | + esc_html__( |
|
100 | + 'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"', |
|
101 | + 'event_espresso' |
|
102 | + ), |
|
103 | + $input->html_id(), |
|
104 | + var_export($input->raw_value(), true), |
|
105 | + $input->html_name() . '[]' |
|
106 | + ), |
|
107 | + '4.8.1' |
|
108 | + ); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + $html = \EEH_HTML::div('', '', 'checkbox-dropdown-selector-wrap-dv'); |
|
113 | + $html .= '<button id="' . $input->html_id() . '-btn"'; |
|
114 | + // $html .= ' name="' . $input->html_name() . '"'; |
|
115 | + $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"'; |
|
116 | + $html .= ' style="' . $input->html_style() . '"'; |
|
117 | + $html .= ' data-target="' . $input->html_id() . '-options-dv"'; |
|
118 | + $html .= ' ' . $input->html_other_attributes() . '>'; |
|
119 | + $html .= '<span class="checkbox-dropdown-selector-selected-spn">'; |
|
120 | + $html .= $select_button_text; |
|
121 | + $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>'; |
|
122 | + $html .= '</button>'; |
|
123 | + $html .= EEH_HTML::div( |
|
124 | + '', |
|
125 | + $input->html_id() . '-options-dv', |
|
126 | + 'checkbox-dropdown-selector' |
|
127 | + ); |
|
128 | + $html .= EEH_HTML::link( |
|
129 | + '', |
|
130 | + '<span class="dashicons dashicons-no"></span>', |
|
131 | + esc_html__('close datetime selector', 'event_espresso'), |
|
132 | + '', |
|
133 | + 'close-espresso-notice' |
|
134 | + ); |
|
135 | + $html .= EEH_HTML::ul(); |
|
136 | + $input_raw_value = (array)$input->raw_value(); |
|
137 | + foreach ($input->options() as $value => $display_text) { |
|
138 | + $html .= EEH_HTML::li(); |
|
139 | + $value = $input->get_normalization_strategy()->unnormalize_one($value); |
|
140 | + $html_id = $this->get_sub_input_id($value); |
|
141 | + $html .= EEH_HTML::nl(0, 'checkbox'); |
|
142 | + $html .= '<label for="' |
|
143 | + . $html_id |
|
144 | + . '" id="' |
|
145 | + . $html_id |
|
146 | + . '-lbl" class="ee-checkbox-label-after' |
|
147 | + . $label_size_class |
|
148 | + . '">'; |
|
149 | + $html .= EEH_HTML::nl(1, 'checkbox'); |
|
150 | + $html .= '<input type="checkbox"'; |
|
151 | + $html .= ' name="' . $input->html_name() . '[]"'; |
|
152 | + $html .= ' id="' . $html_id . '"'; |
|
153 | + $html .= ' class="' . $input->html_class() . '-option"'; |
|
154 | + $html .= ' style="' . $input->html_style() . '"'; |
|
155 | + $html .= ' value="' . esc_attr($value) . '"'; |
|
156 | + $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
|
157 | + ? ' checked="checked"' |
|
158 | + : ''; |
|
159 | + $html .= ' ' . $this->_input->other_html_attributes(); |
|
160 | + $html .= '>'; |
|
161 | + $html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>'; |
|
162 | + $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
163 | + $html .= EEH_HTML::lix(); |
|
164 | + } |
|
165 | + $html .= EEH_HTML::ulx(); |
|
166 | + $html .= EEH_HTML::divx(); |
|
167 | + $html .= EEH_HTML::divx(); |
|
168 | + $html .= \EEH_HTML::br(); |
|
169 | + return $html; |
|
170 | + } |
|
171 | 171 | |
172 | 172 | |
173 | 173 |
@@ -24,20 +24,20 @@ discard block |
||
24 | 24 | { |
25 | 25 | wp_register_style( |
26 | 26 | 'checkbox_dropdown_selector', |
27 | - EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css', |
|
27 | + EE_GLOBAL_ASSETS_URL.'css/checkbox_dropdown_selector.css', |
|
28 | 28 | array('espresso_default'), |
29 | 29 | EVENT_ESPRESSO_VERSION |
30 | 30 | ); |
31 | 31 | wp_register_style( |
32 | 32 | 'espresso_default', |
33 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
33 | + EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', |
|
34 | 34 | array('dashicons'), |
35 | 35 | EVENT_ESPRESSO_VERSION |
36 | 36 | ); |
37 | 37 | wp_enqueue_style('checkbox_dropdown_selector'); |
38 | 38 | wp_register_script( |
39 | 39 | 'checkbox_dropdown_selector', |
40 | - EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js', |
|
40 | + EE_GLOBAL_ASSETS_URL.'scripts/checkbox_dropdown_selector.js', |
|
41 | 41 | array('jquery'), |
42 | 42 | EVENT_ESPRESSO_VERSION, |
43 | 43 | true |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * Informs the rest of the forms system what CSS and JS is needed to display the input |
52 | 52 | */ |
53 | - public function enqueue_js(){ |
|
53 | + public function enqueue_js() { |
|
54 | 54 | EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
55 | 55 | } |
56 | 56 | |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * @param array $iframe_css |
63 | 63 | * @return array |
64 | 64 | */ |
65 | - public function iframe_css(array $iframe_css){ |
|
66 | - $iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css'; |
|
65 | + public function iframe_css(array $iframe_css) { |
|
66 | + $iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL.'css/checkbox_dropdown_selector.css'; |
|
67 | 67 | return $iframe_css; |
68 | 68 | } |
69 | 69 | |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | * @param array $iframe_js |
76 | 76 | * @return array |
77 | 77 | */ |
78 | - public function iframe_js(array $iframe_js){ |
|
79 | - $iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js'; |
|
78 | + public function iframe_js(array $iframe_js) { |
|
79 | + $iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL.'scripts/checkbox_dropdown_selector.js'; |
|
80 | 80 | return $iframe_js; |
81 | 81 | } |
82 | 82 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | ), |
103 | 103 | $input->html_id(), |
104 | 104 | var_export($input->raw_value(), true), |
105 | - $input->html_name() . '[]' |
|
105 | + $input->html_name().'[]' |
|
106 | 106 | ), |
107 | 107 | '4.8.1' |
108 | 108 | ); |
@@ -110,19 +110,19 @@ discard block |
||
110 | 110 | |
111 | 111 | |
112 | 112 | $html = \EEH_HTML::div('', '', 'checkbox-dropdown-selector-wrap-dv'); |
113 | - $html .= '<button id="' . $input->html_id() . '-btn"'; |
|
113 | + $html .= '<button id="'.$input->html_id().'-btn"'; |
|
114 | 114 | // $html .= ' name="' . $input->html_name() . '"'; |
115 | - $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"'; |
|
116 | - $html .= ' style="' . $input->html_style() . '"'; |
|
117 | - $html .= ' data-target="' . $input->html_id() . '-options-dv"'; |
|
118 | - $html .= ' ' . $input->html_other_attributes() . '>'; |
|
115 | + $html .= ' class="'.$input->html_class().' checkbox-dropdown-selector-btn button-secondary button"'; |
|
116 | + $html .= ' style="'.$input->html_style().'"'; |
|
117 | + $html .= ' data-target="'.$input->html_id().'-options-dv"'; |
|
118 | + $html .= ' '.$input->html_other_attributes().'>'; |
|
119 | 119 | $html .= '<span class="checkbox-dropdown-selector-selected-spn">'; |
120 | 120 | $html .= $select_button_text; |
121 | 121 | $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>'; |
122 | 122 | $html .= '</button>'; |
123 | 123 | $html .= EEH_HTML::div( |
124 | 124 | '', |
125 | - $input->html_id() . '-options-dv', |
|
125 | + $input->html_id().'-options-dv', |
|
126 | 126 | 'checkbox-dropdown-selector' |
127 | 127 | ); |
128 | 128 | $html .= EEH_HTML::link( |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | 'close-espresso-notice' |
134 | 134 | ); |
135 | 135 | $html .= EEH_HTML::ul(); |
136 | - $input_raw_value = (array)$input->raw_value(); |
|
136 | + $input_raw_value = (array) $input->raw_value(); |
|
137 | 137 | foreach ($input->options() as $value => $display_text) { |
138 | 138 | $html .= EEH_HTML::li(); |
139 | 139 | $value = $input->get_normalization_strategy()->unnormalize_one($value); |
@@ -148,18 +148,18 @@ discard block |
||
148 | 148 | . '">'; |
149 | 149 | $html .= EEH_HTML::nl(1, 'checkbox'); |
150 | 150 | $html .= '<input type="checkbox"'; |
151 | - $html .= ' name="' . $input->html_name() . '[]"'; |
|
152 | - $html .= ' id="' . $html_id . '"'; |
|
153 | - $html .= ' class="' . $input->html_class() . '-option"'; |
|
154 | - $html .= ' style="' . $input->html_style() . '"'; |
|
155 | - $html .= ' value="' . esc_attr($value) . '"'; |
|
151 | + $html .= ' name="'.$input->html_name().'[]"'; |
|
152 | + $html .= ' id="'.$html_id.'"'; |
|
153 | + $html .= ' class="'.$input->html_class().'-option"'; |
|
154 | + $html .= ' style="'.$input->html_style().'"'; |
|
155 | + $html .= ' value="'.esc_attr($value).'"'; |
|
156 | 156 | $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
157 | 157 | ? ' checked="checked"' |
158 | 158 | : ''; |
159 | - $html .= ' ' . $this->_input->other_html_attributes(); |
|
159 | + $html .= ' '.$this->_input->other_html_attributes(); |
|
160 | 160 | $html .= '>'; |
161 | - $html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>'; |
|
162 | - $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
161 | + $html .= '<span class="datetime-selector-option-text-spn">'.$display_text.'</span>'; |
|
162 | + $html .= EEH_HTML::nl(-1, 'checkbox').'</label>'; |
|
163 | 163 | $html .= EEH_HTML::lix(); |
164 | 164 | } |
165 | 165 | $html .= EEH_HTML::ulx(); |
@@ -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 | /** |
@@ -28,593 +28,593 @@ discard block |
||
28 | 28 | class Registration_Form_Admin_Page extends EE_Admin_Page |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * _question |
|
33 | - * holds the specific question object for the question details screen |
|
34 | - * |
|
35 | - * @var EE_Question $_question |
|
36 | - */ |
|
37 | - protected $_question; |
|
38 | - |
|
39 | - /** |
|
40 | - * _question_group |
|
41 | - * holds the specific question group object for the question group details screen |
|
42 | - * |
|
43 | - * @var EE_Question_Group $_question_group |
|
44 | - */ |
|
45 | - protected $_question_group; |
|
46 | - |
|
47 | - /** |
|
48 | - *_question_model EEM_Question model instance (for queries) |
|
49 | - * |
|
50 | - * @var EEM_Question $_question_model ; |
|
51 | - */ |
|
52 | - protected $_question_model; |
|
53 | - |
|
54 | - /** |
|
55 | - * _question_group_model EEM_Question_group instance (for queries) |
|
56 | - * |
|
57 | - * @var EEM_Question_Group $_question_group_model |
|
58 | - */ |
|
59 | - protected $_question_group_model; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @Constructor |
|
64 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
65 | - * @access public |
|
66 | - */ |
|
67 | - public function __construct($routing = true) |
|
68 | - { |
|
69 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
70 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
71 | - $this->_question_model = EEM_Question::instance(); |
|
72 | - $this->_question_group_model = EEM_Question_Group::instance(); |
|
73 | - parent::__construct($routing); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - protected function _init_page_props() |
|
78 | - { |
|
79 | - $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
80 | - $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
81 | - $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
82 | - $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - protected function _ajax_hooks() |
|
87 | - { |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - protected function _define_page_props() |
|
92 | - { |
|
93 | - $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
94 | - $this->_labels = array( |
|
95 | - 'buttons' => array( |
|
96 | - 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
97 | - ), |
|
98 | - ); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - *_set_page_routes |
|
104 | - */ |
|
105 | - protected function _set_page_routes() |
|
106 | - { |
|
107 | - $qst_id = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
108 | - $this->_page_routes = array( |
|
109 | - 'default' => array( |
|
110 | - 'func' => '_questions_overview_list_table', |
|
111 | - 'capability' => 'ee_read_questions', |
|
112 | - ), |
|
113 | - |
|
114 | - 'edit_question' => array( |
|
115 | - 'func' => '_edit_question', |
|
116 | - 'capability' => 'ee_edit_question', |
|
117 | - 'obj_id' => $qst_id, |
|
118 | - 'args' => array('edit'), |
|
119 | - ), |
|
120 | - |
|
121 | - 'question_groups' => array( |
|
122 | - 'func' => '_questions_groups_preview', |
|
123 | - 'capability' => 'ee_read_question_groups', |
|
124 | - ), |
|
125 | - |
|
126 | - 'update_question' => array( |
|
127 | - 'func' => '_insert_or_update_question', |
|
128 | - 'args' => array('new_question' => false), |
|
129 | - 'capability' => 'ee_edit_question', |
|
130 | - 'obj_id' => $qst_id, |
|
131 | - 'noheader' => true, |
|
132 | - ), |
|
133 | - ); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - protected function _set_page_config() |
|
138 | - { |
|
139 | - $this->_page_config = array( |
|
140 | - 'default' => array( |
|
141 | - 'nav' => array( |
|
142 | - 'label' => esc_html__('Questions', 'event_espresso'), |
|
143 | - 'order' => 10, |
|
144 | - ), |
|
145 | - 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
146 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
147 | - 'help_tabs' => array( |
|
148 | - 'registration_form_questions_overview_help_tab' => array( |
|
149 | - 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
150 | - 'filename' => 'registration_form_questions_overview', |
|
151 | - ), |
|
152 | - 'registration_form_questions_overview_table_column_headings_help_tab' => array( |
|
153 | - 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
154 | - 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
155 | - ), |
|
156 | - 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array( |
|
157 | - 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
158 | - 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
159 | - ), |
|
160 | - ), |
|
161 | - 'help_tour' => array('Registration_Form_Questions_Overview_Help_Tour'), |
|
162 | - 'require_nonce' => false, |
|
163 | - 'qtips' => array( |
|
164 | - 'EE_Registration_Form_Tips', |
|
165 | - )/**/ |
|
166 | - ), |
|
167 | - |
|
168 | - 'question_groups' => array( |
|
169 | - 'nav' => array( |
|
170 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
171 | - 'order' => 20, |
|
172 | - ), |
|
173 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
174 | - 'help_tabs' => array( |
|
175 | - 'registration_form_question_groups_help_tab' => array( |
|
176 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
177 | - 'filename' => 'registration_form_question_groups', |
|
178 | - ), |
|
179 | - ), |
|
180 | - 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
181 | - 'require_nonce' => false, |
|
182 | - ), |
|
183 | - |
|
184 | - 'edit_question' => array( |
|
185 | - 'nav' => array( |
|
186 | - 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
187 | - 'order' => 15, |
|
188 | - 'persistent' => false, |
|
189 | - 'url' => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']), |
|
190 | - $this->_current_page_view_url) : $this->_admin_base_url, |
|
191 | - ), |
|
192 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
193 | - 'help_tabs' => array( |
|
194 | - 'registration_form_edit_question_group_help_tab' => array( |
|
195 | - 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
196 | - 'filename' => 'registration_form_edit_question', |
|
197 | - ), |
|
198 | - ), |
|
199 | - 'help_tour' => array('Registration_Form_Edit_Question_Help_Tour'), |
|
200 | - 'require_nonce' => false, |
|
201 | - ), |
|
202 | - ); |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - protected function _add_screen_options() |
|
207 | - { |
|
208 | - //todo |
|
209 | - } |
|
210 | - |
|
211 | - protected function _add_screen_options_default() |
|
212 | - { |
|
213 | - $page_title = $this->_admin_page_title; |
|
214 | - $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
215 | - $this->_per_page_screen_option(); |
|
216 | - $this->_admin_page_title = $page_title; |
|
217 | - } |
|
218 | - |
|
219 | - protected function _add_screen_options_question_groups() |
|
220 | - { |
|
221 | - $page_title = $this->_admin_page_title; |
|
222 | - $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
223 | - $this->_per_page_screen_option(); |
|
224 | - $this->_admin_page_title = $page_title; |
|
225 | - } |
|
226 | - |
|
227 | - //none of the below group are currently used for Event Categories |
|
228 | - protected function _add_feature_pointers() |
|
229 | - { |
|
230 | - } |
|
231 | - |
|
232 | - public function load_scripts_styles() |
|
233 | - { |
|
234 | - wp_register_style('espresso_registration', |
|
235 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
236 | - wp_enqueue_style('espresso_registration'); |
|
237 | - } |
|
238 | - |
|
239 | - public function admin_init() |
|
240 | - { |
|
241 | - } |
|
242 | - |
|
243 | - public function admin_notices() |
|
244 | - { |
|
245 | - } |
|
246 | - |
|
247 | - public function admin_footer_scripts() |
|
248 | - { |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - public function load_scripts_styles_default() |
|
253 | - { |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - public function load_scripts_styles_add_question() |
|
258 | - { |
|
259 | - $this->load_scripts_styles_forms(); |
|
260 | - wp_register_script('espresso_registration_form_single', |
|
261 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
262 | - EVENT_ESPRESSO_VERSION, true); |
|
263 | - wp_enqueue_script('espresso_registration_form_single'); |
|
264 | - } |
|
265 | - |
|
266 | - public function load_scripts_styles_edit_question() |
|
267 | - { |
|
268 | - $this->load_scripts_styles_forms(); |
|
269 | - wp_register_script('espresso_registration_form_single', |
|
270 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
271 | - EVENT_ESPRESSO_VERSION, true); |
|
272 | - wp_enqueue_script('espresso_registration_form_single'); |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - public function recaptcha_info_help_tab() |
|
277 | - { |
|
278 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
279 | - EEH_Template::display_template($template, array()); |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - public function load_scripts_styles_forms() |
|
284 | - { |
|
285 | - //styles |
|
286 | - wp_enqueue_style('espresso-ui-theme'); |
|
287 | - //scripts |
|
288 | - wp_enqueue_script('ee_admin_js'); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - protected function _set_list_table_views_default() |
|
293 | - { |
|
294 | - $this->_views = array( |
|
295 | - 'all' => array( |
|
296 | - 'slug' => 'all', |
|
297 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
298 | - 'count' => 0, |
|
31 | + /** |
|
32 | + * _question |
|
33 | + * holds the specific question object for the question details screen |
|
34 | + * |
|
35 | + * @var EE_Question $_question |
|
36 | + */ |
|
37 | + protected $_question; |
|
38 | + |
|
39 | + /** |
|
40 | + * _question_group |
|
41 | + * holds the specific question group object for the question group details screen |
|
42 | + * |
|
43 | + * @var EE_Question_Group $_question_group |
|
44 | + */ |
|
45 | + protected $_question_group; |
|
46 | + |
|
47 | + /** |
|
48 | + *_question_model EEM_Question model instance (for queries) |
|
49 | + * |
|
50 | + * @var EEM_Question $_question_model ; |
|
51 | + */ |
|
52 | + protected $_question_model; |
|
53 | + |
|
54 | + /** |
|
55 | + * _question_group_model EEM_Question_group instance (for queries) |
|
56 | + * |
|
57 | + * @var EEM_Question_Group $_question_group_model |
|
58 | + */ |
|
59 | + protected $_question_group_model; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @Constructor |
|
64 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
65 | + * @access public |
|
66 | + */ |
|
67 | + public function __construct($routing = true) |
|
68 | + { |
|
69 | + require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
70 | + require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
71 | + $this->_question_model = EEM_Question::instance(); |
|
72 | + $this->_question_group_model = EEM_Question_Group::instance(); |
|
73 | + parent::__construct($routing); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + protected function _init_page_props() |
|
78 | + { |
|
79 | + $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
80 | + $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
81 | + $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
82 | + $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + protected function _ajax_hooks() |
|
87 | + { |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + protected function _define_page_props() |
|
92 | + { |
|
93 | + $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
94 | + $this->_labels = array( |
|
95 | + 'buttons' => array( |
|
96 | + 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
97 | + ), |
|
98 | + ); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + *_set_page_routes |
|
104 | + */ |
|
105 | + protected function _set_page_routes() |
|
106 | + { |
|
107 | + $qst_id = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
108 | + $this->_page_routes = array( |
|
109 | + 'default' => array( |
|
110 | + 'func' => '_questions_overview_list_table', |
|
111 | + 'capability' => 'ee_read_questions', |
|
112 | + ), |
|
113 | + |
|
114 | + 'edit_question' => array( |
|
115 | + 'func' => '_edit_question', |
|
116 | + 'capability' => 'ee_edit_question', |
|
117 | + 'obj_id' => $qst_id, |
|
118 | + 'args' => array('edit'), |
|
119 | + ), |
|
120 | + |
|
121 | + 'question_groups' => array( |
|
122 | + 'func' => '_questions_groups_preview', |
|
123 | + 'capability' => 'ee_read_question_groups', |
|
124 | + ), |
|
125 | + |
|
126 | + 'update_question' => array( |
|
127 | + 'func' => '_insert_or_update_question', |
|
128 | + 'args' => array('new_question' => false), |
|
129 | + 'capability' => 'ee_edit_question', |
|
130 | + 'obj_id' => $qst_id, |
|
131 | + 'noheader' => true, |
|
132 | + ), |
|
133 | + ); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + protected function _set_page_config() |
|
138 | + { |
|
139 | + $this->_page_config = array( |
|
140 | + 'default' => array( |
|
141 | + 'nav' => array( |
|
142 | + 'label' => esc_html__('Questions', 'event_espresso'), |
|
143 | + 'order' => 10, |
|
144 | + ), |
|
145 | + 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
146 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
147 | + 'help_tabs' => array( |
|
148 | + 'registration_form_questions_overview_help_tab' => array( |
|
149 | + 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
150 | + 'filename' => 'registration_form_questions_overview', |
|
151 | + ), |
|
152 | + 'registration_form_questions_overview_table_column_headings_help_tab' => array( |
|
153 | + 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
154 | + 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
155 | + ), |
|
156 | + 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array( |
|
157 | + 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
158 | + 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
159 | + ), |
|
160 | + ), |
|
161 | + 'help_tour' => array('Registration_Form_Questions_Overview_Help_Tour'), |
|
162 | + 'require_nonce' => false, |
|
163 | + 'qtips' => array( |
|
164 | + 'EE_Registration_Form_Tips', |
|
165 | + )/**/ |
|
166 | + ), |
|
167 | + |
|
168 | + 'question_groups' => array( |
|
169 | + 'nav' => array( |
|
170 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
171 | + 'order' => 20, |
|
172 | + ), |
|
173 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
174 | + 'help_tabs' => array( |
|
175 | + 'registration_form_question_groups_help_tab' => array( |
|
176 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
177 | + 'filename' => 'registration_form_question_groups', |
|
178 | + ), |
|
179 | + ), |
|
180 | + 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
181 | + 'require_nonce' => false, |
|
182 | + ), |
|
183 | + |
|
184 | + 'edit_question' => array( |
|
185 | + 'nav' => array( |
|
186 | + 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
187 | + 'order' => 15, |
|
188 | + 'persistent' => false, |
|
189 | + 'url' => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']), |
|
190 | + $this->_current_page_view_url) : $this->_admin_base_url, |
|
191 | + ), |
|
192 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
193 | + 'help_tabs' => array( |
|
194 | + 'registration_form_edit_question_group_help_tab' => array( |
|
195 | + 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
196 | + 'filename' => 'registration_form_edit_question', |
|
197 | + ), |
|
198 | + ), |
|
199 | + 'help_tour' => array('Registration_Form_Edit_Question_Help_Tour'), |
|
200 | + 'require_nonce' => false, |
|
201 | + ), |
|
202 | + ); |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + protected function _add_screen_options() |
|
207 | + { |
|
208 | + //todo |
|
209 | + } |
|
210 | + |
|
211 | + protected function _add_screen_options_default() |
|
212 | + { |
|
213 | + $page_title = $this->_admin_page_title; |
|
214 | + $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
215 | + $this->_per_page_screen_option(); |
|
216 | + $this->_admin_page_title = $page_title; |
|
217 | + } |
|
218 | + |
|
219 | + protected function _add_screen_options_question_groups() |
|
220 | + { |
|
221 | + $page_title = $this->_admin_page_title; |
|
222 | + $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
223 | + $this->_per_page_screen_option(); |
|
224 | + $this->_admin_page_title = $page_title; |
|
225 | + } |
|
226 | + |
|
227 | + //none of the below group are currently used for Event Categories |
|
228 | + protected function _add_feature_pointers() |
|
229 | + { |
|
230 | + } |
|
231 | + |
|
232 | + public function load_scripts_styles() |
|
233 | + { |
|
234 | + wp_register_style('espresso_registration', |
|
235 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
236 | + wp_enqueue_style('espresso_registration'); |
|
237 | + } |
|
238 | + |
|
239 | + public function admin_init() |
|
240 | + { |
|
241 | + } |
|
242 | + |
|
243 | + public function admin_notices() |
|
244 | + { |
|
245 | + } |
|
246 | + |
|
247 | + public function admin_footer_scripts() |
|
248 | + { |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + public function load_scripts_styles_default() |
|
253 | + { |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + public function load_scripts_styles_add_question() |
|
258 | + { |
|
259 | + $this->load_scripts_styles_forms(); |
|
260 | + wp_register_script('espresso_registration_form_single', |
|
261 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
262 | + EVENT_ESPRESSO_VERSION, true); |
|
263 | + wp_enqueue_script('espresso_registration_form_single'); |
|
264 | + } |
|
265 | + |
|
266 | + public function load_scripts_styles_edit_question() |
|
267 | + { |
|
268 | + $this->load_scripts_styles_forms(); |
|
269 | + wp_register_script('espresso_registration_form_single', |
|
270 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
271 | + EVENT_ESPRESSO_VERSION, true); |
|
272 | + wp_enqueue_script('espresso_registration_form_single'); |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + public function recaptcha_info_help_tab() |
|
277 | + { |
|
278 | + $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
279 | + EEH_Template::display_template($template, array()); |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + public function load_scripts_styles_forms() |
|
284 | + { |
|
285 | + //styles |
|
286 | + wp_enqueue_style('espresso-ui-theme'); |
|
287 | + //scripts |
|
288 | + wp_enqueue_script('ee_admin_js'); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + protected function _set_list_table_views_default() |
|
293 | + { |
|
294 | + $this->_views = array( |
|
295 | + 'all' => array( |
|
296 | + 'slug' => 'all', |
|
297 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
298 | + 'count' => 0, |
|
299 | 299 | // 'bulk_action' => array( |
300 | 300 | // 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
301 | 301 | // ) |
302 | - ), |
|
303 | - ); |
|
304 | - |
|
305 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
306 | - 'espresso_registration_form_trash_questions') |
|
307 | - ) { |
|
308 | - $this->_views['trash'] = array( |
|
309 | - 'slug' => 'trash', |
|
310 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
311 | - 'count' => 0, |
|
302 | + ), |
|
303 | + ); |
|
304 | + |
|
305 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
306 | + 'espresso_registration_form_trash_questions') |
|
307 | + ) { |
|
308 | + $this->_views['trash'] = array( |
|
309 | + 'slug' => 'trash', |
|
310 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
311 | + 'count' => 0, |
|
312 | 312 | // 'bulk_action' => array( |
313 | 313 | // 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
314 | 314 | // 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
315 | - ); |
|
316 | - } |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * This just previews the question groups tab that comes in caffeinated. |
|
321 | - * |
|
322 | - * @return string html |
|
323 | - */ |
|
324 | - protected function _questions_groups_preview() |
|
325 | - { |
|
326 | - $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
327 | - $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
328 | - 'event_espresso') . '" />'; |
|
329 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
330 | - 'event_espresso') . '</strong>'; |
|
331 | - $this->display_admin_caf_preview_page('question_groups_tab'); |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * Extracts the question field's values from the POST request to update or insert them |
|
337 | - * |
|
338 | - * @param \EEM_Base $model |
|
339 | - * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
340 | - */ |
|
341 | - protected function _set_column_values_for(EEM_Base $model) |
|
342 | - { |
|
343 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
344 | - $set_column_values = array(); |
|
345 | - |
|
346 | - //some initial checks for proper values. |
|
347 | - //if QST_admin_only, then no matter what QST_required is we disable. |
|
348 | - if (! empty($this->_req_data['QST_admin_only'])) { |
|
349 | - $this->_req_data['QST_required'] = 0; |
|
350 | - } |
|
351 | - foreach ($model->field_settings() as $fieldName => $settings) { |
|
352 | - // basically if QSG_identifier is empty or not set |
|
353 | - if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
|
354 | - $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
|
355 | - $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
315 | + ); |
|
316 | + } |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * This just previews the question groups tab that comes in caffeinated. |
|
321 | + * |
|
322 | + * @return string html |
|
323 | + */ |
|
324 | + protected function _questions_groups_preview() |
|
325 | + { |
|
326 | + $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
327 | + $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
328 | + 'event_espresso') . '" />'; |
|
329 | + $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
330 | + 'event_espresso') . '</strong>'; |
|
331 | + $this->display_admin_caf_preview_page('question_groups_tab'); |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * Extracts the question field's values from the POST request to update or insert them |
|
337 | + * |
|
338 | + * @param \EEM_Base $model |
|
339 | + * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
340 | + */ |
|
341 | + protected function _set_column_values_for(EEM_Base $model) |
|
342 | + { |
|
343 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
344 | + $set_column_values = array(); |
|
345 | + |
|
346 | + //some initial checks for proper values. |
|
347 | + //if QST_admin_only, then no matter what QST_required is we disable. |
|
348 | + if (! empty($this->_req_data['QST_admin_only'])) { |
|
349 | + $this->_req_data['QST_required'] = 0; |
|
350 | + } |
|
351 | + foreach ($model->field_settings() as $fieldName => $settings) { |
|
352 | + // basically if QSG_identifier is empty or not set |
|
353 | + if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
|
354 | + $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
|
355 | + $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
356 | 356 | // dd($set_column_values); |
357 | - } //if the admin label is blank, use a slug version of the question text |
|
358 | - else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
|
359 | - $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
|
360 | - $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
361 | - } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
362 | - $set_column_values[$fieldName] = 0; |
|
363 | - } else if ($fieldName === 'QST_max') { |
|
364 | - $qst_system = EEM_Question::instance()->get_var( |
|
365 | - array( |
|
366 | - array( |
|
367 | - 'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0, |
|
368 | - ), |
|
369 | - ), |
|
370 | - 'QST_system'); |
|
371 | - $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
372 | - if (empty($this->_req_data['QST_max']) || |
|
373 | - $this->_req_data['QST_max'] > $max_max |
|
374 | - ) { |
|
375 | - $set_column_values[$fieldName] = $max_max; |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - //only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
381 | - if ( |
|
382 | - ! isset($set_column_values[$fieldName]) && |
|
383 | - isset($this->_req_data[$fieldName]) |
|
384 | - ) { |
|
385 | - $set_column_values[$fieldName] = $this->_req_data[$fieldName]; |
|
386 | - } |
|
387 | - |
|
388 | - } |
|
389 | - return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - *_questions_overview_list_table |
|
395 | - */ |
|
396 | - protected function _questions_overview_list_table() |
|
397 | - { |
|
398 | - $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
399 | - $this->display_admin_list_table_page_with_sidebar(); |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * _edit_question |
|
405 | - */ |
|
406 | - protected function _edit_question() |
|
407 | - { |
|
408 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
409 | - $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false; |
|
410 | - |
|
411 | - switch ($this->_req_action) { |
|
412 | - case 'add_question' : |
|
413 | - $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
414 | - break; |
|
415 | - case 'edit_question' : |
|
416 | - $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
417 | - break; |
|
418 | - default : |
|
419 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
420 | - } |
|
421 | - |
|
422 | - // add PRC_ID to title if editing |
|
423 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
424 | - if ($ID) { |
|
425 | - $question = $this->_question_model->get_one_by_ID($ID); |
|
426 | - $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
427 | - $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
428 | - } else { |
|
429 | - $question = EE_Question::new_instance(); |
|
430 | - $question->set_order_to_latest(); |
|
431 | - $this->_set_add_edit_form_tags('insert_question'); |
|
432 | - } |
|
433 | - if( $question->system_ID() === EEM_Attendee::system_question_phone ){ |
|
434 | - $question_types = array_intersect_key( |
|
435 | - EEM_Question::instance()->allowed_question_types(), |
|
436 | - array_flip( |
|
437 | - array( |
|
438 | - EEM_Question::QST_type_text, |
|
439 | - EEM_Question::QST_type_us_phone |
|
440 | - ) |
|
441 | - ) |
|
442 | - ); |
|
443 | - } else { |
|
444 | - $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types(); |
|
445 | - } |
|
446 | - $this->_template_args['QST_ID'] = $ID; |
|
447 | - $this->_template_args['question'] = $question; |
|
448 | - $this->_template_args['question_types'] = $question_types; |
|
449 | - $this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question( |
|
450 | - $question->system_ID() |
|
451 | - ); |
|
452 | - $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
453 | - $this->_set_publish_post_box_vars('id', $ID); |
|
454 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
455 | - REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
456 | - $this->_template_args, true |
|
457 | - ); |
|
458 | - |
|
459 | - // the details template wrapper |
|
460 | - $this->display_admin_page_with_sidebar(); |
|
461 | - } |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * @return string |
|
466 | - */ |
|
467 | - protected function _get_question_type_descriptions() |
|
468 | - { |
|
469 | - EE_Registry::instance()->load_helper('HTML'); |
|
470 | - $descriptions = ''; |
|
471 | - $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
|
472 | - foreach ($question_type_descriptions as $type => $question_type_description) { |
|
473 | - if ($type == 'HTML_TEXTAREA') { |
|
474 | - $html = new EE_Simple_HTML_Validation_Strategy(); |
|
475 | - $question_type_description .= sprintf( |
|
476 | - esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
477 | - '<br/>', |
|
478 | - $html->get_list_of_allowed_tags() |
|
479 | - ); |
|
480 | - } |
|
481 | - $descriptions .= EEH_HTML::p( |
|
482 | - $question_type_description, |
|
483 | - 'question_type_description-' . $type, |
|
484 | - 'question_type_description description', |
|
485 | - 'display:none;' |
|
486 | - ); |
|
487 | - } |
|
488 | - return $descriptions; |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * @param bool|true $new_question |
|
494 | - * @throws \EE_Error |
|
495 | - */ |
|
496 | - protected function _insert_or_update_question($new_question = true) |
|
497 | - { |
|
498 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
499 | - $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
500 | - if ($new_question) { |
|
501 | - $question = EE_Question::new_instance($set_column_values); |
|
502 | - $action_desc = 'added'; |
|
503 | - } else { |
|
504 | - $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
505 | - $action_desc = 'updated'; |
|
506 | - } |
|
507 | - $success = $question->save(); |
|
508 | - $ID = $question->ID(); |
|
509 | - if ($ID && $question->should_have_question_options()) { |
|
510 | - //save the related options |
|
511 | - //trash removed options, save old ones |
|
512 | - //get list of all options |
|
513 | - $options = $question->options(); |
|
514 | - if (! empty($options)) { |
|
515 | - foreach ($options as $option_ID => $option) { |
|
516 | - $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
517 | - if ($option_req_index !== false) { |
|
518 | - $option->save($this->_req_data['question_options'][$option_req_index]); |
|
519 | - } else { |
|
520 | - //not found, remove it |
|
521 | - $option->delete(); |
|
522 | - } |
|
523 | - } |
|
524 | - } |
|
525 | - //save new related options |
|
526 | - foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
|
527 | - //skip $index that is from our sample |
|
528 | - if ( $index === 'xxcountxx' ) { |
|
529 | - continue; |
|
530 | - } |
|
531 | - //note we allow saving blank options. |
|
532 | - if (empty($option_req_data['QSO_ID']) |
|
533 | - ) {//no ID! save it! |
|
534 | - $new_option = EE_Question_Option::new_instance(array( |
|
535 | - 'QSO_value' => $option_req_data['QSO_value'], |
|
536 | - 'QSO_desc' => $option_req_data['QSO_desc'], |
|
537 | - 'QSO_order' => $option_req_data['QSO_order'], |
|
538 | - 'QST_ID' => $question->ID(), |
|
539 | - )); |
|
540 | - $new_option->save(); |
|
541 | - } |
|
542 | - } |
|
543 | - } |
|
544 | - $query_args = array('action' => 'edit_question', 'QST_ID' => $ID); |
|
545 | - if ($success !== false) { |
|
546 | - $msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
547 | - $this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'), |
|
548 | - $this->_question_model->item_name()); |
|
549 | - EE_Error::add_success($msg); |
|
550 | - } |
|
551 | - |
|
552 | - $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
553 | - } |
|
554 | - |
|
555 | - |
|
556 | - /** |
|
557 | - * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
558 | - * by ID |
|
559 | - * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
560 | - * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
561 | - * |
|
562 | - * @param int $ID of the question option to find |
|
563 | - * @return int index in question_options array if successful, FALSE if unsuccessful |
|
564 | - */ |
|
565 | - protected function _get_option_req_data_index($ID) |
|
566 | - { |
|
567 | - $req_data_for_question_options = $this->_req_data['question_options']; |
|
568 | - foreach ($req_data_for_question_options as $num => $option_data) { |
|
569 | - if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
570 | - return $num; |
|
571 | - } |
|
572 | - } |
|
573 | - return false; |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - |
|
578 | - |
|
579 | - /***********/ |
|
580 | - /* QUERIES */ |
|
581 | - /** |
|
582 | - * For internal use in getting all the query parameters |
|
583 | - * (because it's pretty well the same between question, question groups, |
|
584 | - * and for both when searching for trashed and untrashed ones) |
|
585 | - * |
|
586 | - * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
587 | - * @param int $per_page |
|
588 | - * @param int $current_page |
|
589 | - * @return array lik EEM_Base::get_all's $query_params parameter |
|
590 | - */ |
|
591 | - protected function get_query_params($model, $per_page = 10, $current_page = 10) |
|
592 | - { |
|
593 | - $query_params = array(); |
|
594 | - $offset = ($current_page - 1) * $per_page; |
|
595 | - $query_params['limit'] = array($offset, $per_page); |
|
596 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
597 | - $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
|
598 | - $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
|
599 | - $query_params['order_by'] = array($field_to_order_by => $order); |
|
600 | - $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
601 | - if (! empty($search_string)) { |
|
602 | - if ($model instanceof EEM_Question_Group) { |
|
603 | - $query_params[0] = array( |
|
604 | - 'OR' => array( |
|
605 | - 'QSG_name' => array('LIKE', "%$search_string%"), |
|
606 | - 'QSG_desc' => array('LIKE', "%$search_string%"), |
|
607 | - ), |
|
608 | - ); |
|
609 | - } else { |
|
610 | - $query_params[0] = array( |
|
611 | - 'QST_display_text' => array('LIKE', "%$search_string%"), |
|
612 | - ); |
|
613 | - } |
|
614 | - } |
|
615 | - |
|
616 | - //capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented) |
|
617 | - /*if ( $model instanceof EEM_Question_Group ) { |
|
357 | + } //if the admin label is blank, use a slug version of the question text |
|
358 | + else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
|
359 | + $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
|
360 | + $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
361 | + } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
362 | + $set_column_values[$fieldName] = 0; |
|
363 | + } else if ($fieldName === 'QST_max') { |
|
364 | + $qst_system = EEM_Question::instance()->get_var( |
|
365 | + array( |
|
366 | + array( |
|
367 | + 'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0, |
|
368 | + ), |
|
369 | + ), |
|
370 | + 'QST_system'); |
|
371 | + $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
372 | + if (empty($this->_req_data['QST_max']) || |
|
373 | + $this->_req_data['QST_max'] > $max_max |
|
374 | + ) { |
|
375 | + $set_column_values[$fieldName] = $max_max; |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + //only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
381 | + if ( |
|
382 | + ! isset($set_column_values[$fieldName]) && |
|
383 | + isset($this->_req_data[$fieldName]) |
|
384 | + ) { |
|
385 | + $set_column_values[$fieldName] = $this->_req_data[$fieldName]; |
|
386 | + } |
|
387 | + |
|
388 | + } |
|
389 | + return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + *_questions_overview_list_table |
|
395 | + */ |
|
396 | + protected function _questions_overview_list_table() |
|
397 | + { |
|
398 | + $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
399 | + $this->display_admin_list_table_page_with_sidebar(); |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * _edit_question |
|
405 | + */ |
|
406 | + protected function _edit_question() |
|
407 | + { |
|
408 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
409 | + $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false; |
|
410 | + |
|
411 | + switch ($this->_req_action) { |
|
412 | + case 'add_question' : |
|
413 | + $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
414 | + break; |
|
415 | + case 'edit_question' : |
|
416 | + $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
417 | + break; |
|
418 | + default : |
|
419 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
420 | + } |
|
421 | + |
|
422 | + // add PRC_ID to title if editing |
|
423 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
424 | + if ($ID) { |
|
425 | + $question = $this->_question_model->get_one_by_ID($ID); |
|
426 | + $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
427 | + $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
428 | + } else { |
|
429 | + $question = EE_Question::new_instance(); |
|
430 | + $question->set_order_to_latest(); |
|
431 | + $this->_set_add_edit_form_tags('insert_question'); |
|
432 | + } |
|
433 | + if( $question->system_ID() === EEM_Attendee::system_question_phone ){ |
|
434 | + $question_types = array_intersect_key( |
|
435 | + EEM_Question::instance()->allowed_question_types(), |
|
436 | + array_flip( |
|
437 | + array( |
|
438 | + EEM_Question::QST_type_text, |
|
439 | + EEM_Question::QST_type_us_phone |
|
440 | + ) |
|
441 | + ) |
|
442 | + ); |
|
443 | + } else { |
|
444 | + $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types(); |
|
445 | + } |
|
446 | + $this->_template_args['QST_ID'] = $ID; |
|
447 | + $this->_template_args['question'] = $question; |
|
448 | + $this->_template_args['question_types'] = $question_types; |
|
449 | + $this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question( |
|
450 | + $question->system_ID() |
|
451 | + ); |
|
452 | + $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
453 | + $this->_set_publish_post_box_vars('id', $ID); |
|
454 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
455 | + REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
456 | + $this->_template_args, true |
|
457 | + ); |
|
458 | + |
|
459 | + // the details template wrapper |
|
460 | + $this->display_admin_page_with_sidebar(); |
|
461 | + } |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * @return string |
|
466 | + */ |
|
467 | + protected function _get_question_type_descriptions() |
|
468 | + { |
|
469 | + EE_Registry::instance()->load_helper('HTML'); |
|
470 | + $descriptions = ''; |
|
471 | + $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
|
472 | + foreach ($question_type_descriptions as $type => $question_type_description) { |
|
473 | + if ($type == 'HTML_TEXTAREA') { |
|
474 | + $html = new EE_Simple_HTML_Validation_Strategy(); |
|
475 | + $question_type_description .= sprintf( |
|
476 | + esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
477 | + '<br/>', |
|
478 | + $html->get_list_of_allowed_tags() |
|
479 | + ); |
|
480 | + } |
|
481 | + $descriptions .= EEH_HTML::p( |
|
482 | + $question_type_description, |
|
483 | + 'question_type_description-' . $type, |
|
484 | + 'question_type_description description', |
|
485 | + 'display:none;' |
|
486 | + ); |
|
487 | + } |
|
488 | + return $descriptions; |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * @param bool|true $new_question |
|
494 | + * @throws \EE_Error |
|
495 | + */ |
|
496 | + protected function _insert_or_update_question($new_question = true) |
|
497 | + { |
|
498 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
499 | + $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
500 | + if ($new_question) { |
|
501 | + $question = EE_Question::new_instance($set_column_values); |
|
502 | + $action_desc = 'added'; |
|
503 | + } else { |
|
504 | + $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
505 | + $action_desc = 'updated'; |
|
506 | + } |
|
507 | + $success = $question->save(); |
|
508 | + $ID = $question->ID(); |
|
509 | + if ($ID && $question->should_have_question_options()) { |
|
510 | + //save the related options |
|
511 | + //trash removed options, save old ones |
|
512 | + //get list of all options |
|
513 | + $options = $question->options(); |
|
514 | + if (! empty($options)) { |
|
515 | + foreach ($options as $option_ID => $option) { |
|
516 | + $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
517 | + if ($option_req_index !== false) { |
|
518 | + $option->save($this->_req_data['question_options'][$option_req_index]); |
|
519 | + } else { |
|
520 | + //not found, remove it |
|
521 | + $option->delete(); |
|
522 | + } |
|
523 | + } |
|
524 | + } |
|
525 | + //save new related options |
|
526 | + foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
|
527 | + //skip $index that is from our sample |
|
528 | + if ( $index === 'xxcountxx' ) { |
|
529 | + continue; |
|
530 | + } |
|
531 | + //note we allow saving blank options. |
|
532 | + if (empty($option_req_data['QSO_ID']) |
|
533 | + ) {//no ID! save it! |
|
534 | + $new_option = EE_Question_Option::new_instance(array( |
|
535 | + 'QSO_value' => $option_req_data['QSO_value'], |
|
536 | + 'QSO_desc' => $option_req_data['QSO_desc'], |
|
537 | + 'QSO_order' => $option_req_data['QSO_order'], |
|
538 | + 'QST_ID' => $question->ID(), |
|
539 | + )); |
|
540 | + $new_option->save(); |
|
541 | + } |
|
542 | + } |
|
543 | + } |
|
544 | + $query_args = array('action' => 'edit_question', 'QST_ID' => $ID); |
|
545 | + if ($success !== false) { |
|
546 | + $msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
547 | + $this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'), |
|
548 | + $this->_question_model->item_name()); |
|
549 | + EE_Error::add_success($msg); |
|
550 | + } |
|
551 | + |
|
552 | + $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
553 | + } |
|
554 | + |
|
555 | + |
|
556 | + /** |
|
557 | + * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
558 | + * by ID |
|
559 | + * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
560 | + * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
561 | + * |
|
562 | + * @param int $ID of the question option to find |
|
563 | + * @return int index in question_options array if successful, FALSE if unsuccessful |
|
564 | + */ |
|
565 | + protected function _get_option_req_data_index($ID) |
|
566 | + { |
|
567 | + $req_data_for_question_options = $this->_req_data['question_options']; |
|
568 | + foreach ($req_data_for_question_options as $num => $option_data) { |
|
569 | + if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
570 | + return $num; |
|
571 | + } |
|
572 | + } |
|
573 | + return false; |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + |
|
578 | + |
|
579 | + /***********/ |
|
580 | + /* QUERIES */ |
|
581 | + /** |
|
582 | + * For internal use in getting all the query parameters |
|
583 | + * (because it's pretty well the same between question, question groups, |
|
584 | + * and for both when searching for trashed and untrashed ones) |
|
585 | + * |
|
586 | + * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
587 | + * @param int $per_page |
|
588 | + * @param int $current_page |
|
589 | + * @return array lik EEM_Base::get_all's $query_params parameter |
|
590 | + */ |
|
591 | + protected function get_query_params($model, $per_page = 10, $current_page = 10) |
|
592 | + { |
|
593 | + $query_params = array(); |
|
594 | + $offset = ($current_page - 1) * $per_page; |
|
595 | + $query_params['limit'] = array($offset, $per_page); |
|
596 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
597 | + $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
|
598 | + $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
|
599 | + $query_params['order_by'] = array($field_to_order_by => $order); |
|
600 | + $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
601 | + if (! empty($search_string)) { |
|
602 | + if ($model instanceof EEM_Question_Group) { |
|
603 | + $query_params[0] = array( |
|
604 | + 'OR' => array( |
|
605 | + 'QSG_name' => array('LIKE', "%$search_string%"), |
|
606 | + 'QSG_desc' => array('LIKE', "%$search_string%"), |
|
607 | + ), |
|
608 | + ); |
|
609 | + } else { |
|
610 | + $query_params[0] = array( |
|
611 | + 'QST_display_text' => array('LIKE', "%$search_string%"), |
|
612 | + ); |
|
613 | + } |
|
614 | + } |
|
615 | + |
|
616 | + //capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented) |
|
617 | + /*if ( $model instanceof EEM_Question_Group ) { |
|
618 | 618 | if ( ! EE_Registry::instance()->CAP->current_user_can( 'edit_others_question_groups', 'espresso_registration_form_edit_question_group' ) ) { |
619 | 619 | $query_params[0] = array( |
620 | 620 | 'AND' => array( |
@@ -644,62 +644,62 @@ discard block |
||
644 | 644 | } |
645 | 645 | }/**/ |
646 | 646 | |
647 | - return $query_params; |
|
648 | - |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * @param int $per_page |
|
654 | - * @param int $current_page |
|
655 | - * @param bool|false $count |
|
656 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
657 | - */ |
|
658 | - public function get_questions($per_page = 10, $current_page = 1, $count = false) |
|
659 | - { |
|
660 | - $QST = EEM_Question::instance(); |
|
661 | - $query_params = $this->get_query_params($QST, $per_page, $current_page); |
|
662 | - if ($count) { |
|
663 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
664 | - $results = $QST->count($where); |
|
665 | - } else { |
|
666 | - $results = $QST->get_all($query_params); |
|
667 | - } |
|
668 | - return $results; |
|
669 | - |
|
670 | - } |
|
671 | - |
|
672 | - |
|
673 | - /** |
|
674 | - * @param $per_page |
|
675 | - * @param int $current_page |
|
676 | - * @param bool|false $count |
|
677 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
678 | - */ |
|
679 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
680 | - { |
|
681 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
682 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
683 | - $questions = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params); |
|
684 | - return $questions; |
|
685 | - } |
|
686 | - |
|
687 | - |
|
688 | - /** |
|
689 | - * @param $per_page |
|
690 | - * @param int $current_page |
|
691 | - * @param bool|false $count |
|
692 | - * @return \EE_Soft_Delete_Base_Class[] |
|
693 | - */ |
|
694 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
695 | - { |
|
696 | - /** @type EEM_Question_Group $questionGroupModel */ |
|
697 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
698 | - //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
699 | - return $questionGroupModel->get_all( |
|
700 | - $this->get_query_params($questionGroupModel, $per_page, $current_page) |
|
701 | - ); |
|
702 | - } |
|
647 | + return $query_params; |
|
648 | + |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * @param int $per_page |
|
654 | + * @param int $current_page |
|
655 | + * @param bool|false $count |
|
656 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
657 | + */ |
|
658 | + public function get_questions($per_page = 10, $current_page = 1, $count = false) |
|
659 | + { |
|
660 | + $QST = EEM_Question::instance(); |
|
661 | + $query_params = $this->get_query_params($QST, $per_page, $current_page); |
|
662 | + if ($count) { |
|
663 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
664 | + $results = $QST->count($where); |
|
665 | + } else { |
|
666 | + $results = $QST->get_all($query_params); |
|
667 | + } |
|
668 | + return $results; |
|
669 | + |
|
670 | + } |
|
671 | + |
|
672 | + |
|
673 | + /** |
|
674 | + * @param $per_page |
|
675 | + * @param int $current_page |
|
676 | + * @param bool|false $count |
|
677 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
678 | + */ |
|
679 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
680 | + { |
|
681 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
682 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
683 | + $questions = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params); |
|
684 | + return $questions; |
|
685 | + } |
|
686 | + |
|
687 | + |
|
688 | + /** |
|
689 | + * @param $per_page |
|
690 | + * @param int $current_page |
|
691 | + * @param bool|false $count |
|
692 | + * @return \EE_Soft_Delete_Base_Class[] |
|
693 | + */ |
|
694 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
695 | + { |
|
696 | + /** @type EEM_Question_Group $questionGroupModel */ |
|
697 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
698 | + //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
699 | + return $questionGroupModel->get_all( |
|
700 | + $this->get_query_params($questionGroupModel, $per_page, $current_page) |
|
701 | + ); |
|
702 | + } |
|
703 | 703 | |
704 | 704 | |
705 | 705 | } //ends Registration_Form_Admin_Page class |
@@ -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 | |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function __construct($routing = true) |
68 | 68 | { |
69 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
70 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
69 | + require_once(EE_MODELS.'EEM_Question.model.php'); |
|
70 | + require_once(EE_MODELS.'EEM_Question_Group.model.php'); |
|
71 | 71 | $this->_question_model = EEM_Question::instance(); |
72 | 72 | $this->_question_group_model = EEM_Question_Group::instance(); |
73 | 73 | parent::__construct($routing); |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | public function load_scripts_styles() |
233 | 233 | { |
234 | 234 | wp_register_style('espresso_registration', |
235 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
235 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
236 | 236 | wp_enqueue_style('espresso_registration'); |
237 | 237 | } |
238 | 238 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | { |
259 | 259 | $this->load_scripts_styles_forms(); |
260 | 260 | wp_register_script('espresso_registration_form_single', |
261 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
261 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
262 | 262 | EVENT_ESPRESSO_VERSION, true); |
263 | 263 | wp_enqueue_script('espresso_registration_form_single'); |
264 | 264 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | { |
268 | 268 | $this->load_scripts_styles_forms(); |
269 | 269 | wp_register_script('espresso_registration_form_single', |
270 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
270 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
271 | 271 | EVENT_ESPRESSO_VERSION, true); |
272 | 272 | wp_enqueue_script('espresso_registration_form_single'); |
273 | 273 | } |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | |
276 | 276 | public function recaptcha_info_help_tab() |
277 | 277 | { |
278 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
278 | + $template = REGISTRATION_FORM_TEMPLATE_PATH.'recaptcha_info_help_tab.template.php'; |
|
279 | 279 | EEH_Template::display_template($template, array()); |
280 | 280 | } |
281 | 281 | |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | protected function _questions_groups_preview() |
325 | 325 | { |
326 | 326 | $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
327 | - $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
328 | - 'event_espresso') . '" />'; |
|
329 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
330 | - 'event_espresso') . '</strong>'; |
|
327 | + $this->_template_args['preview_img'] = '<img src="'.REGISTRATION_FORM_ASSETS_URL.'caf_reg_form_preview.jpg" alt="'.esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
328 | + 'event_espresso').'" />'; |
|
329 | + $this->_template_args['preview_text'] = '<strong>'.esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
330 | + 'event_espresso').'</strong>'; |
|
331 | 331 | $this->display_admin_caf_preview_page('question_groups_tab'); |
332 | 332 | } |
333 | 333 | |
@@ -345,20 +345,20 @@ discard block |
||
345 | 345 | |
346 | 346 | //some initial checks for proper values. |
347 | 347 | //if QST_admin_only, then no matter what QST_required is we disable. |
348 | - if (! empty($this->_req_data['QST_admin_only'])) { |
|
348 | + if ( ! empty($this->_req_data['QST_admin_only'])) { |
|
349 | 349 | $this->_req_data['QST_required'] = 0; |
350 | 350 | } |
351 | 351 | foreach ($model->field_settings() as $fieldName => $settings) { |
352 | 352 | // basically if QSG_identifier is empty or not set |
353 | 353 | if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
354 | 354 | $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
355 | - $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
355 | + $set_column_values[$fieldName] = sanitize_title($QSG_name).'-'.uniqid('', true); |
|
356 | 356 | // dd($set_column_values); |
357 | 357 | } //if the admin label is blank, use a slug version of the question text |
358 | 358 | else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
359 | 359 | $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
360 | 360 | $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
361 | - } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
361 | + } else if ($fieldName === 'QST_admin_only' && ( ! isset($this->_req_data['QST_admin_only']))) { |
|
362 | 362 | $set_column_values[$fieldName] = 0; |
363 | 363 | } else if ($fieldName === 'QST_max') { |
364 | 364 | $qst_system = EEM_Question::instance()->get_var( |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | ), |
369 | 369 | ), |
370 | 370 | 'QST_system'); |
371 | - $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
371 | + $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
372 | 372 | if (empty($this->_req_data['QST_max']) || |
373 | 373 | $this->_req_data['QST_max'] > $max_max |
374 | 374 | ) { |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | } |
387 | 387 | |
388 | 388 | } |
389 | - return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
389 | + return $set_column_values; //validation fo this data to be performed by the model before insertion. |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | } |
421 | 421 | |
422 | 422 | // add PRC_ID to title if editing |
423 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
423 | + $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title; |
|
424 | 424 | if ($ID) { |
425 | 425 | $question = $this->_question_model->get_one_by_ID($ID); |
426 | 426 | $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | $question->set_order_to_latest(); |
431 | 431 | $this->_set_add_edit_form_tags('insert_question'); |
432 | 432 | } |
433 | - if( $question->system_ID() === EEM_Attendee::system_question_phone ){ |
|
433 | + if ($question->system_ID() === EEM_Attendee::system_question_phone) { |
|
434 | 434 | $question_types = array_intersect_key( |
435 | 435 | EEM_Question::instance()->allowed_question_types(), |
436 | 436 | array_flip( |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
453 | 453 | $this->_set_publish_post_box_vars('id', $ID); |
454 | 454 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
455 | - REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
455 | + REGISTRATION_FORM_TEMPLATE_PATH.'questions_main_meta_box.template.php', |
|
456 | 456 | $this->_template_args, true |
457 | 457 | ); |
458 | 458 | |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | } |
481 | 481 | $descriptions .= EEH_HTML::p( |
482 | 482 | $question_type_description, |
483 | - 'question_type_description-' . $type, |
|
483 | + 'question_type_description-'.$type, |
|
484 | 484 | 'question_type_description description', |
485 | 485 | 'display:none;' |
486 | 486 | ); |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | $question = EE_Question::new_instance($set_column_values); |
502 | 502 | $action_desc = 'added'; |
503 | 503 | } else { |
504 | - $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
504 | + $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
505 | 505 | $action_desc = 'updated'; |
506 | 506 | } |
507 | 507 | $success = $question->save(); |
@@ -510,8 +510,8 @@ discard block |
||
510 | 510 | //save the related options |
511 | 511 | //trash removed options, save old ones |
512 | 512 | //get list of all options |
513 | - $options = $question->options(); |
|
514 | - if (! empty($options)) { |
|
513 | + $options = $question->options(); |
|
514 | + if ( ! empty($options)) { |
|
515 | 515 | foreach ($options as $option_ID => $option) { |
516 | 516 | $option_req_index = $this->_get_option_req_data_index($option_ID); |
517 | 517 | if ($option_req_index !== false) { |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | //save new related options |
526 | 526 | foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
527 | 527 | //skip $index that is from our sample |
528 | - if ( $index === 'xxcountxx' ) { |
|
528 | + if ($index === 'xxcountxx') { |
|
529 | 529 | continue; |
530 | 530 | } |
531 | 531 | //note we allow saving blank options. |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | { |
567 | 567 | $req_data_for_question_options = $this->_req_data['question_options']; |
568 | 568 | foreach ($req_data_for_question_options as $num => $option_data) { |
569 | - if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
569 | + if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) { |
|
570 | 570 | return $num; |
571 | 571 | } |
572 | 572 | } |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
599 | 599 | $query_params['order_by'] = array($field_to_order_by => $order); |
600 | 600 | $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
601 | - if (! empty($search_string)) { |
|
601 | + if ( ! empty($search_string)) { |
|
602 | 602 | if ($model instanceof EEM_Question_Group) { |
603 | 603 | $query_params[0] = array( |
604 | 604 | 'OR' => array( |
@@ -38,217 +38,217 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | |
64 | 64 | } else { |
65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | - /** |
|
68 | - * espresso_minimum_php_version_error |
|
69 | - * |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - function espresso_minimum_php_version_error() |
|
73 | - { |
|
74 | - ?> |
|
65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | + /** |
|
68 | + * espresso_minimum_php_version_error |
|
69 | + * |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + function espresso_minimum_php_version_error() |
|
73 | + { |
|
74 | + ?> |
|
75 | 75 | <div class="error"> |
76 | 76 | <p> |
77 | 77 | <?php |
78 | - printf( |
|
79 | - esc_html__( |
|
80 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
81 | - 'event_espresso' |
|
82 | - ), |
|
83 | - EE_MIN_PHP_VER_REQUIRED, |
|
84 | - PHP_VERSION, |
|
85 | - '<br/>', |
|
86 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
87 | - ); |
|
88 | - ?> |
|
78 | + printf( |
|
79 | + esc_html__( |
|
80 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
81 | + 'event_espresso' |
|
82 | + ), |
|
83 | + EE_MIN_PHP_VER_REQUIRED, |
|
84 | + PHP_VERSION, |
|
85 | + '<br/>', |
|
86 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
87 | + ); |
|
88 | + ?> |
|
89 | 89 | </p> |
90 | 90 | </div> |
91 | 91 | <?php |
92 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
93 | - } |
|
92 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
93 | + } |
|
94 | 94 | |
95 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
96 | - } else { |
|
97 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
98 | - /** |
|
99 | - * espresso_version |
|
100 | - * Returns the plugin version |
|
101 | - * |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - function espresso_version() |
|
105 | - { |
|
106 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.51.rc.006'); |
|
107 | - } |
|
95 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
96 | + } else { |
|
97 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
98 | + /** |
|
99 | + * espresso_version |
|
100 | + * Returns the plugin version |
|
101 | + * |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + function espresso_version() |
|
105 | + { |
|
106 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.51.rc.006'); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * espresso_plugin_activation |
|
111 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
112 | - */ |
|
113 | - function espresso_plugin_activation() |
|
114 | - { |
|
115 | - update_option('ee_espresso_activation', true); |
|
116 | - } |
|
109 | + /** |
|
110 | + * espresso_plugin_activation |
|
111 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
112 | + */ |
|
113 | + function espresso_plugin_activation() |
|
114 | + { |
|
115 | + update_option('ee_espresso_activation', true); |
|
116 | + } |
|
117 | 117 | |
118 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
119 | - /** |
|
120 | - * espresso_load_error_handling |
|
121 | - * this function loads EE's class for handling exceptions and errors |
|
122 | - */ |
|
123 | - function espresso_load_error_handling() |
|
124 | - { |
|
125 | - static $error_handling_loaded = false; |
|
126 | - if ($error_handling_loaded) { |
|
127 | - return; |
|
128 | - } |
|
129 | - // load debugging tools |
|
130 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
131 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
132 | - \EEH_Debug_Tools::instance(); |
|
133 | - } |
|
134 | - // load error handling |
|
135 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
136 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
137 | - } else { |
|
138 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
139 | - } |
|
140 | - $error_handling_loaded = true; |
|
141 | - } |
|
118 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
119 | + /** |
|
120 | + * espresso_load_error_handling |
|
121 | + * this function loads EE's class for handling exceptions and errors |
|
122 | + */ |
|
123 | + function espresso_load_error_handling() |
|
124 | + { |
|
125 | + static $error_handling_loaded = false; |
|
126 | + if ($error_handling_loaded) { |
|
127 | + return; |
|
128 | + } |
|
129 | + // load debugging tools |
|
130 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
131 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
132 | + \EEH_Debug_Tools::instance(); |
|
133 | + } |
|
134 | + // load error handling |
|
135 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
136 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
137 | + } else { |
|
138 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
139 | + } |
|
140 | + $error_handling_loaded = true; |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * espresso_load_required |
|
145 | - * given a class name and path, this function will load that file or throw an exception |
|
146 | - * |
|
147 | - * @param string $classname |
|
148 | - * @param string $full_path_to_file |
|
149 | - * @throws EE_Error |
|
150 | - */ |
|
151 | - function espresso_load_required($classname, $full_path_to_file) |
|
152 | - { |
|
153 | - if (is_readable($full_path_to_file)) { |
|
154 | - require_once $full_path_to_file; |
|
155 | - } else { |
|
156 | - throw new \EE_Error ( |
|
157 | - sprintf( |
|
158 | - esc_html__( |
|
159 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
160 | - 'event_espresso' |
|
161 | - ), |
|
162 | - $classname |
|
163 | - ) |
|
164 | - ); |
|
165 | - } |
|
166 | - } |
|
143 | + /** |
|
144 | + * espresso_load_required |
|
145 | + * given a class name and path, this function will load that file or throw an exception |
|
146 | + * |
|
147 | + * @param string $classname |
|
148 | + * @param string $full_path_to_file |
|
149 | + * @throws EE_Error |
|
150 | + */ |
|
151 | + function espresso_load_required($classname, $full_path_to_file) |
|
152 | + { |
|
153 | + if (is_readable($full_path_to_file)) { |
|
154 | + require_once $full_path_to_file; |
|
155 | + } else { |
|
156 | + throw new \EE_Error ( |
|
157 | + sprintf( |
|
158 | + esc_html__( |
|
159 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
160 | + 'event_espresso' |
|
161 | + ), |
|
162 | + $classname |
|
163 | + ) |
|
164 | + ); |
|
165 | + } |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * @since 4.9.27 |
|
170 | - * @throws \EE_Error |
|
171 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
172 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
173 | - * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
174 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
175 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
176 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
177 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
178 | - * @throws \OutOfBoundsException |
|
179 | - */ |
|
180 | - function bootstrap_espresso() |
|
181 | - { |
|
182 | - require_once __DIR__ . '/core/espresso_definitions.php'; |
|
183 | - try { |
|
184 | - espresso_load_error_handling(); |
|
185 | - espresso_load_required( |
|
186 | - 'EEH_Base', |
|
187 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
188 | - ); |
|
189 | - espresso_load_required( |
|
190 | - 'EEH_File', |
|
191 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
192 | - ); |
|
193 | - espresso_load_required( |
|
194 | - 'EEH_File', |
|
195 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
196 | - ); |
|
197 | - espresso_load_required( |
|
198 | - 'EEH_Array', |
|
199 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
200 | - ); |
|
201 | - // instantiate and configure PSR4 autoloader |
|
202 | - espresso_load_required( |
|
203 | - 'Psr4Autoloader', |
|
204 | - EE_CORE . 'Psr4Autoloader.php' |
|
205 | - ); |
|
206 | - espresso_load_required( |
|
207 | - 'EE_Psr4AutoloaderInit', |
|
208 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
209 | - ); |
|
210 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
211 | - $AutoloaderInit->initializeAutoloader(); |
|
212 | - espresso_load_required( |
|
213 | - 'EE_Request', |
|
214 | - EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
215 | - ); |
|
216 | - espresso_load_required( |
|
217 | - 'EE_Response', |
|
218 | - EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
219 | - ); |
|
220 | - espresso_load_required( |
|
221 | - 'EE_Bootstrap', |
|
222 | - EE_CORE . 'EE_Bootstrap.core.php' |
|
223 | - ); |
|
224 | - // bootstrap EE and the request stack |
|
225 | - new EE_Bootstrap( |
|
226 | - new EE_Request($_GET, $_POST, $_COOKIE), |
|
227 | - new EE_Response() |
|
228 | - ); |
|
229 | - } catch (Exception $e) { |
|
230 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
231 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
232 | - } |
|
233 | - } |
|
234 | - bootstrap_espresso(); |
|
235 | - } |
|
168 | + /** |
|
169 | + * @since 4.9.27 |
|
170 | + * @throws \EE_Error |
|
171 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
172 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
173 | + * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
174 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
175 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
176 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
177 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
178 | + * @throws \OutOfBoundsException |
|
179 | + */ |
|
180 | + function bootstrap_espresso() |
|
181 | + { |
|
182 | + require_once __DIR__ . '/core/espresso_definitions.php'; |
|
183 | + try { |
|
184 | + espresso_load_error_handling(); |
|
185 | + espresso_load_required( |
|
186 | + 'EEH_Base', |
|
187 | + EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
188 | + ); |
|
189 | + espresso_load_required( |
|
190 | + 'EEH_File', |
|
191 | + EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
192 | + ); |
|
193 | + espresso_load_required( |
|
194 | + 'EEH_File', |
|
195 | + EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
196 | + ); |
|
197 | + espresso_load_required( |
|
198 | + 'EEH_Array', |
|
199 | + EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
200 | + ); |
|
201 | + // instantiate and configure PSR4 autoloader |
|
202 | + espresso_load_required( |
|
203 | + 'Psr4Autoloader', |
|
204 | + EE_CORE . 'Psr4Autoloader.php' |
|
205 | + ); |
|
206 | + espresso_load_required( |
|
207 | + 'EE_Psr4AutoloaderInit', |
|
208 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
209 | + ); |
|
210 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
211 | + $AutoloaderInit->initializeAutoloader(); |
|
212 | + espresso_load_required( |
|
213 | + 'EE_Request', |
|
214 | + EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
215 | + ); |
|
216 | + espresso_load_required( |
|
217 | + 'EE_Response', |
|
218 | + EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
219 | + ); |
|
220 | + espresso_load_required( |
|
221 | + 'EE_Bootstrap', |
|
222 | + EE_CORE . 'EE_Bootstrap.core.php' |
|
223 | + ); |
|
224 | + // bootstrap EE and the request stack |
|
225 | + new EE_Bootstrap( |
|
226 | + new EE_Request($_GET, $_POST, $_COOKIE), |
|
227 | + new EE_Response() |
|
228 | + ); |
|
229 | + } catch (Exception $e) { |
|
230 | + require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
231 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
232 | + } |
|
233 | + } |
|
234 | + bootstrap_espresso(); |
|
235 | + } |
|
236 | 236 | } |
237 | 237 | if (! function_exists('espresso_deactivate_plugin')) { |
238 | - /** |
|
239 | - * deactivate_plugin |
|
240 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
241 | - * |
|
242 | - * @access public |
|
243 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
244 | - * @return void |
|
245 | - */ |
|
246 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
247 | - { |
|
248 | - if (! function_exists('deactivate_plugins')) { |
|
249 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
250 | - } |
|
251 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
252 | - deactivate_plugins($plugin_basename); |
|
253 | - } |
|
238 | + /** |
|
239 | + * deactivate_plugin |
|
240 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
241 | + * |
|
242 | + * @access public |
|
243 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
244 | + * @return void |
|
245 | + */ |
|
246 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
247 | + { |
|
248 | + if (! function_exists('deactivate_plugins')) { |
|
249 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
250 | + } |
|
251 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
252 | + deactivate_plugins($plugin_basename); |
|
253 | + } |
|
254 | 254 | } |
@@ -311,8 +311,8 @@ discard block |
||
311 | 311 | //eg if given "/var/something/somewhere/", we want to get "somewhere"'s |
312 | 312 | //parent folder, "/var/something/" |
313 | 313 | $ds = strlen($file_or_folder_path) > 1 |
314 | - ? strrpos($file_or_folder_path, DS, -2) |
|
315 | - : strlen($file_or_folder_path); |
|
314 | + ? strrpos($file_or_folder_path, DS, -2) |
|
315 | + : strlen($file_or_folder_path); |
|
316 | 316 | return substr($file_or_folder_path, 0, $ds + 1); |
317 | 317 | } |
318 | 318 | |
@@ -658,14 +658,14 @@ discard block |
||
658 | 658 | |
659 | 659 | |
660 | 660 | |
661 | - /** |
|
662 | - * Resets the file helper's state. Useful between tests that may have used a mock |
|
663 | - * filesystem. |
|
664 | - */ |
|
661 | + /** |
|
662 | + * Resets the file helper's state. Useful between tests that may have used a mock |
|
663 | + * filesystem. |
|
664 | + */ |
|
665 | 665 | public static function reset() |
666 | - { |
|
667 | - self::$_wp_filesystem_direct = null; |
|
668 | - } |
|
666 | + { |
|
667 | + self::$_wp_filesystem_direct = null; |
|
668 | + } |
|
669 | 669 | } |
670 | 670 | // End of file EEH_File.helper.php |
671 | 671 | // Location: /helpers/EEH_File.helper.php |
672 | 672 | \ No newline at end of file |
@@ -38,30 +38,30 @@ discard block |
||
38 | 38 | * @throws EE_Error if filesystem credentials are required |
39 | 39 | * @return WP_Filesystem_Base |
40 | 40 | */ |
41 | - private static function _get_wp_filesystem( $filepath = null) { |
|
42 | - if( apply_filters( |
|
41 | + private static function _get_wp_filesystem($filepath = null) { |
|
42 | + if (apply_filters( |
|
43 | 43 | 'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', |
44 | - $filepath && EEH_File::is_in_uploads_folder( $filepath ), |
|
45 | - $filepath ) ) { |
|
46 | - if( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct ) { |
|
47 | - require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); |
|
44 | + $filepath && EEH_File::is_in_uploads_folder($filepath), |
|
45 | + $filepath )) { |
|
46 | + if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) { |
|
47 | + require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php'); |
|
48 | 48 | $method = 'direct'; |
49 | - $wp_filesystem_direct_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method ); |
|
49 | + $wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method); |
|
50 | 50 | //check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem() |
51 | - if ( ! defined('FS_CHMOD_DIR') ) { |
|
52 | - define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) ); |
|
51 | + if ( ! defined('FS_CHMOD_DIR')) { |
|
52 | + define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755)); |
|
53 | 53 | } |
54 | - if ( ! defined('FS_CHMOD_FILE') ) { |
|
55 | - define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) ); |
|
54 | + if ( ! defined('FS_CHMOD_FILE')) { |
|
55 | + define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644)); |
|
56 | 56 | } |
57 | - require_once( $wp_filesystem_direct_file ); |
|
58 | - EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct( array() ); |
|
57 | + require_once($wp_filesystem_direct_file); |
|
58 | + EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array()); |
|
59 | 59 | } |
60 | 60 | return EEH_File::$_wp_filesystem_direct; |
61 | 61 | } |
62 | 62 | global $wp_filesystem; |
63 | 63 | // no filesystem setup ??? |
64 | - if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) { |
|
64 | + if ( ! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
65 | 65 | // if some eager beaver's just trying to get in there too early... |
66 | 66 | // let them do it, because we are one of those eager beavers! :P |
67 | 67 | /** |
@@ -74,34 +74,34 @@ discard block |
||
74 | 74 | * and there may be troubles if the WP files are owned by a different user |
75 | 75 | * than the server user. But both of these issues should exist in 4.4 and earlier too |
76 | 76 | */ |
77 | - if ( FALSE && ! did_action( 'wp_loaded' )) { |
|
77 | + if (FALSE && ! did_action('wp_loaded')) { |
|
78 | 78 | $msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'); |
79 | - if ( WP_DEBUG ) { |
|
80 | - $msg .= '<br />' . __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
79 | + if (WP_DEBUG) { |
|
80 | + $msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso'); |
|
81 | 81 | } |
82 | - throw new EE_Error( $msg ); |
|
82 | + throw new EE_Error($msg); |
|
83 | 83 | } else { |
84 | 84 | // should be loaded if we are past the wp_loaded hook... |
85 | - if ( ! function_exists( 'WP_Filesystem' )) { |
|
86 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
87 | - require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
|
85 | + if ( ! function_exists('WP_Filesystem')) { |
|
86 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
87 | + require_once(ABSPATH.'wp-admin/includes/template.php'); |
|
88 | 88 | } |
89 | 89 | // turn on output buffering so that we can capture the credentials form |
90 | 90 | ob_start(); |
91 | - $credentials = request_filesystem_credentials( '' ); |
|
91 | + $credentials = request_filesystem_credentials(''); |
|
92 | 92 | // store credentials form for the time being |
93 | 93 | EEH_File::$_credentials_form = ob_get_clean(); |
94 | 94 | // basically check for direct or previously configured access |
95 | - if ( ! WP_Filesystem( $credentials ) ) { |
|
95 | + if ( ! WP_Filesystem($credentials)) { |
|
96 | 96 | // if credentials do NOT exist |
97 | - if ( $credentials === FALSE ) { |
|
98 | - add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 ); |
|
99 | - throw new EE_Error( __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
|
100 | - } elseif( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
101 | - add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 ); |
|
97 | + if ($credentials === FALSE) { |
|
98 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
99 | + throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso')); |
|
100 | + } elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { |
|
101 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
102 | 102 | throw new EE_Error( |
103 | 103 | sprintf( |
104 | - __( 'WP Filesystem Error: $1%s', 'event_espresso' ), |
|
104 | + __('WP Filesystem Error: $1%s', 'event_espresso'), |
|
105 | 105 | $wp_filesystem->errors->get_error_message() ) ); |
106 | 106 | } |
107 | 107 | } |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * display_request_filesystem_credentials_form |
115 | 115 | */ |
116 | 116 | public static function display_request_filesystem_credentials_form() { |
117 | - if ( ! empty( EEH_File::$_credentials_form )) { |
|
118 | - echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>'; |
|
117 | + if ( ! empty(EEH_File::$_credentials_form)) { |
|
118 | + echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>'; |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
@@ -133,29 +133,29 @@ discard block |
||
133 | 133 | * @throws EE_Error if filesystem credentials are required |
134 | 134 | * @return bool |
135 | 135 | */ |
136 | - public static function verify_filepath_and_permissions( $full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '' ) { |
|
136 | + public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') { |
|
137 | 137 | // load WP_Filesystem and set file permissions |
138 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
139 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
140 | - if ( ! $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) )) { |
|
141 | - $file_name = ! empty( $type_of_file ) ? $file_name . ' ' . $type_of_file : $file_name; |
|
142 | - $file_name .= ! empty( $file_ext ) ? ' file' : ' folder'; |
|
138 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
139 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
140 | + if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
141 | + $file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name; |
|
142 | + $file_name .= ! empty($file_ext) ? ' file' : ' folder'; |
|
143 | 143 | $msg = sprintf( |
144 | - __( 'The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso' ), |
|
144 | + __('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'), |
|
145 | 145 | $file_name, |
146 | 146 | '<br />' |
147 | 147 | ); |
148 | - if ( EEH_File::exists( $full_file_path )) { |
|
149 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, $type_of_file ); |
|
148 | + if (EEH_File::exists($full_file_path)) { |
|
149 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file); |
|
150 | 150 | } else { |
151 | 151 | // no file permissions means the file was not found |
152 | 152 | $msg .= sprintf( |
153 | - __( 'Please ensure the following path is correct: "%s".', 'event_espresso' ), |
|
153 | + __('Please ensure the following path is correct: "%s".', 'event_espresso'), |
|
154 | 154 | $full_file_path |
155 | 155 | ); |
156 | 156 | } |
157 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
158 | - throw new EE_Error( $msg . '||' . $msg ); |
|
157 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
158 | + throw new EE_Error($msg.'||'.$msg); |
|
159 | 159 | } |
160 | 160 | return FALSE; |
161 | 161 | } |
@@ -173,24 +173,24 @@ discard block |
||
173 | 173 | * @throws EE_Error if filesystem credentials are required |
174 | 174 | * @return string |
175 | 175 | */ |
176 | - private static function _permissions_error_for_unreadable_filepath( $full_file_path = '', $type_of_file = '' ){ |
|
176 | + private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') { |
|
177 | 177 | // load WP_Filesystem and set file permissions |
178 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
178 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
179 | 179 | // check file permissions |
180 | - $perms = $wp_filesystem->getchmod( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ); |
|
181 | - if ( $perms ) { |
|
180 | + $perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
181 | + if ($perms) { |
|
182 | 182 | // file permissions exist, but way be set incorrectly |
183 | - $type_of_file = ! empty( $type_of_file ) ? $type_of_file . ' ' : ''; |
|
184 | - $type_of_file .= ! empty( $type_of_file ) ? 'file' : 'folder'; |
|
183 | + $type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : ''; |
|
184 | + $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder'; |
|
185 | 185 | return sprintf( |
186 | - __( 'File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso' ), |
|
186 | + __('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'), |
|
187 | 187 | $type_of_file, |
188 | 188 | $perms |
189 | 189 | ); |
190 | 190 | } else { |
191 | 191 | // file exists but file permissions could not be read ?!?! |
192 | 192 | return sprintf( |
193 | - __( 'Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso' ), |
|
193 | + __('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'), |
|
194 | 194 | $full_file_path |
195 | 195 | ); |
196 | 196 | } |
@@ -208,35 +208,35 @@ discard block |
||
208 | 208 | * can't write to it |
209 | 209 | * @return bool false if folder isn't writable; true if it exists and is writeable, |
210 | 210 | */ |
211 | - public static function ensure_folder_exists_and_is_writable( $folder = '' ){ |
|
212 | - if ( empty( $folder )) { |
|
211 | + public static function ensure_folder_exists_and_is_writable($folder = '') { |
|
212 | + if (empty($folder)) { |
|
213 | 213 | return false; |
214 | 214 | } |
215 | 215 | // remove ending DS |
216 | - $folder = EEH_File::standardise_directory_separators( rtrim( $folder, '/\\' )); |
|
217 | - $parent_folder = EEH_File::get_parent_folder( $folder ); |
|
216 | + $folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\')); |
|
217 | + $parent_folder = EEH_File::get_parent_folder($folder); |
|
218 | 218 | // add DS to folder |
219 | - $folder = EEH_File::end_with_directory_separator( $folder ); |
|
220 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $folder ); |
|
221 | - if ( ! $wp_filesystem->is_dir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) { |
|
219 | + $folder = EEH_File::end_with_directory_separator($folder); |
|
220 | + $wp_filesystem = EEH_File::_get_wp_filesystem($folder); |
|
221 | + if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
222 | 222 | //ok so it doesn't exist. Does its parent? Can we write to it? |
223 | - if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) { |
|
223 | + if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
224 | 224 | return false; |
225 | 225 | } |
226 | - if ( ! EEH_File::verify_is_writable( $parent_folder, 'folder' )) { |
|
226 | + if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
227 | 227 | return false; |
228 | 228 | } else { |
229 | - if ( ! $wp_filesystem->mkdir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) { |
|
230 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
231 | - $msg = sprintf( __( '"%s" could not be created.', 'event_espresso' ), $folder ); |
|
232 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $folder ); |
|
233 | - throw new EE_Error( $msg ); |
|
229 | + if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) { |
|
230 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
231 | + $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder); |
|
232 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder); |
|
233 | + throw new EE_Error($msg); |
|
234 | 234 | } |
235 | 235 | return false; |
236 | 236 | } |
237 | - EEH_File::add_index_file( $folder ); |
|
237 | + EEH_File::add_index_file($folder); |
|
238 | 238 | } |
239 | - } elseif ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
239 | + } elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
240 | 240 | return false; |
241 | 241 | } |
242 | 242 | return true; |
@@ -251,15 +251,15 @@ discard block |
||
251 | 251 | * @throws EE_Error if filesystem credentials are required |
252 | 252 | * @return bool |
253 | 253 | */ |
254 | - public static function verify_is_writable( $full_path = '', $file_or_folder = 'folder' ){ |
|
254 | + public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') { |
|
255 | 255 | // load WP_Filesystem and set file permissions |
256 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_path ); |
|
257 | - $full_path = EEH_File::standardise_directory_separators( $full_path ); |
|
258 | - if ( ! $wp_filesystem->is_writable( EEH_File::convert_local_filepath_to_remote_filepath( $full_path ) ) ) { |
|
259 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
260 | - $msg = sprintf( __( 'The "%1$s" %2$s is not writable.', 'event_espresso' ), $full_path, $file_or_folder ); |
|
261 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_path ); |
|
262 | - throw new EE_Error( $msg ); |
|
256 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_path); |
|
257 | + $full_path = EEH_File::standardise_directory_separators($full_path); |
|
258 | + if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) { |
|
259 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
260 | + $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder); |
|
261 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path); |
|
262 | + throw new EE_Error($msg); |
|
263 | 263 | } |
264 | 264 | return FALSE; |
265 | 265 | } |
@@ -276,25 +276,25 @@ discard block |
||
276 | 276 | * @throws EE_Error if filesystem credentials are required |
277 | 277 | * @return bool |
278 | 278 | */ |
279 | - public static function ensure_file_exists_and_is_writable( $full_file_path = '' ) { |
|
279 | + public static function ensure_file_exists_and_is_writable($full_file_path = '') { |
|
280 | 280 | // load WP_Filesystem and set file permissions |
281 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
282 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
283 | - $parent_folder = EEH_File::get_parent_folder( $full_file_path ); |
|
284 | - if ( ! EEH_File::exists( $full_file_path )) { |
|
285 | - if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) { |
|
281 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
282 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
283 | + $parent_folder = EEH_File::get_parent_folder($full_file_path); |
|
284 | + if ( ! EEH_File::exists($full_file_path)) { |
|
285 | + if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) { |
|
286 | 286 | return false; |
287 | 287 | } |
288 | - if ( ! $wp_filesystem->touch( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) { |
|
289 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
290 | - $msg = sprintf( __( 'The "%s" file could not be created.', 'event_espresso' ), $full_file_path ); |
|
291 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path ); |
|
292 | - throw new EE_Error( $msg ); |
|
288 | + if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
289 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
290 | + $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path); |
|
291 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
292 | + throw new EE_Error($msg); |
|
293 | 293 | } |
294 | 294 | return false; |
295 | 295 | } |
296 | 296 | } |
297 | - if ( ! EEH_File::verify_is_writable( $full_file_path, 'file' )) { |
|
297 | + if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
298 | 298 | return false; |
299 | 299 | } |
300 | 300 | return true; |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | * @param string $file_or_folder_path |
307 | 307 | * @return string parent folder, ENDING with a directory separator |
308 | 308 | */ |
309 | - public static function get_parent_folder( $file_or_folder_path ) { |
|
309 | + public static function get_parent_folder($file_or_folder_path) { |
|
310 | 310 | //find the last DS, ignoring a DS on the very end |
311 | 311 | //eg if given "/var/something/somewhere/", we want to get "somewhere"'s |
312 | 312 | //parent folder, "/var/something/" |
@@ -328,12 +328,12 @@ discard block |
||
328 | 328 | * @throws EE_Error if filesystem credentials are required |
329 | 329 | * @return string |
330 | 330 | */ |
331 | - public static function get_file_contents( $full_file_path = '' ){ |
|
332 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
333 | - if ( EEH_File::verify_filepath_and_permissions( $full_file_path, EEH_File::get_filename_from_filepath( $full_file_path ) , EEH_File::get_file_extension( $full_file_path ))) { |
|
331 | + public static function get_file_contents($full_file_path = '') { |
|
332 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
333 | + if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) { |
|
334 | 334 | // load WP_Filesystem and set file permissions |
335 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
336 | - return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ); |
|
335 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
336 | + return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)); |
|
337 | 337 | } |
338 | 338 | return ''; |
339 | 339 | } |
@@ -348,26 +348,26 @@ discard block |
||
348 | 348 | * @throws EE_Error if filesystem credentials are required |
349 | 349 | * @return bool |
350 | 350 | */ |
351 | - public static function write_to_file( $full_file_path = '', $file_contents = '', $file_type = '' ){ |
|
352 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
353 | - $file_type = ! empty( $file_type ) ? rtrim( $file_type, ' ' ) . ' ' : ''; |
|
354 | - $folder = EEH_File::remove_filename_from_filepath( $full_file_path ); |
|
355 | - if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
356 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
357 | - $msg = sprintf( __( 'The %1$sfile located at "%2$s" is not writable.', 'event_espresso' ), $file_type, $full_file_path ); |
|
358 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path ); |
|
359 | - throw new EE_Error( $msg ); |
|
351 | + public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') { |
|
352 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
353 | + $file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : ''; |
|
354 | + $folder = EEH_File::remove_filename_from_filepath($full_file_path); |
|
355 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
356 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
357 | + $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path); |
|
358 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
359 | + throw new EE_Error($msg); |
|
360 | 360 | } |
361 | 361 | return FALSE; |
362 | 362 | } |
363 | 363 | // load WP_Filesystem and set file permissions |
364 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
364 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
365 | 365 | // write the file |
366 | - if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ), $file_contents )) { |
|
367 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
368 | - $msg = sprintf( __( 'The %1$sfile located at "%2$s" could not be written to.', 'event_espresso' ), $file_type, $full_file_path ); |
|
369 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, 'f' ); |
|
370 | - throw new EE_Error( $msg ); |
|
366 | + if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) { |
|
367 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
368 | + $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path); |
|
369 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f'); |
|
370 | + throw new EE_Error($msg); |
|
371 | 371 | } |
372 | 372 | return FALSE; |
373 | 373 | } |
@@ -383,9 +383,9 @@ discard block |
||
383 | 383 | * @throws EE_Error if filesystem credentials are required |
384 | 384 | * @return boolean |
385 | 385 | */ |
386 | - public static function delete( $filepath, $recursive = false, $type = false ) { |
|
386 | + public static function delete($filepath, $recursive = false, $type = false) { |
|
387 | 387 | $wp_filesystem = EEH_File::_get_wp_filesystem(); |
388 | - return $wp_filesystem->delete( $filepath, $recursive, $type ) ? TRUE : FALSE; |
|
388 | + return $wp_filesystem->delete($filepath, $recursive, $type) ? TRUE : FALSE; |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | |
@@ -397,9 +397,9 @@ discard block |
||
397 | 397 | * @throws EE_Error if filesystem credentials are required |
398 | 398 | * @return bool |
399 | 399 | */ |
400 | - public static function exists( $full_file_path = '' ) { |
|
401 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
402 | - return $wp_filesystem->exists( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ? TRUE : FALSE; |
|
400 | + public static function exists($full_file_path = '') { |
|
401 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
402 | + return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? TRUE : FALSE; |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | |
@@ -412,9 +412,9 @@ discard block |
||
412 | 412 | * @throws EE_Error if filesystem credentials are required |
413 | 413 | * @return bool |
414 | 414 | */ |
415 | - public static function is_readable( $full_file_path = '' ) { |
|
416 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path ); |
|
417 | - if( $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) { |
|
415 | + public static function is_readable($full_file_path = '') { |
|
416 | + $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path); |
|
417 | + if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) { |
|
418 | 418 | return true; |
419 | 419 | } else { |
420 | 420 | return false; |
@@ -430,8 +430,8 @@ discard block |
||
430 | 430 | * @param string $full_file_path |
431 | 431 | * @return string |
432 | 432 | */ |
433 | - public static function remove_filename_from_filepath( $full_file_path = '' ) { |
|
434 | - return pathinfo( $full_file_path, PATHINFO_DIRNAME ); |
|
433 | + public static function remove_filename_from_filepath($full_file_path = '') { |
|
434 | + return pathinfo($full_file_path, PATHINFO_DIRNAME); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | |
@@ -441,8 +441,8 @@ discard block |
||
441 | 441 | * @param string $full_file_path |
442 | 442 | * @return string |
443 | 443 | */ |
444 | - public static function get_filename_from_filepath( $full_file_path = '' ) { |
|
445 | - return pathinfo( $full_file_path, PATHINFO_BASENAME ); |
|
444 | + public static function get_filename_from_filepath($full_file_path = '') { |
|
445 | + return pathinfo($full_file_path, PATHINFO_BASENAME); |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | |
@@ -452,8 +452,8 @@ discard block |
||
452 | 452 | * @param string $full_file_path |
453 | 453 | * @return string |
454 | 454 | */ |
455 | - public static function get_file_extension( $full_file_path = '' ) { |
|
456 | - return pathinfo( $full_file_path, PATHINFO_EXTENSION ); |
|
455 | + public static function get_file_extension($full_file_path = '') { |
|
456 | + return pathinfo($full_file_path, PATHINFO_EXTENSION); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | |
@@ -464,10 +464,10 @@ discard block |
||
464 | 464 | * @throws EE_Error if filesystem credentials are required |
465 | 465 | * @return bool |
466 | 466 | */ |
467 | - public static function add_htaccess_deny_from_all( $folder = '' ) { |
|
468 | - $folder = EEH_File::standardise_and_end_with_directory_separator( $folder ); |
|
469 | - if ( ! EEH_File::exists( $folder . '.htaccess' ) ) { |
|
470 | - if ( ! EEH_File::write_to_file( $folder . '.htaccess', 'deny from all', '.htaccess' )) { |
|
467 | + public static function add_htaccess_deny_from_all($folder = '') { |
|
468 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
469 | + if ( ! EEH_File::exists($folder.'.htaccess')) { |
|
470 | + if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) { |
|
471 | 471 | return FALSE; |
472 | 472 | } |
473 | 473 | } |
@@ -481,10 +481,10 @@ discard block |
||
481 | 481 | * @throws EE_Error if filesystem credentials are required |
482 | 482 | * @return boolean |
483 | 483 | */ |
484 | - public static function add_index_file( $folder ) { |
|
485 | - $folder = EEH_File::standardise_and_end_with_directory_separator( $folder ); |
|
486 | - if ( ! EEH_File::exists( $folder . 'index.php' ) ) { |
|
487 | - if ( ! EEH_File::write_to_file( $folder . 'index.php', 'You are not permitted to read from this folder', '.php' )) { |
|
484 | + public static function add_index_file($folder) { |
|
485 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
486 | + if ( ! EEH_File::exists($folder.'index.php')) { |
|
487 | + if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) { |
|
488 | 488 | return false; |
489 | 489 | } |
490 | 490 | } |
@@ -499,11 +499,11 @@ discard block |
||
499 | 499 | * @param string $file_path |
500 | 500 | * @return string |
501 | 501 | */ |
502 | - public static function get_classname_from_filepath_with_standard_filename( $file_path ){ |
|
502 | + public static function get_classname_from_filepath_with_standard_filename($file_path) { |
|
503 | 503 | //extract file from path |
504 | - $filename = basename( $file_path ); |
|
504 | + $filename = basename($file_path); |
|
505 | 505 | //now remove the first period and everything after |
506 | - $pos_of_first_period = strpos( $filename,'.' ); |
|
506 | + $pos_of_first_period = strpos($filename, '.'); |
|
507 | 507 | return substr($filename, 0, $pos_of_first_period); |
508 | 508 | } |
509 | 509 | |
@@ -515,8 +515,8 @@ discard block |
||
515 | 515 | * @param string $file_path |
516 | 516 | * @return string |
517 | 517 | */ |
518 | - public static function standardise_directory_separators( $file_path ){ |
|
519 | - return str_replace( array( '\\', '/' ), DS, $file_path ); |
|
518 | + public static function standardise_directory_separators($file_path) { |
|
519 | + return str_replace(array('\\', '/'), DS, $file_path); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | |
@@ -527,8 +527,8 @@ discard block |
||
527 | 527 | * @param string $file_path |
528 | 528 | * @return string |
529 | 529 | */ |
530 | - public static function end_with_directory_separator( $file_path ){ |
|
531 | - return rtrim( $file_path, '/\\' ) . DS; |
|
530 | + public static function end_with_directory_separator($file_path) { |
|
531 | + return rtrim($file_path, '/\\').DS; |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | * @param $file_path |
539 | 539 | * @return string |
540 | 540 | */ |
541 | - public static function standardise_and_end_with_directory_separator( $file_path ){ |
|
542 | - return self::end_with_directory_separator( self::standardise_directory_separators( $file_path )); |
|
541 | + public static function standardise_and_end_with_directory_separator($file_path) { |
|
542 | + return self::end_with_directory_separator(self::standardise_directory_separators($file_path)); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | |
@@ -556,21 +556,21 @@ discard block |
||
556 | 556 | * if $index_numerically == FALSE (Default) keys are what the class names SHOULD be; |
557 | 557 | * and values are their filepaths |
558 | 558 | */ |
559 | - public static function get_contents_of_folders( $folder_paths = array(), $index_numerically = FALSE ){ |
|
559 | + public static function get_contents_of_folders($folder_paths = array(), $index_numerically = FALSE) { |
|
560 | 560 | $class_to_folder_path = array(); |
561 | - foreach( $folder_paths as $folder_path ){ |
|
562 | - $folder_path = self::standardise_and_end_with_directory_separator( $folder_path ); |
|
561 | + foreach ($folder_paths as $folder_path) { |
|
562 | + $folder_path = self::standardise_and_end_with_directory_separator($folder_path); |
|
563 | 563 | // load WP_Filesystem and set file permissions |
564 | - $files_in_folder = glob( $folder_path . '*' ); |
|
564 | + $files_in_folder = glob($folder_path.'*'); |
|
565 | 565 | $class_to_folder_path = array(); |
566 | - if ( $files_in_folder ) { |
|
567 | - foreach( $files_in_folder as $file_path ){ |
|
566 | + if ($files_in_folder) { |
|
567 | + foreach ($files_in_folder as $file_path) { |
|
568 | 568 | //only add files, not folders |
569 | - if ( ! is_dir( $file_path )) { |
|
570 | - if ( $index_numerically ) { |
|
569 | + if ( ! is_dir($file_path)) { |
|
570 | + if ($index_numerically) { |
|
571 | 571 | $class_to_folder_path[] = $file_path; |
572 | 572 | } else { |
573 | - $classname = self::get_classname_from_filepath_with_standard_filename( $file_path ); |
|
573 | + $classname = self::get_classname_from_filepath_with_standard_filename($file_path); |
|
574 | 574 | $class_to_folder_path[$classname] = $file_path; |
575 | 575 | } |
576 | 576 | } |
@@ -590,39 +590,39 @@ discard block |
||
590 | 590 | * @throws EE_Error if filesystem credentials are required |
591 | 591 | * @return boolean success |
592 | 592 | */ |
593 | - public static function copy( $source_file, $destination_file, $overwrite = FALSE ){ |
|
594 | - $full_source_path = EEH_File::standardise_directory_separators( $source_file ); |
|
595 | - if( ! EEH_File::exists( $full_source_path ) ){ |
|
596 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
597 | - $msg = sprintf( __( 'The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso' ), $full_source_path ); |
|
598 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path ); |
|
599 | - throw new EE_Error( $msg ); |
|
593 | + public static function copy($source_file, $destination_file, $overwrite = FALSE) { |
|
594 | + $full_source_path = EEH_File::standardise_directory_separators($source_file); |
|
595 | + if ( ! EEH_File::exists($full_source_path)) { |
|
596 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
597 | + $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path); |
|
598 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path); |
|
599 | + throw new EE_Error($msg); |
|
600 | 600 | } |
601 | 601 | return FALSE; |
602 | 602 | } |
603 | 603 | |
604 | - $full_dest_path = EEH_File::standardise_directory_separators( $destination_file ); |
|
605 | - $folder = EEH_File::remove_filename_from_filepath( $full_dest_path ); |
|
606 | - if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
607 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
608 | - $msg = sprintf( __( 'The file located at "%2$s" is not writable.', 'event_espresso' ), $full_dest_path ); |
|
609 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_dest_path ); |
|
610 | - throw new EE_Error( $msg ); |
|
604 | + $full_dest_path = EEH_File::standardise_directory_separators($destination_file); |
|
605 | + $folder = EEH_File::remove_filename_from_filepath($full_dest_path); |
|
606 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
607 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
608 | + $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path); |
|
609 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path); |
|
610 | + throw new EE_Error($msg); |
|
611 | 611 | } |
612 | 612 | return FALSE; |
613 | 613 | } |
614 | 614 | |
615 | 615 | // load WP_Filesystem and set file permissions |
616 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $destination_file ); |
|
616 | + $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file); |
|
617 | 617 | // write the file |
618 | 618 | if ( ! $wp_filesystem->copy( |
619 | - EEH_File::convert_local_filepath_to_remote_filepath( $full_source_path ), |
|
620 | - EEH_File::convert_local_filepath_to_remote_filepath( $full_dest_path ), |
|
619 | + EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), |
|
620 | + EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), |
|
621 | 621 | $overwrite )) { |
622 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
623 | - $msg = sprintf( __( 'Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso' ), $full_source_path ); |
|
624 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path, 'f' ); |
|
625 | - throw new EE_Error( $msg ); |
|
622 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
623 | + $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path); |
|
624 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f'); |
|
625 | + throw new EE_Error($msg); |
|
626 | 626 | } |
627 | 627 | return FALSE; |
628 | 628 | } |
@@ -634,9 +634,9 @@ discard block |
||
634 | 634 | * @param string $filepath |
635 | 635 | * @return boolean |
636 | 636 | */ |
637 | - public static function is_in_uploads_folder( $filepath ) { |
|
637 | + public static function is_in_uploads_folder($filepath) { |
|
638 | 638 | $uploads = wp_upload_dir(); |
639 | - return strpos( $filepath, $uploads[ 'basedir' ] ) === 0 ? true : false; |
|
639 | + return strpos($filepath, $uploads['basedir']) === 0 ? true : false; |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | /** |
@@ -651,9 +651,9 @@ discard block |
||
651 | 651 | * @return string the remote filepath (eg the filepath the filesystem method, eg |
652 | 652 | * ftp or ssh, will use to access the folder |
653 | 653 | */ |
654 | - public static function convert_local_filepath_to_remote_filepath( $local_filepath ) { |
|
655 | - $wp_filesystem = EEH_File::_get_wp_filesystem( $local_filepath ); |
|
656 | - return str_replace( WP_CONTENT_DIR . DS, $wp_filesystem->wp_content_dir(), $local_filepath ); |
|
654 | + public static function convert_local_filepath_to_remote_filepath($local_filepath) { |
|
655 | + $wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath); |
|
656 | + return str_replace(WP_CONTENT_DIR.DS, $wp_filesystem->wp_content_dir(), $local_filepath); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | use EventEspresso\core\services\loaders\LoaderInterface; |
6 | 6 | |
7 | 7 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
8 | - exit('No direct script access allowed'); |
|
8 | + exit('No direct script access allowed'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | |
@@ -22,819 +22,819 @@ discard block |
||
22 | 22 | class EE_Dependency_Map |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * This means that the requested class dependency is not present in the dependency map |
|
27 | - */ |
|
28 | - const not_registered = 0; |
|
29 | - |
|
30 | - /** |
|
31 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
32 | - */ |
|
33 | - const load_new_object = 1; |
|
34 | - |
|
35 | - /** |
|
36 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
37 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
38 | - */ |
|
39 | - const load_from_cache = 2; |
|
40 | - |
|
41 | - /** |
|
42 | - * When registering a dependency, |
|
43 | - * this indicates to keep any existing dependencies that already exist, |
|
44 | - * and simply discard any new dependencies declared in the incoming data |
|
45 | - */ |
|
46 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
47 | - |
|
48 | - /** |
|
49 | - * When registering a dependency, |
|
50 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
51 | - */ |
|
52 | - const OVERWRITE_DEPENDENCIES = 1; |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @type EE_Dependency_Map $_instance |
|
58 | - */ |
|
59 | - protected static $_instance; |
|
60 | - |
|
61 | - /** |
|
62 | - * @type EE_Request $request |
|
63 | - */ |
|
64 | - protected $_request; |
|
65 | - |
|
66 | - /** |
|
67 | - * @type EE_Response $response |
|
68 | - */ |
|
69 | - protected $_response; |
|
70 | - |
|
71 | - /** |
|
72 | - * @type LoaderInterface $loader |
|
73 | - */ |
|
74 | - protected $loader; |
|
75 | - |
|
76 | - /** |
|
77 | - * @type array $_dependency_map |
|
78 | - */ |
|
79 | - protected $_dependency_map = array(); |
|
80 | - |
|
81 | - /** |
|
82 | - * @type array $_class_loaders |
|
83 | - */ |
|
84 | - protected $_class_loaders = array(); |
|
85 | - |
|
86 | - /** |
|
87 | - * @type array $_aliases |
|
88 | - */ |
|
89 | - protected $_aliases = array(); |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * EE_Dependency_Map constructor. |
|
95 | - * |
|
96 | - * @param EE_Request $request |
|
97 | - * @param EE_Response $response |
|
98 | - */ |
|
99 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
100 | - { |
|
101 | - $this->_request = $request; |
|
102 | - $this->_response = $response; |
|
103 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
104 | - do_action('EE_Dependency_Map____construct'); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @throws InvalidDataTypeException |
|
111 | - * @throws InvalidInterfaceException |
|
112 | - * @throws InvalidArgumentException |
|
113 | - */ |
|
114 | - public function initialize() |
|
115 | - { |
|
116 | - $this->_register_core_dependencies(); |
|
117 | - $this->_register_core_class_loaders(); |
|
118 | - $this->_register_core_aliases(); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @singleton method used to instantiate class object |
|
125 | - * @access public |
|
126 | - * @param EE_Request $request |
|
127 | - * @param EE_Response $response |
|
128 | - * @return EE_Dependency_Map |
|
129 | - */ |
|
130 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
131 | - { |
|
132 | - // check if class object is instantiated, and instantiated properly |
|
133 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
134 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
135 | - } |
|
136 | - return self::$_instance; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @param LoaderInterface $loader |
|
143 | - */ |
|
144 | - public function setLoader(LoaderInterface $loader) |
|
145 | - { |
|
146 | - $this->loader = $loader; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @param string $class |
|
153 | - * @param array $dependencies |
|
154 | - * @param int $overwrite |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public static function register_dependencies( |
|
158 | - $class, |
|
159 | - array $dependencies, |
|
160 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
161 | - ) { |
|
162 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
169 | - * to the class specified by the first parameter. |
|
170 | - * IMPORTANT !!! |
|
171 | - * The order of elements in the incoming $dependencies array MUST match |
|
172 | - * the order of the constructor parameters for the class in question. |
|
173 | - * This is especially important when overriding any existing dependencies that are registered. |
|
174 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
175 | - * |
|
176 | - * @param string $class |
|
177 | - * @param array $dependencies |
|
178 | - * @param int $overwrite |
|
179 | - * @return bool |
|
180 | - */ |
|
181 | - public function registerDependencies( |
|
182 | - $class, |
|
183 | - array $dependencies, |
|
184 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
185 | - ) { |
|
186 | - $class = trim($class, '\\'); |
|
187 | - $registered = false; |
|
188 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
189 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
190 | - } |
|
191 | - // we need to make sure that any aliases used when registering a dependency |
|
192 | - // get resolved to the correct class name |
|
193 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
194 | - $alias = self::$_instance->get_alias($dependency); |
|
195 | - if ( |
|
196 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
197 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
198 | - ) { |
|
199 | - unset($dependencies[$dependency]); |
|
200 | - $dependencies[$alias] = $load_source; |
|
201 | - $registered = true; |
|
202 | - } |
|
203 | - } |
|
204 | - // now add our two lists of dependencies together. |
|
205 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
206 | - // so $dependencies is NOT overwritten because it is listed first |
|
207 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
208 | - // Union is way faster than array_merge() but should be used with caution... |
|
209 | - // especially with numerically indexed arrays |
|
210 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
211 | - // now we need to ensure that the resulting dependencies |
|
212 | - // array only has the entries that are required for the class |
|
213 | - // so first count how many dependencies were originally registered for the class |
|
214 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
215 | - // if that count is non-zero (meaning dependencies were already registered) |
|
216 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
217 | - // then truncate the final array to match that count |
|
218 | - ? array_slice($dependencies, 0, $dependency_count) |
|
219 | - // otherwise just take the incoming array because nothing previously existed |
|
220 | - : $dependencies; |
|
221 | - return $registered; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * @param string $class_name |
|
228 | - * @param string $loader |
|
229 | - * @return bool |
|
230 | - * @throws DomainException |
|
231 | - */ |
|
232 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
233 | - { |
|
234 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
235 | - throw new DomainException( |
|
236 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
237 | - ); |
|
238 | - } |
|
239 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
240 | - if ( |
|
241 | - ! is_callable($loader) |
|
242 | - && ( |
|
243 | - strpos($loader, 'load_') !== 0 |
|
244 | - || ! method_exists('EE_Registry', $loader) |
|
245 | - ) |
|
246 | - ) { |
|
247 | - throw new DomainException( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $loader |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - $class_name = self::$_instance->get_alias($class_name); |
|
258 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
259 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
260 | - return true; |
|
261 | - } |
|
262 | - return false; |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * @return array |
|
269 | - */ |
|
270 | - public function dependency_map() |
|
271 | - { |
|
272 | - return $this->_dependency_map; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
279 | - * |
|
280 | - * @param string $class_name |
|
281 | - * @return boolean |
|
282 | - */ |
|
283 | - public function has($class_name = '') |
|
284 | - { |
|
285 | - // all legacy models have the same dependencies |
|
286 | - if (strpos($class_name, 'EEM_') === 0) { |
|
287 | - $class_name = 'LEGACY_MODELS'; |
|
288 | - } |
|
289 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
296 | - * |
|
297 | - * @param string $class_name |
|
298 | - * @param string $dependency |
|
299 | - * @return bool |
|
300 | - */ |
|
301 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
302 | - { |
|
303 | - // all legacy models have the same dependencies |
|
304 | - if (strpos($class_name, 'EEM_') === 0) { |
|
305 | - $class_name = 'LEGACY_MODELS'; |
|
306 | - } |
|
307 | - $dependency = $this->get_alias($dependency); |
|
308 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
309 | - ? true |
|
310 | - : false; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
317 | - * |
|
318 | - * @param string $class_name |
|
319 | - * @param string $dependency |
|
320 | - * @return int |
|
321 | - */ |
|
322 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
323 | - { |
|
324 | - // all legacy models have the same dependencies |
|
325 | - if (strpos($class_name, 'EEM_') === 0) { |
|
326 | - $class_name = 'LEGACY_MODELS'; |
|
327 | - } |
|
328 | - $dependency = $this->get_alias($dependency); |
|
329 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
330 | - ? $this->_dependency_map[$class_name][$dependency] |
|
331 | - : EE_Dependency_Map::not_registered; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * @param string $class_name |
|
338 | - * @return string | Closure |
|
339 | - */ |
|
340 | - public function class_loader($class_name) |
|
341 | - { |
|
342 | - // all legacy models use load_model() |
|
343 | - if(strpos($class_name, 'EEM_') === 0){ |
|
344 | - return 'load_model'; |
|
345 | - } |
|
346 | - $class_name = $this->get_alias($class_name); |
|
347 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * @return array |
|
354 | - */ |
|
355 | - public function class_loaders() |
|
356 | - { |
|
357 | - return $this->_class_loaders; |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * adds an alias for a classname |
|
364 | - * |
|
365 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
366 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
367 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
368 | - */ |
|
369 | - public function add_alias($class_name, $alias, $for_class = '') |
|
370 | - { |
|
371 | - if ($for_class !== '') { |
|
372 | - if (! isset($this->_aliases[$for_class])) { |
|
373 | - $this->_aliases[$for_class] = array(); |
|
374 | - } |
|
375 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
376 | - } |
|
377 | - $this->_aliases[$class_name] = $alias; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * returns TRUE if the provided class name has an alias |
|
384 | - * |
|
385 | - * @param string $class_name |
|
386 | - * @param string $for_class |
|
387 | - * @return bool |
|
388 | - */ |
|
389 | - public function has_alias($class_name = '', $for_class = '') |
|
390 | - { |
|
391 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
392 | - || ( |
|
393 | - isset($this->_aliases[$class_name]) |
|
394 | - && ! is_array($this->_aliases[$class_name]) |
|
395 | - ); |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
402 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
403 | - * for example: |
|
404 | - * if the following two entries were added to the _aliases array: |
|
405 | - * array( |
|
406 | - * 'interface_alias' => 'some\namespace\interface' |
|
407 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
408 | - * ) |
|
409 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
410 | - * to load an instance of 'some\namespace\classname' |
|
411 | - * |
|
412 | - * @param string $class_name |
|
413 | - * @param string $for_class |
|
414 | - * @return string |
|
415 | - */ |
|
416 | - public function get_alias($class_name = '', $for_class = '') |
|
417 | - { |
|
418 | - if (! $this->has_alias($class_name, $for_class)) { |
|
419 | - return $class_name; |
|
420 | - } |
|
421 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
422 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
423 | - } |
|
424 | - return $this->get_alias($this->_aliases[$class_name]); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
431 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
432 | - * This is done by using the following class constants: |
|
433 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
434 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
435 | - */ |
|
436 | - protected function _register_core_dependencies() |
|
437 | - { |
|
438 | - $this->_dependency_map = array( |
|
439 | - 'EE_Request_Handler' => array( |
|
440 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
441 | - ), |
|
442 | - 'EE_System' => array( |
|
443 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
444 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
445 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
446 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
447 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
448 | - ), |
|
449 | - 'EE_Session' => array( |
|
450 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
451 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
452 | - ), |
|
453 | - 'EE_Cart' => array( |
|
454 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
455 | - ), |
|
456 | - 'EE_Front_Controller' => array( |
|
457 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
458 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
459 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
460 | - ), |
|
461 | - 'EE_Messenger_Collection_Loader' => array( |
|
462 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
463 | - ), |
|
464 | - 'EE_Message_Type_Collection_Loader' => array( |
|
465 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
466 | - ), |
|
467 | - 'EE_Message_Resource_Manager' => array( |
|
468 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
469 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
470 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
471 | - ), |
|
472 | - 'EE_Message_Factory' => array( |
|
473 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
474 | - ), |
|
475 | - 'EE_messages' => array( |
|
476 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
477 | - ), |
|
478 | - 'EE_Messages_Generator' => array( |
|
479 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
480 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
481 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
482 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
483 | - ), |
|
484 | - 'EE_Messages_Processor' => array( |
|
485 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | - ), |
|
487 | - 'EE_Messages_Queue' => array( |
|
488 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
489 | - ), |
|
490 | - 'EE_Messages_Template_Defaults' => array( |
|
491 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
492 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
493 | - ), |
|
494 | - 'EE_Message_To_Generate_From_Request' => array( |
|
495 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
496 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
497 | - ), |
|
498 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
499 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
500 | - ), |
|
501 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
502 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
503 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
504 | - ), |
|
505 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
506 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
507 | - ), |
|
508 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
509 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
510 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
511 | - ), |
|
512 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
513 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
514 | - ), |
|
515 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
516 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
517 | - ), |
|
518 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
519 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
520 | - ), |
|
521 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
522 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
523 | - ), |
|
524 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
525 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
526 | - ), |
|
527 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
528 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
529 | - ), |
|
530 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
531 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
532 | - ), |
|
533 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
534 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
535 | - ), |
|
536 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
537 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | - ), |
|
539 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
540 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
541 | - ), |
|
542 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
543 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
544 | - ), |
|
545 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
546 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
547 | - ), |
|
548 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
549 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
550 | - ), |
|
551 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
552 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
553 | - ), |
|
554 | - 'EE_Data_Migration_Class_Base' => array( |
|
555 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
556 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
557 | - ), |
|
558 | - 'EE_DMS_Core_4_1_0' => array( |
|
559 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
560 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
561 | - ), |
|
562 | - 'EE_DMS_Core_4_2_0' => array( |
|
563 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
564 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
565 | - ), |
|
566 | - 'EE_DMS_Core_4_3_0' => array( |
|
567 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
568 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
569 | - ), |
|
570 | - 'EE_DMS_Core_4_4_0' => array( |
|
571 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
572 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
573 | - ), |
|
574 | - 'EE_DMS_Core_4_5_0' => array( |
|
575 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
576 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
577 | - ), |
|
578 | - 'EE_DMS_Core_4_6_0' => array( |
|
579 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
581 | - ), |
|
582 | - 'EE_DMS_Core_4_7_0' => array( |
|
583 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
584 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
585 | - ), |
|
586 | - 'EE_DMS_Core_4_8_0' => array( |
|
587 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
588 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
589 | - ), |
|
590 | - 'EE_DMS_Core_4_9_0' => array( |
|
591 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
592 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
593 | - ), |
|
594 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
595 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
596 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
597 | - ), |
|
598 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
599 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
600 | - ), |
|
601 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
602 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
603 | - ), |
|
604 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
605 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
606 | - ), |
|
607 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
608 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
609 | - ), |
|
610 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
611 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
612 | - ), |
|
613 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
614 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
615 | - ), |
|
616 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
617 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | - ), |
|
619 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
620 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
621 | - ), |
|
622 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
623 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
624 | - ), |
|
625 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
626 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
627 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
628 | - ), |
|
629 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
630 | - null, |
|
631 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
632 | - ), |
|
633 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
634 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
635 | - ), |
|
636 | - 'LEGACY_MODELS' => array( |
|
637 | - null, |
|
638 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
639 | - ), |
|
640 | - 'EE_Module_Request_Router' => array( |
|
641 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
642 | - ), |
|
643 | - 'EE_Registration_Processor' => array( |
|
644 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
645 | - ), |
|
646 | - 'EventEspresso\core\services\currency\CurrencyFactory' => array( |
|
647 | - 'EEM_Country' => EE_Dependency_Map::load_from_cache, |
|
648 | - 'EE_Organization_Config' => EE_Dependency_Map::load_from_cache, |
|
649 | - 'EventEspresso\core\services\currency\CurrencySubunits' => EE_Dependency_Map::load_from_cache |
|
650 | - ), |
|
651 | - 'EventEspresso\core\services\currency\MoneyFactory' => array( |
|
652 | - 'EventEspresso\core\services\currency\CurrencyFactory' => EE_Dependency_Map::load_from_cache, |
|
653 | - 'EventEspresso\core\services\currency\Calculator' => EE_Dependency_Map::load_from_cache, |
|
654 | - array() |
|
655 | - ), |
|
656 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
657 | - null, |
|
658 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
659 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
660 | - ), |
|
661 | - ); |
|
662 | - } |
|
663 | - |
|
664 | - |
|
665 | - |
|
666 | - /** |
|
667 | - * Registers how core classes are loaded. |
|
668 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
669 | - * 'EE_Request_Handler' => 'load_core' |
|
670 | - * 'EE_Messages_Queue' => 'load_lib' |
|
671 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
672 | - * or, if greater control is required, by providing a custom closure. For example: |
|
673 | - * 'Some_Class' => function () { |
|
674 | - * return new Some_Class(); |
|
675 | - * }, |
|
676 | - * This is required for instantiating dependencies |
|
677 | - * where an interface has been type hinted in a class constructor. For example: |
|
678 | - * 'Required_Interface' => function () { |
|
679 | - * return new A_Class_That_Implements_Required_Interface(); |
|
680 | - * }, |
|
681 | - * |
|
682 | - * @throws InvalidInterfaceException |
|
683 | - * @throws InvalidDataTypeException |
|
684 | - * @throws InvalidArgumentException |
|
685 | - */ |
|
686 | - protected function _register_core_class_loaders() |
|
687 | - { |
|
688 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
689 | - //be used in a closure. |
|
690 | - $request = &$this->_request; |
|
691 | - $response = &$this->_response; |
|
692 | - // $loader = &$this->loader; |
|
693 | - $this->_class_loaders = array( |
|
694 | - //load_core |
|
695 | - 'EE_Capabilities' => 'load_core', |
|
696 | - 'EE_Encryption' => 'load_core', |
|
697 | - 'EE_Front_Controller' => 'load_core', |
|
698 | - 'EE_Module_Request_Router' => 'load_core', |
|
699 | - 'EE_Registry' => 'load_core', |
|
700 | - 'EE_Request' => function () use (&$request) { |
|
701 | - return $request; |
|
702 | - }, |
|
703 | - 'EE_Response' => function () use (&$response) { |
|
704 | - return $response; |
|
705 | - }, |
|
706 | - 'EE_Request_Handler' => 'load_core', |
|
707 | - 'EE_Session' => 'load_core', |
|
708 | - 'EE_Cron_Tasks' => 'load_core', |
|
709 | - 'EE_System' => 'load_core', |
|
710 | - 'EE_Maintenance_Mode' => 'load_core', |
|
711 | - 'EE_Register_CPTs' => 'load_core', |
|
712 | - 'EE_Admin' => 'load_core', |
|
713 | - //load_lib |
|
714 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
715 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
716 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
717 | - 'EE_Messenger_Collection' => 'load_lib', |
|
718 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
719 | - 'EE_Messages_Processor' => 'load_lib', |
|
720 | - 'EE_Message_Repository' => 'load_lib', |
|
721 | - 'EE_Messages_Queue' => 'load_lib', |
|
722 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
723 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
724 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
725 | - 'EE_Messages_Generator' => function () { |
|
726 | - return EE_Registry::instance()->load_lib( |
|
727 | - 'Messages_Generator', |
|
728 | - array(), |
|
729 | - false, |
|
730 | - false |
|
731 | - ); |
|
732 | - }, |
|
733 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
734 | - return EE_Registry::instance()->load_lib( |
|
735 | - 'Messages_Template_Defaults', |
|
736 | - $arguments, |
|
737 | - false, |
|
738 | - false |
|
739 | - ); |
|
740 | - }, |
|
741 | - //load_model |
|
742 | - // 'EEM_Attendee' => 'load_model', |
|
743 | - // 'EEM_Message_Template_Group' => 'load_model', |
|
744 | - // 'EEM_Message_Template' => 'load_model', |
|
745 | - //load_helper |
|
746 | - 'EEH_Parse_Shortcodes' => function () { |
|
747 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
748 | - return new EEH_Parse_Shortcodes(); |
|
749 | - } |
|
750 | - return null; |
|
751 | - }, |
|
752 | - 'EE_Template_Config' => function () { |
|
753 | - return EE_Config::instance()->template_settings; |
|
754 | - }, |
|
755 | - 'EE_Currency_Config' => function () { |
|
756 | - return EE_Config::instance()->currency; |
|
757 | - }, |
|
758 | - 'EE_Registration_Config' => function () { |
|
759 | - return EE_Config::instance()->registration; |
|
760 | - }, |
|
761 | - 'EE_Organization_Config' => function () { |
|
762 | - return EE_Config::instance()->organization; |
|
763 | - }, |
|
764 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
765 | - return LoaderFactory::getLoader(); |
|
766 | - }, |
|
767 | - ); |
|
768 | - } |
|
769 | - |
|
770 | - |
|
771 | - |
|
772 | - /** |
|
773 | - * can be used for supplying alternate names for classes, |
|
774 | - * or for connecting interface names to instantiable classes |
|
775 | - */ |
|
776 | - protected function _register_core_aliases() |
|
777 | - { |
|
778 | - $this->_aliases = array( |
|
779 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
780 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
781 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
782 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
783 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
784 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
785 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
786 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
787 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
788 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
789 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
790 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
791 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
792 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
793 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
794 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
795 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
796 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
797 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
798 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
799 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
800 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
801 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
802 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
803 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
804 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
805 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
806 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
807 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
808 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
809 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
810 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
811 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
812 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
813 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
814 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
815 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
816 | - 'EventEspresso\core\services\currency\Calculator' => 'EventEspresso\core\services\currency\DefaultCalculator', |
|
817 | - ); |
|
818 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
819 | - $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
820 | - } |
|
821 | - } |
|
822 | - |
|
823 | - |
|
824 | - |
|
825 | - /** |
|
826 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
827 | - * request Primarily used by unit tests. |
|
828 | - * |
|
829 | - * @throws InvalidDataTypeException |
|
830 | - * @throws InvalidInterfaceException |
|
831 | - * @throws InvalidArgumentException |
|
832 | - */ |
|
833 | - public function reset() |
|
834 | - { |
|
835 | - $this->_register_core_class_loaders(); |
|
836 | - $this->_register_core_dependencies(); |
|
837 | - } |
|
25 | + /** |
|
26 | + * This means that the requested class dependency is not present in the dependency map |
|
27 | + */ |
|
28 | + const not_registered = 0; |
|
29 | + |
|
30 | + /** |
|
31 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
32 | + */ |
|
33 | + const load_new_object = 1; |
|
34 | + |
|
35 | + /** |
|
36 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
37 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
38 | + */ |
|
39 | + const load_from_cache = 2; |
|
40 | + |
|
41 | + /** |
|
42 | + * When registering a dependency, |
|
43 | + * this indicates to keep any existing dependencies that already exist, |
|
44 | + * and simply discard any new dependencies declared in the incoming data |
|
45 | + */ |
|
46 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
47 | + |
|
48 | + /** |
|
49 | + * When registering a dependency, |
|
50 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
51 | + */ |
|
52 | + const OVERWRITE_DEPENDENCIES = 1; |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @type EE_Dependency_Map $_instance |
|
58 | + */ |
|
59 | + protected static $_instance; |
|
60 | + |
|
61 | + /** |
|
62 | + * @type EE_Request $request |
|
63 | + */ |
|
64 | + protected $_request; |
|
65 | + |
|
66 | + /** |
|
67 | + * @type EE_Response $response |
|
68 | + */ |
|
69 | + protected $_response; |
|
70 | + |
|
71 | + /** |
|
72 | + * @type LoaderInterface $loader |
|
73 | + */ |
|
74 | + protected $loader; |
|
75 | + |
|
76 | + /** |
|
77 | + * @type array $_dependency_map |
|
78 | + */ |
|
79 | + protected $_dependency_map = array(); |
|
80 | + |
|
81 | + /** |
|
82 | + * @type array $_class_loaders |
|
83 | + */ |
|
84 | + protected $_class_loaders = array(); |
|
85 | + |
|
86 | + /** |
|
87 | + * @type array $_aliases |
|
88 | + */ |
|
89 | + protected $_aliases = array(); |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * EE_Dependency_Map constructor. |
|
95 | + * |
|
96 | + * @param EE_Request $request |
|
97 | + * @param EE_Response $response |
|
98 | + */ |
|
99 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
100 | + { |
|
101 | + $this->_request = $request; |
|
102 | + $this->_response = $response; |
|
103 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
104 | + do_action('EE_Dependency_Map____construct'); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @throws InvalidDataTypeException |
|
111 | + * @throws InvalidInterfaceException |
|
112 | + * @throws InvalidArgumentException |
|
113 | + */ |
|
114 | + public function initialize() |
|
115 | + { |
|
116 | + $this->_register_core_dependencies(); |
|
117 | + $this->_register_core_class_loaders(); |
|
118 | + $this->_register_core_aliases(); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @singleton method used to instantiate class object |
|
125 | + * @access public |
|
126 | + * @param EE_Request $request |
|
127 | + * @param EE_Response $response |
|
128 | + * @return EE_Dependency_Map |
|
129 | + */ |
|
130 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
131 | + { |
|
132 | + // check if class object is instantiated, and instantiated properly |
|
133 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
134 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
135 | + } |
|
136 | + return self::$_instance; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @param LoaderInterface $loader |
|
143 | + */ |
|
144 | + public function setLoader(LoaderInterface $loader) |
|
145 | + { |
|
146 | + $this->loader = $loader; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @param string $class |
|
153 | + * @param array $dependencies |
|
154 | + * @param int $overwrite |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public static function register_dependencies( |
|
158 | + $class, |
|
159 | + array $dependencies, |
|
160 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
161 | + ) { |
|
162 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
169 | + * to the class specified by the first parameter. |
|
170 | + * IMPORTANT !!! |
|
171 | + * The order of elements in the incoming $dependencies array MUST match |
|
172 | + * the order of the constructor parameters for the class in question. |
|
173 | + * This is especially important when overriding any existing dependencies that are registered. |
|
174 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
175 | + * |
|
176 | + * @param string $class |
|
177 | + * @param array $dependencies |
|
178 | + * @param int $overwrite |
|
179 | + * @return bool |
|
180 | + */ |
|
181 | + public function registerDependencies( |
|
182 | + $class, |
|
183 | + array $dependencies, |
|
184 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
185 | + ) { |
|
186 | + $class = trim($class, '\\'); |
|
187 | + $registered = false; |
|
188 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
189 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
190 | + } |
|
191 | + // we need to make sure that any aliases used when registering a dependency |
|
192 | + // get resolved to the correct class name |
|
193 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
194 | + $alias = self::$_instance->get_alias($dependency); |
|
195 | + if ( |
|
196 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
197 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
198 | + ) { |
|
199 | + unset($dependencies[$dependency]); |
|
200 | + $dependencies[$alias] = $load_source; |
|
201 | + $registered = true; |
|
202 | + } |
|
203 | + } |
|
204 | + // now add our two lists of dependencies together. |
|
205 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
206 | + // so $dependencies is NOT overwritten because it is listed first |
|
207 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
208 | + // Union is way faster than array_merge() but should be used with caution... |
|
209 | + // especially with numerically indexed arrays |
|
210 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
211 | + // now we need to ensure that the resulting dependencies |
|
212 | + // array only has the entries that are required for the class |
|
213 | + // so first count how many dependencies were originally registered for the class |
|
214 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
215 | + // if that count is non-zero (meaning dependencies were already registered) |
|
216 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
217 | + // then truncate the final array to match that count |
|
218 | + ? array_slice($dependencies, 0, $dependency_count) |
|
219 | + // otherwise just take the incoming array because nothing previously existed |
|
220 | + : $dependencies; |
|
221 | + return $registered; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * @param string $class_name |
|
228 | + * @param string $loader |
|
229 | + * @return bool |
|
230 | + * @throws DomainException |
|
231 | + */ |
|
232 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
233 | + { |
|
234 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
235 | + throw new DomainException( |
|
236 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
237 | + ); |
|
238 | + } |
|
239 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
240 | + if ( |
|
241 | + ! is_callable($loader) |
|
242 | + && ( |
|
243 | + strpos($loader, 'load_') !== 0 |
|
244 | + || ! method_exists('EE_Registry', $loader) |
|
245 | + ) |
|
246 | + ) { |
|
247 | + throw new DomainException( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $loader |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + $class_name = self::$_instance->get_alias($class_name); |
|
258 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
259 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
260 | + return true; |
|
261 | + } |
|
262 | + return false; |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * @return array |
|
269 | + */ |
|
270 | + public function dependency_map() |
|
271 | + { |
|
272 | + return $this->_dependency_map; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
279 | + * |
|
280 | + * @param string $class_name |
|
281 | + * @return boolean |
|
282 | + */ |
|
283 | + public function has($class_name = '') |
|
284 | + { |
|
285 | + // all legacy models have the same dependencies |
|
286 | + if (strpos($class_name, 'EEM_') === 0) { |
|
287 | + $class_name = 'LEGACY_MODELS'; |
|
288 | + } |
|
289 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
296 | + * |
|
297 | + * @param string $class_name |
|
298 | + * @param string $dependency |
|
299 | + * @return bool |
|
300 | + */ |
|
301 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
302 | + { |
|
303 | + // all legacy models have the same dependencies |
|
304 | + if (strpos($class_name, 'EEM_') === 0) { |
|
305 | + $class_name = 'LEGACY_MODELS'; |
|
306 | + } |
|
307 | + $dependency = $this->get_alias($dependency); |
|
308 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
309 | + ? true |
|
310 | + : false; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
317 | + * |
|
318 | + * @param string $class_name |
|
319 | + * @param string $dependency |
|
320 | + * @return int |
|
321 | + */ |
|
322 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
323 | + { |
|
324 | + // all legacy models have the same dependencies |
|
325 | + if (strpos($class_name, 'EEM_') === 0) { |
|
326 | + $class_name = 'LEGACY_MODELS'; |
|
327 | + } |
|
328 | + $dependency = $this->get_alias($dependency); |
|
329 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
330 | + ? $this->_dependency_map[$class_name][$dependency] |
|
331 | + : EE_Dependency_Map::not_registered; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * @param string $class_name |
|
338 | + * @return string | Closure |
|
339 | + */ |
|
340 | + public function class_loader($class_name) |
|
341 | + { |
|
342 | + // all legacy models use load_model() |
|
343 | + if(strpos($class_name, 'EEM_') === 0){ |
|
344 | + return 'load_model'; |
|
345 | + } |
|
346 | + $class_name = $this->get_alias($class_name); |
|
347 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * @return array |
|
354 | + */ |
|
355 | + public function class_loaders() |
|
356 | + { |
|
357 | + return $this->_class_loaders; |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * adds an alias for a classname |
|
364 | + * |
|
365 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
366 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
367 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
368 | + */ |
|
369 | + public function add_alias($class_name, $alias, $for_class = '') |
|
370 | + { |
|
371 | + if ($for_class !== '') { |
|
372 | + if (! isset($this->_aliases[$for_class])) { |
|
373 | + $this->_aliases[$for_class] = array(); |
|
374 | + } |
|
375 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
376 | + } |
|
377 | + $this->_aliases[$class_name] = $alias; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * returns TRUE if the provided class name has an alias |
|
384 | + * |
|
385 | + * @param string $class_name |
|
386 | + * @param string $for_class |
|
387 | + * @return bool |
|
388 | + */ |
|
389 | + public function has_alias($class_name = '', $for_class = '') |
|
390 | + { |
|
391 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
392 | + || ( |
|
393 | + isset($this->_aliases[$class_name]) |
|
394 | + && ! is_array($this->_aliases[$class_name]) |
|
395 | + ); |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
402 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
403 | + * for example: |
|
404 | + * if the following two entries were added to the _aliases array: |
|
405 | + * array( |
|
406 | + * 'interface_alias' => 'some\namespace\interface' |
|
407 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
408 | + * ) |
|
409 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
410 | + * to load an instance of 'some\namespace\classname' |
|
411 | + * |
|
412 | + * @param string $class_name |
|
413 | + * @param string $for_class |
|
414 | + * @return string |
|
415 | + */ |
|
416 | + public function get_alias($class_name = '', $for_class = '') |
|
417 | + { |
|
418 | + if (! $this->has_alias($class_name, $for_class)) { |
|
419 | + return $class_name; |
|
420 | + } |
|
421 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
422 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
423 | + } |
|
424 | + return $this->get_alias($this->_aliases[$class_name]); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
431 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
432 | + * This is done by using the following class constants: |
|
433 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
434 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
435 | + */ |
|
436 | + protected function _register_core_dependencies() |
|
437 | + { |
|
438 | + $this->_dependency_map = array( |
|
439 | + 'EE_Request_Handler' => array( |
|
440 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
441 | + ), |
|
442 | + 'EE_System' => array( |
|
443 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
444 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
445 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
446 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
447 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
448 | + ), |
|
449 | + 'EE_Session' => array( |
|
450 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
451 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
452 | + ), |
|
453 | + 'EE_Cart' => array( |
|
454 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
455 | + ), |
|
456 | + 'EE_Front_Controller' => array( |
|
457 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
458 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
459 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
460 | + ), |
|
461 | + 'EE_Messenger_Collection_Loader' => array( |
|
462 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
463 | + ), |
|
464 | + 'EE_Message_Type_Collection_Loader' => array( |
|
465 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
466 | + ), |
|
467 | + 'EE_Message_Resource_Manager' => array( |
|
468 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
469 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
470 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
471 | + ), |
|
472 | + 'EE_Message_Factory' => array( |
|
473 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
474 | + ), |
|
475 | + 'EE_messages' => array( |
|
476 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
477 | + ), |
|
478 | + 'EE_Messages_Generator' => array( |
|
479 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
480 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
481 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
482 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
483 | + ), |
|
484 | + 'EE_Messages_Processor' => array( |
|
485 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | + ), |
|
487 | + 'EE_Messages_Queue' => array( |
|
488 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
489 | + ), |
|
490 | + 'EE_Messages_Template_Defaults' => array( |
|
491 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
492 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
493 | + ), |
|
494 | + 'EE_Message_To_Generate_From_Request' => array( |
|
495 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
496 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
497 | + ), |
|
498 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
499 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
500 | + ), |
|
501 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
502 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
503 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
504 | + ), |
|
505 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
506 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
507 | + ), |
|
508 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
509 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
510 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
511 | + ), |
|
512 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
513 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
514 | + ), |
|
515 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
516 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
517 | + ), |
|
518 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
519 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
520 | + ), |
|
521 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
522 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
523 | + ), |
|
524 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
525 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
526 | + ), |
|
527 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
528 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
529 | + ), |
|
530 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
531 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
532 | + ), |
|
533 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
534 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
535 | + ), |
|
536 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
537 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | + ), |
|
539 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
540 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
541 | + ), |
|
542 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
543 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
544 | + ), |
|
545 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
546 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
547 | + ), |
|
548 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
549 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
550 | + ), |
|
551 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
552 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
553 | + ), |
|
554 | + 'EE_Data_Migration_Class_Base' => array( |
|
555 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
556 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
557 | + ), |
|
558 | + 'EE_DMS_Core_4_1_0' => array( |
|
559 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
560 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
561 | + ), |
|
562 | + 'EE_DMS_Core_4_2_0' => array( |
|
563 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
564 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
565 | + ), |
|
566 | + 'EE_DMS_Core_4_3_0' => array( |
|
567 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
568 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
569 | + ), |
|
570 | + 'EE_DMS_Core_4_4_0' => array( |
|
571 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
572 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
573 | + ), |
|
574 | + 'EE_DMS_Core_4_5_0' => array( |
|
575 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
576 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
577 | + ), |
|
578 | + 'EE_DMS_Core_4_6_0' => array( |
|
579 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
581 | + ), |
|
582 | + 'EE_DMS_Core_4_7_0' => array( |
|
583 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
584 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
585 | + ), |
|
586 | + 'EE_DMS_Core_4_8_0' => array( |
|
587 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
588 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
589 | + ), |
|
590 | + 'EE_DMS_Core_4_9_0' => array( |
|
591 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
592 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
593 | + ), |
|
594 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
595 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
596 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
597 | + ), |
|
598 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
599 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
600 | + ), |
|
601 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
602 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
603 | + ), |
|
604 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
605 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
606 | + ), |
|
607 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
608 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
609 | + ), |
|
610 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
611 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
612 | + ), |
|
613 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
614 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
615 | + ), |
|
616 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
617 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | + ), |
|
619 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
620 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
621 | + ), |
|
622 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
623 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
624 | + ), |
|
625 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
626 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
627 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
628 | + ), |
|
629 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
630 | + null, |
|
631 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
632 | + ), |
|
633 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
634 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
635 | + ), |
|
636 | + 'LEGACY_MODELS' => array( |
|
637 | + null, |
|
638 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
639 | + ), |
|
640 | + 'EE_Module_Request_Router' => array( |
|
641 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
642 | + ), |
|
643 | + 'EE_Registration_Processor' => array( |
|
644 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
645 | + ), |
|
646 | + 'EventEspresso\core\services\currency\CurrencyFactory' => array( |
|
647 | + 'EEM_Country' => EE_Dependency_Map::load_from_cache, |
|
648 | + 'EE_Organization_Config' => EE_Dependency_Map::load_from_cache, |
|
649 | + 'EventEspresso\core\services\currency\CurrencySubunits' => EE_Dependency_Map::load_from_cache |
|
650 | + ), |
|
651 | + 'EventEspresso\core\services\currency\MoneyFactory' => array( |
|
652 | + 'EventEspresso\core\services\currency\CurrencyFactory' => EE_Dependency_Map::load_from_cache, |
|
653 | + 'EventEspresso\core\services\currency\Calculator' => EE_Dependency_Map::load_from_cache, |
|
654 | + array() |
|
655 | + ), |
|
656 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
657 | + null, |
|
658 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
659 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
660 | + ), |
|
661 | + ); |
|
662 | + } |
|
663 | + |
|
664 | + |
|
665 | + |
|
666 | + /** |
|
667 | + * Registers how core classes are loaded. |
|
668 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
669 | + * 'EE_Request_Handler' => 'load_core' |
|
670 | + * 'EE_Messages_Queue' => 'load_lib' |
|
671 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
672 | + * or, if greater control is required, by providing a custom closure. For example: |
|
673 | + * 'Some_Class' => function () { |
|
674 | + * return new Some_Class(); |
|
675 | + * }, |
|
676 | + * This is required for instantiating dependencies |
|
677 | + * where an interface has been type hinted in a class constructor. For example: |
|
678 | + * 'Required_Interface' => function () { |
|
679 | + * return new A_Class_That_Implements_Required_Interface(); |
|
680 | + * }, |
|
681 | + * |
|
682 | + * @throws InvalidInterfaceException |
|
683 | + * @throws InvalidDataTypeException |
|
684 | + * @throws InvalidArgumentException |
|
685 | + */ |
|
686 | + protected function _register_core_class_loaders() |
|
687 | + { |
|
688 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
689 | + //be used in a closure. |
|
690 | + $request = &$this->_request; |
|
691 | + $response = &$this->_response; |
|
692 | + // $loader = &$this->loader; |
|
693 | + $this->_class_loaders = array( |
|
694 | + //load_core |
|
695 | + 'EE_Capabilities' => 'load_core', |
|
696 | + 'EE_Encryption' => 'load_core', |
|
697 | + 'EE_Front_Controller' => 'load_core', |
|
698 | + 'EE_Module_Request_Router' => 'load_core', |
|
699 | + 'EE_Registry' => 'load_core', |
|
700 | + 'EE_Request' => function () use (&$request) { |
|
701 | + return $request; |
|
702 | + }, |
|
703 | + 'EE_Response' => function () use (&$response) { |
|
704 | + return $response; |
|
705 | + }, |
|
706 | + 'EE_Request_Handler' => 'load_core', |
|
707 | + 'EE_Session' => 'load_core', |
|
708 | + 'EE_Cron_Tasks' => 'load_core', |
|
709 | + 'EE_System' => 'load_core', |
|
710 | + 'EE_Maintenance_Mode' => 'load_core', |
|
711 | + 'EE_Register_CPTs' => 'load_core', |
|
712 | + 'EE_Admin' => 'load_core', |
|
713 | + //load_lib |
|
714 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
715 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
716 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
717 | + 'EE_Messenger_Collection' => 'load_lib', |
|
718 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
719 | + 'EE_Messages_Processor' => 'load_lib', |
|
720 | + 'EE_Message_Repository' => 'load_lib', |
|
721 | + 'EE_Messages_Queue' => 'load_lib', |
|
722 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
723 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
724 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
725 | + 'EE_Messages_Generator' => function () { |
|
726 | + return EE_Registry::instance()->load_lib( |
|
727 | + 'Messages_Generator', |
|
728 | + array(), |
|
729 | + false, |
|
730 | + false |
|
731 | + ); |
|
732 | + }, |
|
733 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
734 | + return EE_Registry::instance()->load_lib( |
|
735 | + 'Messages_Template_Defaults', |
|
736 | + $arguments, |
|
737 | + false, |
|
738 | + false |
|
739 | + ); |
|
740 | + }, |
|
741 | + //load_model |
|
742 | + // 'EEM_Attendee' => 'load_model', |
|
743 | + // 'EEM_Message_Template_Group' => 'load_model', |
|
744 | + // 'EEM_Message_Template' => 'load_model', |
|
745 | + //load_helper |
|
746 | + 'EEH_Parse_Shortcodes' => function () { |
|
747 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
748 | + return new EEH_Parse_Shortcodes(); |
|
749 | + } |
|
750 | + return null; |
|
751 | + }, |
|
752 | + 'EE_Template_Config' => function () { |
|
753 | + return EE_Config::instance()->template_settings; |
|
754 | + }, |
|
755 | + 'EE_Currency_Config' => function () { |
|
756 | + return EE_Config::instance()->currency; |
|
757 | + }, |
|
758 | + 'EE_Registration_Config' => function () { |
|
759 | + return EE_Config::instance()->registration; |
|
760 | + }, |
|
761 | + 'EE_Organization_Config' => function () { |
|
762 | + return EE_Config::instance()->organization; |
|
763 | + }, |
|
764 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
765 | + return LoaderFactory::getLoader(); |
|
766 | + }, |
|
767 | + ); |
|
768 | + } |
|
769 | + |
|
770 | + |
|
771 | + |
|
772 | + /** |
|
773 | + * can be used for supplying alternate names for classes, |
|
774 | + * or for connecting interface names to instantiable classes |
|
775 | + */ |
|
776 | + protected function _register_core_aliases() |
|
777 | + { |
|
778 | + $this->_aliases = array( |
|
779 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
780 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
781 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
782 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
783 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
784 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
785 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
786 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
787 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
788 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
789 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
790 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
791 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
792 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
793 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
794 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
795 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
796 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
797 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
798 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
799 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
800 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
801 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
802 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
803 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
804 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
805 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
806 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
807 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
808 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
809 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
810 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
811 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
812 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
813 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
814 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
815 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
816 | + 'EventEspresso\core\services\currency\Calculator' => 'EventEspresso\core\services\currency\DefaultCalculator', |
|
817 | + ); |
|
818 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
819 | + $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
820 | + } |
|
821 | + } |
|
822 | + |
|
823 | + |
|
824 | + |
|
825 | + /** |
|
826 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
827 | + * request Primarily used by unit tests. |
|
828 | + * |
|
829 | + * @throws InvalidDataTypeException |
|
830 | + * @throws InvalidInterfaceException |
|
831 | + * @throws InvalidArgumentException |
|
832 | + */ |
|
833 | + public function reset() |
|
834 | + { |
|
835 | + $this->_register_core_class_loaders(); |
|
836 | + $this->_register_core_dependencies(); |
|
837 | + } |
|
838 | 838 | |
839 | 839 | |
840 | 840 | } |
@@ -22,338 +22,338 @@ |
||
22 | 22 | class Money |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * number of decimal places to be added to currencies for internal computations, |
|
27 | - * but removed before any output or formatting is applied. |
|
28 | - * This allows us to avoid rounding errors during calculations. |
|
29 | - */ |
|
30 | - const EXTRA_PRECISION = 3; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var int $amount |
|
34 | - */ |
|
35 | - private $amount; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var Currency $currency |
|
39 | - */ |
|
40 | - private $currency; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var Calculator $calculator |
|
44 | - */ |
|
45 | - protected $calculator; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var MoneyFormatter[] $formatters |
|
49 | - */ |
|
50 | - protected $formatters; |
|
51 | - |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Money constructor. |
|
56 | - * |
|
57 | - * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc |
|
58 | - * example: $12.5 USD would equate to a value amount of 12.50 |
|
59 | - * @param Currency $currency |
|
60 | - * @param Calculator $calculator |
|
61 | - * @param MoneyFormatter[] $formatters |
|
62 | - * @throws InvalidDataTypeException |
|
63 | - */ |
|
64 | - public function __construct($amount, Currency $currency, Calculator $calculator, array $formatters) |
|
65 | - { |
|
66 | - $this->currency = $currency; |
|
67 | - $this->amount = $this->parseAmount($amount); |
|
68 | - $this->calculator = $calculator; |
|
69 | - $this->formatters = $formatters; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @return Calculator |
|
76 | - */ |
|
77 | - protected function calculator() |
|
78 | - { |
|
79 | - return $this->calculator; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * @return MoneyFormatter[] |
|
86 | - */ |
|
87 | - protected function formatters() |
|
88 | - { |
|
89 | - return $this->formatters; |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Convert's a standard unit amount into the subunits of the currency |
|
96 | - * |
|
97 | - * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc |
|
98 | - * example: $12.5 USD would equate to a value amount of 12.50 |
|
99 | - * @return integer in the currency's subunit |
|
100 | - * @throws InvalidDataTypeException |
|
101 | - */ |
|
102 | - private function parseAmount($amount) |
|
103 | - { |
|
104 | - if (! in_array(gettype($amount), array('integer', 'double', 'string'), true)) { |
|
105 | - throw new InvalidDataTypeException( |
|
106 | - '$amount', |
|
107 | - $amount, |
|
108 | - 'integer (or float or string)' |
|
109 | - ); |
|
110 | - } |
|
111 | - if ($this->currency->decimalMark() !== '.') { |
|
112 | - // remove thousands separator and replace decimal place with standard decimal. |
|
113 | - $amount = str_replace( |
|
114 | - array( |
|
115 | - $this->currency->thousands(), |
|
116 | - $this->currency->decimalMark(), |
|
117 | - ), |
|
118 | - array( |
|
119 | - '', |
|
120 | - '.', |
|
121 | - ), |
|
122 | - $amount |
|
123 | - ); |
|
124 | - } |
|
125 | - // remove any non numeric values but leave the decimal |
|
126 | - $amount = (float) preg_replace('/([^0-9\\.-])/', '', $amount); |
|
127 | - // shift the decimal position by the number of decimal places used internally |
|
128 | - // ex: 12.5 for a currency using 2 decimal places, would become 1250 |
|
129 | - // then if our extra internal precision was 3, it would become 1250000 |
|
130 | - $amount *= pow(10, $this->precision()); |
|
131 | - // then round up the remaining value if there is still a fractional amount left |
|
132 | - $amount = round($amount); |
|
133 | - return (int)$amount; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * adds or subtracts additional decimal places based on the value of the Money::EXTRA_PRECISION constant |
|
140 | - * |
|
141 | - * @param bool $positive |
|
142 | - * @return integer |
|
143 | - */ |
|
144 | - private function precision($positive = true) |
|
145 | - { |
|
146 | - $sign = $positive ? 1 : -1; |
|
147 | - return ((int) $this->currency->subunitOrderOfMagnitudeDiff() + Money::EXTRA_PRECISION) * $sign; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Returns the money amount as an unformatted string |
|
154 | - * IF YOU REQUIRE A FORMATTED STRING, THEN USE Money::format() |
|
155 | - * In the currency's standard units |
|
156 | - * |
|
157 | - * @return string |
|
158 | - */ |
|
159 | - public function amount() |
|
160 | - { |
|
161 | - // shift the decimal position BACK by the number of decimal places used internally |
|
162 | - // ex: 1250 for a currency using 2 decimal places, would become 12.50 |
|
163 | - $amount = (string) $this->amount * pow(10, $this->precision(false)); |
|
164 | - // then shave off our extra internal precision using the number of decimal places for the currency |
|
165 | - $amount = round($amount, $this->currency->subunitOrderOfMagnitudeDiff()); |
|
166 | - return (string) $amount; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * Returns the money SUBUNITS amount as an INTEGER |
|
173 | - * |
|
174 | - * @return integer |
|
175 | - */ |
|
176 | - public function amountInSubunits() |
|
177 | - { |
|
178 | - // shift the decimal position BACK by the number of decimal places used internally |
|
179 | - // for extra internal precision, but NOT for the number of decimals used by the currency |
|
180 | - // ex: if our extra internal precision was 3, then 1250000 would become 1250 |
|
181 | - // and even if the currency used 2 decimal places, we would return 1250 and NOT 12.50 |
|
182 | - $amount = (string) $this->amount * pow(10, Money::EXTRA_PRECISION * -1); |
|
183 | - // then shave off anything after the decimal |
|
184 | - $amount = round($amount); |
|
185 | - return (int) $amount; |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * applies formatting based on the specified formatting level |
|
192 | - * corresponding to one of the constants on MoneyFormatter |
|
193 | - * |
|
194 | - * @param int $formatting_level |
|
195 | - * @return string |
|
196 | - */ |
|
197 | - public function format($formatting_level = MoneyFormatter::ADD_THOUSANDS) |
|
198 | - { |
|
199 | - $formatted_amount = $this->amount(); |
|
200 | - $formatters = $this->formatters(); |
|
201 | - // if we are applying thousands formatting... |
|
202 | - if ($formatting_level >= MoneyFormatter::ADD_THOUSANDS) { |
|
203 | - // then let's remove decimal formatting since it's included in thousands formatting |
|
204 | - unset($formatters[ MoneyFormatter::DECIMAL_ONLY ]); |
|
205 | - } |
|
206 | - for ($x = 1; $x <= $formatting_level; $x++) { |
|
207 | - if (isset($formatters[ $x ]) && $formatters[ $x ] instanceof MoneyFormatter) { |
|
208 | - $formatted_amount = $formatters[ $x ]->format($formatted_amount, $this->currency); |
|
209 | - } |
|
210 | - } |
|
211 | - return (string) apply_filters( |
|
212 | - 'FHEE__EventEspresso_core_domain_values_currency_Money__format__formatted_amount', |
|
213 | - $formatted_amount, |
|
214 | - $this |
|
215 | - ); |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * Returns the Currency object for this money |
|
222 | - * |
|
223 | - * @return Currency |
|
224 | - */ |
|
225 | - public function currency() |
|
226 | - { |
|
227 | - return $this->currency; |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * adds the supplied Money amount to this Money amount |
|
234 | - * and returns a new Money object |
|
235 | - * |
|
236 | - * @param Money $other |
|
237 | - * @return Money |
|
238 | - * @throws InvalidArgumentException |
|
239 | - */ |
|
240 | - public function add(Money $other) |
|
241 | - { |
|
242 | - $this->verifySameCurrency($other->currency()); |
|
243 | - return new Money( |
|
244 | - $this->calculator()->add( |
|
245 | - $this->amount(), |
|
246 | - $other->amount() |
|
247 | - ), |
|
248 | - $this->currency(), |
|
249 | - $this->calculator(), |
|
250 | - $this->formatters() |
|
251 | - ); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * subtracts the supplied Money amount from this Money amount |
|
258 | - * and returns a new Money object |
|
259 | - * |
|
260 | - * @param Money $other |
|
261 | - * @return Money |
|
262 | - * @throws InvalidArgumentException |
|
263 | - */ |
|
264 | - public function subtract(Money $other) |
|
265 | - { |
|
266 | - $this->verifySameCurrency($other->currency()); |
|
267 | - return new Money( |
|
268 | - $this->calculator()->subtract( |
|
269 | - $this->amount(), |
|
270 | - $other->amount() |
|
271 | - ), |
|
272 | - $this->currency(), |
|
273 | - $this->calculator(), |
|
274 | - $this->formatters() |
|
275 | - ); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * multiplies this Money amount by the supplied $multiplier |
|
282 | - * and returns a new Money object |
|
283 | - * |
|
284 | - * @param float|int|string $multiplier |
|
285 | - * @param int $rounding_mode |
|
286 | - * @return Money |
|
287 | - * @throws InvalidDataTypeException |
|
288 | - */ |
|
289 | - public function multiply($multiplier, $rounding_mode = Calculator::ROUND_HALF_UP) |
|
290 | - { |
|
291 | - return new Money( |
|
292 | - $this->calculator()->multiply( |
|
293 | - $this->amount(), |
|
294 | - $multiplier, |
|
295 | - $this->precision(), |
|
296 | - $rounding_mode |
|
297 | - ), |
|
298 | - $this->currency(), |
|
299 | - $this->calculator(), |
|
300 | - $this->formatters() |
|
301 | - ); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * divides this Money amount by the supplied $divisor |
|
308 | - * and returns a new Money object |
|
309 | - * |
|
310 | - * @param float|int|string $divisor |
|
311 | - * @param int $rounding_mode |
|
312 | - * @return Money |
|
313 | - * @throws InvalidDataTypeException |
|
314 | - */ |
|
315 | - public function divide($divisor, $rounding_mode = Calculator::ROUND_HALF_UP) |
|
316 | - { |
|
317 | - return new Money( |
|
318 | - $this->calculator()->divide( |
|
319 | - $this->amount(), |
|
320 | - $divisor, |
|
321 | - $this->precision(), |
|
322 | - $rounding_mode |
|
323 | - ), |
|
324 | - $this->currency(), |
|
325 | - $this->calculator(), |
|
326 | - $this->formatters() |
|
327 | - ); |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * @param Currency $other_currency |
|
334 | - * @throws InvalidArgumentException |
|
335 | - */ |
|
336 | - public function verifySameCurrency(Currency $other_currency) |
|
337 | - { |
|
338 | - if ($this->currency()->equals($other_currency) !== true) { |
|
339 | - throw new InvalidArgumentException( |
|
340 | - esc_html__( |
|
341 | - 'Currencies must be the same in order to add or subtract their values.', |
|
342 | - 'event_espresso' |
|
343 | - ) |
|
344 | - ); |
|
345 | - } |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * @return string |
|
352 | - */ |
|
353 | - public function __toString() |
|
354 | - { |
|
355 | - return $this->format(MoneyFormatter::DECIMAL_ONLY); |
|
356 | - } |
|
25 | + /** |
|
26 | + * number of decimal places to be added to currencies for internal computations, |
|
27 | + * but removed before any output or formatting is applied. |
|
28 | + * This allows us to avoid rounding errors during calculations. |
|
29 | + */ |
|
30 | + const EXTRA_PRECISION = 3; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var int $amount |
|
34 | + */ |
|
35 | + private $amount; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var Currency $currency |
|
39 | + */ |
|
40 | + private $currency; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var Calculator $calculator |
|
44 | + */ |
|
45 | + protected $calculator; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var MoneyFormatter[] $formatters |
|
49 | + */ |
|
50 | + protected $formatters; |
|
51 | + |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Money constructor. |
|
56 | + * |
|
57 | + * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc |
|
58 | + * example: $12.5 USD would equate to a value amount of 12.50 |
|
59 | + * @param Currency $currency |
|
60 | + * @param Calculator $calculator |
|
61 | + * @param MoneyFormatter[] $formatters |
|
62 | + * @throws InvalidDataTypeException |
|
63 | + */ |
|
64 | + public function __construct($amount, Currency $currency, Calculator $calculator, array $formatters) |
|
65 | + { |
|
66 | + $this->currency = $currency; |
|
67 | + $this->amount = $this->parseAmount($amount); |
|
68 | + $this->calculator = $calculator; |
|
69 | + $this->formatters = $formatters; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @return Calculator |
|
76 | + */ |
|
77 | + protected function calculator() |
|
78 | + { |
|
79 | + return $this->calculator; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * @return MoneyFormatter[] |
|
86 | + */ |
|
87 | + protected function formatters() |
|
88 | + { |
|
89 | + return $this->formatters; |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Convert's a standard unit amount into the subunits of the currency |
|
96 | + * |
|
97 | + * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc |
|
98 | + * example: $12.5 USD would equate to a value amount of 12.50 |
|
99 | + * @return integer in the currency's subunit |
|
100 | + * @throws InvalidDataTypeException |
|
101 | + */ |
|
102 | + private function parseAmount($amount) |
|
103 | + { |
|
104 | + if (! in_array(gettype($amount), array('integer', 'double', 'string'), true)) { |
|
105 | + throw new InvalidDataTypeException( |
|
106 | + '$amount', |
|
107 | + $amount, |
|
108 | + 'integer (or float or string)' |
|
109 | + ); |
|
110 | + } |
|
111 | + if ($this->currency->decimalMark() !== '.') { |
|
112 | + // remove thousands separator and replace decimal place with standard decimal. |
|
113 | + $amount = str_replace( |
|
114 | + array( |
|
115 | + $this->currency->thousands(), |
|
116 | + $this->currency->decimalMark(), |
|
117 | + ), |
|
118 | + array( |
|
119 | + '', |
|
120 | + '.', |
|
121 | + ), |
|
122 | + $amount |
|
123 | + ); |
|
124 | + } |
|
125 | + // remove any non numeric values but leave the decimal |
|
126 | + $amount = (float) preg_replace('/([^0-9\\.-])/', '', $amount); |
|
127 | + // shift the decimal position by the number of decimal places used internally |
|
128 | + // ex: 12.5 for a currency using 2 decimal places, would become 1250 |
|
129 | + // then if our extra internal precision was 3, it would become 1250000 |
|
130 | + $amount *= pow(10, $this->precision()); |
|
131 | + // then round up the remaining value if there is still a fractional amount left |
|
132 | + $amount = round($amount); |
|
133 | + return (int)$amount; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * adds or subtracts additional decimal places based on the value of the Money::EXTRA_PRECISION constant |
|
140 | + * |
|
141 | + * @param bool $positive |
|
142 | + * @return integer |
|
143 | + */ |
|
144 | + private function precision($positive = true) |
|
145 | + { |
|
146 | + $sign = $positive ? 1 : -1; |
|
147 | + return ((int) $this->currency->subunitOrderOfMagnitudeDiff() + Money::EXTRA_PRECISION) * $sign; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Returns the money amount as an unformatted string |
|
154 | + * IF YOU REQUIRE A FORMATTED STRING, THEN USE Money::format() |
|
155 | + * In the currency's standard units |
|
156 | + * |
|
157 | + * @return string |
|
158 | + */ |
|
159 | + public function amount() |
|
160 | + { |
|
161 | + // shift the decimal position BACK by the number of decimal places used internally |
|
162 | + // ex: 1250 for a currency using 2 decimal places, would become 12.50 |
|
163 | + $amount = (string) $this->amount * pow(10, $this->precision(false)); |
|
164 | + // then shave off our extra internal precision using the number of decimal places for the currency |
|
165 | + $amount = round($amount, $this->currency->subunitOrderOfMagnitudeDiff()); |
|
166 | + return (string) $amount; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * Returns the money SUBUNITS amount as an INTEGER |
|
173 | + * |
|
174 | + * @return integer |
|
175 | + */ |
|
176 | + public function amountInSubunits() |
|
177 | + { |
|
178 | + // shift the decimal position BACK by the number of decimal places used internally |
|
179 | + // for extra internal precision, but NOT for the number of decimals used by the currency |
|
180 | + // ex: if our extra internal precision was 3, then 1250000 would become 1250 |
|
181 | + // and even if the currency used 2 decimal places, we would return 1250 and NOT 12.50 |
|
182 | + $amount = (string) $this->amount * pow(10, Money::EXTRA_PRECISION * -1); |
|
183 | + // then shave off anything after the decimal |
|
184 | + $amount = round($amount); |
|
185 | + return (int) $amount; |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * applies formatting based on the specified formatting level |
|
192 | + * corresponding to one of the constants on MoneyFormatter |
|
193 | + * |
|
194 | + * @param int $formatting_level |
|
195 | + * @return string |
|
196 | + */ |
|
197 | + public function format($formatting_level = MoneyFormatter::ADD_THOUSANDS) |
|
198 | + { |
|
199 | + $formatted_amount = $this->amount(); |
|
200 | + $formatters = $this->formatters(); |
|
201 | + // if we are applying thousands formatting... |
|
202 | + if ($formatting_level >= MoneyFormatter::ADD_THOUSANDS) { |
|
203 | + // then let's remove decimal formatting since it's included in thousands formatting |
|
204 | + unset($formatters[ MoneyFormatter::DECIMAL_ONLY ]); |
|
205 | + } |
|
206 | + for ($x = 1; $x <= $formatting_level; $x++) { |
|
207 | + if (isset($formatters[ $x ]) && $formatters[ $x ] instanceof MoneyFormatter) { |
|
208 | + $formatted_amount = $formatters[ $x ]->format($formatted_amount, $this->currency); |
|
209 | + } |
|
210 | + } |
|
211 | + return (string) apply_filters( |
|
212 | + 'FHEE__EventEspresso_core_domain_values_currency_Money__format__formatted_amount', |
|
213 | + $formatted_amount, |
|
214 | + $this |
|
215 | + ); |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * Returns the Currency object for this money |
|
222 | + * |
|
223 | + * @return Currency |
|
224 | + */ |
|
225 | + public function currency() |
|
226 | + { |
|
227 | + return $this->currency; |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * adds the supplied Money amount to this Money amount |
|
234 | + * and returns a new Money object |
|
235 | + * |
|
236 | + * @param Money $other |
|
237 | + * @return Money |
|
238 | + * @throws InvalidArgumentException |
|
239 | + */ |
|
240 | + public function add(Money $other) |
|
241 | + { |
|
242 | + $this->verifySameCurrency($other->currency()); |
|
243 | + return new Money( |
|
244 | + $this->calculator()->add( |
|
245 | + $this->amount(), |
|
246 | + $other->amount() |
|
247 | + ), |
|
248 | + $this->currency(), |
|
249 | + $this->calculator(), |
|
250 | + $this->formatters() |
|
251 | + ); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * subtracts the supplied Money amount from this Money amount |
|
258 | + * and returns a new Money object |
|
259 | + * |
|
260 | + * @param Money $other |
|
261 | + * @return Money |
|
262 | + * @throws InvalidArgumentException |
|
263 | + */ |
|
264 | + public function subtract(Money $other) |
|
265 | + { |
|
266 | + $this->verifySameCurrency($other->currency()); |
|
267 | + return new Money( |
|
268 | + $this->calculator()->subtract( |
|
269 | + $this->amount(), |
|
270 | + $other->amount() |
|
271 | + ), |
|
272 | + $this->currency(), |
|
273 | + $this->calculator(), |
|
274 | + $this->formatters() |
|
275 | + ); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * multiplies this Money amount by the supplied $multiplier |
|
282 | + * and returns a new Money object |
|
283 | + * |
|
284 | + * @param float|int|string $multiplier |
|
285 | + * @param int $rounding_mode |
|
286 | + * @return Money |
|
287 | + * @throws InvalidDataTypeException |
|
288 | + */ |
|
289 | + public function multiply($multiplier, $rounding_mode = Calculator::ROUND_HALF_UP) |
|
290 | + { |
|
291 | + return new Money( |
|
292 | + $this->calculator()->multiply( |
|
293 | + $this->amount(), |
|
294 | + $multiplier, |
|
295 | + $this->precision(), |
|
296 | + $rounding_mode |
|
297 | + ), |
|
298 | + $this->currency(), |
|
299 | + $this->calculator(), |
|
300 | + $this->formatters() |
|
301 | + ); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * divides this Money amount by the supplied $divisor |
|
308 | + * and returns a new Money object |
|
309 | + * |
|
310 | + * @param float|int|string $divisor |
|
311 | + * @param int $rounding_mode |
|
312 | + * @return Money |
|
313 | + * @throws InvalidDataTypeException |
|
314 | + */ |
|
315 | + public function divide($divisor, $rounding_mode = Calculator::ROUND_HALF_UP) |
|
316 | + { |
|
317 | + return new Money( |
|
318 | + $this->calculator()->divide( |
|
319 | + $this->amount(), |
|
320 | + $divisor, |
|
321 | + $this->precision(), |
|
322 | + $rounding_mode |
|
323 | + ), |
|
324 | + $this->currency(), |
|
325 | + $this->calculator(), |
|
326 | + $this->formatters() |
|
327 | + ); |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * @param Currency $other_currency |
|
334 | + * @throws InvalidArgumentException |
|
335 | + */ |
|
336 | + public function verifySameCurrency(Currency $other_currency) |
|
337 | + { |
|
338 | + if ($this->currency()->equals($other_currency) !== true) { |
|
339 | + throw new InvalidArgumentException( |
|
340 | + esc_html__( |
|
341 | + 'Currencies must be the same in order to add or subtract their values.', |
|
342 | + 'event_espresso' |
|
343 | + ) |
|
344 | + ); |
|
345 | + } |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * @return string |
|
352 | + */ |
|
353 | + public function __toString() |
|
354 | + { |
|
355 | + return $this->format(MoneyFormatter::DECIMAL_ONLY); |
|
356 | + } |
|
357 | 357 | } |
358 | 358 | // End of file Money.php |
359 | 359 | // Location: core/entities/money/Money.php |