@@ -95,7 +95,7 @@ |
||
95 | 95 | * |
96 | 96 | * @param EE_Event $event EE event object |
97 | 97 | * @param array $data The request data from the form |
98 | - * @return bool success or fail |
|
98 | + * @return integer success or fail |
|
99 | 99 | */ |
100 | 100 | public function attach_evt_message_templates($event, $data) |
101 | 101 | { |
@@ -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 | /** |
@@ -17,246 +17,246 @@ discard block |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * espresso_events_Messages_Hooks_Extend constructor. |
|
22 | - * |
|
23 | - * @param \EE_Admin_Page $admin_page |
|
24 | - */ |
|
25 | - public function __construct(EE_Admin_Page $admin_page) |
|
26 | - { |
|
27 | - /** |
|
28 | - * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages |
|
29 | - */ |
|
30 | - if ( |
|
31 | - ! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'messages_events_editor_metabox') |
|
32 | - ) { |
|
33 | - return; |
|
34 | - } |
|
35 | - add_filter( |
|
36 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
37 | - array($this, 'caf_updates'), |
|
38 | - 10 |
|
39 | - ); |
|
40 | - parent::__construct($admin_page); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * extending the properties set in espresso_events_Messages_Hooks |
|
46 | - * |
|
47 | - * @access protected |
|
48 | - * @return void |
|
49 | - */ |
|
50 | - protected function _extend_properties() |
|
51 | - { |
|
52 | - |
|
53 | - define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
54 | - $this->_ajax_func = array( |
|
55 | - 'ee_msgs_create_new_custom' => 'create_new_custom', |
|
56 | - ); |
|
57 | - $this->_metaboxes = array( |
|
58 | - 0 => array( |
|
59 | - 'page_route' => array('edit', 'create_new'), |
|
60 | - 'func' => 'messages_metabox', |
|
61 | - 'label' => __('Notifications', 'event_espresso'), |
|
62 | - 'priority' => 'high', |
|
63 | - ), |
|
64 | - ); |
|
65 | - |
|
66 | - //see explanation for layout in EE_Admin_Hooks |
|
67 | - $this->_scripts_styles = array( |
|
68 | - 'registers' => array( |
|
69 | - 'events_msg_admin' => array( |
|
70 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
71 | - 'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'), |
|
72 | - ), |
|
73 | - 'events_msg_admin_css' => array( |
|
74 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
75 | - 'type' => 'css', |
|
76 | - ), |
|
77 | - ), |
|
78 | - 'enqueues' => array( |
|
79 | - 'events_msg_admin' => array('edit', 'create_new'), |
|
80 | - 'events_msg_admin_css' => array('edit', 'create_new'), |
|
81 | - ), |
|
82 | - ); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - public function caf_updates($update_callbacks) |
|
87 | - { |
|
88 | - $update_callbacks[] = array($this, 'attach_evt_message_templates'); |
|
89 | - return $update_callbacks; |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Handles attaching Message Templates to the Event on save. |
|
95 | - * |
|
96 | - * @param EE_Event $event EE event object |
|
97 | - * @param array $data The request data from the form |
|
98 | - * @return bool success or fail |
|
99 | - */ |
|
100 | - public function attach_evt_message_templates($event, $data) |
|
101 | - { |
|
102 | - //first we remove all existing relations on the Event for message types. |
|
103 | - $event->_remove_relations('Message_Template_Group'); |
|
104 | - //now let's just loop through the selected templates and add relations! |
|
105 | - if (isset($data['event_message_templates_relation'])) { |
|
106 | - foreach ($data['event_message_templates_relation'] as $grp_ID) { |
|
107 | - $event->_add_relation_to($grp_ID, 'Message_Template_Group'); |
|
108 | - } |
|
109 | - } |
|
110 | - //now save |
|
111 | - return $event->save(); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @param $event |
|
117 | - * @param $callback_args |
|
118 | - * @return string |
|
119 | - * @throws \EE_Error |
|
120 | - */ |
|
121 | - public function messages_metabox($event, $callback_args) |
|
122 | - { |
|
123 | - //let's get the active messengers (b/c messenger objects have the active message templates) |
|
124 | - //convert 'evt_id' to 'EVT_ID' |
|
125 | - $this->_req_data['EVT_ID'] = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
126 | - $this->_req_data['EVT_ID'] = isset($this->_req_data['post']) && empty($this->_req_data['EVT_ID']) |
|
127 | - ? $this->_req_data['post'] |
|
128 | - : $this->_req_data['EVT_ID']; |
|
129 | - |
|
130 | - $this->_req_data['EVT_ID'] = empty($this->_req_data['EVT_ID']) && isset($this->_req_data['evt_id']) |
|
131 | - ? $this->_req_data['evt_id'] |
|
132 | - : $this->_req_data['EVT_ID']; |
|
133 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
134 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
135 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
136 | - $tabs = array(); |
|
137 | - |
|
138 | - //empty messengers? |
|
139 | - //Note message types will always have at least one available because every messenger has a default message type associated with it (payment) if no other message types are selected. |
|
140 | - if (empty($active_messengers)) { |
|
141 | - $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce( |
|
142 | - array('action' => 'settings'), |
|
143 | - EE_MSG_ADMIN_URL |
|
144 | - ); |
|
145 | - $error_msg = sprintf( |
|
146 | - __('There are no active messengers. So no notifications will go out for %1$sany%2$s events. You will want to %3$sActivate a Messenger%4$s.', |
|
147 | - 'event_espresso'), |
|
148 | - '<strong>', |
|
149 | - '</strong>', |
|
150 | - '<a href="' . $msg_activate_url . '">', |
|
151 | - '</a>' |
|
152 | - ); |
|
153 | - $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
154 | - $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
155 | - |
|
156 | - echo $error_content; |
|
157 | - echo $internal_content; |
|
158 | - return ''; |
|
159 | - } |
|
160 | - |
|
161 | - $event_id = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
162 | - //get content for active messengers |
|
163 | - foreach ($active_messengers as $name => $messenger) { |
|
164 | - //first check if there are any active message types for this messenger. |
|
165 | - $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name); |
|
166 | - if (empty($active_mts)) { |
|
167 | - continue; |
|
168 | - } |
|
169 | - |
|
170 | - $tab_content = $messenger->get_messenger_admin_page_content( |
|
171 | - 'events', |
|
172 | - 'edit', |
|
173 | - array('event' => $event_id) |
|
174 | - ); |
|
175 | - |
|
176 | - if (! empty($tab_content)) { |
|
177 | - $tabs[$name] = $tab_content; |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - //we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper. |
|
183 | - $tabbed_content = EEH_Tabbed_Content::display($tabs); |
|
184 | - if ($tabbed_content instanceof WP_Error) { |
|
185 | - $tabbed_content = $tabbed_content->get_error_message(); |
|
186 | - } |
|
187 | - |
|
188 | - $notices = ' |
|
20 | + /** |
|
21 | + * espresso_events_Messages_Hooks_Extend constructor. |
|
22 | + * |
|
23 | + * @param \EE_Admin_Page $admin_page |
|
24 | + */ |
|
25 | + public function __construct(EE_Admin_Page $admin_page) |
|
26 | + { |
|
27 | + /** |
|
28 | + * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages |
|
29 | + */ |
|
30 | + if ( |
|
31 | + ! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'messages_events_editor_metabox') |
|
32 | + ) { |
|
33 | + return; |
|
34 | + } |
|
35 | + add_filter( |
|
36 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
37 | + array($this, 'caf_updates'), |
|
38 | + 10 |
|
39 | + ); |
|
40 | + parent::__construct($admin_page); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * extending the properties set in espresso_events_Messages_Hooks |
|
46 | + * |
|
47 | + * @access protected |
|
48 | + * @return void |
|
49 | + */ |
|
50 | + protected function _extend_properties() |
|
51 | + { |
|
52 | + |
|
53 | + define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
54 | + $this->_ajax_func = array( |
|
55 | + 'ee_msgs_create_new_custom' => 'create_new_custom', |
|
56 | + ); |
|
57 | + $this->_metaboxes = array( |
|
58 | + 0 => array( |
|
59 | + 'page_route' => array('edit', 'create_new'), |
|
60 | + 'func' => 'messages_metabox', |
|
61 | + 'label' => __('Notifications', 'event_espresso'), |
|
62 | + 'priority' => 'high', |
|
63 | + ), |
|
64 | + ); |
|
65 | + |
|
66 | + //see explanation for layout in EE_Admin_Hooks |
|
67 | + $this->_scripts_styles = array( |
|
68 | + 'registers' => array( |
|
69 | + 'events_msg_admin' => array( |
|
70 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
71 | + 'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'), |
|
72 | + ), |
|
73 | + 'events_msg_admin_css' => array( |
|
74 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
75 | + 'type' => 'css', |
|
76 | + ), |
|
77 | + ), |
|
78 | + 'enqueues' => array( |
|
79 | + 'events_msg_admin' => array('edit', 'create_new'), |
|
80 | + 'events_msg_admin_css' => array('edit', 'create_new'), |
|
81 | + ), |
|
82 | + ); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + public function caf_updates($update_callbacks) |
|
87 | + { |
|
88 | + $update_callbacks[] = array($this, 'attach_evt_message_templates'); |
|
89 | + return $update_callbacks; |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Handles attaching Message Templates to the Event on save. |
|
95 | + * |
|
96 | + * @param EE_Event $event EE event object |
|
97 | + * @param array $data The request data from the form |
|
98 | + * @return bool success or fail |
|
99 | + */ |
|
100 | + public function attach_evt_message_templates($event, $data) |
|
101 | + { |
|
102 | + //first we remove all existing relations on the Event for message types. |
|
103 | + $event->_remove_relations('Message_Template_Group'); |
|
104 | + //now let's just loop through the selected templates and add relations! |
|
105 | + if (isset($data['event_message_templates_relation'])) { |
|
106 | + foreach ($data['event_message_templates_relation'] as $grp_ID) { |
|
107 | + $event->_add_relation_to($grp_ID, 'Message_Template_Group'); |
|
108 | + } |
|
109 | + } |
|
110 | + //now save |
|
111 | + return $event->save(); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @param $event |
|
117 | + * @param $callback_args |
|
118 | + * @return string |
|
119 | + * @throws \EE_Error |
|
120 | + */ |
|
121 | + public function messages_metabox($event, $callback_args) |
|
122 | + { |
|
123 | + //let's get the active messengers (b/c messenger objects have the active message templates) |
|
124 | + //convert 'evt_id' to 'EVT_ID' |
|
125 | + $this->_req_data['EVT_ID'] = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
126 | + $this->_req_data['EVT_ID'] = isset($this->_req_data['post']) && empty($this->_req_data['EVT_ID']) |
|
127 | + ? $this->_req_data['post'] |
|
128 | + : $this->_req_data['EVT_ID']; |
|
129 | + |
|
130 | + $this->_req_data['EVT_ID'] = empty($this->_req_data['EVT_ID']) && isset($this->_req_data['evt_id']) |
|
131 | + ? $this->_req_data['evt_id'] |
|
132 | + : $this->_req_data['EVT_ID']; |
|
133 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
134 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
135 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
136 | + $tabs = array(); |
|
137 | + |
|
138 | + //empty messengers? |
|
139 | + //Note message types will always have at least one available because every messenger has a default message type associated with it (payment) if no other message types are selected. |
|
140 | + if (empty($active_messengers)) { |
|
141 | + $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce( |
|
142 | + array('action' => 'settings'), |
|
143 | + EE_MSG_ADMIN_URL |
|
144 | + ); |
|
145 | + $error_msg = sprintf( |
|
146 | + __('There are no active messengers. So no notifications will go out for %1$sany%2$s events. You will want to %3$sActivate a Messenger%4$s.', |
|
147 | + 'event_espresso'), |
|
148 | + '<strong>', |
|
149 | + '</strong>', |
|
150 | + '<a href="' . $msg_activate_url . '">', |
|
151 | + '</a>' |
|
152 | + ); |
|
153 | + $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
154 | + $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
155 | + |
|
156 | + echo $error_content; |
|
157 | + echo $internal_content; |
|
158 | + return ''; |
|
159 | + } |
|
160 | + |
|
161 | + $event_id = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
162 | + //get content for active messengers |
|
163 | + foreach ($active_messengers as $name => $messenger) { |
|
164 | + //first check if there are any active message types for this messenger. |
|
165 | + $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name); |
|
166 | + if (empty($active_mts)) { |
|
167 | + continue; |
|
168 | + } |
|
169 | + |
|
170 | + $tab_content = $messenger->get_messenger_admin_page_content( |
|
171 | + 'events', |
|
172 | + 'edit', |
|
173 | + array('event' => $event_id) |
|
174 | + ); |
|
175 | + |
|
176 | + if (! empty($tab_content)) { |
|
177 | + $tabs[$name] = $tab_content; |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + //we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper. |
|
183 | + $tabbed_content = EEH_Tabbed_Content::display($tabs); |
|
184 | + if ($tabbed_content instanceof WP_Error) { |
|
185 | + $tabbed_content = $tabbed_content->get_error_message(); |
|
186 | + } |
|
187 | + |
|
188 | + $notices = ' |
|
189 | 189 | <div id="espresso-ajax-loading" class="ajax-loader-grey"> |
190 | 190 | <span class="ee-spinner ee-spin"></span><span class="hidden">' . __('loading...', 'event_espresso') . '</span> |
191 | 191 | </div> |
192 | 192 | <div class="ee-notices"></div>'; |
193 | 193 | |
194 | - if (defined('DOING_AJAX')) { |
|
195 | - return $tabbed_content; |
|
196 | - } |
|
197 | - |
|
198 | - do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
|
199 | - echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
200 | - do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
|
201 | - |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * Ajax callback for ee_msgs_create_new_custom ajax request. |
|
207 | - * Takes incoming GRP_ID and name and description values from ajax request |
|
208 | - * to create a new custom template based off of the incoming GRP_ID. |
|
209 | - * |
|
210 | - * @access public |
|
211 | - * @return string either an html string will be returned or a success message |
|
212 | - */ |
|
213 | - public function create_new_custom() |
|
214 | - { |
|
215 | - |
|
216 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
217 | - wp_die(__('You don\'t have privileges to do this action', 'event_espresso')); |
|
218 | - } |
|
219 | - |
|
220 | - //let's clean up the _POST global a bit for downstream usage of name and description. |
|
221 | - $_POST['templateName'] = ! empty($this->_req_data['custom_template_args']['MTP_name']) |
|
222 | - ? $this->_req_data['custom_template_args']['MTP_name'] |
|
223 | - : ''; |
|
224 | - $_POST['templateDescription'] = ! empty($this->_req_data['custom_template_args']['MTP_description']) |
|
225 | - ? $this->_req_data['custom_template_args']['MTP_description'] |
|
226 | - : ''; |
|
227 | - |
|
228 | - |
|
229 | - // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent |
|
230 | - $this->_set_page_object(); |
|
231 | - |
|
232 | - // is this a template switch if so EE_Admin_Page child needs this object |
|
233 | - $this->_page_object->set_hook_object($this); |
|
234 | - |
|
235 | - $this->_page_object->add_message_template( |
|
236 | - $this->_req_data['messageType'], |
|
237 | - $this->_req_data['messenger'], |
|
238 | - $this->_req_data['group_ID'] |
|
239 | - ); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - public function create_new_admin_footer() |
|
244 | - { |
|
245 | - $this->edit_admin_footer(); |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * This is the dynamic method for this class |
|
251 | - * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page. |
|
252 | - * |
|
253 | - * @return string (admin_footer contents) |
|
254 | - */ |
|
255 | - public function edit_admin_footer() |
|
256 | - { |
|
257 | - EEH_Template::display_template( |
|
258 | - EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
259 | - ); |
|
260 | - } |
|
194 | + if (defined('DOING_AJAX')) { |
|
195 | + return $tabbed_content; |
|
196 | + } |
|
197 | + |
|
198 | + do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
|
199 | + echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
200 | + do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
|
201 | + |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * Ajax callback for ee_msgs_create_new_custom ajax request. |
|
207 | + * Takes incoming GRP_ID and name and description values from ajax request |
|
208 | + * to create a new custom template based off of the incoming GRP_ID. |
|
209 | + * |
|
210 | + * @access public |
|
211 | + * @return string either an html string will be returned or a success message |
|
212 | + */ |
|
213 | + public function create_new_custom() |
|
214 | + { |
|
215 | + |
|
216 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
217 | + wp_die(__('You don\'t have privileges to do this action', 'event_espresso')); |
|
218 | + } |
|
219 | + |
|
220 | + //let's clean up the _POST global a bit for downstream usage of name and description. |
|
221 | + $_POST['templateName'] = ! empty($this->_req_data['custom_template_args']['MTP_name']) |
|
222 | + ? $this->_req_data['custom_template_args']['MTP_name'] |
|
223 | + : ''; |
|
224 | + $_POST['templateDescription'] = ! empty($this->_req_data['custom_template_args']['MTP_description']) |
|
225 | + ? $this->_req_data['custom_template_args']['MTP_description'] |
|
226 | + : ''; |
|
227 | + |
|
228 | + |
|
229 | + // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent |
|
230 | + $this->_set_page_object(); |
|
231 | + |
|
232 | + // is this a template switch if so EE_Admin_Page child needs this object |
|
233 | + $this->_page_object->set_hook_object($this); |
|
234 | + |
|
235 | + $this->_page_object->add_message_template( |
|
236 | + $this->_req_data['messageType'], |
|
237 | + $this->_req_data['messenger'], |
|
238 | + $this->_req_data['group_ID'] |
|
239 | + ); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + public function create_new_admin_footer() |
|
244 | + { |
|
245 | + $this->edit_admin_footer(); |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * This is the dynamic method for this class |
|
251 | + * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page. |
|
252 | + * |
|
253 | + * @return string (admin_footer contents) |
|
254 | + */ |
|
255 | + public function edit_admin_footer() |
|
256 | + { |
|
257 | + EEH_Template::display_template( |
|
258 | + EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
259 | + ); |
|
260 | + } |
|
261 | 261 | |
262 | 262 | } //end class espresso_events_Messages_Hooks_Extend |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | protected function _extend_properties() |
51 | 51 | { |
52 | 52 | |
53 | - define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
53 | + define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'messages/assets/'); |
|
54 | 54 | $this->_ajax_func = array( |
55 | 55 | 'ee_msgs_create_new_custom' => 'create_new_custom', |
56 | 56 | ); |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | $this->_scripts_styles = array( |
68 | 68 | 'registers' => array( |
69 | 69 | 'events_msg_admin' => array( |
70 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
70 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL.'events_messages_admin.js', |
|
71 | 71 | 'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'), |
72 | 72 | ), |
73 | 73 | 'events_msg_admin_css' => array( |
74 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
74 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL.'ee_msg_events_admin.css', |
|
75 | 75 | 'type' => 'css', |
76 | 76 | ), |
77 | 77 | ), |
@@ -142,16 +142,16 @@ discard block |
||
142 | 142 | array('action' => 'settings'), |
143 | 143 | EE_MSG_ADMIN_URL |
144 | 144 | ); |
145 | - $error_msg = sprintf( |
|
145 | + $error_msg = sprintf( |
|
146 | 146 | __('There are no active messengers. So no notifications will go out for %1$sany%2$s events. You will want to %3$sActivate a Messenger%4$s.', |
147 | 147 | 'event_espresso'), |
148 | 148 | '<strong>', |
149 | 149 | '</strong>', |
150 | - '<a href="' . $msg_activate_url . '">', |
|
150 | + '<a href="'.$msg_activate_url.'">', |
|
151 | 151 | '</a>' |
152 | 152 | ); |
153 | - $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
154 | - $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
153 | + $error_content = '<div class="error"><p>'.$error_msg.'</p></div>'; |
|
154 | + $internal_content = '<div id="messages-error"><p>'.$error_msg.'</p></div>'; |
|
155 | 155 | |
156 | 156 | echo $error_content; |
157 | 157 | echo $internal_content; |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | array('event' => $event_id) |
174 | 174 | ); |
175 | 175 | |
176 | - if (! empty($tab_content)) { |
|
176 | + if ( ! empty($tab_content)) { |
|
177 | 177 | $tabs[$name] = $tab_content; |
178 | 178 | } |
179 | 179 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | |
188 | 188 | $notices = ' |
189 | 189 | <div id="espresso-ajax-loading" class="ajax-loader-grey"> |
190 | - <span class="ee-spinner ee-spin"></span><span class="hidden">' . __('loading...', 'event_espresso') . '</span> |
|
190 | + <span class="ee-spinner ee-spin"></span><span class="hidden">' . __('loading...', 'event_espresso').'</span> |
|
191 | 191 | </div> |
192 | 192 | <div class="ee-notices"></div>'; |
193 | 193 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | } |
197 | 197 | |
198 | 198 | do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
199 | - echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
199 | + echo $notices.'<div class="messages-tabs-content">'.$tabbed_content.'</div>'; |
|
200 | 200 | do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
201 | 201 | |
202 | 202 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | public function create_new_custom() |
214 | 214 | { |
215 | 215 | |
216 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
216 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
217 | 217 | wp_die(__('You don\'t have privileges to do this action', 'event_espresso')); |
218 | 218 | } |
219 | 219 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | public function edit_admin_footer() |
256 | 256 | { |
257 | 257 | EEH_Template::display_template( |
258 | - EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
258 | + EE_CORE_CAF_ADMIN_EXTEND.'messages/templates/create_custom_template_form.template.php' |
|
259 | 259 | ); |
260 | 260 | } |
261 | 261 |
@@ -14,1249 +14,1249 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * Extend_Events_Admin_Page constructor. |
|
19 | - * |
|
20 | - * @param bool $routing |
|
21 | - */ |
|
22 | - public function __construct($routing = true) |
|
23 | - { |
|
24 | - parent::__construct($routing); |
|
25 | - if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
26 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
27 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
28 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
29 | - } |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * Sets routes. |
|
35 | - */ |
|
36 | - protected function _extend_page_config() |
|
37 | - { |
|
38 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
39 | - //is there a evt_id in the request? |
|
40 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
41 | - ? $this->_req_data['EVT_ID'] |
|
42 | - : 0; |
|
43 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
44 | - //tkt_id? |
|
45 | - $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
46 | - ? $this->_req_data['TKT_ID'] |
|
47 | - : 0; |
|
48 | - $new_page_routes = array( |
|
49 | - 'duplicate_event' => array( |
|
50 | - 'func' => '_duplicate_event', |
|
51 | - 'capability' => 'ee_edit_event', |
|
52 | - 'obj_id' => $evt_id, |
|
53 | - 'noheader' => true, |
|
54 | - ), |
|
55 | - 'ticket_list_table' => array( |
|
56 | - 'func' => '_tickets_overview_list_table', |
|
57 | - 'capability' => 'ee_read_default_tickets', |
|
58 | - ), |
|
59 | - 'trash_ticket' => array( |
|
60 | - 'func' => '_trash_or_restore_ticket', |
|
61 | - 'capability' => 'ee_delete_default_ticket', |
|
62 | - 'obj_id' => $tkt_id, |
|
63 | - 'noheader' => true, |
|
64 | - 'args' => array('trash' => true), |
|
65 | - ), |
|
66 | - 'trash_tickets' => array( |
|
67 | - 'func' => '_trash_or_restore_ticket', |
|
68 | - 'capability' => 'ee_delete_default_tickets', |
|
69 | - 'noheader' => true, |
|
70 | - 'args' => array('trash' => true), |
|
71 | - ), |
|
72 | - 'restore_ticket' => array( |
|
73 | - 'func' => '_trash_or_restore_ticket', |
|
74 | - 'capability' => 'ee_delete_default_ticket', |
|
75 | - 'obj_id' => $tkt_id, |
|
76 | - 'noheader' => true, |
|
77 | - ), |
|
78 | - 'restore_tickets' => array( |
|
79 | - 'func' => '_trash_or_restore_ticket', |
|
80 | - 'capability' => 'ee_delete_default_tickets', |
|
81 | - 'noheader' => true, |
|
82 | - ), |
|
83 | - 'delete_ticket' => array( |
|
84 | - 'func' => '_delete_ticket', |
|
85 | - 'capability' => 'ee_delete_default_ticket', |
|
86 | - 'obj_id' => $tkt_id, |
|
87 | - 'noheader' => true, |
|
88 | - ), |
|
89 | - 'delete_tickets' => array( |
|
90 | - 'func' => '_delete_ticket', |
|
91 | - 'capability' => 'ee_delete_default_tickets', |
|
92 | - 'noheader' => true, |
|
93 | - ), |
|
94 | - 'import_page' => array( |
|
95 | - 'func' => '_import_page', |
|
96 | - 'capability' => 'import', |
|
97 | - ), |
|
98 | - 'import' => array( |
|
99 | - 'func' => '_import_events', |
|
100 | - 'capability' => 'import', |
|
101 | - 'noheader' => true, |
|
102 | - ), |
|
103 | - 'import_events' => array( |
|
104 | - 'func' => '_import_events', |
|
105 | - 'capability' => 'import', |
|
106 | - 'noheader' => true, |
|
107 | - ), |
|
108 | - 'export_events' => array( |
|
109 | - 'func' => '_events_export', |
|
110 | - 'capability' => 'export', |
|
111 | - 'noheader' => true, |
|
112 | - ), |
|
113 | - 'export_categories' => array( |
|
114 | - 'func' => '_categories_export', |
|
115 | - 'capability' => 'export', |
|
116 | - 'noheader' => true, |
|
117 | - ), |
|
118 | - 'sample_export_file' => array( |
|
119 | - 'func' => '_sample_export_file', |
|
120 | - 'capability' => 'export', |
|
121 | - 'noheader' => true, |
|
122 | - ), |
|
123 | - 'update_template_settings' => array( |
|
124 | - 'func' => '_update_template_settings', |
|
125 | - 'capability' => 'manage_options', |
|
126 | - 'noheader' => true, |
|
127 | - ), |
|
128 | - ); |
|
129 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
130 | - //partial route/config override |
|
131 | - $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
132 | - $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
133 | - $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
134 | - $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
135 | - $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
136 | - $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
137 | - //add tickets tab but only if there are more than one default ticket! |
|
138 | - $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
139 | - array(array('TKT_is_default' => 1)), |
|
140 | - 'TKT_ID', |
|
141 | - true |
|
142 | - ); |
|
143 | - if ($tkt_count > 1) { |
|
144 | - $new_page_config = array( |
|
145 | - 'ticket_list_table' => array( |
|
146 | - 'nav' => array( |
|
147 | - 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
148 | - 'order' => 60, |
|
149 | - ), |
|
150 | - 'list_table' => 'Tickets_List_Table', |
|
151 | - 'require_nonce' => false, |
|
152 | - ), |
|
153 | - ); |
|
154 | - } |
|
155 | - //template settings |
|
156 | - $new_page_config['template_settings'] = array( |
|
157 | - 'nav' => array( |
|
158 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
159 | - 'order' => 30, |
|
160 | - ), |
|
161 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
162 | - 'help_tabs' => array( |
|
163 | - 'general_settings_templates_help_tab' => array( |
|
164 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
165 | - 'filename' => 'general_settings_templates', |
|
166 | - ), |
|
167 | - ), |
|
168 | - 'help_tour' => array('Templates_Help_Tour'), |
|
169 | - 'require_nonce' => false, |
|
170 | - ); |
|
171 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
172 | - //add filters and actions |
|
173 | - //modifying _views |
|
174 | - add_filter( |
|
175 | - 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
176 | - array($this, 'add_additional_datetime_button'), |
|
177 | - 10, |
|
178 | - 2 |
|
179 | - ); |
|
180 | - add_filter( |
|
181 | - 'FHEE_event_datetime_metabox_clone_button_template', |
|
182 | - array($this, 'add_datetime_clone_button'), |
|
183 | - 10, |
|
184 | - 2 |
|
185 | - ); |
|
186 | - add_filter( |
|
187 | - 'FHEE_event_datetime_metabox_timezones_template', |
|
188 | - array($this, 'datetime_timezones_template'), |
|
189 | - 10, |
|
190 | - 2 |
|
191 | - ); |
|
192 | - //filters for event list table |
|
193 | - add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2); |
|
194 | - add_filter( |
|
195 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
196 | - array($this, 'extra_list_table_actions'), |
|
197 | - 10, |
|
198 | - 2 |
|
199 | - ); |
|
200 | - //legend item |
|
201 | - add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items')); |
|
202 | - add_action('admin_init', array($this, 'admin_init')); |
|
203 | - //heartbeat stuff |
|
204 | - add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2); |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * admin_init |
|
210 | - */ |
|
211 | - public function admin_init() |
|
212 | - { |
|
213 | - EE_Registry::$i18n_js_strings = array_merge( |
|
214 | - EE_Registry::$i18n_js_strings, |
|
215 | - array( |
|
216 | - 'image_confirm' => esc_html__( |
|
217 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
218 | - 'event_espresso' |
|
219 | - ), |
|
220 | - 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
221 | - 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
222 | - 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
223 | - 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
224 | - 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
225 | - ) |
|
226 | - ); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle |
|
232 | - * accordingly. |
|
233 | - * |
|
234 | - * @param array $response The existing heartbeat response array. |
|
235 | - * @param array $data The incoming data package. |
|
236 | - * @return array possibly appended response. |
|
237 | - */ |
|
238 | - public function heartbeat_response($response, $data) |
|
239 | - { |
|
240 | - /** |
|
241 | - * check whether count of tickets is approaching the potential |
|
242 | - * limits for the server. |
|
243 | - */ |
|
244 | - if (! empty($data['input_count'])) { |
|
245 | - $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check( |
|
246 | - $data['input_count'] |
|
247 | - ); |
|
248 | - } |
|
249 | - return $response; |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * Add per page screen options to the default ticket list table view. |
|
255 | - */ |
|
256 | - protected function _add_screen_options_ticket_list_table() |
|
257 | - { |
|
258 | - $this->_per_page_screen_option(); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @param string $return |
|
264 | - * @param int $id |
|
265 | - * @param string $new_title |
|
266 | - * @param string $new_slug |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
270 | - { |
|
271 | - $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
272 | - //make sure this is only when editing |
|
273 | - if (! empty($id)) { |
|
274 | - $href = EE_Admin_Page::add_query_args_and_nonce( |
|
275 | - array('action' => 'duplicate_event', 'EVT_ID' => $id), |
|
276 | - $this->_admin_base_url |
|
277 | - ); |
|
278 | - $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
279 | - $return .= '<a href="' |
|
280 | - . $href |
|
281 | - . '" title="' |
|
282 | - . $title |
|
283 | - . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
284 | - . $title |
|
285 | - . '</button>'; |
|
286 | - } |
|
287 | - return $return; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * Set the list table views for the default ticket list table view. |
|
293 | - */ |
|
294 | - public function _set_list_table_views_ticket_list_table() |
|
295 | - { |
|
296 | - $this->_views = array( |
|
297 | - 'all' => array( |
|
298 | - 'slug' => 'all', |
|
299 | - 'label' => esc_html__('All', 'event_espresso'), |
|
300 | - 'count' => 0, |
|
301 | - 'bulk_action' => array( |
|
302 | - 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
303 | - ), |
|
304 | - ), |
|
305 | - 'trashed' => array( |
|
306 | - 'slug' => 'trashed', |
|
307 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
308 | - 'count' => 0, |
|
309 | - 'bulk_action' => array( |
|
310 | - 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
311 | - 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
312 | - ), |
|
313 | - ), |
|
314 | - ); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Enqueue scripts and styles for the event editor. |
|
320 | - */ |
|
321 | - public function load_scripts_styles_edit() |
|
322 | - { |
|
323 | - wp_register_script( |
|
324 | - 'ee-event-editor-heartbeat', |
|
325 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
326 | - array('ee_admin_js', 'heartbeat'), |
|
327 | - EVENT_ESPRESSO_VERSION, |
|
328 | - true |
|
329 | - ); |
|
330 | - wp_enqueue_script('ee-accounting'); |
|
331 | - //styles |
|
332 | - wp_enqueue_style('espresso-ui-theme'); |
|
333 | - wp_enqueue_script('event_editor_js'); |
|
334 | - wp_enqueue_script('ee-event-editor-heartbeat'); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Returns template for the additional datetime. |
|
340 | - * @param $template |
|
341 | - * @param $template_args |
|
342 | - * @return mixed |
|
343 | - * @throws DomainException |
|
344 | - */ |
|
345 | - public function add_additional_datetime_button($template, $template_args) |
|
346 | - { |
|
347 | - return EEH_Template::display_template( |
|
348 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
349 | - $template_args, |
|
350 | - true |
|
351 | - ); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Returns the template for cloning a datetime. |
|
357 | - * @param $template |
|
358 | - * @param $template_args |
|
359 | - * @return mixed |
|
360 | - * @throws DomainException |
|
361 | - */ |
|
362 | - public function add_datetime_clone_button($template, $template_args) |
|
363 | - { |
|
364 | - return EEH_Template::display_template( |
|
365 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
366 | - $template_args, |
|
367 | - true |
|
368 | - ); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Returns the template for datetime timezones. |
|
374 | - * @param $template |
|
375 | - * @param $template_args |
|
376 | - * @return mixed |
|
377 | - * @throws DomainException |
|
378 | - */ |
|
379 | - public function datetime_timezones_template($template, $template_args) |
|
380 | - { |
|
381 | - return EEH_Template::display_template( |
|
382 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
383 | - $template_args, |
|
384 | - true |
|
385 | - ); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * Sets the views for the default list table view. |
|
391 | - */ |
|
392 | - protected function _set_list_table_views_default() |
|
393 | - { |
|
394 | - parent::_set_list_table_views_default(); |
|
395 | - $new_views = array( |
|
396 | - 'today' => array( |
|
397 | - 'slug' => 'today', |
|
398 | - 'label' => esc_html__('Today', 'event_espresso'), |
|
399 | - 'count' => $this->total_events_today(), |
|
400 | - 'bulk_action' => array( |
|
401 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
402 | - ), |
|
403 | - ), |
|
404 | - 'month' => array( |
|
405 | - 'slug' => 'month', |
|
406 | - 'label' => esc_html__('This Month', 'event_espresso'), |
|
407 | - 'count' => $this->total_events_this_month(), |
|
408 | - 'bulk_action' => array( |
|
409 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
410 | - ), |
|
411 | - ), |
|
412 | - ); |
|
413 | - $this->_views = array_merge($this->_views, $new_views); |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * Returns the extra action links for the default list table view. |
|
419 | - * @param array $action_links |
|
420 | - * @param \EE_Event $event |
|
421 | - * @return array |
|
422 | - * @throws EE_Error |
|
423 | - */ |
|
424 | - public function extra_list_table_actions(array $action_links, \EE_Event $event) |
|
425 | - { |
|
426 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
427 | - 'ee_read_registrations', |
|
428 | - 'espresso_registrations_reports', |
|
429 | - $event->ID() |
|
430 | - ) |
|
431 | - ) { |
|
432 | - $reports_query_args = array( |
|
433 | - 'action' => 'reports', |
|
434 | - 'EVT_ID' => $event->ID(), |
|
435 | - ); |
|
436 | - $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
437 | - $action_links[] = '<a href="' |
|
438 | - . $reports_link |
|
439 | - . '" title="' |
|
440 | - . esc_attr__('View Report', 'event_espresso') |
|
441 | - . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
442 | - . "\n\t"; |
|
443 | - } |
|
444 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
445 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
446 | - $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
447 | - 'see_notifications_for', |
|
448 | - null, |
|
449 | - array('EVT_ID' => $event->ID()) |
|
450 | - ); |
|
451 | - } |
|
452 | - return $action_links; |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * @param $items |
|
458 | - * @return mixed |
|
459 | - */ |
|
460 | - public function additional_legend_items($items) |
|
461 | - { |
|
462 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
463 | - 'ee_read_registrations', |
|
464 | - 'espresso_registrations_reports' |
|
465 | - ) |
|
466 | - ) { |
|
467 | - $items['reports'] = array( |
|
468 | - 'class' => 'dashicons dashicons-chart-bar', |
|
469 | - 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
470 | - ); |
|
471 | - } |
|
472 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
473 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
474 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
475 | - $items['view_related_messages'] = array( |
|
476 | - 'class' => $related_for_icon['css_class'], |
|
477 | - 'desc' => $related_for_icon['label'], |
|
478 | - ); |
|
479 | - } |
|
480 | - } |
|
481 | - return $items; |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * This is the callback method for the duplicate event route |
|
487 | - * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
488 | - * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
489 | - * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
490 | - * After duplication the redirect is to the new event edit page. |
|
491 | - * |
|
492 | - * @return void |
|
493 | - * @access protected |
|
494 | - * @throws EE_Error If EE_Event is not available with given ID |
|
495 | - */ |
|
496 | - protected function _duplicate_event() |
|
497 | - { |
|
498 | - // first make sure the ID for the event is in the request. |
|
499 | - // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
500 | - if (! isset($this->_req_data['EVT_ID'])) { |
|
501 | - EE_Error::add_error( |
|
502 | - esc_html__( |
|
503 | - 'In order to duplicate an event an Event ID is required. None was given.', |
|
504 | - 'event_espresso' |
|
505 | - ), |
|
506 | - __FILE__, |
|
507 | - __FUNCTION__, |
|
508 | - __LINE__ |
|
509 | - ); |
|
510 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
511 | - return; |
|
512 | - } |
|
513 | - //k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
514 | - $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
515 | - if (! $orig_event instanceof EE_Event) { |
|
516 | - throw new EE_Error( |
|
517 | - sprintf( |
|
518 | - esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
519 | - $this->_req_data['EVT_ID'] |
|
520 | - ) |
|
521 | - ); |
|
522 | - } |
|
523 | - //k now let's clone the $orig_event before getting relations |
|
524 | - $new_event = clone $orig_event; |
|
525 | - //original datetimes |
|
526 | - $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
527 | - //other original relations |
|
528 | - $orig_ven = $orig_event->get_many_related('Venue'); |
|
529 | - //reset the ID and modify other details to make it clear this is a dupe |
|
530 | - $new_event->set('EVT_ID', 0); |
|
531 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
532 | - $new_event->set('EVT_name', $new_name); |
|
533 | - $new_event->set( |
|
534 | - 'EVT_slug', |
|
535 | - wp_unique_post_slug( |
|
536 | - sanitize_title($orig_event->name()), |
|
537 | - 0, |
|
538 | - 'publish', |
|
539 | - 'espresso_events', |
|
540 | - 0 |
|
541 | - ) |
|
542 | - ); |
|
543 | - $new_event->set('status', 'draft'); |
|
544 | - //duplicate discussion settings |
|
545 | - $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
546 | - $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
547 | - //save the new event |
|
548 | - $new_event->save(); |
|
549 | - //venues |
|
550 | - foreach ($orig_ven as $ven) { |
|
551 | - $new_event->_add_relation_to($ven, 'Venue'); |
|
552 | - } |
|
553 | - $new_event->save(); |
|
554 | - //now we need to get the question group relations and handle that |
|
555 | - //first primary question groups |
|
556 | - $orig_primary_qgs = $orig_event->get_many_related( |
|
557 | - 'Question_Group', |
|
558 | - array(array('Event_Question_Group.EQG_primary' => 1)) |
|
559 | - ); |
|
560 | - if (! empty($orig_primary_qgs)) { |
|
561 | - foreach ($orig_primary_qgs as $id => $obj) { |
|
562 | - if ($obj instanceof EE_Question_Group) { |
|
563 | - $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1)); |
|
564 | - } |
|
565 | - } |
|
566 | - } |
|
567 | - //next additional attendee question groups |
|
568 | - $orig_additional_qgs = $orig_event->get_many_related( |
|
569 | - 'Question_Group', |
|
570 | - array(array('Event_Question_Group.EQG_primary' => 0)) |
|
571 | - ); |
|
572 | - if (! empty($orig_additional_qgs)) { |
|
573 | - foreach ($orig_additional_qgs as $id => $obj) { |
|
574 | - if ($obj instanceof EE_Question_Group) { |
|
575 | - $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0)); |
|
576 | - } |
|
577 | - } |
|
578 | - } |
|
579 | - //now save |
|
580 | - $new_event->save(); |
|
581 | - //k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
582 | - $cloned_tickets = array(); |
|
583 | - foreach ($orig_datetimes as $orig_dtt) { |
|
584 | - if (! $orig_dtt instanceof EE_Datetime) { |
|
585 | - continue; |
|
586 | - } |
|
587 | - $new_dtt = clone $orig_dtt; |
|
588 | - $orig_tkts = $orig_dtt->tickets(); |
|
589 | - //save new dtt then add to event |
|
590 | - $new_dtt->set('DTT_ID', 0); |
|
591 | - $new_dtt->set('DTT_sold', 0); |
|
592 | - $new_dtt->set_reserved(0); |
|
593 | - $new_dtt->save(); |
|
594 | - $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
595 | - $new_event->save(); |
|
596 | - //now let's get the ticket relations setup. |
|
597 | - foreach ((array)$orig_tkts as $orig_tkt) { |
|
598 | - //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
599 | - if (! $orig_tkt instanceof EE_Ticket) { |
|
600 | - continue; |
|
601 | - } |
|
602 | - //is this ticket archived? If it is then let's skip |
|
603 | - if ($orig_tkt->get('TKT_deleted')) { |
|
604 | - continue; |
|
605 | - } |
|
606 | - // does this original ticket already exist in the clone_tickets cache? |
|
607 | - // If so we'll just use the new ticket from it. |
|
608 | - if (isset($cloned_tickets[$orig_tkt->ID()])) { |
|
609 | - $new_tkt = $cloned_tickets[$orig_tkt->ID()]; |
|
610 | - } else { |
|
611 | - $new_tkt = clone $orig_tkt; |
|
612 | - //get relations on the $orig_tkt that we need to setup. |
|
613 | - $orig_prices = $orig_tkt->prices(); |
|
614 | - $new_tkt->set('TKT_ID', 0); |
|
615 | - $new_tkt->set('TKT_sold', 0); |
|
616 | - $new_tkt->set('TKT_reserved', 0); |
|
617 | - $new_tkt->save(); //make sure new ticket has ID. |
|
618 | - //price relations on new ticket need to be setup. |
|
619 | - foreach ($orig_prices as $orig_price) { |
|
620 | - $new_price = clone $orig_price; |
|
621 | - $new_price->set('PRC_ID', 0); |
|
622 | - $new_price->save(); |
|
623 | - $new_tkt->_add_relation_to($new_price, 'Price'); |
|
624 | - $new_tkt->save(); |
|
625 | - } |
|
626 | - |
|
627 | - do_action( |
|
628 | - 'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after', |
|
629 | - $orig_tkt, |
|
630 | - $new_tkt, |
|
631 | - $orig_prices, |
|
632 | - $orig_event, |
|
633 | - $orig_dtt, |
|
634 | - $new_dtt |
|
635 | - ); |
|
636 | - } |
|
637 | - // k now we can add the new ticket as a relation to the new datetime |
|
638 | - // and make sure its added to our cached $cloned_tickets array |
|
639 | - // for use with later datetimes that have the same ticket. |
|
640 | - $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
641 | - $new_dtt->save(); |
|
642 | - $cloned_tickets[$orig_tkt->ID()] = $new_tkt; |
|
643 | - } |
|
644 | - } |
|
645 | - //clone taxonomy information |
|
646 | - $taxonomies_to_clone_with = apply_filters( |
|
647 | - 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
648 | - array('espresso_event_categories', 'espresso_event_type', 'post_tag') |
|
649 | - ); |
|
650 | - //get terms for original event (notice) |
|
651 | - $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
652 | - //loop through terms and add them to new event. |
|
653 | - foreach ($orig_terms as $term) { |
|
654 | - wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
655 | - } |
|
656 | - do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
657 | - //now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
658 | - if ($new_event->ID()) { |
|
659 | - $redirect_args = array( |
|
660 | - 'post' => $new_event->ID(), |
|
661 | - 'action' => 'edit', |
|
662 | - ); |
|
663 | - EE_Error::add_success( |
|
664 | - esc_html__( |
|
665 | - 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
666 | - 'event_espresso' |
|
667 | - ) |
|
668 | - ); |
|
669 | - } else { |
|
670 | - $redirect_args = array( |
|
671 | - 'action' => 'default', |
|
672 | - ); |
|
673 | - EE_Error::add_error( |
|
674 | - esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
675 | - __FILE__, |
|
676 | - __FUNCTION__, |
|
677 | - __LINE__ |
|
678 | - ); |
|
679 | - } |
|
680 | - $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
681 | - } |
|
682 | - |
|
683 | - |
|
684 | - /** |
|
685 | - * Generates output for the import page. |
|
686 | - * @throws DomainException |
|
687 | - */ |
|
688 | - protected function _import_page() |
|
689 | - { |
|
690 | - $title = esc_html__('Import', 'event_espresso'); |
|
691 | - $intro = esc_html__( |
|
692 | - 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
693 | - 'event_espresso' |
|
694 | - ); |
|
695 | - $form_url = EVENTS_ADMIN_URL; |
|
696 | - $action = 'import_events'; |
|
697 | - $type = 'csv'; |
|
698 | - $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
699 | - $title, $intro, $form_url, $action, $type |
|
700 | - ); |
|
701 | - $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
702 | - array('action' => 'sample_export_file'), |
|
703 | - $this->_admin_base_url |
|
704 | - ); |
|
705 | - $content = EEH_Template::display_template( |
|
706 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
707 | - $this->_template_args, |
|
708 | - true |
|
709 | - ); |
|
710 | - $this->_template_args['admin_page_content'] = $content; |
|
711 | - $this->display_admin_page_with_sidebar(); |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * _import_events |
|
717 | - * This handles displaying the screen and running imports for importing events. |
|
718 | - * |
|
719 | - * @return void |
|
720 | - */ |
|
721 | - protected function _import_events() |
|
722 | - { |
|
723 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
724 | - $success = EE_Import::instance()->import(); |
|
725 | - $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
|
726 | - } |
|
727 | - |
|
728 | - |
|
729 | - /** |
|
730 | - * _events_export |
|
731 | - * Will export all (or just the given event) to a Excel compatible file. |
|
732 | - * |
|
733 | - * @access protected |
|
734 | - * @return void |
|
735 | - */ |
|
736 | - protected function _events_export() |
|
737 | - { |
|
738 | - if (isset($this->_req_data['EVT_ID'])) { |
|
739 | - $event_ids = $this->_req_data['EVT_ID']; |
|
740 | - } elseif (isset($this->_req_data['EVT_IDs'])) { |
|
741 | - $event_ids = $this->_req_data['EVT_IDs']; |
|
742 | - } else { |
|
743 | - $event_ids = null; |
|
744 | - } |
|
745 | - //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
746 | - $new_request_args = array( |
|
747 | - 'export' => 'report', |
|
748 | - 'action' => 'all_event_data', |
|
749 | - 'EVT_ID' => $event_ids, |
|
750 | - ); |
|
751 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
752 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
753 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
754 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
755 | - $EE_Export->export(); |
|
756 | - } |
|
757 | - } |
|
758 | - |
|
759 | - |
|
760 | - /** |
|
761 | - * handle category exports() |
|
762 | - * |
|
763 | - * @return void |
|
764 | - */ |
|
765 | - protected function _categories_export() |
|
766 | - { |
|
767 | - //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
768 | - $new_request_args = array( |
|
769 | - 'export' => 'report', |
|
770 | - 'action' => 'categories', |
|
771 | - 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
772 | - ); |
|
773 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
774 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
775 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
776 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
777 | - $EE_Export->export(); |
|
778 | - } |
|
779 | - } |
|
780 | - |
|
781 | - |
|
782 | - /** |
|
783 | - * Creates a sample CSV file for importing |
|
784 | - */ |
|
785 | - protected function _sample_export_file() |
|
786 | - { |
|
787 | - // require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
788 | - EE_Export::instance()->export_sample(); |
|
789 | - } |
|
790 | - |
|
791 | - |
|
792 | - /************* Template Settings *************/ |
|
793 | - /** |
|
794 | - * Generates template settings page output |
|
795 | - * @throws DomainException |
|
796 | - * @throws EE_Error |
|
797 | - */ |
|
798 | - protected function _template_settings() |
|
799 | - { |
|
800 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
801 | - /** |
|
802 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
803 | - * from General_Settings_Admin_Page to here. |
|
804 | - */ |
|
805 | - $this->_template_args = apply_filters( |
|
806 | - 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
807 | - $this->_template_args |
|
808 | - ); |
|
809 | - $this->_set_add_edit_form_tags('update_template_settings'); |
|
810 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
811 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
812 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
813 | - $this->_template_args, |
|
814 | - true |
|
815 | - ); |
|
816 | - $this->display_admin_page_with_sidebar(); |
|
817 | - } |
|
818 | - |
|
819 | - |
|
820 | - /** |
|
821 | - * Handler for updating template settings. |
|
822 | - */ |
|
823 | - protected function _update_template_settings() |
|
824 | - { |
|
825 | - /** |
|
826 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
827 | - * from General_Settings_Admin_Page to here. |
|
828 | - */ |
|
829 | - EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
830 | - 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
831 | - EE_Registry::instance()->CFG->template_settings, |
|
832 | - $this->_req_data |
|
833 | - ); |
|
834 | - //update custom post type slugs and detect if we need to flush rewrite rules |
|
835 | - $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
836 | - EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
837 | - ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
838 | - : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']); |
|
839 | - $what = 'Template Settings'; |
|
840 | - $success = $this->_update_espresso_configuration( |
|
841 | - $what, |
|
842 | - EE_Registry::instance()->CFG->template_settings, |
|
843 | - __FILE__, |
|
844 | - __FUNCTION__, |
|
845 | - __LINE__ |
|
846 | - ); |
|
847 | - if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
848 | - update_option('ee_flush_rewrite_rules', true); |
|
849 | - } |
|
850 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings')); |
|
851 | - } |
|
852 | - |
|
853 | - |
|
854 | - /** |
|
855 | - * _premium_event_editor_meta_boxes |
|
856 | - * add all metaboxes related to the event_editor |
|
857 | - * |
|
858 | - * @access protected |
|
859 | - * @return void |
|
860 | - * @throws EE_Error |
|
861 | - */ |
|
862 | - protected function _premium_event_editor_meta_boxes() |
|
863 | - { |
|
864 | - $this->verify_cpt_object(); |
|
865 | - add_meta_box( |
|
866 | - 'espresso_event_editor_event_options', |
|
867 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
868 | - array($this, 'registration_options_meta_box'), |
|
869 | - $this->page_slug, |
|
870 | - 'side', |
|
871 | - 'core' |
|
872 | - ); |
|
873 | - } |
|
874 | - |
|
875 | - |
|
876 | - /** |
|
877 | - * override caf metabox |
|
878 | - * |
|
879 | - * @return void |
|
880 | - * @throws DomainException |
|
881 | - */ |
|
882 | - public function registration_options_meta_box() |
|
883 | - { |
|
884 | - $yes_no_values = array( |
|
885 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
886 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
887 | - ); |
|
888 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
889 | - array( |
|
890 | - EEM_Registration::status_id_cancelled, |
|
891 | - EEM_Registration::status_id_declined, |
|
892 | - EEM_Registration::status_id_incomplete, |
|
893 | - EEM_Registration::status_id_wait_list, |
|
894 | - ), |
|
895 | - true |
|
896 | - ); |
|
897 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
898 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
899 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
900 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
901 | - 'default_reg_status', |
|
902 | - $default_reg_status_values, |
|
903 | - $this->_cpt_model_obj->default_registration_status() |
|
904 | - ); |
|
905 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
906 | - 'display_desc', |
|
907 | - $yes_no_values, |
|
908 | - $this->_cpt_model_obj->display_description() |
|
909 | - ); |
|
910 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
911 | - 'display_ticket_selector', |
|
912 | - $yes_no_values, |
|
913 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
914 | - '', |
|
915 | - '', |
|
916 | - false |
|
917 | - ); |
|
918 | - $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
919 | - 'EVT_default_registration_status', |
|
920 | - $default_reg_status_values, |
|
921 | - $this->_cpt_model_obj->default_registration_status() |
|
922 | - ); |
|
923 | - $template_args['additional_registration_options'] = apply_filters( |
|
924 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
925 | - '', |
|
926 | - $template_args, |
|
927 | - $yes_no_values, |
|
928 | - $default_reg_status_values |
|
929 | - ); |
|
930 | - EEH_Template::display_template( |
|
931 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
932 | - $template_args |
|
933 | - ); |
|
934 | - } |
|
935 | - |
|
936 | - |
|
937 | - |
|
938 | - /** |
|
939 | - * wp_list_table_mods for caf |
|
940 | - * ============================ |
|
941 | - */ |
|
942 | - /** |
|
943 | - * hook into list table filters and provide filters for caffeinated list table |
|
944 | - * |
|
945 | - * @param array $old_filters any existing filters present |
|
946 | - * @param array $list_table_obj the list table object |
|
947 | - * @return array new filters |
|
948 | - */ |
|
949 | - public function list_table_filters($old_filters, $list_table_obj) |
|
950 | - { |
|
951 | - $filters = array(); |
|
952 | - //first month/year filters |
|
953 | - $filters[] = $this->espresso_event_months_dropdown(); |
|
954 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
955 | - //active status dropdown |
|
956 | - if ($status !== 'draft') { |
|
957 | - $filters[] = $this->active_status_dropdown( |
|
958 | - isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
959 | - ); |
|
960 | - } |
|
961 | - //category filter |
|
962 | - $filters[] = $this->category_dropdown(); |
|
963 | - return array_merge($old_filters, $filters); |
|
964 | - } |
|
965 | - |
|
966 | - |
|
967 | - /** |
|
968 | - * espresso_event_months_dropdown |
|
969 | - * |
|
970 | - * @access public |
|
971 | - * @return string dropdown listing month/year selections for events. |
|
972 | - */ |
|
973 | - public function espresso_event_months_dropdown() |
|
974 | - { |
|
975 | - // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
976 | - // Note we need to include any other filters that are set! |
|
977 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
978 | - //categories? |
|
979 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
980 | - ? $this->_req_data['EVT_CAT'] |
|
981 | - : null; |
|
982 | - //active status? |
|
983 | - $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
984 | - $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
985 | - return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
986 | - } |
|
987 | - |
|
988 | - |
|
989 | - /** |
|
990 | - * returns a list of "active" statuses on the event |
|
991 | - * |
|
992 | - * @param string $current_value whatever the current active status is |
|
993 | - * @return string |
|
994 | - */ |
|
995 | - public function active_status_dropdown($current_value = '') |
|
996 | - { |
|
997 | - $select_name = 'active_status'; |
|
998 | - $values = array( |
|
999 | - 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
1000 | - 'active' => esc_html__('Active', 'event_espresso'), |
|
1001 | - 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
1002 | - 'expired' => esc_html__('Expired', 'event_espresso'), |
|
1003 | - 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
1004 | - ); |
|
1005 | - $id = 'id="espresso-active-status-dropdown-filter"'; |
|
1006 | - $class = 'wide'; |
|
1007 | - return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class); |
|
1008 | - } |
|
1009 | - |
|
1010 | - |
|
1011 | - /** |
|
1012 | - * output a dropdown of the categories for the category filter on the event admin list table |
|
1013 | - * |
|
1014 | - * @access public |
|
1015 | - * @return string html |
|
1016 | - */ |
|
1017 | - public function category_dropdown() |
|
1018 | - { |
|
1019 | - $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
1020 | - return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
1021 | - } |
|
1022 | - |
|
1023 | - |
|
1024 | - /** |
|
1025 | - * get total number of events today |
|
1026 | - * |
|
1027 | - * @access public |
|
1028 | - * @return int |
|
1029 | - * @throws EE_Error |
|
1030 | - */ |
|
1031 | - public function total_events_today() |
|
1032 | - { |
|
1033 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1034 | - 'DTT_EVT_start', |
|
1035 | - date('Y-m-d') . ' 00:00:00', |
|
1036 | - 'Y-m-d H:i:s', |
|
1037 | - 'UTC' |
|
1038 | - ); |
|
1039 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1040 | - 'DTT_EVT_start', |
|
1041 | - date('Y-m-d') . ' 23:59:59', |
|
1042 | - 'Y-m-d H:i:s', |
|
1043 | - 'UTC' |
|
1044 | - ); |
|
1045 | - $where = array( |
|
1046 | - 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
1047 | - ); |
|
1048 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
1049 | - return $count; |
|
1050 | - } |
|
1051 | - |
|
1052 | - |
|
1053 | - /** |
|
1054 | - * get total number of events this month |
|
1055 | - * |
|
1056 | - * @access public |
|
1057 | - * @return int |
|
1058 | - * @throws EE_Error |
|
1059 | - */ |
|
1060 | - public function total_events_this_month() |
|
1061 | - { |
|
1062 | - //Dates |
|
1063 | - $this_year_r = date('Y'); |
|
1064 | - $this_month_r = date('m'); |
|
1065 | - $days_this_month = date('t'); |
|
1066 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1067 | - 'DTT_EVT_start', |
|
1068 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
1069 | - 'Y-m-d H:i:s', |
|
1070 | - 'UTC' |
|
1071 | - ); |
|
1072 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1073 | - 'DTT_EVT_start', |
|
1074 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
1075 | - 'Y-m-d H:i:s', |
|
1076 | - 'UTC' |
|
1077 | - ); |
|
1078 | - $where = array( |
|
1079 | - 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
1080 | - ); |
|
1081 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
1082 | - return $count; |
|
1083 | - } |
|
1084 | - |
|
1085 | - |
|
1086 | - /** DEFAULT TICKETS STUFF **/ |
|
1087 | - |
|
1088 | - /** |
|
1089 | - * Output default tickets list table view. |
|
1090 | - */ |
|
1091 | - public function _tickets_overview_list_table() |
|
1092 | - { |
|
1093 | - $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
1094 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
1095 | - } |
|
1096 | - |
|
1097 | - |
|
1098 | - /** |
|
1099 | - * @param int $per_page |
|
1100 | - * @param bool $count |
|
1101 | - * @param bool $trashed |
|
1102 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
1103 | - */ |
|
1104 | - public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
1105 | - { |
|
1106 | - $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
1107 | - $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
1108 | - switch ($orderby) { |
|
1109 | - case 'TKT_name': |
|
1110 | - $orderby = array('TKT_name' => $order); |
|
1111 | - break; |
|
1112 | - case 'TKT_price': |
|
1113 | - $orderby = array('TKT_price' => $order); |
|
1114 | - break; |
|
1115 | - case 'TKT_uses': |
|
1116 | - $orderby = array('TKT_uses' => $order); |
|
1117 | - break; |
|
1118 | - case 'TKT_min': |
|
1119 | - $orderby = array('TKT_min' => $order); |
|
1120 | - break; |
|
1121 | - case 'TKT_max': |
|
1122 | - $orderby = array('TKT_max' => $order); |
|
1123 | - break; |
|
1124 | - case 'TKT_qty': |
|
1125 | - $orderby = array('TKT_qty' => $order); |
|
1126 | - break; |
|
1127 | - } |
|
1128 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
1129 | - ? $this->_req_data['paged'] |
|
1130 | - : 1; |
|
1131 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
1132 | - ? $this->_req_data['perpage'] |
|
1133 | - : $per_page; |
|
1134 | - $_where = array( |
|
1135 | - 'TKT_is_default' => 1, |
|
1136 | - 'TKT_deleted' => $trashed, |
|
1137 | - ); |
|
1138 | - $offset = ($current_page - 1) * $per_page; |
|
1139 | - $limit = array($offset, $per_page); |
|
1140 | - if (isset($this->_req_data['s'])) { |
|
1141 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
1142 | - $_where['OR'] = array( |
|
1143 | - 'TKT_name' => array('LIKE', $sstr), |
|
1144 | - 'TKT_description' => array('LIKE', $sstr), |
|
1145 | - ); |
|
1146 | - } |
|
1147 | - $query_params = array( |
|
1148 | - $_where, |
|
1149 | - 'order_by' => $orderby, |
|
1150 | - 'limit' => $limit, |
|
1151 | - 'group_by' => 'TKT_ID', |
|
1152 | - ); |
|
1153 | - if ($count) { |
|
1154 | - return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where)); |
|
1155 | - } else { |
|
1156 | - return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
1157 | - } |
|
1158 | - } |
|
1159 | - |
|
1160 | - |
|
1161 | - /** |
|
1162 | - * @param bool $trash |
|
1163 | - * @throws EE_Error |
|
1164 | - */ |
|
1165 | - protected function _trash_or_restore_ticket($trash = false) |
|
1166 | - { |
|
1167 | - $success = 1; |
|
1168 | - $TKT = EEM_Ticket::instance(); |
|
1169 | - //checkboxes? |
|
1170 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1171 | - //if array has more than one element then success message should be plural |
|
1172 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1173 | - //cycle thru the boxes |
|
1174 | - while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1175 | - if ($trash) { |
|
1176 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1177 | - $success = 0; |
|
1178 | - } |
|
1179 | - } else { |
|
1180 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1181 | - $success = 0; |
|
1182 | - } |
|
1183 | - } |
|
1184 | - } |
|
1185 | - } else { |
|
1186 | - //grab single id and trash |
|
1187 | - $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
1188 | - if ($trash) { |
|
1189 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1190 | - $success = 0; |
|
1191 | - } |
|
1192 | - } else { |
|
1193 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1194 | - $success = 0; |
|
1195 | - } |
|
1196 | - } |
|
1197 | - } |
|
1198 | - $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
1199 | - $query_args = array( |
|
1200 | - 'action' => 'ticket_list_table', |
|
1201 | - 'status' => $trash ? '' : 'trashed', |
|
1202 | - ); |
|
1203 | - $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
1204 | - } |
|
1205 | - |
|
1206 | - |
|
1207 | - /** |
|
1208 | - * Handles trashing default ticket. |
|
1209 | - */ |
|
1210 | - protected function _delete_ticket() |
|
1211 | - { |
|
1212 | - $success = 1; |
|
1213 | - //checkboxes? |
|
1214 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1215 | - //if array has more than one element then success message should be plural |
|
1216 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1217 | - //cycle thru the boxes |
|
1218 | - while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1219 | - //delete |
|
1220 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1221 | - $success = 0; |
|
1222 | - } |
|
1223 | - } |
|
1224 | - } else { |
|
1225 | - //grab single id and trash |
|
1226 | - $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
1227 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1228 | - $success = 0; |
|
1229 | - } |
|
1230 | - } |
|
1231 | - $action_desc = 'deleted'; |
|
1232 | - $query_args = array( |
|
1233 | - 'action' => 'ticket_list_table', |
|
1234 | - 'status' => 'trashed', |
|
1235 | - ); |
|
1236 | - //fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
1237 | - if (EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
1238 | - array(array('TKT_is_default' => 1)), |
|
1239 | - 'TKT_ID', |
|
1240 | - true |
|
1241 | - ) |
|
1242 | - ) { |
|
1243 | - $query_args = array(); |
|
1244 | - } |
|
1245 | - $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
1246 | - } |
|
1247 | - |
|
1248 | - |
|
1249 | - /** |
|
1250 | - * @param int $TKT_ID |
|
1251 | - * @return bool|int |
|
1252 | - * @throws EE_Error |
|
1253 | - */ |
|
1254 | - protected function _delete_the_ticket($TKT_ID) |
|
1255 | - { |
|
1256 | - $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
1257 | - $tkt->_remove_relations('Datetime'); |
|
1258 | - //delete all related prices first |
|
1259 | - $tkt->delete_related_permanently('Price'); |
|
1260 | - return $tkt->delete_permanently(); |
|
1261 | - } |
|
17 | + /** |
|
18 | + * Extend_Events_Admin_Page constructor. |
|
19 | + * |
|
20 | + * @param bool $routing |
|
21 | + */ |
|
22 | + public function __construct($routing = true) |
|
23 | + { |
|
24 | + parent::__construct($routing); |
|
25 | + if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
26 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
27 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
28 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
29 | + } |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * Sets routes. |
|
35 | + */ |
|
36 | + protected function _extend_page_config() |
|
37 | + { |
|
38 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
39 | + //is there a evt_id in the request? |
|
40 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
41 | + ? $this->_req_data['EVT_ID'] |
|
42 | + : 0; |
|
43 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
44 | + //tkt_id? |
|
45 | + $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
46 | + ? $this->_req_data['TKT_ID'] |
|
47 | + : 0; |
|
48 | + $new_page_routes = array( |
|
49 | + 'duplicate_event' => array( |
|
50 | + 'func' => '_duplicate_event', |
|
51 | + 'capability' => 'ee_edit_event', |
|
52 | + 'obj_id' => $evt_id, |
|
53 | + 'noheader' => true, |
|
54 | + ), |
|
55 | + 'ticket_list_table' => array( |
|
56 | + 'func' => '_tickets_overview_list_table', |
|
57 | + 'capability' => 'ee_read_default_tickets', |
|
58 | + ), |
|
59 | + 'trash_ticket' => array( |
|
60 | + 'func' => '_trash_or_restore_ticket', |
|
61 | + 'capability' => 'ee_delete_default_ticket', |
|
62 | + 'obj_id' => $tkt_id, |
|
63 | + 'noheader' => true, |
|
64 | + 'args' => array('trash' => true), |
|
65 | + ), |
|
66 | + 'trash_tickets' => array( |
|
67 | + 'func' => '_trash_or_restore_ticket', |
|
68 | + 'capability' => 'ee_delete_default_tickets', |
|
69 | + 'noheader' => true, |
|
70 | + 'args' => array('trash' => true), |
|
71 | + ), |
|
72 | + 'restore_ticket' => array( |
|
73 | + 'func' => '_trash_or_restore_ticket', |
|
74 | + 'capability' => 'ee_delete_default_ticket', |
|
75 | + 'obj_id' => $tkt_id, |
|
76 | + 'noheader' => true, |
|
77 | + ), |
|
78 | + 'restore_tickets' => array( |
|
79 | + 'func' => '_trash_or_restore_ticket', |
|
80 | + 'capability' => 'ee_delete_default_tickets', |
|
81 | + 'noheader' => true, |
|
82 | + ), |
|
83 | + 'delete_ticket' => array( |
|
84 | + 'func' => '_delete_ticket', |
|
85 | + 'capability' => 'ee_delete_default_ticket', |
|
86 | + 'obj_id' => $tkt_id, |
|
87 | + 'noheader' => true, |
|
88 | + ), |
|
89 | + 'delete_tickets' => array( |
|
90 | + 'func' => '_delete_ticket', |
|
91 | + 'capability' => 'ee_delete_default_tickets', |
|
92 | + 'noheader' => true, |
|
93 | + ), |
|
94 | + 'import_page' => array( |
|
95 | + 'func' => '_import_page', |
|
96 | + 'capability' => 'import', |
|
97 | + ), |
|
98 | + 'import' => array( |
|
99 | + 'func' => '_import_events', |
|
100 | + 'capability' => 'import', |
|
101 | + 'noheader' => true, |
|
102 | + ), |
|
103 | + 'import_events' => array( |
|
104 | + 'func' => '_import_events', |
|
105 | + 'capability' => 'import', |
|
106 | + 'noheader' => true, |
|
107 | + ), |
|
108 | + 'export_events' => array( |
|
109 | + 'func' => '_events_export', |
|
110 | + 'capability' => 'export', |
|
111 | + 'noheader' => true, |
|
112 | + ), |
|
113 | + 'export_categories' => array( |
|
114 | + 'func' => '_categories_export', |
|
115 | + 'capability' => 'export', |
|
116 | + 'noheader' => true, |
|
117 | + ), |
|
118 | + 'sample_export_file' => array( |
|
119 | + 'func' => '_sample_export_file', |
|
120 | + 'capability' => 'export', |
|
121 | + 'noheader' => true, |
|
122 | + ), |
|
123 | + 'update_template_settings' => array( |
|
124 | + 'func' => '_update_template_settings', |
|
125 | + 'capability' => 'manage_options', |
|
126 | + 'noheader' => true, |
|
127 | + ), |
|
128 | + ); |
|
129 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
130 | + //partial route/config override |
|
131 | + $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
132 | + $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
133 | + $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
134 | + $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
135 | + $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
136 | + $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
137 | + //add tickets tab but only if there are more than one default ticket! |
|
138 | + $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
139 | + array(array('TKT_is_default' => 1)), |
|
140 | + 'TKT_ID', |
|
141 | + true |
|
142 | + ); |
|
143 | + if ($tkt_count > 1) { |
|
144 | + $new_page_config = array( |
|
145 | + 'ticket_list_table' => array( |
|
146 | + 'nav' => array( |
|
147 | + 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
148 | + 'order' => 60, |
|
149 | + ), |
|
150 | + 'list_table' => 'Tickets_List_Table', |
|
151 | + 'require_nonce' => false, |
|
152 | + ), |
|
153 | + ); |
|
154 | + } |
|
155 | + //template settings |
|
156 | + $new_page_config['template_settings'] = array( |
|
157 | + 'nav' => array( |
|
158 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
159 | + 'order' => 30, |
|
160 | + ), |
|
161 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
162 | + 'help_tabs' => array( |
|
163 | + 'general_settings_templates_help_tab' => array( |
|
164 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
165 | + 'filename' => 'general_settings_templates', |
|
166 | + ), |
|
167 | + ), |
|
168 | + 'help_tour' => array('Templates_Help_Tour'), |
|
169 | + 'require_nonce' => false, |
|
170 | + ); |
|
171 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
172 | + //add filters and actions |
|
173 | + //modifying _views |
|
174 | + add_filter( |
|
175 | + 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
176 | + array($this, 'add_additional_datetime_button'), |
|
177 | + 10, |
|
178 | + 2 |
|
179 | + ); |
|
180 | + add_filter( |
|
181 | + 'FHEE_event_datetime_metabox_clone_button_template', |
|
182 | + array($this, 'add_datetime_clone_button'), |
|
183 | + 10, |
|
184 | + 2 |
|
185 | + ); |
|
186 | + add_filter( |
|
187 | + 'FHEE_event_datetime_metabox_timezones_template', |
|
188 | + array($this, 'datetime_timezones_template'), |
|
189 | + 10, |
|
190 | + 2 |
|
191 | + ); |
|
192 | + //filters for event list table |
|
193 | + add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2); |
|
194 | + add_filter( |
|
195 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
196 | + array($this, 'extra_list_table_actions'), |
|
197 | + 10, |
|
198 | + 2 |
|
199 | + ); |
|
200 | + //legend item |
|
201 | + add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items')); |
|
202 | + add_action('admin_init', array($this, 'admin_init')); |
|
203 | + //heartbeat stuff |
|
204 | + add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2); |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * admin_init |
|
210 | + */ |
|
211 | + public function admin_init() |
|
212 | + { |
|
213 | + EE_Registry::$i18n_js_strings = array_merge( |
|
214 | + EE_Registry::$i18n_js_strings, |
|
215 | + array( |
|
216 | + 'image_confirm' => esc_html__( |
|
217 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
218 | + 'event_espresso' |
|
219 | + ), |
|
220 | + 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
221 | + 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
222 | + 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
223 | + 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
224 | + 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
225 | + ) |
|
226 | + ); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle |
|
232 | + * accordingly. |
|
233 | + * |
|
234 | + * @param array $response The existing heartbeat response array. |
|
235 | + * @param array $data The incoming data package. |
|
236 | + * @return array possibly appended response. |
|
237 | + */ |
|
238 | + public function heartbeat_response($response, $data) |
|
239 | + { |
|
240 | + /** |
|
241 | + * check whether count of tickets is approaching the potential |
|
242 | + * limits for the server. |
|
243 | + */ |
|
244 | + if (! empty($data['input_count'])) { |
|
245 | + $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check( |
|
246 | + $data['input_count'] |
|
247 | + ); |
|
248 | + } |
|
249 | + return $response; |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * Add per page screen options to the default ticket list table view. |
|
255 | + */ |
|
256 | + protected function _add_screen_options_ticket_list_table() |
|
257 | + { |
|
258 | + $this->_per_page_screen_option(); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @param string $return |
|
264 | + * @param int $id |
|
265 | + * @param string $new_title |
|
266 | + * @param string $new_slug |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
270 | + { |
|
271 | + $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
272 | + //make sure this is only when editing |
|
273 | + if (! empty($id)) { |
|
274 | + $href = EE_Admin_Page::add_query_args_and_nonce( |
|
275 | + array('action' => 'duplicate_event', 'EVT_ID' => $id), |
|
276 | + $this->_admin_base_url |
|
277 | + ); |
|
278 | + $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
279 | + $return .= '<a href="' |
|
280 | + . $href |
|
281 | + . '" title="' |
|
282 | + . $title |
|
283 | + . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
284 | + . $title |
|
285 | + . '</button>'; |
|
286 | + } |
|
287 | + return $return; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * Set the list table views for the default ticket list table view. |
|
293 | + */ |
|
294 | + public function _set_list_table_views_ticket_list_table() |
|
295 | + { |
|
296 | + $this->_views = array( |
|
297 | + 'all' => array( |
|
298 | + 'slug' => 'all', |
|
299 | + 'label' => esc_html__('All', 'event_espresso'), |
|
300 | + 'count' => 0, |
|
301 | + 'bulk_action' => array( |
|
302 | + 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
303 | + ), |
|
304 | + ), |
|
305 | + 'trashed' => array( |
|
306 | + 'slug' => 'trashed', |
|
307 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
308 | + 'count' => 0, |
|
309 | + 'bulk_action' => array( |
|
310 | + 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
311 | + 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
312 | + ), |
|
313 | + ), |
|
314 | + ); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Enqueue scripts and styles for the event editor. |
|
320 | + */ |
|
321 | + public function load_scripts_styles_edit() |
|
322 | + { |
|
323 | + wp_register_script( |
|
324 | + 'ee-event-editor-heartbeat', |
|
325 | + EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
326 | + array('ee_admin_js', 'heartbeat'), |
|
327 | + EVENT_ESPRESSO_VERSION, |
|
328 | + true |
|
329 | + ); |
|
330 | + wp_enqueue_script('ee-accounting'); |
|
331 | + //styles |
|
332 | + wp_enqueue_style('espresso-ui-theme'); |
|
333 | + wp_enqueue_script('event_editor_js'); |
|
334 | + wp_enqueue_script('ee-event-editor-heartbeat'); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Returns template for the additional datetime. |
|
340 | + * @param $template |
|
341 | + * @param $template_args |
|
342 | + * @return mixed |
|
343 | + * @throws DomainException |
|
344 | + */ |
|
345 | + public function add_additional_datetime_button($template, $template_args) |
|
346 | + { |
|
347 | + return EEH_Template::display_template( |
|
348 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
349 | + $template_args, |
|
350 | + true |
|
351 | + ); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Returns the template for cloning a datetime. |
|
357 | + * @param $template |
|
358 | + * @param $template_args |
|
359 | + * @return mixed |
|
360 | + * @throws DomainException |
|
361 | + */ |
|
362 | + public function add_datetime_clone_button($template, $template_args) |
|
363 | + { |
|
364 | + return EEH_Template::display_template( |
|
365 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
366 | + $template_args, |
|
367 | + true |
|
368 | + ); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Returns the template for datetime timezones. |
|
374 | + * @param $template |
|
375 | + * @param $template_args |
|
376 | + * @return mixed |
|
377 | + * @throws DomainException |
|
378 | + */ |
|
379 | + public function datetime_timezones_template($template, $template_args) |
|
380 | + { |
|
381 | + return EEH_Template::display_template( |
|
382 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
383 | + $template_args, |
|
384 | + true |
|
385 | + ); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * Sets the views for the default list table view. |
|
391 | + */ |
|
392 | + protected function _set_list_table_views_default() |
|
393 | + { |
|
394 | + parent::_set_list_table_views_default(); |
|
395 | + $new_views = array( |
|
396 | + 'today' => array( |
|
397 | + 'slug' => 'today', |
|
398 | + 'label' => esc_html__('Today', 'event_espresso'), |
|
399 | + 'count' => $this->total_events_today(), |
|
400 | + 'bulk_action' => array( |
|
401 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
402 | + ), |
|
403 | + ), |
|
404 | + 'month' => array( |
|
405 | + 'slug' => 'month', |
|
406 | + 'label' => esc_html__('This Month', 'event_espresso'), |
|
407 | + 'count' => $this->total_events_this_month(), |
|
408 | + 'bulk_action' => array( |
|
409 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
410 | + ), |
|
411 | + ), |
|
412 | + ); |
|
413 | + $this->_views = array_merge($this->_views, $new_views); |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * Returns the extra action links for the default list table view. |
|
419 | + * @param array $action_links |
|
420 | + * @param \EE_Event $event |
|
421 | + * @return array |
|
422 | + * @throws EE_Error |
|
423 | + */ |
|
424 | + public function extra_list_table_actions(array $action_links, \EE_Event $event) |
|
425 | + { |
|
426 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
427 | + 'ee_read_registrations', |
|
428 | + 'espresso_registrations_reports', |
|
429 | + $event->ID() |
|
430 | + ) |
|
431 | + ) { |
|
432 | + $reports_query_args = array( |
|
433 | + 'action' => 'reports', |
|
434 | + 'EVT_ID' => $event->ID(), |
|
435 | + ); |
|
436 | + $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
437 | + $action_links[] = '<a href="' |
|
438 | + . $reports_link |
|
439 | + . '" title="' |
|
440 | + . esc_attr__('View Report', 'event_espresso') |
|
441 | + . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
442 | + . "\n\t"; |
|
443 | + } |
|
444 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
445 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
446 | + $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
447 | + 'see_notifications_for', |
|
448 | + null, |
|
449 | + array('EVT_ID' => $event->ID()) |
|
450 | + ); |
|
451 | + } |
|
452 | + return $action_links; |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * @param $items |
|
458 | + * @return mixed |
|
459 | + */ |
|
460 | + public function additional_legend_items($items) |
|
461 | + { |
|
462 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
463 | + 'ee_read_registrations', |
|
464 | + 'espresso_registrations_reports' |
|
465 | + ) |
|
466 | + ) { |
|
467 | + $items['reports'] = array( |
|
468 | + 'class' => 'dashicons dashicons-chart-bar', |
|
469 | + 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
470 | + ); |
|
471 | + } |
|
472 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
473 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
474 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
475 | + $items['view_related_messages'] = array( |
|
476 | + 'class' => $related_for_icon['css_class'], |
|
477 | + 'desc' => $related_for_icon['label'], |
|
478 | + ); |
|
479 | + } |
|
480 | + } |
|
481 | + return $items; |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * This is the callback method for the duplicate event route |
|
487 | + * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
488 | + * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
489 | + * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
490 | + * After duplication the redirect is to the new event edit page. |
|
491 | + * |
|
492 | + * @return void |
|
493 | + * @access protected |
|
494 | + * @throws EE_Error If EE_Event is not available with given ID |
|
495 | + */ |
|
496 | + protected function _duplicate_event() |
|
497 | + { |
|
498 | + // first make sure the ID for the event is in the request. |
|
499 | + // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
500 | + if (! isset($this->_req_data['EVT_ID'])) { |
|
501 | + EE_Error::add_error( |
|
502 | + esc_html__( |
|
503 | + 'In order to duplicate an event an Event ID is required. None was given.', |
|
504 | + 'event_espresso' |
|
505 | + ), |
|
506 | + __FILE__, |
|
507 | + __FUNCTION__, |
|
508 | + __LINE__ |
|
509 | + ); |
|
510 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
511 | + return; |
|
512 | + } |
|
513 | + //k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
514 | + $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
515 | + if (! $orig_event instanceof EE_Event) { |
|
516 | + throw new EE_Error( |
|
517 | + sprintf( |
|
518 | + esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
519 | + $this->_req_data['EVT_ID'] |
|
520 | + ) |
|
521 | + ); |
|
522 | + } |
|
523 | + //k now let's clone the $orig_event before getting relations |
|
524 | + $new_event = clone $orig_event; |
|
525 | + //original datetimes |
|
526 | + $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
527 | + //other original relations |
|
528 | + $orig_ven = $orig_event->get_many_related('Venue'); |
|
529 | + //reset the ID and modify other details to make it clear this is a dupe |
|
530 | + $new_event->set('EVT_ID', 0); |
|
531 | + $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
532 | + $new_event->set('EVT_name', $new_name); |
|
533 | + $new_event->set( |
|
534 | + 'EVT_slug', |
|
535 | + wp_unique_post_slug( |
|
536 | + sanitize_title($orig_event->name()), |
|
537 | + 0, |
|
538 | + 'publish', |
|
539 | + 'espresso_events', |
|
540 | + 0 |
|
541 | + ) |
|
542 | + ); |
|
543 | + $new_event->set('status', 'draft'); |
|
544 | + //duplicate discussion settings |
|
545 | + $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
546 | + $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
547 | + //save the new event |
|
548 | + $new_event->save(); |
|
549 | + //venues |
|
550 | + foreach ($orig_ven as $ven) { |
|
551 | + $new_event->_add_relation_to($ven, 'Venue'); |
|
552 | + } |
|
553 | + $new_event->save(); |
|
554 | + //now we need to get the question group relations and handle that |
|
555 | + //first primary question groups |
|
556 | + $orig_primary_qgs = $orig_event->get_many_related( |
|
557 | + 'Question_Group', |
|
558 | + array(array('Event_Question_Group.EQG_primary' => 1)) |
|
559 | + ); |
|
560 | + if (! empty($orig_primary_qgs)) { |
|
561 | + foreach ($orig_primary_qgs as $id => $obj) { |
|
562 | + if ($obj instanceof EE_Question_Group) { |
|
563 | + $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1)); |
|
564 | + } |
|
565 | + } |
|
566 | + } |
|
567 | + //next additional attendee question groups |
|
568 | + $orig_additional_qgs = $orig_event->get_many_related( |
|
569 | + 'Question_Group', |
|
570 | + array(array('Event_Question_Group.EQG_primary' => 0)) |
|
571 | + ); |
|
572 | + if (! empty($orig_additional_qgs)) { |
|
573 | + foreach ($orig_additional_qgs as $id => $obj) { |
|
574 | + if ($obj instanceof EE_Question_Group) { |
|
575 | + $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0)); |
|
576 | + } |
|
577 | + } |
|
578 | + } |
|
579 | + //now save |
|
580 | + $new_event->save(); |
|
581 | + //k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
582 | + $cloned_tickets = array(); |
|
583 | + foreach ($orig_datetimes as $orig_dtt) { |
|
584 | + if (! $orig_dtt instanceof EE_Datetime) { |
|
585 | + continue; |
|
586 | + } |
|
587 | + $new_dtt = clone $orig_dtt; |
|
588 | + $orig_tkts = $orig_dtt->tickets(); |
|
589 | + //save new dtt then add to event |
|
590 | + $new_dtt->set('DTT_ID', 0); |
|
591 | + $new_dtt->set('DTT_sold', 0); |
|
592 | + $new_dtt->set_reserved(0); |
|
593 | + $new_dtt->save(); |
|
594 | + $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
595 | + $new_event->save(); |
|
596 | + //now let's get the ticket relations setup. |
|
597 | + foreach ((array)$orig_tkts as $orig_tkt) { |
|
598 | + //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
599 | + if (! $orig_tkt instanceof EE_Ticket) { |
|
600 | + continue; |
|
601 | + } |
|
602 | + //is this ticket archived? If it is then let's skip |
|
603 | + if ($orig_tkt->get('TKT_deleted')) { |
|
604 | + continue; |
|
605 | + } |
|
606 | + // does this original ticket already exist in the clone_tickets cache? |
|
607 | + // If so we'll just use the new ticket from it. |
|
608 | + if (isset($cloned_tickets[$orig_tkt->ID()])) { |
|
609 | + $new_tkt = $cloned_tickets[$orig_tkt->ID()]; |
|
610 | + } else { |
|
611 | + $new_tkt = clone $orig_tkt; |
|
612 | + //get relations on the $orig_tkt that we need to setup. |
|
613 | + $orig_prices = $orig_tkt->prices(); |
|
614 | + $new_tkt->set('TKT_ID', 0); |
|
615 | + $new_tkt->set('TKT_sold', 0); |
|
616 | + $new_tkt->set('TKT_reserved', 0); |
|
617 | + $new_tkt->save(); //make sure new ticket has ID. |
|
618 | + //price relations on new ticket need to be setup. |
|
619 | + foreach ($orig_prices as $orig_price) { |
|
620 | + $new_price = clone $orig_price; |
|
621 | + $new_price->set('PRC_ID', 0); |
|
622 | + $new_price->save(); |
|
623 | + $new_tkt->_add_relation_to($new_price, 'Price'); |
|
624 | + $new_tkt->save(); |
|
625 | + } |
|
626 | + |
|
627 | + do_action( |
|
628 | + 'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after', |
|
629 | + $orig_tkt, |
|
630 | + $new_tkt, |
|
631 | + $orig_prices, |
|
632 | + $orig_event, |
|
633 | + $orig_dtt, |
|
634 | + $new_dtt |
|
635 | + ); |
|
636 | + } |
|
637 | + // k now we can add the new ticket as a relation to the new datetime |
|
638 | + // and make sure its added to our cached $cloned_tickets array |
|
639 | + // for use with later datetimes that have the same ticket. |
|
640 | + $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
641 | + $new_dtt->save(); |
|
642 | + $cloned_tickets[$orig_tkt->ID()] = $new_tkt; |
|
643 | + } |
|
644 | + } |
|
645 | + //clone taxonomy information |
|
646 | + $taxonomies_to_clone_with = apply_filters( |
|
647 | + 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
648 | + array('espresso_event_categories', 'espresso_event_type', 'post_tag') |
|
649 | + ); |
|
650 | + //get terms for original event (notice) |
|
651 | + $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
652 | + //loop through terms and add them to new event. |
|
653 | + foreach ($orig_terms as $term) { |
|
654 | + wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
655 | + } |
|
656 | + do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
657 | + //now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
658 | + if ($new_event->ID()) { |
|
659 | + $redirect_args = array( |
|
660 | + 'post' => $new_event->ID(), |
|
661 | + 'action' => 'edit', |
|
662 | + ); |
|
663 | + EE_Error::add_success( |
|
664 | + esc_html__( |
|
665 | + 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
666 | + 'event_espresso' |
|
667 | + ) |
|
668 | + ); |
|
669 | + } else { |
|
670 | + $redirect_args = array( |
|
671 | + 'action' => 'default', |
|
672 | + ); |
|
673 | + EE_Error::add_error( |
|
674 | + esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
675 | + __FILE__, |
|
676 | + __FUNCTION__, |
|
677 | + __LINE__ |
|
678 | + ); |
|
679 | + } |
|
680 | + $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
681 | + } |
|
682 | + |
|
683 | + |
|
684 | + /** |
|
685 | + * Generates output for the import page. |
|
686 | + * @throws DomainException |
|
687 | + */ |
|
688 | + protected function _import_page() |
|
689 | + { |
|
690 | + $title = esc_html__('Import', 'event_espresso'); |
|
691 | + $intro = esc_html__( |
|
692 | + 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
693 | + 'event_espresso' |
|
694 | + ); |
|
695 | + $form_url = EVENTS_ADMIN_URL; |
|
696 | + $action = 'import_events'; |
|
697 | + $type = 'csv'; |
|
698 | + $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
699 | + $title, $intro, $form_url, $action, $type |
|
700 | + ); |
|
701 | + $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
702 | + array('action' => 'sample_export_file'), |
|
703 | + $this->_admin_base_url |
|
704 | + ); |
|
705 | + $content = EEH_Template::display_template( |
|
706 | + EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
707 | + $this->_template_args, |
|
708 | + true |
|
709 | + ); |
|
710 | + $this->_template_args['admin_page_content'] = $content; |
|
711 | + $this->display_admin_page_with_sidebar(); |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * _import_events |
|
717 | + * This handles displaying the screen and running imports for importing events. |
|
718 | + * |
|
719 | + * @return void |
|
720 | + */ |
|
721 | + protected function _import_events() |
|
722 | + { |
|
723 | + require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
724 | + $success = EE_Import::instance()->import(); |
|
725 | + $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
|
726 | + } |
|
727 | + |
|
728 | + |
|
729 | + /** |
|
730 | + * _events_export |
|
731 | + * Will export all (or just the given event) to a Excel compatible file. |
|
732 | + * |
|
733 | + * @access protected |
|
734 | + * @return void |
|
735 | + */ |
|
736 | + protected function _events_export() |
|
737 | + { |
|
738 | + if (isset($this->_req_data['EVT_ID'])) { |
|
739 | + $event_ids = $this->_req_data['EVT_ID']; |
|
740 | + } elseif (isset($this->_req_data['EVT_IDs'])) { |
|
741 | + $event_ids = $this->_req_data['EVT_IDs']; |
|
742 | + } else { |
|
743 | + $event_ids = null; |
|
744 | + } |
|
745 | + //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
746 | + $new_request_args = array( |
|
747 | + 'export' => 'report', |
|
748 | + 'action' => 'all_event_data', |
|
749 | + 'EVT_ID' => $event_ids, |
|
750 | + ); |
|
751 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
752 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
753 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
754 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
755 | + $EE_Export->export(); |
|
756 | + } |
|
757 | + } |
|
758 | + |
|
759 | + |
|
760 | + /** |
|
761 | + * handle category exports() |
|
762 | + * |
|
763 | + * @return void |
|
764 | + */ |
|
765 | + protected function _categories_export() |
|
766 | + { |
|
767 | + //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
768 | + $new_request_args = array( |
|
769 | + 'export' => 'report', |
|
770 | + 'action' => 'categories', |
|
771 | + 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
772 | + ); |
|
773 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
774 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
775 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
776 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
777 | + $EE_Export->export(); |
|
778 | + } |
|
779 | + } |
|
780 | + |
|
781 | + |
|
782 | + /** |
|
783 | + * Creates a sample CSV file for importing |
|
784 | + */ |
|
785 | + protected function _sample_export_file() |
|
786 | + { |
|
787 | + // require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
788 | + EE_Export::instance()->export_sample(); |
|
789 | + } |
|
790 | + |
|
791 | + |
|
792 | + /************* Template Settings *************/ |
|
793 | + /** |
|
794 | + * Generates template settings page output |
|
795 | + * @throws DomainException |
|
796 | + * @throws EE_Error |
|
797 | + */ |
|
798 | + protected function _template_settings() |
|
799 | + { |
|
800 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
801 | + /** |
|
802 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
803 | + * from General_Settings_Admin_Page to here. |
|
804 | + */ |
|
805 | + $this->_template_args = apply_filters( |
|
806 | + 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
807 | + $this->_template_args |
|
808 | + ); |
|
809 | + $this->_set_add_edit_form_tags('update_template_settings'); |
|
810 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
811 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
812 | + EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
813 | + $this->_template_args, |
|
814 | + true |
|
815 | + ); |
|
816 | + $this->display_admin_page_with_sidebar(); |
|
817 | + } |
|
818 | + |
|
819 | + |
|
820 | + /** |
|
821 | + * Handler for updating template settings. |
|
822 | + */ |
|
823 | + protected function _update_template_settings() |
|
824 | + { |
|
825 | + /** |
|
826 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
827 | + * from General_Settings_Admin_Page to here. |
|
828 | + */ |
|
829 | + EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
830 | + 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
831 | + EE_Registry::instance()->CFG->template_settings, |
|
832 | + $this->_req_data |
|
833 | + ); |
|
834 | + //update custom post type slugs and detect if we need to flush rewrite rules |
|
835 | + $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
836 | + EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
837 | + ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
838 | + : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']); |
|
839 | + $what = 'Template Settings'; |
|
840 | + $success = $this->_update_espresso_configuration( |
|
841 | + $what, |
|
842 | + EE_Registry::instance()->CFG->template_settings, |
|
843 | + __FILE__, |
|
844 | + __FUNCTION__, |
|
845 | + __LINE__ |
|
846 | + ); |
|
847 | + if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
848 | + update_option('ee_flush_rewrite_rules', true); |
|
849 | + } |
|
850 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings')); |
|
851 | + } |
|
852 | + |
|
853 | + |
|
854 | + /** |
|
855 | + * _premium_event_editor_meta_boxes |
|
856 | + * add all metaboxes related to the event_editor |
|
857 | + * |
|
858 | + * @access protected |
|
859 | + * @return void |
|
860 | + * @throws EE_Error |
|
861 | + */ |
|
862 | + protected function _premium_event_editor_meta_boxes() |
|
863 | + { |
|
864 | + $this->verify_cpt_object(); |
|
865 | + add_meta_box( |
|
866 | + 'espresso_event_editor_event_options', |
|
867 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
868 | + array($this, 'registration_options_meta_box'), |
|
869 | + $this->page_slug, |
|
870 | + 'side', |
|
871 | + 'core' |
|
872 | + ); |
|
873 | + } |
|
874 | + |
|
875 | + |
|
876 | + /** |
|
877 | + * override caf metabox |
|
878 | + * |
|
879 | + * @return void |
|
880 | + * @throws DomainException |
|
881 | + */ |
|
882 | + public function registration_options_meta_box() |
|
883 | + { |
|
884 | + $yes_no_values = array( |
|
885 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
886 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
887 | + ); |
|
888 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
889 | + array( |
|
890 | + EEM_Registration::status_id_cancelled, |
|
891 | + EEM_Registration::status_id_declined, |
|
892 | + EEM_Registration::status_id_incomplete, |
|
893 | + EEM_Registration::status_id_wait_list, |
|
894 | + ), |
|
895 | + true |
|
896 | + ); |
|
897 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
898 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
899 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
900 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
901 | + 'default_reg_status', |
|
902 | + $default_reg_status_values, |
|
903 | + $this->_cpt_model_obj->default_registration_status() |
|
904 | + ); |
|
905 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
906 | + 'display_desc', |
|
907 | + $yes_no_values, |
|
908 | + $this->_cpt_model_obj->display_description() |
|
909 | + ); |
|
910 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
911 | + 'display_ticket_selector', |
|
912 | + $yes_no_values, |
|
913 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
914 | + '', |
|
915 | + '', |
|
916 | + false |
|
917 | + ); |
|
918 | + $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
919 | + 'EVT_default_registration_status', |
|
920 | + $default_reg_status_values, |
|
921 | + $this->_cpt_model_obj->default_registration_status() |
|
922 | + ); |
|
923 | + $template_args['additional_registration_options'] = apply_filters( |
|
924 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
925 | + '', |
|
926 | + $template_args, |
|
927 | + $yes_no_values, |
|
928 | + $default_reg_status_values |
|
929 | + ); |
|
930 | + EEH_Template::display_template( |
|
931 | + EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
932 | + $template_args |
|
933 | + ); |
|
934 | + } |
|
935 | + |
|
936 | + |
|
937 | + |
|
938 | + /** |
|
939 | + * wp_list_table_mods for caf |
|
940 | + * ============================ |
|
941 | + */ |
|
942 | + /** |
|
943 | + * hook into list table filters and provide filters for caffeinated list table |
|
944 | + * |
|
945 | + * @param array $old_filters any existing filters present |
|
946 | + * @param array $list_table_obj the list table object |
|
947 | + * @return array new filters |
|
948 | + */ |
|
949 | + public function list_table_filters($old_filters, $list_table_obj) |
|
950 | + { |
|
951 | + $filters = array(); |
|
952 | + //first month/year filters |
|
953 | + $filters[] = $this->espresso_event_months_dropdown(); |
|
954 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
955 | + //active status dropdown |
|
956 | + if ($status !== 'draft') { |
|
957 | + $filters[] = $this->active_status_dropdown( |
|
958 | + isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
959 | + ); |
|
960 | + } |
|
961 | + //category filter |
|
962 | + $filters[] = $this->category_dropdown(); |
|
963 | + return array_merge($old_filters, $filters); |
|
964 | + } |
|
965 | + |
|
966 | + |
|
967 | + /** |
|
968 | + * espresso_event_months_dropdown |
|
969 | + * |
|
970 | + * @access public |
|
971 | + * @return string dropdown listing month/year selections for events. |
|
972 | + */ |
|
973 | + public function espresso_event_months_dropdown() |
|
974 | + { |
|
975 | + // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
976 | + // Note we need to include any other filters that are set! |
|
977 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
978 | + //categories? |
|
979 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
980 | + ? $this->_req_data['EVT_CAT'] |
|
981 | + : null; |
|
982 | + //active status? |
|
983 | + $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
984 | + $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
985 | + return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
986 | + } |
|
987 | + |
|
988 | + |
|
989 | + /** |
|
990 | + * returns a list of "active" statuses on the event |
|
991 | + * |
|
992 | + * @param string $current_value whatever the current active status is |
|
993 | + * @return string |
|
994 | + */ |
|
995 | + public function active_status_dropdown($current_value = '') |
|
996 | + { |
|
997 | + $select_name = 'active_status'; |
|
998 | + $values = array( |
|
999 | + 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
1000 | + 'active' => esc_html__('Active', 'event_espresso'), |
|
1001 | + 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
1002 | + 'expired' => esc_html__('Expired', 'event_espresso'), |
|
1003 | + 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
1004 | + ); |
|
1005 | + $id = 'id="espresso-active-status-dropdown-filter"'; |
|
1006 | + $class = 'wide'; |
|
1007 | + return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class); |
|
1008 | + } |
|
1009 | + |
|
1010 | + |
|
1011 | + /** |
|
1012 | + * output a dropdown of the categories for the category filter on the event admin list table |
|
1013 | + * |
|
1014 | + * @access public |
|
1015 | + * @return string html |
|
1016 | + */ |
|
1017 | + public function category_dropdown() |
|
1018 | + { |
|
1019 | + $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
1020 | + return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
1021 | + } |
|
1022 | + |
|
1023 | + |
|
1024 | + /** |
|
1025 | + * get total number of events today |
|
1026 | + * |
|
1027 | + * @access public |
|
1028 | + * @return int |
|
1029 | + * @throws EE_Error |
|
1030 | + */ |
|
1031 | + public function total_events_today() |
|
1032 | + { |
|
1033 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1034 | + 'DTT_EVT_start', |
|
1035 | + date('Y-m-d') . ' 00:00:00', |
|
1036 | + 'Y-m-d H:i:s', |
|
1037 | + 'UTC' |
|
1038 | + ); |
|
1039 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1040 | + 'DTT_EVT_start', |
|
1041 | + date('Y-m-d') . ' 23:59:59', |
|
1042 | + 'Y-m-d H:i:s', |
|
1043 | + 'UTC' |
|
1044 | + ); |
|
1045 | + $where = array( |
|
1046 | + 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
1047 | + ); |
|
1048 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
1049 | + return $count; |
|
1050 | + } |
|
1051 | + |
|
1052 | + |
|
1053 | + /** |
|
1054 | + * get total number of events this month |
|
1055 | + * |
|
1056 | + * @access public |
|
1057 | + * @return int |
|
1058 | + * @throws EE_Error |
|
1059 | + */ |
|
1060 | + public function total_events_this_month() |
|
1061 | + { |
|
1062 | + //Dates |
|
1063 | + $this_year_r = date('Y'); |
|
1064 | + $this_month_r = date('m'); |
|
1065 | + $days_this_month = date('t'); |
|
1066 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1067 | + 'DTT_EVT_start', |
|
1068 | + $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
1069 | + 'Y-m-d H:i:s', |
|
1070 | + 'UTC' |
|
1071 | + ); |
|
1072 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1073 | + 'DTT_EVT_start', |
|
1074 | + $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
1075 | + 'Y-m-d H:i:s', |
|
1076 | + 'UTC' |
|
1077 | + ); |
|
1078 | + $where = array( |
|
1079 | + 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
1080 | + ); |
|
1081 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
1082 | + return $count; |
|
1083 | + } |
|
1084 | + |
|
1085 | + |
|
1086 | + /** DEFAULT TICKETS STUFF **/ |
|
1087 | + |
|
1088 | + /** |
|
1089 | + * Output default tickets list table view. |
|
1090 | + */ |
|
1091 | + public function _tickets_overview_list_table() |
|
1092 | + { |
|
1093 | + $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
1094 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
1095 | + } |
|
1096 | + |
|
1097 | + |
|
1098 | + /** |
|
1099 | + * @param int $per_page |
|
1100 | + * @param bool $count |
|
1101 | + * @param bool $trashed |
|
1102 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
1103 | + */ |
|
1104 | + public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
1105 | + { |
|
1106 | + $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
1107 | + $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
1108 | + switch ($orderby) { |
|
1109 | + case 'TKT_name': |
|
1110 | + $orderby = array('TKT_name' => $order); |
|
1111 | + break; |
|
1112 | + case 'TKT_price': |
|
1113 | + $orderby = array('TKT_price' => $order); |
|
1114 | + break; |
|
1115 | + case 'TKT_uses': |
|
1116 | + $orderby = array('TKT_uses' => $order); |
|
1117 | + break; |
|
1118 | + case 'TKT_min': |
|
1119 | + $orderby = array('TKT_min' => $order); |
|
1120 | + break; |
|
1121 | + case 'TKT_max': |
|
1122 | + $orderby = array('TKT_max' => $order); |
|
1123 | + break; |
|
1124 | + case 'TKT_qty': |
|
1125 | + $orderby = array('TKT_qty' => $order); |
|
1126 | + break; |
|
1127 | + } |
|
1128 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
1129 | + ? $this->_req_data['paged'] |
|
1130 | + : 1; |
|
1131 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
1132 | + ? $this->_req_data['perpage'] |
|
1133 | + : $per_page; |
|
1134 | + $_where = array( |
|
1135 | + 'TKT_is_default' => 1, |
|
1136 | + 'TKT_deleted' => $trashed, |
|
1137 | + ); |
|
1138 | + $offset = ($current_page - 1) * $per_page; |
|
1139 | + $limit = array($offset, $per_page); |
|
1140 | + if (isset($this->_req_data['s'])) { |
|
1141 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
1142 | + $_where['OR'] = array( |
|
1143 | + 'TKT_name' => array('LIKE', $sstr), |
|
1144 | + 'TKT_description' => array('LIKE', $sstr), |
|
1145 | + ); |
|
1146 | + } |
|
1147 | + $query_params = array( |
|
1148 | + $_where, |
|
1149 | + 'order_by' => $orderby, |
|
1150 | + 'limit' => $limit, |
|
1151 | + 'group_by' => 'TKT_ID', |
|
1152 | + ); |
|
1153 | + if ($count) { |
|
1154 | + return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where)); |
|
1155 | + } else { |
|
1156 | + return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
1157 | + } |
|
1158 | + } |
|
1159 | + |
|
1160 | + |
|
1161 | + /** |
|
1162 | + * @param bool $trash |
|
1163 | + * @throws EE_Error |
|
1164 | + */ |
|
1165 | + protected function _trash_or_restore_ticket($trash = false) |
|
1166 | + { |
|
1167 | + $success = 1; |
|
1168 | + $TKT = EEM_Ticket::instance(); |
|
1169 | + //checkboxes? |
|
1170 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1171 | + //if array has more than one element then success message should be plural |
|
1172 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1173 | + //cycle thru the boxes |
|
1174 | + while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1175 | + if ($trash) { |
|
1176 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1177 | + $success = 0; |
|
1178 | + } |
|
1179 | + } else { |
|
1180 | + if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1181 | + $success = 0; |
|
1182 | + } |
|
1183 | + } |
|
1184 | + } |
|
1185 | + } else { |
|
1186 | + //grab single id and trash |
|
1187 | + $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
1188 | + if ($trash) { |
|
1189 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1190 | + $success = 0; |
|
1191 | + } |
|
1192 | + } else { |
|
1193 | + if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1194 | + $success = 0; |
|
1195 | + } |
|
1196 | + } |
|
1197 | + } |
|
1198 | + $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
1199 | + $query_args = array( |
|
1200 | + 'action' => 'ticket_list_table', |
|
1201 | + 'status' => $trash ? '' : 'trashed', |
|
1202 | + ); |
|
1203 | + $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
1204 | + } |
|
1205 | + |
|
1206 | + |
|
1207 | + /** |
|
1208 | + * Handles trashing default ticket. |
|
1209 | + */ |
|
1210 | + protected function _delete_ticket() |
|
1211 | + { |
|
1212 | + $success = 1; |
|
1213 | + //checkboxes? |
|
1214 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1215 | + //if array has more than one element then success message should be plural |
|
1216 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1217 | + //cycle thru the boxes |
|
1218 | + while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1219 | + //delete |
|
1220 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1221 | + $success = 0; |
|
1222 | + } |
|
1223 | + } |
|
1224 | + } else { |
|
1225 | + //grab single id and trash |
|
1226 | + $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
1227 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1228 | + $success = 0; |
|
1229 | + } |
|
1230 | + } |
|
1231 | + $action_desc = 'deleted'; |
|
1232 | + $query_args = array( |
|
1233 | + 'action' => 'ticket_list_table', |
|
1234 | + 'status' => 'trashed', |
|
1235 | + ); |
|
1236 | + //fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
1237 | + if (EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
1238 | + array(array('TKT_is_default' => 1)), |
|
1239 | + 'TKT_ID', |
|
1240 | + true |
|
1241 | + ) |
|
1242 | + ) { |
|
1243 | + $query_args = array(); |
|
1244 | + } |
|
1245 | + $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
1246 | + } |
|
1247 | + |
|
1248 | + |
|
1249 | + /** |
|
1250 | + * @param int $TKT_ID |
|
1251 | + * @return bool|int |
|
1252 | + * @throws EE_Error |
|
1253 | + */ |
|
1254 | + protected function _delete_the_ticket($TKT_ID) |
|
1255 | + { |
|
1256 | + $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
1257 | + $tkt->_remove_relations('Datetime'); |
|
1258 | + //delete all related prices first |
|
1259 | + $tkt->delete_related_permanently('Price'); |
|
1260 | + return $tkt->delete_permanently(); |
|
1261 | + } |
|
1262 | 1262 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.44.rc.026'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.44.rc.026'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -21,741 +21,741 @@ discard block |
||
21 | 21 | class EE_Dependency_Map |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * This means that the requested class dependency is not present in the dependency map |
|
26 | - */ |
|
27 | - const not_registered = 0; |
|
28 | - |
|
29 | - /** |
|
30 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
31 | - */ |
|
32 | - const load_new_object = 1; |
|
33 | - |
|
34 | - /** |
|
35 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
36 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
37 | - */ |
|
38 | - const load_from_cache = 2; |
|
39 | - |
|
40 | - /** |
|
41 | - * When registering a dependency, |
|
42 | - * this indicates to keep any existing dependencies that already exist, |
|
43 | - * and simply discard any new dependencies declared in the incoming data |
|
44 | - */ |
|
45 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
46 | - |
|
47 | - /** |
|
48 | - * When registering a dependency, |
|
49 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
50 | - */ |
|
51 | - const OVERWRITE_DEPENDENCIES = 1; |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @type EE_Dependency_Map $_instance |
|
57 | - */ |
|
58 | - protected static $_instance; |
|
59 | - |
|
60 | - /** |
|
61 | - * @type EE_Request $request |
|
62 | - */ |
|
63 | - protected $_request; |
|
64 | - |
|
65 | - /** |
|
66 | - * @type EE_Response $response |
|
67 | - */ |
|
68 | - protected $_response; |
|
69 | - |
|
70 | - /** |
|
71 | - * @type LoaderInterface $loader |
|
72 | - */ |
|
73 | - protected $loader; |
|
74 | - |
|
75 | - /** |
|
76 | - * @type array $_dependency_map |
|
77 | - */ |
|
78 | - protected $_dependency_map = array(); |
|
79 | - |
|
80 | - /** |
|
81 | - * @type array $_class_loaders |
|
82 | - */ |
|
83 | - protected $_class_loaders = array(); |
|
84 | - |
|
85 | - /** |
|
86 | - * @type array $_aliases |
|
87 | - */ |
|
88 | - protected $_aliases = array(); |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * EE_Dependency_Map constructor. |
|
94 | - * |
|
95 | - * @param EE_Request $request |
|
96 | - * @param EE_Response $response |
|
97 | - */ |
|
98 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
99 | - { |
|
100 | - $this->_request = $request; |
|
101 | - $this->_response = $response; |
|
102 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
103 | - do_action('EE_Dependency_Map____construct'); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @throws InvalidDataTypeException |
|
110 | - * @throws InvalidInterfaceException |
|
111 | - * @throws InvalidArgumentException |
|
112 | - */ |
|
113 | - public function initialize() |
|
114 | - { |
|
115 | - $this->_register_core_dependencies(); |
|
116 | - $this->_register_core_class_loaders(); |
|
117 | - $this->_register_core_aliases(); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @singleton method used to instantiate class object |
|
124 | - * @access public |
|
125 | - * @param EE_Request $request |
|
126 | - * @param EE_Response $response |
|
127 | - * @return EE_Dependency_Map |
|
128 | - */ |
|
129 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
130 | - { |
|
131 | - // check if class object is instantiated, and instantiated properly |
|
132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
133 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
134 | - } |
|
135 | - return self::$_instance; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @param LoaderInterface $loader |
|
142 | - */ |
|
143 | - public function setLoader(LoaderInterface $loader) |
|
144 | - { |
|
145 | - $this->loader = $loader; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @param string $class |
|
152 | - * @param array $dependencies |
|
153 | - * @param int $overwrite |
|
154 | - * @return bool |
|
155 | - */ |
|
156 | - public static function register_dependencies( |
|
157 | - $class, |
|
158 | - array $dependencies, |
|
159 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
160 | - ) { |
|
161 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
168 | - * to the class specified by the first parameter. |
|
169 | - * IMPORTANT !!! |
|
170 | - * The order of elements in the incoming $dependencies array MUST match |
|
171 | - * the order of the constructor parameters for the class in question. |
|
172 | - * This is especially important when overriding any existing dependencies that are registered. |
|
173 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
174 | - * |
|
175 | - * @param string $class |
|
176 | - * @param array $dependencies |
|
177 | - * @param int $overwrite |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - public function registerDependencies( |
|
181 | - $class, |
|
182 | - array $dependencies, |
|
183 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
184 | - ) { |
|
185 | - $class = trim($class, '\\'); |
|
186 | - $registered = false; |
|
187 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
188 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
189 | - } |
|
190 | - // we need to make sure that any aliases used when registering a dependency |
|
191 | - // get resolved to the correct class name |
|
192 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
193 | - $alias = self::$_instance->get_alias($dependency); |
|
194 | - if ( |
|
195 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
196 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
197 | - ) { |
|
198 | - unset($dependencies[$dependency]); |
|
199 | - $dependencies[$alias] = $load_source; |
|
200 | - $registered = true; |
|
201 | - } |
|
202 | - } |
|
203 | - // now add our two lists of dependencies together. |
|
204 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
205 | - // so $dependencies is NOT overwritten because it is listed first |
|
206 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
207 | - // Union is way faster than array_merge() but should be used with caution... |
|
208 | - // especially with numerically indexed arrays |
|
209 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
210 | - // now we need to ensure that the resulting dependencies |
|
211 | - // array only has the entries that are required for the class |
|
212 | - // so first count how many dependencies were originally registered for the class |
|
213 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
214 | - // if that count is non-zero (meaning dependencies were already registered) |
|
215 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
216 | - // then truncate the final array to match that count |
|
217 | - ? array_slice($dependencies, 0, $dependency_count) |
|
218 | - // otherwise just take the incoming array because nothing previously existed |
|
219 | - : $dependencies; |
|
220 | - return $registered; |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * @param string $class_name |
|
227 | - * @param string $loader |
|
228 | - * @return bool |
|
229 | - * @throws DomainException |
|
230 | - */ |
|
231 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
232 | - { |
|
233 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
234 | - throw new DomainException( |
|
235 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
236 | - ); |
|
237 | - } |
|
238 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
239 | - if ( |
|
240 | - ! is_callable($loader) |
|
241 | - && ( |
|
242 | - strpos($loader, 'load_') !== 0 |
|
243 | - || ! method_exists('EE_Registry', $loader) |
|
244 | - ) |
|
245 | - ) { |
|
246 | - throw new DomainException( |
|
247 | - sprintf( |
|
248 | - esc_html__( |
|
249 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
250 | - 'event_espresso' |
|
251 | - ), |
|
252 | - $loader |
|
253 | - ) |
|
254 | - ); |
|
255 | - } |
|
256 | - $class_name = self::$_instance->get_alias($class_name); |
|
257 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
258 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
259 | - return true; |
|
260 | - } |
|
261 | - return false; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * @return array |
|
268 | - */ |
|
269 | - public function dependency_map() |
|
270 | - { |
|
271 | - return $this->_dependency_map; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
278 | - * |
|
279 | - * @param string $class_name |
|
280 | - * @return boolean |
|
281 | - */ |
|
282 | - public function has($class_name = '') |
|
283 | - { |
|
284 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
291 | - * |
|
292 | - * @param string $class_name |
|
293 | - * @param string $dependency |
|
294 | - * @return bool |
|
295 | - */ |
|
296 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
297 | - { |
|
298 | - $dependency = $this->get_alias($dependency); |
|
299 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
300 | - ? true |
|
301 | - : false; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
308 | - * |
|
309 | - * @param string $class_name |
|
310 | - * @param string $dependency |
|
311 | - * @return int |
|
312 | - */ |
|
313 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
314 | - { |
|
315 | - $dependency = $this->get_alias($dependency); |
|
316 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
317 | - ? $this->_dependency_map[$class_name][$dependency] |
|
318 | - : EE_Dependency_Map::not_registered; |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * @param string $class_name |
|
325 | - * @return string | Closure |
|
326 | - */ |
|
327 | - public function class_loader($class_name) |
|
328 | - { |
|
329 | - // don't use loaders for FQCNs |
|
330 | - if(strpos($class_name, '\\') !== false){ |
|
331 | - return ''; |
|
332 | - } |
|
333 | - $class_name = $this->get_alias($class_name); |
|
334 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * @return array |
|
341 | - */ |
|
342 | - public function class_loaders() |
|
343 | - { |
|
344 | - return $this->_class_loaders; |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * adds an alias for a classname |
|
351 | - * |
|
352 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
353 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
354 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
355 | - */ |
|
356 | - public function add_alias($class_name, $alias, $for_class = '') |
|
357 | - { |
|
358 | - if ($for_class !== '') { |
|
359 | - if (! isset($this->_aliases[$for_class])) { |
|
360 | - $this->_aliases[$for_class] = array(); |
|
361 | - } |
|
362 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
363 | - } |
|
364 | - $this->_aliases[$class_name] = $alias; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * returns TRUE if the provided class name has an alias |
|
371 | - * |
|
372 | - * @param string $class_name |
|
373 | - * @param string $for_class |
|
374 | - * @return bool |
|
375 | - */ |
|
376 | - public function has_alias($class_name = '', $for_class = '') |
|
377 | - { |
|
378 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
379 | - || ( |
|
380 | - isset($this->_aliases[$class_name]) |
|
381 | - && ! is_array($this->_aliases[$class_name]) |
|
382 | - ); |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
389 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
390 | - * for example: |
|
391 | - * if the following two entries were added to the _aliases array: |
|
392 | - * array( |
|
393 | - * 'interface_alias' => 'some\namespace\interface' |
|
394 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
395 | - * ) |
|
396 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
397 | - * to load an instance of 'some\namespace\classname' |
|
398 | - * |
|
399 | - * @param string $class_name |
|
400 | - * @param string $for_class |
|
401 | - * @return string |
|
402 | - */ |
|
403 | - public function get_alias($class_name = '', $for_class = '') |
|
404 | - { |
|
405 | - if (! $this->has_alias($class_name, $for_class)) { |
|
406 | - return $class_name; |
|
407 | - } |
|
408 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
409 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
410 | - } |
|
411 | - return $this->get_alias($this->_aliases[$class_name]); |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
418 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
419 | - * This is done by using the following class constants: |
|
420 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
421 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
422 | - */ |
|
423 | - protected function _register_core_dependencies() |
|
424 | - { |
|
425 | - $this->_dependency_map = array( |
|
426 | - 'EE_Request_Handler' => array( |
|
427 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
428 | - ), |
|
429 | - 'EE_System' => array( |
|
430 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
431 | - ), |
|
432 | - 'EE_Session' => array( |
|
433 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
434 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
435 | - ), |
|
436 | - 'EE_Cart' => array( |
|
437 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
438 | - ), |
|
439 | - 'EE_Front_Controller' => array( |
|
440 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
441 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
442 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
443 | - ), |
|
444 | - 'EE_Messenger_Collection_Loader' => array( |
|
445 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
446 | - ), |
|
447 | - 'EE_Message_Type_Collection_Loader' => array( |
|
448 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
449 | - ), |
|
450 | - 'EE_Message_Resource_Manager' => array( |
|
451 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
452 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
453 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
454 | - ), |
|
455 | - 'EE_Message_Factory' => array( |
|
456 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
457 | - ), |
|
458 | - 'EE_messages' => array( |
|
459 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
460 | - ), |
|
461 | - 'EE_Messages_Generator' => array( |
|
462 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
463 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
464 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
465 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
466 | - ), |
|
467 | - 'EE_Messages_Processor' => array( |
|
468 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
469 | - ), |
|
470 | - 'EE_Messages_Queue' => array( |
|
471 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
472 | - ), |
|
473 | - 'EE_Messages_Template_Defaults' => array( |
|
474 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
475 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
476 | - ), |
|
477 | - 'EE_Message_To_Generate_From_Request' => array( |
|
478 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
479 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
480 | - ), |
|
481 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
482 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
483 | - ), |
|
484 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
485 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
486 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
487 | - ), |
|
488 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
489 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
490 | - ), |
|
491 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
492 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
493 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
494 | - ), |
|
495 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
496 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
497 | - ), |
|
498 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
499 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
500 | - ), |
|
501 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
502 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
503 | - ), |
|
504 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
505 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
506 | - ), |
|
507 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
508 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
509 | - ), |
|
510 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
511 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
512 | - ), |
|
513 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
514 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
515 | - ), |
|
516 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
517 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
518 | - ), |
|
519 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
520 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
521 | - ), |
|
522 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
523 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
524 | - ), |
|
525 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
526 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
527 | - ), |
|
528 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
529 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
530 | - ), |
|
531 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
532 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
533 | - ), |
|
534 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
535 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
536 | - ), |
|
537 | - 'EE_Data_Migration_Class_Base' => array( |
|
538 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
539 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
540 | - ), |
|
541 | - 'EE_DMS_Core_4_1_0' => array( |
|
542 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
543 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
544 | - ), |
|
545 | - 'EE_DMS_Core_4_2_0' => array( |
|
546 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
547 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
548 | - ), |
|
549 | - 'EE_DMS_Core_4_3_0' => array( |
|
550 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
551 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
552 | - ), |
|
553 | - 'EE_DMS_Core_4_4_0' => array( |
|
554 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
555 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
556 | - ), |
|
557 | - 'EE_DMS_Core_4_5_0' => array( |
|
558 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
559 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
560 | - ), |
|
561 | - 'EE_DMS_Core_4_6_0' => array( |
|
562 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
563 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
564 | - ), |
|
565 | - 'EE_DMS_Core_4_7_0' => array( |
|
566 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
567 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
568 | - ), |
|
569 | - 'EE_DMS_Core_4_8_0' => array( |
|
570 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
571 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
572 | - ), |
|
573 | - 'EE_DMS_Core_4_9_0' => array( |
|
574 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
575 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
576 | - ), |
|
577 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
578 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
579 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
580 | - ), |
|
581 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
582 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
583 | - ), |
|
584 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
585 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
586 | - ), |
|
587 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
588 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
589 | - ), |
|
590 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
591 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
592 | - ), |
|
593 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
594 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
595 | - ), |
|
596 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
597 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
598 | - ), |
|
599 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
600 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
601 | - ), |
|
602 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
603 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
604 | - ), |
|
605 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
606 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
607 | - ), |
|
608 | - ); |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * Registers how core classes are loaded. |
|
615 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
616 | - * 'EE_Request_Handler' => 'load_core' |
|
617 | - * 'EE_Messages_Queue' => 'load_lib' |
|
618 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
619 | - * or, if greater control is required, by providing a custom closure. For example: |
|
620 | - * 'Some_Class' => function () { |
|
621 | - * return new Some_Class(); |
|
622 | - * }, |
|
623 | - * This is required for instantiating dependencies |
|
624 | - * where an interface has been type hinted in a class constructor. For example: |
|
625 | - * 'Required_Interface' => function () { |
|
626 | - * return new A_Class_That_Implements_Required_Interface(); |
|
627 | - * }, |
|
628 | - */ |
|
629 | - protected function _register_core_class_loaders() |
|
630 | - { |
|
631 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
632 | - //be used in a closure. |
|
633 | - $request = &$this->_request; |
|
634 | - $response = &$this->_response; |
|
635 | - $loader = &$this->loader; |
|
636 | - $this->_class_loaders = array( |
|
637 | - //load_core |
|
638 | - 'EE_Capabilities' => 'load_core', |
|
639 | - 'EE_Encryption' => 'load_core', |
|
640 | - 'EE_Front_Controller' => 'load_core', |
|
641 | - 'EE_Module_Request_Router' => 'load_core', |
|
642 | - 'EE_Registry' => 'load_core', |
|
643 | - 'EE_Request' => function () use (&$request) { |
|
644 | - return $request; |
|
645 | - }, |
|
646 | - 'EE_Response' => function () use (&$response) { |
|
647 | - return $response; |
|
648 | - }, |
|
649 | - 'EE_Request_Handler' => 'load_core', |
|
650 | - 'EE_Session' => 'load_core', |
|
651 | - //load_lib |
|
652 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
653 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
654 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
655 | - 'EE_Messenger_Collection' => 'load_lib', |
|
656 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
657 | - 'EE_Messages_Processor' => 'load_lib', |
|
658 | - 'EE_Message_Repository' => 'load_lib', |
|
659 | - 'EE_Messages_Queue' => 'load_lib', |
|
660 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
661 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
662 | - 'EE_Messages_Generator' => function () { |
|
663 | - return EE_Registry::instance()->load_lib( |
|
664 | - 'Messages_Generator', |
|
665 | - array(), |
|
666 | - false, |
|
667 | - false |
|
668 | - ); |
|
669 | - }, |
|
670 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
671 | - return EE_Registry::instance()->load_lib( |
|
672 | - 'Messages_Template_Defaults', |
|
673 | - $arguments, |
|
674 | - false, |
|
675 | - false |
|
676 | - ); |
|
677 | - }, |
|
678 | - //load_model |
|
679 | - 'EEM_Attendee' => 'load_model', |
|
680 | - 'EEM_Message_Template_Group' => 'load_model', |
|
681 | - 'EEM_Message_Template' => 'load_model', |
|
682 | - //load_helper |
|
683 | - 'EEH_Parse_Shortcodes' => function () { |
|
684 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
685 | - return new EEH_Parse_Shortcodes(); |
|
686 | - } |
|
687 | - return null; |
|
688 | - }, |
|
689 | - 'EE_Template_Config' => function () { |
|
690 | - return EE_Config::instance()->template_settings; |
|
691 | - }, |
|
692 | - 'EE_Currency_Config' => function () { |
|
693 | - return EE_Config::instance()->currency; |
|
694 | - }, |
|
695 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
696 | - return $loader; |
|
697 | - }, |
|
698 | - ); |
|
699 | - } |
|
700 | - |
|
701 | - |
|
702 | - |
|
703 | - /** |
|
704 | - * can be used for supplying alternate names for classes, |
|
705 | - * or for connecting interface names to instantiable classes |
|
706 | - */ |
|
707 | - protected function _register_core_aliases() |
|
708 | - { |
|
709 | - $this->_aliases = array( |
|
710 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
711 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
712 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
713 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
714 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
715 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
716 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
717 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
718 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
719 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
720 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
721 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
722 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
723 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
724 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
725 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
726 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
727 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
728 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
729 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
730 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
731 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
732 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
733 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
734 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
735 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
736 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
737 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
738 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
739 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
740 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
741 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
742 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
743 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
744 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
745 | - ); |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - |
|
750 | - /** |
|
751 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
752 | - * request Primarily used by unit tests. |
|
753 | - */ |
|
754 | - public function reset() |
|
755 | - { |
|
756 | - $this->_register_core_class_loaders(); |
|
757 | - $this->_register_core_dependencies(); |
|
758 | - } |
|
24 | + /** |
|
25 | + * This means that the requested class dependency is not present in the dependency map |
|
26 | + */ |
|
27 | + const not_registered = 0; |
|
28 | + |
|
29 | + /** |
|
30 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
31 | + */ |
|
32 | + const load_new_object = 1; |
|
33 | + |
|
34 | + /** |
|
35 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
36 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
37 | + */ |
|
38 | + const load_from_cache = 2; |
|
39 | + |
|
40 | + /** |
|
41 | + * When registering a dependency, |
|
42 | + * this indicates to keep any existing dependencies that already exist, |
|
43 | + * and simply discard any new dependencies declared in the incoming data |
|
44 | + */ |
|
45 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
46 | + |
|
47 | + /** |
|
48 | + * When registering a dependency, |
|
49 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
50 | + */ |
|
51 | + const OVERWRITE_DEPENDENCIES = 1; |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @type EE_Dependency_Map $_instance |
|
57 | + */ |
|
58 | + protected static $_instance; |
|
59 | + |
|
60 | + /** |
|
61 | + * @type EE_Request $request |
|
62 | + */ |
|
63 | + protected $_request; |
|
64 | + |
|
65 | + /** |
|
66 | + * @type EE_Response $response |
|
67 | + */ |
|
68 | + protected $_response; |
|
69 | + |
|
70 | + /** |
|
71 | + * @type LoaderInterface $loader |
|
72 | + */ |
|
73 | + protected $loader; |
|
74 | + |
|
75 | + /** |
|
76 | + * @type array $_dependency_map |
|
77 | + */ |
|
78 | + protected $_dependency_map = array(); |
|
79 | + |
|
80 | + /** |
|
81 | + * @type array $_class_loaders |
|
82 | + */ |
|
83 | + protected $_class_loaders = array(); |
|
84 | + |
|
85 | + /** |
|
86 | + * @type array $_aliases |
|
87 | + */ |
|
88 | + protected $_aliases = array(); |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * EE_Dependency_Map constructor. |
|
94 | + * |
|
95 | + * @param EE_Request $request |
|
96 | + * @param EE_Response $response |
|
97 | + */ |
|
98 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
99 | + { |
|
100 | + $this->_request = $request; |
|
101 | + $this->_response = $response; |
|
102 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
103 | + do_action('EE_Dependency_Map____construct'); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @throws InvalidDataTypeException |
|
110 | + * @throws InvalidInterfaceException |
|
111 | + * @throws InvalidArgumentException |
|
112 | + */ |
|
113 | + public function initialize() |
|
114 | + { |
|
115 | + $this->_register_core_dependencies(); |
|
116 | + $this->_register_core_class_loaders(); |
|
117 | + $this->_register_core_aliases(); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @singleton method used to instantiate class object |
|
124 | + * @access public |
|
125 | + * @param EE_Request $request |
|
126 | + * @param EE_Response $response |
|
127 | + * @return EE_Dependency_Map |
|
128 | + */ |
|
129 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
130 | + { |
|
131 | + // check if class object is instantiated, and instantiated properly |
|
132 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
133 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
134 | + } |
|
135 | + return self::$_instance; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @param LoaderInterface $loader |
|
142 | + */ |
|
143 | + public function setLoader(LoaderInterface $loader) |
|
144 | + { |
|
145 | + $this->loader = $loader; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @param string $class |
|
152 | + * @param array $dependencies |
|
153 | + * @param int $overwrite |
|
154 | + * @return bool |
|
155 | + */ |
|
156 | + public static function register_dependencies( |
|
157 | + $class, |
|
158 | + array $dependencies, |
|
159 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
160 | + ) { |
|
161 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
168 | + * to the class specified by the first parameter. |
|
169 | + * IMPORTANT !!! |
|
170 | + * The order of elements in the incoming $dependencies array MUST match |
|
171 | + * the order of the constructor parameters for the class in question. |
|
172 | + * This is especially important when overriding any existing dependencies that are registered. |
|
173 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
174 | + * |
|
175 | + * @param string $class |
|
176 | + * @param array $dependencies |
|
177 | + * @param int $overwrite |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + public function registerDependencies( |
|
181 | + $class, |
|
182 | + array $dependencies, |
|
183 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
184 | + ) { |
|
185 | + $class = trim($class, '\\'); |
|
186 | + $registered = false; |
|
187 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
188 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
189 | + } |
|
190 | + // we need to make sure that any aliases used when registering a dependency |
|
191 | + // get resolved to the correct class name |
|
192 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
193 | + $alias = self::$_instance->get_alias($dependency); |
|
194 | + if ( |
|
195 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
196 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
197 | + ) { |
|
198 | + unset($dependencies[$dependency]); |
|
199 | + $dependencies[$alias] = $load_source; |
|
200 | + $registered = true; |
|
201 | + } |
|
202 | + } |
|
203 | + // now add our two lists of dependencies together. |
|
204 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
205 | + // so $dependencies is NOT overwritten because it is listed first |
|
206 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
207 | + // Union is way faster than array_merge() but should be used with caution... |
|
208 | + // especially with numerically indexed arrays |
|
209 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
210 | + // now we need to ensure that the resulting dependencies |
|
211 | + // array only has the entries that are required for the class |
|
212 | + // so first count how many dependencies were originally registered for the class |
|
213 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
214 | + // if that count is non-zero (meaning dependencies were already registered) |
|
215 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
216 | + // then truncate the final array to match that count |
|
217 | + ? array_slice($dependencies, 0, $dependency_count) |
|
218 | + // otherwise just take the incoming array because nothing previously existed |
|
219 | + : $dependencies; |
|
220 | + return $registered; |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * @param string $class_name |
|
227 | + * @param string $loader |
|
228 | + * @return bool |
|
229 | + * @throws DomainException |
|
230 | + */ |
|
231 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
232 | + { |
|
233 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
234 | + throw new DomainException( |
|
235 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
236 | + ); |
|
237 | + } |
|
238 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
239 | + if ( |
|
240 | + ! is_callable($loader) |
|
241 | + && ( |
|
242 | + strpos($loader, 'load_') !== 0 |
|
243 | + || ! method_exists('EE_Registry', $loader) |
|
244 | + ) |
|
245 | + ) { |
|
246 | + throw new DomainException( |
|
247 | + sprintf( |
|
248 | + esc_html__( |
|
249 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
250 | + 'event_espresso' |
|
251 | + ), |
|
252 | + $loader |
|
253 | + ) |
|
254 | + ); |
|
255 | + } |
|
256 | + $class_name = self::$_instance->get_alias($class_name); |
|
257 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
258 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
259 | + return true; |
|
260 | + } |
|
261 | + return false; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * @return array |
|
268 | + */ |
|
269 | + public function dependency_map() |
|
270 | + { |
|
271 | + return $this->_dependency_map; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
278 | + * |
|
279 | + * @param string $class_name |
|
280 | + * @return boolean |
|
281 | + */ |
|
282 | + public function has($class_name = '') |
|
283 | + { |
|
284 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
291 | + * |
|
292 | + * @param string $class_name |
|
293 | + * @param string $dependency |
|
294 | + * @return bool |
|
295 | + */ |
|
296 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
297 | + { |
|
298 | + $dependency = $this->get_alias($dependency); |
|
299 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
300 | + ? true |
|
301 | + : false; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
308 | + * |
|
309 | + * @param string $class_name |
|
310 | + * @param string $dependency |
|
311 | + * @return int |
|
312 | + */ |
|
313 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
314 | + { |
|
315 | + $dependency = $this->get_alias($dependency); |
|
316 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
317 | + ? $this->_dependency_map[$class_name][$dependency] |
|
318 | + : EE_Dependency_Map::not_registered; |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * @param string $class_name |
|
325 | + * @return string | Closure |
|
326 | + */ |
|
327 | + public function class_loader($class_name) |
|
328 | + { |
|
329 | + // don't use loaders for FQCNs |
|
330 | + if(strpos($class_name, '\\') !== false){ |
|
331 | + return ''; |
|
332 | + } |
|
333 | + $class_name = $this->get_alias($class_name); |
|
334 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * @return array |
|
341 | + */ |
|
342 | + public function class_loaders() |
|
343 | + { |
|
344 | + return $this->_class_loaders; |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * adds an alias for a classname |
|
351 | + * |
|
352 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
353 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
354 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
355 | + */ |
|
356 | + public function add_alias($class_name, $alias, $for_class = '') |
|
357 | + { |
|
358 | + if ($for_class !== '') { |
|
359 | + if (! isset($this->_aliases[$for_class])) { |
|
360 | + $this->_aliases[$for_class] = array(); |
|
361 | + } |
|
362 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
363 | + } |
|
364 | + $this->_aliases[$class_name] = $alias; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * returns TRUE if the provided class name has an alias |
|
371 | + * |
|
372 | + * @param string $class_name |
|
373 | + * @param string $for_class |
|
374 | + * @return bool |
|
375 | + */ |
|
376 | + public function has_alias($class_name = '', $for_class = '') |
|
377 | + { |
|
378 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
379 | + || ( |
|
380 | + isset($this->_aliases[$class_name]) |
|
381 | + && ! is_array($this->_aliases[$class_name]) |
|
382 | + ); |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
389 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
390 | + * for example: |
|
391 | + * if the following two entries were added to the _aliases array: |
|
392 | + * array( |
|
393 | + * 'interface_alias' => 'some\namespace\interface' |
|
394 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
395 | + * ) |
|
396 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
397 | + * to load an instance of 'some\namespace\classname' |
|
398 | + * |
|
399 | + * @param string $class_name |
|
400 | + * @param string $for_class |
|
401 | + * @return string |
|
402 | + */ |
|
403 | + public function get_alias($class_name = '', $for_class = '') |
|
404 | + { |
|
405 | + if (! $this->has_alias($class_name, $for_class)) { |
|
406 | + return $class_name; |
|
407 | + } |
|
408 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
409 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
410 | + } |
|
411 | + return $this->get_alias($this->_aliases[$class_name]); |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
418 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
419 | + * This is done by using the following class constants: |
|
420 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
421 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
422 | + */ |
|
423 | + protected function _register_core_dependencies() |
|
424 | + { |
|
425 | + $this->_dependency_map = array( |
|
426 | + 'EE_Request_Handler' => array( |
|
427 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
428 | + ), |
|
429 | + 'EE_System' => array( |
|
430 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
431 | + ), |
|
432 | + 'EE_Session' => array( |
|
433 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
434 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
435 | + ), |
|
436 | + 'EE_Cart' => array( |
|
437 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
438 | + ), |
|
439 | + 'EE_Front_Controller' => array( |
|
440 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
441 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
442 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
443 | + ), |
|
444 | + 'EE_Messenger_Collection_Loader' => array( |
|
445 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
446 | + ), |
|
447 | + 'EE_Message_Type_Collection_Loader' => array( |
|
448 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
449 | + ), |
|
450 | + 'EE_Message_Resource_Manager' => array( |
|
451 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
452 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
453 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
454 | + ), |
|
455 | + 'EE_Message_Factory' => array( |
|
456 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
457 | + ), |
|
458 | + 'EE_messages' => array( |
|
459 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
460 | + ), |
|
461 | + 'EE_Messages_Generator' => array( |
|
462 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
463 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
464 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
465 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
466 | + ), |
|
467 | + 'EE_Messages_Processor' => array( |
|
468 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
469 | + ), |
|
470 | + 'EE_Messages_Queue' => array( |
|
471 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
472 | + ), |
|
473 | + 'EE_Messages_Template_Defaults' => array( |
|
474 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
475 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
476 | + ), |
|
477 | + 'EE_Message_To_Generate_From_Request' => array( |
|
478 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
479 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
480 | + ), |
|
481 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
482 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
483 | + ), |
|
484 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
485 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
486 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
487 | + ), |
|
488 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
489 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
490 | + ), |
|
491 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
492 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
493 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
494 | + ), |
|
495 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
496 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
497 | + ), |
|
498 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
499 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
500 | + ), |
|
501 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
502 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
503 | + ), |
|
504 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
505 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
506 | + ), |
|
507 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
508 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
509 | + ), |
|
510 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
511 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
512 | + ), |
|
513 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
514 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
515 | + ), |
|
516 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
517 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
518 | + ), |
|
519 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
520 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
521 | + ), |
|
522 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
523 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
524 | + ), |
|
525 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
526 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
527 | + ), |
|
528 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
529 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
530 | + ), |
|
531 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
532 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
533 | + ), |
|
534 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
535 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
536 | + ), |
|
537 | + 'EE_Data_Migration_Class_Base' => array( |
|
538 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
539 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
540 | + ), |
|
541 | + 'EE_DMS_Core_4_1_0' => array( |
|
542 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
543 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
544 | + ), |
|
545 | + 'EE_DMS_Core_4_2_0' => array( |
|
546 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
547 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
548 | + ), |
|
549 | + 'EE_DMS_Core_4_3_0' => array( |
|
550 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
551 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
552 | + ), |
|
553 | + 'EE_DMS_Core_4_4_0' => array( |
|
554 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
555 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
556 | + ), |
|
557 | + 'EE_DMS_Core_4_5_0' => array( |
|
558 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
559 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
560 | + ), |
|
561 | + 'EE_DMS_Core_4_6_0' => array( |
|
562 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
563 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
564 | + ), |
|
565 | + 'EE_DMS_Core_4_7_0' => array( |
|
566 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
567 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
568 | + ), |
|
569 | + 'EE_DMS_Core_4_8_0' => array( |
|
570 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
571 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
572 | + ), |
|
573 | + 'EE_DMS_Core_4_9_0' => array( |
|
574 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
575 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
576 | + ), |
|
577 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
578 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
579 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
580 | + ), |
|
581 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
582 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
583 | + ), |
|
584 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
585 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
586 | + ), |
|
587 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
588 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
589 | + ), |
|
590 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
591 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
592 | + ), |
|
593 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
594 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
595 | + ), |
|
596 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
597 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
598 | + ), |
|
599 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
600 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
601 | + ), |
|
602 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
603 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
604 | + ), |
|
605 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
606 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
607 | + ), |
|
608 | + ); |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * Registers how core classes are loaded. |
|
615 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
616 | + * 'EE_Request_Handler' => 'load_core' |
|
617 | + * 'EE_Messages_Queue' => 'load_lib' |
|
618 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
619 | + * or, if greater control is required, by providing a custom closure. For example: |
|
620 | + * 'Some_Class' => function () { |
|
621 | + * return new Some_Class(); |
|
622 | + * }, |
|
623 | + * This is required for instantiating dependencies |
|
624 | + * where an interface has been type hinted in a class constructor. For example: |
|
625 | + * 'Required_Interface' => function () { |
|
626 | + * return new A_Class_That_Implements_Required_Interface(); |
|
627 | + * }, |
|
628 | + */ |
|
629 | + protected function _register_core_class_loaders() |
|
630 | + { |
|
631 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
632 | + //be used in a closure. |
|
633 | + $request = &$this->_request; |
|
634 | + $response = &$this->_response; |
|
635 | + $loader = &$this->loader; |
|
636 | + $this->_class_loaders = array( |
|
637 | + //load_core |
|
638 | + 'EE_Capabilities' => 'load_core', |
|
639 | + 'EE_Encryption' => 'load_core', |
|
640 | + 'EE_Front_Controller' => 'load_core', |
|
641 | + 'EE_Module_Request_Router' => 'load_core', |
|
642 | + 'EE_Registry' => 'load_core', |
|
643 | + 'EE_Request' => function () use (&$request) { |
|
644 | + return $request; |
|
645 | + }, |
|
646 | + 'EE_Response' => function () use (&$response) { |
|
647 | + return $response; |
|
648 | + }, |
|
649 | + 'EE_Request_Handler' => 'load_core', |
|
650 | + 'EE_Session' => 'load_core', |
|
651 | + //load_lib |
|
652 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
653 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
654 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
655 | + 'EE_Messenger_Collection' => 'load_lib', |
|
656 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
657 | + 'EE_Messages_Processor' => 'load_lib', |
|
658 | + 'EE_Message_Repository' => 'load_lib', |
|
659 | + 'EE_Messages_Queue' => 'load_lib', |
|
660 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
661 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
662 | + 'EE_Messages_Generator' => function () { |
|
663 | + return EE_Registry::instance()->load_lib( |
|
664 | + 'Messages_Generator', |
|
665 | + array(), |
|
666 | + false, |
|
667 | + false |
|
668 | + ); |
|
669 | + }, |
|
670 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
671 | + return EE_Registry::instance()->load_lib( |
|
672 | + 'Messages_Template_Defaults', |
|
673 | + $arguments, |
|
674 | + false, |
|
675 | + false |
|
676 | + ); |
|
677 | + }, |
|
678 | + //load_model |
|
679 | + 'EEM_Attendee' => 'load_model', |
|
680 | + 'EEM_Message_Template_Group' => 'load_model', |
|
681 | + 'EEM_Message_Template' => 'load_model', |
|
682 | + //load_helper |
|
683 | + 'EEH_Parse_Shortcodes' => function () { |
|
684 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
685 | + return new EEH_Parse_Shortcodes(); |
|
686 | + } |
|
687 | + return null; |
|
688 | + }, |
|
689 | + 'EE_Template_Config' => function () { |
|
690 | + return EE_Config::instance()->template_settings; |
|
691 | + }, |
|
692 | + 'EE_Currency_Config' => function () { |
|
693 | + return EE_Config::instance()->currency; |
|
694 | + }, |
|
695 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
696 | + return $loader; |
|
697 | + }, |
|
698 | + ); |
|
699 | + } |
|
700 | + |
|
701 | + |
|
702 | + |
|
703 | + /** |
|
704 | + * can be used for supplying alternate names for classes, |
|
705 | + * or for connecting interface names to instantiable classes |
|
706 | + */ |
|
707 | + protected function _register_core_aliases() |
|
708 | + { |
|
709 | + $this->_aliases = array( |
|
710 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
711 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
712 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
713 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
714 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
715 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
716 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
717 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
718 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
719 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
720 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
721 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
722 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
723 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
724 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
725 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
726 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
727 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
728 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
729 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
730 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
731 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
732 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
733 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
734 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
735 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
736 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
737 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
738 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
739 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
740 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
741 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
742 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
743 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
744 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
745 | + ); |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + |
|
750 | + /** |
|
751 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
752 | + * request Primarily used by unit tests. |
|
753 | + */ |
|
754 | + public function reset() |
|
755 | + { |
|
756 | + $this->_register_core_class_loaders(); |
|
757 | + $this->_register_core_dependencies(); |
|
758 | + } |
|
759 | 759 | |
760 | 760 | |
761 | 761 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | 7 | exit('No direct script access allowed'); |
8 | 8 | } |
9 | 9 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
130 | 130 | { |
131 | 131 | // check if class object is instantiated, and instantiated properly |
132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
132 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
133 | 133 | self::$_instance = new EE_Dependency_Map($request, $response); |
134 | 134 | } |
135 | 135 | return self::$_instance; |
@@ -184,16 +184,16 @@ discard block |
||
184 | 184 | ) { |
185 | 185 | $class = trim($class, '\\'); |
186 | 186 | $registered = false; |
187 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
188 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
187 | + if (empty(self::$_instance->_dependency_map[$class])) { |
|
188 | + self::$_instance->_dependency_map[$class] = array(); |
|
189 | 189 | } |
190 | 190 | // we need to make sure that any aliases used when registering a dependency |
191 | 191 | // get resolved to the correct class name |
192 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
192 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
193 | 193 | $alias = self::$_instance->get_alias($dependency); |
194 | 194 | if ( |
195 | 195 | $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
196 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
196 | + || ! isset(self::$_instance->_dependency_map[$class][$alias]) |
|
197 | 197 | ) { |
198 | 198 | unset($dependencies[$dependency]); |
199 | 199 | $dependencies[$alias] = $load_source; |
@@ -206,13 +206,13 @@ discard block |
||
206 | 206 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
207 | 207 | // Union is way faster than array_merge() but should be used with caution... |
208 | 208 | // especially with numerically indexed arrays |
209 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
209 | + $dependencies += self::$_instance->_dependency_map[$class]; |
|
210 | 210 | // now we need to ensure that the resulting dependencies |
211 | 211 | // array only has the entries that are required for the class |
212 | 212 | // so first count how many dependencies were originally registered for the class |
213 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
213 | + $dependency_count = count(self::$_instance->_dependency_map[$class]); |
|
214 | 214 | // if that count is non-zero (meaning dependencies were already registered) |
215 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
215 | + self::$_instance->_dependency_map[$class] = $dependency_count |
|
216 | 216 | // then truncate the final array to match that count |
217 | 217 | ? array_slice($dependencies, 0, $dependency_count) |
218 | 218 | // otherwise just take the incoming array because nothing previously existed |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | */ |
231 | 231 | public static function register_class_loader($class_name, $loader = 'load_core') |
232 | 232 | { |
233 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
233 | + if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
234 | 234 | throw new DomainException( |
235 | 235 | esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
236 | 236 | ); |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | ); |
255 | 255 | } |
256 | 256 | $class_name = self::$_instance->get_alias($class_name); |
257 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
257 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
258 | 258 | self::$_instance->_class_loaders[$class_name] = $loader; |
259 | 259 | return true; |
260 | 260 | } |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | public function class_loader($class_name) |
328 | 328 | { |
329 | 329 | // don't use loaders for FQCNs |
330 | - if(strpos($class_name, '\\') !== false){ |
|
330 | + if (strpos($class_name, '\\') !== false) { |
|
331 | 331 | return ''; |
332 | 332 | } |
333 | 333 | $class_name = $this->get_alias($class_name); |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | public function add_alias($class_name, $alias, $for_class = '') |
357 | 357 | { |
358 | 358 | if ($for_class !== '') { |
359 | - if (! isset($this->_aliases[$for_class])) { |
|
359 | + if ( ! isset($this->_aliases[$for_class])) { |
|
360 | 360 | $this->_aliases[$for_class] = array(); |
361 | 361 | } |
362 | 362 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -402,10 +402,10 @@ discard block |
||
402 | 402 | */ |
403 | 403 | public function get_alias($class_name = '', $for_class = '') |
404 | 404 | { |
405 | - if (! $this->has_alias($class_name, $for_class)) { |
|
405 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
406 | 406 | return $class_name; |
407 | 407 | } |
408 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
408 | + if ($for_class !== '' && isset($this->_aliases[$for_class][$class_name])) { |
|
409 | 409 | return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
410 | 410 | } |
411 | 411 | return $this->get_alias($this->_aliases[$class_name]); |
@@ -640,10 +640,10 @@ discard block |
||
640 | 640 | 'EE_Front_Controller' => 'load_core', |
641 | 641 | 'EE_Module_Request_Router' => 'load_core', |
642 | 642 | 'EE_Registry' => 'load_core', |
643 | - 'EE_Request' => function () use (&$request) { |
|
643 | + 'EE_Request' => function() use (&$request) { |
|
644 | 644 | return $request; |
645 | 645 | }, |
646 | - 'EE_Response' => function () use (&$response) { |
|
646 | + 'EE_Response' => function() use (&$response) { |
|
647 | 647 | return $response; |
648 | 648 | }, |
649 | 649 | 'EE_Request_Handler' => 'load_core', |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | 'EE_Messages_Queue' => 'load_lib', |
660 | 660 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
661 | 661 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
662 | - 'EE_Messages_Generator' => function () { |
|
662 | + 'EE_Messages_Generator' => function() { |
|
663 | 663 | return EE_Registry::instance()->load_lib( |
664 | 664 | 'Messages_Generator', |
665 | 665 | array(), |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | false |
668 | 668 | ); |
669 | 669 | }, |
670 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
670 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
671 | 671 | return EE_Registry::instance()->load_lib( |
672 | 672 | 'Messages_Template_Defaults', |
673 | 673 | $arguments, |
@@ -680,19 +680,19 @@ discard block |
||
680 | 680 | 'EEM_Message_Template_Group' => 'load_model', |
681 | 681 | 'EEM_Message_Template' => 'load_model', |
682 | 682 | //load_helper |
683 | - 'EEH_Parse_Shortcodes' => function () { |
|
683 | + 'EEH_Parse_Shortcodes' => function() { |
|
684 | 684 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
685 | 685 | return new EEH_Parse_Shortcodes(); |
686 | 686 | } |
687 | 687 | return null; |
688 | 688 | }, |
689 | - 'EE_Template_Config' => function () { |
|
689 | + 'EE_Template_Config' => function() { |
|
690 | 690 | return EE_Config::instance()->template_settings; |
691 | 691 | }, |
692 | - 'EE_Currency_Config' => function () { |
|
692 | + 'EE_Currency_Config' => function() { |
|
693 | 693 | return EE_Config::instance()->currency; |
694 | 694 | }, |
695 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
695 | + 'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) { |
|
696 | 696 | return $loader; |
697 | 697 | }, |
698 | 698 | ); |