@@ -10,105 +10,105 @@ |
||
10 | 10 | */ |
11 | 11 | trait MessagesAdmin |
12 | 12 | { |
13 | - /** |
|
14 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | - * a string. |
|
16 | - */ |
|
17 | - public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | - { |
|
19 | - $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | - } |
|
13 | + /** |
|
14 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | + * a string. |
|
16 | + */ |
|
17 | + public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | + { |
|
19 | + $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | - * a string. |
|
25 | - */ |
|
26 | - public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | - { |
|
28 | - $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | - } |
|
22 | + /** |
|
23 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | + * a string. |
|
25 | + */ |
|
26 | + public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | + { |
|
28 | + $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | - * a string. |
|
35 | - */ |
|
36 | - public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | - { |
|
38 | - $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | - } |
|
32 | + /** |
|
33 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | + * a string. |
|
35 | + */ |
|
36 | + public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | + { |
|
38 | + $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * Directs to message settings page |
|
44 | - */ |
|
45 | - public function amOnMessageSettingsPage() |
|
46 | - { |
|
47 | - $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | - } |
|
42 | + /** |
|
43 | + * Directs to message settings page |
|
44 | + */ |
|
45 | + public function amOnMessageSettingsPage() |
|
46 | + { |
|
47 | + $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | - { |
|
53 | - $this->actor()->dragAndDrop( |
|
54 | - MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | - MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | - ); |
|
57 | - } |
|
51 | + public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | + { |
|
53 | + $this->actor()->dragAndDrop( |
|
54 | + MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | + MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | + ); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | - * @param string $message_type_slug |
|
63 | - * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | - */ |
|
65 | - public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | - { |
|
67 | - $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | - } |
|
60 | + /** |
|
61 | + * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | + * @param string $message_type_slug |
|
63 | + * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | + */ |
|
65 | + public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | + { |
|
67 | + $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | - * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | - * |
|
75 | - * @param int $expected_occurence_count |
|
76 | - * @param string $text_to_check_for |
|
77 | - * @param string $field |
|
78 | - * @param string $message_type_label |
|
79 | - * @param string $message_status |
|
80 | - * @param string $messenger |
|
81 | - * @param string $context |
|
82 | - */ |
|
83 | - public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | - $expected_occurence_count, |
|
85 | - $text_to_check_for, |
|
86 | - $field, |
|
87 | - $message_type_label, |
|
88 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | - $messenger = 'Email', |
|
90 | - $context = 'Event Admin' |
|
91 | - ) { |
|
92 | - $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | - $field, |
|
94 | - $message_type_label, |
|
95 | - $message_status, |
|
96 | - $messenger, |
|
97 | - $context, |
|
98 | - $text_to_check_for |
|
99 | - )); |
|
100 | - $actual_count = count($elements); |
|
101 | - $this->actor()->assertEquals( |
|
102 | - $expected_occurence_count, |
|
103 | - $actual_count, |
|
104 | - sprintf( |
|
105 | - 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
106 | - $expected_occurence_count, |
|
107 | - $text_to_check_for, |
|
108 | - $field, |
|
109 | - $actual_count |
|
110 | - ) |
|
111 | - ); |
|
112 | - } |
|
71 | + /** |
|
72 | + * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | + * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | + * |
|
75 | + * @param int $expected_occurence_count |
|
76 | + * @param string $text_to_check_for |
|
77 | + * @param string $field |
|
78 | + * @param string $message_type_label |
|
79 | + * @param string $message_status |
|
80 | + * @param string $messenger |
|
81 | + * @param string $context |
|
82 | + */ |
|
83 | + public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | + $expected_occurence_count, |
|
85 | + $text_to_check_for, |
|
86 | + $field, |
|
87 | + $message_type_label, |
|
88 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | + $messenger = 'Email', |
|
90 | + $context = 'Event Admin' |
|
91 | + ) { |
|
92 | + $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | + $field, |
|
94 | + $message_type_label, |
|
95 | + $message_status, |
|
96 | + $messenger, |
|
97 | + $context, |
|
98 | + $text_to_check_for |
|
99 | + )); |
|
100 | + $actual_count = count($elements); |
|
101 | + $this->actor()->assertEquals( |
|
102 | + $expected_occurence_count, |
|
103 | + $actual_count, |
|
104 | + sprintf( |
|
105 | + 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
106 | + $expected_occurence_count, |
|
107 | + $text_to_check_for, |
|
108 | + $field, |
|
109 | + $actual_count |
|
110 | + ) |
|
111 | + ); |
|
112 | + } |
|
113 | 113 | |
114 | 114 | } |
115 | 115 | \ No newline at end of file |
@@ -12,481 +12,481 @@ |
||
12 | 12 | class Custom_Messages_Template_List_Table extends EE_Admin_List_Table |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Custom_Messages_Template_List_Table constructor. |
|
17 | - * |
|
18 | - * @param EE_Admin_Page $admin_page |
|
19 | - */ |
|
20 | - public function __construct($admin_page) |
|
21 | - { |
|
22 | - //Set parent defaults |
|
23 | - parent::__construct($admin_page); |
|
24 | - } |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * @return Messages_Admin_Page |
|
29 | - */ |
|
30 | - public function get_admin_page() |
|
31 | - { |
|
32 | - return $this->_admin_page; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Setup initial data. |
|
37 | - */ |
|
38 | - protected function _setup_data() |
|
39 | - { |
|
40 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
41 | - $this->_per_page, |
|
42 | - $this->_view, |
|
43 | - false, |
|
44 | - false, |
|
45 | - false |
|
46 | - ); |
|
47 | - $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
48 | - $this->_per_page, |
|
49 | - $this->_view, |
|
50 | - true, |
|
51 | - true, |
|
52 | - false |
|
53 | - ); |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Set initial properties |
|
59 | - */ |
|
60 | - protected function _set_properties() |
|
61 | - { |
|
62 | - $this->_wp_list_args = array( |
|
63 | - 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
64 | - 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
65 | - 'ajax' => true, //for now, |
|
66 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
67 | - ); |
|
68 | - |
|
69 | - $this->_columns = array( |
|
70 | - 'cb' => '<input type="checkbox" />', |
|
71 | - 'name' => esc_html__('Template Name', 'event_espresso'), |
|
72 | - 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
73 | - 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
74 | - 'description' => esc_html__('Description', 'event_espresso'), |
|
75 | - 'events' => esc_html__('Events', 'event_espresso'), |
|
76 | - //count of events using this template. |
|
77 | - 'actions' => '' |
|
78 | - ); |
|
79 | - |
|
80 | - $this->_sortable_columns = array( |
|
81 | - 'messenger' => array('MTP_messenger' => true), |
|
82 | - ); |
|
83 | - |
|
84 | - $this->_hidden_columns = array(); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
90 | - * message_type or messenger object before generating the row. |
|
91 | - * |
|
92 | - * @param EE_Message_Template_Group $item |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function single_row($item) |
|
96 | - { |
|
97 | - $message_type = $item->message_type_obj(); |
|
98 | - $messenger = $item->messenger_obj(); |
|
99 | - |
|
100 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
101 | - echo ''; |
|
102 | - return; |
|
103 | - } |
|
104 | - |
|
105 | - parent::single_row($item); |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - protected function _get_table_filters() |
|
113 | - { |
|
114 | - $filters = array(); |
|
115 | - |
|
116 | - //get select inputs |
|
117 | - $select_inputs = array( |
|
118 | - $this->_get_messengers_dropdown_filter(), |
|
119 | - $this->_get_message_types_dropdown_filter(), |
|
120 | - ); |
|
121 | - |
|
122 | - //set filters to select inputs if they aren't empty |
|
123 | - foreach ($select_inputs as $select_input) { |
|
124 | - if ($select_input) { |
|
125 | - $filters[] = $select_input; |
|
126 | - } |
|
127 | - } |
|
128 | - return $filters; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * we're just removing the search box for message templates, not needed. |
|
133 | - * |
|
134 | - * @return string (empty); |
|
135 | - */ |
|
136 | - function search_box($text, $input_id) |
|
137 | - { |
|
138 | - return ''; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * Set the view counts on the _views property |
|
144 | - */ |
|
145 | - protected function _add_view_counts() |
|
146 | - { |
|
147 | - foreach ($this->_views as $view => $args) { |
|
148 | - $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
149 | - $this->_per_page, |
|
150 | - $view, |
|
151 | - true, |
|
152 | - true, |
|
153 | - false |
|
154 | - ); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Custom message for when there are no items found. |
|
161 | - * |
|
162 | - * @since 4.3.0 |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - public function no_items() |
|
166 | - { |
|
167 | - if ($this->_view !== 'trashed') { |
|
168 | - printf( |
|
169 | - esc_html__( |
|
170 | - '%sNo Custom Templates found.%s To create your first custom message template, go to the "Default Message Templates" tab and click the "Create Custom" button next to the template you want to use as a base for the new one.', |
|
171 | - 'event_espresso' |
|
172 | - ), |
|
173 | - '<strong>', |
|
174 | - '</strong>' |
|
175 | - ); |
|
176 | - } else { |
|
177 | - parent::no_items(); |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @param EE_Message_Template_Group $item |
|
184 | - * @return string |
|
185 | - */ |
|
186 | - public function column_cb($item) |
|
187 | - { |
|
188 | - return sprintf('<input type="checkbox" name="checkbox[%s] value="1" />', $item->GRP_ID()); |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * @param EE_Message_Template_Group $item |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - function column_name($item) |
|
197 | - { |
|
198 | - return '<p>' . $item->name() . '</p>'; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @param EE_Message_Template_Group $item |
|
204 | - * @return string |
|
205 | - */ |
|
206 | - function column_description($item) |
|
207 | - { |
|
208 | - return '<p>' . $item->description() . '</p>'; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * @param EE_Message_Template_Group $item |
|
214 | - * @return string |
|
215 | - */ |
|
216 | - function column_actions($item) |
|
217 | - { |
|
218 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
219 | - 'ee_edit_messages', |
|
220 | - 'espresso_messages_add_new_message_template' |
|
221 | - )) { |
|
222 | - $create_args = array( |
|
223 | - 'GRP_ID' => $item->ID(), |
|
224 | - 'messenger' => $item->messenger(), |
|
225 | - 'message_type' => $item->message_type(), |
|
226 | - 'action' => 'add_new_message_template', |
|
227 | - ); |
|
228 | - $create_link = EE_Admin_Page::add_query_args_and_nonce($create_args, EE_MSG_ADMIN_URL); |
|
229 | - return sprintf( |
|
230 | - '<p><a href="%s" class="button button-small">%s</a></p>', |
|
231 | - $create_link, |
|
232 | - esc_html__('Create Custom', 'event_espresso') |
|
233 | - ); |
|
234 | - } |
|
235 | - return ''; |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Return the content for the messenger column |
|
241 | - * @param EE_Message_Template_Group $item |
|
242 | - * @return string |
|
243 | - */ |
|
244 | - function column_messenger($item) |
|
245 | - { |
|
246 | - |
|
247 | - //Build row actions |
|
248 | - $actions = array(); |
|
249 | - $edit_lnk_url = ''; |
|
250 | - |
|
251 | - // edit link but only if item isn't trashed. |
|
252 | - if (! $item->get('MTP_deleted') |
|
253 | - && EE_Registry::instance()->CAP->current_user_can( |
|
254 | - 'ee_edit_message', |
|
255 | - 'espresso_messages_edit_message_template', |
|
256 | - $item->ID() |
|
257 | - ) |
|
258 | - ) { |
|
259 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
260 | - 'action' => 'edit_message_template', |
|
261 | - 'id' => $item->GRP_ID(), |
|
262 | - ), EE_MSG_ADMIN_URL); |
|
263 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '"' |
|
264 | - . ' class="' . $item->message_type() . '-edit-link"' |
|
265 | - . ' title="' |
|
266 | - . esc_attr__('Edit Template', 'event_espresso') |
|
267 | - . '">' |
|
268 | - . esc_html__('Edit', 'event_espresso') |
|
269 | - . '</a>'; |
|
270 | - } |
|
271 | - |
|
272 | - $name_link = ! $item->get('MTP_deleted') |
|
273 | - && EE_Registry::instance()->CAP->current_user_can( |
|
274 | - 'ee_edit_message', |
|
275 | - 'espresso_messages_edit_message_template', |
|
276 | - $item->ID() |
|
277 | - ) |
|
278 | - && $edit_lnk_url |
|
279 | - ? '<a href="' |
|
280 | - . $edit_lnk_url |
|
281 | - . '" title="' |
|
282 | - . esc_attr__('Edit Template', 'event_espresso') |
|
283 | - . '">' |
|
284 | - . ucwords($item->messenger_obj()->label['singular']) |
|
285 | - . '</a>' |
|
286 | - : ucwords($item->messenger_obj()->label['singular']); |
|
287 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'trash_message_template', |
|
288 | - 'id' => $item->GRP_ID(), |
|
289 | - 'noheader' => true, |
|
290 | - ), EE_MSG_ADMIN_URL); |
|
291 | - // restore link |
|
292 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'restore_message_template', |
|
293 | - 'id' => $item->GRP_ID(), |
|
294 | - 'noheader' => true, |
|
295 | - ), EE_MSG_ADMIN_URL); |
|
296 | - // delete price link |
|
297 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_message_template', |
|
298 | - 'id' => $item->GRP_ID(), |
|
299 | - 'noheader' => true, |
|
300 | - ), EE_MSG_ADMIN_URL); |
|
301 | - |
|
302 | - if (! $item->get('MTP_deleted') |
|
303 | - && EE_Registry::instance()->CAP->current_user_can( |
|
304 | - 'ee_delete_message', |
|
305 | - 'espresso_messages_trash_message_template', |
|
306 | - $item->ID() |
|
307 | - ) |
|
308 | - ) { |
|
309 | - $actions['trash'] = '<a href="' |
|
310 | - . $trash_lnk_url |
|
311 | - . '" title="' |
|
312 | - . esc_attr__('Move Template Group to Trash', 'event_espresso') |
|
313 | - . '">' |
|
314 | - . esc_html__('Move to Trash', 'event_espresso') |
|
315 | - . '</a>'; |
|
316 | - } else { |
|
317 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
318 | - 'ee_delete_message', |
|
319 | - 'espresso_messages_restore_message_template', |
|
320 | - $item->ID() |
|
321 | - )) { |
|
322 | - $actions['restore'] = '<a href="' |
|
323 | - . $restore_lnk_url |
|
324 | - . '" title="' |
|
325 | - . esc_attr__('Restore Message Template', 'event_espresso') |
|
326 | - . '">' |
|
327 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
328 | - } |
|
329 | - |
|
330 | - if ($this->_view == 'trashed' |
|
331 | - && EE_Registry::instance()->CAP->current_user_can( |
|
332 | - 'ee_delete_message', |
|
333 | - 'espresso_messages_delete_message_template', |
|
334 | - $item->ID() |
|
335 | - )) { |
|
336 | - $actions['delete'] = '<a href="' |
|
337 | - . $delete_lnk_url |
|
338 | - . '" title="' |
|
339 | - . esc_attr__('Delete Template Group Permanently', 'event_espresso') |
|
340 | - . '">' |
|
341 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
342 | - . '</a>'; |
|
343 | - } |
|
344 | - } |
|
345 | - |
|
346 | - //we want to display the contexts in here so we need to set them up |
|
347 | - $c_label = $item->context_label(); |
|
348 | - $c_configs = $item->contexts_config(); |
|
349 | - $ctxt = array(); |
|
350 | - $context_templates = $item->context_templates(); |
|
351 | - foreach ($context_templates as $context => $template_fields) { |
|
352 | - $mtp_to = ! empty($context_templates[$context]['to']) |
|
353 | - && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
354 | - ? $context_templates[$context]['to']->get('MTP_content') |
|
355 | - : null; |
|
356 | - $inactive = empty($mtp_to) && ! empty($context_templates[$context]['to']) |
|
357 | - ? ' class="mtp-inactive"' |
|
358 | - : ''; |
|
359 | - $context_title = ucwords($c_configs[$context]['label']); |
|
360 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit_message_template', |
|
361 | - 'id' => $item->GRP_ID(), |
|
362 | - 'context' => $context, |
|
363 | - ), EE_MSG_ADMIN_URL); |
|
364 | - $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
365 | - 'ee_edit_message', |
|
366 | - 'espresso_messages_edit_message_template', |
|
367 | - $item->ID() |
|
368 | - ) |
|
369 | - ? '<a' |
|
370 | - . $inactive |
|
371 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
372 | - . ' href="' . $edit_link . '"' |
|
373 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
374 | - . $context_title |
|
375 | - . '</a>' |
|
376 | - : $context_title; |
|
377 | - } |
|
378 | - |
|
379 | - $ctx_content = ! $item->get('MTP_deleted') |
|
380 | - && EE_Registry::instance()->CAP->current_user_can( |
|
381 | - 'ee_edit_message', |
|
382 | - 'espresso_messages_edit_message_template', |
|
383 | - $item->ID() |
|
384 | - ) |
|
385 | - ? sprintf( |
|
386 | - '<strong>%s:</strong> ', |
|
387 | - ucwords($c_label['plural']) |
|
388 | - ) |
|
389 | - . implode(' | ', $ctxt) |
|
390 | - : ''; |
|
391 | - |
|
392 | - |
|
393 | - //Return the name contents |
|
394 | - return sprintf( |
|
395 | - '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
396 | - /* $1%s */ |
|
397 | - $name_link, |
|
398 | - /* $2%s */ |
|
399 | - $item->GRP_ID(), |
|
400 | - /* %4$s */ |
|
401 | - $ctx_content, |
|
402 | - /* $3%s */ |
|
403 | - $this->row_actions($actions) |
|
404 | - ); |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * column_events |
|
409 | - * This provides a count of events using this custom template |
|
410 | - * |
|
411 | - * @param EE_Message_Template_Group $item message_template group data |
|
412 | - * @return string column output |
|
413 | - */ |
|
414 | - function column_events($item) |
|
415 | - { |
|
416 | - return $item->count_events(); |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * column_message_type |
|
421 | - * |
|
422 | - * @param EE_Message_Template_Group $item message info for the row |
|
423 | - * @return string message_type name |
|
424 | - */ |
|
425 | - function column_message_type($item) |
|
426 | - { |
|
427 | - return ucwords($item->message_type_obj()->label['singular']); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Generate dropdown filter select input for messengers |
|
433 | - * |
|
434 | - * @return string |
|
435 | - */ |
|
436 | - protected function _get_messengers_dropdown_filter() |
|
437 | - { |
|
438 | - $messenger_options = array(); |
|
439 | - $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
440 | - array( |
|
441 | - array( |
|
442 | - 'MTP_is_active' => true, |
|
443 | - 'MTP_is_global' => false, |
|
444 | - ), |
|
445 | - 'group_by' => 'MTP_messenger', |
|
446 | - ) |
|
447 | - ); |
|
448 | - |
|
449 | - foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
450 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
451 | - $messenger = $active_message_template_group->messenger_obj(); |
|
452 | - $messenger_label = $messenger instanceof EE_messenger |
|
453 | - ? $messenger->label['singular'] |
|
454 | - : $active_message_template_group->messenger(); |
|
455 | - $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
456 | - } |
|
457 | - } |
|
458 | - return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * Generate dropdown filter select input for message types |
|
464 | - * |
|
465 | - * @return string |
|
466 | - */ |
|
467 | - protected function _get_message_types_dropdown_filter() |
|
468 | - { |
|
469 | - $message_type_options = array(); |
|
470 | - $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
471 | - array( |
|
472 | - array( |
|
473 | - 'MTP_is_active' => true, |
|
474 | - 'MTP_is_global' => false, |
|
475 | - ), |
|
476 | - 'group_by' => 'MTP_message_type', |
|
477 | - ) |
|
478 | - ); |
|
479 | - |
|
480 | - foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
481 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
482 | - $message_type = $active_message_template_group->message_type_obj(); |
|
483 | - $message_type_label = $message_type instanceof EE_message_type |
|
484 | - ? $message_type->label['singular'] |
|
485 | - : $active_message_template_group->message_type(); |
|
486 | - $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
487 | - } |
|
488 | - } |
|
489 | - return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
490 | - } |
|
15 | + /** |
|
16 | + * Custom_Messages_Template_List_Table constructor. |
|
17 | + * |
|
18 | + * @param EE_Admin_Page $admin_page |
|
19 | + */ |
|
20 | + public function __construct($admin_page) |
|
21 | + { |
|
22 | + //Set parent defaults |
|
23 | + parent::__construct($admin_page); |
|
24 | + } |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * @return Messages_Admin_Page |
|
29 | + */ |
|
30 | + public function get_admin_page() |
|
31 | + { |
|
32 | + return $this->_admin_page; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Setup initial data. |
|
37 | + */ |
|
38 | + protected function _setup_data() |
|
39 | + { |
|
40 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
41 | + $this->_per_page, |
|
42 | + $this->_view, |
|
43 | + false, |
|
44 | + false, |
|
45 | + false |
|
46 | + ); |
|
47 | + $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
48 | + $this->_per_page, |
|
49 | + $this->_view, |
|
50 | + true, |
|
51 | + true, |
|
52 | + false |
|
53 | + ); |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Set initial properties |
|
59 | + */ |
|
60 | + protected function _set_properties() |
|
61 | + { |
|
62 | + $this->_wp_list_args = array( |
|
63 | + 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
64 | + 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
65 | + 'ajax' => true, //for now, |
|
66 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
67 | + ); |
|
68 | + |
|
69 | + $this->_columns = array( |
|
70 | + 'cb' => '<input type="checkbox" />', |
|
71 | + 'name' => esc_html__('Template Name', 'event_espresso'), |
|
72 | + 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
73 | + 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
74 | + 'description' => esc_html__('Description', 'event_espresso'), |
|
75 | + 'events' => esc_html__('Events', 'event_espresso'), |
|
76 | + //count of events using this template. |
|
77 | + 'actions' => '' |
|
78 | + ); |
|
79 | + |
|
80 | + $this->_sortable_columns = array( |
|
81 | + 'messenger' => array('MTP_messenger' => true), |
|
82 | + ); |
|
83 | + |
|
84 | + $this->_hidden_columns = array(); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
90 | + * message_type or messenger object before generating the row. |
|
91 | + * |
|
92 | + * @param EE_Message_Template_Group $item |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function single_row($item) |
|
96 | + { |
|
97 | + $message_type = $item->message_type_obj(); |
|
98 | + $messenger = $item->messenger_obj(); |
|
99 | + |
|
100 | + if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
101 | + echo ''; |
|
102 | + return; |
|
103 | + } |
|
104 | + |
|
105 | + parent::single_row($item); |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + protected function _get_table_filters() |
|
113 | + { |
|
114 | + $filters = array(); |
|
115 | + |
|
116 | + //get select inputs |
|
117 | + $select_inputs = array( |
|
118 | + $this->_get_messengers_dropdown_filter(), |
|
119 | + $this->_get_message_types_dropdown_filter(), |
|
120 | + ); |
|
121 | + |
|
122 | + //set filters to select inputs if they aren't empty |
|
123 | + foreach ($select_inputs as $select_input) { |
|
124 | + if ($select_input) { |
|
125 | + $filters[] = $select_input; |
|
126 | + } |
|
127 | + } |
|
128 | + return $filters; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * we're just removing the search box for message templates, not needed. |
|
133 | + * |
|
134 | + * @return string (empty); |
|
135 | + */ |
|
136 | + function search_box($text, $input_id) |
|
137 | + { |
|
138 | + return ''; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * Set the view counts on the _views property |
|
144 | + */ |
|
145 | + protected function _add_view_counts() |
|
146 | + { |
|
147 | + foreach ($this->_views as $view => $args) { |
|
148 | + $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
149 | + $this->_per_page, |
|
150 | + $view, |
|
151 | + true, |
|
152 | + true, |
|
153 | + false |
|
154 | + ); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Custom message for when there are no items found. |
|
161 | + * |
|
162 | + * @since 4.3.0 |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + public function no_items() |
|
166 | + { |
|
167 | + if ($this->_view !== 'trashed') { |
|
168 | + printf( |
|
169 | + esc_html__( |
|
170 | + '%sNo Custom Templates found.%s To create your first custom message template, go to the "Default Message Templates" tab and click the "Create Custom" button next to the template you want to use as a base for the new one.', |
|
171 | + 'event_espresso' |
|
172 | + ), |
|
173 | + '<strong>', |
|
174 | + '</strong>' |
|
175 | + ); |
|
176 | + } else { |
|
177 | + parent::no_items(); |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @param EE_Message_Template_Group $item |
|
184 | + * @return string |
|
185 | + */ |
|
186 | + public function column_cb($item) |
|
187 | + { |
|
188 | + return sprintf('<input type="checkbox" name="checkbox[%s] value="1" />', $item->GRP_ID()); |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * @param EE_Message_Template_Group $item |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + function column_name($item) |
|
197 | + { |
|
198 | + return '<p>' . $item->name() . '</p>'; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @param EE_Message_Template_Group $item |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + function column_description($item) |
|
207 | + { |
|
208 | + return '<p>' . $item->description() . '</p>'; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * @param EE_Message_Template_Group $item |
|
214 | + * @return string |
|
215 | + */ |
|
216 | + function column_actions($item) |
|
217 | + { |
|
218 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
219 | + 'ee_edit_messages', |
|
220 | + 'espresso_messages_add_new_message_template' |
|
221 | + )) { |
|
222 | + $create_args = array( |
|
223 | + 'GRP_ID' => $item->ID(), |
|
224 | + 'messenger' => $item->messenger(), |
|
225 | + 'message_type' => $item->message_type(), |
|
226 | + 'action' => 'add_new_message_template', |
|
227 | + ); |
|
228 | + $create_link = EE_Admin_Page::add_query_args_and_nonce($create_args, EE_MSG_ADMIN_URL); |
|
229 | + return sprintf( |
|
230 | + '<p><a href="%s" class="button button-small">%s</a></p>', |
|
231 | + $create_link, |
|
232 | + esc_html__('Create Custom', 'event_espresso') |
|
233 | + ); |
|
234 | + } |
|
235 | + return ''; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Return the content for the messenger column |
|
241 | + * @param EE_Message_Template_Group $item |
|
242 | + * @return string |
|
243 | + */ |
|
244 | + function column_messenger($item) |
|
245 | + { |
|
246 | + |
|
247 | + //Build row actions |
|
248 | + $actions = array(); |
|
249 | + $edit_lnk_url = ''; |
|
250 | + |
|
251 | + // edit link but only if item isn't trashed. |
|
252 | + if (! $item->get('MTP_deleted') |
|
253 | + && EE_Registry::instance()->CAP->current_user_can( |
|
254 | + 'ee_edit_message', |
|
255 | + 'espresso_messages_edit_message_template', |
|
256 | + $item->ID() |
|
257 | + ) |
|
258 | + ) { |
|
259 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
260 | + 'action' => 'edit_message_template', |
|
261 | + 'id' => $item->GRP_ID(), |
|
262 | + ), EE_MSG_ADMIN_URL); |
|
263 | + $actions['edit'] = '<a href="' . $edit_lnk_url . '"' |
|
264 | + . ' class="' . $item->message_type() . '-edit-link"' |
|
265 | + . ' title="' |
|
266 | + . esc_attr__('Edit Template', 'event_espresso') |
|
267 | + . '">' |
|
268 | + . esc_html__('Edit', 'event_espresso') |
|
269 | + . '</a>'; |
|
270 | + } |
|
271 | + |
|
272 | + $name_link = ! $item->get('MTP_deleted') |
|
273 | + && EE_Registry::instance()->CAP->current_user_can( |
|
274 | + 'ee_edit_message', |
|
275 | + 'espresso_messages_edit_message_template', |
|
276 | + $item->ID() |
|
277 | + ) |
|
278 | + && $edit_lnk_url |
|
279 | + ? '<a href="' |
|
280 | + . $edit_lnk_url |
|
281 | + . '" title="' |
|
282 | + . esc_attr__('Edit Template', 'event_espresso') |
|
283 | + . '">' |
|
284 | + . ucwords($item->messenger_obj()->label['singular']) |
|
285 | + . '</a>' |
|
286 | + : ucwords($item->messenger_obj()->label['singular']); |
|
287 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'trash_message_template', |
|
288 | + 'id' => $item->GRP_ID(), |
|
289 | + 'noheader' => true, |
|
290 | + ), EE_MSG_ADMIN_URL); |
|
291 | + // restore link |
|
292 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'restore_message_template', |
|
293 | + 'id' => $item->GRP_ID(), |
|
294 | + 'noheader' => true, |
|
295 | + ), EE_MSG_ADMIN_URL); |
|
296 | + // delete price link |
|
297 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_message_template', |
|
298 | + 'id' => $item->GRP_ID(), |
|
299 | + 'noheader' => true, |
|
300 | + ), EE_MSG_ADMIN_URL); |
|
301 | + |
|
302 | + if (! $item->get('MTP_deleted') |
|
303 | + && EE_Registry::instance()->CAP->current_user_can( |
|
304 | + 'ee_delete_message', |
|
305 | + 'espresso_messages_trash_message_template', |
|
306 | + $item->ID() |
|
307 | + ) |
|
308 | + ) { |
|
309 | + $actions['trash'] = '<a href="' |
|
310 | + . $trash_lnk_url |
|
311 | + . '" title="' |
|
312 | + . esc_attr__('Move Template Group to Trash', 'event_espresso') |
|
313 | + . '">' |
|
314 | + . esc_html__('Move to Trash', 'event_espresso') |
|
315 | + . '</a>'; |
|
316 | + } else { |
|
317 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
318 | + 'ee_delete_message', |
|
319 | + 'espresso_messages_restore_message_template', |
|
320 | + $item->ID() |
|
321 | + )) { |
|
322 | + $actions['restore'] = '<a href="' |
|
323 | + . $restore_lnk_url |
|
324 | + . '" title="' |
|
325 | + . esc_attr__('Restore Message Template', 'event_espresso') |
|
326 | + . '">' |
|
327 | + . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
328 | + } |
|
329 | + |
|
330 | + if ($this->_view == 'trashed' |
|
331 | + && EE_Registry::instance()->CAP->current_user_can( |
|
332 | + 'ee_delete_message', |
|
333 | + 'espresso_messages_delete_message_template', |
|
334 | + $item->ID() |
|
335 | + )) { |
|
336 | + $actions['delete'] = '<a href="' |
|
337 | + . $delete_lnk_url |
|
338 | + . '" title="' |
|
339 | + . esc_attr__('Delete Template Group Permanently', 'event_espresso') |
|
340 | + . '">' |
|
341 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
342 | + . '</a>'; |
|
343 | + } |
|
344 | + } |
|
345 | + |
|
346 | + //we want to display the contexts in here so we need to set them up |
|
347 | + $c_label = $item->context_label(); |
|
348 | + $c_configs = $item->contexts_config(); |
|
349 | + $ctxt = array(); |
|
350 | + $context_templates = $item->context_templates(); |
|
351 | + foreach ($context_templates as $context => $template_fields) { |
|
352 | + $mtp_to = ! empty($context_templates[$context]['to']) |
|
353 | + && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
354 | + ? $context_templates[$context]['to']->get('MTP_content') |
|
355 | + : null; |
|
356 | + $inactive = empty($mtp_to) && ! empty($context_templates[$context]['to']) |
|
357 | + ? ' class="mtp-inactive"' |
|
358 | + : ''; |
|
359 | + $context_title = ucwords($c_configs[$context]['label']); |
|
360 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit_message_template', |
|
361 | + 'id' => $item->GRP_ID(), |
|
362 | + 'context' => $context, |
|
363 | + ), EE_MSG_ADMIN_URL); |
|
364 | + $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
365 | + 'ee_edit_message', |
|
366 | + 'espresso_messages_edit_message_template', |
|
367 | + $item->ID() |
|
368 | + ) |
|
369 | + ? '<a' |
|
370 | + . $inactive |
|
371 | + . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
372 | + . ' href="' . $edit_link . '"' |
|
373 | + . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
374 | + . $context_title |
|
375 | + . '</a>' |
|
376 | + : $context_title; |
|
377 | + } |
|
378 | + |
|
379 | + $ctx_content = ! $item->get('MTP_deleted') |
|
380 | + && EE_Registry::instance()->CAP->current_user_can( |
|
381 | + 'ee_edit_message', |
|
382 | + 'espresso_messages_edit_message_template', |
|
383 | + $item->ID() |
|
384 | + ) |
|
385 | + ? sprintf( |
|
386 | + '<strong>%s:</strong> ', |
|
387 | + ucwords($c_label['plural']) |
|
388 | + ) |
|
389 | + . implode(' | ', $ctxt) |
|
390 | + : ''; |
|
391 | + |
|
392 | + |
|
393 | + //Return the name contents |
|
394 | + return sprintf( |
|
395 | + '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
396 | + /* $1%s */ |
|
397 | + $name_link, |
|
398 | + /* $2%s */ |
|
399 | + $item->GRP_ID(), |
|
400 | + /* %4$s */ |
|
401 | + $ctx_content, |
|
402 | + /* $3%s */ |
|
403 | + $this->row_actions($actions) |
|
404 | + ); |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * column_events |
|
409 | + * This provides a count of events using this custom template |
|
410 | + * |
|
411 | + * @param EE_Message_Template_Group $item message_template group data |
|
412 | + * @return string column output |
|
413 | + */ |
|
414 | + function column_events($item) |
|
415 | + { |
|
416 | + return $item->count_events(); |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * column_message_type |
|
421 | + * |
|
422 | + * @param EE_Message_Template_Group $item message info for the row |
|
423 | + * @return string message_type name |
|
424 | + */ |
|
425 | + function column_message_type($item) |
|
426 | + { |
|
427 | + return ucwords($item->message_type_obj()->label['singular']); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Generate dropdown filter select input for messengers |
|
433 | + * |
|
434 | + * @return string |
|
435 | + */ |
|
436 | + protected function _get_messengers_dropdown_filter() |
|
437 | + { |
|
438 | + $messenger_options = array(); |
|
439 | + $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
440 | + array( |
|
441 | + array( |
|
442 | + 'MTP_is_active' => true, |
|
443 | + 'MTP_is_global' => false, |
|
444 | + ), |
|
445 | + 'group_by' => 'MTP_messenger', |
|
446 | + ) |
|
447 | + ); |
|
448 | + |
|
449 | + foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
450 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
451 | + $messenger = $active_message_template_group->messenger_obj(); |
|
452 | + $messenger_label = $messenger instanceof EE_messenger |
|
453 | + ? $messenger->label['singular'] |
|
454 | + : $active_message_template_group->messenger(); |
|
455 | + $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
456 | + } |
|
457 | + } |
|
458 | + return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * Generate dropdown filter select input for message types |
|
464 | + * |
|
465 | + * @return string |
|
466 | + */ |
|
467 | + protected function _get_message_types_dropdown_filter() |
|
468 | + { |
|
469 | + $message_type_options = array(); |
|
470 | + $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
471 | + array( |
|
472 | + array( |
|
473 | + 'MTP_is_active' => true, |
|
474 | + 'MTP_is_global' => false, |
|
475 | + ), |
|
476 | + 'group_by' => 'MTP_message_type', |
|
477 | + ) |
|
478 | + ); |
|
479 | + |
|
480 | + foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
481 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
482 | + $message_type = $active_message_template_group->message_type_obj(); |
|
483 | + $message_type_label = $message_type instanceof EE_message_type |
|
484 | + ? $message_type->label['singular'] |
|
485 | + : $active_message_template_group->message_type(); |
|
486 | + $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
487 | + } |
|
488 | + } |
|
489 | + return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
490 | + } |
|
491 | 491 | |
492 | 492 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | protected function _setup_data() |
39 | 39 | { |
40 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
40 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
41 | 41 | $this->_per_page, |
42 | 42 | $this->_view, |
43 | 43 | false, |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $message_type = $item->message_type_obj(); |
98 | 98 | $messenger = $item->messenger_obj(); |
99 | 99 | |
100 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
100 | + if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
101 | 101 | echo ''; |
102 | 102 | return; |
103 | 103 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | function column_name($item) |
197 | 197 | { |
198 | - return '<p>' . $item->name() . '</p>'; |
|
198 | + return '<p>'.$item->name().'</p>'; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | */ |
206 | 206 | function column_description($item) |
207 | 207 | { |
208 | - return '<p>' . $item->description() . '</p>'; |
|
208 | + return '<p>'.$item->description().'</p>'; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -249,19 +249,19 @@ discard block |
||
249 | 249 | $edit_lnk_url = ''; |
250 | 250 | |
251 | 251 | // edit link but only if item isn't trashed. |
252 | - if (! $item->get('MTP_deleted') |
|
252 | + if ( ! $item->get('MTP_deleted') |
|
253 | 253 | && EE_Registry::instance()->CAP->current_user_can( |
254 | 254 | 'ee_edit_message', |
255 | 255 | 'espresso_messages_edit_message_template', |
256 | 256 | $item->ID() |
257 | 257 | ) |
258 | 258 | ) { |
259 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
259 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
260 | 260 | 'action' => 'edit_message_template', |
261 | 261 | 'id' => $item->GRP_ID(), |
262 | 262 | ), EE_MSG_ADMIN_URL); |
263 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '"' |
|
264 | - . ' class="' . $item->message_type() . '-edit-link"' |
|
263 | + $actions['edit'] = '<a href="'.$edit_lnk_url.'"' |
|
264 | + . ' class="'.$item->message_type().'-edit-link"' |
|
265 | 265 | . ' title="' |
266 | 266 | . esc_attr__('Edit Template', 'event_espresso') |
267 | 267 | . '">' |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | . '</a>'; |
270 | 270 | } |
271 | 271 | |
272 | - $name_link = ! $item->get('MTP_deleted') |
|
272 | + $name_link = ! $item->get('MTP_deleted') |
|
273 | 273 | && EE_Registry::instance()->CAP->current_user_can( |
274 | 274 | 'ee_edit_message', |
275 | 275 | 'espresso_messages_edit_message_template', |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | 'noheader' => true, |
300 | 300 | ), EE_MSG_ADMIN_URL); |
301 | 301 | |
302 | - if (! $item->get('MTP_deleted') |
|
302 | + if ( ! $item->get('MTP_deleted') |
|
303 | 303 | && EE_Registry::instance()->CAP->current_user_can( |
304 | 304 | 'ee_delete_message', |
305 | 305 | 'espresso_messages_trash_message_template', |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | . '" title="' |
325 | 325 | . esc_attr__('Restore Message Template', 'event_espresso') |
326 | 326 | . '">' |
327 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
327 | + . esc_html__('Restore', 'event_espresso').'</a>'; |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | if ($this->_view == 'trashed' |
@@ -361,16 +361,16 @@ discard block |
||
361 | 361 | 'id' => $item->GRP_ID(), |
362 | 362 | 'context' => $context, |
363 | 363 | ), EE_MSG_ADMIN_URL); |
364 | - $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
364 | + $ctxt[] = EE_Registry::instance()->CAP->current_user_can( |
|
365 | 365 | 'ee_edit_message', |
366 | 366 | 'espresso_messages_edit_message_template', |
367 | 367 | $item->ID() |
368 | 368 | ) |
369 | 369 | ? '<a' |
370 | 370 | . $inactive |
371 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
372 | - . ' href="' . $edit_link . '"' |
|
373 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
371 | + . ' class="'.$item->message_type().'-'.$context.'-edit-link"' |
|
372 | + . ' href="'.$edit_link.'"' |
|
373 | + . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">' |
|
374 | 374 | . $context_title |
375 | 375 | . '</a>' |
376 | 376 | : $context_title; |
@@ -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 | /** |
@@ -32,224 +32,224 @@ discard block |
||
32 | 32 | { |
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * This is used to hold the reports template data which is setup early in the request. |
|
37 | - * @type array |
|
38 | - */ |
|
39 | - protected $_reports_template_data = array(); |
|
40 | - |
|
41 | - /** |
|
42 | - * @Constructor |
|
43 | - * @access public |
|
44 | - * |
|
45 | - * @param bool $routing |
|
46 | - * |
|
47 | - * @return \Extend_Transactions_Admin_Page |
|
48 | - */ |
|
49 | - public function __construct($routing = true) |
|
50 | - { |
|
51 | - parent::__construct($routing); |
|
52 | - define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/'); |
|
53 | - define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/'); |
|
54 | - define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/'); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * _extend_page_config |
|
60 | - * |
|
61 | - * @access protected |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - protected function _extend_page_config() |
|
65 | - { |
|
66 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions'; |
|
67 | - |
|
68 | - $new_page_routes = array( |
|
69 | - 'reports' => array( |
|
70 | - 'func' => '_transaction_reports', |
|
71 | - 'capability' => 'ee_read_transactions' |
|
72 | - ) |
|
73 | - ); |
|
74 | - |
|
75 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
76 | - |
|
77 | - $new_page_config = array( |
|
78 | - 'reports' => array( |
|
79 | - 'nav' => array( |
|
80 | - 'label' => __('Reports', 'event_espresso'), |
|
81 | - 'order' => 20 |
|
82 | - ), |
|
83 | - 'help_tabs' => array( |
|
84 | - 'transactions_reports_help_tab' => array( |
|
85 | - 'title' => __('Transaction Reports', 'event_espresso'), |
|
86 | - 'filename' => 'transactions_reports' |
|
87 | - ) |
|
88 | - ), |
|
89 | - /*'help_tour' => array( 'Transaction_Reports_Help_Tour' ),*/ |
|
90 | - 'require_nonce' => false |
|
91 | - ) |
|
92 | - ); |
|
93 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * load_scripts_styles_reports |
|
99 | - * |
|
100 | - * @access public |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - public function load_scripts_styles_reports() |
|
104 | - { |
|
105 | - wp_register_script( |
|
106 | - 'ee-txn-reports-js', |
|
107 | - TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js', |
|
108 | - array('google-charts'), |
|
109 | - EVENT_ESPRESSO_VERSION, |
|
110 | - true |
|
111 | - ); |
|
112 | - wp_enqueue_script('ee-txn-reports-js'); |
|
113 | - $this->_transaction_reports_js_setup(); |
|
114 | - EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts(); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
120 | - * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method. |
|
121 | - */ |
|
122 | - protected function _transaction_reports_js_setup() |
|
123 | - { |
|
124 | - $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report(); |
|
125 | - $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report(); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * _transaction_reports |
|
131 | - * generates Business Reports regarding Transactions |
|
132 | - * |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - protected function _transaction_reports() |
|
136 | - { |
|
137 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
138 | - $this->_admin_page_title = __('Transactions', 'event_espresso'); |
|
139 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
|
140 | - $this->_reports_template_data, true); |
|
141 | - |
|
142 | - // the final template wrapper |
|
143 | - $this->display_admin_page_with_no_sidebar(); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * _revenue_per_day_report |
|
149 | - * generates Business Report showing Total Revenue per Day. |
|
150 | - * |
|
151 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
152 | - * |
|
153 | - * @return string |
|
154 | - */ |
|
155 | - private function _revenue_per_day_report($period = '-1 month') |
|
156 | - { |
|
157 | - |
|
158 | - $report_ID = 'txn-admin-revenue-per-day-report-dv'; |
|
159 | - |
|
160 | - $TXN = EEM_Transaction::instance(); |
|
161 | - |
|
162 | - $results = $TXN->get_revenue_per_day_report($period); |
|
163 | - $results = (array)$results; |
|
164 | - $revenue = array(); |
|
165 | - $subtitle = ''; |
|
166 | - |
|
167 | - if ($results) { |
|
168 | - $revenue[] = array( |
|
169 | - __('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'), |
|
170 | - __('Total Revenue', 'event_espresso') |
|
171 | - ); |
|
172 | - foreach ($results as $result) { |
|
173 | - $revenue[] = array($result->txnDate, (float)$result->revenue); |
|
174 | - } |
|
175 | - |
|
176 | - //setup the date range. |
|
177 | - $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
178 | - $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
179 | - $subtitle = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
|
180 | - $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d')); |
|
181 | - } |
|
182 | - |
|
183 | - $report_title = esc_html__('Total Revenue per Day', 'event_espresso'); |
|
184 | - |
|
185 | - $report_params = array( |
|
186 | - 'title' => $report_title, |
|
187 | - 'subtitle' => $subtitle, |
|
188 | - 'id' => $report_ID, |
|
189 | - 'revenue' => $revenue, |
|
190 | - 'noResults' => empty($revenue) || count($revenue) === 1, |
|
191 | - 'noTxnMsg' => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
|
192 | - '<h2>' . $report_title . '</h2><p>', '</p>') |
|
193 | - ); |
|
194 | - wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params); |
|
195 | - |
|
196 | - return $report_ID; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * _revenue_per_event_report |
|
202 | - * generates Business Report showing total revenue per event. |
|
203 | - * |
|
204 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
205 | - * |
|
206 | - * @return int |
|
207 | - */ |
|
208 | - private function _revenue_per_event_report($period = '-1 month') |
|
209 | - { |
|
210 | - |
|
211 | - $report_ID = 'txn-admin-revenue-per-event-report-dv'; |
|
212 | - |
|
213 | - $TXN = EEM_Transaction::instance(); |
|
214 | - $results = $TXN->get_revenue_per_event_report($period); |
|
215 | - $results = (array)$results; |
|
216 | - $revenue = array(); |
|
217 | - $subtitle = ''; |
|
218 | - |
|
219 | - if ($results) { |
|
220 | - $revenue[] = array( |
|
221 | - __('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'), |
|
222 | - __('Total Revenue', 'event_espresso') |
|
223 | - ); |
|
224 | - foreach ($results as $result) { |
|
225 | - if ($result->revenue > 1) { |
|
226 | - $event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8')); |
|
227 | - $event_name = wp_trim_words($event_name, 5, '...'); |
|
228 | - $revenue[] = array($event_name, (float)$result->revenue); |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - //setup the date range. |
|
233 | - $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
234 | - $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
235 | - $subtitle = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
|
236 | - $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d')); |
|
237 | - } |
|
238 | - |
|
239 | - $report_title = esc_html__('Total Revenue per Event', 'event_espresso'); |
|
240 | - |
|
241 | - $report_params = array( |
|
242 | - 'title' => $report_title, |
|
243 | - 'subtitle' => $subtitle, |
|
244 | - 'id' => $report_ID, |
|
245 | - 'revenue' => $revenue, |
|
246 | - 'noResults' => empty($revenue), |
|
247 | - 'noTxnMsg' => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
|
248 | - '<h2>' . $report_title . '</h2><p>', '</p>') |
|
249 | - ); |
|
250 | - wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params); |
|
251 | - |
|
252 | - return $report_ID; |
|
253 | - } |
|
35 | + /** |
|
36 | + * This is used to hold the reports template data which is setup early in the request. |
|
37 | + * @type array |
|
38 | + */ |
|
39 | + protected $_reports_template_data = array(); |
|
40 | + |
|
41 | + /** |
|
42 | + * @Constructor |
|
43 | + * @access public |
|
44 | + * |
|
45 | + * @param bool $routing |
|
46 | + * |
|
47 | + * @return \Extend_Transactions_Admin_Page |
|
48 | + */ |
|
49 | + public function __construct($routing = true) |
|
50 | + { |
|
51 | + parent::__construct($routing); |
|
52 | + define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/'); |
|
53 | + define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/'); |
|
54 | + define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/'); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * _extend_page_config |
|
60 | + * |
|
61 | + * @access protected |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + protected function _extend_page_config() |
|
65 | + { |
|
66 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions'; |
|
67 | + |
|
68 | + $new_page_routes = array( |
|
69 | + 'reports' => array( |
|
70 | + 'func' => '_transaction_reports', |
|
71 | + 'capability' => 'ee_read_transactions' |
|
72 | + ) |
|
73 | + ); |
|
74 | + |
|
75 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
76 | + |
|
77 | + $new_page_config = array( |
|
78 | + 'reports' => array( |
|
79 | + 'nav' => array( |
|
80 | + 'label' => __('Reports', 'event_espresso'), |
|
81 | + 'order' => 20 |
|
82 | + ), |
|
83 | + 'help_tabs' => array( |
|
84 | + 'transactions_reports_help_tab' => array( |
|
85 | + 'title' => __('Transaction Reports', 'event_espresso'), |
|
86 | + 'filename' => 'transactions_reports' |
|
87 | + ) |
|
88 | + ), |
|
89 | + /*'help_tour' => array( 'Transaction_Reports_Help_Tour' ),*/ |
|
90 | + 'require_nonce' => false |
|
91 | + ) |
|
92 | + ); |
|
93 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * load_scripts_styles_reports |
|
99 | + * |
|
100 | + * @access public |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + public function load_scripts_styles_reports() |
|
104 | + { |
|
105 | + wp_register_script( |
|
106 | + 'ee-txn-reports-js', |
|
107 | + TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js', |
|
108 | + array('google-charts'), |
|
109 | + EVENT_ESPRESSO_VERSION, |
|
110 | + true |
|
111 | + ); |
|
112 | + wp_enqueue_script('ee-txn-reports-js'); |
|
113 | + $this->_transaction_reports_js_setup(); |
|
114 | + EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts(); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
120 | + * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method. |
|
121 | + */ |
|
122 | + protected function _transaction_reports_js_setup() |
|
123 | + { |
|
124 | + $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report(); |
|
125 | + $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report(); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * _transaction_reports |
|
131 | + * generates Business Reports regarding Transactions |
|
132 | + * |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + protected function _transaction_reports() |
|
136 | + { |
|
137 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
138 | + $this->_admin_page_title = __('Transactions', 'event_espresso'); |
|
139 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
|
140 | + $this->_reports_template_data, true); |
|
141 | + |
|
142 | + // the final template wrapper |
|
143 | + $this->display_admin_page_with_no_sidebar(); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * _revenue_per_day_report |
|
149 | + * generates Business Report showing Total Revenue per Day. |
|
150 | + * |
|
151 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
152 | + * |
|
153 | + * @return string |
|
154 | + */ |
|
155 | + private function _revenue_per_day_report($period = '-1 month') |
|
156 | + { |
|
157 | + |
|
158 | + $report_ID = 'txn-admin-revenue-per-day-report-dv'; |
|
159 | + |
|
160 | + $TXN = EEM_Transaction::instance(); |
|
161 | + |
|
162 | + $results = $TXN->get_revenue_per_day_report($period); |
|
163 | + $results = (array)$results; |
|
164 | + $revenue = array(); |
|
165 | + $subtitle = ''; |
|
166 | + |
|
167 | + if ($results) { |
|
168 | + $revenue[] = array( |
|
169 | + __('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'), |
|
170 | + __('Total Revenue', 'event_espresso') |
|
171 | + ); |
|
172 | + foreach ($results as $result) { |
|
173 | + $revenue[] = array($result->txnDate, (float)$result->revenue); |
|
174 | + } |
|
175 | + |
|
176 | + //setup the date range. |
|
177 | + $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
178 | + $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
179 | + $subtitle = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
|
180 | + $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d')); |
|
181 | + } |
|
182 | + |
|
183 | + $report_title = esc_html__('Total Revenue per Day', 'event_espresso'); |
|
184 | + |
|
185 | + $report_params = array( |
|
186 | + 'title' => $report_title, |
|
187 | + 'subtitle' => $subtitle, |
|
188 | + 'id' => $report_ID, |
|
189 | + 'revenue' => $revenue, |
|
190 | + 'noResults' => empty($revenue) || count($revenue) === 1, |
|
191 | + 'noTxnMsg' => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
|
192 | + '<h2>' . $report_title . '</h2><p>', '</p>') |
|
193 | + ); |
|
194 | + wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params); |
|
195 | + |
|
196 | + return $report_ID; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * _revenue_per_event_report |
|
202 | + * generates Business Report showing total revenue per event. |
|
203 | + * |
|
204 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
205 | + * |
|
206 | + * @return int |
|
207 | + */ |
|
208 | + private function _revenue_per_event_report($period = '-1 month') |
|
209 | + { |
|
210 | + |
|
211 | + $report_ID = 'txn-admin-revenue-per-event-report-dv'; |
|
212 | + |
|
213 | + $TXN = EEM_Transaction::instance(); |
|
214 | + $results = $TXN->get_revenue_per_event_report($period); |
|
215 | + $results = (array)$results; |
|
216 | + $revenue = array(); |
|
217 | + $subtitle = ''; |
|
218 | + |
|
219 | + if ($results) { |
|
220 | + $revenue[] = array( |
|
221 | + __('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'), |
|
222 | + __('Total Revenue', 'event_espresso') |
|
223 | + ); |
|
224 | + foreach ($results as $result) { |
|
225 | + if ($result->revenue > 1) { |
|
226 | + $event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8')); |
|
227 | + $event_name = wp_trim_words($event_name, 5, '...'); |
|
228 | + $revenue[] = array($event_name, (float)$result->revenue); |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + //setup the date range. |
|
233 | + $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
234 | + $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
235 | + $subtitle = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
|
236 | + $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d')); |
|
237 | + } |
|
238 | + |
|
239 | + $report_title = esc_html__('Total Revenue per Event', 'event_espresso'); |
|
240 | + |
|
241 | + $report_params = array( |
|
242 | + 'title' => $report_title, |
|
243 | + 'subtitle' => $subtitle, |
|
244 | + 'id' => $report_ID, |
|
245 | + 'revenue' => $revenue, |
|
246 | + 'noResults' => empty($revenue), |
|
247 | + 'noTxnMsg' => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
|
248 | + '<h2>' . $report_title . '</h2><p>', '</p>') |
|
249 | + ); |
|
250 | + wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params); |
|
251 | + |
|
252 | + return $report_ID; |
|
253 | + } |
|
254 | 254 | |
255 | 255 | } |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | public function __construct($routing = true) |
50 | 50 | { |
51 | 51 | parent::__construct($routing); |
52 | - define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/'); |
|
53 | - define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/'); |
|
54 | - define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/'); |
|
52 | + define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'transactions/templates/'); |
|
53 | + define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'transactions/assets/'); |
|
54 | + define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'transactions/assets/'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | protected function _extend_page_config() |
65 | 65 | { |
66 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions'; |
|
66 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'transactions'; |
|
67 | 67 | |
68 | 68 | $new_page_routes = array( |
69 | 69 | 'reports' => array( |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | { |
105 | 105 | wp_register_script( |
106 | 106 | 'ee-txn-reports-js', |
107 | - TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js', |
|
107 | + TXN_CAF_ASSETS_URL.'ee-transaction-admin-reports.js', |
|
108 | 108 | array('google-charts'), |
109 | 109 | EVENT_ESPRESSO_VERSION, |
110 | 110 | true |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | protected function _transaction_reports() |
136 | 136 | { |
137 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
137 | + $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php'; |
|
138 | 138 | $this->_admin_page_title = __('Transactions', 'event_espresso'); |
139 | 139 | $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
140 | 140 | $this->_reports_template_data, true); |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $TXN = EEM_Transaction::instance(); |
161 | 161 | |
162 | 162 | $results = $TXN->get_revenue_per_day_report($period); |
163 | - $results = (array)$results; |
|
163 | + $results = (array) $results; |
|
164 | 164 | $revenue = array(); |
165 | 165 | $subtitle = ''; |
166 | 166 | |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | __('Total Revenue', 'event_espresso') |
171 | 171 | ); |
172 | 172 | foreach ($results as $result) { |
173 | - $revenue[] = array($result->txnDate, (float)$result->revenue); |
|
173 | + $revenue[] = array($result->txnDate, (float) $result->revenue); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | //setup the date range. |
177 | - $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
177 | + $beginning_date = new DateTime('now'.$period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
178 | 178 | $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
179 | 179 | $subtitle = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
180 | 180 | $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d')); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | 'revenue' => $revenue, |
190 | 190 | 'noResults' => empty($revenue) || count($revenue) === 1, |
191 | 191 | 'noTxnMsg' => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
192 | - '<h2>' . $report_title . '</h2><p>', '</p>') |
|
192 | + '<h2>'.$report_title.'</h2><p>', '</p>') |
|
193 | 193 | ); |
194 | 194 | wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params); |
195 | 195 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | |
213 | 213 | $TXN = EEM_Transaction::instance(); |
214 | 214 | $results = $TXN->get_revenue_per_event_report($period); |
215 | - $results = (array)$results; |
|
215 | + $results = (array) $results; |
|
216 | 216 | $revenue = array(); |
217 | 217 | $subtitle = ''; |
218 | 218 | |
@@ -225,12 +225,12 @@ discard block |
||
225 | 225 | if ($result->revenue > 1) { |
226 | 226 | $event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8')); |
227 | 227 | $event_name = wp_trim_words($event_name, 5, '...'); |
228 | - $revenue[] = array($event_name, (float)$result->revenue); |
|
228 | + $revenue[] = array($event_name, (float) $result->revenue); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | 232 | //setup the date range. |
233 | - $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
233 | + $beginning_date = new DateTime('now'.$period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
234 | 234 | $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
235 | 235 | $subtitle = sprintf(_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
236 | 236 | $beginning_date->format('Y-m-d'), $ending_date->format('Y-m-d')); |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | 'revenue' => $revenue, |
246 | 246 | 'noResults' => empty($revenue), |
247 | 247 | 'noTxnMsg' => sprintf(__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
248 | - '<h2>' . $report_title . '</h2><p>', '</p>') |
|
248 | + '<h2>'.$report_title.'</h2><p>', '</p>') |
|
249 | 249 | ); |
250 | 250 | wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params); |
251 | 251 |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | |
165 | 165 | |
166 | 166 | //If there is no event objecdt by now then get out. |
167 | - if (! $this->_event instanceof EE_Event) { |
|
167 | + if ( ! $this->_event instanceof EE_Event) { |
|
168 | 168 | return ''; |
169 | 169 | } |
170 | 170 | |
@@ -190,11 +190,11 @@ discard block |
||
190 | 190 | break; |
191 | 191 | |
192 | 192 | case 'image': |
193 | - return '<img src="' . $venue->feature_image_url(array(200, 200,)) |
|
194 | - . '" alt="' . sprintf( |
|
193 | + return '<img src="'.$venue->feature_image_url(array(200, 200,)) |
|
194 | + . '" alt="'.sprintf( |
|
195 | 195 | esc_attr__('%s Feature Image', 'event_espresso'), |
196 | 196 | $venue->get('VNU_name') |
197 | - ) . '" />'; |
|
197 | + ).'" />'; |
|
198 | 198 | break; |
199 | 199 | |
200 | 200 | case 'phone': |
@@ -16,257 +16,257 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * Will hold the EE_Event if available |
|
21 | - * |
|
22 | - * @var EE_Event |
|
23 | - */ |
|
24 | - protected $_event; |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * Initialize properties |
|
29 | - */ |
|
30 | - protected function _init_props() |
|
31 | - { |
|
32 | - $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
33 | - $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
34 | - $this->_shortcodes = array( |
|
35 | - '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
36 | - '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
37 | - '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
38 | - '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
39 | - '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
40 | - '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
41 | - '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
42 | - '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
43 | - '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
44 | - '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
45 | - '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
46 | - 'This just outputs the venue address in a semantic address format.', |
|
47 | - 'event_espresso' |
|
48 | - ), |
|
49 | - '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
50 | - '[GOOGLE_MAP_URL]' => esc_html__( |
|
51 | - 'URL for the google map associated with the venue.', |
|
52 | - 'event_espresso' |
|
53 | - ), |
|
54 | - '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
55 | - '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Parse incoming shortcode |
|
62 | - * @param string $shortcode |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - protected function _parser($shortcode) |
|
66 | - { |
|
67 | - |
|
68 | - switch ($shortcode) { |
|
69 | - case '[VENUE_TITLE]': |
|
70 | - return $this->_venue('title'); |
|
71 | - break; |
|
72 | - |
|
73 | - case '[VENUE_DESCRIPTION]': |
|
74 | - return $this->_venue('description'); |
|
75 | - break; |
|
76 | - |
|
77 | - case '[VENUE_URL]': |
|
78 | - return $this->_venue('url'); |
|
79 | - break; |
|
80 | - |
|
81 | - case '[VENUE_IMAGE]': |
|
82 | - return $this->_venue('image'); |
|
83 | - break; |
|
84 | - |
|
85 | - case '[VENUE_PHONE]': |
|
86 | - return $this->_venue('phone'); |
|
87 | - break; |
|
88 | - |
|
89 | - case '[VENUE_ADDRESS]': |
|
90 | - return $this->_venue('address'); |
|
91 | - break; |
|
92 | - |
|
93 | - case '[VENUE_ADDRESS2]': |
|
94 | - return $this->_venue('address2'); |
|
95 | - break; |
|
96 | - |
|
97 | - case '[VENUE_CITY]': |
|
98 | - return $this->_venue('city'); |
|
99 | - break; |
|
100 | - |
|
101 | - case '[VENUE_COUNTRY]': |
|
102 | - return $this->_venue('country'); |
|
103 | - break; |
|
104 | - |
|
105 | - case '[VENUE_STATE]': |
|
106 | - return $this->_venue('state'); |
|
107 | - break; |
|
108 | - |
|
109 | - case '[VENUE_ZIP]': |
|
110 | - return $this->_venue('zip'); |
|
111 | - break; |
|
112 | - |
|
113 | - case '[VENUE_FORMATTED_ADDRESS]': |
|
114 | - return $this->_venue('formatted_address'); |
|
115 | - break; |
|
116 | - |
|
117 | - case '[GOOGLE_MAP_URL]': |
|
118 | - return $this->_venue('gmap_url'); |
|
119 | - break; |
|
120 | - |
|
121 | - case '[GOOGLE_MAP_LINK]': |
|
122 | - return $this->_venue('gmap_link'); |
|
123 | - break; |
|
124 | - |
|
125 | - case '[GOOGLE_MAP_IMAGE]': |
|
126 | - return $this->_venue('gmap_link_img'); |
|
127 | - break; |
|
128 | - |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * This retrieves the specified venue information |
|
135 | - * |
|
136 | - * @param string $field What Venue field to retrieve |
|
137 | - * @return string What was retrieved! |
|
138 | - * @throws EE_Error |
|
139 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
140 | - */ |
|
141 | - private function _venue($field) |
|
142 | - { |
|
143 | - //we need the EE_Event object to get the venue. |
|
144 | - $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
145 | - |
|
146 | - //if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the reg_obj instead. |
|
147 | - if (empty($this->_event)) { |
|
148 | - $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
149 | - $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
150 | - |
|
151 | - $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : null; |
|
152 | - |
|
153 | - //if still empty do we have a ticket data item? |
|
154 | - $this->_event = empty($this->_event) |
|
155 | - && $this->_data instanceof EE_Ticket |
|
156 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
157 | - ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event'] |
|
158 | - : $this->_event; |
|
159 | - |
|
160 | - //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee and use that. |
|
161 | - $event = $aee instanceof EE_Messages_Addressee ? reset($aee->events) : array(); |
|
162 | - $this->_event = empty($this->_event) && ! empty($events) ? $event : $this->_event; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - //If there is no event objecdt by now then get out. |
|
167 | - if (! $this->_event instanceof EE_Event) { |
|
168 | - return ''; |
|
169 | - } |
|
170 | - |
|
171 | - /** @var EE_Venue $venue */ |
|
172 | - $venue = $this->_event->get_first_related('Venue'); |
|
173 | - |
|
174 | - if (empty($venue)) { |
|
175 | - return ''; |
|
176 | - } //no venue so get out. |
|
177 | - |
|
178 | - switch ($field) { |
|
179 | - case 'title': |
|
180 | - return $venue->get('VNU_name'); |
|
181 | - break; |
|
182 | - |
|
183 | - case 'description': |
|
184 | - return $venue->get('VNU_desc'); |
|
185 | - break; |
|
186 | - |
|
187 | - case 'url': |
|
188 | - $url = $venue->get('VNU_url'); |
|
189 | - return empty($url) ? $venue->get_permalink() : $url; |
|
190 | - break; |
|
191 | - |
|
192 | - case 'image': |
|
193 | - return '<img src="' . $venue->feature_image_url(array(200, 200,)) |
|
194 | - . '" alt="' . sprintf( |
|
195 | - esc_attr__('%s Feature Image', 'event_espresso'), |
|
196 | - $venue->get('VNU_name') |
|
197 | - ) . '" />'; |
|
198 | - break; |
|
199 | - |
|
200 | - case 'phone': |
|
201 | - return $venue->get('VNU_phone'); |
|
202 | - break; |
|
203 | - |
|
204 | - case 'address': |
|
205 | - return $venue->get('VNU_address'); |
|
206 | - break; |
|
207 | - |
|
208 | - case 'address2': |
|
209 | - return $venue->get('VNU_address2'); |
|
210 | - break; |
|
211 | - |
|
212 | - case 'city': |
|
213 | - return $venue->get('VNU_city'); |
|
214 | - break; |
|
215 | - |
|
216 | - case 'state': |
|
217 | - $state = $venue->state_obj(); |
|
218 | - return is_object($state) ? $state->get('STA_name') : ''; |
|
219 | - break; |
|
220 | - |
|
221 | - case 'country': |
|
222 | - $country = $venue->country_obj(); |
|
223 | - return is_object($country) ? $country->get('CNT_name') : ''; |
|
224 | - break; |
|
225 | - |
|
226 | - case 'zip': |
|
227 | - return $venue->get('VNU_zip'); |
|
228 | - break; |
|
229 | - |
|
230 | - case 'formatted_address': |
|
231 | - return EEH_Address::format($venue); |
|
232 | - break; |
|
233 | - |
|
234 | - case 'gmap_link': |
|
235 | - case 'gmap_url': |
|
236 | - case 'gmap_link_img': |
|
237 | - $atts = $this->get_map_attributes($venue, $field); |
|
238 | - return EEH_Maps::google_map_link($atts); |
|
239 | - break; |
|
240 | - } |
|
241 | - return ''; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * Generates the attributes for retrieving a google_map artifact. |
|
247 | - * @param EE_Venue $venue |
|
248 | - * @param string $field |
|
249 | - * @return array |
|
250 | - * @throws EE_Error |
|
251 | - */ |
|
252 | - protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
253 | - { |
|
254 | - $state = $venue->state_obj(); |
|
255 | - $country = $venue->country_obj(); |
|
256 | - $atts = array( |
|
257 | - 'id' => $venue->ID(), |
|
258 | - 'address' => $venue->get('VNU_address'), |
|
259 | - 'city' => $venue->get('VNU_city'), |
|
260 | - 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
261 | - 'zip' => $venue->get('VNU_zip'), |
|
262 | - 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
263 | - 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
264 | - 'map_w' => 200, |
|
265 | - 'map_h' => 200, |
|
266 | - ); |
|
267 | - if ($field === 'gmap_url') { |
|
268 | - $atts['type'] = 'url_only'; |
|
269 | - } |
|
270 | - return $atts; |
|
271 | - } |
|
19 | + /** |
|
20 | + * Will hold the EE_Event if available |
|
21 | + * |
|
22 | + * @var EE_Event |
|
23 | + */ |
|
24 | + protected $_event; |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * Initialize properties |
|
29 | + */ |
|
30 | + protected function _init_props() |
|
31 | + { |
|
32 | + $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
33 | + $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
34 | + $this->_shortcodes = array( |
|
35 | + '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
36 | + '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
37 | + '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
38 | + '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
39 | + '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
40 | + '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
41 | + '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
42 | + '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
43 | + '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
44 | + '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
45 | + '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
46 | + 'This just outputs the venue address in a semantic address format.', |
|
47 | + 'event_espresso' |
|
48 | + ), |
|
49 | + '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
50 | + '[GOOGLE_MAP_URL]' => esc_html__( |
|
51 | + 'URL for the google map associated with the venue.', |
|
52 | + 'event_espresso' |
|
53 | + ), |
|
54 | + '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
55 | + '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Parse incoming shortcode |
|
62 | + * @param string $shortcode |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + protected function _parser($shortcode) |
|
66 | + { |
|
67 | + |
|
68 | + switch ($shortcode) { |
|
69 | + case '[VENUE_TITLE]': |
|
70 | + return $this->_venue('title'); |
|
71 | + break; |
|
72 | + |
|
73 | + case '[VENUE_DESCRIPTION]': |
|
74 | + return $this->_venue('description'); |
|
75 | + break; |
|
76 | + |
|
77 | + case '[VENUE_URL]': |
|
78 | + return $this->_venue('url'); |
|
79 | + break; |
|
80 | + |
|
81 | + case '[VENUE_IMAGE]': |
|
82 | + return $this->_venue('image'); |
|
83 | + break; |
|
84 | + |
|
85 | + case '[VENUE_PHONE]': |
|
86 | + return $this->_venue('phone'); |
|
87 | + break; |
|
88 | + |
|
89 | + case '[VENUE_ADDRESS]': |
|
90 | + return $this->_venue('address'); |
|
91 | + break; |
|
92 | + |
|
93 | + case '[VENUE_ADDRESS2]': |
|
94 | + return $this->_venue('address2'); |
|
95 | + break; |
|
96 | + |
|
97 | + case '[VENUE_CITY]': |
|
98 | + return $this->_venue('city'); |
|
99 | + break; |
|
100 | + |
|
101 | + case '[VENUE_COUNTRY]': |
|
102 | + return $this->_venue('country'); |
|
103 | + break; |
|
104 | + |
|
105 | + case '[VENUE_STATE]': |
|
106 | + return $this->_venue('state'); |
|
107 | + break; |
|
108 | + |
|
109 | + case '[VENUE_ZIP]': |
|
110 | + return $this->_venue('zip'); |
|
111 | + break; |
|
112 | + |
|
113 | + case '[VENUE_FORMATTED_ADDRESS]': |
|
114 | + return $this->_venue('formatted_address'); |
|
115 | + break; |
|
116 | + |
|
117 | + case '[GOOGLE_MAP_URL]': |
|
118 | + return $this->_venue('gmap_url'); |
|
119 | + break; |
|
120 | + |
|
121 | + case '[GOOGLE_MAP_LINK]': |
|
122 | + return $this->_venue('gmap_link'); |
|
123 | + break; |
|
124 | + |
|
125 | + case '[GOOGLE_MAP_IMAGE]': |
|
126 | + return $this->_venue('gmap_link_img'); |
|
127 | + break; |
|
128 | + |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * This retrieves the specified venue information |
|
135 | + * |
|
136 | + * @param string $field What Venue field to retrieve |
|
137 | + * @return string What was retrieved! |
|
138 | + * @throws EE_Error |
|
139 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
140 | + */ |
|
141 | + private function _venue($field) |
|
142 | + { |
|
143 | + //we need the EE_Event object to get the venue. |
|
144 | + $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
145 | + |
|
146 | + //if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the reg_obj instead. |
|
147 | + if (empty($this->_event)) { |
|
148 | + $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
149 | + $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
150 | + |
|
151 | + $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : null; |
|
152 | + |
|
153 | + //if still empty do we have a ticket data item? |
|
154 | + $this->_event = empty($this->_event) |
|
155 | + && $this->_data instanceof EE_Ticket |
|
156 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
157 | + ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event'] |
|
158 | + : $this->_event; |
|
159 | + |
|
160 | + //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee and use that. |
|
161 | + $event = $aee instanceof EE_Messages_Addressee ? reset($aee->events) : array(); |
|
162 | + $this->_event = empty($this->_event) && ! empty($events) ? $event : $this->_event; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + //If there is no event objecdt by now then get out. |
|
167 | + if (! $this->_event instanceof EE_Event) { |
|
168 | + return ''; |
|
169 | + } |
|
170 | + |
|
171 | + /** @var EE_Venue $venue */ |
|
172 | + $venue = $this->_event->get_first_related('Venue'); |
|
173 | + |
|
174 | + if (empty($venue)) { |
|
175 | + return ''; |
|
176 | + } //no venue so get out. |
|
177 | + |
|
178 | + switch ($field) { |
|
179 | + case 'title': |
|
180 | + return $venue->get('VNU_name'); |
|
181 | + break; |
|
182 | + |
|
183 | + case 'description': |
|
184 | + return $venue->get('VNU_desc'); |
|
185 | + break; |
|
186 | + |
|
187 | + case 'url': |
|
188 | + $url = $venue->get('VNU_url'); |
|
189 | + return empty($url) ? $venue->get_permalink() : $url; |
|
190 | + break; |
|
191 | + |
|
192 | + case 'image': |
|
193 | + return '<img src="' . $venue->feature_image_url(array(200, 200,)) |
|
194 | + . '" alt="' . sprintf( |
|
195 | + esc_attr__('%s Feature Image', 'event_espresso'), |
|
196 | + $venue->get('VNU_name') |
|
197 | + ) . '" />'; |
|
198 | + break; |
|
199 | + |
|
200 | + case 'phone': |
|
201 | + return $venue->get('VNU_phone'); |
|
202 | + break; |
|
203 | + |
|
204 | + case 'address': |
|
205 | + return $venue->get('VNU_address'); |
|
206 | + break; |
|
207 | + |
|
208 | + case 'address2': |
|
209 | + return $venue->get('VNU_address2'); |
|
210 | + break; |
|
211 | + |
|
212 | + case 'city': |
|
213 | + return $venue->get('VNU_city'); |
|
214 | + break; |
|
215 | + |
|
216 | + case 'state': |
|
217 | + $state = $venue->state_obj(); |
|
218 | + return is_object($state) ? $state->get('STA_name') : ''; |
|
219 | + break; |
|
220 | + |
|
221 | + case 'country': |
|
222 | + $country = $venue->country_obj(); |
|
223 | + return is_object($country) ? $country->get('CNT_name') : ''; |
|
224 | + break; |
|
225 | + |
|
226 | + case 'zip': |
|
227 | + return $venue->get('VNU_zip'); |
|
228 | + break; |
|
229 | + |
|
230 | + case 'formatted_address': |
|
231 | + return EEH_Address::format($venue); |
|
232 | + break; |
|
233 | + |
|
234 | + case 'gmap_link': |
|
235 | + case 'gmap_url': |
|
236 | + case 'gmap_link_img': |
|
237 | + $atts = $this->get_map_attributes($venue, $field); |
|
238 | + return EEH_Maps::google_map_link($atts); |
|
239 | + break; |
|
240 | + } |
|
241 | + return ''; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * Generates the attributes for retrieving a google_map artifact. |
|
247 | + * @param EE_Venue $venue |
|
248 | + * @param string $field |
|
249 | + * @return array |
|
250 | + * @throws EE_Error |
|
251 | + */ |
|
252 | + protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
253 | + { |
|
254 | + $state = $venue->state_obj(); |
|
255 | + $country = $venue->country_obj(); |
|
256 | + $atts = array( |
|
257 | + 'id' => $venue->ID(), |
|
258 | + 'address' => $venue->get('VNU_address'), |
|
259 | + 'city' => $venue->get('VNU_city'), |
|
260 | + 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
261 | + 'zip' => $venue->get('VNU_zip'), |
|
262 | + 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
263 | + 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
264 | + 'map_w' => 200, |
|
265 | + 'map_h' => 200, |
|
266 | + ); |
|
267 | + if ($field === 'gmap_url') { |
|
268 | + $atts['type'] = 'url_only'; |
|
269 | + } |
|
270 | + return $atts; |
|
271 | + } |
|
272 | 272 | } |
@@ -14,176 +14,176 @@ |
||
14 | 14 | class EEH_Maps |
15 | 15 | { |
16 | 16 | |
17 | - // array of map settings |
|
18 | - public static $gmap_vars = array(); |
|
19 | - |
|
20 | - |
|
21 | - /** |
|
22 | - * google_map - creates a Google Map Link |
|
23 | - * |
|
24 | - * @param array $ee_gmaps_opts array of attributes required for the map link generation |
|
25 | - * @return string (link to map!) |
|
26 | - */ |
|
27 | - public static function google_map($ee_gmaps_opts) |
|
28 | - { |
|
29 | - |
|
30 | - $ee_map_width = ! empty($ee_gmaps_opts['ee_map_width']) ? $ee_gmaps_opts['ee_map_width'] : '300'; |
|
31 | - $ee_map_height = ! empty($ee_gmaps_opts['ee_map_height']) ? $ee_gmaps_opts['ee_map_height'] : '185'; |
|
32 | - $ee_map_zoom = ! empty($ee_gmaps_opts['ee_map_zoom']) ? $ee_gmaps_opts['ee_map_zoom'] : '12'; |
|
33 | - $ee_map_nav_display = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false'; |
|
34 | - $ee_map_nav_size = ! empty($ee_gmaps_opts['ee_map_nav_size']) |
|
35 | - ? $ee_gmaps_opts['ee_map_nav_size'] |
|
36 | - : 'default'; |
|
37 | - $ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control']) |
|
38 | - ? $ee_gmaps_opts['ee_map_type_control'] |
|
39 | - : 'default'; |
|
40 | - $static_url = ! empty($ee_gmaps_opts['ee_static_url']) ? $ee_gmaps_opts['ee_static_url'] : false; |
|
41 | - |
|
42 | - if (! empty($ee_gmaps_opts['ee_map_align'])) { |
|
43 | - switch ($ee_gmaps_opts['ee_map_align']) { |
|
44 | - case "left": |
|
45 | - $map_align = 'ee-gmap-align-left left'; |
|
46 | - break; |
|
47 | - case "right": |
|
48 | - $map_align = 'ee-gmap-align-right right'; |
|
49 | - break; |
|
50 | - case "center": |
|
51 | - $map_align = 'ee-gmap-align-center center'; |
|
52 | - break; |
|
53 | - case "none": |
|
54 | - default: |
|
55 | - $map_align = 'ee-gmap-align-none'; |
|
56 | - } |
|
57 | - } else { |
|
58 | - $map_align = 'ee-gmap-align-none'; |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - // Determine whether user has set a hardoded url to use and |
|
63 | - // if so display a Google static iframe map else run V3 api |
|
64 | - if ($static_url) { |
|
65 | - $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">'; |
|
66 | - $html .= '<iframe src="' . $static_url . '&output=embed"' |
|
67 | - . ' style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"' |
|
68 | - . ' frameborder="0" scrolling="no">'; |
|
69 | - $html .= '</iframe>'; |
|
70 | - $html .= '<a href="' . $static_url . '">View Large map</a>'; |
|
71 | - $html .= '</div>'; |
|
72 | - return $html; |
|
73 | - |
|
74 | - } else { |
|
75 | - EEH_Maps::$gmap_vars[$ee_gmaps_opts['map_ID']] = array( |
|
76 | - 'map_ID' => $ee_gmaps_opts['map_ID'], |
|
77 | - 'ee_map_zoom' => $ee_map_zoom, |
|
78 | - 'ee_map_nav_display' => $ee_map_nav_display, |
|
79 | - 'ee_map_nav_size' => $ee_map_nav_size, |
|
80 | - 'ee_map_type_control' => $ee_map_type_control, |
|
81 | - 'location' => $ee_gmaps_opts['location'], |
|
82 | - ); |
|
83 | - |
|
84 | - $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;'; |
|
85 | - $html = '<div class="ee-gmap-wrapper ' . $map_align . '">' |
|
86 | - . '<div class="ee-gmap" id="map_canvas_' . $ee_gmaps_opts['map_ID'] . '"' |
|
87 | - . ' style="' . $style . '"></div>' |
|
88 | - . '</div>'; |
|
89 | - |
|
90 | - wp_enqueue_script('gmap_api'); |
|
91 | - wp_enqueue_script('ee_gmap'); |
|
92 | - add_action('wp_footer', array('EEH_Maps', 'footer_enqueue_script')); |
|
93 | - |
|
94 | - return $html; |
|
95 | - } // end auto map or static url map check |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * enqueue_script |
|
101 | - * |
|
102 | - * @return void |
|
103 | - */ |
|
104 | - public static function footer_enqueue_script() |
|
105 | - { |
|
106 | - wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * registers scripts for maps |
|
112 | - */ |
|
113 | - public static function espresso_google_map_js() |
|
114 | - { |
|
115 | - $api_url = sprintf( |
|
116 | - "https://maps.googleapis.com/maps/api/js?key=%s", |
|
117 | - apply_filters( |
|
118 | - 'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
|
119 | - EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
120 | - ) |
|
121 | - ); |
|
122 | - wp_register_script('gmap_api', $api_url, array('jquery'), null, true); |
|
123 | - wp_register_script('ee_gmap', plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', array('gmap_api'), '1.0', true); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * creates a Google Map Link |
|
128 | - * |
|
129 | - * @param array $atts array of attributes required for the map link generation |
|
130 | - * @return string (link to map!) |
|
131 | - */ |
|
132 | - public static function google_map_link($atts) |
|
133 | - { |
|
134 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
135 | - extract($atts); |
|
136 | - /** @var string $address */ |
|
137 | - /** @var string $city */ |
|
138 | - /** @var string $state */ |
|
139 | - /** @var string $zip */ |
|
140 | - /** @var string $country */ |
|
141 | - $address = "{$address}"; |
|
142 | - $city = "{$city}"; |
|
143 | - $state = "{$state}"; |
|
144 | - $zip = "{$zip}"; |
|
145 | - $country = "{$country}"; |
|
146 | - $text = isset($text) ? "{$text}" : ""; |
|
147 | - $type = isset($type) ? "{$type}" : ""; |
|
148 | - $map_w = isset($map_w) ? "{$map_w}" : 400; |
|
149 | - $map_h = isset($map_h) ? "{$map_h}" : 400; |
|
150 | - $id = isset($id) ? $id : 'not_set'; |
|
151 | - $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view'; |
|
152 | - |
|
153 | - $address_string = ($address != '' ? $address : '') |
|
154 | - . ($city != '' ? ',' . $city : '') |
|
155 | - . ($state != '' ? ',' . $state : '') |
|
156 | - . ($zip != '' ? ',' . $zip : '') |
|
157 | - . ($country != '' ? ',' . $country : ''); |
|
158 | - |
|
159 | - $google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode($address_string)); |
|
160 | - |
|
161 | - switch ($type) { |
|
162 | - case 'text': |
|
163 | - default: |
|
164 | - $text = $text == '' ? __('Map and Directions', 'event_espresso') : $text; |
|
165 | - break; |
|
166 | - |
|
167 | - case 'url_only': |
|
168 | - case 'url': |
|
169 | - $text = $google_map; |
|
170 | - break; |
|
171 | - |
|
172 | - case 'map': |
|
173 | - $scheme = is_ssl() ? 'https://' : 'http://'; |
|
174 | - |
|
175 | - $api_key = apply_filters( |
|
176 | - 'FHEE__EEH_Maps__espresso_google_maps_link__api_key', |
|
177 | - EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
178 | - ); |
|
179 | - |
|
180 | - return '<a class="a_map_image_link" href="' . $google_map . '" target="_blank">' . '<img class="map_image_link" id="venue_map_' . $id . '" ' . $map_image_class . ' src="' . htmlentities2($scheme . 'maps.googleapis.com/maps/api/staticmap?center=' . urlencode($address_string) . '&zoom=14&size=' . $map_w . 'x' . $map_h . '&markers=color:green|label:|' . urlencode($address_string) . '&sensor=false&key=' . $api_key) . '" /></a>'; |
|
181 | - } |
|
182 | - |
|
183 | - return $type === 'url_only' |
|
184 | - ? $text |
|
185 | - : '<a href="' . $google_map . '" target="_blank">' . $text . '</a>'; |
|
186 | - } |
|
17 | + // array of map settings |
|
18 | + public static $gmap_vars = array(); |
|
19 | + |
|
20 | + |
|
21 | + /** |
|
22 | + * google_map - creates a Google Map Link |
|
23 | + * |
|
24 | + * @param array $ee_gmaps_opts array of attributes required for the map link generation |
|
25 | + * @return string (link to map!) |
|
26 | + */ |
|
27 | + public static function google_map($ee_gmaps_opts) |
|
28 | + { |
|
29 | + |
|
30 | + $ee_map_width = ! empty($ee_gmaps_opts['ee_map_width']) ? $ee_gmaps_opts['ee_map_width'] : '300'; |
|
31 | + $ee_map_height = ! empty($ee_gmaps_opts['ee_map_height']) ? $ee_gmaps_opts['ee_map_height'] : '185'; |
|
32 | + $ee_map_zoom = ! empty($ee_gmaps_opts['ee_map_zoom']) ? $ee_gmaps_opts['ee_map_zoom'] : '12'; |
|
33 | + $ee_map_nav_display = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false'; |
|
34 | + $ee_map_nav_size = ! empty($ee_gmaps_opts['ee_map_nav_size']) |
|
35 | + ? $ee_gmaps_opts['ee_map_nav_size'] |
|
36 | + : 'default'; |
|
37 | + $ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control']) |
|
38 | + ? $ee_gmaps_opts['ee_map_type_control'] |
|
39 | + : 'default'; |
|
40 | + $static_url = ! empty($ee_gmaps_opts['ee_static_url']) ? $ee_gmaps_opts['ee_static_url'] : false; |
|
41 | + |
|
42 | + if (! empty($ee_gmaps_opts['ee_map_align'])) { |
|
43 | + switch ($ee_gmaps_opts['ee_map_align']) { |
|
44 | + case "left": |
|
45 | + $map_align = 'ee-gmap-align-left left'; |
|
46 | + break; |
|
47 | + case "right": |
|
48 | + $map_align = 'ee-gmap-align-right right'; |
|
49 | + break; |
|
50 | + case "center": |
|
51 | + $map_align = 'ee-gmap-align-center center'; |
|
52 | + break; |
|
53 | + case "none": |
|
54 | + default: |
|
55 | + $map_align = 'ee-gmap-align-none'; |
|
56 | + } |
|
57 | + } else { |
|
58 | + $map_align = 'ee-gmap-align-none'; |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + // Determine whether user has set a hardoded url to use and |
|
63 | + // if so display a Google static iframe map else run V3 api |
|
64 | + if ($static_url) { |
|
65 | + $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">'; |
|
66 | + $html .= '<iframe src="' . $static_url . '&output=embed"' |
|
67 | + . ' style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"' |
|
68 | + . ' frameborder="0" scrolling="no">'; |
|
69 | + $html .= '</iframe>'; |
|
70 | + $html .= '<a href="' . $static_url . '">View Large map</a>'; |
|
71 | + $html .= '</div>'; |
|
72 | + return $html; |
|
73 | + |
|
74 | + } else { |
|
75 | + EEH_Maps::$gmap_vars[$ee_gmaps_opts['map_ID']] = array( |
|
76 | + 'map_ID' => $ee_gmaps_opts['map_ID'], |
|
77 | + 'ee_map_zoom' => $ee_map_zoom, |
|
78 | + 'ee_map_nav_display' => $ee_map_nav_display, |
|
79 | + 'ee_map_nav_size' => $ee_map_nav_size, |
|
80 | + 'ee_map_type_control' => $ee_map_type_control, |
|
81 | + 'location' => $ee_gmaps_opts['location'], |
|
82 | + ); |
|
83 | + |
|
84 | + $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;'; |
|
85 | + $html = '<div class="ee-gmap-wrapper ' . $map_align . '">' |
|
86 | + . '<div class="ee-gmap" id="map_canvas_' . $ee_gmaps_opts['map_ID'] . '"' |
|
87 | + . ' style="' . $style . '"></div>' |
|
88 | + . '</div>'; |
|
89 | + |
|
90 | + wp_enqueue_script('gmap_api'); |
|
91 | + wp_enqueue_script('ee_gmap'); |
|
92 | + add_action('wp_footer', array('EEH_Maps', 'footer_enqueue_script')); |
|
93 | + |
|
94 | + return $html; |
|
95 | + } // end auto map or static url map check |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * enqueue_script |
|
101 | + * |
|
102 | + * @return void |
|
103 | + */ |
|
104 | + public static function footer_enqueue_script() |
|
105 | + { |
|
106 | + wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * registers scripts for maps |
|
112 | + */ |
|
113 | + public static function espresso_google_map_js() |
|
114 | + { |
|
115 | + $api_url = sprintf( |
|
116 | + "https://maps.googleapis.com/maps/api/js?key=%s", |
|
117 | + apply_filters( |
|
118 | + 'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
|
119 | + EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
120 | + ) |
|
121 | + ); |
|
122 | + wp_register_script('gmap_api', $api_url, array('jquery'), null, true); |
|
123 | + wp_register_script('ee_gmap', plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', array('gmap_api'), '1.0', true); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * creates a Google Map Link |
|
128 | + * |
|
129 | + * @param array $atts array of attributes required for the map link generation |
|
130 | + * @return string (link to map!) |
|
131 | + */ |
|
132 | + public static function google_map_link($atts) |
|
133 | + { |
|
134 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
135 | + extract($atts); |
|
136 | + /** @var string $address */ |
|
137 | + /** @var string $city */ |
|
138 | + /** @var string $state */ |
|
139 | + /** @var string $zip */ |
|
140 | + /** @var string $country */ |
|
141 | + $address = "{$address}"; |
|
142 | + $city = "{$city}"; |
|
143 | + $state = "{$state}"; |
|
144 | + $zip = "{$zip}"; |
|
145 | + $country = "{$country}"; |
|
146 | + $text = isset($text) ? "{$text}" : ""; |
|
147 | + $type = isset($type) ? "{$type}" : ""; |
|
148 | + $map_w = isset($map_w) ? "{$map_w}" : 400; |
|
149 | + $map_h = isset($map_h) ? "{$map_h}" : 400; |
|
150 | + $id = isset($id) ? $id : 'not_set'; |
|
151 | + $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view'; |
|
152 | + |
|
153 | + $address_string = ($address != '' ? $address : '') |
|
154 | + . ($city != '' ? ',' . $city : '') |
|
155 | + . ($state != '' ? ',' . $state : '') |
|
156 | + . ($zip != '' ? ',' . $zip : '') |
|
157 | + . ($country != '' ? ',' . $country : ''); |
|
158 | + |
|
159 | + $google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode($address_string)); |
|
160 | + |
|
161 | + switch ($type) { |
|
162 | + case 'text': |
|
163 | + default: |
|
164 | + $text = $text == '' ? __('Map and Directions', 'event_espresso') : $text; |
|
165 | + break; |
|
166 | + |
|
167 | + case 'url_only': |
|
168 | + case 'url': |
|
169 | + $text = $google_map; |
|
170 | + break; |
|
171 | + |
|
172 | + case 'map': |
|
173 | + $scheme = is_ssl() ? 'https://' : 'http://'; |
|
174 | + |
|
175 | + $api_key = apply_filters( |
|
176 | + 'FHEE__EEH_Maps__espresso_google_maps_link__api_key', |
|
177 | + EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
178 | + ); |
|
179 | + |
|
180 | + return '<a class="a_map_image_link" href="' . $google_map . '" target="_blank">' . '<img class="map_image_link" id="venue_map_' . $id . '" ' . $map_image_class . ' src="' . htmlentities2($scheme . 'maps.googleapis.com/maps/api/staticmap?center=' . urlencode($address_string) . '&zoom=14&size=' . $map_w . 'x' . $map_h . '&markers=color:green|label:|' . urlencode($address_string) . '&sensor=false&key=' . $api_key) . '" /></a>'; |
|
181 | + } |
|
182 | + |
|
183 | + return $type === 'url_only' |
|
184 | + ? $text |
|
185 | + : '<a href="' . $google_map . '" target="_blank">' . $text . '</a>'; |
|
186 | + } |
|
187 | 187 | } |
188 | 188 | // End of file EEH_Maps.helper.php |
189 | 189 | // Location: /helpers/EEH_Maps.helper.php |
190 | 190 | \ No newline at end of file |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | : 'default'; |
40 | 40 | $static_url = ! empty($ee_gmaps_opts['ee_static_url']) ? $ee_gmaps_opts['ee_static_url'] : false; |
41 | 41 | |
42 | - if (! empty($ee_gmaps_opts['ee_map_align'])) { |
|
42 | + if ( ! empty($ee_gmaps_opts['ee_map_align'])) { |
|
43 | 43 | switch ($ee_gmaps_opts['ee_map_align']) { |
44 | 44 | case "left": |
45 | 45 | $map_align = 'ee-gmap-align-left left'; |
@@ -62,12 +62,12 @@ discard block |
||
62 | 62 | // Determine whether user has set a hardoded url to use and |
63 | 63 | // if so display a Google static iframe map else run V3 api |
64 | 64 | if ($static_url) { |
65 | - $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">'; |
|
66 | - $html .= '<iframe src="' . $static_url . '&output=embed"' |
|
67 | - . ' style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"' |
|
65 | + $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper '.$map_align.'">'; |
|
66 | + $html .= '<iframe src="'.$static_url.'&output=embed"' |
|
67 | + . ' style="width: '.$ee_map_width.'px; height: '.$ee_map_height.'px;"' |
|
68 | 68 | . ' frameborder="0" scrolling="no">'; |
69 | 69 | $html .= '</iframe>'; |
70 | - $html .= '<a href="' . $static_url . '">View Large map</a>'; |
|
70 | + $html .= '<a href="'.$static_url.'">View Large map</a>'; |
|
71 | 71 | $html .= '</div>'; |
72 | 72 | return $html; |
73 | 73 | |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | 'location' => $ee_gmaps_opts['location'], |
82 | 82 | ); |
83 | 83 | |
84 | - $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;'; |
|
85 | - $html = '<div class="ee-gmap-wrapper ' . $map_align . '">' |
|
86 | - . '<div class="ee-gmap" id="map_canvas_' . $ee_gmaps_opts['map_ID'] . '"' |
|
87 | - . ' style="' . $style . '"></div>' |
|
84 | + $style = 'width: '.$ee_map_width.'px; height: '.$ee_map_height.'px;'; |
|
85 | + $html = '<div class="ee-gmap-wrapper '.$map_align.'">' |
|
86 | + . '<div class="ee-gmap" id="map_canvas_'.$ee_gmaps_opts['map_ID'].'"' |
|
87 | + . ' style="'.$style.'"></div>' |
|
88 | 88 | . '</div>'; |
89 | 89 | |
90 | 90 | wp_enqueue_script('gmap_api'); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | ) |
121 | 121 | ); |
122 | 122 | wp_register_script('gmap_api', $api_url, array('jquery'), null, true); |
123 | - wp_register_script('ee_gmap', plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', array('gmap_api'), '1.0', true); |
|
123 | + wp_register_script('ee_gmap', plugin_dir_url(__FILE__).'assets/ee_gmap.js', array('gmap_api'), '1.0', true); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -151,12 +151,12 @@ discard block |
||
151 | 151 | $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view'; |
152 | 152 | |
153 | 153 | $address_string = ($address != '' ? $address : '') |
154 | - . ($city != '' ? ',' . $city : '') |
|
155 | - . ($state != '' ? ',' . $state : '') |
|
156 | - . ($zip != '' ? ',' . $zip : '') |
|
157 | - . ($country != '' ? ',' . $country : ''); |
|
154 | + . ($city != '' ? ','.$city : '') |
|
155 | + . ($state != '' ? ','.$state : '') |
|
156 | + . ($zip != '' ? ','.$zip : '') |
|
157 | + . ($country != '' ? ','.$country : ''); |
|
158 | 158 | |
159 | - $google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode($address_string)); |
|
159 | + $google_map = htmlentities2('http://maps.google.com/maps?q='.urlencode($address_string)); |
|
160 | 160 | |
161 | 161 | switch ($type) { |
162 | 162 | case 'text': |
@@ -177,12 +177,12 @@ discard block |
||
177 | 177 | EE_Registry::instance()->CFG->map_settings->google_map_api_key |
178 | 178 | ); |
179 | 179 | |
180 | - return '<a class="a_map_image_link" href="' . $google_map . '" target="_blank">' . '<img class="map_image_link" id="venue_map_' . $id . '" ' . $map_image_class . ' src="' . htmlentities2($scheme . 'maps.googleapis.com/maps/api/staticmap?center=' . urlencode($address_string) . '&zoom=14&size=' . $map_w . 'x' . $map_h . '&markers=color:green|label:|' . urlencode($address_string) . '&sensor=false&key=' . $api_key) . '" /></a>'; |
|
180 | + return '<a class="a_map_image_link" href="'.$google_map.'" target="_blank">'.'<img class="map_image_link" id="venue_map_'.$id.'" '.$map_image_class.' src="'.htmlentities2($scheme.'maps.googleapis.com/maps/api/staticmap?center='.urlencode($address_string).'&zoom=14&size='.$map_w.'x'.$map_h.'&markers=color:green|label:|'.urlencode($address_string).'&sensor=false&key='.$api_key).'" /></a>'; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | return $type === 'url_only' |
184 | 184 | ? $text |
185 | - : '<a href="' . $google_map . '" target="_blank">' . $text . '</a>'; |
|
185 | + : '<a href="'.$google_map.'" target="_blank">'.$text.'</a>'; |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | // End of file EEH_Maps.helper.php |
@@ -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 | |
@@ -16,698 +16,698 @@ discard block |
||
16 | 16 | |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * @return EED_Module|EED_Add_New_State |
|
21 | - */ |
|
22 | - public static function instance() |
|
23 | - { |
|
24 | - return parent::get_instance(__CLASS__); |
|
25 | - } |
|
26 | - |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
31 | - * |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public static function set_hooks() |
|
35 | - { |
|
36 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
37 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
38 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
39 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
40 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
41 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
42 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
43 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
44 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
45 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
46 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
47 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
48 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
49 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
50 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
51 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
52 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
59 | - * |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public static function set_hooks_admin() |
|
63 | - { |
|
64 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
65 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
66 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
67 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
68 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
69 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
70 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
71 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
72 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
73 | - add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
74 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
75 | - add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
76 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
77 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
78 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
79 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
80 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
81 | - add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
82 | - array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
83 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
84 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
85 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
86 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public static function set_definitions() |
|
95 | - { |
|
96 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
97 | - define('ANS_TEMPLATES_PATH', str_replace( |
|
98 | - '\\', |
|
99 | - DS, plugin_dir_path(__FILE__)) . 'templates' . DS |
|
100 | - ); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @param WP $WP |
|
107 | - * @return void |
|
108 | - */ |
|
109 | - public function run($WP) |
|
110 | - { |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @return void |
|
117 | - */ |
|
118 | - public static function translate_js_strings() |
|
119 | - { |
|
120 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
121 | - 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
122 | - 'event_espresso' |
|
123 | - ); |
|
124 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
125 | - 'In order to proceed, you need to enter the name of your State/Province.', |
|
126 | - 'event_espresso' |
|
127 | - ); |
|
128 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
129 | - 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
130 | - 'event_espresso' |
|
131 | - ); |
|
132 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
133 | - 'The new state was successfully saved to the database.', |
|
134 | - 'event_espresso' |
|
135 | - ); |
|
136 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
137 | - 'An unknown error has occurred on the server while saving the new state to the database.', |
|
138 | - 'event_espresso' |
|
139 | - ); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - public static function wp_enqueue_scripts() |
|
148 | - { |
|
149 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
150 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
151 | - array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
152 | - wp_enqueue_script('add_new_state'); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * display_add_new_state_micro_form |
|
160 | - * |
|
161 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
162 | - * @return string |
|
163 | - * @throws EE_Error |
|
164 | - */ |
|
165 | - // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
166 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
167 | - { |
|
168 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
169 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
170 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
171 | - // is the "state" question in this form section? |
|
172 | - $input = $question_group_reg_form->get_subsection('state'); |
|
173 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
174 | - //ok then all we need to do is make sure the input's HTML name is consistent |
|
175 | - //by forcing it to set it now, like it did while getting the form for display |
|
176 | - if ($input instanceof EE_State_Select_Input) { |
|
177 | - $input->html_name(); |
|
178 | - } |
|
179 | - return $question_group_reg_form; |
|
180 | - } |
|
181 | - // we're only doing this for state select inputs |
|
182 | - if ($input instanceof EE_State_Select_Input) { |
|
183 | - // grab any set values from the request |
|
184 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
185 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
186 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
187 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
188 | - $country_options = array(); |
|
189 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
190 | - if (! empty($countries)) { |
|
191 | - foreach ($countries as $country) { |
|
192 | - if ($country instanceof EE_Country) { |
|
193 | - $country_options[$country->ID()] = $country->name(); |
|
194 | - } |
|
195 | - } |
|
196 | - } |
|
197 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
198 | - array( |
|
199 | - 'name' => 'new_state_micro_form', |
|
200 | - 'html_id' => 'new_state_micro_form', |
|
201 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
202 | - 'subsections' => array( |
|
203 | - // add hidden input to indicate that a new state is being added |
|
204 | - 'add_new_state' => new EE_Hidden_Input( |
|
205 | - array( |
|
206 | - 'html_name' => str_replace( |
|
207 | - 'state', |
|
208 | - 'nsmf_add_new_state', $input->html_name() |
|
209 | - ), |
|
210 | - 'html_id' => str_replace( |
|
211 | - 'state', |
|
212 | - 'nsmf_add_new_state', $input->html_id() |
|
213 | - ), |
|
214 | - 'default' => 0, |
|
215 | - ) |
|
216 | - ), |
|
217 | - // add link for displaying hidden container |
|
218 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
219 | - apply_filters( |
|
220 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
221 | - EEH_HTML::link( |
|
222 | - '', |
|
223 | - esc_html__('click here to add a new state/province', 'event_espresso'), |
|
224 | - '', |
|
225 | - 'display-' . $input->html_id(), |
|
226 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
227 | - '', |
|
228 | - 'data-target="' . $input->html_id() . '"' |
|
229 | - ) |
|
230 | - ) |
|
231 | - ), |
|
232 | - // add initial html for hidden container |
|
233 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
234 | - apply_filters( |
|
235 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
236 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
237 | - 'display: none;') . |
|
238 | - EEH_HTML::h6( |
|
239 | - esc_html__( |
|
240 | - 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
241 | - 'event_espresso' |
|
242 | - ) |
|
243 | - ) . |
|
244 | - EEH_HTML::ul() . |
|
245 | - EEH_HTML::li( |
|
246 | - esc_html__( |
|
247 | - 'first select the Country that your State/Province belongs to', |
|
248 | - 'event_espresso' |
|
249 | - ) |
|
250 | - ) . |
|
251 | - EEH_HTML::li( |
|
252 | - esc_html__('enter the name of your State/Province', 'event_espresso') |
|
253 | - ) . |
|
254 | - EEH_HTML::li( |
|
255 | - esc_html__( |
|
256 | - 'enter a two to six letter abbreviation for the name of your State/Province', |
|
257 | - 'event_espresso' |
|
258 | - ) |
|
259 | - ) . |
|
260 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
261 | - EEH_HTML::ulx() |
|
262 | - ) |
|
263 | - ), |
|
264 | - // NEW STATE COUNTRY |
|
265 | - 'new_state_country' => new EE_Country_Select_Input( |
|
266 | - $country_options, |
|
267 | - array( |
|
268 | - 'html_name' => $country_name, |
|
269 | - 'html_id' => str_replace( |
|
270 | - 'state', |
|
271 | - 'nsmf_new_state_country', $input->html_id() |
|
272 | - ), |
|
273 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
274 | - 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
275 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
276 | - 'required' => false, |
|
277 | - ) |
|
278 | - ), |
|
279 | - // NEW STATE NAME |
|
280 | - 'new_state_name' => new EE_Text_Input( |
|
281 | - array( |
|
282 | - 'html_name' => $state_name, |
|
283 | - 'html_id' => str_replace( |
|
284 | - 'state', |
|
285 | - 'nsmf_new_state_name', $input->html_id() |
|
286 | - ), |
|
287 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
288 | - 'html_label_text' => esc_html__('New State/Province Name', |
|
289 | - 'event_espresso'), |
|
290 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
291 | - 'required' => false, |
|
292 | - ) |
|
293 | - ), |
|
294 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
295 | - // NEW STATE NAME |
|
296 | - 'new_state_abbrv' => new EE_Text_Input( |
|
297 | - array( |
|
298 | - 'html_name' => $abbrv_name, |
|
299 | - 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
300 | - $input->html_id()), |
|
301 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
302 | - 'html_label_text' => esc_html__( |
|
303 | - 'New State/Province Abbreviation', |
|
304 | - 'event_espresso' |
|
305 | - ) . ' *', |
|
306 | - 'html_other_attributes' => 'size="24"', |
|
307 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
308 | - 'required' => false, |
|
309 | - ) |
|
310 | - ), |
|
311 | - // "submit" button |
|
312 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
313 | - apply_filters( |
|
314 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
315 | - EEH_HTML::nbsp(3) . |
|
316 | - EEH_HTML::link( |
|
317 | - '', |
|
318 | - esc_html__('ADD', 'event_espresso'), |
|
319 | - '', |
|
320 | - 'submit-' . $new_state_submit_id, |
|
321 | - 'ee-form-add-new-state-submit button button-secondary', |
|
322 | - '', |
|
323 | - 'data-target="' . $new_state_submit_id . '"' |
|
324 | - ) |
|
325 | - ) |
|
326 | - ), |
|
327 | - // extra info |
|
328 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
329 | - apply_filters( |
|
330 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
331 | - EEH_HTML::br(2) |
|
332 | - . |
|
333 | - EEH_HTML::div('', '', 'small-text') |
|
334 | - . |
|
335 | - EEH_HTML::strong( |
|
336 | - '* ' . |
|
337 | - esc_html__( |
|
338 | - 'Don\'t know your State/Province Abbreviation?', |
|
339 | - 'event_espresso' |
|
340 | - ) |
|
341 | - ) |
|
342 | - . |
|
343 | - EEH_HTML::br() |
|
344 | - . |
|
345 | - sprintf( |
|
346 | - esc_html__( |
|
347 | - 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
348 | - 'event_espresso' |
|
349 | - ), |
|
350 | - EEH_HTML::link( |
|
351 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
352 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
353 | - '', |
|
354 | - '', |
|
355 | - 'ee-form-add-new-state-wiki-lnk', |
|
356 | - '', |
|
357 | - 'target="_blank"' |
|
358 | - ) |
|
359 | - ) |
|
360 | - . |
|
361 | - EEH_HTML::divx() |
|
362 | - . |
|
363 | - EEH_HTML::br() |
|
364 | - . |
|
365 | - EEH_HTML::link( |
|
366 | - '', |
|
367 | - esc_html__('cancel new State/Province', 'event_espresso'), |
|
368 | - '', |
|
369 | - 'hide-' . $input->html_id(), |
|
370 | - 'ee-form-cancel-new-state-lnk smaller-text', |
|
371 | - '', |
|
372 | - 'data-target="' . $input->html_id() . '"' |
|
373 | - ) |
|
374 | - . |
|
375 | - EEH_HTML::divx() |
|
376 | - . |
|
377 | - EEH_HTML::br() |
|
378 | - ) |
|
379 | - ), |
|
380 | - ), |
|
381 | - ) |
|
382 | - ); |
|
383 | - $question_group_reg_form->add_subsections( |
|
384 | - array('new_state_micro_form' => $new_state_micro_form), |
|
385 | - 'state', |
|
386 | - false |
|
387 | - ); |
|
388 | - } |
|
389 | - return $question_group_reg_form; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * set_new_state_input_width |
|
396 | - * |
|
397 | - * @return int|string |
|
398 | - * @throws EE_Error |
|
399 | - */ |
|
400 | - public static function add_new_state() |
|
401 | - { |
|
402 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
403 | - if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
404 | - EE_Registry::instance()->load_model('State'); |
|
405 | - // grab country ISO code, new state name, and new state abbreviation |
|
406 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
407 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
408 | - : false; |
|
409 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
410 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
411 | - : false; |
|
412 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
413 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
414 | - : false; |
|
415 | - if ($state_country && $state_name && $state_abbr) { |
|
416 | - $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
417 | - 'CNT_ISO' => strtoupper($state_country), |
|
418 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
419 | - 'STA_name' => ucwords($state_name), |
|
420 | - 'STA_active' => false, |
|
421 | - )); |
|
422 | - if ($new_state instanceof EE_State) { |
|
423 | - // clean house |
|
424 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
425 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
426 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
427 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
428 | - // get any existing new states |
|
429 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
430 | - 'nsmf_new_states' |
|
431 | - ); |
|
432 | - $new_states[$new_state->ID()] = $new_state; |
|
433 | - EE_Registry::instance()->SSN->set_session_data( |
|
434 | - array('nsmf_new_states' => $new_states) |
|
435 | - ); |
|
436 | - if (EE_Registry::instance()->REQ->ajax) { |
|
437 | - echo wp_json_encode(array( |
|
438 | - 'success' => true, |
|
439 | - 'id' => $new_state->ID(), |
|
440 | - 'name' => $new_state->name(), |
|
441 | - 'abbrev' => $new_state->abbrev(), |
|
442 | - 'country_iso' => $new_state->country_iso(), |
|
443 | - 'country_name' => $new_state->country()->name(), |
|
444 | - )); |
|
445 | - exit(); |
|
446 | - } |
|
447 | - return $new_state->ID(); |
|
448 | - } |
|
449 | - } else { |
|
450 | - $error = esc_html__( |
|
451 | - 'A new State/Province could not be added because invalid or missing data was received.', |
|
452 | - 'event_espresso' |
|
453 | - ); |
|
454 | - if (EE_Registry::instance()->REQ->ajax) { |
|
455 | - echo wp_json_encode(array('error' => $error)); |
|
456 | - exit(); |
|
457 | - } |
|
458 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
459 | - } |
|
460 | - } |
|
461 | - return false; |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - |
|
466 | - /** |
|
467 | - * recursively drills down through request params to remove any that were added by this module |
|
468 | - * |
|
469 | - * @param array $request_params |
|
470 | - * @return array |
|
471 | - */ |
|
472 | - public static function filter_checkout_request_params($request_params) |
|
473 | - { |
|
474 | - foreach ($request_params as $form_section) { |
|
475 | - if (is_array($form_section)) { |
|
476 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
477 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
478 | - } |
|
479 | - } |
|
480 | - return $request_params; |
|
481 | - } |
|
482 | - |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * @param array $request_params |
|
487 | - * @return array |
|
488 | - */ |
|
489 | - public static function unset_new_state_request_params($request_params) |
|
490 | - { |
|
491 | - unset( |
|
492 | - $request_params['new_state_micro_form'], |
|
493 | - $request_params['new_state_micro_add_new_state'], |
|
494 | - $request_params['new_state_micro_new_state_country'], |
|
495 | - $request_params['new_state_micro_new_state_name'], |
|
496 | - $request_params['new_state_micro_new_state_abbrv'] |
|
497 | - ); |
|
498 | - return $request_params; |
|
499 | - } |
|
500 | - |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * @param array $props_n_values |
|
505 | - * @return bool |
|
506 | - * @throws EE_Error |
|
507 | - */ |
|
508 | - public static function save_new_state_to_db($props_n_values = array()) |
|
509 | - { |
|
510 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
511 | - if (! empty($existing_state)) { |
|
512 | - return array_pop($existing_state); |
|
513 | - } |
|
514 | - $new_state = EE_State::new_instance($props_n_values); |
|
515 | - if ($new_state instanceof EE_State) { |
|
516 | - // if not non-ajax admin |
|
517 | - $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
518 | - $new_state_notice = sprintf( |
|
519 | - esc_html__( |
|
520 | - 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
521 | - 'event_espresso' |
|
522 | - ), |
|
523 | - '<b>' . $new_state->name() . '</b>', |
|
524 | - '<b>' . $new_state->abbrev() . '</b>', |
|
525 | - '<b>' . $new_state->country()->name() . '</b>', |
|
526 | - '<a href="' . add_query_arg(array( |
|
527 | - 'page' => 'espresso_general_settings', |
|
528 | - 'action' => 'country_settings', |
|
529 | - 'country' => $new_state->country_iso(), |
|
530 | - ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
531 | - 'event_espresso') . '</a>', |
|
532 | - '<br />' |
|
533 | - ); |
|
534 | - EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
|
535 | - $new_state->save(); |
|
536 | - EEM_State::instance()->reset_cached_states(); |
|
537 | - return $new_state; |
|
538 | - } |
|
539 | - return false; |
|
540 | - } |
|
541 | - |
|
542 | - |
|
543 | - |
|
544 | - /** |
|
545 | - * @param string $CNT_ISO |
|
546 | - * @param string $STA_ID |
|
547 | - * @param array $cols_n_values |
|
548 | - * @return void |
|
549 | - */ |
|
550 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
551 | - { |
|
552 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false; |
|
553 | - if (! $CNT_ISO) { |
|
554 | - EE_Error::add_error( |
|
555 | - esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
556 | - __FILE__, |
|
557 | - __FUNCTION__, |
|
558 | - __LINE__ |
|
559 | - ); |
|
560 | - } |
|
561 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
562 | - : false; |
|
563 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
564 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
565 | - if ($state instanceof EE_State) { |
|
566 | - $STA_abbrev = $state->abbrev(); |
|
567 | - } |
|
568 | - } |
|
569 | - if (! $STA_abbrev) { |
|
570 | - EE_Error::add_error( |
|
571 | - esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
572 | - __FILE__, |
|
573 | - __FUNCTION__, |
|
574 | - __LINE__ |
|
575 | - ); |
|
576 | - } |
|
577 | - EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * @param EE_State[] $state_options |
|
584 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
585 | - * @param EE_Registration $registration |
|
586 | - * @param EE_Question $question |
|
587 | - * @param $answer |
|
588 | - * @return array |
|
589 | - */ |
|
590 | - public static function inject_new_reg_state_into_options( |
|
591 | - $state_options = array(), |
|
592 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
593 | - EE_Registration $registration, |
|
594 | - EE_Question $question, |
|
595 | - $answer |
|
596 | - ) { |
|
597 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
598 | - && $question->type() |
|
599 | - === EEM_Question::QST_type_state |
|
600 | - ) { |
|
601 | - $STA_ID = $answer->value(); |
|
602 | - if (! empty($STA_ID)) { |
|
603 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
604 | - if ($state instanceof EE_State) { |
|
605 | - $country = $state->country(); |
|
606 | - if ($country instanceof EE_Country) { |
|
607 | - if (! isset($state_options[$country->name()])) { |
|
608 | - $state_options[$country->name()] = array(); |
|
609 | - } |
|
610 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
611 | - $state_options[$country->name()][$STA_ID] = $state->name(); |
|
612 | - } |
|
613 | - } |
|
614 | - } |
|
615 | - } |
|
616 | - } |
|
617 | - return $state_options; |
|
618 | - } |
|
619 | - |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * @param EE_Country[] $country_options |
|
624 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
625 | - * @param EE_Registration $registration |
|
626 | - * @param EE_Question $question |
|
627 | - * @param $answer |
|
628 | - * @return array |
|
629 | - */ |
|
630 | - public static function inject_new_reg_country_into_options( |
|
631 | - $country_options = array(), |
|
632 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
633 | - EE_Registration $registration, |
|
634 | - EE_Question $question, |
|
635 | - $answer |
|
636 | - ) { |
|
637 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
638 | - && $question->type() |
|
639 | - === EEM_Question::QST_type_country |
|
640 | - ) { |
|
641 | - $CNT_ISO = $answer->value(); |
|
642 | - if (! empty($CNT_ISO)) { |
|
643 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
644 | - if ($country instanceof EE_Country) { |
|
645 | - if (! isset($country_options[$CNT_ISO])) { |
|
646 | - $country_options[$CNT_ISO] = $country->name(); |
|
647 | - } |
|
648 | - } |
|
649 | - } |
|
650 | - } |
|
651 | - return $country_options; |
|
652 | - } |
|
653 | - |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * @param EE_State[] $state_options |
|
658 | - * @return array |
|
659 | - * @throws EE_Error |
|
660 | - */ |
|
661 | - public static function state_options($state_options = array()) |
|
662 | - { |
|
663 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
664 | - foreach ($new_states as $new_state) { |
|
665 | - if ( |
|
666 | - $new_state instanceof EE_State |
|
667 | - && $new_state->country() instanceof EE_Country |
|
668 | - ) { |
|
669 | - $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
670 | - } |
|
671 | - } |
|
672 | - return $state_options; |
|
673 | - } |
|
674 | - |
|
675 | - |
|
676 | - |
|
677 | - /** |
|
678 | - * @return array |
|
679 | - */ |
|
680 | - protected static function _get_new_states() |
|
681 | - { |
|
682 | - $new_states = array(); |
|
683 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
684 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
685 | - 'nsmf_new_states' |
|
686 | - ); |
|
687 | - } |
|
688 | - return is_array($new_states) ? $new_states : array(); |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * @param EE_Country[] $country_options |
|
695 | - * @return array |
|
696 | - * @throws EE_Error |
|
697 | - */ |
|
698 | - public static function country_options($country_options = array()) |
|
699 | - { |
|
700 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
701 | - foreach ($new_states as $new_state) { |
|
702 | - if ( |
|
703 | - $new_state instanceof EE_State |
|
704 | - && $new_state->country() instanceof EE_Country |
|
705 | - ) { |
|
706 | - $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
707 | - } |
|
708 | - } |
|
709 | - return $country_options; |
|
710 | - } |
|
19 | + /** |
|
20 | + * @return EED_Module|EED_Add_New_State |
|
21 | + */ |
|
22 | + public static function instance() |
|
23 | + { |
|
24 | + return parent::get_instance(__CLASS__); |
|
25 | + } |
|
26 | + |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
31 | + * |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public static function set_hooks() |
|
35 | + { |
|
36 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
37 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
38 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
39 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
40 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
41 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
42 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
43 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
44 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
45 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
46 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
47 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
48 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
49 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
50 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
51 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
52 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
59 | + * |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public static function set_hooks_admin() |
|
63 | + { |
|
64 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
65 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
66 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
67 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
68 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
69 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
70 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
71 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
72 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
73 | + add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
74 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
75 | + add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
76 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
77 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
78 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
79 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
80 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
81 | + add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
82 | + array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
83 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
84 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
85 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
86 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public static function set_definitions() |
|
95 | + { |
|
96 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
97 | + define('ANS_TEMPLATES_PATH', str_replace( |
|
98 | + '\\', |
|
99 | + DS, plugin_dir_path(__FILE__)) . 'templates' . DS |
|
100 | + ); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @param WP $WP |
|
107 | + * @return void |
|
108 | + */ |
|
109 | + public function run($WP) |
|
110 | + { |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @return void |
|
117 | + */ |
|
118 | + public static function translate_js_strings() |
|
119 | + { |
|
120 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
121 | + 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
122 | + 'event_espresso' |
|
123 | + ); |
|
124 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
125 | + 'In order to proceed, you need to enter the name of your State/Province.', |
|
126 | + 'event_espresso' |
|
127 | + ); |
|
128 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
129 | + 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
130 | + 'event_espresso' |
|
131 | + ); |
|
132 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
133 | + 'The new state was successfully saved to the database.', |
|
134 | + 'event_espresso' |
|
135 | + ); |
|
136 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
137 | + 'An unknown error has occurred on the server while saving the new state to the database.', |
|
138 | + 'event_espresso' |
|
139 | + ); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + public static function wp_enqueue_scripts() |
|
148 | + { |
|
149 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
150 | + wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
151 | + array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
152 | + wp_enqueue_script('add_new_state'); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * display_add_new_state_micro_form |
|
160 | + * |
|
161 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
162 | + * @return string |
|
163 | + * @throws EE_Error |
|
164 | + */ |
|
165 | + // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
166 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
167 | + { |
|
168 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
169 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
170 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
171 | + // is the "state" question in this form section? |
|
172 | + $input = $question_group_reg_form->get_subsection('state'); |
|
173 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
174 | + //ok then all we need to do is make sure the input's HTML name is consistent |
|
175 | + //by forcing it to set it now, like it did while getting the form for display |
|
176 | + if ($input instanceof EE_State_Select_Input) { |
|
177 | + $input->html_name(); |
|
178 | + } |
|
179 | + return $question_group_reg_form; |
|
180 | + } |
|
181 | + // we're only doing this for state select inputs |
|
182 | + if ($input instanceof EE_State_Select_Input) { |
|
183 | + // grab any set values from the request |
|
184 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
185 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
186 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
187 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
188 | + $country_options = array(); |
|
189 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
190 | + if (! empty($countries)) { |
|
191 | + foreach ($countries as $country) { |
|
192 | + if ($country instanceof EE_Country) { |
|
193 | + $country_options[$country->ID()] = $country->name(); |
|
194 | + } |
|
195 | + } |
|
196 | + } |
|
197 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
198 | + array( |
|
199 | + 'name' => 'new_state_micro_form', |
|
200 | + 'html_id' => 'new_state_micro_form', |
|
201 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
202 | + 'subsections' => array( |
|
203 | + // add hidden input to indicate that a new state is being added |
|
204 | + 'add_new_state' => new EE_Hidden_Input( |
|
205 | + array( |
|
206 | + 'html_name' => str_replace( |
|
207 | + 'state', |
|
208 | + 'nsmf_add_new_state', $input->html_name() |
|
209 | + ), |
|
210 | + 'html_id' => str_replace( |
|
211 | + 'state', |
|
212 | + 'nsmf_add_new_state', $input->html_id() |
|
213 | + ), |
|
214 | + 'default' => 0, |
|
215 | + ) |
|
216 | + ), |
|
217 | + // add link for displaying hidden container |
|
218 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
219 | + apply_filters( |
|
220 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
221 | + EEH_HTML::link( |
|
222 | + '', |
|
223 | + esc_html__('click here to add a new state/province', 'event_espresso'), |
|
224 | + '', |
|
225 | + 'display-' . $input->html_id(), |
|
226 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
227 | + '', |
|
228 | + 'data-target="' . $input->html_id() . '"' |
|
229 | + ) |
|
230 | + ) |
|
231 | + ), |
|
232 | + // add initial html for hidden container |
|
233 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
234 | + apply_filters( |
|
235 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
236 | + EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
237 | + 'display: none;') . |
|
238 | + EEH_HTML::h6( |
|
239 | + esc_html__( |
|
240 | + 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
241 | + 'event_espresso' |
|
242 | + ) |
|
243 | + ) . |
|
244 | + EEH_HTML::ul() . |
|
245 | + EEH_HTML::li( |
|
246 | + esc_html__( |
|
247 | + 'first select the Country that your State/Province belongs to', |
|
248 | + 'event_espresso' |
|
249 | + ) |
|
250 | + ) . |
|
251 | + EEH_HTML::li( |
|
252 | + esc_html__('enter the name of your State/Province', 'event_espresso') |
|
253 | + ) . |
|
254 | + EEH_HTML::li( |
|
255 | + esc_html__( |
|
256 | + 'enter a two to six letter abbreviation for the name of your State/Province', |
|
257 | + 'event_espresso' |
|
258 | + ) |
|
259 | + ) . |
|
260 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
261 | + EEH_HTML::ulx() |
|
262 | + ) |
|
263 | + ), |
|
264 | + // NEW STATE COUNTRY |
|
265 | + 'new_state_country' => new EE_Country_Select_Input( |
|
266 | + $country_options, |
|
267 | + array( |
|
268 | + 'html_name' => $country_name, |
|
269 | + 'html_id' => str_replace( |
|
270 | + 'state', |
|
271 | + 'nsmf_new_state_country', $input->html_id() |
|
272 | + ), |
|
273 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
274 | + 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
275 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
276 | + 'required' => false, |
|
277 | + ) |
|
278 | + ), |
|
279 | + // NEW STATE NAME |
|
280 | + 'new_state_name' => new EE_Text_Input( |
|
281 | + array( |
|
282 | + 'html_name' => $state_name, |
|
283 | + 'html_id' => str_replace( |
|
284 | + 'state', |
|
285 | + 'nsmf_new_state_name', $input->html_id() |
|
286 | + ), |
|
287 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
288 | + 'html_label_text' => esc_html__('New State/Province Name', |
|
289 | + 'event_espresso'), |
|
290 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
291 | + 'required' => false, |
|
292 | + ) |
|
293 | + ), |
|
294 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
295 | + // NEW STATE NAME |
|
296 | + 'new_state_abbrv' => new EE_Text_Input( |
|
297 | + array( |
|
298 | + 'html_name' => $abbrv_name, |
|
299 | + 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
300 | + $input->html_id()), |
|
301 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
302 | + 'html_label_text' => esc_html__( |
|
303 | + 'New State/Province Abbreviation', |
|
304 | + 'event_espresso' |
|
305 | + ) . ' *', |
|
306 | + 'html_other_attributes' => 'size="24"', |
|
307 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
308 | + 'required' => false, |
|
309 | + ) |
|
310 | + ), |
|
311 | + // "submit" button |
|
312 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
313 | + apply_filters( |
|
314 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
315 | + EEH_HTML::nbsp(3) . |
|
316 | + EEH_HTML::link( |
|
317 | + '', |
|
318 | + esc_html__('ADD', 'event_espresso'), |
|
319 | + '', |
|
320 | + 'submit-' . $new_state_submit_id, |
|
321 | + 'ee-form-add-new-state-submit button button-secondary', |
|
322 | + '', |
|
323 | + 'data-target="' . $new_state_submit_id . '"' |
|
324 | + ) |
|
325 | + ) |
|
326 | + ), |
|
327 | + // extra info |
|
328 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
329 | + apply_filters( |
|
330 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
331 | + EEH_HTML::br(2) |
|
332 | + . |
|
333 | + EEH_HTML::div('', '', 'small-text') |
|
334 | + . |
|
335 | + EEH_HTML::strong( |
|
336 | + '* ' . |
|
337 | + esc_html__( |
|
338 | + 'Don\'t know your State/Province Abbreviation?', |
|
339 | + 'event_espresso' |
|
340 | + ) |
|
341 | + ) |
|
342 | + . |
|
343 | + EEH_HTML::br() |
|
344 | + . |
|
345 | + sprintf( |
|
346 | + esc_html__( |
|
347 | + 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
348 | + 'event_espresso' |
|
349 | + ), |
|
350 | + EEH_HTML::link( |
|
351 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
352 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
353 | + '', |
|
354 | + '', |
|
355 | + 'ee-form-add-new-state-wiki-lnk', |
|
356 | + '', |
|
357 | + 'target="_blank"' |
|
358 | + ) |
|
359 | + ) |
|
360 | + . |
|
361 | + EEH_HTML::divx() |
|
362 | + . |
|
363 | + EEH_HTML::br() |
|
364 | + . |
|
365 | + EEH_HTML::link( |
|
366 | + '', |
|
367 | + esc_html__('cancel new State/Province', 'event_espresso'), |
|
368 | + '', |
|
369 | + 'hide-' . $input->html_id(), |
|
370 | + 'ee-form-cancel-new-state-lnk smaller-text', |
|
371 | + '', |
|
372 | + 'data-target="' . $input->html_id() . '"' |
|
373 | + ) |
|
374 | + . |
|
375 | + EEH_HTML::divx() |
|
376 | + . |
|
377 | + EEH_HTML::br() |
|
378 | + ) |
|
379 | + ), |
|
380 | + ), |
|
381 | + ) |
|
382 | + ); |
|
383 | + $question_group_reg_form->add_subsections( |
|
384 | + array('new_state_micro_form' => $new_state_micro_form), |
|
385 | + 'state', |
|
386 | + false |
|
387 | + ); |
|
388 | + } |
|
389 | + return $question_group_reg_form; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * set_new_state_input_width |
|
396 | + * |
|
397 | + * @return int|string |
|
398 | + * @throws EE_Error |
|
399 | + */ |
|
400 | + public static function add_new_state() |
|
401 | + { |
|
402 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
403 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
404 | + EE_Registry::instance()->load_model('State'); |
|
405 | + // grab country ISO code, new state name, and new state abbreviation |
|
406 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
407 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
408 | + : false; |
|
409 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
410 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
411 | + : false; |
|
412 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
413 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
414 | + : false; |
|
415 | + if ($state_country && $state_name && $state_abbr) { |
|
416 | + $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
417 | + 'CNT_ISO' => strtoupper($state_country), |
|
418 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
419 | + 'STA_name' => ucwords($state_name), |
|
420 | + 'STA_active' => false, |
|
421 | + )); |
|
422 | + if ($new_state instanceof EE_State) { |
|
423 | + // clean house |
|
424 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
425 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
426 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
427 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
428 | + // get any existing new states |
|
429 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
430 | + 'nsmf_new_states' |
|
431 | + ); |
|
432 | + $new_states[$new_state->ID()] = $new_state; |
|
433 | + EE_Registry::instance()->SSN->set_session_data( |
|
434 | + array('nsmf_new_states' => $new_states) |
|
435 | + ); |
|
436 | + if (EE_Registry::instance()->REQ->ajax) { |
|
437 | + echo wp_json_encode(array( |
|
438 | + 'success' => true, |
|
439 | + 'id' => $new_state->ID(), |
|
440 | + 'name' => $new_state->name(), |
|
441 | + 'abbrev' => $new_state->abbrev(), |
|
442 | + 'country_iso' => $new_state->country_iso(), |
|
443 | + 'country_name' => $new_state->country()->name(), |
|
444 | + )); |
|
445 | + exit(); |
|
446 | + } |
|
447 | + return $new_state->ID(); |
|
448 | + } |
|
449 | + } else { |
|
450 | + $error = esc_html__( |
|
451 | + 'A new State/Province could not be added because invalid or missing data was received.', |
|
452 | + 'event_espresso' |
|
453 | + ); |
|
454 | + if (EE_Registry::instance()->REQ->ajax) { |
|
455 | + echo wp_json_encode(array('error' => $error)); |
|
456 | + exit(); |
|
457 | + } |
|
458 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
459 | + } |
|
460 | + } |
|
461 | + return false; |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + |
|
466 | + /** |
|
467 | + * recursively drills down through request params to remove any that were added by this module |
|
468 | + * |
|
469 | + * @param array $request_params |
|
470 | + * @return array |
|
471 | + */ |
|
472 | + public static function filter_checkout_request_params($request_params) |
|
473 | + { |
|
474 | + foreach ($request_params as $form_section) { |
|
475 | + if (is_array($form_section)) { |
|
476 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
477 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
478 | + } |
|
479 | + } |
|
480 | + return $request_params; |
|
481 | + } |
|
482 | + |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * @param array $request_params |
|
487 | + * @return array |
|
488 | + */ |
|
489 | + public static function unset_new_state_request_params($request_params) |
|
490 | + { |
|
491 | + unset( |
|
492 | + $request_params['new_state_micro_form'], |
|
493 | + $request_params['new_state_micro_add_new_state'], |
|
494 | + $request_params['new_state_micro_new_state_country'], |
|
495 | + $request_params['new_state_micro_new_state_name'], |
|
496 | + $request_params['new_state_micro_new_state_abbrv'] |
|
497 | + ); |
|
498 | + return $request_params; |
|
499 | + } |
|
500 | + |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * @param array $props_n_values |
|
505 | + * @return bool |
|
506 | + * @throws EE_Error |
|
507 | + */ |
|
508 | + public static function save_new_state_to_db($props_n_values = array()) |
|
509 | + { |
|
510 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
511 | + if (! empty($existing_state)) { |
|
512 | + return array_pop($existing_state); |
|
513 | + } |
|
514 | + $new_state = EE_State::new_instance($props_n_values); |
|
515 | + if ($new_state instanceof EE_State) { |
|
516 | + // if not non-ajax admin |
|
517 | + $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
518 | + $new_state_notice = sprintf( |
|
519 | + esc_html__( |
|
520 | + 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
521 | + 'event_espresso' |
|
522 | + ), |
|
523 | + '<b>' . $new_state->name() . '</b>', |
|
524 | + '<b>' . $new_state->abbrev() . '</b>', |
|
525 | + '<b>' . $new_state->country()->name() . '</b>', |
|
526 | + '<a href="' . add_query_arg(array( |
|
527 | + 'page' => 'espresso_general_settings', |
|
528 | + 'action' => 'country_settings', |
|
529 | + 'country' => $new_state->country_iso(), |
|
530 | + ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
531 | + 'event_espresso') . '</a>', |
|
532 | + '<br />' |
|
533 | + ); |
|
534 | + EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
|
535 | + $new_state->save(); |
|
536 | + EEM_State::instance()->reset_cached_states(); |
|
537 | + return $new_state; |
|
538 | + } |
|
539 | + return false; |
|
540 | + } |
|
541 | + |
|
542 | + |
|
543 | + |
|
544 | + /** |
|
545 | + * @param string $CNT_ISO |
|
546 | + * @param string $STA_ID |
|
547 | + * @param array $cols_n_values |
|
548 | + * @return void |
|
549 | + */ |
|
550 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
551 | + { |
|
552 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false; |
|
553 | + if (! $CNT_ISO) { |
|
554 | + EE_Error::add_error( |
|
555 | + esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
556 | + __FILE__, |
|
557 | + __FUNCTION__, |
|
558 | + __LINE__ |
|
559 | + ); |
|
560 | + } |
|
561 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
562 | + : false; |
|
563 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
564 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
565 | + if ($state instanceof EE_State) { |
|
566 | + $STA_abbrev = $state->abbrev(); |
|
567 | + } |
|
568 | + } |
|
569 | + if (! $STA_abbrev) { |
|
570 | + EE_Error::add_error( |
|
571 | + esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
572 | + __FILE__, |
|
573 | + __FUNCTION__, |
|
574 | + __LINE__ |
|
575 | + ); |
|
576 | + } |
|
577 | + EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * @param EE_State[] $state_options |
|
584 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
585 | + * @param EE_Registration $registration |
|
586 | + * @param EE_Question $question |
|
587 | + * @param $answer |
|
588 | + * @return array |
|
589 | + */ |
|
590 | + public static function inject_new_reg_state_into_options( |
|
591 | + $state_options = array(), |
|
592 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
593 | + EE_Registration $registration, |
|
594 | + EE_Question $question, |
|
595 | + $answer |
|
596 | + ) { |
|
597 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
598 | + && $question->type() |
|
599 | + === EEM_Question::QST_type_state |
|
600 | + ) { |
|
601 | + $STA_ID = $answer->value(); |
|
602 | + if (! empty($STA_ID)) { |
|
603 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
604 | + if ($state instanceof EE_State) { |
|
605 | + $country = $state->country(); |
|
606 | + if ($country instanceof EE_Country) { |
|
607 | + if (! isset($state_options[$country->name()])) { |
|
608 | + $state_options[$country->name()] = array(); |
|
609 | + } |
|
610 | + if (! isset($state_options[$country->name()][$STA_ID])) { |
|
611 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
612 | + } |
|
613 | + } |
|
614 | + } |
|
615 | + } |
|
616 | + } |
|
617 | + return $state_options; |
|
618 | + } |
|
619 | + |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * @param EE_Country[] $country_options |
|
624 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
625 | + * @param EE_Registration $registration |
|
626 | + * @param EE_Question $question |
|
627 | + * @param $answer |
|
628 | + * @return array |
|
629 | + */ |
|
630 | + public static function inject_new_reg_country_into_options( |
|
631 | + $country_options = array(), |
|
632 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
633 | + EE_Registration $registration, |
|
634 | + EE_Question $question, |
|
635 | + $answer |
|
636 | + ) { |
|
637 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
638 | + && $question->type() |
|
639 | + === EEM_Question::QST_type_country |
|
640 | + ) { |
|
641 | + $CNT_ISO = $answer->value(); |
|
642 | + if (! empty($CNT_ISO)) { |
|
643 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
644 | + if ($country instanceof EE_Country) { |
|
645 | + if (! isset($country_options[$CNT_ISO])) { |
|
646 | + $country_options[$CNT_ISO] = $country->name(); |
|
647 | + } |
|
648 | + } |
|
649 | + } |
|
650 | + } |
|
651 | + return $country_options; |
|
652 | + } |
|
653 | + |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * @param EE_State[] $state_options |
|
658 | + * @return array |
|
659 | + * @throws EE_Error |
|
660 | + */ |
|
661 | + public static function state_options($state_options = array()) |
|
662 | + { |
|
663 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
664 | + foreach ($new_states as $new_state) { |
|
665 | + if ( |
|
666 | + $new_state instanceof EE_State |
|
667 | + && $new_state->country() instanceof EE_Country |
|
668 | + ) { |
|
669 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
670 | + } |
|
671 | + } |
|
672 | + return $state_options; |
|
673 | + } |
|
674 | + |
|
675 | + |
|
676 | + |
|
677 | + /** |
|
678 | + * @return array |
|
679 | + */ |
|
680 | + protected static function _get_new_states() |
|
681 | + { |
|
682 | + $new_states = array(); |
|
683 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
684 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
685 | + 'nsmf_new_states' |
|
686 | + ); |
|
687 | + } |
|
688 | + return is_array($new_states) ? $new_states : array(); |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * @param EE_Country[] $country_options |
|
695 | + * @return array |
|
696 | + * @throws EE_Error |
|
697 | + */ |
|
698 | + public static function country_options($country_options = array()) |
|
699 | + { |
|
700 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
701 | + foreach ($new_states as $new_state) { |
|
702 | + if ( |
|
703 | + $new_state instanceof EE_State |
|
704 | + && $new_state->country() instanceof EE_Country |
|
705 | + ) { |
|
706 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
707 | + } |
|
708 | + } |
|
709 | + return $country_options; |
|
710 | + } |
|
711 | 711 | |
712 | 712 | |
713 | 713 |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public static function set_definitions() |
95 | 95 | { |
96 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
96 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
97 | 97 | define('ANS_TEMPLATES_PATH', str_replace( |
98 | 98 | '\\', |
99 | - DS, plugin_dir_path(__FILE__)) . 'templates' . DS |
|
99 | + DS, plugin_dir_path(__FILE__)).'templates'.DS |
|
100 | 100 | ); |
101 | 101 | } |
102 | 102 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | public static function wp_enqueue_scripts() |
148 | 148 | { |
149 | 149 | if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
150 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
150 | + wp_register_script('add_new_state', ANS_ASSETS_URL.'add_new_state.js', |
|
151 | 151 | array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
152 | 152 | wp_enqueue_script('add_new_state'); |
153 | 153 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
188 | 188 | $country_options = array(); |
189 | 189 | $countries = EEM_Country::instance()->get_all_countries(); |
190 | - if (! empty($countries)) { |
|
190 | + if ( ! empty($countries)) { |
|
191 | 191 | foreach ($countries as $country) { |
192 | 192 | if ($country instanceof EE_Country) { |
193 | 193 | $country_options[$country->ID()] = $country->name(); |
@@ -222,10 +222,10 @@ discard block |
||
222 | 222 | '', |
223 | 223 | esc_html__('click here to add a new state/province', 'event_espresso'), |
224 | 224 | '', |
225 | - 'display-' . $input->html_id(), |
|
225 | + 'display-'.$input->html_id(), |
|
226 | 226 | 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
227 | 227 | '', |
228 | - 'data-target="' . $input->html_id() . '"' |
|
228 | + 'data-target="'.$input->html_id().'"' |
|
229 | 229 | ) |
230 | 230 | ) |
231 | 231 | ), |
@@ -233,31 +233,31 @@ discard block |
||
233 | 233 | 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
234 | 234 | apply_filters( |
235 | 235 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
236 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
237 | - 'display: none;') . |
|
236 | + EEH_HTML::div('', $input->html_id().'-dv', 'ee-form-add-new-state-dv', |
|
237 | + 'display: none;'). |
|
238 | 238 | EEH_HTML::h6( |
239 | 239 | esc_html__( |
240 | 240 | 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
241 | 241 | 'event_espresso' |
242 | 242 | ) |
243 | - ) . |
|
244 | - EEH_HTML::ul() . |
|
243 | + ). |
|
244 | + EEH_HTML::ul(). |
|
245 | 245 | EEH_HTML::li( |
246 | 246 | esc_html__( |
247 | 247 | 'first select the Country that your State/Province belongs to', |
248 | 248 | 'event_espresso' |
249 | 249 | ) |
250 | - ) . |
|
250 | + ). |
|
251 | 251 | EEH_HTML::li( |
252 | 252 | esc_html__('enter the name of your State/Province', 'event_espresso') |
253 | - ) . |
|
253 | + ). |
|
254 | 254 | EEH_HTML::li( |
255 | 255 | esc_html__( |
256 | 256 | 'enter a two to six letter abbreviation for the name of your State/Province', |
257 | 257 | 'event_espresso' |
258 | 258 | ) |
259 | - ) . |
|
260 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
259 | + ). |
|
260 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')). |
|
261 | 261 | EEH_HTML::ulx() |
262 | 262 | ) |
263 | 263 | ), |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | 'state', |
271 | 271 | 'nsmf_new_state_country', $input->html_id() |
272 | 272 | ), |
273 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
273 | + 'html_class' => $input->html_class().' new-state-country', |
|
274 | 274 | 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
275 | 275 | 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
276 | 276 | 'required' => false, |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | 'state', |
285 | 285 | 'nsmf_new_state_name', $input->html_id() |
286 | 286 | ), |
287 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
287 | + 'html_class' => $input->html_class().' new-state-state', |
|
288 | 288 | 'html_label_text' => esc_html__('New State/Province Name', |
289 | 289 | 'event_espresso'), |
290 | 290 | 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
@@ -298,11 +298,11 @@ discard block |
||
298 | 298 | 'html_name' => $abbrv_name, |
299 | 299 | 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
300 | 300 | $input->html_id()), |
301 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
301 | + 'html_class' => $input->html_class().' new-state-abbrv', |
|
302 | 302 | 'html_label_text' => esc_html__( |
303 | 303 | 'New State/Province Abbreviation', |
304 | 304 | 'event_espresso' |
305 | - ) . ' *', |
|
305 | + ).' *', |
|
306 | 306 | 'html_other_attributes' => 'size="24"', |
307 | 307 | 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
308 | 308 | 'required' => false, |
@@ -312,15 +312,15 @@ discard block |
||
312 | 312 | 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
313 | 313 | apply_filters( |
314 | 314 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
315 | - EEH_HTML::nbsp(3) . |
|
315 | + EEH_HTML::nbsp(3). |
|
316 | 316 | EEH_HTML::link( |
317 | 317 | '', |
318 | 318 | esc_html__('ADD', 'event_espresso'), |
319 | 319 | '', |
320 | - 'submit-' . $new_state_submit_id, |
|
320 | + 'submit-'.$new_state_submit_id, |
|
321 | 321 | 'ee-form-add-new-state-submit button button-secondary', |
322 | 322 | '', |
323 | - 'data-target="' . $new_state_submit_id . '"' |
|
323 | + 'data-target="'.$new_state_submit_id.'"' |
|
324 | 324 | ) |
325 | 325 | ) |
326 | 326 | ), |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | EEH_HTML::div('', '', 'small-text') |
334 | 334 | . |
335 | 335 | EEH_HTML::strong( |
336 | - '* ' . |
|
336 | + '* '. |
|
337 | 337 | esc_html__( |
338 | 338 | 'Don\'t know your State/Province Abbreviation?', |
339 | 339 | 'event_espresso' |
@@ -366,10 +366,10 @@ discard block |
||
366 | 366 | '', |
367 | 367 | esc_html__('cancel new State/Province', 'event_espresso'), |
368 | 368 | '', |
369 | - 'hide-' . $input->html_id(), |
|
369 | + 'hide-'.$input->html_id(), |
|
370 | 370 | 'ee-form-cancel-new-state-lnk smaller-text', |
371 | 371 | '', |
372 | - 'data-target="' . $input->html_id() . '"' |
|
372 | + 'data-target="'.$input->html_id().'"' |
|
373 | 373 | ) |
374 | 374 | . |
375 | 375 | EEH_HTML::divx() |
@@ -508,27 +508,27 @@ discard block |
||
508 | 508 | public static function save_new_state_to_db($props_n_values = array()) |
509 | 509 | { |
510 | 510 | $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
511 | - if (! empty($existing_state)) { |
|
511 | + if ( ! empty($existing_state)) { |
|
512 | 512 | return array_pop($existing_state); |
513 | 513 | } |
514 | 514 | $new_state = EE_State::new_instance($props_n_values); |
515 | 515 | if ($new_state instanceof EE_State) { |
516 | 516 | // if not non-ajax admin |
517 | - $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
517 | + $new_state_key = 'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(); |
|
518 | 518 | $new_state_notice = sprintf( |
519 | 519 | esc_html__( |
520 | 520 | 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
521 | 521 | 'event_espresso' |
522 | 522 | ), |
523 | - '<b>' . $new_state->name() . '</b>', |
|
524 | - '<b>' . $new_state->abbrev() . '</b>', |
|
525 | - '<b>' . $new_state->country()->name() . '</b>', |
|
526 | - '<a href="' . add_query_arg(array( |
|
523 | + '<b>'.$new_state->name().'</b>', |
|
524 | + '<b>'.$new_state->abbrev().'</b>', |
|
525 | + '<b>'.$new_state->country()->name().'</b>', |
|
526 | + '<a href="'.add_query_arg(array( |
|
527 | 527 | 'page' => 'espresso_general_settings', |
528 | 528 | 'action' => 'country_settings', |
529 | 529 | 'country' => $new_state->country_iso(), |
530 | - ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
531 | - 'event_espresso') . '</a>', |
|
530 | + ), admin_url('admin.php')).'">'.esc_html__('Event Espresso - General Settings > Countries Tab', |
|
531 | + 'event_espresso').'</a>', |
|
532 | 532 | '<br />' |
533 | 533 | ); |
534 | 534 | EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
551 | 551 | { |
552 | 552 | $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false; |
553 | - if (! $CNT_ISO) { |
|
553 | + if ( ! $CNT_ISO) { |
|
554 | 554 | EE_Error::add_error( |
555 | 555 | esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
556 | 556 | __FILE__, |
@@ -560,13 +560,13 @@ discard block |
||
560 | 560 | } |
561 | 561 | $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
562 | 562 | : false; |
563 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
563 | + if ( ! $STA_abbrev && ! empty($STA_ID)) { |
|
564 | 564 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
565 | 565 | if ($state instanceof EE_State) { |
566 | 566 | $STA_abbrev = $state->abbrev(); |
567 | 567 | } |
568 | 568 | } |
569 | - if (! $STA_abbrev) { |
|
569 | + if ( ! $STA_abbrev) { |
|
570 | 570 | EE_Error::add_error( |
571 | 571 | esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
572 | 572 | __FILE__, |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | __LINE__ |
575 | 575 | ); |
576 | 576 | } |
577 | - EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
577 | + EE_Error::dismiss_persistent_admin_notice($CNT_ISO.'-'.$STA_abbrev, true, true); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | |
@@ -599,15 +599,15 @@ discard block |
||
599 | 599 | === EEM_Question::QST_type_state |
600 | 600 | ) { |
601 | 601 | $STA_ID = $answer->value(); |
602 | - if (! empty($STA_ID)) { |
|
602 | + if ( ! empty($STA_ID)) { |
|
603 | 603 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
604 | 604 | if ($state instanceof EE_State) { |
605 | 605 | $country = $state->country(); |
606 | 606 | if ($country instanceof EE_Country) { |
607 | - if (! isset($state_options[$country->name()])) { |
|
607 | + if ( ! isset($state_options[$country->name()])) { |
|
608 | 608 | $state_options[$country->name()] = array(); |
609 | 609 | } |
610 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
610 | + if ( ! isset($state_options[$country->name()][$STA_ID])) { |
|
611 | 611 | $state_options[$country->name()][$STA_ID] = $state->name(); |
612 | 612 | } |
613 | 613 | } |
@@ -639,10 +639,10 @@ discard block |
||
639 | 639 | === EEM_Question::QST_type_country |
640 | 640 | ) { |
641 | 641 | $CNT_ISO = $answer->value(); |
642 | - if (! empty($CNT_ISO)) { |
|
642 | + if ( ! empty($CNT_ISO)) { |
|
643 | 643 | $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
644 | 644 | if ($country instanceof EE_Country) { |
645 | - if (! isset($country_options[$CNT_ISO])) { |
|
645 | + if ( ! isset($country_options[$CNT_ISO])) { |
|
646 | 646 | $country_options[$CNT_ISO] = $country->name(); |
647 | 647 | } |
648 | 648 | } |
@@ -32,49 +32,49 @@ discard block |
||
32 | 32 | |
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * get_event |
|
37 | - * attempts to retrieve an EE_Event object any way it can |
|
38 | - * |
|
39 | - * @param int|WP_Post $EVT_ID |
|
40 | - * @return EE_Event|null |
|
41 | - * @throws \EE_Error |
|
42 | - */ |
|
35 | + /** |
|
36 | + * get_event |
|
37 | + * attempts to retrieve an EE_Event object any way it can |
|
38 | + * |
|
39 | + * @param int|WP_Post $EVT_ID |
|
40 | + * @return EE_Event|null |
|
41 | + * @throws \EE_Error |
|
42 | + */ |
|
43 | 43 | public static function get_event( $EVT_ID = 0 ) { |
44 | - // international newspaper? |
|
45 | - global $post; |
|
46 | - $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events' |
|
47 | - ? $EVT_ID->ID |
|
48 | - : absint($EVT_ID); |
|
49 | - // do we already have the Event you are looking for? |
|
50 | - if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) { |
|
51 | - return EEH_Event_View::$_event; |
|
52 | - } |
|
53 | - //reset property so that the new event is cached. |
|
54 | - EEH_Event_View::$_event = null; |
|
55 | - |
|
56 | - if ($EVT_ID || $post instanceof WP_Post) { |
|
57 | - //if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID |
|
58 | - //then let's just use that cached event on the $post object. |
|
59 | - if (($post instanceof WP_Post |
|
60 | - && $post->post_type === 'espresso_events' |
|
61 | - ) |
|
62 | - && isset($post->EE_Event) |
|
63 | - && ($EVT_ID === 0 |
|
64 | - || $EVT_ID === $post->ID |
|
65 | - ) |
|
66 | - ) { |
|
67 | - EEH_Event_View::$_event = $post->EE_Event; |
|
68 | - } |
|
69 | - |
|
70 | - //If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID. |
|
71 | - if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
72 | - EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - return EEH_Event_View::$_event; |
|
77 | - } |
|
44 | + // international newspaper? |
|
45 | + global $post; |
|
46 | + $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events' |
|
47 | + ? $EVT_ID->ID |
|
48 | + : absint($EVT_ID); |
|
49 | + // do we already have the Event you are looking for? |
|
50 | + if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) { |
|
51 | + return EEH_Event_View::$_event; |
|
52 | + } |
|
53 | + //reset property so that the new event is cached. |
|
54 | + EEH_Event_View::$_event = null; |
|
55 | + |
|
56 | + if ($EVT_ID || $post instanceof WP_Post) { |
|
57 | + //if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID |
|
58 | + //then let's just use that cached event on the $post object. |
|
59 | + if (($post instanceof WP_Post |
|
60 | + && $post->post_type === 'espresso_events' |
|
61 | + ) |
|
62 | + && isset($post->EE_Event) |
|
63 | + && ($EVT_ID === 0 |
|
64 | + || $EVT_ID === $post->ID |
|
65 | + ) |
|
66 | + ) { |
|
67 | + EEH_Event_View::$_event = $post->EE_Event; |
|
68 | + } |
|
69 | + |
|
70 | + //If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID. |
|
71 | + if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
72 | + EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + return EEH_Event_View::$_event; |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | 80 | |
@@ -150,58 +150,58 @@ discard block |
||
150 | 150 | * @return string |
151 | 151 | */ |
152 | 152 | public static function event_content_or_excerpt( $num_words = NULL, $more = NULL ) { |
153 | - global $post; |
|
153 | + global $post; |
|
154 | 154 | ob_start(); |
155 | 155 | if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) { |
156 | 156 | // admin has chosen "full description" |
157 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
157 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
158 | 158 | the_content(); |
159 | 159 | } else if (( is_archive() && espresso_display_excerpt_in_event_list() ) ) { |
160 | - if ( has_excerpt( $post->ID )) { |
|
161 | - // admin has chosen "excerpt (short desc)" |
|
162 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
163 | - // AND an excerpt actually exists |
|
164 | - the_excerpt(); |
|
165 | - } else { |
|
166 | - // admin has chosen "excerpt (short desc)" |
|
167 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
168 | - // but NO excerpt actually exists, so we need to create one |
|
169 | - if ( ! empty( $num_words )) { |
|
170 | - if ( empty( $more )) { |
|
171 | - $more_link_text = __( '(more…)' ); |
|
172 | - $more = ' <a href="' . get_permalink() . '"'; |
|
173 | - $more .= ' class="more-link"'; |
|
174 | - $more .= \EED_Events_Archive::link_target(); |
|
175 | - $more .= '>' . $more_link_text . '</a>'; |
|
176 | - $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
177 | - } |
|
178 | - $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' )); |
|
179 | - |
|
180 | - $content = wp_trim_words( $content, $num_words, ' ' ) . $more; |
|
181 | - } else { |
|
182 | - $content = get_the_content(); |
|
183 | - } |
|
184 | - global $allowedtags; |
|
185 | - // make sure links are allowed |
|
186 | - $allowedtags['a'] = isset($allowedtags['a']) |
|
187 | - ? $allowedtags['a'] |
|
188 | - : array(); |
|
189 | - // as well as target attribute |
|
190 | - $allowedtags['a']['target'] = isset($allowedtags['a']['target']) |
|
191 | - ? $allowedtags['a']['target'] |
|
192 | - : false; |
|
193 | - // but get previous value so we can reset it |
|
194 | - $prev_value = $allowedtags['a']['target']; |
|
195 | - $allowedtags['a']['target'] = true; |
|
196 | - $content = wp_kses( $content, $allowedtags ); |
|
197 | - $content = strip_shortcodes( $content ); |
|
198 | - echo apply_filters( 'the_content', $content ); |
|
199 | - $allowedtags['a']['target'] = $prev_value; |
|
200 | - } |
|
201 | - } else { |
|
202 | - // admin has chosen "none" |
|
203 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
204 | - echo apply_filters( 'the_content', '' ); |
|
160 | + if ( has_excerpt( $post->ID )) { |
|
161 | + // admin has chosen "excerpt (short desc)" |
|
162 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
163 | + // AND an excerpt actually exists |
|
164 | + the_excerpt(); |
|
165 | + } else { |
|
166 | + // admin has chosen "excerpt (short desc)" |
|
167 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
168 | + // but NO excerpt actually exists, so we need to create one |
|
169 | + if ( ! empty( $num_words )) { |
|
170 | + if ( empty( $more )) { |
|
171 | + $more_link_text = __( '(more…)' ); |
|
172 | + $more = ' <a href="' . get_permalink() . '"'; |
|
173 | + $more .= ' class="more-link"'; |
|
174 | + $more .= \EED_Events_Archive::link_target(); |
|
175 | + $more .= '>' . $more_link_text . '</a>'; |
|
176 | + $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
177 | + } |
|
178 | + $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' )); |
|
179 | + |
|
180 | + $content = wp_trim_words( $content, $num_words, ' ' ) . $more; |
|
181 | + } else { |
|
182 | + $content = get_the_content(); |
|
183 | + } |
|
184 | + global $allowedtags; |
|
185 | + // make sure links are allowed |
|
186 | + $allowedtags['a'] = isset($allowedtags['a']) |
|
187 | + ? $allowedtags['a'] |
|
188 | + : array(); |
|
189 | + // as well as target attribute |
|
190 | + $allowedtags['a']['target'] = isset($allowedtags['a']['target']) |
|
191 | + ? $allowedtags['a']['target'] |
|
192 | + : false; |
|
193 | + // but get previous value so we can reset it |
|
194 | + $prev_value = $allowedtags['a']['target']; |
|
195 | + $allowedtags['a']['target'] = true; |
|
196 | + $content = wp_kses( $content, $allowedtags ); |
|
197 | + $content = strip_shortcodes( $content ); |
|
198 | + echo apply_filters( 'the_content', $content ); |
|
199 | + $allowedtags['a']['target'] = $prev_value; |
|
200 | + } |
|
201 | + } else { |
|
202 | + // admin has chosen "none" |
|
203 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
204 | + echo apply_filters( 'the_content', '' ); |
|
205 | 205 | } |
206 | 206 | return ob_get_clean(); |
207 | 207 | } |
@@ -248,11 +248,11 @@ discard block |
||
248 | 248 | $url = get_term_link( $term, 'espresso_venue_categories' ); |
249 | 249 | if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) { |
250 | 250 | $category_links[] = '<a href="' . esc_url( $url ) |
251 | - . '" rel="tag"' |
|
252 | - . \EED_Events_Archive::link_target() |
|
253 | - .'>' |
|
254 | - . $term->name |
|
255 | - . '</a>'; |
|
251 | + . '" rel="tag"' |
|
252 | + . \EED_Events_Archive::link_target() |
|
253 | + .'>' |
|
254 | + . $term->name |
|
255 | + . '</a>'; |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | <ul class="wp-people-group" id="ee-people-group-owners"> |
4 | 4 | <li class="wp-person" id="ee-person-sshoultes"> |
5 | 5 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
6 | - <?php echo esp_gravatar_image( '[email protected]', 'Seth Shoultes' ); ?> |
|
6 | + <?php echo esp_gravatar_image('[email protected]', 'Seth Shoultes'); ?> |
|
7 | 7 | </a> |
8 | 8 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
9 | 9 | Seth Shoultes |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | </li> |
13 | 13 | <li class="wp-person" id="ee-person-gkoyle"> |
14 | 14 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
15 | - <?php echo esp_gravatar_image( '[email protected]', 'Garth Koyle' ); ?> |
|
15 | + <?php echo esp_gravatar_image('[email protected]', 'Garth Koyle'); ?> |
|
16 | 16 | </a> |
17 | 17 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
18 | 18 | Garth Koyle |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | <ul class="wp-people-group" id="ee-people-group-core-developers"> |
25 | 25 | <li class="wp-person" id="ee-person-bchristensen"> |
26 | 26 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
27 | - <?php echo esp_gravatar_image( '[email protected]', 'Brent Christensen' ); ?> |
|
27 | + <?php echo esp_gravatar_image('[email protected]', 'Brent Christensen'); ?> |
|
28 | 28 | </a> |
29 | 29 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
30 | 30 | Brent Christensen |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | </li> |
34 | 34 | <li class="wp-person" id="ee-person-dethier"> |
35 | 35 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
36 | - <?php echo esp_gravatar_image( '[email protected]', 'Darren Ethier' ); ?> |
|
36 | + <?php echo esp_gravatar_image('[email protected]', 'Darren Ethier'); ?> |
|
37 | 37 | </a> |
38 | 38 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
39 | 39 | Darren Ethier |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | </li> |
43 | 43 | <li class="wp-person" id="ee-person-mnelson"> |
44 | 44 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
45 | - <?php echo esp_gravatar_image( '[email protected]', 'Michael Nelson' ); ?> |
|
45 | + <?php echo esp_gravatar_image('[email protected]', 'Michael Nelson'); ?> |
|
46 | 46 | </a> |
47 | 47 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
48 | 48 | Michael Nelson |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | </li> |
52 | 52 | <li class="wp-person" id="ee-person-nkolivoshka"> |
53 | 53 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
54 | - <?php echo esp_gravatar_image( '[email protected]', 'Nazar Kolivoshka' ); ?> |
|
54 | + <?php echo esp_gravatar_image('[email protected]', 'Nazar Kolivoshka'); ?> |
|
55 | 55 | </a> |
56 | 56 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
57 | 57 | Nazar Kolivoshka |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | <ul class="wp-people-group" id="ee-people-group-support-staff"> |
64 | 64 | <li class="wp-person" id="ee-person-jfeck"> |
65 | 65 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
66 | - <?php echo esp_gravatar_image( '[email protected]', 'Josh Feck' ); ?> |
|
66 | + <?php echo esp_gravatar_image('[email protected]', 'Josh Feck'); ?> |
|
67 | 67 | </a> |
68 | 68 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
69 | 69 | Josh Feck |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | </li> |
72 | 72 | <li class="wp-person" id="ee-person-twarwick"> |
73 | 73 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
74 | - <?php echo esp_gravatar_image( '[email protected]', 'Tony Warwick' ); ?> |
|
74 | + <?php echo esp_gravatar_image('[email protected]', 'Tony Warwick'); ?> |
|
75 | 75 | </a> |
76 | 76 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
77 | 77 | Tony Warwick |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | </li> |
80 | 80 | <li class="wp-person" id="ee-person-lcaum"> |
81 | 81 | <a href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
82 | - <?php echo esp_gravatar_image( '[email protected]', 'Lorenzo Caum' ); ?> |
|
82 | + <?php echo esp_gravatar_image('[email protected]', 'Lorenzo Caum'); ?> |
|
83 | 83 | </a> |
84 | 84 | <a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>"> |
85 | 85 | Lorenzo Caum |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | </ul> |
90 | 90 | <h3 class="wp-people-group"><?php _e('Contributor Recognition', 'event_espresso'); ?></h3> |
91 | 91 | <p class="description"> |
92 | - <?php printf( __('For every major release we want to recognize the people who contributed to the release via a GitHub pull request. Want to see your name listed here? %sWhen you submit a pull request that gets included in a major release%s, we\'ll add your name here linked to your GitHub profile.', 'event_espresso'), '<a href="https://github.com/eventespresso/event-espresso-core" title="Contribute to Event Espresso by making a pull request via GitHub">', '</a>' ); ?> |
|
92 | + <?php printf(__('For every major release we want to recognize the people who contributed to the release via a GitHub pull request. Want to see your name listed here? %sWhen you submit a pull request that gets included in a major release%s, we\'ll add your name here linked to your GitHub profile.', 'event_espresso'), '<a href="https://github.com/eventespresso/event-espresso-core" title="Contribute to Event Espresso by making a pull request via GitHub">', '</a>'); ?> |
|
93 | 93 | </p> |
94 | 94 | <p class="wp-credits-list"> |
95 | 95 | <ul> |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | </p> |
104 | 104 | <h3 class="wp-people-group"><?php _e('External Libraries', 'event_espresso'); ?></h3> |
105 | 105 | <p class="description"> |
106 | - <?php printf( __('Along with the libraries %sincluded with WordPress%s, Event Espresso utilizes the following third party libraries:', 'event_espresso'), '<a href="credits.php">', '</a>' ); ?> |
|
106 | + <?php printf(__('Along with the libraries %sincluded with WordPress%s, Event Espresso utilizes the following third party libraries:', 'event_espresso'), '<a href="credits.php">', '</a>'); ?> |
|
107 | 107 | </p> |
108 | 108 | <p class="wp-credits-list"> |
109 | 109 | <a href="http://josscrowcroft.github.io/accounting.js/"><?php _e('accounting.js', 'event_espresso'); ?></a>, |
@@ -119,10 +119,10 @@ discard block |
||
119 | 119 | |
120 | 120 | <?php |
121 | 121 | function esp_gravatar_profile($email) { |
122 | - echo 'http://www.gravatar.com/' . md5($email); |
|
122 | + echo 'http://www.gravatar.com/'.md5($email); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | function esp_gravatar_image($email, $name) { |
126 | - echo '<img src="http://0.gravatar.com/avatar/' . md5($email) . '?s=60" class="gravatar" alt="' . $name . '"/>'; |
|
126 | + echo '<img src="http://0.gravatar.com/avatar/'.md5($email).'?s=60" class="gravatar" alt="'.$name.'"/>'; |
|
127 | 127 | } |
128 | 128 | ?> |
@@ -5,8 +5,8 @@ discard block |
||
5 | 5 | // if you're a dev and want to receive all errors via email |
6 | 6 | // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
7 | 7 | if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) { |
8 | - set_error_handler(array('EE_Error', 'error_handler')); |
|
9 | - register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
8 | + set_error_handler(array('EE_Error', 'error_handler')); |
|
9 | + register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | |
@@ -23,259 +23,259 @@ discard block |
||
23 | 23 | { |
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * name of the file to log exceptions to |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - private static $_exception_log_file = 'espresso_error_log.txt'; |
|
32 | - |
|
33 | - /** |
|
34 | - * stores details for all exception |
|
35 | - * |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - private static $_all_exceptions = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * tracks number of errors |
|
42 | - * |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - private static $_error_count = 0; |
|
46 | - |
|
47 | - /** |
|
48 | - * has shutdown action been added ? |
|
49 | - * |
|
50 | - * @var array $_espresso_notices |
|
51 | - */ |
|
52 | - private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @override default exception handling |
|
58 | - * @param string $message |
|
59 | - * @param int $code |
|
60 | - * @param Exception|null $previous |
|
61 | - */ |
|
62 | - public function __construct($message, $code = 0, Exception $previous = null) |
|
63 | - { |
|
64 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
65 | - parent::__construct($message, $code); |
|
66 | - } else { |
|
67 | - parent::__construct($message, $code, $previous); |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * error_handler |
|
75 | - * |
|
76 | - * @param $code |
|
77 | - * @param $message |
|
78 | - * @param $file |
|
79 | - * @param $line |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - public static function error_handler($code, $message, $file, $line) |
|
83 | - { |
|
84 | - $type = EE_Error::error_type($code); |
|
85 | - $site = site_url(); |
|
86 | - switch ($site) { |
|
87 | - case 'http://ee4.eventespresso.com/' : |
|
88 | - case 'http://ee4decaf.eventespresso.com/' : |
|
89 | - case 'http://ee4hf.eventespresso.com/' : |
|
90 | - case 'http://ee4a.eventespresso.com/' : |
|
91 | - case 'http://ee4ad.eventespresso.com/' : |
|
92 | - case 'http://ee4b.eventespresso.com/' : |
|
93 | - case 'http://ee4bd.eventespresso.com/' : |
|
94 | - case 'http://ee4d.eventespresso.com/' : |
|
95 | - case 'http://ee4dd.eventespresso.com/' : |
|
96 | - $to = '[email protected]'; |
|
97 | - break; |
|
98 | - default : |
|
99 | - $to = get_option('admin_email'); |
|
100 | - } |
|
101 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
102 | - $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
103 | - if (function_exists('wp_mail')) { |
|
104 | - add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
105 | - wp_mail($to, $subject, $msg); |
|
106 | - } |
|
107 | - echo '<div id="message" class="espresso-notices error"><p>'; |
|
108 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
109 | - echo '<br /></p></div>'; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * error_type |
|
116 | - * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
117 | - * |
|
118 | - * @param $code |
|
119 | - * @return string |
|
120 | - */ |
|
121 | - public static function error_type($code) |
|
122 | - { |
|
123 | - switch ($code) { |
|
124 | - case E_ERROR: // 1 // |
|
125 | - return 'E_ERROR'; |
|
126 | - case E_WARNING: // 2 // |
|
127 | - return 'E_WARNING'; |
|
128 | - case E_PARSE: // 4 // |
|
129 | - return 'E_PARSE'; |
|
130 | - case E_NOTICE: // 8 // |
|
131 | - return 'E_NOTICE'; |
|
132 | - case E_CORE_ERROR: // 16 // |
|
133 | - return 'E_CORE_ERROR'; |
|
134 | - case E_CORE_WARNING: // 32 // |
|
135 | - return 'E_CORE_WARNING'; |
|
136 | - case E_COMPILE_ERROR: // 64 // |
|
137 | - return 'E_COMPILE_ERROR'; |
|
138 | - case E_COMPILE_WARNING: // 128 // |
|
139 | - return 'E_COMPILE_WARNING'; |
|
140 | - case E_USER_ERROR: // 256 // |
|
141 | - return 'E_USER_ERROR'; |
|
142 | - case E_USER_WARNING: // 512 // |
|
143 | - return 'E_USER_WARNING'; |
|
144 | - case E_USER_NOTICE: // 1024 // |
|
145 | - return 'E_USER_NOTICE'; |
|
146 | - case E_STRICT: // 2048 // |
|
147 | - return 'E_STRICT'; |
|
148 | - case E_RECOVERABLE_ERROR: // 4096 // |
|
149 | - return 'E_RECOVERABLE_ERROR'; |
|
150 | - case E_DEPRECATED: // 8192 // |
|
151 | - return 'E_DEPRECATED'; |
|
152 | - case E_USER_DEPRECATED: // 16384 // |
|
153 | - return 'E_USER_DEPRECATED'; |
|
154 | - case E_ALL: // 16384 // |
|
155 | - return 'E_ALL'; |
|
156 | - } |
|
157 | - return ''; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * fatal_error_handler |
|
164 | - * |
|
165 | - * @return void |
|
166 | - */ |
|
167 | - public static function fatal_error_handler() |
|
168 | - { |
|
169 | - $last_error = error_get_last(); |
|
170 | - if ($last_error['type'] === E_ERROR) { |
|
171 | - EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * _format_error |
|
179 | - * |
|
180 | - * @param $code |
|
181 | - * @param $message |
|
182 | - * @param $file |
|
183 | - * @param $line |
|
184 | - * @return string |
|
185 | - */ |
|
186 | - private static function _format_error($code, $message, $file, $line) |
|
187 | - { |
|
188 | - $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
189 | - $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
190 | - $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
191 | - $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
192 | - $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
193 | - $html .= '</tbody></table>'; |
|
194 | - return $html; |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * set_content_type |
|
201 | - * |
|
202 | - * @param $content_type |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - public static function set_content_type($content_type) |
|
206 | - { |
|
207 | - return 'text/html'; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * @return void |
|
214 | - * @throws EE_Error |
|
215 | - * @throws ReflectionException |
|
216 | - */ |
|
217 | - public function get_error() |
|
218 | - { |
|
219 | - if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
220 | - throw $this; |
|
221 | - } |
|
222 | - // get separate user and developer messages if they exist |
|
223 | - $msg = explode('||', $this->getMessage()); |
|
224 | - $user_msg = $msg[0]; |
|
225 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
226 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
227 | - // add details to _all_exceptions array |
|
228 | - $x_time = time(); |
|
229 | - self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
230 | - self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
231 | - self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
232 | - self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
233 | - self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
234 | - self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
235 | - self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
236 | - self::$_error_count++; |
|
237 | - //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
238 | - $this->display_errors(); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * has_error |
|
245 | - * |
|
246 | - * @param bool $check_stored |
|
247 | - * @param string $type_to_check |
|
248 | - * @return bool |
|
249 | - */ |
|
250 | - public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
251 | - { |
|
252 | - $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
253 | - && ! empty(self::$_espresso_notices[$type_to_check]) |
|
254 | - ? true |
|
255 | - : false; |
|
256 | - if ($check_stored && ! $has_error) { |
|
257 | - $notices = (array)get_option('ee_notices', array()); |
|
258 | - foreach ($notices as $type => $notice) { |
|
259 | - if ($type === $type_to_check && $notice) { |
|
260 | - return true; |
|
261 | - } |
|
262 | - } |
|
263 | - } |
|
264 | - return $has_error; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * display_errors |
|
271 | - * |
|
272 | - * @echo string |
|
273 | - * @throws \ReflectionException |
|
274 | - */ |
|
275 | - public function display_errors() |
|
276 | - { |
|
277 | - $trace_details = ''; |
|
278 | - $output = ' |
|
26 | + /** |
|
27 | + * name of the file to log exceptions to |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + private static $_exception_log_file = 'espresso_error_log.txt'; |
|
32 | + |
|
33 | + /** |
|
34 | + * stores details for all exception |
|
35 | + * |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + private static $_all_exceptions = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * tracks number of errors |
|
42 | + * |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + private static $_error_count = 0; |
|
46 | + |
|
47 | + /** |
|
48 | + * has shutdown action been added ? |
|
49 | + * |
|
50 | + * @var array $_espresso_notices |
|
51 | + */ |
|
52 | + private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @override default exception handling |
|
58 | + * @param string $message |
|
59 | + * @param int $code |
|
60 | + * @param Exception|null $previous |
|
61 | + */ |
|
62 | + public function __construct($message, $code = 0, Exception $previous = null) |
|
63 | + { |
|
64 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
65 | + parent::__construct($message, $code); |
|
66 | + } else { |
|
67 | + parent::__construct($message, $code, $previous); |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * error_handler |
|
75 | + * |
|
76 | + * @param $code |
|
77 | + * @param $message |
|
78 | + * @param $file |
|
79 | + * @param $line |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + public static function error_handler($code, $message, $file, $line) |
|
83 | + { |
|
84 | + $type = EE_Error::error_type($code); |
|
85 | + $site = site_url(); |
|
86 | + switch ($site) { |
|
87 | + case 'http://ee4.eventespresso.com/' : |
|
88 | + case 'http://ee4decaf.eventespresso.com/' : |
|
89 | + case 'http://ee4hf.eventespresso.com/' : |
|
90 | + case 'http://ee4a.eventespresso.com/' : |
|
91 | + case 'http://ee4ad.eventespresso.com/' : |
|
92 | + case 'http://ee4b.eventespresso.com/' : |
|
93 | + case 'http://ee4bd.eventespresso.com/' : |
|
94 | + case 'http://ee4d.eventespresso.com/' : |
|
95 | + case 'http://ee4dd.eventespresso.com/' : |
|
96 | + $to = '[email protected]'; |
|
97 | + break; |
|
98 | + default : |
|
99 | + $to = get_option('admin_email'); |
|
100 | + } |
|
101 | + $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
102 | + $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
103 | + if (function_exists('wp_mail')) { |
|
104 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
105 | + wp_mail($to, $subject, $msg); |
|
106 | + } |
|
107 | + echo '<div id="message" class="espresso-notices error"><p>'; |
|
108 | + echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
109 | + echo '<br /></p></div>'; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * error_type |
|
116 | + * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
117 | + * |
|
118 | + * @param $code |
|
119 | + * @return string |
|
120 | + */ |
|
121 | + public static function error_type($code) |
|
122 | + { |
|
123 | + switch ($code) { |
|
124 | + case E_ERROR: // 1 // |
|
125 | + return 'E_ERROR'; |
|
126 | + case E_WARNING: // 2 // |
|
127 | + return 'E_WARNING'; |
|
128 | + case E_PARSE: // 4 // |
|
129 | + return 'E_PARSE'; |
|
130 | + case E_NOTICE: // 8 // |
|
131 | + return 'E_NOTICE'; |
|
132 | + case E_CORE_ERROR: // 16 // |
|
133 | + return 'E_CORE_ERROR'; |
|
134 | + case E_CORE_WARNING: // 32 // |
|
135 | + return 'E_CORE_WARNING'; |
|
136 | + case E_COMPILE_ERROR: // 64 // |
|
137 | + return 'E_COMPILE_ERROR'; |
|
138 | + case E_COMPILE_WARNING: // 128 // |
|
139 | + return 'E_COMPILE_WARNING'; |
|
140 | + case E_USER_ERROR: // 256 // |
|
141 | + return 'E_USER_ERROR'; |
|
142 | + case E_USER_WARNING: // 512 // |
|
143 | + return 'E_USER_WARNING'; |
|
144 | + case E_USER_NOTICE: // 1024 // |
|
145 | + return 'E_USER_NOTICE'; |
|
146 | + case E_STRICT: // 2048 // |
|
147 | + return 'E_STRICT'; |
|
148 | + case E_RECOVERABLE_ERROR: // 4096 // |
|
149 | + return 'E_RECOVERABLE_ERROR'; |
|
150 | + case E_DEPRECATED: // 8192 // |
|
151 | + return 'E_DEPRECATED'; |
|
152 | + case E_USER_DEPRECATED: // 16384 // |
|
153 | + return 'E_USER_DEPRECATED'; |
|
154 | + case E_ALL: // 16384 // |
|
155 | + return 'E_ALL'; |
|
156 | + } |
|
157 | + return ''; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * fatal_error_handler |
|
164 | + * |
|
165 | + * @return void |
|
166 | + */ |
|
167 | + public static function fatal_error_handler() |
|
168 | + { |
|
169 | + $last_error = error_get_last(); |
|
170 | + if ($last_error['type'] === E_ERROR) { |
|
171 | + EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * _format_error |
|
179 | + * |
|
180 | + * @param $code |
|
181 | + * @param $message |
|
182 | + * @param $file |
|
183 | + * @param $line |
|
184 | + * @return string |
|
185 | + */ |
|
186 | + private static function _format_error($code, $message, $file, $line) |
|
187 | + { |
|
188 | + $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
189 | + $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
190 | + $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
191 | + $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
192 | + $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
193 | + $html .= '</tbody></table>'; |
|
194 | + return $html; |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * set_content_type |
|
201 | + * |
|
202 | + * @param $content_type |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + public static function set_content_type($content_type) |
|
206 | + { |
|
207 | + return 'text/html'; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * @return void |
|
214 | + * @throws EE_Error |
|
215 | + * @throws ReflectionException |
|
216 | + */ |
|
217 | + public function get_error() |
|
218 | + { |
|
219 | + if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
220 | + throw $this; |
|
221 | + } |
|
222 | + // get separate user and developer messages if they exist |
|
223 | + $msg = explode('||', $this->getMessage()); |
|
224 | + $user_msg = $msg[0]; |
|
225 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
226 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
227 | + // add details to _all_exceptions array |
|
228 | + $x_time = time(); |
|
229 | + self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
230 | + self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
231 | + self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
232 | + self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
233 | + self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
234 | + self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
235 | + self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
236 | + self::$_error_count++; |
|
237 | + //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
238 | + $this->display_errors(); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * has_error |
|
245 | + * |
|
246 | + * @param bool $check_stored |
|
247 | + * @param string $type_to_check |
|
248 | + * @return bool |
|
249 | + */ |
|
250 | + public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
251 | + { |
|
252 | + $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
253 | + && ! empty(self::$_espresso_notices[$type_to_check]) |
|
254 | + ? true |
|
255 | + : false; |
|
256 | + if ($check_stored && ! $has_error) { |
|
257 | + $notices = (array)get_option('ee_notices', array()); |
|
258 | + foreach ($notices as $type => $notice) { |
|
259 | + if ($type === $type_to_check && $notice) { |
|
260 | + return true; |
|
261 | + } |
|
262 | + } |
|
263 | + } |
|
264 | + return $has_error; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * display_errors |
|
271 | + * |
|
272 | + * @echo string |
|
273 | + * @throws \ReflectionException |
|
274 | + */ |
|
275 | + public function display_errors() |
|
276 | + { |
|
277 | + $trace_details = ''; |
|
278 | + $output = ' |
|
279 | 279 | <style type="text/css"> |
280 | 280 | #ee-error-message { |
281 | 281 | max-width:90% !important; |
@@ -331,19 +331,19 @@ discard block |
||
331 | 331 | } |
332 | 332 | </style> |
333 | 333 | <div id="ee-error-message" class="error">'; |
334 | - if (! WP_DEBUG) { |
|
335 | - $output .= ' |
|
334 | + if (! WP_DEBUG) { |
|
335 | + $output .= ' |
|
336 | 336 | <p>'; |
337 | - } |
|
338 | - // cycle thru errors |
|
339 | - foreach (self::$_all_exceptions as $time => $ex) { |
|
340 | - $error_code = ''; |
|
341 | - // process trace info |
|
342 | - if (empty($ex['trace'])) { |
|
343 | - $trace_details .= __('Sorry, but no trace information was available for this exception.', |
|
344 | - 'event_espresso'); |
|
345 | - } else { |
|
346 | - $trace_details .= ' |
|
337 | + } |
|
338 | + // cycle thru errors |
|
339 | + foreach (self::$_all_exceptions as $time => $ex) { |
|
340 | + $error_code = ''; |
|
341 | + // process trace info |
|
342 | + if (empty($ex['trace'])) { |
|
343 | + $trace_details .= __('Sorry, but no trace information was available for this exception.', |
|
344 | + 'event_espresso'); |
|
345 | + } else { |
|
346 | + $trace_details .= ' |
|
347 | 347 | <div id="ee-trace-details"> |
348 | 348 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
349 | 349 | <tr> |
@@ -353,38 +353,38 @@ discard block |
||
353 | 353 | <th scope="col" align="left">Class</th> |
354 | 354 | <th scope="col" align="left">Method( arguments )</th> |
355 | 355 | </tr>'; |
356 | - $last_on_stack = count($ex['trace']) - 1; |
|
357 | - // reverse array so that stack is in proper chronological order |
|
358 | - $sorted_trace = array_reverse($ex['trace']); |
|
359 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
360 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
361 | - $class = isset($trace['class']) ? $trace['class'] : ''; |
|
362 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
363 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
364 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
365 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
366 | - $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
367 | - if (empty($file) && ! empty($class)) { |
|
368 | - $a = new ReflectionClass($class); |
|
369 | - $file = $a->getFileName(); |
|
370 | - if (empty($line) && ! empty($function)) { |
|
371 | - $b = new ReflectionMethod($class, $function); |
|
372 | - $line = $b->getStartLine(); |
|
373 | - } |
|
374 | - } |
|
375 | - if ($nmbr === $last_on_stack) { |
|
376 | - $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
377 | - $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
378 | - $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
379 | - } |
|
380 | - $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
381 | - $line_dsply = ! empty($line) ? $line : ' '; |
|
382 | - $file_dsply = ! empty($file) ? $file : ' '; |
|
383 | - $class_dsply = ! empty($class) ? $class : ' '; |
|
384 | - $type_dsply = ! empty($type) ? $type : ' '; |
|
385 | - $function_dsply = ! empty($function) ? $function : ' '; |
|
386 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
387 | - $trace_details .= ' |
|
356 | + $last_on_stack = count($ex['trace']) - 1; |
|
357 | + // reverse array so that stack is in proper chronological order |
|
358 | + $sorted_trace = array_reverse($ex['trace']); |
|
359 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
360 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
361 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
362 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
363 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
364 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
365 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
366 | + $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
367 | + if (empty($file) && ! empty($class)) { |
|
368 | + $a = new ReflectionClass($class); |
|
369 | + $file = $a->getFileName(); |
|
370 | + if (empty($line) && ! empty($function)) { |
|
371 | + $b = new ReflectionMethod($class, $function); |
|
372 | + $line = $b->getStartLine(); |
|
373 | + } |
|
374 | + } |
|
375 | + if ($nmbr === $last_on_stack) { |
|
376 | + $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
377 | + $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
378 | + $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
379 | + } |
|
380 | + $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
381 | + $line_dsply = ! empty($line) ? $line : ' '; |
|
382 | + $file_dsply = ! empty($file) ? $file : ' '; |
|
383 | + $class_dsply = ! empty($class) ? $class : ' '; |
|
384 | + $type_dsply = ! empty($type) ? $type : ' '; |
|
385 | + $function_dsply = ! empty($function) ? $function : ' '; |
|
386 | + $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
387 | + $trace_details .= ' |
|
388 | 388 | <tr> |
389 | 389 | <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
390 | 390 | <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
@@ -392,669 +392,669 @@ discard block |
||
392 | 392 | <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
393 | 393 | <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
394 | 394 | </tr>'; |
395 | - } |
|
396 | - $trace_details .= ' |
|
395 | + } |
|
396 | + $trace_details .= ' |
|
397 | 397 | </table> |
398 | 398 | </div>'; |
399 | - } |
|
400 | - $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
401 | - // add generic non-identifying messages for non-privileged users |
|
402 | - if (! WP_DEBUG) { |
|
403 | - $output .= '<span class="ee-error-user-msg-spn">' |
|
404 | - . trim($ex['msg']) |
|
405 | - . '</span> <sup>' |
|
406 | - . $ex['code'] |
|
407 | - . '</sup><br />'; |
|
408 | - } else { |
|
409 | - // or helpful developer messages if debugging is on |
|
410 | - $output .= ' |
|
399 | + } |
|
400 | + $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
401 | + // add generic non-identifying messages for non-privileged users |
|
402 | + if (! WP_DEBUG) { |
|
403 | + $output .= '<span class="ee-error-user-msg-spn">' |
|
404 | + . trim($ex['msg']) |
|
405 | + . '</span> <sup>' |
|
406 | + . $ex['code'] |
|
407 | + . '</sup><br />'; |
|
408 | + } else { |
|
409 | + // or helpful developer messages if debugging is on |
|
410 | + $output .= ' |
|
411 | 411 | <div class="ee-error-dev-msg-dv"> |
412 | 412 | <p class="ee-error-dev-msg-pg"> |
413 | 413 | <strong class="ee-error-dev-msg-str">An ' |
414 | - . $ex['name'] |
|
415 | - . ' exception was thrown!</strong> <span>code: ' |
|
416 | - . $ex['code'] |
|
417 | - . '</span><br /> |
|
414 | + . $ex['name'] |
|
415 | + . ' exception was thrown!</strong> <span>code: ' |
|
416 | + . $ex['code'] |
|
417 | + . '</span><br /> |
|
418 | 418 | <span class="big-text">"' |
419 | - . trim($ex['msg']) |
|
420 | - . '"</span><br/> |
|
419 | + . trim($ex['msg']) |
|
420 | + . '"</span><br/> |
|
421 | 421 | <a id="display-ee-error-trace-' |
422 | - . self::$_error_count |
|
423 | - . $time |
|
424 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
425 | - . self::$_error_count |
|
426 | - . $time |
|
427 | - . '"> |
|
422 | + . self::$_error_count |
|
423 | + . $time |
|
424 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
425 | + . self::$_error_count |
|
426 | + . $time |
|
427 | + . '"> |
|
428 | 428 | ' |
429 | - . __('click to view backtrace and class/method details', 'event_espresso') |
|
430 | - . ' |
|
429 | + . __('click to view backtrace and class/method details', 'event_espresso') |
|
430 | + . ' |
|
431 | 431 | </a><br /> |
432 | 432 | <span class="small-text lt-grey-text">' |
433 | - . $ex['file'] |
|
434 | - . ' ( line no: ' |
|
435 | - . $ex['line'] |
|
436 | - . ' )</span> |
|
433 | + . $ex['file'] |
|
434 | + . ' ( line no: ' |
|
435 | + . $ex['line'] |
|
436 | + . ' )</span> |
|
437 | 437 | </p> |
438 | 438 | <div id="ee-error-trace-' |
439 | - . self::$_error_count |
|
440 | - . $time |
|
441 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
439 | + . self::$_error_count |
|
440 | + . $time |
|
441 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
442 | 442 | ' |
443 | - . $trace_details; |
|
444 | - if (! empty($class)) { |
|
445 | - $output .= ' |
|
443 | + . $trace_details; |
|
444 | + if (! empty($class)) { |
|
445 | + $output .= ' |
|
446 | 446 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
447 | 447 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
448 | 448 | <h3>Class Details</h3>'; |
449 | - $a = new ReflectionClass($class); |
|
450 | - $output .= ' |
|
449 | + $a = new ReflectionClass($class); |
|
450 | + $output .= ' |
|
451 | 451 | <pre>' . $a . '</pre> |
452 | 452 | </div> |
453 | 453 | </div>'; |
454 | - } |
|
455 | - $output .= ' |
|
454 | + } |
|
455 | + $output .= ' |
|
456 | 456 | </div> |
457 | 457 | </div> |
458 | 458 | <br />'; |
459 | - } |
|
460 | - $this->write_to_error_log($time, $ex); |
|
461 | - } |
|
462 | - // remove last linebreak |
|
463 | - $output = substr($output, 0, -6); |
|
464 | - if (! WP_DEBUG) { |
|
465 | - $output .= ' |
|
459 | + } |
|
460 | + $this->write_to_error_log($time, $ex); |
|
461 | + } |
|
462 | + // remove last linebreak |
|
463 | + $output = substr($output, 0, -6); |
|
464 | + if (! WP_DEBUG) { |
|
465 | + $output .= ' |
|
466 | 466 | </p>'; |
467 | - } |
|
468 | - $output .= ' |
|
467 | + } |
|
468 | + $output .= ' |
|
469 | 469 | </div>'; |
470 | - $output .= self::_print_scripts(true); |
|
471 | - if (defined('DOING_AJAX')) { |
|
472 | - echo wp_json_encode(array('error' => $output)); |
|
473 | - exit(); |
|
474 | - } |
|
475 | - echo $output; |
|
476 | - die(); |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * generate string from exception trace args |
|
483 | - * |
|
484 | - * @param array $arguments |
|
485 | - * @param bool $array |
|
486 | - * @return string |
|
487 | - */ |
|
488 | - private function _convert_args_to_string($arguments = array(), $array = false) |
|
489 | - { |
|
490 | - $arg_string = ''; |
|
491 | - if (! empty($arguments)) { |
|
492 | - $args = array(); |
|
493 | - foreach ($arguments as $arg) { |
|
494 | - if (! empty($arg)) { |
|
495 | - if (is_string($arg)) { |
|
496 | - $args[] = " '" . $arg . "'"; |
|
497 | - } elseif (is_array($arg)) { |
|
498 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
499 | - } elseif ($arg === null) { |
|
500 | - $args[] = ' NULL'; |
|
501 | - } elseif (is_bool($arg)) { |
|
502 | - $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
503 | - } elseif (is_object($arg)) { |
|
504 | - $args[] = ' OBJECT ' . get_class($arg); |
|
505 | - } elseif (is_resource($arg)) { |
|
506 | - $args[] = get_resource_type($arg); |
|
507 | - } else { |
|
508 | - $args[] = $arg; |
|
509 | - } |
|
510 | - } |
|
511 | - } |
|
512 | - $arg_string = implode(', ', $args); |
|
513 | - } |
|
514 | - if ($array) { |
|
515 | - $arg_string .= ' )'; |
|
516 | - } |
|
517 | - return $arg_string; |
|
518 | - } |
|
519 | - |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * add error message |
|
524 | - * |
|
525 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
526 | - * separate messages for user || dev |
|
527 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
528 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
529 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
530 | - * @return void |
|
531 | - */ |
|
532 | - public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
533 | - { |
|
534 | - self::_add_notice('errors', $msg, $file, $func, $line); |
|
535 | - self::$_error_count++; |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
542 | - * adds an error |
|
543 | - * |
|
544 | - * @param string $msg |
|
545 | - * @param string $file |
|
546 | - * @param string $func |
|
547 | - * @param string $line |
|
548 | - * @throws EE_Error |
|
549 | - */ |
|
550 | - public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
551 | - { |
|
552 | - if (WP_DEBUG) { |
|
553 | - throw new EE_Error($msg); |
|
554 | - } |
|
555 | - EE_Error::add_error($msg, $file, $func, $line); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - |
|
560 | - /** |
|
561 | - * add success message |
|
562 | - * |
|
563 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
564 | - * separate messages for user || dev |
|
565 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
566 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
567 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
568 | - * @return void |
|
569 | - */ |
|
570 | - public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
571 | - { |
|
572 | - self::_add_notice('success', $msg, $file, $func, $line); |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * add attention message |
|
579 | - * |
|
580 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
581 | - * separate messages for user || dev |
|
582 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
583 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
584 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
585 | - * @return void |
|
586 | - */ |
|
587 | - public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
588 | - { |
|
589 | - self::_add_notice('attention', $msg, $file, $func, $line); |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * add success message |
|
596 | - * |
|
597 | - * @param string $type whether the message is for a success or error notification |
|
598 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
599 | - * separate messages for user || dev |
|
600 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
601 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
602 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
603 | - * @return void |
|
604 | - */ |
|
605 | - private static function _add_notice($type = 'success', $msg = null, $file = null, $func = null, $line = null) |
|
606 | - { |
|
607 | - if (empty($msg)) { |
|
608 | - EE_Error::doing_it_wrong( |
|
609 | - 'EE_Error::add_' . $type . '()', |
|
610 | - sprintf( |
|
611 | - __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
612 | - 'event_espresso'), |
|
613 | - $type, |
|
614 | - $file, |
|
615 | - $line |
|
616 | - ), |
|
617 | - EVENT_ESPRESSO_VERSION |
|
618 | - ); |
|
619 | - } |
|
620 | - if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
621 | - EE_Error::doing_it_wrong( |
|
622 | - 'EE_Error::add_error()', |
|
623 | - __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
624 | - 'event_espresso'), |
|
625 | - EVENT_ESPRESSO_VERSION |
|
626 | - ); |
|
627 | - } |
|
628 | - // get separate user and developer messages if they exist |
|
629 | - $msg = explode('||', $msg); |
|
630 | - $user_msg = $msg[0]; |
|
631 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
632 | - /** |
|
633 | - * Do an action so other code can be triggered when a notice is created |
|
634 | - * |
|
635 | - * @param string $type can be 'errors', 'attention', or 'success' |
|
636 | - * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
637 | - * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
638 | - * @param string $file file where error was generated |
|
639 | - * @param string $func function where error was generated |
|
640 | - * @param string $line line where error was generated |
|
641 | - */ |
|
642 | - do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
643 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
644 | - // add notice if message exists |
|
645 | - if (! empty($msg)) { |
|
646 | - // get error code |
|
647 | - $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
648 | - if (WP_DEBUG && $type === 'errors') { |
|
649 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
650 | - } |
|
651 | - // add notice. Index by code if it's not blank |
|
652 | - if ($notice_code) { |
|
653 | - self::$_espresso_notices[$type][$notice_code] = $msg; |
|
654 | - } else { |
|
655 | - self::$_espresso_notices[$type][] = $msg; |
|
656 | - } |
|
657 | - add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
658 | - } |
|
659 | - } |
|
660 | - |
|
661 | - |
|
662 | - |
|
663 | - /** |
|
664 | - * in some case it may be necessary to overwrite the existing success messages |
|
665 | - * |
|
666 | - * @return void |
|
667 | - */ |
|
668 | - public static function overwrite_success() |
|
669 | - { |
|
670 | - self::$_espresso_notices['success'] = false; |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - |
|
675 | - /** |
|
676 | - * in some case it may be necessary to overwrite the existing attention messages |
|
677 | - * |
|
678 | - * @return void |
|
679 | - */ |
|
680 | - public static function overwrite_attention() |
|
681 | - { |
|
682 | - self::$_espresso_notices['attention'] = false; |
|
683 | - } |
|
684 | - |
|
685 | - |
|
686 | - |
|
687 | - /** |
|
688 | - * in some case it may be necessary to overwrite the existing error messages |
|
689 | - * |
|
690 | - * @return void |
|
691 | - */ |
|
692 | - public static function overwrite_errors() |
|
693 | - { |
|
694 | - self::$_espresso_notices['errors'] = false; |
|
695 | - } |
|
696 | - |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * reset_notices |
|
701 | - * |
|
702 | - * @return void |
|
703 | - */ |
|
704 | - public static function reset_notices() |
|
705 | - { |
|
706 | - self::$_espresso_notices['success'] = false; |
|
707 | - self::$_espresso_notices['attention'] = false; |
|
708 | - self::$_espresso_notices['errors'] = false; |
|
709 | - } |
|
710 | - |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * has_errors |
|
715 | - * |
|
716 | - * @return int |
|
717 | - */ |
|
718 | - public static function has_notices() |
|
719 | - { |
|
720 | - $has_notices = 0; |
|
721 | - // check for success messages |
|
722 | - $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3 |
|
723 | - : $has_notices; |
|
724 | - // check for attention messages |
|
725 | - $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2 |
|
726 | - : $has_notices; |
|
727 | - // check for error messages |
|
728 | - $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1 |
|
729 | - : $has_notices; |
|
730 | - return $has_notices; |
|
731 | - } |
|
732 | - |
|
733 | - |
|
734 | - |
|
735 | - /** |
|
736 | - * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
737 | - * |
|
738 | - * @since 4.9.0 |
|
739 | - * @return array |
|
740 | - */ |
|
741 | - public static function get_vanilla_notices() |
|
742 | - { |
|
743 | - return array( |
|
744 | - 'success' => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(), |
|
745 | - 'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention'] |
|
746 | - : array(), |
|
747 | - 'errors' => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(), |
|
748 | - ); |
|
749 | - } |
|
750 | - |
|
751 | - |
|
752 | - |
|
753 | - /** |
|
754 | - * compile all error or success messages into one string |
|
755 | - * |
|
756 | - * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
757 | - * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
758 | - * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
759 | - * - ONLY do this just before redirecting |
|
760 | - * @param boolean $remove_empty whether or not to unset empty messages |
|
761 | - * @return array |
|
762 | - */ |
|
763 | - public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
764 | - { |
|
765 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
766 | - $success_messages = ''; |
|
767 | - $attention_messages = ''; |
|
768 | - $error_messages = ''; |
|
769 | - $print_scripts = false; |
|
770 | - // either save notices to the db |
|
771 | - if ($save_to_transient) { |
|
772 | - update_option('ee_notices', self::$_espresso_notices); |
|
773 | - return array(); |
|
774 | - } |
|
775 | - // grab any notices that have been previously saved |
|
776 | - if ($notices = get_option('ee_notices', false)) { |
|
777 | - foreach ($notices as $type => $notice) { |
|
778 | - if (is_array($notice) && ! empty($notice)) { |
|
779 | - // make sure that existing notice type is an array |
|
780 | - self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
781 | - && ! empty(self::$_espresso_notices[$type]) |
|
782 | - ? self::$_espresso_notices[$type] : array(); |
|
783 | - // merge stored notices with any newly created ones |
|
784 | - self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
785 | - $print_scripts = true; |
|
786 | - } |
|
787 | - } |
|
788 | - // now clear any stored notices |
|
789 | - update_option('ee_notices', false); |
|
790 | - } |
|
791 | - // check for success messages |
|
792 | - if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
793 | - // combine messages |
|
794 | - $success_messages .= implode(self::$_espresso_notices['success'], '<br /><br />'); |
|
795 | - $print_scripts = true; |
|
796 | - } |
|
797 | - // check for attention messages |
|
798 | - if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
799 | - // combine messages |
|
800 | - $attention_messages .= implode(self::$_espresso_notices['attention'], '<br /><br />'); |
|
801 | - $print_scripts = true; |
|
802 | - } |
|
803 | - // check for error messages |
|
804 | - if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
805 | - $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
806 | - ? __('The following errors have occurred:<br />', 'event_espresso') |
|
807 | - : __('An error has occurred:<br />', 'event_espresso'); |
|
808 | - // combine messages |
|
809 | - $error_messages .= implode(self::$_espresso_notices['errors'], '<br /><br />'); |
|
810 | - $print_scripts = true; |
|
811 | - } |
|
812 | - if ($format_output) { |
|
813 | - $notices = '<div id="espresso-notices">'; |
|
814 | - $close = is_admin() ? '' |
|
815 | - : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>'; |
|
816 | - if ($success_messages !== '') { |
|
817 | - $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
|
818 | - $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
819 | - //showMessage( $success_messages ); |
|
820 | - $notices .= '<div id="' |
|
821 | - . $css_id |
|
822 | - . '" class="espresso-notices ' |
|
823 | - . $css_class |
|
824 | - . '" style="display:none;"><p>' |
|
825 | - . $success_messages |
|
826 | - . '</p>' |
|
827 | - . $close |
|
828 | - . '</div>'; |
|
829 | - } |
|
830 | - if ($attention_messages !== '') { |
|
831 | - $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
|
832 | - $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
833 | - //showMessage( $error_messages, TRUE ); |
|
834 | - $notices .= '<div id="' |
|
835 | - . $css_id |
|
836 | - . '" class="espresso-notices ' |
|
837 | - . $css_class |
|
838 | - . '" style="display:none;"><p>' |
|
839 | - . $attention_messages |
|
840 | - . '</p>' |
|
841 | - . $close |
|
842 | - . '</div>'; |
|
843 | - } |
|
844 | - if ($error_messages !== '') { |
|
845 | - $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
|
846 | - $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
847 | - //showMessage( $error_messages, TRUE ); |
|
848 | - $notices .= '<div id="' |
|
849 | - . $css_id |
|
850 | - . '" class="espresso-notices ' |
|
851 | - . $css_class |
|
852 | - . '" style="display:none;"><p>' |
|
853 | - . $error_messages |
|
854 | - . '</p>' |
|
855 | - . $close |
|
856 | - . '</div>'; |
|
857 | - } |
|
858 | - $notices .= '</div>'; |
|
859 | - } else { |
|
860 | - $notices = array( |
|
861 | - 'success' => $success_messages, |
|
862 | - 'attention' => $attention_messages, |
|
863 | - 'errors' => $error_messages, |
|
864 | - ); |
|
865 | - if ($remove_empty) { |
|
866 | - // remove empty notices |
|
867 | - foreach ($notices as $type => $notice) { |
|
868 | - if (empty($notice)) { |
|
869 | - unset($notices[$type]); |
|
870 | - } |
|
871 | - } |
|
872 | - } |
|
873 | - } |
|
874 | - if ($print_scripts) { |
|
875 | - self::_print_scripts(); |
|
876 | - } |
|
877 | - return $notices; |
|
878 | - } |
|
879 | - |
|
880 | - |
|
881 | - |
|
882 | - /** |
|
883 | - * add_persistent_admin_notice |
|
884 | - * |
|
885 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
886 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
887 | - * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
888 | - * @return void |
|
889 | - */ |
|
890 | - public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
891 | - { |
|
892 | - if (! empty($pan_name) && ! empty($pan_message)) { |
|
893 | - $persistent_admin_notices = get_option('ee_pers_admin_notices', array()); |
|
894 | - //maybe initialize persistent_admin_notices |
|
895 | - if (empty($persistent_admin_notices)) { |
|
896 | - add_option('ee_pers_admin_notices', array(), '', 'no'); |
|
897 | - } |
|
898 | - $pan_name = sanitize_key($pan_name); |
|
899 | - if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) { |
|
900 | - $persistent_admin_notices[$pan_name] = $pan_message; |
|
901 | - update_option('ee_pers_admin_notices', $persistent_admin_notices); |
|
902 | - } |
|
903 | - } |
|
904 | - } |
|
905 | - |
|
906 | - |
|
907 | - |
|
908 | - /** |
|
909 | - * dismiss_persistent_admin_notice |
|
910 | - * |
|
911 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
912 | - * @param bool $purge |
|
913 | - * @param bool $return_immediately |
|
914 | - * @return void |
|
915 | - */ |
|
916 | - public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return_immediately = false) |
|
917 | - { |
|
918 | - $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice') |
|
919 | - ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name; |
|
920 | - if (! empty($pan_name)) { |
|
921 | - $persistent_admin_notices = get_option('ee_pers_admin_notices', array()); |
|
922 | - // check if notice we wish to dismiss is actually in the $persistent_admin_notices array |
|
923 | - if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) { |
|
924 | - // completely delete nag notice, or just NULL message so that it can NOT be added again ? |
|
925 | - if ($purge) { |
|
926 | - unset($persistent_admin_notices[$pan_name]); |
|
927 | - } else { |
|
928 | - $persistent_admin_notices[$pan_name] = null; |
|
929 | - } |
|
930 | - if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === false) { |
|
931 | - EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.', |
|
932 | - 'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__); |
|
933 | - } |
|
934 | - } |
|
935 | - } |
|
936 | - if ($return_immediately) { |
|
937 | - return; |
|
938 | - } |
|
939 | - if (EE_Registry::instance()->REQ->ajax) { |
|
940 | - // grab any notices and concatenate into string |
|
941 | - echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(false)))); |
|
942 | - exit(); |
|
943 | - } |
|
944 | - // save errors to a transient to be displayed on next request (after redirect) |
|
945 | - EE_Error::get_notices(false, true); |
|
946 | - $return_url = EE_Registry::instance()->REQ->is_set('return_url') |
|
947 | - ? EE_Registry::instance()->REQ->get('return_url') : ''; |
|
948 | - wp_safe_redirect(urldecode($return_url)); |
|
949 | - } |
|
950 | - |
|
951 | - |
|
952 | - |
|
953 | - /** |
|
954 | - * display_persistent_admin_notices |
|
955 | - * |
|
956 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
957 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
958 | - * @param string $return_url URL to go back to after nag notice is dismissed |
|
959 | - * @return string |
|
960 | - */ |
|
961 | - public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
962 | - { |
|
963 | - if (! empty($pan_name) && ! empty($pan_message)) { |
|
964 | - $args = array( |
|
965 | - 'nag_notice' => $pan_name, |
|
966 | - 'return_url' => urlencode($return_url), |
|
967 | - 'ajax_url' => WP_AJAX_URL, |
|
968 | - 'unknown_error' => __('An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
969 | - 'event_espresso'), |
|
970 | - ); |
|
971 | - wp_localize_script('espresso_core', 'ee_dismiss', $args); |
|
972 | - return ' |
|
470 | + $output .= self::_print_scripts(true); |
|
471 | + if (defined('DOING_AJAX')) { |
|
472 | + echo wp_json_encode(array('error' => $output)); |
|
473 | + exit(); |
|
474 | + } |
|
475 | + echo $output; |
|
476 | + die(); |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * generate string from exception trace args |
|
483 | + * |
|
484 | + * @param array $arguments |
|
485 | + * @param bool $array |
|
486 | + * @return string |
|
487 | + */ |
|
488 | + private function _convert_args_to_string($arguments = array(), $array = false) |
|
489 | + { |
|
490 | + $arg_string = ''; |
|
491 | + if (! empty($arguments)) { |
|
492 | + $args = array(); |
|
493 | + foreach ($arguments as $arg) { |
|
494 | + if (! empty($arg)) { |
|
495 | + if (is_string($arg)) { |
|
496 | + $args[] = " '" . $arg . "'"; |
|
497 | + } elseif (is_array($arg)) { |
|
498 | + $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
499 | + } elseif ($arg === null) { |
|
500 | + $args[] = ' NULL'; |
|
501 | + } elseif (is_bool($arg)) { |
|
502 | + $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
503 | + } elseif (is_object($arg)) { |
|
504 | + $args[] = ' OBJECT ' . get_class($arg); |
|
505 | + } elseif (is_resource($arg)) { |
|
506 | + $args[] = get_resource_type($arg); |
|
507 | + } else { |
|
508 | + $args[] = $arg; |
|
509 | + } |
|
510 | + } |
|
511 | + } |
|
512 | + $arg_string = implode(', ', $args); |
|
513 | + } |
|
514 | + if ($array) { |
|
515 | + $arg_string .= ' )'; |
|
516 | + } |
|
517 | + return $arg_string; |
|
518 | + } |
|
519 | + |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * add error message |
|
524 | + * |
|
525 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
526 | + * separate messages for user || dev |
|
527 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
528 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
529 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
530 | + * @return void |
|
531 | + */ |
|
532 | + public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
533 | + { |
|
534 | + self::_add_notice('errors', $msg, $file, $func, $line); |
|
535 | + self::$_error_count++; |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
542 | + * adds an error |
|
543 | + * |
|
544 | + * @param string $msg |
|
545 | + * @param string $file |
|
546 | + * @param string $func |
|
547 | + * @param string $line |
|
548 | + * @throws EE_Error |
|
549 | + */ |
|
550 | + public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
551 | + { |
|
552 | + if (WP_DEBUG) { |
|
553 | + throw new EE_Error($msg); |
|
554 | + } |
|
555 | + EE_Error::add_error($msg, $file, $func, $line); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + |
|
560 | + /** |
|
561 | + * add success message |
|
562 | + * |
|
563 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
564 | + * separate messages for user || dev |
|
565 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
566 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
567 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
568 | + * @return void |
|
569 | + */ |
|
570 | + public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
571 | + { |
|
572 | + self::_add_notice('success', $msg, $file, $func, $line); |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * add attention message |
|
579 | + * |
|
580 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
581 | + * separate messages for user || dev |
|
582 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
583 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
584 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
585 | + * @return void |
|
586 | + */ |
|
587 | + public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
588 | + { |
|
589 | + self::_add_notice('attention', $msg, $file, $func, $line); |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * add success message |
|
596 | + * |
|
597 | + * @param string $type whether the message is for a success or error notification |
|
598 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
599 | + * separate messages for user || dev |
|
600 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
601 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
602 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
603 | + * @return void |
|
604 | + */ |
|
605 | + private static function _add_notice($type = 'success', $msg = null, $file = null, $func = null, $line = null) |
|
606 | + { |
|
607 | + if (empty($msg)) { |
|
608 | + EE_Error::doing_it_wrong( |
|
609 | + 'EE_Error::add_' . $type . '()', |
|
610 | + sprintf( |
|
611 | + __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
612 | + 'event_espresso'), |
|
613 | + $type, |
|
614 | + $file, |
|
615 | + $line |
|
616 | + ), |
|
617 | + EVENT_ESPRESSO_VERSION |
|
618 | + ); |
|
619 | + } |
|
620 | + if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
621 | + EE_Error::doing_it_wrong( |
|
622 | + 'EE_Error::add_error()', |
|
623 | + __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
624 | + 'event_espresso'), |
|
625 | + EVENT_ESPRESSO_VERSION |
|
626 | + ); |
|
627 | + } |
|
628 | + // get separate user and developer messages if they exist |
|
629 | + $msg = explode('||', $msg); |
|
630 | + $user_msg = $msg[0]; |
|
631 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
632 | + /** |
|
633 | + * Do an action so other code can be triggered when a notice is created |
|
634 | + * |
|
635 | + * @param string $type can be 'errors', 'attention', or 'success' |
|
636 | + * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
637 | + * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
638 | + * @param string $file file where error was generated |
|
639 | + * @param string $func function where error was generated |
|
640 | + * @param string $line line where error was generated |
|
641 | + */ |
|
642 | + do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
643 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
644 | + // add notice if message exists |
|
645 | + if (! empty($msg)) { |
|
646 | + // get error code |
|
647 | + $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
648 | + if (WP_DEBUG && $type === 'errors') { |
|
649 | + $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
650 | + } |
|
651 | + // add notice. Index by code if it's not blank |
|
652 | + if ($notice_code) { |
|
653 | + self::$_espresso_notices[$type][$notice_code] = $msg; |
|
654 | + } else { |
|
655 | + self::$_espresso_notices[$type][] = $msg; |
|
656 | + } |
|
657 | + add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
658 | + } |
|
659 | + } |
|
660 | + |
|
661 | + |
|
662 | + |
|
663 | + /** |
|
664 | + * in some case it may be necessary to overwrite the existing success messages |
|
665 | + * |
|
666 | + * @return void |
|
667 | + */ |
|
668 | + public static function overwrite_success() |
|
669 | + { |
|
670 | + self::$_espresso_notices['success'] = false; |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + |
|
675 | + /** |
|
676 | + * in some case it may be necessary to overwrite the existing attention messages |
|
677 | + * |
|
678 | + * @return void |
|
679 | + */ |
|
680 | + public static function overwrite_attention() |
|
681 | + { |
|
682 | + self::$_espresso_notices['attention'] = false; |
|
683 | + } |
|
684 | + |
|
685 | + |
|
686 | + |
|
687 | + /** |
|
688 | + * in some case it may be necessary to overwrite the existing error messages |
|
689 | + * |
|
690 | + * @return void |
|
691 | + */ |
|
692 | + public static function overwrite_errors() |
|
693 | + { |
|
694 | + self::$_espresso_notices['errors'] = false; |
|
695 | + } |
|
696 | + |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * reset_notices |
|
701 | + * |
|
702 | + * @return void |
|
703 | + */ |
|
704 | + public static function reset_notices() |
|
705 | + { |
|
706 | + self::$_espresso_notices['success'] = false; |
|
707 | + self::$_espresso_notices['attention'] = false; |
|
708 | + self::$_espresso_notices['errors'] = false; |
|
709 | + } |
|
710 | + |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * has_errors |
|
715 | + * |
|
716 | + * @return int |
|
717 | + */ |
|
718 | + public static function has_notices() |
|
719 | + { |
|
720 | + $has_notices = 0; |
|
721 | + // check for success messages |
|
722 | + $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3 |
|
723 | + : $has_notices; |
|
724 | + // check for attention messages |
|
725 | + $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2 |
|
726 | + : $has_notices; |
|
727 | + // check for error messages |
|
728 | + $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1 |
|
729 | + : $has_notices; |
|
730 | + return $has_notices; |
|
731 | + } |
|
732 | + |
|
733 | + |
|
734 | + |
|
735 | + /** |
|
736 | + * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
737 | + * |
|
738 | + * @since 4.9.0 |
|
739 | + * @return array |
|
740 | + */ |
|
741 | + public static function get_vanilla_notices() |
|
742 | + { |
|
743 | + return array( |
|
744 | + 'success' => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(), |
|
745 | + 'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention'] |
|
746 | + : array(), |
|
747 | + 'errors' => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(), |
|
748 | + ); |
|
749 | + } |
|
750 | + |
|
751 | + |
|
752 | + |
|
753 | + /** |
|
754 | + * compile all error or success messages into one string |
|
755 | + * |
|
756 | + * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
757 | + * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
758 | + * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
759 | + * - ONLY do this just before redirecting |
|
760 | + * @param boolean $remove_empty whether or not to unset empty messages |
|
761 | + * @return array |
|
762 | + */ |
|
763 | + public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
764 | + { |
|
765 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
766 | + $success_messages = ''; |
|
767 | + $attention_messages = ''; |
|
768 | + $error_messages = ''; |
|
769 | + $print_scripts = false; |
|
770 | + // either save notices to the db |
|
771 | + if ($save_to_transient) { |
|
772 | + update_option('ee_notices', self::$_espresso_notices); |
|
773 | + return array(); |
|
774 | + } |
|
775 | + // grab any notices that have been previously saved |
|
776 | + if ($notices = get_option('ee_notices', false)) { |
|
777 | + foreach ($notices as $type => $notice) { |
|
778 | + if (is_array($notice) && ! empty($notice)) { |
|
779 | + // make sure that existing notice type is an array |
|
780 | + self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
781 | + && ! empty(self::$_espresso_notices[$type]) |
|
782 | + ? self::$_espresso_notices[$type] : array(); |
|
783 | + // merge stored notices with any newly created ones |
|
784 | + self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
785 | + $print_scripts = true; |
|
786 | + } |
|
787 | + } |
|
788 | + // now clear any stored notices |
|
789 | + update_option('ee_notices', false); |
|
790 | + } |
|
791 | + // check for success messages |
|
792 | + if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
793 | + // combine messages |
|
794 | + $success_messages .= implode(self::$_espresso_notices['success'], '<br /><br />'); |
|
795 | + $print_scripts = true; |
|
796 | + } |
|
797 | + // check for attention messages |
|
798 | + if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
799 | + // combine messages |
|
800 | + $attention_messages .= implode(self::$_espresso_notices['attention'], '<br /><br />'); |
|
801 | + $print_scripts = true; |
|
802 | + } |
|
803 | + // check for error messages |
|
804 | + if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
805 | + $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
806 | + ? __('The following errors have occurred:<br />', 'event_espresso') |
|
807 | + : __('An error has occurred:<br />', 'event_espresso'); |
|
808 | + // combine messages |
|
809 | + $error_messages .= implode(self::$_espresso_notices['errors'], '<br /><br />'); |
|
810 | + $print_scripts = true; |
|
811 | + } |
|
812 | + if ($format_output) { |
|
813 | + $notices = '<div id="espresso-notices">'; |
|
814 | + $close = is_admin() ? '' |
|
815 | + : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>'; |
|
816 | + if ($success_messages !== '') { |
|
817 | + $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
|
818 | + $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
819 | + //showMessage( $success_messages ); |
|
820 | + $notices .= '<div id="' |
|
821 | + . $css_id |
|
822 | + . '" class="espresso-notices ' |
|
823 | + . $css_class |
|
824 | + . '" style="display:none;"><p>' |
|
825 | + . $success_messages |
|
826 | + . '</p>' |
|
827 | + . $close |
|
828 | + . '</div>'; |
|
829 | + } |
|
830 | + if ($attention_messages !== '') { |
|
831 | + $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
|
832 | + $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
833 | + //showMessage( $error_messages, TRUE ); |
|
834 | + $notices .= '<div id="' |
|
835 | + . $css_id |
|
836 | + . '" class="espresso-notices ' |
|
837 | + . $css_class |
|
838 | + . '" style="display:none;"><p>' |
|
839 | + . $attention_messages |
|
840 | + . '</p>' |
|
841 | + . $close |
|
842 | + . '</div>'; |
|
843 | + } |
|
844 | + if ($error_messages !== '') { |
|
845 | + $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
|
846 | + $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
847 | + //showMessage( $error_messages, TRUE ); |
|
848 | + $notices .= '<div id="' |
|
849 | + . $css_id |
|
850 | + . '" class="espresso-notices ' |
|
851 | + . $css_class |
|
852 | + . '" style="display:none;"><p>' |
|
853 | + . $error_messages |
|
854 | + . '</p>' |
|
855 | + . $close |
|
856 | + . '</div>'; |
|
857 | + } |
|
858 | + $notices .= '</div>'; |
|
859 | + } else { |
|
860 | + $notices = array( |
|
861 | + 'success' => $success_messages, |
|
862 | + 'attention' => $attention_messages, |
|
863 | + 'errors' => $error_messages, |
|
864 | + ); |
|
865 | + if ($remove_empty) { |
|
866 | + // remove empty notices |
|
867 | + foreach ($notices as $type => $notice) { |
|
868 | + if (empty($notice)) { |
|
869 | + unset($notices[$type]); |
|
870 | + } |
|
871 | + } |
|
872 | + } |
|
873 | + } |
|
874 | + if ($print_scripts) { |
|
875 | + self::_print_scripts(); |
|
876 | + } |
|
877 | + return $notices; |
|
878 | + } |
|
879 | + |
|
880 | + |
|
881 | + |
|
882 | + /** |
|
883 | + * add_persistent_admin_notice |
|
884 | + * |
|
885 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
886 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
887 | + * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
888 | + * @return void |
|
889 | + */ |
|
890 | + public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
891 | + { |
|
892 | + if (! empty($pan_name) && ! empty($pan_message)) { |
|
893 | + $persistent_admin_notices = get_option('ee_pers_admin_notices', array()); |
|
894 | + //maybe initialize persistent_admin_notices |
|
895 | + if (empty($persistent_admin_notices)) { |
|
896 | + add_option('ee_pers_admin_notices', array(), '', 'no'); |
|
897 | + } |
|
898 | + $pan_name = sanitize_key($pan_name); |
|
899 | + if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) { |
|
900 | + $persistent_admin_notices[$pan_name] = $pan_message; |
|
901 | + update_option('ee_pers_admin_notices', $persistent_admin_notices); |
|
902 | + } |
|
903 | + } |
|
904 | + } |
|
905 | + |
|
906 | + |
|
907 | + |
|
908 | + /** |
|
909 | + * dismiss_persistent_admin_notice |
|
910 | + * |
|
911 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
912 | + * @param bool $purge |
|
913 | + * @param bool $return_immediately |
|
914 | + * @return void |
|
915 | + */ |
|
916 | + public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return_immediately = false) |
|
917 | + { |
|
918 | + $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice') |
|
919 | + ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name; |
|
920 | + if (! empty($pan_name)) { |
|
921 | + $persistent_admin_notices = get_option('ee_pers_admin_notices', array()); |
|
922 | + // check if notice we wish to dismiss is actually in the $persistent_admin_notices array |
|
923 | + if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) { |
|
924 | + // completely delete nag notice, or just NULL message so that it can NOT be added again ? |
|
925 | + if ($purge) { |
|
926 | + unset($persistent_admin_notices[$pan_name]); |
|
927 | + } else { |
|
928 | + $persistent_admin_notices[$pan_name] = null; |
|
929 | + } |
|
930 | + if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === false) { |
|
931 | + EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.', |
|
932 | + 'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__); |
|
933 | + } |
|
934 | + } |
|
935 | + } |
|
936 | + if ($return_immediately) { |
|
937 | + return; |
|
938 | + } |
|
939 | + if (EE_Registry::instance()->REQ->ajax) { |
|
940 | + // grab any notices and concatenate into string |
|
941 | + echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(false)))); |
|
942 | + exit(); |
|
943 | + } |
|
944 | + // save errors to a transient to be displayed on next request (after redirect) |
|
945 | + EE_Error::get_notices(false, true); |
|
946 | + $return_url = EE_Registry::instance()->REQ->is_set('return_url') |
|
947 | + ? EE_Registry::instance()->REQ->get('return_url') : ''; |
|
948 | + wp_safe_redirect(urldecode($return_url)); |
|
949 | + } |
|
950 | + |
|
951 | + |
|
952 | + |
|
953 | + /** |
|
954 | + * display_persistent_admin_notices |
|
955 | + * |
|
956 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
957 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
958 | + * @param string $return_url URL to go back to after nag notice is dismissed |
|
959 | + * @return string |
|
960 | + */ |
|
961 | + public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
962 | + { |
|
963 | + if (! empty($pan_name) && ! empty($pan_message)) { |
|
964 | + $args = array( |
|
965 | + 'nag_notice' => $pan_name, |
|
966 | + 'return_url' => urlencode($return_url), |
|
967 | + 'ajax_url' => WP_AJAX_URL, |
|
968 | + 'unknown_error' => __('An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
969 | + 'event_espresso'), |
|
970 | + ); |
|
971 | + wp_localize_script('espresso_core', 'ee_dismiss', $args); |
|
972 | + return ' |
|
973 | 973 | <div id="' |
974 | - . $pan_name |
|
975 | - . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;"> |
|
974 | + . $pan_name |
|
975 | + . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;"> |
|
976 | 976 | <p>' |
977 | - . $pan_message |
|
978 | - . '</p> |
|
977 | + . $pan_message |
|
978 | + . '</p> |
|
979 | 979 | <a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="' |
980 | - . $pan_name |
|
981 | - . '"> |
|
980 | + . $pan_name |
|
981 | + . '"> |
|
982 | 982 | <span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>' |
983 | - . __('Dismiss', 'event_espresso') |
|
984 | - . ' |
|
983 | + . __('Dismiss', 'event_espresso') |
|
984 | + . ' |
|
985 | 985 | </a> |
986 | 986 | <div style="clear:both;"></div> |
987 | 987 | </div>'; |
988 | - } |
|
989 | - return ''; |
|
990 | - } |
|
991 | - |
|
992 | - |
|
993 | - |
|
994 | - /** |
|
995 | - * get_persistent_admin_notices |
|
996 | - * |
|
997 | - * @param string $return_url |
|
998 | - * @return string |
|
999 | - */ |
|
1000 | - public static function get_persistent_admin_notices($return_url = '') |
|
1001 | - { |
|
1002 | - $notices = ''; |
|
1003 | - // check for persistent admin notices |
|
1004 | - //filter the list though so plugins can notify the admin in a different way if they want |
|
1005 | - $persistent_admin_notices = apply_filters( |
|
1006 | - 'FHEE__EE_Error__get_persistent_admin_notices', |
|
1007 | - get_option('ee_pers_admin_notices', false), |
|
1008 | - 'ee_pers_admin_notices', |
|
1009 | - $return_url |
|
1010 | - ); |
|
1011 | - if ($persistent_admin_notices) { |
|
1012 | - // load scripts |
|
1013 | - wp_register_script( |
|
1014 | - 'espresso_core', |
|
1015 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1016 | - array('jquery'), |
|
1017 | - EVENT_ESPRESSO_VERSION, |
|
1018 | - true |
|
1019 | - ); |
|
1020 | - wp_register_script( |
|
1021 | - 'ee_error_js', |
|
1022 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1023 | - array('espresso_core'), |
|
1024 | - EVENT_ESPRESSO_VERSION, |
|
1025 | - true |
|
1026 | - ); |
|
1027 | - wp_enqueue_script('ee_error_js'); |
|
1028 | - // and display notices |
|
1029 | - foreach ($persistent_admin_notices as $pan_name => $pan_message) { |
|
1030 | - $notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url); |
|
1031 | - } |
|
1032 | - } |
|
1033 | - return $notices; |
|
1034 | - } |
|
1035 | - |
|
1036 | - |
|
1037 | - |
|
1038 | - /** |
|
1039 | - * _print_scripts |
|
1040 | - * |
|
1041 | - * @param bool $force_print |
|
1042 | - * @return string |
|
1043 | - */ |
|
1044 | - private static function _print_scripts($force_print = false) |
|
1045 | - { |
|
1046 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
1047 | - if (wp_script_is('ee_error_js', 'enqueued')) { |
|
1048 | - return ''; |
|
1049 | - } |
|
1050 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
1051 | - wp_enqueue_style('espresso_default'); |
|
1052 | - wp_enqueue_style('espresso_custom_css'); |
|
1053 | - wp_enqueue_script('ee_error_js'); |
|
1054 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
1055 | - } |
|
1056 | - } else { |
|
1057 | - return ' |
|
988 | + } |
|
989 | + return ''; |
|
990 | + } |
|
991 | + |
|
992 | + |
|
993 | + |
|
994 | + /** |
|
995 | + * get_persistent_admin_notices |
|
996 | + * |
|
997 | + * @param string $return_url |
|
998 | + * @return string |
|
999 | + */ |
|
1000 | + public static function get_persistent_admin_notices($return_url = '') |
|
1001 | + { |
|
1002 | + $notices = ''; |
|
1003 | + // check for persistent admin notices |
|
1004 | + //filter the list though so plugins can notify the admin in a different way if they want |
|
1005 | + $persistent_admin_notices = apply_filters( |
|
1006 | + 'FHEE__EE_Error__get_persistent_admin_notices', |
|
1007 | + get_option('ee_pers_admin_notices', false), |
|
1008 | + 'ee_pers_admin_notices', |
|
1009 | + $return_url |
|
1010 | + ); |
|
1011 | + if ($persistent_admin_notices) { |
|
1012 | + // load scripts |
|
1013 | + wp_register_script( |
|
1014 | + 'espresso_core', |
|
1015 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1016 | + array('jquery'), |
|
1017 | + EVENT_ESPRESSO_VERSION, |
|
1018 | + true |
|
1019 | + ); |
|
1020 | + wp_register_script( |
|
1021 | + 'ee_error_js', |
|
1022 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1023 | + array('espresso_core'), |
|
1024 | + EVENT_ESPRESSO_VERSION, |
|
1025 | + true |
|
1026 | + ); |
|
1027 | + wp_enqueue_script('ee_error_js'); |
|
1028 | + // and display notices |
|
1029 | + foreach ($persistent_admin_notices as $pan_name => $pan_message) { |
|
1030 | + $notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url); |
|
1031 | + } |
|
1032 | + } |
|
1033 | + return $notices; |
|
1034 | + } |
|
1035 | + |
|
1036 | + |
|
1037 | + |
|
1038 | + /** |
|
1039 | + * _print_scripts |
|
1040 | + * |
|
1041 | + * @param bool $force_print |
|
1042 | + * @return string |
|
1043 | + */ |
|
1044 | + private static function _print_scripts($force_print = false) |
|
1045 | + { |
|
1046 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
1047 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
1048 | + return ''; |
|
1049 | + } |
|
1050 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
1051 | + wp_enqueue_style('espresso_default'); |
|
1052 | + wp_enqueue_style('espresso_custom_css'); |
|
1053 | + wp_enqueue_script('ee_error_js'); |
|
1054 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
1055 | + } |
|
1056 | + } else { |
|
1057 | + return ' |
|
1058 | 1058 | <script> |
1059 | 1059 | /* <![CDATA[ */ |
1060 | 1060 | var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -1064,143 +1064,143 @@ discard block |
||
1064 | 1064 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
1065 | 1065 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
1066 | 1066 | '; |
1067 | - } |
|
1068 | - return ''; |
|
1069 | - } |
|
1070 | - |
|
1071 | - |
|
1072 | - |
|
1073 | - /** |
|
1074 | - * enqueue_error_scripts |
|
1075 | - * |
|
1076 | - * @return void |
|
1077 | - */ |
|
1078 | - public static function enqueue_error_scripts() |
|
1079 | - { |
|
1080 | - self::_print_scripts(); |
|
1081 | - } |
|
1082 | - |
|
1083 | - |
|
1084 | - |
|
1085 | - /** |
|
1086 | - * create error code from filepath, function name, |
|
1087 | - * and line number where exception or error was thrown |
|
1088 | - * |
|
1089 | - * @param string $file |
|
1090 | - * @param string $func |
|
1091 | - * @param string $line |
|
1092 | - * @return string |
|
1093 | - */ |
|
1094 | - public static function generate_error_code($file = '', $func = '', $line = '') |
|
1095 | - { |
|
1096 | - $file = explode('.', basename($file)); |
|
1097 | - $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
1098 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
1099 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
1100 | - return $error_code; |
|
1101 | - } |
|
1102 | - |
|
1103 | - |
|
1104 | - |
|
1105 | - /** |
|
1106 | - * write exception details to log file |
|
1107 | - * |
|
1108 | - * @param int $time |
|
1109 | - * @param array $ex |
|
1110 | - * @param bool $clear |
|
1111 | - * @return void |
|
1112 | - */ |
|
1113 | - public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
1114 | - { |
|
1115 | - if (empty($ex)) { |
|
1116 | - return; |
|
1117 | - } |
|
1118 | - if (! $time) { |
|
1119 | - $time = time(); |
|
1120 | - } |
|
1121 | - $exception_log = '----------------------------------------------------------------------------------------' |
|
1122 | - . PHP_EOL; |
|
1123 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
1124 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
1125 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
1126 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
1127 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
1128 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
1129 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
1130 | - $exception_log .= '----------------------------------------------------------------------------------------' |
|
1131 | - . PHP_EOL; |
|
1132 | - try { |
|
1133 | - EEH_File::ensure_file_exists_and_is_writable( |
|
1134 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file |
|
1135 | - ); |
|
1136 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs'); |
|
1137 | - if (! $clear) { |
|
1138 | - //get existing log file and append new log info |
|
1139 | - $exception_log = EEH_File::get_file_contents( |
|
1140 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file |
|
1141 | - ) . $exception_log; |
|
1142 | - } |
|
1143 | - EEH_File::write_to_file( |
|
1144 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file, |
|
1145 | - $exception_log |
|
1146 | - ); |
|
1147 | - } catch (EE_Error $e) { |
|
1148 | - EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
1149 | - 'event_espresso'), $e->getMessage())); |
|
1150 | - return; |
|
1151 | - } |
|
1152 | - } |
|
1153 | - |
|
1154 | - |
|
1155 | - |
|
1156 | - /** |
|
1157 | - * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1158 | - * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1159 | - * but the code execution is done in a manner that could lead to unexpected results |
|
1160 | - * (i.e. running to early, or too late in WP or EE loading process). |
|
1161 | - * A good test for knowing whether to use this method is: |
|
1162 | - * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1163 | - * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1164 | - * 2. If this is loaded before something else, it won't break anything, |
|
1165 | - * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1166 | - * |
|
1167 | - * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1168 | - * @param string $function The function that was called |
|
1169 | - * @param string $message A message explaining what has been done incorrectly |
|
1170 | - * @param string $version The version of Event Espresso where the error was added |
|
1171 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1172 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
1173 | - * but not have any notices appear until a later version. This allows developers |
|
1174 | - * extra time to update their code before notices appear. |
|
1175 | - * @param int $error_type |
|
1176 | - */ |
|
1177 | - public static function doing_it_wrong( |
|
1178 | - $function, |
|
1179 | - $message, |
|
1180 | - $version, |
|
1181 | - $applies_when = '', |
|
1182 | - $error_type = null |
|
1183 | - ) { |
|
1184 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1185 | - EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1186 | - } |
|
1187 | - } |
|
1188 | - |
|
1189 | - |
|
1190 | - |
|
1191 | - /** |
|
1192 | - * Like get_notices, but returns an array of all the notices of the given type. |
|
1193 | - * |
|
1194 | - * @return array { |
|
1195 | - * @type array $success all the success messages |
|
1196 | - * @type array $errors all the error messages |
|
1197 | - * @type array $attention all the attention messages |
|
1198 | - * } |
|
1199 | - */ |
|
1200 | - public static function get_raw_notices() |
|
1201 | - { |
|
1202 | - return self::$_espresso_notices; |
|
1203 | - } |
|
1067 | + } |
|
1068 | + return ''; |
|
1069 | + } |
|
1070 | + |
|
1071 | + |
|
1072 | + |
|
1073 | + /** |
|
1074 | + * enqueue_error_scripts |
|
1075 | + * |
|
1076 | + * @return void |
|
1077 | + */ |
|
1078 | + public static function enqueue_error_scripts() |
|
1079 | + { |
|
1080 | + self::_print_scripts(); |
|
1081 | + } |
|
1082 | + |
|
1083 | + |
|
1084 | + |
|
1085 | + /** |
|
1086 | + * create error code from filepath, function name, |
|
1087 | + * and line number where exception or error was thrown |
|
1088 | + * |
|
1089 | + * @param string $file |
|
1090 | + * @param string $func |
|
1091 | + * @param string $line |
|
1092 | + * @return string |
|
1093 | + */ |
|
1094 | + public static function generate_error_code($file = '', $func = '', $line = '') |
|
1095 | + { |
|
1096 | + $file = explode('.', basename($file)); |
|
1097 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
1098 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
1099 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
1100 | + return $error_code; |
|
1101 | + } |
|
1102 | + |
|
1103 | + |
|
1104 | + |
|
1105 | + /** |
|
1106 | + * write exception details to log file |
|
1107 | + * |
|
1108 | + * @param int $time |
|
1109 | + * @param array $ex |
|
1110 | + * @param bool $clear |
|
1111 | + * @return void |
|
1112 | + */ |
|
1113 | + public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
1114 | + { |
|
1115 | + if (empty($ex)) { |
|
1116 | + return; |
|
1117 | + } |
|
1118 | + if (! $time) { |
|
1119 | + $time = time(); |
|
1120 | + } |
|
1121 | + $exception_log = '----------------------------------------------------------------------------------------' |
|
1122 | + . PHP_EOL; |
|
1123 | + $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
1124 | + $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
1125 | + $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
1126 | + $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
1127 | + $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
1128 | + $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
1129 | + $exception_log .= $ex['string'] . PHP_EOL; |
|
1130 | + $exception_log .= '----------------------------------------------------------------------------------------' |
|
1131 | + . PHP_EOL; |
|
1132 | + try { |
|
1133 | + EEH_File::ensure_file_exists_and_is_writable( |
|
1134 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file |
|
1135 | + ); |
|
1136 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs'); |
|
1137 | + if (! $clear) { |
|
1138 | + //get existing log file and append new log info |
|
1139 | + $exception_log = EEH_File::get_file_contents( |
|
1140 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file |
|
1141 | + ) . $exception_log; |
|
1142 | + } |
|
1143 | + EEH_File::write_to_file( |
|
1144 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file, |
|
1145 | + $exception_log |
|
1146 | + ); |
|
1147 | + } catch (EE_Error $e) { |
|
1148 | + EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
1149 | + 'event_espresso'), $e->getMessage())); |
|
1150 | + return; |
|
1151 | + } |
|
1152 | + } |
|
1153 | + |
|
1154 | + |
|
1155 | + |
|
1156 | + /** |
|
1157 | + * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1158 | + * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1159 | + * but the code execution is done in a manner that could lead to unexpected results |
|
1160 | + * (i.e. running to early, or too late in WP or EE loading process). |
|
1161 | + * A good test for knowing whether to use this method is: |
|
1162 | + * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1163 | + * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1164 | + * 2. If this is loaded before something else, it won't break anything, |
|
1165 | + * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1166 | + * |
|
1167 | + * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1168 | + * @param string $function The function that was called |
|
1169 | + * @param string $message A message explaining what has been done incorrectly |
|
1170 | + * @param string $version The version of Event Espresso where the error was added |
|
1171 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1172 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
1173 | + * but not have any notices appear until a later version. This allows developers |
|
1174 | + * extra time to update their code before notices appear. |
|
1175 | + * @param int $error_type |
|
1176 | + */ |
|
1177 | + public static function doing_it_wrong( |
|
1178 | + $function, |
|
1179 | + $message, |
|
1180 | + $version, |
|
1181 | + $applies_when = '', |
|
1182 | + $error_type = null |
|
1183 | + ) { |
|
1184 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1185 | + EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1186 | + } |
|
1187 | + } |
|
1188 | + |
|
1189 | + |
|
1190 | + |
|
1191 | + /** |
|
1192 | + * Like get_notices, but returns an array of all the notices of the given type. |
|
1193 | + * |
|
1194 | + * @return array { |
|
1195 | + * @type array $success all the success messages |
|
1196 | + * @type array $errors all the error messages |
|
1197 | + * @type array $attention all the attention messages |
|
1198 | + * } |
|
1199 | + */ |
|
1200 | + public static function get_raw_notices() |
|
1201 | + { |
|
1202 | + return self::$_espresso_notices; |
|
1203 | + } |
|
1204 | 1204 | |
1205 | 1205 | |
1206 | 1206 | |
@@ -1216,27 +1216,27 @@ discard block |
||
1216 | 1216 | */ |
1217 | 1217 | function espresso_error_enqueue_scripts() |
1218 | 1218 | { |
1219 | - // js for error handling |
|
1220 | - wp_register_script( |
|
1221 | - 'espresso_core', |
|
1222 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1223 | - array('jquery'), |
|
1224 | - EVENT_ESPRESSO_VERSION, |
|
1225 | - false |
|
1226 | - ); |
|
1227 | - wp_register_script( |
|
1228 | - 'ee_error_js', |
|
1229 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1230 | - array('espresso_core'), |
|
1231 | - EVENT_ESPRESSO_VERSION, |
|
1232 | - false |
|
1233 | - ); |
|
1219 | + // js for error handling |
|
1220 | + wp_register_script( |
|
1221 | + 'espresso_core', |
|
1222 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1223 | + array('jquery'), |
|
1224 | + EVENT_ESPRESSO_VERSION, |
|
1225 | + false |
|
1226 | + ); |
|
1227 | + wp_register_script( |
|
1228 | + 'ee_error_js', |
|
1229 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1230 | + array('espresso_core'), |
|
1231 | + EVENT_ESPRESSO_VERSION, |
|
1232 | + false |
|
1233 | + ); |
|
1234 | 1234 | } |
1235 | 1235 | |
1236 | 1236 | if (is_admin()) { |
1237 | - add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1237 | + add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1238 | 1238 | } else { |
1239 | - add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1239 | + add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1240 | 1240 | } |
1241 | 1241 | |
1242 | 1242 |