@@ -15,131 +15,131 @@ |
||
15 | 15 | class Messages_Overview_Help_Tour extends EE_Help_Tour |
16 | 16 | { |
17 | 17 | |
18 | - protected function _set_tour_properties() |
|
19 | - { |
|
20 | - $this->_label = __('Messages Overview Tour', 'event_espresso'); |
|
21 | - $this->_slug = 'messages-overview-joyride'; |
|
22 | - } |
|
18 | + protected function _set_tour_properties() |
|
19 | + { |
|
20 | + $this->_label = __('Messages Overview Tour', 'event_espresso'); |
|
21 | + $this->_slug = 'messages-overview-joyride'; |
|
22 | + } |
|
23 | 23 | |
24 | 24 | |
25 | - protected function _set_tour_stops() |
|
26 | - { |
|
27 | - $this->_stops = array( |
|
28 | - 10 => array( |
|
29 | - 'content' => $this->_start(), |
|
30 | - ), |
|
31 | - 20 => array( |
|
32 | - 'id' => 'event', |
|
33 | - 'content' => $this->event_column_stop(), |
|
34 | - 'options' => array( |
|
35 | - 'tipLocation' => 'top', |
|
36 | - 'tipAdjustmentX' => -5, |
|
37 | - 'tipAdjustmentY' => -30, |
|
38 | - ), |
|
39 | - ), |
|
40 | - 30 => array( |
|
41 | - 'id' => 'message_type', |
|
42 | - 'content' => $this->_message_type_column_stop(), |
|
43 | - 'options' => array( |
|
44 | - 'tipLocation' => 'top', |
|
45 | - 'tipAdjustmentX' => 20, |
|
46 | - 'tipAdjustmentY' => -30, |
|
47 | - ), |
|
48 | - ), |
|
49 | - 40 => array( |
|
50 | - 'id' => 'messenger', |
|
51 | - 'content' => $this->_messenger_column_stop(), |
|
52 | - 'options' => array( |
|
53 | - 'tipLocation' => 'top', |
|
54 | - 'tipAdjustmentX' => 5, |
|
55 | - 'tipAdjustmentY' => -30, |
|
56 | - ), |
|
57 | - ), |
|
58 | - 50 => array( |
|
59 | - 'id' => 'description', |
|
60 | - 'content' => $this->_description_column_stop(), |
|
61 | - 'options' => array( |
|
62 | - 'tipLocation' => 'top', |
|
63 | - 'tipAdjustmentX' => 5, |
|
64 | - 'tipAdjustmentY' => -30, |
|
65 | - ), |
|
66 | - ), |
|
67 | - 60 => array( |
|
68 | - 'class' => 'bulkactions', |
|
69 | - 'content' => $this->_bulk_actions_stop(), |
|
70 | - 'options' => array( |
|
71 | - 'tipLocation' => 'top', |
|
72 | - 'tipAdjustmentX' => 25, |
|
73 | - 'tipAdjustmentY' => -35, |
|
74 | - ), |
|
75 | - ), |
|
76 | - 70 => array( |
|
77 | - 'id' => 'ee_messenger_filter_by', |
|
78 | - 'content' => $this->_filters_stop(), |
|
79 | - 'options' => array( |
|
80 | - 'tipLocation' => 'top', |
|
81 | - 'tipAdjustmentX' => 25, |
|
82 | - 'tipAdjustmentY' => -30, |
|
83 | - ), |
|
84 | - ), |
|
85 | - ); |
|
86 | - } |
|
25 | + protected function _set_tour_stops() |
|
26 | + { |
|
27 | + $this->_stops = array( |
|
28 | + 10 => array( |
|
29 | + 'content' => $this->_start(), |
|
30 | + ), |
|
31 | + 20 => array( |
|
32 | + 'id' => 'event', |
|
33 | + 'content' => $this->event_column_stop(), |
|
34 | + 'options' => array( |
|
35 | + 'tipLocation' => 'top', |
|
36 | + 'tipAdjustmentX' => -5, |
|
37 | + 'tipAdjustmentY' => -30, |
|
38 | + ), |
|
39 | + ), |
|
40 | + 30 => array( |
|
41 | + 'id' => 'message_type', |
|
42 | + 'content' => $this->_message_type_column_stop(), |
|
43 | + 'options' => array( |
|
44 | + 'tipLocation' => 'top', |
|
45 | + 'tipAdjustmentX' => 20, |
|
46 | + 'tipAdjustmentY' => -30, |
|
47 | + ), |
|
48 | + ), |
|
49 | + 40 => array( |
|
50 | + 'id' => 'messenger', |
|
51 | + 'content' => $this->_messenger_column_stop(), |
|
52 | + 'options' => array( |
|
53 | + 'tipLocation' => 'top', |
|
54 | + 'tipAdjustmentX' => 5, |
|
55 | + 'tipAdjustmentY' => -30, |
|
56 | + ), |
|
57 | + ), |
|
58 | + 50 => array( |
|
59 | + 'id' => 'description', |
|
60 | + 'content' => $this->_description_column_stop(), |
|
61 | + 'options' => array( |
|
62 | + 'tipLocation' => 'top', |
|
63 | + 'tipAdjustmentX' => 5, |
|
64 | + 'tipAdjustmentY' => -30, |
|
65 | + ), |
|
66 | + ), |
|
67 | + 60 => array( |
|
68 | + 'class' => 'bulkactions', |
|
69 | + 'content' => $this->_bulk_actions_stop(), |
|
70 | + 'options' => array( |
|
71 | + 'tipLocation' => 'top', |
|
72 | + 'tipAdjustmentX' => 25, |
|
73 | + 'tipAdjustmentY' => -35, |
|
74 | + ), |
|
75 | + ), |
|
76 | + 70 => array( |
|
77 | + 'id' => 'ee_messenger_filter_by', |
|
78 | + 'content' => $this->_filters_stop(), |
|
79 | + 'options' => array( |
|
80 | + 'tipLocation' => 'top', |
|
81 | + 'tipAdjustmentX' => 25, |
|
82 | + 'tipAdjustmentY' => -30, |
|
83 | + ), |
|
84 | + ), |
|
85 | + ); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - protected function _start() |
|
90 | - { |
|
91 | - $content = '<h3>' . __('Messages Overview', 'event_espresso') . '</h3>'; |
|
92 | - $content .= '<p>' |
|
93 | - . __( |
|
94 | - 'This tour of the Messages Overview page will go over different areas of the screen to help you understand what they are used for.', |
|
95 | - 'event_espresso' |
|
96 | - ) . '</p>'; |
|
97 | - return $content; |
|
98 | - } |
|
89 | + protected function _start() |
|
90 | + { |
|
91 | + $content = '<h3>' . __('Messages Overview', 'event_espresso') . '</h3>'; |
|
92 | + $content .= '<p>' |
|
93 | + . __( |
|
94 | + 'This tour of the Messages Overview page will go over different areas of the screen to help you understand what they are used for.', |
|
95 | + 'event_espresso' |
|
96 | + ) . '</p>'; |
|
97 | + return $content; |
|
98 | + } |
|
99 | 99 | |
100 | - protected function event_column_stop() |
|
101 | - { |
|
102 | - return '<p>' |
|
103 | - . __( |
|
104 | - 'View if a message is associated with one event or multiple events. Can be sorted in ascending and descending order.', |
|
105 | - 'event_espresso' |
|
106 | - ) . '</p>'; |
|
107 | - } |
|
100 | + protected function event_column_stop() |
|
101 | + { |
|
102 | + return '<p>' |
|
103 | + . __( |
|
104 | + 'View if a message is associated with one event or multiple events. Can be sorted in ascending and descending order.', |
|
105 | + 'event_espresso' |
|
106 | + ) . '</p>'; |
|
107 | + } |
|
108 | 108 | |
109 | - protected function _message_type_column_stop() |
|
110 | - { |
|
111 | - return '<p>' |
|
112 | - . __( |
|
113 | - 'View the type of message. Can be sorted in ascending or descending order.', |
|
114 | - 'event_espresso' |
|
115 | - ) . '</p>'; |
|
116 | - } |
|
109 | + protected function _message_type_column_stop() |
|
110 | + { |
|
111 | + return '<p>' |
|
112 | + . __( |
|
113 | + 'View the type of message. Can be sorted in ascending or descending order.', |
|
114 | + 'event_espresso' |
|
115 | + ) . '</p>'; |
|
116 | + } |
|
117 | 117 | |
118 | - protected function _messenger_column_stop() |
|
119 | - { |
|
120 | - return '<p>' |
|
121 | - . __( |
|
122 | - 'View who messages will be sent to. Can be sorted in ascending or descending order.', |
|
123 | - 'event_espresso' |
|
124 | - ) . '</p>'; |
|
125 | - } |
|
118 | + protected function _messenger_column_stop() |
|
119 | + { |
|
120 | + return '<p>' |
|
121 | + . __( |
|
122 | + 'View who messages will be sent to. Can be sorted in ascending or descending order.', |
|
123 | + 'event_espresso' |
|
124 | + ) . '</p>'; |
|
125 | + } |
|
126 | 126 | |
127 | - protected function _description_column_stop() |
|
128 | - { |
|
129 | - return '<p>' . __('View the description for each message type.', 'event_espresso') . '</p>'; |
|
130 | - } |
|
127 | + protected function _description_column_stop() |
|
128 | + { |
|
129 | + return '<p>' . __('View the description for each message type.', 'event_espresso') . '</p>'; |
|
130 | + } |
|
131 | 131 | |
132 | - protected function _bulk_actions_stop() |
|
133 | - { |
|
134 | - return '<p>' . __('Perform bulk actions to multiple message types.', 'event_espresso') . '</p>'; |
|
135 | - } |
|
132 | + protected function _bulk_actions_stop() |
|
133 | + { |
|
134 | + return '<p>' . __('Perform bulk actions to multiple message types.', 'event_espresso') . '</p>'; |
|
135 | + } |
|
136 | 136 | |
137 | - protected function _filters_stop() |
|
138 | - { |
|
139 | - return '<p>' |
|
140 | - . __( |
|
141 | - 'You can filter by different notifications by making a selection below and clicking on the filter button. To reset your selection, just click on the reset filters button.', |
|
142 | - 'event_espresso' |
|
143 | - ) . '</p>'; |
|
144 | - } |
|
137 | + protected function _filters_stop() |
|
138 | + { |
|
139 | + return '<p>' |
|
140 | + . __( |
|
141 | + 'You can filter by different notifications by making a selection below and clicking on the filter button. To reset your selection, just click on the reset filters button.', |
|
142 | + 'event_espresso' |
|
143 | + ) . '</p>'; |
|
144 | + } |
|
145 | 145 | } |
@@ -88,12 +88,12 @@ discard block |
||
88 | 88 | |
89 | 89 | protected function _start() |
90 | 90 | { |
91 | - $content = '<h3>' . __('Messages Overview', 'event_espresso') . '</h3>'; |
|
91 | + $content = '<h3>'.__('Messages Overview', 'event_espresso').'</h3>'; |
|
92 | 92 | $content .= '<p>' |
93 | 93 | . __( |
94 | 94 | 'This tour of the Messages Overview page will go over different areas of the screen to help you understand what they are used for.', |
95 | 95 | 'event_espresso' |
96 | - ) . '</p>'; |
|
96 | + ).'</p>'; |
|
97 | 97 | return $content; |
98 | 98 | } |
99 | 99 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | . __( |
104 | 104 | 'View if a message is associated with one event or multiple events. Can be sorted in ascending and descending order.', |
105 | 105 | 'event_espresso' |
106 | - ) . '</p>'; |
|
106 | + ).'</p>'; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | protected function _message_type_column_stop() |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | . __( |
113 | 113 | 'View the type of message. Can be sorted in ascending or descending order.', |
114 | 114 | 'event_espresso' |
115 | - ) . '</p>'; |
|
115 | + ).'</p>'; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | protected function _messenger_column_stop() |
@@ -121,17 +121,17 @@ discard block |
||
121 | 121 | . __( |
122 | 122 | 'View who messages will be sent to. Can be sorted in ascending or descending order.', |
123 | 123 | 'event_espresso' |
124 | - ) . '</p>'; |
|
124 | + ).'</p>'; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | protected function _description_column_stop() |
128 | 128 | { |
129 | - return '<p>' . __('View the description for each message type.', 'event_espresso') . '</p>'; |
|
129 | + return '<p>'.__('View the description for each message type.', 'event_espresso').'</p>'; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | protected function _bulk_actions_stop() |
133 | 133 | { |
134 | - return '<p>' . __('Perform bulk actions to multiple message types.', 'event_espresso') . '</p>'; |
|
134 | + return '<p>'.__('Perform bulk actions to multiple message types.', 'event_espresso').'</p>'; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | protected function _filters_stop() |
@@ -140,6 +140,6 @@ discard block |
||
140 | 140 | . __( |
141 | 141 | 'You can filter by different notifications by making a selection below and clicking on the filter button. To reset your selection, just click on the reset filters button.', |
142 | 142 | 'event_espresso' |
143 | - ) . '</p>'; |
|
143 | + ).'</p>'; |
|
144 | 144 | } |
145 | 145 | } |
@@ -12,434 +12,434 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * @return Messages_Admin_Page |
|
17 | - */ |
|
18 | - public function get_admin_page() |
|
19 | - { |
|
20 | - return $this->_admin_page; |
|
21 | - } |
|
22 | - |
|
23 | - |
|
24 | - protected function _setup_data() |
|
25 | - { |
|
26 | - $this->_data = $this->_get_messages($this->_per_page, $this->_view); |
|
27 | - $this->_all_data_count = $this->_get_messages($this->_per_page, $this->_view, true); |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - protected function _set_properties() |
|
32 | - { |
|
33 | - $this->_wp_list_args = array( |
|
34 | - 'singular' => __('Message', 'event_espresso'), |
|
35 | - 'plural' => __('Messages', 'event_espresso'), |
|
36 | - 'ajax' => true, |
|
37 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
38 | - ); |
|
39 | - |
|
40 | - $this->_columns = array( |
|
41 | - 'cb' => '<input type="checkbox" />', |
|
42 | - 'to' => __('To', 'event_espresso'), |
|
43 | - 'from' => __('From', 'event_espresso'), |
|
44 | - 'messenger' => __('Messenger', 'event_espresso'), |
|
45 | - 'message_type' => __('Message Type', 'event_espresso'), |
|
46 | - 'context' => __('Context', 'event_espresso'), |
|
47 | - 'modified' => __('Modified', 'event_espresso'), |
|
48 | - 'action' => __('Actions', 'event_espresso'), |
|
49 | - 'msg_id' => __('ID', 'event_espresso'), |
|
50 | - ); |
|
51 | - |
|
52 | - $this->_sortable_columns = array( |
|
53 | - 'modified' => array('MSG_modified' => true), |
|
54 | - 'message_type' => array('MSG_message_type' => false), |
|
55 | - 'messenger' => array('MSG_messenger' => false), |
|
56 | - 'to' => array('MSG_to' => false), |
|
57 | - 'from' => array('MSG_from' => false), |
|
58 | - 'context' => array('MSG_context' => false), |
|
59 | - 'msg_id' => array('MSG_ID', false), |
|
60 | - ); |
|
61 | - |
|
62 | - $this->_primary_column = 'to'; |
|
63 | - |
|
64 | - $this->_hidden_columns = array( |
|
65 | - 'msg_id', |
|
66 | - ); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * This simply sets up the row class for the table rows. |
|
72 | - * Allows for easier overriding of child methods for setting up sorting. |
|
73 | - * |
|
74 | - * @param object $item the current item |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - protected function _get_row_class($item) |
|
78 | - { |
|
79 | - $class = parent::_get_row_class($item); |
|
80 | - // add status class |
|
81 | - $class .= ' ee-status-strip msg-status-' . $item->STS_ID(); |
|
82 | - if ($this->_has_checkbox_column) { |
|
83 | - $class .= ' has-checkbox-column'; |
|
84 | - } |
|
85 | - return $class; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * _get_table_filters |
|
91 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
92 | - * get's shown in the table. |
|
93 | - * |
|
94 | - * @abstract |
|
95 | - * @access protected |
|
96 | - * @return string |
|
97 | - * @throws \EE_Error |
|
98 | - */ |
|
99 | - protected function _get_table_filters() |
|
100 | - { |
|
101 | - $filters = array(); |
|
102 | - |
|
103 | - // get select_inputs |
|
104 | - $select_inputs = array( |
|
105 | - $this->_get_messengers_dropdown_filter(), |
|
106 | - $this->_get_message_types_dropdown_filter(), |
|
107 | - $this->_get_contexts_for_message_types_dropdown_filter(), |
|
108 | - ); |
|
109 | - |
|
110 | - // set filters to select inputs if they aren't empty |
|
111 | - foreach ($select_inputs as $select_input) { |
|
112 | - if ($select_input) { |
|
113 | - $filters[] = $select_input; |
|
114 | - } |
|
115 | - } |
|
116 | - return $filters; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - protected function _add_view_counts() |
|
121 | - { |
|
122 | - foreach ($this->_views as $view => $args) { |
|
123 | - $this->_views[ $view ]['count'] = $this->_get_messages($this->_per_page, $view, true, true); |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @param EE_Message $message |
|
130 | - * @return string checkbox |
|
131 | - * @throws \EE_Error |
|
132 | - */ |
|
133 | - public function column_cb($message) |
|
134 | - { |
|
135 | - return sprintf('<input type="checkbox" name="MSG_ID[%s]" value="1" />', $message->ID()); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param EE_Message $message |
|
141 | - * @return string |
|
142 | - * @throws \EE_Error |
|
143 | - */ |
|
144 | - public function column_msg_id(EE_Message $message) |
|
145 | - { |
|
146 | - return $message->ID(); |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @param EE_Message $message |
|
152 | - * @return string The recipient of the message |
|
153 | - * @throws \EE_Error |
|
154 | - */ |
|
155 | - public function column_to(EE_Message $message) |
|
156 | - { |
|
157 | - EE_Registry::instance()->load_helper('URL'); |
|
158 | - $actions = array(); |
|
159 | - $actions['delete'] = '<a href="' |
|
160 | - . EEH_URL::add_query_args_and_nonce( |
|
161 | - array( |
|
162 | - 'page' => 'espresso_messages', |
|
163 | - 'action' => 'delete_ee_message', |
|
164 | - 'MSG_ID' => $message->ID(), |
|
165 | - ), |
|
166 | - admin_url('admin.php') |
|
167 | - ) |
|
168 | - . '">' . __('Delete', 'event_espresso') . '</a>'; |
|
169 | - return esc_html($message->to()) . $this->row_actions($actions); |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * @param EE_Message $message |
|
175 | - * @return string The sender of the message |
|
176 | - */ |
|
177 | - public function column_from(EE_Message $message) |
|
178 | - { |
|
179 | - return esc_html($message->from()); |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @param EE_Message $message |
|
185 | - * @return string The messenger used to send the message. |
|
186 | - */ |
|
187 | - public function column_messenger(EE_Message $message) |
|
188 | - { |
|
189 | - return ucwords($message->messenger_label()); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @param EE_Message $message |
|
195 | - * @return string The message type used to generate the message. |
|
196 | - */ |
|
197 | - public function column_message_type(EE_Message $message) |
|
198 | - { |
|
199 | - return ucwords($message->message_type_label()); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @param EE_Message $message |
|
205 | - * @return string The context the message was generated for. |
|
206 | - */ |
|
207 | - public function column_context(EE_Message $message) |
|
208 | - { |
|
209 | - return $message->context_label(); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * @param EE_Message $message |
|
215 | - * @return string The timestamp when this message was last modified. |
|
216 | - */ |
|
217 | - public function column_modified(EE_Message $message) |
|
218 | - { |
|
219 | - return $message->modified(); |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * @param EE_Message $message |
|
225 | - * @return string Actions that can be done on the current message. |
|
226 | - */ |
|
227 | - public function column_action(EE_Message $message) |
|
228 | - { |
|
229 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
230 | - $action_links = array( |
|
231 | - 'view' => EEH_MSG_Template::get_message_action_link('view', $message), |
|
232 | - 'error' => EEH_MSG_Template::get_message_action_link('error', $message), |
|
233 | - 'generate_now' => EEH_MSG_Template::get_message_action_link('generate_now', $message), |
|
234 | - 'send_now' => EEH_MSG_Template::get_message_action_link('send_now', $message), |
|
235 | - 'queue_for_resending' => EEH_MSG_Template::get_message_action_link('queue_for_resending', $message), |
|
236 | - 'view_transaction' => EEH_MSG_Template::get_message_action_link('view_transaction', $message), |
|
237 | - ); |
|
238 | - $content = ''; |
|
239 | - switch ($message->STS_ID()) { |
|
240 | - case EEM_Message::status_sent: |
|
241 | - $content = $action_links['view'] . $action_links['queue_for_resending'] . $action_links['view_transaction']; |
|
242 | - break; |
|
243 | - case EEM_Message::status_resend: |
|
244 | - $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction']; |
|
245 | - break; |
|
246 | - case EEM_Message::status_retry: |
|
247 | - $content = $action_links['view'] . $action_links['send_now'] . $action_links['error'] . $action_links['view_transaction']; |
|
248 | - break; |
|
249 | - case EEM_Message::status_failed: |
|
250 | - case EEM_Message::status_debug_only: |
|
251 | - $content = $action_links['error'] . $action_links['view_transaction']; |
|
252 | - break; |
|
253 | - case EEM_Message::status_idle: |
|
254 | - $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction']; |
|
255 | - break; |
|
256 | - case EEM_Message::status_incomplete: |
|
257 | - $content = $action_links['generate_now'] . $action_links['view_transaction']; |
|
258 | - break; |
|
259 | - } |
|
260 | - return $content; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * Retrieve the EE_Message objects for the list table. |
|
266 | - * |
|
267 | - * @param int $perpage The number of items per page |
|
268 | - * @param string $view The view items are being retrieved for |
|
269 | - * @param bool $count Whether to just return a count or not. |
|
270 | - * @param bool $all Disregard any paging info (no limit on data returned). |
|
271 | - * @return int|EE_Message[] |
|
272 | - * @throws \EE_Error |
|
273 | - */ |
|
274 | - protected function _get_messages($perpage = 10, $view = 'all', $count = false, $all = false) |
|
275 | - { |
|
276 | - |
|
277 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
278 | - ? $this->_req_data['paged'] |
|
279 | - : 1; |
|
280 | - |
|
281 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
282 | - ? $this->_req_data['perpage'] |
|
283 | - : $perpage; |
|
284 | - |
|
285 | - $offset = ($current_page - 1) * $per_page; |
|
286 | - $limit = $all || $count ? null : array($offset, $per_page); |
|
287 | - $query_params = array( |
|
288 | - 'order_by' => empty($this->_req_data['orderby']) ? 'MSG_modified' : $this->_req_data['orderby'], |
|
289 | - 'order' => empty($this->_req_data['order']) ? 'DESC' : $this->_req_data['order'], |
|
290 | - 'limit' => $limit, |
|
291 | - ); |
|
292 | - |
|
293 | - /** |
|
294 | - * Any filters coming in from other routes? |
|
295 | - */ |
|
296 | - if (isset($this->_req_data['filterby'])) { |
|
297 | - $query_params = array_merge($query_params, EEM_Message::instance()->filter_by_query_params()); |
|
298 | - if (! $count) { |
|
299 | - $query_params['group_by'] = 'MSG_ID'; |
|
300 | - } |
|
301 | - } |
|
302 | - |
|
303 | - // view conditionals |
|
304 | - if ($view !== 'all' && $count && $all) { |
|
305 | - $query_params[0]['AND*view_conditional'] = array( |
|
306 | - 'STS_ID' => strtoupper($view), |
|
307 | - ); |
|
308 | - } |
|
309 | - |
|
310 | - if (! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') { |
|
311 | - $query_params[0]['AND*view_conditional'] = $this->_req_data === EEM_Message::status_failed |
|
312 | - ? array( |
|
313 | - 'STS_ID' => array( |
|
314 | - 'IN', |
|
315 | - array(EEM_Message::status_failed, EEM_Message::status_messenger_executing), |
|
316 | - ), |
|
317 | - ) |
|
318 | - : array('STS_ID' => strtoupper($this->_req_data['status'])); |
|
319 | - } |
|
320 | - |
|
321 | - if (! $all && ! empty($this->_req_data['s'])) { |
|
322 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
323 | - $query_params[0]['OR'] = array( |
|
324 | - 'MSG_to' => array('LIKE', $search_string), |
|
325 | - 'MSG_from' => array('LIKE', $search_string), |
|
326 | - 'MSG_subject' => array('LIKE', $search_string), |
|
327 | - 'MSG_content' => array('LIKE', $search_string), |
|
328 | - ); |
|
329 | - } |
|
330 | - |
|
331 | - // account for debug only status. We don't show Messages with the EEM_Message::status_debug_only to clients when |
|
332 | - // the messages system is in debug mode. |
|
333 | - // Note: for backward compat with previous iterations, this is necessary because there may be EEM_Message::status_debug_only |
|
334 | - // messages in the database. |
|
335 | - if (! EEM_Message::debug()) { |
|
336 | - $query_params[0]['AND*debug_only_conditional'] = array( |
|
337 | - 'STS_ID' => array('!=', EEM_Message::status_debug_only), |
|
338 | - ); |
|
339 | - } |
|
340 | - |
|
341 | - // account for filters |
|
342 | - if (! $all |
|
343 | - && isset($this->_req_data['ee_messenger_filter_by']) |
|
344 | - && $this->_req_data['ee_messenger_filter_by'] !== 'none_selected' |
|
345 | - ) { |
|
346 | - $query_params[0]['AND*messenger_filter'] = array( |
|
347 | - 'MSG_messenger' => $this->_req_data['ee_messenger_filter_by'], |
|
348 | - ); |
|
349 | - } |
|
350 | - if (! $all |
|
351 | - && ! empty($this->_req_data['ee_message_type_filter_by']) |
|
352 | - && $this->_req_data['ee_message_type_filter_by'] !== 'none_selected' |
|
353 | - ) { |
|
354 | - $query_params[0]['AND*message_type_filter'] = array( |
|
355 | - 'MSG_message_type' => $this->_req_data['ee_message_type_filter_by'], |
|
356 | - ); |
|
357 | - } |
|
358 | - |
|
359 | - if (! $all |
|
360 | - && ! empty($this->_req_data['ee_context_filter_by']) |
|
361 | - && $this->_req_data['ee_context_filter_by'] !== 'none_selected' |
|
362 | - ) { |
|
363 | - $query_params[0]['AND*context_filter'] = array( |
|
364 | - 'MSG_context' => array('IN', explode(',', $this->_req_data['ee_context_filter_by'])), |
|
365 | - ); |
|
366 | - } |
|
367 | - |
|
368 | - return $count |
|
369 | - /** @type int */ |
|
370 | - ? EEM_Message::instance()->count($query_params, null, true) |
|
371 | - /** @type EE_Message[] */ |
|
372 | - : EEM_Message::instance()->get_all($query_params); |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * Generate dropdown filter select input for messengers. |
|
378 | - * |
|
379 | - * @return string |
|
380 | - */ |
|
381 | - protected function _get_messengers_dropdown_filter() |
|
382 | - { |
|
383 | - $messenger_options = array(); |
|
384 | - $active_messages_grouped_by_messenger = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
385 | - |
|
386 | - // setup array of messenger options |
|
387 | - foreach ($active_messages_grouped_by_messenger as $active_message) { |
|
388 | - if ($active_message instanceof EE_Message) { |
|
389 | - $messenger_options[ $active_message->messenger() ] = ucwords($active_message->messenger_label()); |
|
390 | - } |
|
391 | - } |
|
392 | - return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * Generate dropdown filter select input for message types |
|
398 | - * |
|
399 | - * @return string |
|
400 | - */ |
|
401 | - protected function _get_message_types_dropdown_filter() |
|
402 | - { |
|
403 | - $message_type_options = array(); |
|
404 | - $active_messages_grouped_by_message_type = EEM_Message::instance()->get_all( |
|
405 | - array('group_by' => 'MSG_message_type') |
|
406 | - ); |
|
407 | - |
|
408 | - // setup array of message type options |
|
409 | - foreach ($active_messages_grouped_by_message_type as $active_message) { |
|
410 | - if ($active_message instanceof EE_Message) { |
|
411 | - $message_type_options[ $active_message->message_type() ] = ucwords( |
|
412 | - $active_message->message_type_label() |
|
413 | - ); |
|
414 | - } |
|
415 | - } |
|
416 | - return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * Generate dropdown filter select input for message type contexts |
|
422 | - * |
|
423 | - * @return string |
|
424 | - */ |
|
425 | - protected function _get_contexts_for_message_types_dropdown_filter() |
|
426 | - { |
|
427 | - $context_options = array(); |
|
428 | - $active_messages_grouped_by_context = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
429 | - |
|
430 | - // setup array of context options |
|
431 | - foreach ($active_messages_grouped_by_context as $active_message) { |
|
432 | - if ($active_message instanceof EE_Message) { |
|
433 | - $message_type = $active_message->message_type_object(); |
|
434 | - if ($message_type instanceof EE_message_type) { |
|
435 | - foreach ($message_type->get_contexts() as $context => $context_details) { |
|
436 | - if (isset($context_details['label'])) { |
|
437 | - $context_options[ $context ] = $context_details['label']; |
|
438 | - } |
|
439 | - } |
|
440 | - } |
|
441 | - } |
|
442 | - } |
|
443 | - return $this->get_admin_page()->get_contexts_for_message_types_select_input($context_options); |
|
444 | - } |
|
15 | + /** |
|
16 | + * @return Messages_Admin_Page |
|
17 | + */ |
|
18 | + public function get_admin_page() |
|
19 | + { |
|
20 | + return $this->_admin_page; |
|
21 | + } |
|
22 | + |
|
23 | + |
|
24 | + protected function _setup_data() |
|
25 | + { |
|
26 | + $this->_data = $this->_get_messages($this->_per_page, $this->_view); |
|
27 | + $this->_all_data_count = $this->_get_messages($this->_per_page, $this->_view, true); |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + protected function _set_properties() |
|
32 | + { |
|
33 | + $this->_wp_list_args = array( |
|
34 | + 'singular' => __('Message', 'event_espresso'), |
|
35 | + 'plural' => __('Messages', 'event_espresso'), |
|
36 | + 'ajax' => true, |
|
37 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
38 | + ); |
|
39 | + |
|
40 | + $this->_columns = array( |
|
41 | + 'cb' => '<input type="checkbox" />', |
|
42 | + 'to' => __('To', 'event_espresso'), |
|
43 | + 'from' => __('From', 'event_espresso'), |
|
44 | + 'messenger' => __('Messenger', 'event_espresso'), |
|
45 | + 'message_type' => __('Message Type', 'event_espresso'), |
|
46 | + 'context' => __('Context', 'event_espresso'), |
|
47 | + 'modified' => __('Modified', 'event_espresso'), |
|
48 | + 'action' => __('Actions', 'event_espresso'), |
|
49 | + 'msg_id' => __('ID', 'event_espresso'), |
|
50 | + ); |
|
51 | + |
|
52 | + $this->_sortable_columns = array( |
|
53 | + 'modified' => array('MSG_modified' => true), |
|
54 | + 'message_type' => array('MSG_message_type' => false), |
|
55 | + 'messenger' => array('MSG_messenger' => false), |
|
56 | + 'to' => array('MSG_to' => false), |
|
57 | + 'from' => array('MSG_from' => false), |
|
58 | + 'context' => array('MSG_context' => false), |
|
59 | + 'msg_id' => array('MSG_ID', false), |
|
60 | + ); |
|
61 | + |
|
62 | + $this->_primary_column = 'to'; |
|
63 | + |
|
64 | + $this->_hidden_columns = array( |
|
65 | + 'msg_id', |
|
66 | + ); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * This simply sets up the row class for the table rows. |
|
72 | + * Allows for easier overriding of child methods for setting up sorting. |
|
73 | + * |
|
74 | + * @param object $item the current item |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + protected function _get_row_class($item) |
|
78 | + { |
|
79 | + $class = parent::_get_row_class($item); |
|
80 | + // add status class |
|
81 | + $class .= ' ee-status-strip msg-status-' . $item->STS_ID(); |
|
82 | + if ($this->_has_checkbox_column) { |
|
83 | + $class .= ' has-checkbox-column'; |
|
84 | + } |
|
85 | + return $class; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * _get_table_filters |
|
91 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
92 | + * get's shown in the table. |
|
93 | + * |
|
94 | + * @abstract |
|
95 | + * @access protected |
|
96 | + * @return string |
|
97 | + * @throws \EE_Error |
|
98 | + */ |
|
99 | + protected function _get_table_filters() |
|
100 | + { |
|
101 | + $filters = array(); |
|
102 | + |
|
103 | + // get select_inputs |
|
104 | + $select_inputs = array( |
|
105 | + $this->_get_messengers_dropdown_filter(), |
|
106 | + $this->_get_message_types_dropdown_filter(), |
|
107 | + $this->_get_contexts_for_message_types_dropdown_filter(), |
|
108 | + ); |
|
109 | + |
|
110 | + // set filters to select inputs if they aren't empty |
|
111 | + foreach ($select_inputs as $select_input) { |
|
112 | + if ($select_input) { |
|
113 | + $filters[] = $select_input; |
|
114 | + } |
|
115 | + } |
|
116 | + return $filters; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + protected function _add_view_counts() |
|
121 | + { |
|
122 | + foreach ($this->_views as $view => $args) { |
|
123 | + $this->_views[ $view ]['count'] = $this->_get_messages($this->_per_page, $view, true, true); |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @param EE_Message $message |
|
130 | + * @return string checkbox |
|
131 | + * @throws \EE_Error |
|
132 | + */ |
|
133 | + public function column_cb($message) |
|
134 | + { |
|
135 | + return sprintf('<input type="checkbox" name="MSG_ID[%s]" value="1" />', $message->ID()); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param EE_Message $message |
|
141 | + * @return string |
|
142 | + * @throws \EE_Error |
|
143 | + */ |
|
144 | + public function column_msg_id(EE_Message $message) |
|
145 | + { |
|
146 | + return $message->ID(); |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @param EE_Message $message |
|
152 | + * @return string The recipient of the message |
|
153 | + * @throws \EE_Error |
|
154 | + */ |
|
155 | + public function column_to(EE_Message $message) |
|
156 | + { |
|
157 | + EE_Registry::instance()->load_helper('URL'); |
|
158 | + $actions = array(); |
|
159 | + $actions['delete'] = '<a href="' |
|
160 | + . EEH_URL::add_query_args_and_nonce( |
|
161 | + array( |
|
162 | + 'page' => 'espresso_messages', |
|
163 | + 'action' => 'delete_ee_message', |
|
164 | + 'MSG_ID' => $message->ID(), |
|
165 | + ), |
|
166 | + admin_url('admin.php') |
|
167 | + ) |
|
168 | + . '">' . __('Delete', 'event_espresso') . '</a>'; |
|
169 | + return esc_html($message->to()) . $this->row_actions($actions); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * @param EE_Message $message |
|
175 | + * @return string The sender of the message |
|
176 | + */ |
|
177 | + public function column_from(EE_Message $message) |
|
178 | + { |
|
179 | + return esc_html($message->from()); |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @param EE_Message $message |
|
185 | + * @return string The messenger used to send the message. |
|
186 | + */ |
|
187 | + public function column_messenger(EE_Message $message) |
|
188 | + { |
|
189 | + return ucwords($message->messenger_label()); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @param EE_Message $message |
|
195 | + * @return string The message type used to generate the message. |
|
196 | + */ |
|
197 | + public function column_message_type(EE_Message $message) |
|
198 | + { |
|
199 | + return ucwords($message->message_type_label()); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @param EE_Message $message |
|
205 | + * @return string The context the message was generated for. |
|
206 | + */ |
|
207 | + public function column_context(EE_Message $message) |
|
208 | + { |
|
209 | + return $message->context_label(); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * @param EE_Message $message |
|
215 | + * @return string The timestamp when this message was last modified. |
|
216 | + */ |
|
217 | + public function column_modified(EE_Message $message) |
|
218 | + { |
|
219 | + return $message->modified(); |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * @param EE_Message $message |
|
225 | + * @return string Actions that can be done on the current message. |
|
226 | + */ |
|
227 | + public function column_action(EE_Message $message) |
|
228 | + { |
|
229 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
230 | + $action_links = array( |
|
231 | + 'view' => EEH_MSG_Template::get_message_action_link('view', $message), |
|
232 | + 'error' => EEH_MSG_Template::get_message_action_link('error', $message), |
|
233 | + 'generate_now' => EEH_MSG_Template::get_message_action_link('generate_now', $message), |
|
234 | + 'send_now' => EEH_MSG_Template::get_message_action_link('send_now', $message), |
|
235 | + 'queue_for_resending' => EEH_MSG_Template::get_message_action_link('queue_for_resending', $message), |
|
236 | + 'view_transaction' => EEH_MSG_Template::get_message_action_link('view_transaction', $message), |
|
237 | + ); |
|
238 | + $content = ''; |
|
239 | + switch ($message->STS_ID()) { |
|
240 | + case EEM_Message::status_sent: |
|
241 | + $content = $action_links['view'] . $action_links['queue_for_resending'] . $action_links['view_transaction']; |
|
242 | + break; |
|
243 | + case EEM_Message::status_resend: |
|
244 | + $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction']; |
|
245 | + break; |
|
246 | + case EEM_Message::status_retry: |
|
247 | + $content = $action_links['view'] . $action_links['send_now'] . $action_links['error'] . $action_links['view_transaction']; |
|
248 | + break; |
|
249 | + case EEM_Message::status_failed: |
|
250 | + case EEM_Message::status_debug_only: |
|
251 | + $content = $action_links['error'] . $action_links['view_transaction']; |
|
252 | + break; |
|
253 | + case EEM_Message::status_idle: |
|
254 | + $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction']; |
|
255 | + break; |
|
256 | + case EEM_Message::status_incomplete: |
|
257 | + $content = $action_links['generate_now'] . $action_links['view_transaction']; |
|
258 | + break; |
|
259 | + } |
|
260 | + return $content; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * Retrieve the EE_Message objects for the list table. |
|
266 | + * |
|
267 | + * @param int $perpage The number of items per page |
|
268 | + * @param string $view The view items are being retrieved for |
|
269 | + * @param bool $count Whether to just return a count or not. |
|
270 | + * @param bool $all Disregard any paging info (no limit on data returned). |
|
271 | + * @return int|EE_Message[] |
|
272 | + * @throws \EE_Error |
|
273 | + */ |
|
274 | + protected function _get_messages($perpage = 10, $view = 'all', $count = false, $all = false) |
|
275 | + { |
|
276 | + |
|
277 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
278 | + ? $this->_req_data['paged'] |
|
279 | + : 1; |
|
280 | + |
|
281 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
282 | + ? $this->_req_data['perpage'] |
|
283 | + : $perpage; |
|
284 | + |
|
285 | + $offset = ($current_page - 1) * $per_page; |
|
286 | + $limit = $all || $count ? null : array($offset, $per_page); |
|
287 | + $query_params = array( |
|
288 | + 'order_by' => empty($this->_req_data['orderby']) ? 'MSG_modified' : $this->_req_data['orderby'], |
|
289 | + 'order' => empty($this->_req_data['order']) ? 'DESC' : $this->_req_data['order'], |
|
290 | + 'limit' => $limit, |
|
291 | + ); |
|
292 | + |
|
293 | + /** |
|
294 | + * Any filters coming in from other routes? |
|
295 | + */ |
|
296 | + if (isset($this->_req_data['filterby'])) { |
|
297 | + $query_params = array_merge($query_params, EEM_Message::instance()->filter_by_query_params()); |
|
298 | + if (! $count) { |
|
299 | + $query_params['group_by'] = 'MSG_ID'; |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + // view conditionals |
|
304 | + if ($view !== 'all' && $count && $all) { |
|
305 | + $query_params[0]['AND*view_conditional'] = array( |
|
306 | + 'STS_ID' => strtoupper($view), |
|
307 | + ); |
|
308 | + } |
|
309 | + |
|
310 | + if (! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') { |
|
311 | + $query_params[0]['AND*view_conditional'] = $this->_req_data === EEM_Message::status_failed |
|
312 | + ? array( |
|
313 | + 'STS_ID' => array( |
|
314 | + 'IN', |
|
315 | + array(EEM_Message::status_failed, EEM_Message::status_messenger_executing), |
|
316 | + ), |
|
317 | + ) |
|
318 | + : array('STS_ID' => strtoupper($this->_req_data['status'])); |
|
319 | + } |
|
320 | + |
|
321 | + if (! $all && ! empty($this->_req_data['s'])) { |
|
322 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
323 | + $query_params[0]['OR'] = array( |
|
324 | + 'MSG_to' => array('LIKE', $search_string), |
|
325 | + 'MSG_from' => array('LIKE', $search_string), |
|
326 | + 'MSG_subject' => array('LIKE', $search_string), |
|
327 | + 'MSG_content' => array('LIKE', $search_string), |
|
328 | + ); |
|
329 | + } |
|
330 | + |
|
331 | + // account for debug only status. We don't show Messages with the EEM_Message::status_debug_only to clients when |
|
332 | + // the messages system is in debug mode. |
|
333 | + // Note: for backward compat with previous iterations, this is necessary because there may be EEM_Message::status_debug_only |
|
334 | + // messages in the database. |
|
335 | + if (! EEM_Message::debug()) { |
|
336 | + $query_params[0]['AND*debug_only_conditional'] = array( |
|
337 | + 'STS_ID' => array('!=', EEM_Message::status_debug_only), |
|
338 | + ); |
|
339 | + } |
|
340 | + |
|
341 | + // account for filters |
|
342 | + if (! $all |
|
343 | + && isset($this->_req_data['ee_messenger_filter_by']) |
|
344 | + && $this->_req_data['ee_messenger_filter_by'] !== 'none_selected' |
|
345 | + ) { |
|
346 | + $query_params[0]['AND*messenger_filter'] = array( |
|
347 | + 'MSG_messenger' => $this->_req_data['ee_messenger_filter_by'], |
|
348 | + ); |
|
349 | + } |
|
350 | + if (! $all |
|
351 | + && ! empty($this->_req_data['ee_message_type_filter_by']) |
|
352 | + && $this->_req_data['ee_message_type_filter_by'] !== 'none_selected' |
|
353 | + ) { |
|
354 | + $query_params[0]['AND*message_type_filter'] = array( |
|
355 | + 'MSG_message_type' => $this->_req_data['ee_message_type_filter_by'], |
|
356 | + ); |
|
357 | + } |
|
358 | + |
|
359 | + if (! $all |
|
360 | + && ! empty($this->_req_data['ee_context_filter_by']) |
|
361 | + && $this->_req_data['ee_context_filter_by'] !== 'none_selected' |
|
362 | + ) { |
|
363 | + $query_params[0]['AND*context_filter'] = array( |
|
364 | + 'MSG_context' => array('IN', explode(',', $this->_req_data['ee_context_filter_by'])), |
|
365 | + ); |
|
366 | + } |
|
367 | + |
|
368 | + return $count |
|
369 | + /** @type int */ |
|
370 | + ? EEM_Message::instance()->count($query_params, null, true) |
|
371 | + /** @type EE_Message[] */ |
|
372 | + : EEM_Message::instance()->get_all($query_params); |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * Generate dropdown filter select input for messengers. |
|
378 | + * |
|
379 | + * @return string |
|
380 | + */ |
|
381 | + protected function _get_messengers_dropdown_filter() |
|
382 | + { |
|
383 | + $messenger_options = array(); |
|
384 | + $active_messages_grouped_by_messenger = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
385 | + |
|
386 | + // setup array of messenger options |
|
387 | + foreach ($active_messages_grouped_by_messenger as $active_message) { |
|
388 | + if ($active_message instanceof EE_Message) { |
|
389 | + $messenger_options[ $active_message->messenger() ] = ucwords($active_message->messenger_label()); |
|
390 | + } |
|
391 | + } |
|
392 | + return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * Generate dropdown filter select input for message types |
|
398 | + * |
|
399 | + * @return string |
|
400 | + */ |
|
401 | + protected function _get_message_types_dropdown_filter() |
|
402 | + { |
|
403 | + $message_type_options = array(); |
|
404 | + $active_messages_grouped_by_message_type = EEM_Message::instance()->get_all( |
|
405 | + array('group_by' => 'MSG_message_type') |
|
406 | + ); |
|
407 | + |
|
408 | + // setup array of message type options |
|
409 | + foreach ($active_messages_grouped_by_message_type as $active_message) { |
|
410 | + if ($active_message instanceof EE_Message) { |
|
411 | + $message_type_options[ $active_message->message_type() ] = ucwords( |
|
412 | + $active_message->message_type_label() |
|
413 | + ); |
|
414 | + } |
|
415 | + } |
|
416 | + return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * Generate dropdown filter select input for message type contexts |
|
422 | + * |
|
423 | + * @return string |
|
424 | + */ |
|
425 | + protected function _get_contexts_for_message_types_dropdown_filter() |
|
426 | + { |
|
427 | + $context_options = array(); |
|
428 | + $active_messages_grouped_by_context = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
429 | + |
|
430 | + // setup array of context options |
|
431 | + foreach ($active_messages_grouped_by_context as $active_message) { |
|
432 | + if ($active_message instanceof EE_Message) { |
|
433 | + $message_type = $active_message->message_type_object(); |
|
434 | + if ($message_type instanceof EE_message_type) { |
|
435 | + foreach ($message_type->get_contexts() as $context => $context_details) { |
|
436 | + if (isset($context_details['label'])) { |
|
437 | + $context_options[ $context ] = $context_details['label']; |
|
438 | + } |
|
439 | + } |
|
440 | + } |
|
441 | + } |
|
442 | + } |
|
443 | + return $this->get_admin_page()->get_contexts_for_message_types_select_input($context_options); |
|
444 | + } |
|
445 | 445 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | { |
79 | 79 | $class = parent::_get_row_class($item); |
80 | 80 | // add status class |
81 | - $class .= ' ee-status-strip msg-status-' . $item->STS_ID(); |
|
81 | + $class .= ' ee-status-strip msg-status-'.$item->STS_ID(); |
|
82 | 82 | if ($this->_has_checkbox_column) { |
83 | 83 | $class .= ' has-checkbox-column'; |
84 | 84 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | protected function _add_view_counts() |
121 | 121 | { |
122 | 122 | foreach ($this->_views as $view => $args) { |
123 | - $this->_views[ $view ]['count'] = $this->_get_messages($this->_per_page, $view, true, true); |
|
123 | + $this->_views[$view]['count'] = $this->_get_messages($this->_per_page, $view, true, true); |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | ), |
166 | 166 | admin_url('admin.php') |
167 | 167 | ) |
168 | - . '">' . __('Delete', 'event_espresso') . '</a>'; |
|
169 | - return esc_html($message->to()) . $this->row_actions($actions); |
|
168 | + . '">'.__('Delete', 'event_espresso').'</a>'; |
|
169 | + return esc_html($message->to()).$this->row_actions($actions); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | |
@@ -238,23 +238,23 @@ discard block |
||
238 | 238 | $content = ''; |
239 | 239 | switch ($message->STS_ID()) { |
240 | 240 | case EEM_Message::status_sent: |
241 | - $content = $action_links['view'] . $action_links['queue_for_resending'] . $action_links['view_transaction']; |
|
241 | + $content = $action_links['view'].$action_links['queue_for_resending'].$action_links['view_transaction']; |
|
242 | 242 | break; |
243 | 243 | case EEM_Message::status_resend: |
244 | - $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction']; |
|
244 | + $content = $action_links['view'].$action_links['send_now'].$action_links['view_transaction']; |
|
245 | 245 | break; |
246 | 246 | case EEM_Message::status_retry: |
247 | - $content = $action_links['view'] . $action_links['send_now'] . $action_links['error'] . $action_links['view_transaction']; |
|
247 | + $content = $action_links['view'].$action_links['send_now'].$action_links['error'].$action_links['view_transaction']; |
|
248 | 248 | break; |
249 | 249 | case EEM_Message::status_failed: |
250 | 250 | case EEM_Message::status_debug_only: |
251 | - $content = $action_links['error'] . $action_links['view_transaction']; |
|
251 | + $content = $action_links['error'].$action_links['view_transaction']; |
|
252 | 252 | break; |
253 | 253 | case EEM_Message::status_idle: |
254 | - $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction']; |
|
254 | + $content = $action_links['view'].$action_links['send_now'].$action_links['view_transaction']; |
|
255 | 255 | break; |
256 | 256 | case EEM_Message::status_incomplete: |
257 | - $content = $action_links['generate_now'] . $action_links['view_transaction']; |
|
257 | + $content = $action_links['generate_now'].$action_links['view_transaction']; |
|
258 | 258 | break; |
259 | 259 | } |
260 | 260 | return $content; |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | */ |
296 | 296 | if (isset($this->_req_data['filterby'])) { |
297 | 297 | $query_params = array_merge($query_params, EEM_Message::instance()->filter_by_query_params()); |
298 | - if (! $count) { |
|
298 | + if ( ! $count) { |
|
299 | 299 | $query_params['group_by'] = 'MSG_ID'; |
300 | 300 | } |
301 | 301 | } |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | ); |
308 | 308 | } |
309 | 309 | |
310 | - if (! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') { |
|
310 | + if ( ! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') { |
|
311 | 311 | $query_params[0]['AND*view_conditional'] = $this->_req_data === EEM_Message::status_failed |
312 | 312 | ? array( |
313 | 313 | 'STS_ID' => array( |
@@ -318,8 +318,8 @@ discard block |
||
318 | 318 | : array('STS_ID' => strtoupper($this->_req_data['status'])); |
319 | 319 | } |
320 | 320 | |
321 | - if (! $all && ! empty($this->_req_data['s'])) { |
|
322 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
321 | + if ( ! $all && ! empty($this->_req_data['s'])) { |
|
322 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
323 | 323 | $query_params[0]['OR'] = array( |
324 | 324 | 'MSG_to' => array('LIKE', $search_string), |
325 | 325 | 'MSG_from' => array('LIKE', $search_string), |
@@ -332,14 +332,14 @@ discard block |
||
332 | 332 | // the messages system is in debug mode. |
333 | 333 | // Note: for backward compat with previous iterations, this is necessary because there may be EEM_Message::status_debug_only |
334 | 334 | // messages in the database. |
335 | - if (! EEM_Message::debug()) { |
|
335 | + if ( ! EEM_Message::debug()) { |
|
336 | 336 | $query_params[0]['AND*debug_only_conditional'] = array( |
337 | 337 | 'STS_ID' => array('!=', EEM_Message::status_debug_only), |
338 | 338 | ); |
339 | 339 | } |
340 | 340 | |
341 | 341 | // account for filters |
342 | - if (! $all |
|
342 | + if ( ! $all |
|
343 | 343 | && isset($this->_req_data['ee_messenger_filter_by']) |
344 | 344 | && $this->_req_data['ee_messenger_filter_by'] !== 'none_selected' |
345 | 345 | ) { |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | 'MSG_messenger' => $this->_req_data['ee_messenger_filter_by'], |
348 | 348 | ); |
349 | 349 | } |
350 | - if (! $all |
|
350 | + if ( ! $all |
|
351 | 351 | && ! empty($this->_req_data['ee_message_type_filter_by']) |
352 | 352 | && $this->_req_data['ee_message_type_filter_by'] !== 'none_selected' |
353 | 353 | ) { |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | ); |
357 | 357 | } |
358 | 358 | |
359 | - if (! $all |
|
359 | + if ( ! $all |
|
360 | 360 | && ! empty($this->_req_data['ee_context_filter_by']) |
361 | 361 | && $this->_req_data['ee_context_filter_by'] !== 'none_selected' |
362 | 362 | ) { |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | // setup array of messenger options |
387 | 387 | foreach ($active_messages_grouped_by_messenger as $active_message) { |
388 | 388 | if ($active_message instanceof EE_Message) { |
389 | - $messenger_options[ $active_message->messenger() ] = ucwords($active_message->messenger_label()); |
|
389 | + $messenger_options[$active_message->messenger()] = ucwords($active_message->messenger_label()); |
|
390 | 390 | } |
391 | 391 | } |
392 | 392 | return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | // setup array of message type options |
409 | 409 | foreach ($active_messages_grouped_by_message_type as $active_message) { |
410 | 410 | if ($active_message instanceof EE_Message) { |
411 | - $message_type_options[ $active_message->message_type() ] = ucwords( |
|
411 | + $message_type_options[$active_message->message_type()] = ucwords( |
|
412 | 412 | $active_message->message_type_label() |
413 | 413 | ); |
414 | 414 | } |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | if ($message_type instanceof EE_message_type) { |
435 | 435 | foreach ($message_type->get_contexts() as $context => $context_details) { |
436 | 436 | if (isset($context_details['label'])) { |
437 | - $context_options[ $context ] = $context_details['label']; |
|
437 | + $context_options[$context] = $context_details['label']; |
|
438 | 438 | } |
439 | 439 | } |
440 | 440 | } |
@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice; |
4 | -use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
5 | 4 | |
6 | 5 | /** |
7 | 6 | * Event Espresso |
@@ -24,678 +24,678 @@ |
||
24 | 24 | class EE_Admin_Page_Loader |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * _installed_pages |
|
29 | - * objects for page_init objects detected and loaded |
|
30 | - * |
|
31 | - * @access private |
|
32 | - * @var \EE_Admin_Page_Init[] |
|
33 | - */ |
|
34 | - private $_installed_pages = array(); |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * this is used to hold the registry of menu slugs for all the installed admin pages |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - private $_menu_slugs = array(); |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * _caffeinated_extends |
|
47 | - * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and |
|
48 | - * pieces needed to do so). This property is defined in the _set_caffeinated method. |
|
49 | - * |
|
50 | - * @var array |
|
51 | - */ |
|
52 | - private $_caffeinated_extends = array(); |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * _current_caf_extend_slug |
|
57 | - * This property is used for holding the page slug that is required for referencing the correct |
|
58 | - * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - private $_current_caf_extend_slug; |
|
63 | - |
|
64 | - /** |
|
65 | - * _prepped_menu_maps |
|
66 | - * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu. |
|
67 | - * |
|
68 | - * @since 4.4.0 |
|
69 | - * @var EE_Admin_Page_Menu_Map[] |
|
70 | - */ |
|
71 | - private $_prepped_menu_maps = array(); |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * _admin_menu_groups |
|
76 | - * array that holds the group headings and details for |
|
77 | - * |
|
78 | - * @access private |
|
79 | - * @var array |
|
80 | - */ |
|
81 | - private $_admin_menu_groups = array(); |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * This property will hold the hook file for setting up the filter that does all the connections between admin |
|
86 | - * pages. |
|
87 | - * |
|
88 | - * @var string |
|
89 | - */ |
|
90 | - public $hook_file; |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * constructor |
|
95 | - * |
|
96 | - * @access public |
|
97 | - * @return \EE_Admin_Page_Loader |
|
98 | - */ |
|
99 | - public function __construct() |
|
100 | - { |
|
101 | - // load menu_map classes |
|
102 | - EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core'); |
|
103 | - // define the default "groups" for the admin_pages |
|
104 | - $this->_set_menu_groups(); |
|
105 | - |
|
106 | - // let's do a scan and see what installed pages we have |
|
107 | - $this->_get_installed_pages(); |
|
108 | - // set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to). |
|
109 | - add_action('admin_menu', array($this, 'set_menus')); |
|
110 | - add_action('network_admin_menu', array($this, 'set_network_menus')); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by |
|
116 | - * files in the caffeinated folder. |
|
117 | - * |
|
118 | - * @access private |
|
119 | - * @return void |
|
120 | - */ |
|
121 | - private function _define_caffeinated_constants() |
|
122 | - { |
|
123 | - if (! defined('EE_CORE_CAF_ADMIN')) { |
|
124 | - define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
125 | - define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
126 | - define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
127 | - define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
128 | - define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
129 | - define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * _set_menu_groups |
|
136 | - * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
137 | - * |
|
138 | - * @access private |
|
139 | - * @return void |
|
140 | - */ |
|
141 | - private function _set_menu_groups() |
|
142 | - { |
|
143 | - |
|
144 | - // set array of EE_Admin_Page_Menu_Group objects |
|
145 | - $groups = array( |
|
146 | - 'main' => new EE_Admin_Page_Menu_Group( |
|
147 | - array( |
|
148 | - 'menu_label' => __('Main', 'event_espresso'), |
|
149 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::NONE, |
|
150 | - 'menu_slug' => 'main', |
|
151 | - 'capability' => 'ee_read_ee', |
|
152 | - 'menu_order' => 0, |
|
153 | - 'parent_slug' => 'espresso_events', |
|
154 | - ) |
|
155 | - ), |
|
156 | - 'management' => new EE_Admin_Page_Menu_Group( |
|
157 | - array( |
|
158 | - 'menu_label' => __('Management', 'event_espresso'), |
|
159 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
160 | - 'menu_slug' => 'management', |
|
161 | - 'capability' => 'ee_read_ee', |
|
162 | - 'menu_order' => 10, |
|
163 | - 'parent_slug' => 'espresso_events', |
|
164 | - ) |
|
165 | - ), |
|
166 | - 'settings' => new EE_Admin_Page_Menu_Group( |
|
167 | - array( |
|
168 | - 'menu_label' => __('Settings', 'event_espresso'), |
|
169 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
170 | - 'menu_slug' => 'settings', |
|
171 | - 'capability' => 'ee_read_ee', |
|
172 | - 'menu_order' => 30, |
|
173 | - 'parent_slug' => 'espresso_events', |
|
174 | - ) |
|
175 | - ), |
|
176 | - 'templates' => new EE_Admin_Page_Menu_Group( |
|
177 | - array( |
|
178 | - 'menu_label' => __('Templates', 'event_espresso'), |
|
179 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
180 | - 'menu_slug' => 'templates', |
|
181 | - 'capability' => 'ee_read_ee', |
|
182 | - 'menu_order' => 40, |
|
183 | - 'parent_slug' => 'espresso_events', |
|
184 | - ) |
|
185 | - ), |
|
186 | - 'extras' => new EE_Admin_Page_Menu_Group( |
|
187 | - array( |
|
188 | - 'menu_label' => __('Extras', 'event_espresso'), |
|
189 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
190 | - 'menu_slug' => 'extras', |
|
191 | - 'capability' => 'ee_read_ee', |
|
192 | - 'menu_order' => 50, |
|
193 | - 'parent_slug' => 'espresso_events', |
|
194 | - 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
195 | - ) |
|
196 | - ), |
|
197 | - 'tools' => new EE_Admin_Page_Menu_Group( |
|
198 | - array( |
|
199 | - 'menu_label' => __("Tools", "event_espresso"), |
|
200 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
201 | - 'menu_slug' => 'tools', |
|
202 | - 'capability' => 'ee_read_ee', |
|
203 | - 'menu_order' => 60, |
|
204 | - 'parent_slug' => 'espresso_events', |
|
205 | - ) |
|
206 | - ), |
|
207 | - 'addons' => new EE_Admin_Page_Menu_Group( |
|
208 | - array( |
|
209 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
210 | - 'menu_label' => __('Add-ons', 'event_espresso'), |
|
211 | - 'menu_slug' => 'addons', |
|
212 | - 'capability' => 'ee_read_ee', |
|
213 | - 'menu_order' => 20, |
|
214 | - 'parent_slug' => 'espresso_events', |
|
215 | - ) |
|
216 | - ), |
|
217 | - ); |
|
218 | - $this->_admin_menu_groups = apply_filters( |
|
219 | - 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
220 | - $groups |
|
221 | - ); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group |
|
227 | - * slug. The other utility with this function is it validates that all the groups are instances of |
|
228 | - * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons). |
|
229 | - * |
|
230 | - * @since 4.4.0 |
|
231 | - * @throws \EE_Error |
|
232 | - * @return EE_Admin_Page_Menu_Group[] |
|
233 | - */ |
|
234 | - private function _rearrange_menu_groups() |
|
235 | - { |
|
236 | - $groups = array(); |
|
237 | - // first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
|
238 | - usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
|
239 | - foreach ($this->_admin_menu_groups as $group) { |
|
240 | - if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
241 | - throw new EE_Error( |
|
242 | - sprintf( |
|
243 | - __( |
|
244 | - 'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', |
|
245 | - 'event_espresso' |
|
246 | - ), |
|
247 | - print_r($group, true) |
|
248 | - ) |
|
249 | - ); |
|
250 | - } |
|
251 | - $groups[ $group->menu_slug ] = $group; |
|
252 | - } |
|
253 | - return $groups; |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * _get_installed_pages |
|
259 | - * This just gets the list of installed EE_Admin_pages. |
|
260 | - * |
|
261 | - * @access private |
|
262 | - * @throws EE_Error |
|
263 | - * @return void |
|
264 | - */ |
|
265 | - private function _get_installed_pages() |
|
266 | - { |
|
267 | - $installed_refs = array(); |
|
268 | - $exclude = array('assets', 'templates'); |
|
269 | - // grab everything in the admin core directory |
|
270 | - $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
271 | - if ($admin_screens) { |
|
272 | - foreach ($admin_screens as $admin_screen) { |
|
273 | - // files and anything in the exclude array need not apply |
|
274 | - if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
275 | - // these folders represent the different EE admin pages |
|
276 | - $installed_refs[ basename($admin_screen) ] = $admin_screen; |
|
277 | - } |
|
278 | - } |
|
279 | - } |
|
280 | - if (empty($installed_refs)) { |
|
281 | - $error_msg[] = __( |
|
282 | - 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
|
283 | - 'event_espresso' |
|
284 | - ); |
|
285 | - $error_msg[] = $error_msg[0] . "\r\n" |
|
286 | - . sprintf( |
|
287 | - __( |
|
288 | - 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
|
289 | - 'event_espresso' |
|
290 | - ), |
|
291 | - EE_ADMIN_PAGES |
|
292 | - ); |
|
293 | - throw new EE_Error(implode('||', $error_msg)); |
|
294 | - } |
|
295 | - // this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
|
296 | - $installed_refs = $this->_set_caffeinated($installed_refs); |
|
297 | - // allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
|
298 | - $installed_refs = apply_filters( |
|
299 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
300 | - $installed_refs |
|
301 | - ); |
|
302 | - $this->_caffeinated_extends = apply_filters( |
|
303 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', |
|
304 | - $this->_caffeinated_extends |
|
305 | - ); |
|
306 | - // loop through admin pages and setup the $_installed_pages array. |
|
307 | - $hooks_ref = array(); |
|
308 | - foreach ($installed_refs as $page => $path) { |
|
309 | - // set autoloaders for our admin page classes based on included path information |
|
310 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path); |
|
311 | - // build list of installed pages |
|
312 | - $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path); |
|
313 | - // verify returned object |
|
314 | - if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
315 | - if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
316 | - continue; |
|
317 | - } |
|
318 | - // skip if in full maintenance mode and maintenance_mode_parent is set |
|
319 | - $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent; |
|
320 | - if (empty($maintenance_mode_parent) |
|
321 | - && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
322 | - ) { |
|
323 | - unset($installed_refs[ $page ]); |
|
324 | - continue; |
|
325 | - } |
|
326 | - $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug; |
|
327 | - $this->_menu_slugs[ $menu_slug ] = $page; |
|
328 | - // flag for register hooks on extended pages b/c extended pages use the default INIT. |
|
329 | - $extend = false; |
|
330 | - // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
|
331 | - if (isset($this->_caffeinated_extends[ $page ])) { |
|
332 | - $this->_current_caf_extend_slug = $page; |
|
333 | - $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name(); |
|
334 | - $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path']; |
|
335 | - $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page']; |
|
336 | - add_filter( |
|
337 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}", |
|
338 | - function ($path_to_file) use ($caf_path) { |
|
339 | - return $caf_path; |
|
340 | - } |
|
341 | - ); |
|
342 | - add_filter( |
|
343 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}", |
|
344 | - function ($admin_page) use ($caf_admin_page) { |
|
345 | - return $caf_admin_page; |
|
346 | - } |
|
347 | - ); |
|
348 | - $extend = true; |
|
349 | - } |
|
350 | - // let's do the registered hooks |
|
351 | - $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend); |
|
352 | - $hooks_ref = array_merge($hooks_ref, $extended_hooks); |
|
353 | - } |
|
354 | - } |
|
355 | - // the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder. So we want to make sure we load the file for the parent. |
|
356 | - // first make sure we've got unique values |
|
357 | - $hooks_ref = array_unique($hooks_ref); |
|
358 | - // now let's loop and require! |
|
359 | - foreach ($hooks_ref as $path) { |
|
360 | - require_once($path); |
|
361 | - } |
|
362 | - // make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
|
363 | - global $ee_menu_slugs; |
|
364 | - $ee_menu_slugs = $this->_menu_slugs; |
|
365 | - // we need to loop again to run any early code |
|
366 | - foreach ($installed_refs as $page => $path) { |
|
367 | - if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
368 | - $this->_installed_pages[ $page ]->do_initial_loads(); |
|
369 | - } |
|
370 | - } |
|
371 | - do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * get_admin_page_object |
|
377 | - * |
|
378 | - * @param string $page_slug |
|
379 | - * @return EE_Admin_Page |
|
380 | - */ |
|
381 | - public function get_admin_page_object($page_slug = '') |
|
382 | - { |
|
383 | - if (isset($this->_installed_pages[ $page_slug ])) { |
|
384 | - return $this->_installed_pages[ $page_slug ]->loaded_page_object(); |
|
385 | - } |
|
386 | - return null; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * _get_classname_for_admin_page |
|
392 | - * generates an "Admin Page" class based on the directory name |
|
393 | - * |
|
394 | - * @param $dir_name |
|
395 | - * @return string |
|
396 | - */ |
|
397 | - private function _get_classname_for_admin_page($dir_name = '') |
|
398 | - { |
|
399 | - $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
400 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * _get_classname_for_admin_init_page |
|
406 | - * generates an "Admin Page Init" class based on the directory name |
|
407 | - * |
|
408 | - * @param $dir_name |
|
409 | - * @return string |
|
410 | - */ |
|
411 | - private function _get_classname_for_admin_init_page($dir_name = '') |
|
412 | - { |
|
413 | - $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
414 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * _load_admin_page |
|
420 | - * Loads and instantiates page_init object for a single EE_admin page. |
|
421 | - * |
|
422 | - * @param string $page page_reference |
|
423 | - * @param string $path |
|
424 | - * @throws EE_Error |
|
425 | - * @return object|bool return page object if valid, bool false if not. |
|
426 | - */ |
|
427 | - private function _load_admin_page($page = '', $path = '') |
|
428 | - { |
|
429 | - $class_name = $this->_get_classname_for_admin_init_page($page); |
|
430 | - EE_Registry::instance()->load_file($path, $class_name, 'core'); |
|
431 | - if (! class_exists($class_name)) { |
|
432 | - $inner_error_msg = '<br />' |
|
433 | - . sprintf( |
|
434 | - esc_html__( |
|
435 | - 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
436 | - 'event_espresso' |
|
437 | - ), |
|
438 | - '<strong>' . $class_name . '</strong>' |
|
439 | - ); |
|
440 | - $error_msg[] = sprintf( |
|
441 | - __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
|
442 | - $page |
|
443 | - ); |
|
444 | - $error_msg[] = $error_msg[0] |
|
445 | - . "\r\n" |
|
446 | - . sprintf( |
|
447 | - esc_html__( |
|
448 | - 'There is no Init class in place for the %s admin page.', |
|
449 | - 'event_espresso' |
|
450 | - ), |
|
451 | - $page |
|
452 | - ) |
|
453 | - . $inner_error_msg; |
|
454 | - throw new EE_Error(implode('||', $error_msg)); |
|
455 | - } |
|
456 | - $a = new ReflectionClass($class_name); |
|
457 | - return $a->newInstance(); |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * set_menus |
|
463 | - * This method sets up the menus for EE Admin Pages |
|
464 | - * |
|
465 | - * @access private |
|
466 | - * @return void |
|
467 | - */ |
|
468 | - public function set_menus() |
|
469 | - { |
|
470 | - // prep the menu pages (sort, group.) |
|
471 | - $this->_prep_pages(); |
|
472 | - foreach ($this->_prepped_menu_maps as $menu_map) { |
|
473 | - if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
474 | - $menu_map->add_menu_page(false); |
|
475 | - } |
|
476 | - } |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - /** |
|
481 | - * set_network_menus |
|
482 | - * This method sets up the menus for network EE Admin Pages. |
|
483 | - * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
484 | - * are only added to the menu map if they are intended for the admin menu |
|
485 | - * |
|
486 | - * @return void |
|
487 | - */ |
|
488 | - public function set_network_menus() |
|
489 | - { |
|
490 | - $this->_prep_pages(); |
|
491 | - foreach ($this->_prepped_menu_maps as $menu_map) { |
|
492 | - if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
493 | - $menu_map->add_menu_page(true); |
|
494 | - } |
|
495 | - } |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * _prep_pages |
|
501 | - * sets the _prepped_menu_maps property |
|
502 | - * |
|
503 | - * @access private |
|
504 | - * @throws EE_Error |
|
505 | - * @return void |
|
506 | - */ |
|
507 | - private function _prep_pages() |
|
508 | - { |
|
509 | - $pages_array = array(); |
|
510 | - // rearrange _admin_menu_groups to be indexed by group slug. |
|
511 | - $menu_groups = $this->_rearrange_menu_groups(); |
|
512 | - foreach ($this->_installed_pages as $page) { |
|
513 | - if ($page instanceof EE_Admin_page_Init) { |
|
514 | - $page_map = $page->get_menu_map(); |
|
515 | - // if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
|
516 | - if (is_array($page_map) || empty($page_map)) { |
|
517 | - new PersistentAdminNotice( |
|
518 | - 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
519 | - sprintf( |
|
520 | - __( |
|
521 | - 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
|
522 | - 'event_espresso' |
|
523 | - ), |
|
524 | - $page->label |
|
525 | - ) |
|
526 | - ); |
|
527 | - continue; |
|
528 | - } |
|
529 | - // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
|
530 | - if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
531 | - throw new EE_Error( |
|
532 | - sprintf( |
|
533 | - __( |
|
534 | - 'The menu map for %s must be an EE_Admin_Page_Menu_Map object. Instead it is %s. Please double check that the menu map has been configured correctly.', |
|
535 | - 'event_espresso' |
|
536 | - ), |
|
537 | - $page->label, |
|
538 | - $page_map |
|
539 | - ) |
|
540 | - ); |
|
541 | - } |
|
542 | - // use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array. |
|
543 | - if (empty($page_map->maintenance_mode_parent) |
|
544 | - && EE_Maintenance_Mode::instance()->level() |
|
545 | - == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
546 | - continue; |
|
547 | - } |
|
548 | - // assign to group (remember $page_map has the admin page stored in it). |
|
549 | - $pages_array[ $page_map->menu_group ][] = $page_map; |
|
550 | - } |
|
551 | - } |
|
552 | - if (empty($pages_array)) { |
|
553 | - throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso')); |
|
554 | - } |
|
555 | - // let's sort the groups, make sure it's a valid group, add header (if to show). |
|
556 | - foreach ($pages_array as $group => $menu_maps) { |
|
557 | - // valid_group? |
|
558 | - if (! array_key_exists($group, $menu_groups)) { |
|
559 | - continue; |
|
560 | - } |
|
561 | - // sort pages. |
|
562 | - usort($menu_maps, array($this, '_sort_menu_maps')); |
|
563 | - // prepend header |
|
564 | - array_unshift($menu_maps, $menu_groups[ $group ]); |
|
565 | - // reset $pages_array with prepped data |
|
566 | - $pages_array[ $group ] = $menu_maps; |
|
567 | - } |
|
568 | - // now let's setup the _prepped_menu_maps property |
|
569 | - foreach ($menu_groups as $group => $group_objs) { |
|
570 | - if (isset($pages_array[ $group ])) { |
|
571 | - $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]); |
|
572 | - } |
|
573 | - }/**/ |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * This method is the "workhorse" for detecting and setting up caffeinated functionality. |
|
579 | - * In this method there are three checks being done: |
|
580 | - * 1. Do we have any NEW admin page sets. If we do, lets add them into the menu setup (via the $installed_refs |
|
581 | - * array) etc. (new page sets are found in caffeinated/new/{page}) |
|
582 | - * 2. Do we have any EXTENDED page sets. Basically an extended EE_Admin Page extends the core {child}_Admin_Page |
|
583 | - * class. eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class: |
|
584 | - * Extend_Events_Admin_Page extends Events_Admin_Page. |
|
585 | - * 3. Do we have any files just for setting up hooks into other core pages. The files can be any name in |
|
586 | - * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the |
|
587 | - * classname inside. These classes are instantiated really early so that any hooks in them are run before the |
|
588 | - * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated |
|
589 | - * admin_pages) |
|
590 | - * |
|
591 | - * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be |
|
592 | - * loaded. |
|
593 | - * @return array |
|
594 | - */ |
|
595 | - private function _set_caffeinated($installed_refs) |
|
596 | - { |
|
597 | - |
|
598 | - // first let's check if there IS a caffeinated folder. If there is not then lets get out. |
|
599 | - if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
600 | - return $installed_refs; |
|
601 | - } |
|
602 | - $this->_define_caffeinated_constants(); |
|
603 | - $exclude = array('tickets'); |
|
604 | - // okay let's setup an "New" pages first (we'll return installed refs later) |
|
605 | - $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
606 | - if ($new_admin_screens) { |
|
607 | - foreach ($new_admin_screens as $admin_screen) { |
|
608 | - // files and anything in the exclude array need not apply |
|
609 | - if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
610 | - // these folders represent the different NEW EE admin pages |
|
611 | - $installed_refs[ basename($admin_screen) ] = $admin_screen; |
|
612 | - // set autoloaders for our admin page classes based on included path information |
|
613 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen); |
|
614 | - } |
|
615 | - } |
|
616 | - } |
|
617 | - // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
|
618 | - $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
619 | - if ($extends) { |
|
620 | - foreach ($extends as $extend) { |
|
621 | - if (is_dir($extend)) { |
|
622 | - $extend_ref = basename($extend); |
|
623 | - // now let's make sure there is a file that matches the expected format |
|
624 | - $filename = str_replace( |
|
625 | - ' ', |
|
626 | - '_', |
|
627 | - ucwords( |
|
628 | - str_replace( |
|
629 | - '_', |
|
630 | - ' ', |
|
631 | - $extend_ref |
|
632 | - ) |
|
633 | - ) |
|
634 | - ); |
|
635 | - $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
636 | - $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace( |
|
637 | - array('\\', '/'), |
|
638 | - DS, |
|
639 | - EE_CORE_CAF_ADMIN |
|
640 | - . 'extend' |
|
641 | - . DS |
|
642 | - . $extend_ref |
|
643 | - . DS |
|
644 | - . $filename |
|
645 | - . '.core.php' |
|
646 | - ); |
|
647 | - $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename; |
|
648 | - // set autoloaders for our admin page classes based on included path information |
|
649 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend); |
|
650 | - } |
|
651 | - } |
|
652 | - } |
|
653 | - // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
|
654 | - $ee_admin_hooks = array(); |
|
655 | - $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
656 | - if ($hooks) { |
|
657 | - foreach ($hooks as $hook) { |
|
658 | - if (is_readable($hook)) { |
|
659 | - require_once $hook; |
|
660 | - $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
661 | - $classname = str_replace('.class.php', '', $classname); |
|
662 | - if (class_exists($classname)) { |
|
663 | - $a = new ReflectionClass($classname); |
|
664 | - $ee_admin_hooks[] = $a->newInstance(); |
|
665 | - } |
|
666 | - } |
|
667 | - } |
|
668 | - }/**/ |
|
669 | - $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
670 | - return $installed_refs; |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - /** |
|
675 | - * Utility method for sorting the _menu_maps (callback for usort php function) |
|
676 | - * |
|
677 | - * @since 4.4.0 |
|
678 | - * @param EE_Admin_Page_Menu_Map $a menu_map object |
|
679 | - * @param EE_Admin_Page_Menu_Map $b being compared to |
|
680 | - * @return int sort order |
|
681 | - */ |
|
682 | - private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b) |
|
683 | - { |
|
684 | - if ($a->menu_order == $b->menu_order) { |
|
685 | - return 0; |
|
686 | - } |
|
687 | - return ($a->menu_order < $b->menu_order) ? -1 : 1; |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - /** |
|
692 | - * _default_header_link |
|
693 | - * This is just a dummy method to use with header submenu items |
|
694 | - * |
|
695 | - * @return bool false |
|
696 | - */ |
|
697 | - public function _default_header_link() |
|
698 | - { |
|
699 | - return false; |
|
700 | - } |
|
27 | + /** |
|
28 | + * _installed_pages |
|
29 | + * objects for page_init objects detected and loaded |
|
30 | + * |
|
31 | + * @access private |
|
32 | + * @var \EE_Admin_Page_Init[] |
|
33 | + */ |
|
34 | + private $_installed_pages = array(); |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * this is used to hold the registry of menu slugs for all the installed admin pages |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + private $_menu_slugs = array(); |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * _caffeinated_extends |
|
47 | + * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and |
|
48 | + * pieces needed to do so). This property is defined in the _set_caffeinated method. |
|
49 | + * |
|
50 | + * @var array |
|
51 | + */ |
|
52 | + private $_caffeinated_extends = array(); |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * _current_caf_extend_slug |
|
57 | + * This property is used for holding the page slug that is required for referencing the correct |
|
58 | + * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + private $_current_caf_extend_slug; |
|
63 | + |
|
64 | + /** |
|
65 | + * _prepped_menu_maps |
|
66 | + * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu. |
|
67 | + * |
|
68 | + * @since 4.4.0 |
|
69 | + * @var EE_Admin_Page_Menu_Map[] |
|
70 | + */ |
|
71 | + private $_prepped_menu_maps = array(); |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * _admin_menu_groups |
|
76 | + * array that holds the group headings and details for |
|
77 | + * |
|
78 | + * @access private |
|
79 | + * @var array |
|
80 | + */ |
|
81 | + private $_admin_menu_groups = array(); |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * This property will hold the hook file for setting up the filter that does all the connections between admin |
|
86 | + * pages. |
|
87 | + * |
|
88 | + * @var string |
|
89 | + */ |
|
90 | + public $hook_file; |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * constructor |
|
95 | + * |
|
96 | + * @access public |
|
97 | + * @return \EE_Admin_Page_Loader |
|
98 | + */ |
|
99 | + public function __construct() |
|
100 | + { |
|
101 | + // load menu_map classes |
|
102 | + EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core'); |
|
103 | + // define the default "groups" for the admin_pages |
|
104 | + $this->_set_menu_groups(); |
|
105 | + |
|
106 | + // let's do a scan and see what installed pages we have |
|
107 | + $this->_get_installed_pages(); |
|
108 | + // set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to). |
|
109 | + add_action('admin_menu', array($this, 'set_menus')); |
|
110 | + add_action('network_admin_menu', array($this, 'set_network_menus')); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by |
|
116 | + * files in the caffeinated folder. |
|
117 | + * |
|
118 | + * @access private |
|
119 | + * @return void |
|
120 | + */ |
|
121 | + private function _define_caffeinated_constants() |
|
122 | + { |
|
123 | + if (! defined('EE_CORE_CAF_ADMIN')) { |
|
124 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
125 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
126 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
127 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
128 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
129 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * _set_menu_groups |
|
136 | + * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
137 | + * |
|
138 | + * @access private |
|
139 | + * @return void |
|
140 | + */ |
|
141 | + private function _set_menu_groups() |
|
142 | + { |
|
143 | + |
|
144 | + // set array of EE_Admin_Page_Menu_Group objects |
|
145 | + $groups = array( |
|
146 | + 'main' => new EE_Admin_Page_Menu_Group( |
|
147 | + array( |
|
148 | + 'menu_label' => __('Main', 'event_espresso'), |
|
149 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::NONE, |
|
150 | + 'menu_slug' => 'main', |
|
151 | + 'capability' => 'ee_read_ee', |
|
152 | + 'menu_order' => 0, |
|
153 | + 'parent_slug' => 'espresso_events', |
|
154 | + ) |
|
155 | + ), |
|
156 | + 'management' => new EE_Admin_Page_Menu_Group( |
|
157 | + array( |
|
158 | + 'menu_label' => __('Management', 'event_espresso'), |
|
159 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
160 | + 'menu_slug' => 'management', |
|
161 | + 'capability' => 'ee_read_ee', |
|
162 | + 'menu_order' => 10, |
|
163 | + 'parent_slug' => 'espresso_events', |
|
164 | + ) |
|
165 | + ), |
|
166 | + 'settings' => new EE_Admin_Page_Menu_Group( |
|
167 | + array( |
|
168 | + 'menu_label' => __('Settings', 'event_espresso'), |
|
169 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
170 | + 'menu_slug' => 'settings', |
|
171 | + 'capability' => 'ee_read_ee', |
|
172 | + 'menu_order' => 30, |
|
173 | + 'parent_slug' => 'espresso_events', |
|
174 | + ) |
|
175 | + ), |
|
176 | + 'templates' => new EE_Admin_Page_Menu_Group( |
|
177 | + array( |
|
178 | + 'menu_label' => __('Templates', 'event_espresso'), |
|
179 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
180 | + 'menu_slug' => 'templates', |
|
181 | + 'capability' => 'ee_read_ee', |
|
182 | + 'menu_order' => 40, |
|
183 | + 'parent_slug' => 'espresso_events', |
|
184 | + ) |
|
185 | + ), |
|
186 | + 'extras' => new EE_Admin_Page_Menu_Group( |
|
187 | + array( |
|
188 | + 'menu_label' => __('Extras', 'event_espresso'), |
|
189 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
190 | + 'menu_slug' => 'extras', |
|
191 | + 'capability' => 'ee_read_ee', |
|
192 | + 'menu_order' => 50, |
|
193 | + 'parent_slug' => 'espresso_events', |
|
194 | + 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
195 | + ) |
|
196 | + ), |
|
197 | + 'tools' => new EE_Admin_Page_Menu_Group( |
|
198 | + array( |
|
199 | + 'menu_label' => __("Tools", "event_espresso"), |
|
200 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
201 | + 'menu_slug' => 'tools', |
|
202 | + 'capability' => 'ee_read_ee', |
|
203 | + 'menu_order' => 60, |
|
204 | + 'parent_slug' => 'espresso_events', |
|
205 | + ) |
|
206 | + ), |
|
207 | + 'addons' => new EE_Admin_Page_Menu_Group( |
|
208 | + array( |
|
209 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
210 | + 'menu_label' => __('Add-ons', 'event_espresso'), |
|
211 | + 'menu_slug' => 'addons', |
|
212 | + 'capability' => 'ee_read_ee', |
|
213 | + 'menu_order' => 20, |
|
214 | + 'parent_slug' => 'espresso_events', |
|
215 | + ) |
|
216 | + ), |
|
217 | + ); |
|
218 | + $this->_admin_menu_groups = apply_filters( |
|
219 | + 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
220 | + $groups |
|
221 | + ); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group |
|
227 | + * slug. The other utility with this function is it validates that all the groups are instances of |
|
228 | + * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons). |
|
229 | + * |
|
230 | + * @since 4.4.0 |
|
231 | + * @throws \EE_Error |
|
232 | + * @return EE_Admin_Page_Menu_Group[] |
|
233 | + */ |
|
234 | + private function _rearrange_menu_groups() |
|
235 | + { |
|
236 | + $groups = array(); |
|
237 | + // first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
|
238 | + usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
|
239 | + foreach ($this->_admin_menu_groups as $group) { |
|
240 | + if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
241 | + throw new EE_Error( |
|
242 | + sprintf( |
|
243 | + __( |
|
244 | + 'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', |
|
245 | + 'event_espresso' |
|
246 | + ), |
|
247 | + print_r($group, true) |
|
248 | + ) |
|
249 | + ); |
|
250 | + } |
|
251 | + $groups[ $group->menu_slug ] = $group; |
|
252 | + } |
|
253 | + return $groups; |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * _get_installed_pages |
|
259 | + * This just gets the list of installed EE_Admin_pages. |
|
260 | + * |
|
261 | + * @access private |
|
262 | + * @throws EE_Error |
|
263 | + * @return void |
|
264 | + */ |
|
265 | + private function _get_installed_pages() |
|
266 | + { |
|
267 | + $installed_refs = array(); |
|
268 | + $exclude = array('assets', 'templates'); |
|
269 | + // grab everything in the admin core directory |
|
270 | + $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
271 | + if ($admin_screens) { |
|
272 | + foreach ($admin_screens as $admin_screen) { |
|
273 | + // files and anything in the exclude array need not apply |
|
274 | + if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
275 | + // these folders represent the different EE admin pages |
|
276 | + $installed_refs[ basename($admin_screen) ] = $admin_screen; |
|
277 | + } |
|
278 | + } |
|
279 | + } |
|
280 | + if (empty($installed_refs)) { |
|
281 | + $error_msg[] = __( |
|
282 | + 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
|
283 | + 'event_espresso' |
|
284 | + ); |
|
285 | + $error_msg[] = $error_msg[0] . "\r\n" |
|
286 | + . sprintf( |
|
287 | + __( |
|
288 | + 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
|
289 | + 'event_espresso' |
|
290 | + ), |
|
291 | + EE_ADMIN_PAGES |
|
292 | + ); |
|
293 | + throw new EE_Error(implode('||', $error_msg)); |
|
294 | + } |
|
295 | + // this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
|
296 | + $installed_refs = $this->_set_caffeinated($installed_refs); |
|
297 | + // allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
|
298 | + $installed_refs = apply_filters( |
|
299 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
300 | + $installed_refs |
|
301 | + ); |
|
302 | + $this->_caffeinated_extends = apply_filters( |
|
303 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', |
|
304 | + $this->_caffeinated_extends |
|
305 | + ); |
|
306 | + // loop through admin pages and setup the $_installed_pages array. |
|
307 | + $hooks_ref = array(); |
|
308 | + foreach ($installed_refs as $page => $path) { |
|
309 | + // set autoloaders for our admin page classes based on included path information |
|
310 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path); |
|
311 | + // build list of installed pages |
|
312 | + $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path); |
|
313 | + // verify returned object |
|
314 | + if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
315 | + if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
316 | + continue; |
|
317 | + } |
|
318 | + // skip if in full maintenance mode and maintenance_mode_parent is set |
|
319 | + $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent; |
|
320 | + if (empty($maintenance_mode_parent) |
|
321 | + && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
322 | + ) { |
|
323 | + unset($installed_refs[ $page ]); |
|
324 | + continue; |
|
325 | + } |
|
326 | + $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug; |
|
327 | + $this->_menu_slugs[ $menu_slug ] = $page; |
|
328 | + // flag for register hooks on extended pages b/c extended pages use the default INIT. |
|
329 | + $extend = false; |
|
330 | + // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
|
331 | + if (isset($this->_caffeinated_extends[ $page ])) { |
|
332 | + $this->_current_caf_extend_slug = $page; |
|
333 | + $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name(); |
|
334 | + $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path']; |
|
335 | + $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page']; |
|
336 | + add_filter( |
|
337 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}", |
|
338 | + function ($path_to_file) use ($caf_path) { |
|
339 | + return $caf_path; |
|
340 | + } |
|
341 | + ); |
|
342 | + add_filter( |
|
343 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}", |
|
344 | + function ($admin_page) use ($caf_admin_page) { |
|
345 | + return $caf_admin_page; |
|
346 | + } |
|
347 | + ); |
|
348 | + $extend = true; |
|
349 | + } |
|
350 | + // let's do the registered hooks |
|
351 | + $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend); |
|
352 | + $hooks_ref = array_merge($hooks_ref, $extended_hooks); |
|
353 | + } |
|
354 | + } |
|
355 | + // the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder. So we want to make sure we load the file for the parent. |
|
356 | + // first make sure we've got unique values |
|
357 | + $hooks_ref = array_unique($hooks_ref); |
|
358 | + // now let's loop and require! |
|
359 | + foreach ($hooks_ref as $path) { |
|
360 | + require_once($path); |
|
361 | + } |
|
362 | + // make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
|
363 | + global $ee_menu_slugs; |
|
364 | + $ee_menu_slugs = $this->_menu_slugs; |
|
365 | + // we need to loop again to run any early code |
|
366 | + foreach ($installed_refs as $page => $path) { |
|
367 | + if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
368 | + $this->_installed_pages[ $page ]->do_initial_loads(); |
|
369 | + } |
|
370 | + } |
|
371 | + do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * get_admin_page_object |
|
377 | + * |
|
378 | + * @param string $page_slug |
|
379 | + * @return EE_Admin_Page |
|
380 | + */ |
|
381 | + public function get_admin_page_object($page_slug = '') |
|
382 | + { |
|
383 | + if (isset($this->_installed_pages[ $page_slug ])) { |
|
384 | + return $this->_installed_pages[ $page_slug ]->loaded_page_object(); |
|
385 | + } |
|
386 | + return null; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * _get_classname_for_admin_page |
|
392 | + * generates an "Admin Page" class based on the directory name |
|
393 | + * |
|
394 | + * @param $dir_name |
|
395 | + * @return string |
|
396 | + */ |
|
397 | + private function _get_classname_for_admin_page($dir_name = '') |
|
398 | + { |
|
399 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
400 | + return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * _get_classname_for_admin_init_page |
|
406 | + * generates an "Admin Page Init" class based on the directory name |
|
407 | + * |
|
408 | + * @param $dir_name |
|
409 | + * @return string |
|
410 | + */ |
|
411 | + private function _get_classname_for_admin_init_page($dir_name = '') |
|
412 | + { |
|
413 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
414 | + return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * _load_admin_page |
|
420 | + * Loads and instantiates page_init object for a single EE_admin page. |
|
421 | + * |
|
422 | + * @param string $page page_reference |
|
423 | + * @param string $path |
|
424 | + * @throws EE_Error |
|
425 | + * @return object|bool return page object if valid, bool false if not. |
|
426 | + */ |
|
427 | + private function _load_admin_page($page = '', $path = '') |
|
428 | + { |
|
429 | + $class_name = $this->_get_classname_for_admin_init_page($page); |
|
430 | + EE_Registry::instance()->load_file($path, $class_name, 'core'); |
|
431 | + if (! class_exists($class_name)) { |
|
432 | + $inner_error_msg = '<br />' |
|
433 | + . sprintf( |
|
434 | + esc_html__( |
|
435 | + 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
436 | + 'event_espresso' |
|
437 | + ), |
|
438 | + '<strong>' . $class_name . '</strong>' |
|
439 | + ); |
|
440 | + $error_msg[] = sprintf( |
|
441 | + __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
|
442 | + $page |
|
443 | + ); |
|
444 | + $error_msg[] = $error_msg[0] |
|
445 | + . "\r\n" |
|
446 | + . sprintf( |
|
447 | + esc_html__( |
|
448 | + 'There is no Init class in place for the %s admin page.', |
|
449 | + 'event_espresso' |
|
450 | + ), |
|
451 | + $page |
|
452 | + ) |
|
453 | + . $inner_error_msg; |
|
454 | + throw new EE_Error(implode('||', $error_msg)); |
|
455 | + } |
|
456 | + $a = new ReflectionClass($class_name); |
|
457 | + return $a->newInstance(); |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * set_menus |
|
463 | + * This method sets up the menus for EE Admin Pages |
|
464 | + * |
|
465 | + * @access private |
|
466 | + * @return void |
|
467 | + */ |
|
468 | + public function set_menus() |
|
469 | + { |
|
470 | + // prep the menu pages (sort, group.) |
|
471 | + $this->_prep_pages(); |
|
472 | + foreach ($this->_prepped_menu_maps as $menu_map) { |
|
473 | + if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
474 | + $menu_map->add_menu_page(false); |
|
475 | + } |
|
476 | + } |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + /** |
|
481 | + * set_network_menus |
|
482 | + * This method sets up the menus for network EE Admin Pages. |
|
483 | + * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
484 | + * are only added to the menu map if they are intended for the admin menu |
|
485 | + * |
|
486 | + * @return void |
|
487 | + */ |
|
488 | + public function set_network_menus() |
|
489 | + { |
|
490 | + $this->_prep_pages(); |
|
491 | + foreach ($this->_prepped_menu_maps as $menu_map) { |
|
492 | + if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
493 | + $menu_map->add_menu_page(true); |
|
494 | + } |
|
495 | + } |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * _prep_pages |
|
501 | + * sets the _prepped_menu_maps property |
|
502 | + * |
|
503 | + * @access private |
|
504 | + * @throws EE_Error |
|
505 | + * @return void |
|
506 | + */ |
|
507 | + private function _prep_pages() |
|
508 | + { |
|
509 | + $pages_array = array(); |
|
510 | + // rearrange _admin_menu_groups to be indexed by group slug. |
|
511 | + $menu_groups = $this->_rearrange_menu_groups(); |
|
512 | + foreach ($this->_installed_pages as $page) { |
|
513 | + if ($page instanceof EE_Admin_page_Init) { |
|
514 | + $page_map = $page->get_menu_map(); |
|
515 | + // if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
|
516 | + if (is_array($page_map) || empty($page_map)) { |
|
517 | + new PersistentAdminNotice( |
|
518 | + 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
519 | + sprintf( |
|
520 | + __( |
|
521 | + 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
|
522 | + 'event_espresso' |
|
523 | + ), |
|
524 | + $page->label |
|
525 | + ) |
|
526 | + ); |
|
527 | + continue; |
|
528 | + } |
|
529 | + // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
|
530 | + if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
531 | + throw new EE_Error( |
|
532 | + sprintf( |
|
533 | + __( |
|
534 | + 'The menu map for %s must be an EE_Admin_Page_Menu_Map object. Instead it is %s. Please double check that the menu map has been configured correctly.', |
|
535 | + 'event_espresso' |
|
536 | + ), |
|
537 | + $page->label, |
|
538 | + $page_map |
|
539 | + ) |
|
540 | + ); |
|
541 | + } |
|
542 | + // use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array. |
|
543 | + if (empty($page_map->maintenance_mode_parent) |
|
544 | + && EE_Maintenance_Mode::instance()->level() |
|
545 | + == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
546 | + continue; |
|
547 | + } |
|
548 | + // assign to group (remember $page_map has the admin page stored in it). |
|
549 | + $pages_array[ $page_map->menu_group ][] = $page_map; |
|
550 | + } |
|
551 | + } |
|
552 | + if (empty($pages_array)) { |
|
553 | + throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso')); |
|
554 | + } |
|
555 | + // let's sort the groups, make sure it's a valid group, add header (if to show). |
|
556 | + foreach ($pages_array as $group => $menu_maps) { |
|
557 | + // valid_group? |
|
558 | + if (! array_key_exists($group, $menu_groups)) { |
|
559 | + continue; |
|
560 | + } |
|
561 | + // sort pages. |
|
562 | + usort($menu_maps, array($this, '_sort_menu_maps')); |
|
563 | + // prepend header |
|
564 | + array_unshift($menu_maps, $menu_groups[ $group ]); |
|
565 | + // reset $pages_array with prepped data |
|
566 | + $pages_array[ $group ] = $menu_maps; |
|
567 | + } |
|
568 | + // now let's setup the _prepped_menu_maps property |
|
569 | + foreach ($menu_groups as $group => $group_objs) { |
|
570 | + if (isset($pages_array[ $group ])) { |
|
571 | + $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]); |
|
572 | + } |
|
573 | + }/**/ |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * This method is the "workhorse" for detecting and setting up caffeinated functionality. |
|
579 | + * In this method there are three checks being done: |
|
580 | + * 1. Do we have any NEW admin page sets. If we do, lets add them into the menu setup (via the $installed_refs |
|
581 | + * array) etc. (new page sets are found in caffeinated/new/{page}) |
|
582 | + * 2. Do we have any EXTENDED page sets. Basically an extended EE_Admin Page extends the core {child}_Admin_Page |
|
583 | + * class. eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class: |
|
584 | + * Extend_Events_Admin_Page extends Events_Admin_Page. |
|
585 | + * 3. Do we have any files just for setting up hooks into other core pages. The files can be any name in |
|
586 | + * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the |
|
587 | + * classname inside. These classes are instantiated really early so that any hooks in them are run before the |
|
588 | + * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated |
|
589 | + * admin_pages) |
|
590 | + * |
|
591 | + * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be |
|
592 | + * loaded. |
|
593 | + * @return array |
|
594 | + */ |
|
595 | + private function _set_caffeinated($installed_refs) |
|
596 | + { |
|
597 | + |
|
598 | + // first let's check if there IS a caffeinated folder. If there is not then lets get out. |
|
599 | + if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
600 | + return $installed_refs; |
|
601 | + } |
|
602 | + $this->_define_caffeinated_constants(); |
|
603 | + $exclude = array('tickets'); |
|
604 | + // okay let's setup an "New" pages first (we'll return installed refs later) |
|
605 | + $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
606 | + if ($new_admin_screens) { |
|
607 | + foreach ($new_admin_screens as $admin_screen) { |
|
608 | + // files and anything in the exclude array need not apply |
|
609 | + if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
610 | + // these folders represent the different NEW EE admin pages |
|
611 | + $installed_refs[ basename($admin_screen) ] = $admin_screen; |
|
612 | + // set autoloaders for our admin page classes based on included path information |
|
613 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen); |
|
614 | + } |
|
615 | + } |
|
616 | + } |
|
617 | + // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
|
618 | + $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
619 | + if ($extends) { |
|
620 | + foreach ($extends as $extend) { |
|
621 | + if (is_dir($extend)) { |
|
622 | + $extend_ref = basename($extend); |
|
623 | + // now let's make sure there is a file that matches the expected format |
|
624 | + $filename = str_replace( |
|
625 | + ' ', |
|
626 | + '_', |
|
627 | + ucwords( |
|
628 | + str_replace( |
|
629 | + '_', |
|
630 | + ' ', |
|
631 | + $extend_ref |
|
632 | + ) |
|
633 | + ) |
|
634 | + ); |
|
635 | + $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
636 | + $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace( |
|
637 | + array('\\', '/'), |
|
638 | + DS, |
|
639 | + EE_CORE_CAF_ADMIN |
|
640 | + . 'extend' |
|
641 | + . DS |
|
642 | + . $extend_ref |
|
643 | + . DS |
|
644 | + . $filename |
|
645 | + . '.core.php' |
|
646 | + ); |
|
647 | + $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename; |
|
648 | + // set autoloaders for our admin page classes based on included path information |
|
649 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend); |
|
650 | + } |
|
651 | + } |
|
652 | + } |
|
653 | + // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
|
654 | + $ee_admin_hooks = array(); |
|
655 | + $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
656 | + if ($hooks) { |
|
657 | + foreach ($hooks as $hook) { |
|
658 | + if (is_readable($hook)) { |
|
659 | + require_once $hook; |
|
660 | + $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
661 | + $classname = str_replace('.class.php', '', $classname); |
|
662 | + if (class_exists($classname)) { |
|
663 | + $a = new ReflectionClass($classname); |
|
664 | + $ee_admin_hooks[] = $a->newInstance(); |
|
665 | + } |
|
666 | + } |
|
667 | + } |
|
668 | + }/**/ |
|
669 | + $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
670 | + return $installed_refs; |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + /** |
|
675 | + * Utility method for sorting the _menu_maps (callback for usort php function) |
|
676 | + * |
|
677 | + * @since 4.4.0 |
|
678 | + * @param EE_Admin_Page_Menu_Map $a menu_map object |
|
679 | + * @param EE_Admin_Page_Menu_Map $b being compared to |
|
680 | + * @return int sort order |
|
681 | + */ |
|
682 | + private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b) |
|
683 | + { |
|
684 | + if ($a->menu_order == $b->menu_order) { |
|
685 | + return 0; |
|
686 | + } |
|
687 | + return ($a->menu_order < $b->menu_order) ? -1 : 1; |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + /** |
|
692 | + * _default_header_link |
|
693 | + * This is just a dummy method to use with header submenu items |
|
694 | + * |
|
695 | + * @return bool false |
|
696 | + */ |
|
697 | + public function _default_header_link() |
|
698 | + { |
|
699 | + return false; |
|
700 | + } |
|
701 | 701 | } |
@@ -120,13 +120,13 @@ discard block |
||
120 | 120 | */ |
121 | 121 | private function _define_caffeinated_constants() |
122 | 122 | { |
123 | - if (! defined('EE_CORE_CAF_ADMIN')) { |
|
124 | - define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
125 | - define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
126 | - define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
127 | - define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
128 | - define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
129 | - define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
123 | + if ( ! defined('EE_CORE_CAF_ADMIN')) { |
|
124 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH.'caffeinated/admin/'); |
|
125 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL.'caffeinated/admin/'); |
|
126 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN.'new/'); |
|
127 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN.'extend/'); |
|
128 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL.'extend/'); |
|
129 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN.'hooks/'); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | // first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
238 | 238 | usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
239 | 239 | foreach ($this->_admin_menu_groups as $group) { |
240 | - if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
240 | + if ( ! $group instanceof EE_Admin_Page_Menu_Group) { |
|
241 | 241 | throw new EE_Error( |
242 | 242 | sprintf( |
243 | 243 | __( |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | ) |
249 | 249 | ); |
250 | 250 | } |
251 | - $groups[ $group->menu_slug ] = $group; |
|
251 | + $groups[$group->menu_slug] = $group; |
|
252 | 252 | } |
253 | 253 | return $groups; |
254 | 254 | } |
@@ -267,13 +267,13 @@ discard block |
||
267 | 267 | $installed_refs = array(); |
268 | 268 | $exclude = array('assets', 'templates'); |
269 | 269 | // grab everything in the admin core directory |
270 | - $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
270 | + $admin_screens = glob(EE_ADMIN_PAGES.'*', GLOB_ONLYDIR); |
|
271 | 271 | if ($admin_screens) { |
272 | 272 | foreach ($admin_screens as $admin_screen) { |
273 | 273 | // files and anything in the exclude array need not apply |
274 | 274 | if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
275 | 275 | // these folders represent the different EE admin pages |
276 | - $installed_refs[ basename($admin_screen) ] = $admin_screen; |
|
276 | + $installed_refs[basename($admin_screen)] = $admin_screen; |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | } |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
283 | 283 | 'event_espresso' |
284 | 284 | ); |
285 | - $error_msg[] = $error_msg[0] . "\r\n" |
|
285 | + $error_msg[] = $error_msg[0]."\r\n" |
|
286 | 286 | . sprintf( |
287 | 287 | __( |
288 | 288 | 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
@@ -309,46 +309,46 @@ discard block |
||
309 | 309 | // set autoloaders for our admin page classes based on included path information |
310 | 310 | EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path); |
311 | 311 | // build list of installed pages |
312 | - $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path); |
|
312 | + $this->_installed_pages[$page] = $this->_load_admin_page($page, $path); |
|
313 | 313 | // verify returned object |
314 | - if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
315 | - if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
314 | + if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
315 | + if ( ! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
316 | 316 | continue; |
317 | 317 | } |
318 | 318 | // skip if in full maintenance mode and maintenance_mode_parent is set |
319 | - $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent; |
|
319 | + $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent; |
|
320 | 320 | if (empty($maintenance_mode_parent) |
321 | 321 | && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
322 | 322 | ) { |
323 | - unset($installed_refs[ $page ]); |
|
323 | + unset($installed_refs[$page]); |
|
324 | 324 | continue; |
325 | 325 | } |
326 | - $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug; |
|
327 | - $this->_menu_slugs[ $menu_slug ] = $page; |
|
326 | + $menu_slug = $this->_installed_pages[$page]->get_menu_map()->menu_slug; |
|
327 | + $this->_menu_slugs[$menu_slug] = $page; |
|
328 | 328 | // flag for register hooks on extended pages b/c extended pages use the default INIT. |
329 | 329 | $extend = false; |
330 | 330 | // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
331 | - if (isset($this->_caffeinated_extends[ $page ])) { |
|
331 | + if (isset($this->_caffeinated_extends[$page])) { |
|
332 | 332 | $this->_current_caf_extend_slug = $page; |
333 | - $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name(); |
|
334 | - $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path']; |
|
335 | - $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page']; |
|
333 | + $admin_page_name = $this->_installed_pages[$page]->get_admin_page_name(); |
|
334 | + $caf_path = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['path']; |
|
335 | + $caf_admin_page = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['admin_page']; |
|
336 | 336 | add_filter( |
337 | 337 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}", |
338 | - function ($path_to_file) use ($caf_path) { |
|
338 | + function($path_to_file) use ($caf_path) { |
|
339 | 339 | return $caf_path; |
340 | 340 | } |
341 | 341 | ); |
342 | 342 | add_filter( |
343 | 343 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}", |
344 | - function ($admin_page) use ($caf_admin_page) { |
|
344 | + function($admin_page) use ($caf_admin_page) { |
|
345 | 345 | return $caf_admin_page; |
346 | 346 | } |
347 | 347 | ); |
348 | 348 | $extend = true; |
349 | 349 | } |
350 | 350 | // let's do the registered hooks |
351 | - $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend); |
|
351 | + $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend); |
|
352 | 352 | $hooks_ref = array_merge($hooks_ref, $extended_hooks); |
353 | 353 | } |
354 | 354 | } |
@@ -364,8 +364,8 @@ discard block |
||
364 | 364 | $ee_menu_slugs = $this->_menu_slugs; |
365 | 365 | // we need to loop again to run any early code |
366 | 366 | foreach ($installed_refs as $page => $path) { |
367 | - if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
368 | - $this->_installed_pages[ $page ]->do_initial_loads(); |
|
367 | + if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
368 | + $this->_installed_pages[$page]->do_initial_loads(); |
|
369 | 369 | } |
370 | 370 | } |
371 | 371 | do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
@@ -380,8 +380,8 @@ discard block |
||
380 | 380 | */ |
381 | 381 | public function get_admin_page_object($page_slug = '') |
382 | 382 | { |
383 | - if (isset($this->_installed_pages[ $page_slug ])) { |
|
384 | - return $this->_installed_pages[ $page_slug ]->loaded_page_object(); |
|
383 | + if (isset($this->_installed_pages[$page_slug])) { |
|
384 | + return $this->_installed_pages[$page_slug]->loaded_page_object(); |
|
385 | 385 | } |
386 | 386 | return null; |
387 | 387 | } |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | private function _get_classname_for_admin_page($dir_name = '') |
398 | 398 | { |
399 | 399 | $class_name = str_replace('_', ' ', strtolower($dir_name)); |
400 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
400 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page'; |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | private function _get_classname_for_admin_init_page($dir_name = '') |
412 | 412 | { |
413 | 413 | $class_name = str_replace('_', ' ', strtolower($dir_name)); |
414 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
414 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page_Init'; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | |
@@ -428,14 +428,14 @@ discard block |
||
428 | 428 | { |
429 | 429 | $class_name = $this->_get_classname_for_admin_init_page($page); |
430 | 430 | EE_Registry::instance()->load_file($path, $class_name, 'core'); |
431 | - if (! class_exists($class_name)) { |
|
431 | + if ( ! class_exists($class_name)) { |
|
432 | 432 | $inner_error_msg = '<br />' |
433 | 433 | . sprintf( |
434 | 434 | esc_html__( |
435 | 435 | 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
436 | 436 | 'event_espresso' |
437 | 437 | ), |
438 | - '<strong>' . $class_name . '</strong>' |
|
438 | + '<strong>'.$class_name.'</strong>' |
|
439 | 439 | ); |
440 | 440 | $error_msg[] = sprintf( |
441 | 441 | __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | // if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
516 | 516 | if (is_array($page_map) || empty($page_map)) { |
517 | 517 | new PersistentAdminNotice( |
518 | - 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
518 | + 'menu_map_warning_'.str_replace(' ', '_', $page->label).'_'.EVENT_ESPRESSO_VERSION, |
|
519 | 519 | sprintf( |
520 | 520 | __( |
521 | 521 | 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | continue; |
528 | 528 | } |
529 | 529 | // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
530 | - if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
530 | + if ( ! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
531 | 531 | throw new EE_Error( |
532 | 532 | sprintf( |
533 | 533 | __( |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | continue; |
547 | 547 | } |
548 | 548 | // assign to group (remember $page_map has the admin page stored in it). |
549 | - $pages_array[ $page_map->menu_group ][] = $page_map; |
|
549 | + $pages_array[$page_map->menu_group][] = $page_map; |
|
550 | 550 | } |
551 | 551 | } |
552 | 552 | if (empty($pages_array)) { |
@@ -555,20 +555,20 @@ discard block |
||
555 | 555 | // let's sort the groups, make sure it's a valid group, add header (if to show). |
556 | 556 | foreach ($pages_array as $group => $menu_maps) { |
557 | 557 | // valid_group? |
558 | - if (! array_key_exists($group, $menu_groups)) { |
|
558 | + if ( ! array_key_exists($group, $menu_groups)) { |
|
559 | 559 | continue; |
560 | 560 | } |
561 | 561 | // sort pages. |
562 | 562 | usort($menu_maps, array($this, '_sort_menu_maps')); |
563 | 563 | // prepend header |
564 | - array_unshift($menu_maps, $menu_groups[ $group ]); |
|
564 | + array_unshift($menu_maps, $menu_groups[$group]); |
|
565 | 565 | // reset $pages_array with prepped data |
566 | - $pages_array[ $group ] = $menu_maps; |
|
566 | + $pages_array[$group] = $menu_maps; |
|
567 | 567 | } |
568 | 568 | // now let's setup the _prepped_menu_maps property |
569 | 569 | foreach ($menu_groups as $group => $group_objs) { |
570 | - if (isset($pages_array[ $group ])) { |
|
571 | - $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]); |
|
570 | + if (isset($pages_array[$group])) { |
|
571 | + $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]); |
|
572 | 572 | } |
573 | 573 | }/**/ |
574 | 574 | } |
@@ -596,26 +596,26 @@ discard block |
||
596 | 596 | { |
597 | 597 | |
598 | 598 | // first let's check if there IS a caffeinated folder. If there is not then lets get out. |
599 | - if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
599 | + if ( ! is_dir(EE_PLUGIN_DIR_PATH.'caffeinated'.DS.'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
600 | 600 | return $installed_refs; |
601 | 601 | } |
602 | 602 | $this->_define_caffeinated_constants(); |
603 | 603 | $exclude = array('tickets'); |
604 | 604 | // okay let's setup an "New" pages first (we'll return installed refs later) |
605 | - $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
605 | + $new_admin_screens = glob(EE_CORE_CAF_ADMIN.'new/*', GLOB_ONLYDIR); |
|
606 | 606 | if ($new_admin_screens) { |
607 | 607 | foreach ($new_admin_screens as $admin_screen) { |
608 | 608 | // files and anything in the exclude array need not apply |
609 | 609 | if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
610 | 610 | // these folders represent the different NEW EE admin pages |
611 | - $installed_refs[ basename($admin_screen) ] = $admin_screen; |
|
611 | + $installed_refs[basename($admin_screen)] = $admin_screen; |
|
612 | 612 | // set autoloaders for our admin page classes based on included path information |
613 | 613 | EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen); |
614 | 614 | } |
615 | 615 | } |
616 | 616 | } |
617 | 617 | // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
618 | - $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
618 | + $extends = glob(EE_CORE_CAF_ADMIN.'extend/*', GLOB_ONLYDIR); |
|
619 | 619 | if ($extends) { |
620 | 620 | foreach ($extends as $extend) { |
621 | 621 | if (is_dir($extend)) { |
@@ -632,8 +632,8 @@ discard block |
||
632 | 632 | ) |
633 | 633 | ) |
634 | 634 | ); |
635 | - $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
636 | - $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace( |
|
635 | + $filename = 'Extend_'.$filename.'_Admin_Page'; |
|
636 | + $this->_caffeinated_extends[$extend_ref]['path'] = str_replace( |
|
637 | 637 | array('\\', '/'), |
638 | 638 | DS, |
639 | 639 | EE_CORE_CAF_ADMIN |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | . $filename |
645 | 645 | . '.core.php' |
646 | 646 | ); |
647 | - $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename; |
|
647 | + $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename; |
|
648 | 648 | // set autoloaders for our admin page classes based on included path information |
649 | 649 | EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend); |
650 | 650 | } |
@@ -652,12 +652,12 @@ discard block |
||
652 | 652 | } |
653 | 653 | // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
654 | 654 | $ee_admin_hooks = array(); |
655 | - $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
655 | + $hooks = glob(EE_CORE_CAF_ADMIN.'hooks/*.class.php'); |
|
656 | 656 | if ($hooks) { |
657 | 657 | foreach ($hooks as $hook) { |
658 | 658 | if (is_readable($hook)) { |
659 | 659 | require_once $hook; |
660 | - $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
660 | + $classname = str_replace(EE_CORE_CAF_ADMIN.'hooks/', '', $hook); |
|
661 | 661 | $classname = str_replace('.class.php', '', $classname); |
662 | 662 | if (class_exists($classname)) { |
663 | 663 | $a = new ReflectionClass($classname); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param $messenger |
85 | 85 | * @param string $orderby |
86 | 86 | * @param string $order |
87 | - * @return array all (including trashed or inactive) message template group objects for the given messenger |
|
87 | + * @return EE_Base_Class[] all (including trashed or inactive) message template group objects for the given messenger |
|
88 | 88 | */ |
89 | 89 | public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC') |
90 | 90 | { |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | /** |
342 | 342 | * This sends things to the validator for the given messenger and message type. |
343 | 343 | * |
344 | - * @param array $fields the incoming fields to check. |
|
344 | + * @param string $fields the incoming fields to check. |
|
345 | 345 | * Note this array is in the formatted fields from the form fields setup. |
346 | 346 | * So we need to reformat this into an array of expected field refs by the validator. |
347 | 347 | * Note also that this is not only the fields for the Message Template Group |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | 'WP_User' => new EE_Belongs_To_Relation() |
45 | 45 | ); |
46 | 46 | foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
47 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
47 | + $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
48 | 48 | } |
49 | 49 | $this->_caps_slug = 'messages'; |
50 | 50 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | $limit = null, |
72 | 72 | $count = false |
73 | 73 | ) { |
74 | - $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
74 | + $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
75 | 75 | return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
76 | 76 | } |
77 | 77 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC') |
90 | 90 | { |
91 | 91 | return $this->get_all_deleted_and_undeleted( |
92 | - array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) ) |
|
92 | + array(array('MTP_messenger' => $messenger), 'order_by' => array($orderby => $order)) |
|
93 | 93 | ); |
94 | 94 | } |
95 | 95 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | && $_REQUEST['ee_messenger_filter_by'] != 'none_selected' |
108 | 108 | && $_REQUEST['ee_messenger_filter_by'] != 'all' |
109 | 109 | ) { |
110 | - $_where['MTP_messenger'] = $_REQUEST['ee_messenger_filter_by'] ; |
|
110 | + $_where['MTP_messenger'] = $_REQUEST['ee_messenger_filter_by']; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | if (isset($_REQUEST['ee_message_type_filter_by']) |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | $global = true, |
142 | 142 | $user_check = false |
143 | 143 | ) { |
144 | - $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
144 | + $_where = $global ? array('MTP_is_global' => true) : array('MTP_is_global' => false); |
|
145 | 145 | $_where['MTP_is_active'] = true; |
146 | 146 | $_where = $this->_maybe_mtp_filters($_where); |
147 | 147 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $_where['MTP_user_id'] = get_current_user_id(); |
156 | 156 | } |
157 | 157 | |
158 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
158 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
159 | 159 | |
160 | 160 | return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
161 | 161 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | { |
177 | 177 | $_where = $this->_maybe_mtp_filters(); |
178 | 178 | |
179 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
179 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
180 | 180 | |
181 | 181 | $r_templates = $count |
182 | 182 | ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true) |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public function get_all_custom_templates_by_event($EVT_ID, $query_params = array()) |
198 | 198 | { |
199 | - $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID )); |
|
199 | + $where = array_merge($query_params, array('Event.EVT_ID' => $EVT_ID)); |
|
200 | 200 | return $this->get_all( |
201 | - array( $where ) |
|
201 | + array($where) |
|
202 | 202 | ); |
203 | 203 | } |
204 | 204 | |
@@ -223,11 +223,11 @@ discard block |
||
223 | 223 | $count = false, |
224 | 224 | $global = true |
225 | 225 | ) { |
226 | - $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
226 | + $_where = $global ? array('MTP_is_global' => true) : array('MTP_is_global' => false); |
|
227 | 227 | $_where['MTP_is_active'] = true; |
228 | 228 | $_where = $this->_maybe_mtp_filters($_where); |
229 | 229 | |
230 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
230 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
231 | 231 | |
232 | 232 | return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
233 | 233 | } |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | 'MTP_is_active' => $active |
266 | 266 | ); |
267 | 267 | |
268 | - $query_params = array( $_where, 'order_by' => array($orderby=>$order), 'limit' => $limit ); |
|
268 | + $query_params = array($_where, 'order_by' => array($orderby=>$order), 'limit' => $limit); |
|
269 | 269 | |
270 | 270 | return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
271 | 271 | } |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | $_where['MTP_is_active'] = $active; |
306 | 306 | } |
307 | 307 | |
308 | - $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit ); |
|
308 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
309 | 309 | |
310 | 310 | return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
311 | 311 | } |
@@ -363,19 +363,19 @@ discard block |
||
363 | 363 | // first let's figure out if the value['content'] in the current index is an array. |
364 | 364 | // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
365 | 365 | if (is_array($value['content'])) { |
366 | - $assembled_fields[ $value['name'] ] = $value['content']['main']; |
|
366 | + $assembled_fields[$value['name']] = $value['content']['main']; |
|
367 | 367 | // loop through the content and get the other fields. |
368 | 368 | foreach ($value['content'] as $name => $val) { |
369 | 369 | if ($name == 'main') { |
370 | 370 | continue; |
371 | 371 | } |
372 | - $assembled_fields[ $name ] = $val; |
|
372 | + $assembled_fields[$name] = $val; |
|
373 | 373 | } |
374 | 374 | continue; |
375 | 375 | } |
376 | 376 | |
377 | 377 | // okay if we're here then this is just a straight field=>$value arrangement |
378 | - $assembled_fields[ $value['name'] ] = $value['content']; |
|
378 | + $assembled_fields[$value['name']] = $value['content']; |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | // now we've got the assembled_fields. |
@@ -385,9 +385,9 @@ discard block |
||
385 | 385 | $mt_ref = ucwords(str_replace('_', ' ', $message_type)); |
386 | 386 | $mt_ref = str_replace(' ', '_', $mt_ref); |
387 | 387 | |
388 | - $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator'; |
|
388 | + $classname = 'EE_Messages_'.$m_ref.'_'.$mt_ref.'_Validator'; |
|
389 | 389 | |
390 | - if (!class_exists($classname)) { |
|
390 | + if ( ! class_exists($classname)) { |
|
391 | 391 | $msg[] = __('The Validator class was unable to load', 'event_espresso'); |
392 | 392 | $msg[] = sprintf( |
393 | 393 | __( |
@@ -425,12 +425,12 @@ discard block |
||
425 | 425 | if (empty($messenger_names) && empty($message_type_names)) { |
426 | 426 | return 0; |
427 | 427 | } |
428 | - if (! empty($messenger_names)) { |
|
429 | - $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names ); |
|
428 | + if ( ! empty($messenger_names)) { |
|
429 | + $query_args[0]['MTP_messenger'] = array('IN', (array) $messenger_names); |
|
430 | 430 | } |
431 | - if (! empty($message_type_names)) { |
|
432 | - $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names ); |
|
431 | + if ( ! empty($message_type_names)) { |
|
432 | + $query_args[0]['MTP_message_type'] = array('IN', (array) $message_type_names); |
|
433 | 433 | } |
434 | - return $this->update(array( 'MTP_is_active' => false ), $query_args); |
|
434 | + return $this->update(array('MTP_is_active' => false), $query_args); |
|
435 | 435 | } |
436 | 436 | } |
@@ -11,426 +11,426 @@ |
||
11 | 11 | class EEM_Message_Template_Group extends EEM_Soft_Delete_Base |
12 | 12 | { |
13 | 13 | |
14 | - // private instance of the EEM_Message_Template_Group object |
|
15 | - protected static $_instance = null; |
|
16 | - |
|
17 | - |
|
18 | - |
|
19 | - protected function __construct($timezone = null) |
|
20 | - { |
|
21 | - $this->singular_item = __('Message Template Group', 'event_espresso'); |
|
22 | - $this->plural_item = __('Message Template Groups', 'event_espresso'); |
|
23 | - $this->_tables = array( |
|
24 | - 'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID') |
|
25 | - ); |
|
26 | - $this->_fields = array( |
|
27 | - 'Message_Template_Group' => array( |
|
28 | - 'GRP_ID' => new EE_Primary_Key_Int_Field('GRP_ID', __('Message Template Group ID', 'event_espresso')), |
|
29 | - 'MTP_name' => new EE_Plain_Text_Field('MTP_name', __('The name of the template group', 'event_espresso'), false, ''), |
|
30 | - 'MTP_description' => new EE_Simple_HTML_Field('MTP_description', __('A brief description about this template.', 'event_espresso'), false, ''), |
|
31 | - 'MTP_user_id'=> new EE_WP_User_Field('MTP_user_id', __('Template Creator ID', 'event_espresso'), false, get_current_user_id()), |
|
32 | - 'MTP_messenger'=>new EE_Plain_Text_Field('MTP_messenger', __('Messenger Used for Template', 'event_espresso'), false, 'email'), |
|
33 | - 'MTP_message_type'=>new EE_Plain_Text_Field('MTP_message_type', __('Message Type', 'event_espresso'), false, 'registration'), |
|
34 | - 'MTP_is_global'=>new EE_Boolean_Field('MTP_is_global', __('Flag indicating if Template Group is Global', 'event_espresso'), false, true), |
|
35 | - 'MTP_is_override'=>new EE_Boolean_Field('MTP_is_override', __('Flag indicating if Template Group overrides any other Templates for the messenger/messagetype combination', 'event_espresso'), false, false), |
|
36 | - 'MTP_deleted'=>new EE_Trashed_Flag_Field('MTP_deleted', __('Flag indicating whether this has been trashed', 'event_espresso'), false, false), |
|
37 | - 'MTP_is_active'=>new EE_Boolean_Field('MTP_is_active', __('Flag indicating whether template group is active', 'event_espresso'), false, true) |
|
38 | - ) |
|
39 | - ); |
|
40 | - $this->_model_relations = array( |
|
41 | - 'Message_Template' => new EE_Has_Many_Relation(), |
|
42 | - 'Message' => new EE_Has_Many_Relation(), |
|
43 | - 'Event' => new EE_HABTM_Relation('Event_Message_Template'), |
|
44 | - 'WP_User' => new EE_Belongs_To_Relation() |
|
45 | - ); |
|
46 | - foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
47 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
48 | - } |
|
49 | - $this->_caps_slug = 'messages'; |
|
50 | - |
|
51 | - parent::__construct($timezone); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * get_all_trashed_message_templates_by_event |
|
58 | - * |
|
59 | - * @access public |
|
60 | - * @param int $EVT_ID specific event id |
|
61 | - * @param string $orderby |
|
62 | - * @param string $order |
|
63 | - * @param null $limit |
|
64 | - * @param bool $count |
|
65 | - * @return array message template objects that are attached to a specific event. |
|
66 | - */ |
|
67 | - public function get_all_trashed_message_templates_by_event( |
|
68 | - $EVT_ID, |
|
69 | - $orderby = 'GRP_ID', |
|
70 | - $order = 'ASC', |
|
71 | - $limit = null, |
|
72 | - $count = false |
|
73 | - ) { |
|
74 | - $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
75 | - return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * get_all_message_templates_by_messenger |
|
82 | - * |
|
83 | - * @access public |
|
84 | - * @param $messenger |
|
85 | - * @param string $orderby |
|
86 | - * @param string $order |
|
87 | - * @return array all (including trashed or inactive) message template group objects for the given messenger |
|
88 | - */ |
|
89 | - public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC') |
|
90 | - { |
|
91 | - return $this->get_all_deleted_and_undeleted( |
|
92 | - array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) ) |
|
93 | - ); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * This simply adds on any messenger/message type filters that may be present in the $_POST global |
|
100 | - * @param array $_where any existing where conditions to append these to. |
|
101 | - * @return array original where conditions or original with additional filters. |
|
102 | - */ |
|
103 | - protected function _maybe_mtp_filters($_where = array()) |
|
104 | - { |
|
105 | - // account for messenger or message type filters |
|
106 | - if (isset($_REQUEST['ee_messenger_filter_by']) |
|
107 | - && $_REQUEST['ee_messenger_filter_by'] != 'none_selected' |
|
108 | - && $_REQUEST['ee_messenger_filter_by'] != 'all' |
|
109 | - ) { |
|
110 | - $_where['MTP_messenger'] = $_REQUEST['ee_messenger_filter_by'] ; |
|
111 | - } |
|
112 | - |
|
113 | - if (isset($_REQUEST['ee_message_type_filter_by']) |
|
114 | - && $_REQUEST['ee_message_type_filter_by'] != 'none_selected' |
|
115 | - ) { |
|
116 | - $_where['MTP_message_type'] = $_REQUEST['ee_message_type_filter_by']; |
|
117 | - } |
|
118 | - |
|
119 | - return $_where; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * get_all_active_message_templates groups |
|
126 | - * |
|
127 | - * @access public |
|
128 | - * @param string $orderby |
|
129 | - * @param string $order |
|
130 | - * @param null $limit |
|
131 | - * @param bool $count |
|
132 | - * @param bool $global |
|
133 | - * @param bool $user_check |
|
134 | - * @return array all active (non_trashed, active) message template objects |
|
135 | - */ |
|
136 | - public function get_all_active_message_templates( |
|
137 | - $orderby = 'GRP_ID', |
|
138 | - $order = 'ASC', |
|
139 | - $limit = null, |
|
140 | - $count = false, |
|
141 | - $global = true, |
|
142 | - $user_check = false |
|
143 | - ) { |
|
144 | - $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
145 | - $_where['MTP_is_active'] = true; |
|
146 | - $_where = $this->_maybe_mtp_filters($_where); |
|
147 | - |
|
148 | - if ($user_check |
|
149 | - && ! $global |
|
150 | - && ! EE_Registry::instance()->CAP->current_user_can( |
|
151 | - 'ee_read_others_messages', |
|
152 | - 'get_all_active_message_templates' |
|
153 | - ) |
|
154 | - ) { |
|
155 | - $_where['MTP_user_id'] = get_current_user_id(); |
|
156 | - } |
|
157 | - |
|
158 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
159 | - |
|
160 | - return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * retrieve ALL message_template groups from db regardless of wht |
|
167 | - * |
|
168 | - * @access public |
|
169 | - * @param string $orderby |
|
170 | - * @param string $order |
|
171 | - * @param null $limit |
|
172 | - * @param bool $count |
|
173 | - * @return mixed array on success, FALSE on fail |
|
174 | - */ |
|
175 | - public function get_all_message_templates($orderby = 'GRP_ID', $order = 'ASC', $limit = null, $count = false) |
|
176 | - { |
|
177 | - $_where = $this->_maybe_mtp_filters(); |
|
178 | - |
|
179 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
180 | - |
|
181 | - $r_templates = $count |
|
182 | - ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true) |
|
183 | - : $this->get_all_deleted_and_undeleted($query_params); |
|
184 | - |
|
185 | - return $r_templates; |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * This gets all the custom templates attached to a specific event |
|
193 | - * @param int $EVT_ID event id |
|
194 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
195 | - * @return EE_Message_Template_Group[] |
|
196 | - */ |
|
197 | - public function get_all_custom_templates_by_event($EVT_ID, $query_params = array()) |
|
198 | - { |
|
199 | - $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID )); |
|
200 | - return $this->get_all( |
|
201 | - array( $where ) |
|
202 | - ); |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * get_all_trashed_grouped_message_templates |
|
209 | - * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed |
|
210 | - * |
|
211 | - * @access public |
|
212 | - * @param string $orderby |
|
213 | - * @param string $order |
|
214 | - * @param null $limit |
|
215 | - * @param bool $count |
|
216 | - * @param bool $global |
|
217 | - * @return \EE_Message_Template_Group[] message template groups. |
|
218 | - */ |
|
219 | - public function get_all_trashed_grouped_message_templates( |
|
220 | - $orderby = 'GRP_ID', |
|
221 | - $order = 'ASC', |
|
222 | - $limit = null, |
|
223 | - $count = false, |
|
224 | - $global = true |
|
225 | - ) { |
|
226 | - $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
227 | - $_where['MTP_is_active'] = true; |
|
228 | - $_where = $this->_maybe_mtp_filters($_where); |
|
229 | - |
|
230 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
231 | - |
|
232 | - return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * this returns the message template group(s) for a given event, messenger, and message template |
|
239 | - * |
|
240 | - * @param string $messenger |
|
241 | - * @param string $message_type |
|
242 | - * @param $evt_id |
|
243 | - * @param string $orderby pointless at this point but still included |
|
244 | - * @param string $order |
|
245 | - * @param mixed (array|null) $limit array($offset, $num) |
|
246 | - * @param bool $count true = just return count, false = objects |
|
247 | - * @param bool $active ignore "active" or not. (default only return active) |
|
248 | - * @return \mixed[]) depending on $count. |
|
249 | - */ |
|
250 | - public function get_event_message_templates_by_m_and_mt_and_evt( |
|
251 | - $messenger, |
|
252 | - $message_type, |
|
253 | - $evt_id, |
|
254 | - $orderby = 'GRP_ID', |
|
255 | - $order = 'ASC', |
|
256 | - $limit = null, |
|
257 | - $count = false, |
|
258 | - $active = true |
|
259 | - ) { |
|
260 | - $_where = array( |
|
261 | - 'MTP_messenger' => $messenger, |
|
262 | - 'MTP_message_type' => $message_type, |
|
263 | - 'Event.EVT_ID' => $evt_id, |
|
264 | - 'MTP_is_global' => true, |
|
265 | - 'MTP_is_active' => $active |
|
266 | - ); |
|
267 | - |
|
268 | - $query_params = array( $_where, 'order_by' => array($orderby=>$order), 'limit' => $limit ); |
|
269 | - |
|
270 | - return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * get all GLOBAL message template groups for the given messenger and message type |
|
278 | - * |
|
279 | - * @param string $messenger slug for messenger |
|
280 | - * @param string $message_type slug for message type |
|
281 | - * @param string $orderby what column to orderby |
|
282 | - * @param string $order ASC or DESC |
|
283 | - * @param mixed (array|null) $limit array($offset, $num) |
|
284 | - * @param bool $count true = just return count, false = objects |
|
285 | - * @param bool $active ignore "active" or not. (default only return active) - |
|
286 | - * 'all' means return both inactive AND inactive. |
|
287 | - * @return array message template objects that are global (i.e. non-event) |
|
288 | - */ |
|
289 | - public function get_global_message_template_by_m_and_mt( |
|
290 | - $messenger, |
|
291 | - $message_type, |
|
292 | - $orderby = 'GRP_ID', |
|
293 | - $order = 'ASC', |
|
294 | - $limit = null, |
|
295 | - $count = false, |
|
296 | - $active = true |
|
297 | - ) { |
|
298 | - $_where = array( |
|
299 | - 'MTP_messenger' => $messenger, |
|
300 | - 'MTP_message_type' => $message_type, |
|
301 | - 'MTP_is_global' => true, |
|
302 | - ); |
|
303 | - |
|
304 | - if ($active != 'all') { |
|
305 | - $_where['MTP_is_active'] = $active; |
|
306 | - } |
|
307 | - |
|
308 | - $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit ); |
|
309 | - |
|
310 | - return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * get all custom message template groups for the given messenger and message type |
|
318 | - * @param string $messenger messenger |
|
319 | - * @param string $message_type messagetype |
|
320 | - * @param array $query_params same as EEM_Base->get_all() |
|
321 | - * @return EE_Message_Template_Group[] |
|
322 | - */ |
|
323 | - public function get_custom_message_template_by_m_and_mt($messenger, $message_type, $query_params = array()) |
|
324 | - { |
|
325 | - return $this->get_all( |
|
326 | - array_merge( |
|
327 | - $query_params, |
|
328 | - array( |
|
329 | - array( |
|
330 | - 'MTP_is_global' => false, |
|
331 | - 'MTP_messenger' => $messenger, |
|
332 | - 'MTP_message_type' => $message_type |
|
333 | - ) |
|
334 | - ) |
|
335 | - ) |
|
336 | - ); |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * This sends things to the validator for the given messenger and message type. |
|
343 | - * |
|
344 | - * @param array $fields the incoming fields to check. |
|
345 | - * Note this array is in the formatted fields from the form fields setup. |
|
346 | - * So we need to reformat this into an array of expected field refs by the validator. |
|
347 | - * Note also that this is not only the fields for the Message Template Group |
|
348 | - * but ALSO for Message Template. |
|
349 | - * @param string $context The context the fields were obtained from. |
|
350 | - * @param string $messenger The messenger we are validating |
|
351 | - * @param string $message_type The message type we are validating. |
|
352 | - * @return mixed If the fields all check out then we return true otherwise error messages are returned |
|
353 | - * (indexed by field name); |
|
354 | - * @throws \EE_Error |
|
355 | - */ |
|
356 | - public function validate($fields, $context, $messenger, $message_type) |
|
357 | - { |
|
358 | - |
|
359 | - $assembled_fields = array(); |
|
360 | - |
|
361 | - // let's loop through all the fields and set them up in the right format |
|
362 | - foreach ($fields as $index => $value) { |
|
363 | - // first let's figure out if the value['content'] in the current index is an array. |
|
364 | - // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
|
365 | - if (is_array($value['content'])) { |
|
366 | - $assembled_fields[ $value['name'] ] = $value['content']['main']; |
|
367 | - // loop through the content and get the other fields. |
|
368 | - foreach ($value['content'] as $name => $val) { |
|
369 | - if ($name == 'main') { |
|
370 | - continue; |
|
371 | - } |
|
372 | - $assembled_fields[ $name ] = $val; |
|
373 | - } |
|
374 | - continue; |
|
375 | - } |
|
376 | - |
|
377 | - // okay if we're here then this is just a straight field=>$value arrangement |
|
378 | - $assembled_fields[ $value['name'] ] = $value['content']; |
|
379 | - } |
|
380 | - |
|
381 | - // now we've got the assembled_fields. |
|
382 | - // We need to setup the string for the appropriate validator class and call that. |
|
383 | - $m_ref = ucwords(str_replace('_', ' ', $messenger)); |
|
384 | - $m_ref = str_replace(' ', '_', $m_ref); |
|
385 | - $mt_ref = ucwords(str_replace('_', ' ', $message_type)); |
|
386 | - $mt_ref = str_replace(' ', '_', $mt_ref); |
|
387 | - |
|
388 | - $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator'; |
|
389 | - |
|
390 | - if (!class_exists($classname)) { |
|
391 | - $msg[] = __('The Validator class was unable to load', 'event_espresso'); |
|
392 | - $msg[] = sprintf( |
|
393 | - __( |
|
394 | - 'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', |
|
395 | - 'event_espresso' |
|
396 | - ), |
|
397 | - $classname |
|
398 | - ); |
|
399 | - throw new EE_Error(implode('||', $msg)); |
|
400 | - } |
|
401 | - |
|
402 | - $a = new ReflectionClass($classname); |
|
403 | - $_VLD = $a->newInstance($assembled_fields, $context); |
|
404 | - $result = $_VLD->validate(); |
|
405 | - return $result; |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * Updates all message template groups matching the incoming arguments to inactive status. |
|
412 | - * |
|
413 | - * @param array $messenger_names The messenger slugs. |
|
414 | - * If empty then all templates matching the message types are marked inactive. |
|
415 | - * Otherwise only templates matching the messengers and message types. |
|
416 | - * @param array $message_type_names The message type slugs. |
|
417 | - * If empty then all templates matching the messengers are marked inactive. |
|
418 | - * Otherwise only templates matching the messengers and message types. |
|
419 | - * |
|
420 | - * @return int count of updated records. |
|
421 | - */ |
|
422 | - public function deactivate_message_template_groups_for($messenger_names = array(), $message_type_names = array()) |
|
423 | - { |
|
424 | - $query_args = array(); |
|
425 | - if (empty($messenger_names) && empty($message_type_names)) { |
|
426 | - return 0; |
|
427 | - } |
|
428 | - if (! empty($messenger_names)) { |
|
429 | - $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names ); |
|
430 | - } |
|
431 | - if (! empty($message_type_names)) { |
|
432 | - $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names ); |
|
433 | - } |
|
434 | - return $this->update(array( 'MTP_is_active' => false ), $query_args); |
|
435 | - } |
|
14 | + // private instance of the EEM_Message_Template_Group object |
|
15 | + protected static $_instance = null; |
|
16 | + |
|
17 | + |
|
18 | + |
|
19 | + protected function __construct($timezone = null) |
|
20 | + { |
|
21 | + $this->singular_item = __('Message Template Group', 'event_espresso'); |
|
22 | + $this->plural_item = __('Message Template Groups', 'event_espresso'); |
|
23 | + $this->_tables = array( |
|
24 | + 'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID') |
|
25 | + ); |
|
26 | + $this->_fields = array( |
|
27 | + 'Message_Template_Group' => array( |
|
28 | + 'GRP_ID' => new EE_Primary_Key_Int_Field('GRP_ID', __('Message Template Group ID', 'event_espresso')), |
|
29 | + 'MTP_name' => new EE_Plain_Text_Field('MTP_name', __('The name of the template group', 'event_espresso'), false, ''), |
|
30 | + 'MTP_description' => new EE_Simple_HTML_Field('MTP_description', __('A brief description about this template.', 'event_espresso'), false, ''), |
|
31 | + 'MTP_user_id'=> new EE_WP_User_Field('MTP_user_id', __('Template Creator ID', 'event_espresso'), false, get_current_user_id()), |
|
32 | + 'MTP_messenger'=>new EE_Plain_Text_Field('MTP_messenger', __('Messenger Used for Template', 'event_espresso'), false, 'email'), |
|
33 | + 'MTP_message_type'=>new EE_Plain_Text_Field('MTP_message_type', __('Message Type', 'event_espresso'), false, 'registration'), |
|
34 | + 'MTP_is_global'=>new EE_Boolean_Field('MTP_is_global', __('Flag indicating if Template Group is Global', 'event_espresso'), false, true), |
|
35 | + 'MTP_is_override'=>new EE_Boolean_Field('MTP_is_override', __('Flag indicating if Template Group overrides any other Templates for the messenger/messagetype combination', 'event_espresso'), false, false), |
|
36 | + 'MTP_deleted'=>new EE_Trashed_Flag_Field('MTP_deleted', __('Flag indicating whether this has been trashed', 'event_espresso'), false, false), |
|
37 | + 'MTP_is_active'=>new EE_Boolean_Field('MTP_is_active', __('Flag indicating whether template group is active', 'event_espresso'), false, true) |
|
38 | + ) |
|
39 | + ); |
|
40 | + $this->_model_relations = array( |
|
41 | + 'Message_Template' => new EE_Has_Many_Relation(), |
|
42 | + 'Message' => new EE_Has_Many_Relation(), |
|
43 | + 'Event' => new EE_HABTM_Relation('Event_Message_Template'), |
|
44 | + 'WP_User' => new EE_Belongs_To_Relation() |
|
45 | + ); |
|
46 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
47 | + $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
48 | + } |
|
49 | + $this->_caps_slug = 'messages'; |
|
50 | + |
|
51 | + parent::__construct($timezone); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * get_all_trashed_message_templates_by_event |
|
58 | + * |
|
59 | + * @access public |
|
60 | + * @param int $EVT_ID specific event id |
|
61 | + * @param string $orderby |
|
62 | + * @param string $order |
|
63 | + * @param null $limit |
|
64 | + * @param bool $count |
|
65 | + * @return array message template objects that are attached to a specific event. |
|
66 | + */ |
|
67 | + public function get_all_trashed_message_templates_by_event( |
|
68 | + $EVT_ID, |
|
69 | + $orderby = 'GRP_ID', |
|
70 | + $order = 'ASC', |
|
71 | + $limit = null, |
|
72 | + $count = false |
|
73 | + ) { |
|
74 | + $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
75 | + return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * get_all_message_templates_by_messenger |
|
82 | + * |
|
83 | + * @access public |
|
84 | + * @param $messenger |
|
85 | + * @param string $orderby |
|
86 | + * @param string $order |
|
87 | + * @return array all (including trashed or inactive) message template group objects for the given messenger |
|
88 | + */ |
|
89 | + public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC') |
|
90 | + { |
|
91 | + return $this->get_all_deleted_and_undeleted( |
|
92 | + array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) ) |
|
93 | + ); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * This simply adds on any messenger/message type filters that may be present in the $_POST global |
|
100 | + * @param array $_where any existing where conditions to append these to. |
|
101 | + * @return array original where conditions or original with additional filters. |
|
102 | + */ |
|
103 | + protected function _maybe_mtp_filters($_where = array()) |
|
104 | + { |
|
105 | + // account for messenger or message type filters |
|
106 | + if (isset($_REQUEST['ee_messenger_filter_by']) |
|
107 | + && $_REQUEST['ee_messenger_filter_by'] != 'none_selected' |
|
108 | + && $_REQUEST['ee_messenger_filter_by'] != 'all' |
|
109 | + ) { |
|
110 | + $_where['MTP_messenger'] = $_REQUEST['ee_messenger_filter_by'] ; |
|
111 | + } |
|
112 | + |
|
113 | + if (isset($_REQUEST['ee_message_type_filter_by']) |
|
114 | + && $_REQUEST['ee_message_type_filter_by'] != 'none_selected' |
|
115 | + ) { |
|
116 | + $_where['MTP_message_type'] = $_REQUEST['ee_message_type_filter_by']; |
|
117 | + } |
|
118 | + |
|
119 | + return $_where; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * get_all_active_message_templates groups |
|
126 | + * |
|
127 | + * @access public |
|
128 | + * @param string $orderby |
|
129 | + * @param string $order |
|
130 | + * @param null $limit |
|
131 | + * @param bool $count |
|
132 | + * @param bool $global |
|
133 | + * @param bool $user_check |
|
134 | + * @return array all active (non_trashed, active) message template objects |
|
135 | + */ |
|
136 | + public function get_all_active_message_templates( |
|
137 | + $orderby = 'GRP_ID', |
|
138 | + $order = 'ASC', |
|
139 | + $limit = null, |
|
140 | + $count = false, |
|
141 | + $global = true, |
|
142 | + $user_check = false |
|
143 | + ) { |
|
144 | + $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
145 | + $_where['MTP_is_active'] = true; |
|
146 | + $_where = $this->_maybe_mtp_filters($_where); |
|
147 | + |
|
148 | + if ($user_check |
|
149 | + && ! $global |
|
150 | + && ! EE_Registry::instance()->CAP->current_user_can( |
|
151 | + 'ee_read_others_messages', |
|
152 | + 'get_all_active_message_templates' |
|
153 | + ) |
|
154 | + ) { |
|
155 | + $_where['MTP_user_id'] = get_current_user_id(); |
|
156 | + } |
|
157 | + |
|
158 | + $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
159 | + |
|
160 | + return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * retrieve ALL message_template groups from db regardless of wht |
|
167 | + * |
|
168 | + * @access public |
|
169 | + * @param string $orderby |
|
170 | + * @param string $order |
|
171 | + * @param null $limit |
|
172 | + * @param bool $count |
|
173 | + * @return mixed array on success, FALSE on fail |
|
174 | + */ |
|
175 | + public function get_all_message_templates($orderby = 'GRP_ID', $order = 'ASC', $limit = null, $count = false) |
|
176 | + { |
|
177 | + $_where = $this->_maybe_mtp_filters(); |
|
178 | + |
|
179 | + $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
180 | + |
|
181 | + $r_templates = $count |
|
182 | + ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true) |
|
183 | + : $this->get_all_deleted_and_undeleted($query_params); |
|
184 | + |
|
185 | + return $r_templates; |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * This gets all the custom templates attached to a specific event |
|
193 | + * @param int $EVT_ID event id |
|
194 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
195 | + * @return EE_Message_Template_Group[] |
|
196 | + */ |
|
197 | + public function get_all_custom_templates_by_event($EVT_ID, $query_params = array()) |
|
198 | + { |
|
199 | + $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID )); |
|
200 | + return $this->get_all( |
|
201 | + array( $where ) |
|
202 | + ); |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * get_all_trashed_grouped_message_templates |
|
209 | + * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed |
|
210 | + * |
|
211 | + * @access public |
|
212 | + * @param string $orderby |
|
213 | + * @param string $order |
|
214 | + * @param null $limit |
|
215 | + * @param bool $count |
|
216 | + * @param bool $global |
|
217 | + * @return \EE_Message_Template_Group[] message template groups. |
|
218 | + */ |
|
219 | + public function get_all_trashed_grouped_message_templates( |
|
220 | + $orderby = 'GRP_ID', |
|
221 | + $order = 'ASC', |
|
222 | + $limit = null, |
|
223 | + $count = false, |
|
224 | + $global = true |
|
225 | + ) { |
|
226 | + $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
227 | + $_where['MTP_is_active'] = true; |
|
228 | + $_where = $this->_maybe_mtp_filters($_where); |
|
229 | + |
|
230 | + $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
231 | + |
|
232 | + return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * this returns the message template group(s) for a given event, messenger, and message template |
|
239 | + * |
|
240 | + * @param string $messenger |
|
241 | + * @param string $message_type |
|
242 | + * @param $evt_id |
|
243 | + * @param string $orderby pointless at this point but still included |
|
244 | + * @param string $order |
|
245 | + * @param mixed (array|null) $limit array($offset, $num) |
|
246 | + * @param bool $count true = just return count, false = objects |
|
247 | + * @param bool $active ignore "active" or not. (default only return active) |
|
248 | + * @return \mixed[]) depending on $count. |
|
249 | + */ |
|
250 | + public function get_event_message_templates_by_m_and_mt_and_evt( |
|
251 | + $messenger, |
|
252 | + $message_type, |
|
253 | + $evt_id, |
|
254 | + $orderby = 'GRP_ID', |
|
255 | + $order = 'ASC', |
|
256 | + $limit = null, |
|
257 | + $count = false, |
|
258 | + $active = true |
|
259 | + ) { |
|
260 | + $_where = array( |
|
261 | + 'MTP_messenger' => $messenger, |
|
262 | + 'MTP_message_type' => $message_type, |
|
263 | + 'Event.EVT_ID' => $evt_id, |
|
264 | + 'MTP_is_global' => true, |
|
265 | + 'MTP_is_active' => $active |
|
266 | + ); |
|
267 | + |
|
268 | + $query_params = array( $_where, 'order_by' => array($orderby=>$order), 'limit' => $limit ); |
|
269 | + |
|
270 | + return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * get all GLOBAL message template groups for the given messenger and message type |
|
278 | + * |
|
279 | + * @param string $messenger slug for messenger |
|
280 | + * @param string $message_type slug for message type |
|
281 | + * @param string $orderby what column to orderby |
|
282 | + * @param string $order ASC or DESC |
|
283 | + * @param mixed (array|null) $limit array($offset, $num) |
|
284 | + * @param bool $count true = just return count, false = objects |
|
285 | + * @param bool $active ignore "active" or not. (default only return active) - |
|
286 | + * 'all' means return both inactive AND inactive. |
|
287 | + * @return array message template objects that are global (i.e. non-event) |
|
288 | + */ |
|
289 | + public function get_global_message_template_by_m_and_mt( |
|
290 | + $messenger, |
|
291 | + $message_type, |
|
292 | + $orderby = 'GRP_ID', |
|
293 | + $order = 'ASC', |
|
294 | + $limit = null, |
|
295 | + $count = false, |
|
296 | + $active = true |
|
297 | + ) { |
|
298 | + $_where = array( |
|
299 | + 'MTP_messenger' => $messenger, |
|
300 | + 'MTP_message_type' => $message_type, |
|
301 | + 'MTP_is_global' => true, |
|
302 | + ); |
|
303 | + |
|
304 | + if ($active != 'all') { |
|
305 | + $_where['MTP_is_active'] = $active; |
|
306 | + } |
|
307 | + |
|
308 | + $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit ); |
|
309 | + |
|
310 | + return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * get all custom message template groups for the given messenger and message type |
|
318 | + * @param string $messenger messenger |
|
319 | + * @param string $message_type messagetype |
|
320 | + * @param array $query_params same as EEM_Base->get_all() |
|
321 | + * @return EE_Message_Template_Group[] |
|
322 | + */ |
|
323 | + public function get_custom_message_template_by_m_and_mt($messenger, $message_type, $query_params = array()) |
|
324 | + { |
|
325 | + return $this->get_all( |
|
326 | + array_merge( |
|
327 | + $query_params, |
|
328 | + array( |
|
329 | + array( |
|
330 | + 'MTP_is_global' => false, |
|
331 | + 'MTP_messenger' => $messenger, |
|
332 | + 'MTP_message_type' => $message_type |
|
333 | + ) |
|
334 | + ) |
|
335 | + ) |
|
336 | + ); |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * This sends things to the validator for the given messenger and message type. |
|
343 | + * |
|
344 | + * @param array $fields the incoming fields to check. |
|
345 | + * Note this array is in the formatted fields from the form fields setup. |
|
346 | + * So we need to reformat this into an array of expected field refs by the validator. |
|
347 | + * Note also that this is not only the fields for the Message Template Group |
|
348 | + * but ALSO for Message Template. |
|
349 | + * @param string $context The context the fields were obtained from. |
|
350 | + * @param string $messenger The messenger we are validating |
|
351 | + * @param string $message_type The message type we are validating. |
|
352 | + * @return mixed If the fields all check out then we return true otherwise error messages are returned |
|
353 | + * (indexed by field name); |
|
354 | + * @throws \EE_Error |
|
355 | + */ |
|
356 | + public function validate($fields, $context, $messenger, $message_type) |
|
357 | + { |
|
358 | + |
|
359 | + $assembled_fields = array(); |
|
360 | + |
|
361 | + // let's loop through all the fields and set them up in the right format |
|
362 | + foreach ($fields as $index => $value) { |
|
363 | + // first let's figure out if the value['content'] in the current index is an array. |
|
364 | + // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
|
365 | + if (is_array($value['content'])) { |
|
366 | + $assembled_fields[ $value['name'] ] = $value['content']['main']; |
|
367 | + // loop through the content and get the other fields. |
|
368 | + foreach ($value['content'] as $name => $val) { |
|
369 | + if ($name == 'main') { |
|
370 | + continue; |
|
371 | + } |
|
372 | + $assembled_fields[ $name ] = $val; |
|
373 | + } |
|
374 | + continue; |
|
375 | + } |
|
376 | + |
|
377 | + // okay if we're here then this is just a straight field=>$value arrangement |
|
378 | + $assembled_fields[ $value['name'] ] = $value['content']; |
|
379 | + } |
|
380 | + |
|
381 | + // now we've got the assembled_fields. |
|
382 | + // We need to setup the string for the appropriate validator class and call that. |
|
383 | + $m_ref = ucwords(str_replace('_', ' ', $messenger)); |
|
384 | + $m_ref = str_replace(' ', '_', $m_ref); |
|
385 | + $mt_ref = ucwords(str_replace('_', ' ', $message_type)); |
|
386 | + $mt_ref = str_replace(' ', '_', $mt_ref); |
|
387 | + |
|
388 | + $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator'; |
|
389 | + |
|
390 | + if (!class_exists($classname)) { |
|
391 | + $msg[] = __('The Validator class was unable to load', 'event_espresso'); |
|
392 | + $msg[] = sprintf( |
|
393 | + __( |
|
394 | + 'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', |
|
395 | + 'event_espresso' |
|
396 | + ), |
|
397 | + $classname |
|
398 | + ); |
|
399 | + throw new EE_Error(implode('||', $msg)); |
|
400 | + } |
|
401 | + |
|
402 | + $a = new ReflectionClass($classname); |
|
403 | + $_VLD = $a->newInstance($assembled_fields, $context); |
|
404 | + $result = $_VLD->validate(); |
|
405 | + return $result; |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * Updates all message template groups matching the incoming arguments to inactive status. |
|
412 | + * |
|
413 | + * @param array $messenger_names The messenger slugs. |
|
414 | + * If empty then all templates matching the message types are marked inactive. |
|
415 | + * Otherwise only templates matching the messengers and message types. |
|
416 | + * @param array $message_type_names The message type slugs. |
|
417 | + * If empty then all templates matching the messengers are marked inactive. |
|
418 | + * Otherwise only templates matching the messengers and message types. |
|
419 | + * |
|
420 | + * @return int count of updated records. |
|
421 | + */ |
|
422 | + public function deactivate_message_template_groups_for($messenger_names = array(), $message_type_names = array()) |
|
423 | + { |
|
424 | + $query_args = array(); |
|
425 | + if (empty($messenger_names) && empty($message_type_names)) { |
|
426 | + return 0; |
|
427 | + } |
|
428 | + if (! empty($messenger_names)) { |
|
429 | + $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names ); |
|
430 | + } |
|
431 | + if (! empty($message_type_names)) { |
|
432 | + $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names ); |
|
433 | + } |
|
434 | + return $this->update(array( 'MTP_is_active' => false ), $query_args); |
|
435 | + } |
|
436 | 436 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | /** |
215 | 215 | * Overrides parent ot also check by the slug |
216 | 216 | * @see EEM_Base::ensure_is_obj() |
217 | - * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
217 | + * @param EE_Payment_Method $base_class_obj_or_id |
|
218 | 218 | * @param boolean $ensure_is_in_db |
219 | 219 | * @return EE_Payment_Method |
220 | 220 | * @throws EE_Error |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | * Note: if an offline payment method was selected on the related transaction then this will have no payment methods returned. |
383 | 383 | * It will ONLY return a payment method for a PAYMENT recorded against the registration. |
384 | 384 | * |
385 | - * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the registration. |
|
386 | - * @return EE_Payment|null |
|
385 | + * @param EE_Registration $registration_or_reg_id Either the EE_Registration object or the id for the registration. |
|
386 | + * @return null|EE_Base_Class |
|
387 | 387 | */ |
388 | 388 | public function get_last_used_for_registration($registration_or_reg_id) |
389 | 389 | { |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | { |
45 | 45 | $this->singlular_item = __('Payment Method', 'event_espresso'); |
46 | 46 | $this->plural_item = __('Payment Methods', 'event_espresso'); |
47 | - $this->_tables = array( 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID') ); |
|
47 | + $this->_tables = array('Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID')); |
|
48 | 48 | $this->_fields = array( |
49 | 49 | 'Payment_Method' => array( |
50 | 50 | 'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')), |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function get_one_by_slug($slug) |
80 | 80 | { |
81 | - return $this->get_one(array( array( 'PMD_slug' => $slug ) )); |
|
81 | + return $this->get_one(array(array('PMD_slug' => $slug))); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | public function is_valid_scope($scope) |
110 | 110 | { |
111 | 111 | $scopes = $this->scopes(); |
112 | - if (isset($scopes[ $scope ])) { |
|
112 | + if (isset($scopes[$scope])) { |
|
113 | 113 | return true; |
114 | 114 | } else { |
115 | 115 | return false; |
@@ -127,8 +127,8 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function get_all_active($scope = null, $query_params = array()) |
129 | 129 | { |
130 | - if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
131 | - $query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' ); |
|
130 | + if ( ! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
131 | + $query_params['order_by'] = array('PMD_order' => 'ASC', 'PMD_ID' => 'ASC'); |
|
132 | 132 | } |
133 | 133 | return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
134 | 134 | } |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | { |
157 | 157 | if ($scope) { |
158 | 158 | if ($this->is_valid_scope($scope)) { |
159 | - return array_replace_recursive(array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params); |
|
159 | + return array_replace_recursive(array(array('PMD_scope' => array('LIKE', "%$scope%"))), $query_params); |
|
160 | 160 | } else { |
161 | 161 | throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope)); |
162 | 162 | } |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | $count = 0; |
166 | 166 | foreach ($this->scopes() as $scope_name => $desc) { |
167 | 167 | $count++; |
168 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' ); |
|
168 | + $acceptable_scopes['PMD_scope*'.$count] = array('LIKE', '%'.$scope_name.'%'); |
|
169 | 169 | } |
170 | - return array_replace_recursive(array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params); |
|
170 | + return array_replace_recursive(array(array('OR*active_scope' => $acceptable_scopes)), $query_params); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | */ |
206 | 206 | public function get_one_of_type($type) |
207 | 207 | { |
208 | - return $this->get_one(array( array( 'PMD_type' => $type ) )); |
|
208 | + return $this->get_one(array(array('PMD_type' => $type))); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | $usable_payment_methods = array(); |
299 | 299 | foreach ($payment_methods as $key => $payment_method) { |
300 | 300 | if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
301 | - $usable_payment_methods[ $key ] = $payment_method; |
|
301 | + $usable_payment_methods[$key] = $payment_method; |
|
302 | 302 | // some payment methods enqueue their scripts in EE_PMT_*::__construct |
303 | 303 | // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
304 | 304 | // its scripts). but for backwards-compat we should continue to do that |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | $payment_method |
313 | 313 | ); |
314 | 314 | new PersistentAdminNotice( |
315 | - 'auto-deactivated-' . $payment_method->type(), |
|
315 | + 'auto-deactivated-'.$payment_method->type(), |
|
316 | 316 | sprintf( |
317 | 317 | __( |
318 | 318 | 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | ), |
321 | 321 | $payment_method->admin_name(), |
322 | 322 | '<br />', |
323 | - '<a href="' . admin_url('plugins.php') . '">', |
|
323 | + '<a href="'.admin_url('plugins.php').'">', |
|
324 | 324 | '</a>' |
325 | 325 | ), |
326 | 326 | true |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | // give addons a chance to override what payment methods are chosen based on the transaction |
346 | 346 | return apply_filters( |
347 | 347 | 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
348 | - $this->get_all_active($scope, array( 'group_by' => 'PMD_type' )), |
|
348 | + $this->get_all_active($scope, array('group_by' => 'PMD_type')), |
|
349 | 349 | $transaction, |
350 | 350 | $scope |
351 | 351 | ); |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | 0 => array( |
370 | 370 | 'Payment.Registration.REG_ID' => $registration_id, |
371 | 371 | ), |
372 | - 'order_by' => array( 'Payment.PAY_ID' => 'DESC' ) |
|
372 | + 'order_by' => array('Payment.PAY_ID' => 'DESC') |
|
373 | 373 | ); |
374 | 374 | return $this->get_one($query_params); |
375 | 375 | } |
@@ -20,363 +20,363 @@ |
||
20 | 20 | class EEM_Payment_Method extends EEM_Base |
21 | 21 | { |
22 | 22 | |
23 | - const scope_cart = 'CART'; |
|
24 | - |
|
25 | - const scope_admin = 'ADMIN'; |
|
26 | - |
|
27 | - const scope_api = 'API'; |
|
28 | - |
|
29 | - /** |
|
30 | - * |
|
31 | - * @type EEM_Payment_Method |
|
32 | - */ |
|
33 | - protected static $_instance = null; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * private constructor to prevent direct creation |
|
39 | - * @Constructor |
|
40 | - * @access protected |
|
41 | - * @return EEM_Payment_Method |
|
42 | - */ |
|
43 | - protected function __construct($timezone = null) |
|
44 | - { |
|
45 | - $this->singlular_item = __('Payment Method', 'event_espresso'); |
|
46 | - $this->plural_item = __('Payment Methods', 'event_espresso'); |
|
47 | - $this->_tables = array( 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID') ); |
|
48 | - $this->_fields = array( |
|
49 | - 'Payment_Method' => array( |
|
50 | - 'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')), |
|
51 | - 'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), false, 'Admin_Only'), |
|
52 | - 'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), false), |
|
53 | - 'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), false, ''), |
|
54 | - 'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), true), |
|
55 | - 'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), true), |
|
56 | - 'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), false), |
|
57 | - 'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), false, 0), |
|
58 | - 'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), false, false), |
|
59 | - 'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), false), |
|
60 | - 'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), false, false), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), true, ''), |
|
61 | - 'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), false, array()), // possible values currently are 'CART','ADMIN','API' |
|
62 | - ) ); |
|
63 | - $this->_model_relations = array( |
|
64 | - 'Payment' => new EE_Has_Many_Relation(), |
|
65 | - 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
66 | - 'Transaction' => new EE_Has_Many_Relation(), |
|
67 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
68 | - ); |
|
69 | - parent::__construct($timezone); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * Gets one by the slug provided |
|
76 | - * @param string $slug |
|
77 | - * @return EE_Payment_Method |
|
78 | - */ |
|
79 | - public function get_one_by_slug($slug) |
|
80 | - { |
|
81 | - return $this->get_one(array( array( 'PMD_slug' => $slug ) )); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Gets all the acceptable scopes for payment methods. |
|
88 | - * Keys are their names as store din the DB, and values are nice names for displaying them |
|
89 | - * @return array |
|
90 | - */ |
|
91 | - public function scopes() |
|
92 | - { |
|
93 | - return apply_filters( |
|
94 | - 'FHEE__EEM_Payment_Method__scopes', |
|
95 | - array( |
|
96 | - self::scope_cart => __("Front-end Registration Page", 'event_espresso'), |
|
97 | - self::scope_admin => __("Admin Registration Page (no online processing)", 'event_espresso') |
|
98 | - ) |
|
99 | - ); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * Determines if this is an valid scope |
|
106 | - * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
|
107 | - * @return boolean |
|
108 | - */ |
|
109 | - public function is_valid_scope($scope) |
|
110 | - { |
|
111 | - $scopes = $this->scopes(); |
|
112 | - if (isset($scopes[ $scope ])) { |
|
113 | - return true; |
|
114 | - } else { |
|
115 | - return false; |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Gets all active payment methods |
|
123 | - * @param string $scope one of |
|
124 | - * @param array $query_params |
|
125 | - * @throws EE_Error |
|
126 | - * @return EE_Payment_Method[] |
|
127 | - */ |
|
128 | - public function get_all_active($scope = null, $query_params = array()) |
|
129 | - { |
|
130 | - if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
131 | - $query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' ); |
|
132 | - } |
|
133 | - return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Counts all active gateways in the specified scope |
|
138 | - * @param string $scope one of EEM_Payment_Method::scope_* |
|
139 | - * @param array $query_params |
|
140 | - * @return int |
|
141 | - */ |
|
142 | - public function count_active($scope = null, $query_params = array()) |
|
143 | - { |
|
144 | - return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
149 | - * argument to get all active for a given scope |
|
150 | - * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
151 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
152 | - * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
153 | - * @throws EE_Error |
|
154 | - */ |
|
155 | - protected function _get_query_params_for_all_active($scope = null, $query_params = array()) |
|
156 | - { |
|
157 | - if ($scope) { |
|
158 | - if ($this->is_valid_scope($scope)) { |
|
159 | - return array_replace_recursive(array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params); |
|
160 | - } else { |
|
161 | - throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope)); |
|
162 | - } |
|
163 | - } else { |
|
164 | - $acceptable_scopes = array(); |
|
165 | - $count = 0; |
|
166 | - foreach ($this->scopes() as $scope_name => $desc) { |
|
167 | - $count++; |
|
168 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' ); |
|
169 | - } |
|
170 | - return array_replace_recursive(array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params); |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
176 | - * argument to get all active for a given scope |
|
177 | - * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
178 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
179 | - * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
180 | - * @throws EE_Error |
|
181 | - */ |
|
182 | - public function get_query_params_for_all_active($scope = null, $query_params = array()) |
|
183 | - { |
|
184 | - return $this->_get_query_params_for_all_active($scope, $query_params); |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Gets one active payment method. see @get_all_active for documentation |
|
190 | - * @param string $scope |
|
191 | - * @param array $query_params |
|
192 | - * @return EE_Payment_Method |
|
193 | - */ |
|
194 | - public function get_one_active($scope = null, $query_params = array()) |
|
195 | - { |
|
196 | - return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Gets one payment method of that type, regardless of whether its active or not |
|
203 | - * @param string $type |
|
204 | - * @return EE_Payment_Method |
|
205 | - */ |
|
206 | - public function get_one_of_type($type) |
|
207 | - { |
|
208 | - return $this->get_one(array( array( 'PMD_type' => $type ) )); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * Overrides parent ot also check by the slug |
|
215 | - * @see EEM_Base::ensure_is_obj() |
|
216 | - * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
217 | - * @param boolean $ensure_is_in_db |
|
218 | - * @return EE_Payment_Method |
|
219 | - * @throws EE_Error |
|
220 | - */ |
|
221 | - public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false) |
|
222 | - { |
|
223 | - // first: check if it's a slug |
|
224 | - if (is_string($base_class_obj_or_id)) { |
|
225 | - $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
226 | - if ($obj) { |
|
227 | - return $obj; |
|
228 | - } |
|
229 | - } |
|
230 | - // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
|
231 | - try { |
|
232 | - return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
233 | - } catch (EE_Error $e) { |
|
234 | - // handle it outside the catch |
|
235 | - } |
|
236 | - throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id)); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * Gets the ID of this object, or if its a string finds the object's id |
|
243 | - * associated with that slug |
|
244 | - * @param mixed $base_obj_or_id_or_slug |
|
245 | - * @return int |
|
246 | - */ |
|
247 | - public function ensure_is_ID($base_obj_or_id_or_slug) |
|
248 | - { |
|
249 | - if (is_string($base_obj_or_id_or_slug)) { |
|
250 | - // assume it's a slug |
|
251 | - $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
252 | - } |
|
253 | - return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default. |
|
260 | - * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart |
|
261 | - */ |
|
262 | - public function verify_button_urls($payment_methods = null) |
|
263 | - { |
|
264 | - $payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
265 | - foreach ($payment_methods as $payment_method) { |
|
266 | - try { |
|
267 | - // If there is really no button URL at all, or if the button URLs still point to decaf folder even |
|
268 | - // though this is a caffeinated install, reset it to the default. |
|
269 | - $current_button_url = $payment_method->button_url(); |
|
270 | - if (empty($current_button_url) |
|
271 | - || ( |
|
272 | - strpos($current_button_url, 'decaf') !== false |
|
273 | - && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false |
|
274 | - ) |
|
275 | - ) { |
|
276 | - $payment_method->save( |
|
277 | - [ |
|
278 | - 'PMD_button_url' => $payment_method->type_obj()->default_button_url() |
|
279 | - ] |
|
280 | - ); |
|
281 | - } |
|
282 | - } catch (EE_Error $e) { |
|
283 | - $payment_method->set_active(false); |
|
284 | - } |
|
285 | - } |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
292 | - * but also verifies the payment method type of each is a usable object. If not, |
|
293 | - * deactivate it, sets a notification, and deactivates it |
|
294 | - * |
|
295 | - * @param array $rows |
|
296 | - * @return EE_Payment_Method[] |
|
297 | - * @throws InvalidDataTypeException |
|
298 | - */ |
|
299 | - protected function _create_objects($rows = array()) |
|
300 | - { |
|
301 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
302 | - $payment_methods = parent::_create_objects($rows); |
|
303 | - /* @var $payment_methods EE_Payment_Method[] */ |
|
304 | - $usable_payment_methods = array(); |
|
305 | - foreach ($payment_methods as $key => $payment_method) { |
|
306 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
307 | - $usable_payment_methods[ $key ] = $payment_method; |
|
308 | - // some payment methods enqueue their scripts in EE_PMT_*::__construct |
|
309 | - // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
|
310 | - // its scripts). but for backwards-compat we should continue to do that |
|
311 | - $payment_method->type_obj(); |
|
312 | - } elseif ($payment_method->active()) { |
|
313 | - // only deactivate and notify the admin if the payment is active somewhere |
|
314 | - $payment_method->deactivate(); |
|
315 | - $payment_method->save(); |
|
316 | - do_action( |
|
317 | - 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
318 | - $payment_method |
|
319 | - ); |
|
320 | - new PersistentAdminNotice( |
|
321 | - 'auto-deactivated-' . $payment_method->type(), |
|
322 | - sprintf( |
|
323 | - __( |
|
324 | - 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
325 | - 'event_espresso' |
|
326 | - ), |
|
327 | - $payment_method->admin_name(), |
|
328 | - '<br />', |
|
329 | - '<a href="' . admin_url('plugins.php') . '">', |
|
330 | - '</a>' |
|
331 | - ), |
|
332 | - true |
|
333 | - ); |
|
334 | - } |
|
335 | - } |
|
336 | - return $usable_payment_methods; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * Gets all the payment methods which can be used for transaction |
|
343 | - * (according to the relations between payment methods and events, and |
|
344 | - * the currencies used for the transaction and their relation to payment methods) |
|
345 | - * @param EE_Transaction $transaction |
|
346 | - * @param string $scope @see EEM_Payment_Method::get_all_for_events |
|
347 | - * @return EE_Payment_Method[] |
|
348 | - */ |
|
349 | - public function get_all_for_transaction($transaction, $scope) |
|
350 | - { |
|
351 | - // give addons a chance to override what payment methods are chosen based on the transaction |
|
352 | - return apply_filters( |
|
353 | - 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
|
354 | - $this->get_all_active($scope, array( 'group_by' => 'PMD_type' )), |
|
355 | - $transaction, |
|
356 | - $scope |
|
357 | - ); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * Returns the payment method used for the last payment made for a registration. |
|
363 | - * |
|
364 | - * Note: if an offline payment method was selected on the related transaction then this will have no payment methods returned. |
|
365 | - * It will ONLY return a payment method for a PAYMENT recorded against the registration. |
|
366 | - * |
|
367 | - * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the registration. |
|
368 | - * @return EE_Payment|null |
|
369 | - */ |
|
370 | - public function get_last_used_for_registration($registration_or_reg_id) |
|
371 | - { |
|
372 | - $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
373 | - |
|
374 | - $query_params = array( |
|
375 | - 0 => array( |
|
376 | - 'Payment.Registration.REG_ID' => $registration_id, |
|
377 | - ), |
|
378 | - 'order_by' => array( 'Payment.PAY_ID' => 'DESC' ) |
|
379 | - ); |
|
380 | - return $this->get_one($query_params); |
|
381 | - } |
|
23 | + const scope_cart = 'CART'; |
|
24 | + |
|
25 | + const scope_admin = 'ADMIN'; |
|
26 | + |
|
27 | + const scope_api = 'API'; |
|
28 | + |
|
29 | + /** |
|
30 | + * |
|
31 | + * @type EEM_Payment_Method |
|
32 | + */ |
|
33 | + protected static $_instance = null; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * private constructor to prevent direct creation |
|
39 | + * @Constructor |
|
40 | + * @access protected |
|
41 | + * @return EEM_Payment_Method |
|
42 | + */ |
|
43 | + protected function __construct($timezone = null) |
|
44 | + { |
|
45 | + $this->singlular_item = __('Payment Method', 'event_espresso'); |
|
46 | + $this->plural_item = __('Payment Methods', 'event_espresso'); |
|
47 | + $this->_tables = array( 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID') ); |
|
48 | + $this->_fields = array( |
|
49 | + 'Payment_Method' => array( |
|
50 | + 'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')), |
|
51 | + 'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), false, 'Admin_Only'), |
|
52 | + 'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), false), |
|
53 | + 'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), false, ''), |
|
54 | + 'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), true), |
|
55 | + 'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), true), |
|
56 | + 'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), false), |
|
57 | + 'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), false, 0), |
|
58 | + 'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), false, false), |
|
59 | + 'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), false), |
|
60 | + 'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), false, false), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), true, ''), |
|
61 | + 'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), false, array()), // possible values currently are 'CART','ADMIN','API' |
|
62 | + ) ); |
|
63 | + $this->_model_relations = array( |
|
64 | + 'Payment' => new EE_Has_Many_Relation(), |
|
65 | + 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
66 | + 'Transaction' => new EE_Has_Many_Relation(), |
|
67 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
68 | + ); |
|
69 | + parent::__construct($timezone); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * Gets one by the slug provided |
|
76 | + * @param string $slug |
|
77 | + * @return EE_Payment_Method |
|
78 | + */ |
|
79 | + public function get_one_by_slug($slug) |
|
80 | + { |
|
81 | + return $this->get_one(array( array( 'PMD_slug' => $slug ) )); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Gets all the acceptable scopes for payment methods. |
|
88 | + * Keys are their names as store din the DB, and values are nice names for displaying them |
|
89 | + * @return array |
|
90 | + */ |
|
91 | + public function scopes() |
|
92 | + { |
|
93 | + return apply_filters( |
|
94 | + 'FHEE__EEM_Payment_Method__scopes', |
|
95 | + array( |
|
96 | + self::scope_cart => __("Front-end Registration Page", 'event_espresso'), |
|
97 | + self::scope_admin => __("Admin Registration Page (no online processing)", 'event_espresso') |
|
98 | + ) |
|
99 | + ); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * Determines if this is an valid scope |
|
106 | + * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
|
107 | + * @return boolean |
|
108 | + */ |
|
109 | + public function is_valid_scope($scope) |
|
110 | + { |
|
111 | + $scopes = $this->scopes(); |
|
112 | + if (isset($scopes[ $scope ])) { |
|
113 | + return true; |
|
114 | + } else { |
|
115 | + return false; |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Gets all active payment methods |
|
123 | + * @param string $scope one of |
|
124 | + * @param array $query_params |
|
125 | + * @throws EE_Error |
|
126 | + * @return EE_Payment_Method[] |
|
127 | + */ |
|
128 | + public function get_all_active($scope = null, $query_params = array()) |
|
129 | + { |
|
130 | + if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
131 | + $query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' ); |
|
132 | + } |
|
133 | + return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Counts all active gateways in the specified scope |
|
138 | + * @param string $scope one of EEM_Payment_Method::scope_* |
|
139 | + * @param array $query_params |
|
140 | + * @return int |
|
141 | + */ |
|
142 | + public function count_active($scope = null, $query_params = array()) |
|
143 | + { |
|
144 | + return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
149 | + * argument to get all active for a given scope |
|
150 | + * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
151 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
152 | + * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
153 | + * @throws EE_Error |
|
154 | + */ |
|
155 | + protected function _get_query_params_for_all_active($scope = null, $query_params = array()) |
|
156 | + { |
|
157 | + if ($scope) { |
|
158 | + if ($this->is_valid_scope($scope)) { |
|
159 | + return array_replace_recursive(array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params); |
|
160 | + } else { |
|
161 | + throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope)); |
|
162 | + } |
|
163 | + } else { |
|
164 | + $acceptable_scopes = array(); |
|
165 | + $count = 0; |
|
166 | + foreach ($this->scopes() as $scope_name => $desc) { |
|
167 | + $count++; |
|
168 | + $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' ); |
|
169 | + } |
|
170 | + return array_replace_recursive(array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params); |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
176 | + * argument to get all active for a given scope |
|
177 | + * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
178 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
179 | + * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
180 | + * @throws EE_Error |
|
181 | + */ |
|
182 | + public function get_query_params_for_all_active($scope = null, $query_params = array()) |
|
183 | + { |
|
184 | + return $this->_get_query_params_for_all_active($scope, $query_params); |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Gets one active payment method. see @get_all_active for documentation |
|
190 | + * @param string $scope |
|
191 | + * @param array $query_params |
|
192 | + * @return EE_Payment_Method |
|
193 | + */ |
|
194 | + public function get_one_active($scope = null, $query_params = array()) |
|
195 | + { |
|
196 | + return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Gets one payment method of that type, regardless of whether its active or not |
|
203 | + * @param string $type |
|
204 | + * @return EE_Payment_Method |
|
205 | + */ |
|
206 | + public function get_one_of_type($type) |
|
207 | + { |
|
208 | + return $this->get_one(array( array( 'PMD_type' => $type ) )); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * Overrides parent ot also check by the slug |
|
215 | + * @see EEM_Base::ensure_is_obj() |
|
216 | + * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
217 | + * @param boolean $ensure_is_in_db |
|
218 | + * @return EE_Payment_Method |
|
219 | + * @throws EE_Error |
|
220 | + */ |
|
221 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false) |
|
222 | + { |
|
223 | + // first: check if it's a slug |
|
224 | + if (is_string($base_class_obj_or_id)) { |
|
225 | + $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
226 | + if ($obj) { |
|
227 | + return $obj; |
|
228 | + } |
|
229 | + } |
|
230 | + // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
|
231 | + try { |
|
232 | + return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
233 | + } catch (EE_Error $e) { |
|
234 | + // handle it outside the catch |
|
235 | + } |
|
236 | + throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id)); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * Gets the ID of this object, or if its a string finds the object's id |
|
243 | + * associated with that slug |
|
244 | + * @param mixed $base_obj_or_id_or_slug |
|
245 | + * @return int |
|
246 | + */ |
|
247 | + public function ensure_is_ID($base_obj_or_id_or_slug) |
|
248 | + { |
|
249 | + if (is_string($base_obj_or_id_or_slug)) { |
|
250 | + // assume it's a slug |
|
251 | + $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
252 | + } |
|
253 | + return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default. |
|
260 | + * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart |
|
261 | + */ |
|
262 | + public function verify_button_urls($payment_methods = null) |
|
263 | + { |
|
264 | + $payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
265 | + foreach ($payment_methods as $payment_method) { |
|
266 | + try { |
|
267 | + // If there is really no button URL at all, or if the button URLs still point to decaf folder even |
|
268 | + // though this is a caffeinated install, reset it to the default. |
|
269 | + $current_button_url = $payment_method->button_url(); |
|
270 | + if (empty($current_button_url) |
|
271 | + || ( |
|
272 | + strpos($current_button_url, 'decaf') !== false |
|
273 | + && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false |
|
274 | + ) |
|
275 | + ) { |
|
276 | + $payment_method->save( |
|
277 | + [ |
|
278 | + 'PMD_button_url' => $payment_method->type_obj()->default_button_url() |
|
279 | + ] |
|
280 | + ); |
|
281 | + } |
|
282 | + } catch (EE_Error $e) { |
|
283 | + $payment_method->set_active(false); |
|
284 | + } |
|
285 | + } |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
292 | + * but also verifies the payment method type of each is a usable object. If not, |
|
293 | + * deactivate it, sets a notification, and deactivates it |
|
294 | + * |
|
295 | + * @param array $rows |
|
296 | + * @return EE_Payment_Method[] |
|
297 | + * @throws InvalidDataTypeException |
|
298 | + */ |
|
299 | + protected function _create_objects($rows = array()) |
|
300 | + { |
|
301 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
302 | + $payment_methods = parent::_create_objects($rows); |
|
303 | + /* @var $payment_methods EE_Payment_Method[] */ |
|
304 | + $usable_payment_methods = array(); |
|
305 | + foreach ($payment_methods as $key => $payment_method) { |
|
306 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
307 | + $usable_payment_methods[ $key ] = $payment_method; |
|
308 | + // some payment methods enqueue their scripts in EE_PMT_*::__construct |
|
309 | + // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
|
310 | + // its scripts). but for backwards-compat we should continue to do that |
|
311 | + $payment_method->type_obj(); |
|
312 | + } elseif ($payment_method->active()) { |
|
313 | + // only deactivate and notify the admin if the payment is active somewhere |
|
314 | + $payment_method->deactivate(); |
|
315 | + $payment_method->save(); |
|
316 | + do_action( |
|
317 | + 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
318 | + $payment_method |
|
319 | + ); |
|
320 | + new PersistentAdminNotice( |
|
321 | + 'auto-deactivated-' . $payment_method->type(), |
|
322 | + sprintf( |
|
323 | + __( |
|
324 | + 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
325 | + 'event_espresso' |
|
326 | + ), |
|
327 | + $payment_method->admin_name(), |
|
328 | + '<br />', |
|
329 | + '<a href="' . admin_url('plugins.php') . '">', |
|
330 | + '</a>' |
|
331 | + ), |
|
332 | + true |
|
333 | + ); |
|
334 | + } |
|
335 | + } |
|
336 | + return $usable_payment_methods; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * Gets all the payment methods which can be used for transaction |
|
343 | + * (according to the relations between payment methods and events, and |
|
344 | + * the currencies used for the transaction and their relation to payment methods) |
|
345 | + * @param EE_Transaction $transaction |
|
346 | + * @param string $scope @see EEM_Payment_Method::get_all_for_events |
|
347 | + * @return EE_Payment_Method[] |
|
348 | + */ |
|
349 | + public function get_all_for_transaction($transaction, $scope) |
|
350 | + { |
|
351 | + // give addons a chance to override what payment methods are chosen based on the transaction |
|
352 | + return apply_filters( |
|
353 | + 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
|
354 | + $this->get_all_active($scope, array( 'group_by' => 'PMD_type' )), |
|
355 | + $transaction, |
|
356 | + $scope |
|
357 | + ); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * Returns the payment method used for the last payment made for a registration. |
|
363 | + * |
|
364 | + * Note: if an offline payment method was selected on the related transaction then this will have no payment methods returned. |
|
365 | + * It will ONLY return a payment method for a PAYMENT recorded against the registration. |
|
366 | + * |
|
367 | + * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the registration. |
|
368 | + * @return EE_Payment|null |
|
369 | + */ |
|
370 | + public function get_last_used_for_registration($registration_or_reg_id) |
|
371 | + { |
|
372 | + $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
373 | + |
|
374 | + $query_params = array( |
|
375 | + 0 => array( |
|
376 | + 'Payment.Registration.REG_ID' => $registration_id, |
|
377 | + ), |
|
378 | + 'order_by' => array( 'Payment.PAY_ID' => 'DESC' ) |
|
379 | + ); |
|
380 | + return $this->get_one($query_params); |
|
381 | + } |
|
382 | 382 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * instantiate a new price object with blank/empty properties |
67 | 67 | * |
68 | 68 | * @access public |
69 | - * @return mixed array on success, FALSE on fail |
|
69 | + * @return EE_Base_Class|null array on success, FALSE on fail |
|
70 | 70 | */ |
71 | 71 | public function get_new_price() |
72 | 72 | { |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @access public |
98 | 98 | * @param int $EVT_ID |
99 | - * @return array on success |
|
99 | + * @return EE_Base_Class[] on success |
|
100 | 100 | */ |
101 | 101 | public function get_all_event_prices($EVT_ID = 0) |
102 | 102 | { |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | * @access public |
224 | 224 | * @param \EE_Price $price_a |
225 | 225 | * @param \EE_Price $price_b |
226 | - * @return bool false on fail |
|
226 | + * @return integer false on fail |
|
227 | 227 | */ |
228 | 228 | public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b) |
229 | 229 | { |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @access public |
242 | 242 | * @param \EE_Price $price_a |
243 | 243 | * @param \EE_Price $price_b |
244 | - * @return bool false on fail |
|
244 | + * @return integer false on fail |
|
245 | 245 | */ |
246 | 246 | public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b) |
247 | 247 | { |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * |
259 | 259 | * @access public |
260 | 260 | * @param int $type - PRT_ID |
261 | - * @return boolean false on fail |
|
261 | + * @return EE_Base_Class[] false on fail |
|
262 | 262 | */ |
263 | 263 | public function get_all_prices_that_are_type($type = 0) |
264 | 264 | { |
@@ -10,279 +10,279 @@ |
||
10 | 10 | class EEM_Price extends EEM_Soft_Delete_Base |
11 | 11 | { |
12 | 12 | |
13 | - // private instance of the EEM_Price object |
|
14 | - protected static $_instance = null; |
|
15 | - |
|
16 | - |
|
17 | - |
|
18 | - /** |
|
19 | - * private constructor to prevent direct creation |
|
20 | - * @Constructor |
|
21 | - * @access protected |
|
22 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
23 | - * @return EEM_Price |
|
24 | - */ |
|
25 | - protected function __construct($timezone) |
|
26 | - { |
|
27 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
28 | - $this->singular_item = __('Price', 'event_espresso'); |
|
29 | - $this->plural_item = __('Prices', 'event_espresso'); |
|
30 | - |
|
31 | - $this->_tables = array( |
|
32 | - 'Price'=>new EE_Primary_Table('esp_price', 'PRC_ID') |
|
33 | - ); |
|
34 | - $this->_fields = array( |
|
35 | - 'Price'=> array( |
|
36 | - 'PRC_ID'=>new EE_Primary_Key_Int_Field('PRC_ID', 'Price ID'), |
|
37 | - 'PRT_ID'=>new EE_Foreign_Key_Int_Field('PRT_ID', 'Price type Id', false, null, 'Price_Type'), |
|
38 | - 'PRC_amount'=>new EE_Money_Field('PRC_amount', 'Price Amount', false, 0), |
|
39 | - 'PRC_name'=>new EE_Plain_Text_Field('PRC_name', 'Name of Price', false, ''), |
|
40 | - 'PRC_desc'=>new EE_Post_Content_Field('PRC_desc', 'Price Description', false, ''), |
|
41 | - 'PRC_is_default'=>new EE_Boolean_Field('PRC_is_default', 'Flag indicating whether price is a default price', false, false), |
|
42 | - 'PRC_overrides'=>new EE_Integer_Field('PRC_overrides', 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', true, 0), |
|
43 | - 'PRC_order'=>new EE_Integer_Field('PRC_order', 'Order of Application of Price (lower numbers apply first?)', false, 1), |
|
44 | - 'PRC_deleted'=>new EE_Trashed_Flag_Field('PRC_deleted', 'Flag Indicating if this has been deleted or not', false, false), |
|
45 | - 'PRC_parent' => new EE_Integer_Field('PRC_parent', __('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), true, 0), |
|
46 | - 'PRC_wp_user' => new EE_WP_User_Field('PRC_wp_user', __('Price Creator ID', 'event_espresso'), false), |
|
47 | - ) |
|
48 | - ); |
|
49 | - $this->_model_relations = array( |
|
50 | - 'Ticket'=>new EE_HABTM_Relation('Ticket_Price'), |
|
51 | - 'Price_Type'=>new EE_Belongs_To_Relation(), |
|
52 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
53 | - ); |
|
54 | - // this model is generally available for reading |
|
55 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event'); |
|
56 | - // account for default tickets in the caps |
|
57 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
58 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
59 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
60 | - parent::__construct($timezone); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * instantiate a new price object with blank/empty properties |
|
67 | - * |
|
68 | - * @access public |
|
69 | - * @return mixed array on success, FALSE on fail |
|
70 | - */ |
|
71 | - public function get_new_price() |
|
72 | - { |
|
73 | - return $this->create_default_object(); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * retrieve ALL prices from db |
|
82 | - * |
|
83 | - * @access public |
|
84 | - * @return EE_PRice[] |
|
85 | - */ |
|
86 | - public function get_all_prices() |
|
87 | - { |
|
88 | - // retrieve all prices |
|
89 | - return $this->get_all(array('order_by'=>array('PRC_amount'=>'ASC'))); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * retrieve all active prices for a particular event |
|
96 | - * |
|
97 | - * @access public |
|
98 | - * @param int $EVT_ID |
|
99 | - * @return array on success |
|
100 | - */ |
|
101 | - public function get_all_event_prices($EVT_ID = 0) |
|
102 | - { |
|
103 | - return $this->get_all(array( |
|
104 | - array( |
|
105 | - 'EVT_ID'=>$EVT_ID, |
|
106 | - 'Price_Type.PBT_ID'=>array('!=', EEM_Price_Type::base_type_tax) |
|
107 | - ), |
|
108 | - 'order_by'=>$this->_order_by_array_for_get_all_method() |
|
109 | - )); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event |
|
115 | - * |
|
116 | - * @access public |
|
117 | - * @param boolean $count return count |
|
118 | - * @return array on success |
|
119 | - * @return boolean false on fail |
|
120 | - */ |
|
121 | - public function get_all_default_prices($count = false) |
|
122 | - { |
|
123 | - $_where = array( |
|
124 | - 'Price_Type.PBT_ID'=>array('!=',4), |
|
125 | - 'PRC_deleted' => 0, |
|
126 | - 'PRC_is_default' => 1 |
|
127 | - ); |
|
128 | - $_query_params = array( |
|
129 | - $_where, |
|
130 | - 'order_by'=>$this->_order_by_array_for_get_all_method() |
|
131 | - ); |
|
132 | - return $count ? $this->count(array($_where)) : $this->get_all($_query_params); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * retrieve all prices that are taxes |
|
146 | - * |
|
147 | - * @access public |
|
148 | - * @return array on success |
|
149 | - * @return array top-level keys are the price's order and their values are an array, |
|
150 | - * next-level keys are the price's ID, and their values are EE_Price objects |
|
151 | - */ |
|
152 | - public function get_all_prices_that_are_taxes() |
|
153 | - { |
|
154 | - $taxes = array(); |
|
155 | - $all_taxes = $this->get_all(array( |
|
156 | - array( 'Price_Type.PBT_ID'=> EEM_Price_Type::base_type_tax ), |
|
157 | - 'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' ) |
|
158 | - )); |
|
159 | - foreach ($all_taxes as $tax) { |
|
160 | - if ($tax instanceof EE_Price) { |
|
161 | - $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
162 | - } |
|
163 | - } |
|
164 | - return $taxes; |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * retrieve all prices for an ticket plus default global prices, but not taxes |
|
173 | - * |
|
174 | - * @access public |
|
175 | - * @param int $TKT_ID the id of the event. If not included then we assume that this is a new ticket. |
|
176 | - * @return boolean false on fail |
|
177 | - */ |
|
178 | - public function get_all_ticket_prices_for_admin($TKT_ID = 0) |
|
179 | - { |
|
180 | - $array_of_price_objects = array(); |
|
181 | - if (empty($TKT_ID)) { |
|
182 | - // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active |
|
183 | - // return that list |
|
184 | - $default_prices = $this->get_all_default_prices(); |
|
185 | - |
|
186 | - if ($default_prices) { |
|
187 | - foreach ($default_prices as $price) { |
|
188 | - if ($price instanceof EE_Price) { |
|
189 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
190 | - } |
|
191 | - } |
|
192 | - return $array_of_price_objects; |
|
193 | - } else { |
|
194 | - return array(); |
|
195 | - } |
|
196 | - } else { |
|
197 | - $ticket_prices = $this->get_all(array( |
|
198 | - array( |
|
199 | - 'TKT_ID'=>$TKT_ID, |
|
200 | - 'PRC_deleted' => 0 |
|
201 | - ), |
|
202 | - 'order_by'=> array('PRC_order' => 'ASC') |
|
203 | - )); |
|
204 | - } |
|
205 | - |
|
206 | - if (!empty($ticket_prices)) { |
|
207 | - foreach ($ticket_prices as $price) { |
|
208 | - if ($price instanceof EE_Price) { |
|
209 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
210 | - } |
|
211 | - } |
|
212 | - return $array_of_price_objects; |
|
213 | - } else { |
|
214 | - return false; |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * _sort_event_prices_by_type |
|
222 | - * |
|
223 | - * @access public |
|
224 | - * @param \EE_Price $price_a |
|
225 | - * @param \EE_Price $price_b |
|
226 | - * @return bool false on fail |
|
227 | - */ |
|
228 | - public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b) |
|
229 | - { |
|
230 | - if ($price_a->type_obj()->order() == $price_b->type_obj()->order()) { |
|
231 | - return $this->_sort_event_prices_by_order($price_a, $price_b); |
|
232 | - } |
|
233 | - return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1; |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * _sort_event_prices_by_order |
|
240 | - * |
|
241 | - * @access public |
|
242 | - * @param \EE_Price $price_a |
|
243 | - * @param \EE_Price $price_b |
|
244 | - * @return bool false on fail |
|
245 | - */ |
|
246 | - public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b) |
|
247 | - { |
|
248 | - if ($price_a->order() == $price_b->order()) { |
|
249 | - return 0; |
|
250 | - } |
|
251 | - return $price_a->order() < $price_b->order() ? -1 : 1; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * get all prices of a specific type |
|
258 | - * |
|
259 | - * @access public |
|
260 | - * @param int $type - PRT_ID |
|
261 | - * @return boolean false on fail |
|
262 | - */ |
|
263 | - public function get_all_prices_that_are_type($type = 0) |
|
264 | - { |
|
265 | - return $this->get_all(array( |
|
266 | - array( |
|
267 | - 'PRT_ID'=>$type |
|
268 | - ), |
|
269 | - 'order_by'=>$this->_order_by_array_for_get_all_method() |
|
270 | - )); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * Returns an array of the normal 'order_by' query parameter provided to the get_all query. |
|
277 | - * Of course you don't have to use it, but this is the order we usually want to sort prices by |
|
278 | - * @return array which can be used like so: $this->get_all(array(array(...where stuff...),'order_by'=>$this->_order_by_array_for_get_all_method())); |
|
279 | - */ |
|
280 | - public function _order_by_array_for_get_all_method() |
|
281 | - { |
|
282 | - return array( |
|
283 | - 'PRC_order'=>'ASC', |
|
284 | - 'Price_Type.PRT_order'=>'ASC', |
|
285 | - 'PRC_ID'=>'ASC' |
|
286 | - ); |
|
287 | - } |
|
13 | + // private instance of the EEM_Price object |
|
14 | + protected static $_instance = null; |
|
15 | + |
|
16 | + |
|
17 | + |
|
18 | + /** |
|
19 | + * private constructor to prevent direct creation |
|
20 | + * @Constructor |
|
21 | + * @access protected |
|
22 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
23 | + * @return EEM_Price |
|
24 | + */ |
|
25 | + protected function __construct($timezone) |
|
26 | + { |
|
27 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
28 | + $this->singular_item = __('Price', 'event_espresso'); |
|
29 | + $this->plural_item = __('Prices', 'event_espresso'); |
|
30 | + |
|
31 | + $this->_tables = array( |
|
32 | + 'Price'=>new EE_Primary_Table('esp_price', 'PRC_ID') |
|
33 | + ); |
|
34 | + $this->_fields = array( |
|
35 | + 'Price'=> array( |
|
36 | + 'PRC_ID'=>new EE_Primary_Key_Int_Field('PRC_ID', 'Price ID'), |
|
37 | + 'PRT_ID'=>new EE_Foreign_Key_Int_Field('PRT_ID', 'Price type Id', false, null, 'Price_Type'), |
|
38 | + 'PRC_amount'=>new EE_Money_Field('PRC_amount', 'Price Amount', false, 0), |
|
39 | + 'PRC_name'=>new EE_Plain_Text_Field('PRC_name', 'Name of Price', false, ''), |
|
40 | + 'PRC_desc'=>new EE_Post_Content_Field('PRC_desc', 'Price Description', false, ''), |
|
41 | + 'PRC_is_default'=>new EE_Boolean_Field('PRC_is_default', 'Flag indicating whether price is a default price', false, false), |
|
42 | + 'PRC_overrides'=>new EE_Integer_Field('PRC_overrides', 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', true, 0), |
|
43 | + 'PRC_order'=>new EE_Integer_Field('PRC_order', 'Order of Application of Price (lower numbers apply first?)', false, 1), |
|
44 | + 'PRC_deleted'=>new EE_Trashed_Flag_Field('PRC_deleted', 'Flag Indicating if this has been deleted or not', false, false), |
|
45 | + 'PRC_parent' => new EE_Integer_Field('PRC_parent', __('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), true, 0), |
|
46 | + 'PRC_wp_user' => new EE_WP_User_Field('PRC_wp_user', __('Price Creator ID', 'event_espresso'), false), |
|
47 | + ) |
|
48 | + ); |
|
49 | + $this->_model_relations = array( |
|
50 | + 'Ticket'=>new EE_HABTM_Relation('Ticket_Price'), |
|
51 | + 'Price_Type'=>new EE_Belongs_To_Relation(), |
|
52 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
53 | + ); |
|
54 | + // this model is generally available for reading |
|
55 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event'); |
|
56 | + // account for default tickets in the caps |
|
57 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
58 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
59 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
60 | + parent::__construct($timezone); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * instantiate a new price object with blank/empty properties |
|
67 | + * |
|
68 | + * @access public |
|
69 | + * @return mixed array on success, FALSE on fail |
|
70 | + */ |
|
71 | + public function get_new_price() |
|
72 | + { |
|
73 | + return $this->create_default_object(); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * retrieve ALL prices from db |
|
82 | + * |
|
83 | + * @access public |
|
84 | + * @return EE_PRice[] |
|
85 | + */ |
|
86 | + public function get_all_prices() |
|
87 | + { |
|
88 | + // retrieve all prices |
|
89 | + return $this->get_all(array('order_by'=>array('PRC_amount'=>'ASC'))); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * retrieve all active prices for a particular event |
|
96 | + * |
|
97 | + * @access public |
|
98 | + * @param int $EVT_ID |
|
99 | + * @return array on success |
|
100 | + */ |
|
101 | + public function get_all_event_prices($EVT_ID = 0) |
|
102 | + { |
|
103 | + return $this->get_all(array( |
|
104 | + array( |
|
105 | + 'EVT_ID'=>$EVT_ID, |
|
106 | + 'Price_Type.PBT_ID'=>array('!=', EEM_Price_Type::base_type_tax) |
|
107 | + ), |
|
108 | + 'order_by'=>$this->_order_by_array_for_get_all_method() |
|
109 | + )); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event |
|
115 | + * |
|
116 | + * @access public |
|
117 | + * @param boolean $count return count |
|
118 | + * @return array on success |
|
119 | + * @return boolean false on fail |
|
120 | + */ |
|
121 | + public function get_all_default_prices($count = false) |
|
122 | + { |
|
123 | + $_where = array( |
|
124 | + 'Price_Type.PBT_ID'=>array('!=',4), |
|
125 | + 'PRC_deleted' => 0, |
|
126 | + 'PRC_is_default' => 1 |
|
127 | + ); |
|
128 | + $_query_params = array( |
|
129 | + $_where, |
|
130 | + 'order_by'=>$this->_order_by_array_for_get_all_method() |
|
131 | + ); |
|
132 | + return $count ? $this->count(array($_where)) : $this->get_all($_query_params); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * retrieve all prices that are taxes |
|
146 | + * |
|
147 | + * @access public |
|
148 | + * @return array on success |
|
149 | + * @return array top-level keys are the price's order and their values are an array, |
|
150 | + * next-level keys are the price's ID, and their values are EE_Price objects |
|
151 | + */ |
|
152 | + public function get_all_prices_that_are_taxes() |
|
153 | + { |
|
154 | + $taxes = array(); |
|
155 | + $all_taxes = $this->get_all(array( |
|
156 | + array( 'Price_Type.PBT_ID'=> EEM_Price_Type::base_type_tax ), |
|
157 | + 'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' ) |
|
158 | + )); |
|
159 | + foreach ($all_taxes as $tax) { |
|
160 | + if ($tax instanceof EE_Price) { |
|
161 | + $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
162 | + } |
|
163 | + } |
|
164 | + return $taxes; |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * retrieve all prices for an ticket plus default global prices, but not taxes |
|
173 | + * |
|
174 | + * @access public |
|
175 | + * @param int $TKT_ID the id of the event. If not included then we assume that this is a new ticket. |
|
176 | + * @return boolean false on fail |
|
177 | + */ |
|
178 | + public function get_all_ticket_prices_for_admin($TKT_ID = 0) |
|
179 | + { |
|
180 | + $array_of_price_objects = array(); |
|
181 | + if (empty($TKT_ID)) { |
|
182 | + // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active |
|
183 | + // return that list |
|
184 | + $default_prices = $this->get_all_default_prices(); |
|
185 | + |
|
186 | + if ($default_prices) { |
|
187 | + foreach ($default_prices as $price) { |
|
188 | + if ($price instanceof EE_Price) { |
|
189 | + $array_of_price_objects[ $price->type() ][] = $price; |
|
190 | + } |
|
191 | + } |
|
192 | + return $array_of_price_objects; |
|
193 | + } else { |
|
194 | + return array(); |
|
195 | + } |
|
196 | + } else { |
|
197 | + $ticket_prices = $this->get_all(array( |
|
198 | + array( |
|
199 | + 'TKT_ID'=>$TKT_ID, |
|
200 | + 'PRC_deleted' => 0 |
|
201 | + ), |
|
202 | + 'order_by'=> array('PRC_order' => 'ASC') |
|
203 | + )); |
|
204 | + } |
|
205 | + |
|
206 | + if (!empty($ticket_prices)) { |
|
207 | + foreach ($ticket_prices as $price) { |
|
208 | + if ($price instanceof EE_Price) { |
|
209 | + $array_of_price_objects[ $price->type() ][] = $price; |
|
210 | + } |
|
211 | + } |
|
212 | + return $array_of_price_objects; |
|
213 | + } else { |
|
214 | + return false; |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * _sort_event_prices_by_type |
|
222 | + * |
|
223 | + * @access public |
|
224 | + * @param \EE_Price $price_a |
|
225 | + * @param \EE_Price $price_b |
|
226 | + * @return bool false on fail |
|
227 | + */ |
|
228 | + public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b) |
|
229 | + { |
|
230 | + if ($price_a->type_obj()->order() == $price_b->type_obj()->order()) { |
|
231 | + return $this->_sort_event_prices_by_order($price_a, $price_b); |
|
232 | + } |
|
233 | + return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1; |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * _sort_event_prices_by_order |
|
240 | + * |
|
241 | + * @access public |
|
242 | + * @param \EE_Price $price_a |
|
243 | + * @param \EE_Price $price_b |
|
244 | + * @return bool false on fail |
|
245 | + */ |
|
246 | + public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b) |
|
247 | + { |
|
248 | + if ($price_a->order() == $price_b->order()) { |
|
249 | + return 0; |
|
250 | + } |
|
251 | + return $price_a->order() < $price_b->order() ? -1 : 1; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * get all prices of a specific type |
|
258 | + * |
|
259 | + * @access public |
|
260 | + * @param int $type - PRT_ID |
|
261 | + * @return boolean false on fail |
|
262 | + */ |
|
263 | + public function get_all_prices_that_are_type($type = 0) |
|
264 | + { |
|
265 | + return $this->get_all(array( |
|
266 | + array( |
|
267 | + 'PRT_ID'=>$type |
|
268 | + ), |
|
269 | + 'order_by'=>$this->_order_by_array_for_get_all_method() |
|
270 | + )); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * Returns an array of the normal 'order_by' query parameter provided to the get_all query. |
|
277 | + * Of course you don't have to use it, but this is the order we usually want to sort prices by |
|
278 | + * @return array which can be used like so: $this->get_all(array(array(...where stuff...),'order_by'=>$this->_order_by_array_for_get_all_method())); |
|
279 | + */ |
|
280 | + public function _order_by_array_for_get_all_method() |
|
281 | + { |
|
282 | + return array( |
|
283 | + 'PRC_order'=>'ASC', |
|
284 | + 'Price_Type.PRT_order'=>'ASC', |
|
285 | + 'PRC_ID'=>'ASC' |
|
286 | + ); |
|
287 | + } |
|
288 | 288 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | protected function __construct($timezone) |
26 | 26 | { |
27 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
27 | + require_once(EE_MODELS.'EEM_Price_Type.model.php'); |
|
28 | 28 | $this->singular_item = __('Price', 'event_espresso'); |
29 | 29 | $this->plural_item = __('Prices', 'event_espresso'); |
30 | 30 | |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | 'WP_User' => new EE_Belongs_To_Relation(), |
53 | 53 | ); |
54 | 54 | // this model is generally available for reading |
55 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event'); |
|
55 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event'); |
|
56 | 56 | // account for default tickets in the caps |
57 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
58 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
59 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
57 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
58 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
59 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
60 | 60 | parent::__construct($timezone); |
61 | 61 | } |
62 | 62 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | return $this->get_all(array( |
104 | 104 | array( |
105 | 105 | 'EVT_ID'=>$EVT_ID, |
106 | - 'Price_Type.PBT_ID'=>array('!=', EEM_Price_Type::base_type_tax) |
|
106 | + 'Price_Type.PBT_ID'=>array('!=', EEM_Price_Type::base_type_tax) |
|
107 | 107 | ), |
108 | 108 | 'order_by'=>$this->_order_by_array_for_get_all_method() |
109 | 109 | )); |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | public function get_all_default_prices($count = false) |
122 | 122 | { |
123 | 123 | $_where = array( |
124 | - 'Price_Type.PBT_ID'=>array('!=',4), |
|
124 | + 'Price_Type.PBT_ID'=>array('!=', 4), |
|
125 | 125 | 'PRC_deleted' => 0, |
126 | 126 | 'PRC_is_default' => 1 |
127 | 127 | ); |
@@ -153,12 +153,12 @@ discard block |
||
153 | 153 | { |
154 | 154 | $taxes = array(); |
155 | 155 | $all_taxes = $this->get_all(array( |
156 | - array( 'Price_Type.PBT_ID'=> EEM_Price_Type::base_type_tax ), |
|
157 | - 'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' ) |
|
156 | + array('Price_Type.PBT_ID'=> EEM_Price_Type::base_type_tax), |
|
157 | + 'order_by' => array('Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC') |
|
158 | 158 | )); |
159 | 159 | foreach ($all_taxes as $tax) { |
160 | 160 | if ($tax instanceof EE_Price) { |
161 | - $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
161 | + $taxes[$tax->order()][$tax->ID()] = $tax; |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | return $taxes; |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | if ($default_prices) { |
187 | 187 | foreach ($default_prices as $price) { |
188 | 188 | if ($price instanceof EE_Price) { |
189 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
189 | + $array_of_price_objects[$price->type()][] = $price; |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | return $array_of_price_objects; |
@@ -203,10 +203,10 @@ discard block |
||
203 | 203 | )); |
204 | 204 | } |
205 | 205 | |
206 | - if (!empty($ticket_prices)) { |
|
206 | + if ( ! empty($ticket_prices)) { |
|
207 | 207 | foreach ($ticket_prices as $price) { |
208 | 208 | if ($price instanceof EE_Price) { |
209 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
209 | + $array_of_price_objects[$price->type()][] = $price; |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | return $array_of_price_objects; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * return an array of Base types. Keys are INTs which are used in the database, |
29 | 29 | * values are text-representations of the base type. |
30 | - * @return array |
|
30 | + * @return integer |
|
31 | 31 | */ |
32 | 32 | public function get_base_types() |
33 | 33 | { |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * instantiate a new price type object with blank/empty properties |
108 | 108 | * |
109 | 109 | * @access public |
110 | - * @return mixed array on success, FALSE on fail |
|
110 | + * @return EE_Price_Type array on success, FALSE on fail |
|
111 | 111 | */ |
112 | 112 | public function get_new_price_type() |
113 | 113 | { |
@@ -11,108 +11,108 @@ discard block |
||
11 | 11 | class EEM_Price_Type extends EEM_Soft_Delete_Base |
12 | 12 | { |
13 | 13 | |
14 | - // private instance of the Price Type object |
|
15 | - protected static $_instance = null; |
|
16 | - // An array of the price type objects |
|
17 | - public $type = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * Price Base types |
|
21 | - * |
|
22 | - * @access private |
|
23 | - * @var int |
|
24 | - */ |
|
25 | - public $base_types = null; |
|
26 | - |
|
27 | - /** |
|
28 | - * return an array of Base types. Keys are INTs which are used in the database, |
|
29 | - * values are text-representations of the base type. |
|
30 | - * @return array |
|
31 | - */ |
|
32 | - public function get_base_types() |
|
33 | - { |
|
34 | - return $this->base_types; |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Gets the name of the base |
|
39 | - * @param type $base_type_int |
|
40 | - * @return type |
|
41 | - */ |
|
42 | - public function get_base_type_name($base_type_int) |
|
43 | - { |
|
44 | - return $this->base_types[ $base_type_int ]; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * constants for price base types. In the DB, we decided to store the price base type |
|
49 | - * as an integer. So, to avoid just having magic numbers everwhere (eg, querying for |
|
50 | - * all price types with PBT_ID = 2), we define these constants, to make code more understandable. |
|
51 | - * So, as an example, to query for all price types that are a tax, we'd do |
|
52 | - * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax))) |
|
53 | - * instead of |
|
54 | - * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2))) |
|
55 | - * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever |
|
56 | - * change, we can continue to use the constant, by simply change its value. |
|
57 | - */ |
|
58 | - const base_type_base_price = 1; |
|
59 | - const base_type_discount = 2; |
|
60 | - const base_type_surcharge = 3; |
|
61 | - const base_type_tax = 4; |
|
62 | - /** |
|
63 | - * private constructor to prevent direct creation |
|
64 | - * @Constructor |
|
65 | - * @access protected |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - protected function __construct($timezone = null) |
|
69 | - { |
|
70 | - $this->base_types = array( |
|
71 | - EEM_Price_Type::base_type_base_price => __('Price', 'event_espresso'), |
|
72 | - EEM_Price_Type::base_type_discount => __('Discount', 'event_espresso'), |
|
73 | - EEM_Price_Type::base_type_surcharge => __('Surcharge', 'event_espresso'), |
|
74 | - EEM_Price_Type::base_type_tax => __('Tax', 'event_espresso') ); |
|
75 | - $this->singular_item = __('Price Type', 'event_espresso'); |
|
76 | - $this->plural_item = __('Price Types', 'event_espresso'); |
|
77 | - |
|
78 | - $this->_tables = array( |
|
79 | - 'Price_Type'=>new EE_Primary_Table('esp_price_type', 'PRT_ID') |
|
80 | - ); |
|
81 | - $this->_fields = array( |
|
82 | - 'Price_Type'=>array( |
|
83 | - 'PRT_ID'=>new EE_Primary_Key_Int_Field('PRT_ID', __('Price Type ID', 'event_espresso')), |
|
84 | - 'PRT_name'=>new EE_Plain_Text_Field('PRT_name', __('Price Type Name', 'event_espresso'), false, ''), |
|
85 | - 'PBT_ID'=>new EE_Enum_Integer_Field('PBT_ID', __('Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax', 'event_espresso'), false, EEM_Price_Type::base_type_base_price, $this->base_types), |
|
86 | - 'PRT_is_percent'=>new EE_Boolean_Field('PRT_is_percent', __('Flag indicating price is a percentage', 'event_espresso'), false, false), |
|
87 | - 'PRT_order'=>new EE_Integer_Field('PRT_order', __('Order in which price should be applied. ', 'event_espresso'), false, 0), |
|
88 | - 'PRT_deleted'=>new EE_Trashed_Flag_Field('PRT_deleted', __('Flag indicating price type has been trashed', 'event_espresso'), false, false), |
|
89 | - 'PRT_wp_user' => new EE_WP_User_Field('PRT_wp_user', __('Price Type Creator ID', 'event_espresso'), false), |
|
90 | - ) |
|
91 | - ); |
|
92 | - $this->_model_relations = array( |
|
93 | - 'Price'=>new EE_Has_Many_Relation(), |
|
94 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
95 | - ); |
|
96 | - // this model is generally available for reading |
|
97 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
98 | - // all price types are "default" in terms of capability names |
|
99 | - $this->_caps_slug = 'default_price_types'; |
|
100 | - parent::__construct($timezone); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * instantiate a new price type object with blank/empty properties |
|
108 | - * |
|
109 | - * @access public |
|
110 | - * @return mixed array on success, FALSE on fail |
|
111 | - */ |
|
112 | - public function get_new_price_type() |
|
113 | - { |
|
114 | - return EE_Price_Type::new_instance(); |
|
115 | - } |
|
14 | + // private instance of the Price Type object |
|
15 | + protected static $_instance = null; |
|
16 | + // An array of the price type objects |
|
17 | + public $type = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * Price Base types |
|
21 | + * |
|
22 | + * @access private |
|
23 | + * @var int |
|
24 | + */ |
|
25 | + public $base_types = null; |
|
26 | + |
|
27 | + /** |
|
28 | + * return an array of Base types. Keys are INTs which are used in the database, |
|
29 | + * values are text-representations of the base type. |
|
30 | + * @return array |
|
31 | + */ |
|
32 | + public function get_base_types() |
|
33 | + { |
|
34 | + return $this->base_types; |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Gets the name of the base |
|
39 | + * @param type $base_type_int |
|
40 | + * @return type |
|
41 | + */ |
|
42 | + public function get_base_type_name($base_type_int) |
|
43 | + { |
|
44 | + return $this->base_types[ $base_type_int ]; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * constants for price base types. In the DB, we decided to store the price base type |
|
49 | + * as an integer. So, to avoid just having magic numbers everwhere (eg, querying for |
|
50 | + * all price types with PBT_ID = 2), we define these constants, to make code more understandable. |
|
51 | + * So, as an example, to query for all price types that are a tax, we'd do |
|
52 | + * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax))) |
|
53 | + * instead of |
|
54 | + * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2))) |
|
55 | + * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever |
|
56 | + * change, we can continue to use the constant, by simply change its value. |
|
57 | + */ |
|
58 | + const base_type_base_price = 1; |
|
59 | + const base_type_discount = 2; |
|
60 | + const base_type_surcharge = 3; |
|
61 | + const base_type_tax = 4; |
|
62 | + /** |
|
63 | + * private constructor to prevent direct creation |
|
64 | + * @Constructor |
|
65 | + * @access protected |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + protected function __construct($timezone = null) |
|
69 | + { |
|
70 | + $this->base_types = array( |
|
71 | + EEM_Price_Type::base_type_base_price => __('Price', 'event_espresso'), |
|
72 | + EEM_Price_Type::base_type_discount => __('Discount', 'event_espresso'), |
|
73 | + EEM_Price_Type::base_type_surcharge => __('Surcharge', 'event_espresso'), |
|
74 | + EEM_Price_Type::base_type_tax => __('Tax', 'event_espresso') ); |
|
75 | + $this->singular_item = __('Price Type', 'event_espresso'); |
|
76 | + $this->plural_item = __('Price Types', 'event_espresso'); |
|
77 | + |
|
78 | + $this->_tables = array( |
|
79 | + 'Price_Type'=>new EE_Primary_Table('esp_price_type', 'PRT_ID') |
|
80 | + ); |
|
81 | + $this->_fields = array( |
|
82 | + 'Price_Type'=>array( |
|
83 | + 'PRT_ID'=>new EE_Primary_Key_Int_Field('PRT_ID', __('Price Type ID', 'event_espresso')), |
|
84 | + 'PRT_name'=>new EE_Plain_Text_Field('PRT_name', __('Price Type Name', 'event_espresso'), false, ''), |
|
85 | + 'PBT_ID'=>new EE_Enum_Integer_Field('PBT_ID', __('Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax', 'event_espresso'), false, EEM_Price_Type::base_type_base_price, $this->base_types), |
|
86 | + 'PRT_is_percent'=>new EE_Boolean_Field('PRT_is_percent', __('Flag indicating price is a percentage', 'event_espresso'), false, false), |
|
87 | + 'PRT_order'=>new EE_Integer_Field('PRT_order', __('Order in which price should be applied. ', 'event_espresso'), false, 0), |
|
88 | + 'PRT_deleted'=>new EE_Trashed_Flag_Field('PRT_deleted', __('Flag indicating price type has been trashed', 'event_espresso'), false, false), |
|
89 | + 'PRT_wp_user' => new EE_WP_User_Field('PRT_wp_user', __('Price Type Creator ID', 'event_espresso'), false), |
|
90 | + ) |
|
91 | + ); |
|
92 | + $this->_model_relations = array( |
|
93 | + 'Price'=>new EE_Has_Many_Relation(), |
|
94 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
95 | + ); |
|
96 | + // this model is generally available for reading |
|
97 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
98 | + // all price types are "default" in terms of capability names |
|
99 | + $this->_caps_slug = 'default_price_types'; |
|
100 | + parent::__construct($timezone); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * instantiate a new price type object with blank/empty properties |
|
108 | + * |
|
109 | + * @access public |
|
110 | + * @return mixed array on success, FALSE on fail |
|
111 | + */ |
|
112 | + public function get_new_price_type() |
|
113 | + { |
|
114 | + return EE_Price_Type::new_instance(); |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | 118 | |
@@ -131,33 +131,33 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @param type $query_params |
133 | 133 | * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info |
134 | - * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects |
|
135 | - * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
|
134 | + * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects |
|
135 | + * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
|
136 | 136 | * @return boolean |
137 | 137 | */ |
138 | - public function delete_permanently($query_params = array(), $allow_blocking = true) |
|
139 | - { |
|
138 | + public function delete_permanently($query_params = array(), $allow_blocking = true) |
|
139 | + { |
|
140 | 140 | |
141 | - $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params); |
|
142 | - $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types); |
|
141 | + $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params); |
|
142 | + $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types); |
|
143 | 143 | |
144 | - $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ]; |
|
144 | + $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ]; |
|
145 | 145 | |
146 | - // check if any prices use this price type |
|
147 | - $prc_query_params = array(array('PRT_ID'=>array('IN',$would_be_deleted_price_type_ids))); |
|
148 | - if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) { |
|
149 | - $prices_names_and_ids = array(); |
|
150 | - foreach ($prices as $price) { |
|
151 | - /* @var $price EE_Price */ |
|
152 | - $prices_names_and_ids[] = $price->name()."(".$price->ID().")"; |
|
153 | - } |
|
154 | - $msg = sprintf(__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type. If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids)); |
|
155 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
156 | - return false; |
|
157 | - } |
|
146 | + // check if any prices use this price type |
|
147 | + $prc_query_params = array(array('PRT_ID'=>array('IN',$would_be_deleted_price_type_ids))); |
|
148 | + if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) { |
|
149 | + $prices_names_and_ids = array(); |
|
150 | + foreach ($prices as $price) { |
|
151 | + /* @var $price EE_Price */ |
|
152 | + $prices_names_and_ids[] = $price->name()."(".$price->ID().")"; |
|
153 | + } |
|
154 | + $msg = sprintf(__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type. If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids)); |
|
155 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
156 | + return false; |
|
157 | + } |
|
158 | 158 | |
159 | 159 | |
160 | 160 | |
161 | - return parent::delete_permanently($query_params); |
|
162 | - } |
|
161 | + return parent::delete_permanently($query_params); |
|
162 | + } |
|
163 | 163 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function get_base_type_name($base_type_int) |
43 | 43 | { |
44 | - return $this->base_types[ $base_type_int ]; |
|
44 | + return $this->base_types[$base_type_int]; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | 'WP_User' => new EE_Belongs_To_Relation(), |
95 | 95 | ); |
96 | 96 | // this model is generally available for reading |
97 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
97 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
98 | 98 | // all price types are "default" in terms of capability names |
99 | 99 | $this->_caps_slug = 'default_price_types'; |
100 | 100 | parent::__construct($timezone); |
@@ -141,10 +141,10 @@ discard block |
||
141 | 141 | $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params); |
142 | 142 | $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types); |
143 | 143 | |
144 | - $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ]; |
|
144 | + $ID = $query_params[0][$this->get_primary_key_field()->get_name()]; |
|
145 | 145 | |
146 | 146 | // check if any prices use this price type |
147 | - $prc_query_params = array(array('PRT_ID'=>array('IN',$would_be_deleted_price_type_ids))); |
|
147 | + $prc_query_params = array(array('PRT_ID'=>array('IN', $would_be_deleted_price_type_ids))); |
|
148 | 148 | if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) { |
149 | 149 | $prices_names_and_ids = array(); |
150 | 150 | foreach ($prices as $price) { |
@@ -15,8 +15,6 @@ discard block |
||
15 | 15 | * This function is a singleton method used to instantiate the EEM_Attendee object |
16 | 16 | * |
17 | 17 | * @access public |
18 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
19 | - * @return EEM_System_Status |
|
20 | 18 | */ |
21 | 19 | public static function instance() |
22 | 20 | { |
@@ -157,7 +155,7 @@ discard block |
||
157 | 155 | |
158 | 156 | /** |
159 | 157 | * |
160 | - * @return array like EE_Config class |
|
158 | + * @return EE_Config like EE_Config class |
|
161 | 159 | */ |
162 | 160 | public function get_ee_config() |
163 | 161 | { |
@@ -214,7 +212,7 @@ discard block |
||
214 | 212 | |
215 | 213 | /** |
216 | 214 | * Checks if site responds ot HTTPS |
217 | - * @return boolean |
|
215 | + * @return string |
|
218 | 216 | */ |
219 | 217 | public function get_https_enabled() |
220 | 218 | { |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | $active_plugins = array_map('strtolower', $active_plugins); |
94 | 94 | $plugin_info = array(); |
95 | 95 | foreach ($active_plugins as $plugin) { |
96 | - $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
96 | + $plugin_data = @get_plugin_data(WP_PLUGIN_DIR.'/'.$plugin); |
|
97 | 97 | |
98 | - $plugin_info[ $plugin ] = $plugin_data; |
|
98 | + $plugin_info[$plugin] = $plugin_data; |
|
99 | 99 | } |
100 | 100 | return $plugin_info; |
101 | 101 | } |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | { |
109 | 109 | $wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT); |
110 | 110 | if ($wp_memory_int < 67108864) { |
111 | - $wp_memory_to_display = '<mark class="error">' . sprintf(__('%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', 'event_espresso'), WP_MEMORY_LIMIT, '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', '</a>"') . '</mark>'; |
|
111 | + $wp_memory_to_display = '<mark class="error">'.sprintf(__('%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', 'event_espresso'), WP_MEMORY_LIMIT, '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', '</a>"').'</mark>'; |
|
112 | 112 | } else { |
113 | - $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>'; |
|
113 | + $wp_memory_to_display = '<mark class="yes">'.size_format($wp_memory_int).'</mark>'; |
|
114 | 114 | } |
115 | 115 | return array( |
116 | 116 | 'name'=>get_bloginfo('name', 'display'), |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options(); |
150 | 150 | $presentable_migration_scripts = array(); |
151 | 151 | foreach ($options as $option_array) { |
152 | - $presentable_migration_scripts[ str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name']) ] = maybe_unserialize($option_array['option_value']); |
|
152 | + $presentable_migration_scripts[str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name'])] = maybe_unserialize($option_array['option_value']); |
|
153 | 153 | } |
154 | 154 | return $presentable_migration_scripts; |
155 | 155 | // return get_option(EE_Data_Migration_Manager::data_migrations_option_name);//EE_Data_Migration_Manager::instance()->get_data_migrations_ran(); |
@@ -175,18 +175,18 @@ discard block |
||
175 | 175 | |
176 | 176 | $pi = preg_replace( |
177 | 177 | array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms', |
178 | - '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#', |
|
178 | + '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#', |
|
179 | 179 | "#[ \t]+#", '# #', '# +#', '# class=".*?"#', '%'%', |
180 | 180 | '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>' |
181 | 181 | .'<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#', |
182 | 182 | '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#', |
183 | 183 | '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#', |
184 | 184 | "# +#", '#<tr>#', '#</tr>#'), |
185 | - array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ', |
|
185 | + array('$1', '', '', '', '</$1>'."\n", '<', ' ', ' ', ' ', '', ' ', |
|
186 | 186 | '<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'. |
187 | 187 | "\n".'<tr><td>PHP Egg</td><td>$1</td></tr>', |
188 | 188 | '<tr><td>PHP Credits Egg</td><td>$1</td></tr>', |
189 | - '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" . |
|
189 | + '<tr><td>Zend Engine</td><td>$2</td></tr>'."\n". |
|
190 | 190 | '<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'), |
191 | 191 | ob_get_clean() |
192 | 192 | ); |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | foreach ($askapache as $m) { |
207 | 207 | $m2 = isset($m[2]) ? $m[2] : null; |
208 | 208 | } |
209 | - $pi[ $n ][ $m[1] ]=(!isset($m[3])||$m2==$m[3]) ? $m2 : array_slice($m, 2); |
|
209 | + $pi[$n][$m[1]] = ( ! isset($m[3]) || $m2 == $m[3]) ? $m2 : array_slice($m, 2); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | return $pi; |
@@ -235,8 +235,8 @@ discard block |
||
235 | 235 | */ |
236 | 236 | public function get_wp_maintenance_mode() |
237 | 237 | { |
238 | - $opened = file_exists(ABSPATH . '.maintenance'); |
|
239 | - return $opened ? sprintf(__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : __('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso') ; |
|
238 | + $opened = file_exists(ABSPATH.'.maintenance'); |
|
239 | + return $opened ? sprintf(__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : __('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso'); |
|
240 | 240 | } |
241 | 241 | /** |
242 | 242 | * Whether or not logging is enabled |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | */ |
245 | 245 | public function get_logging_enabled() |
246 | 246 | { |
247 | - $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a'); |
|
248 | - return $opened ? __('Log Directory is writable', 'event_espresso') : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>') ; |
|
247 | + $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR.'/logs/espresso_log.txt', 'a'); |
|
248 | + return $opened ? __('Log Directory is writable', 'event_espresso') : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>'); |
|
249 | 249 | } |
250 | 250 | /** |
251 | 251 | * Whether curl ro fsock works |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | } elseif ($curl_works) { |
263 | 263 | $status = __('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso'); |
264 | 264 | } else { |
265 | - $status = __('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso'). '</mark>'; |
|
265 | + $status = __('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso').'</mark>'; |
|
266 | 266 | } |
267 | 267 | return $status; |
268 | 268 | } |
@@ -6,79 +6,79 @@ discard block |
||
6 | 6 | class EEM_System_Status |
7 | 7 | { |
8 | 8 | |
9 | - // private instance of the EEM_System_Status object |
|
10 | - protected static $_instance = null; |
|
9 | + // private instance of the EEM_System_Status object |
|
10 | + protected static $_instance = null; |
|
11 | 11 | |
12 | 12 | |
13 | 13 | |
14 | - /** |
|
15 | - * This function is a singleton method used to instantiate the EEM_Attendee object |
|
16 | - * |
|
17 | - * @access public |
|
18 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
19 | - * @return EEM_System_Status |
|
20 | - */ |
|
21 | - public static function instance() |
|
22 | - { |
|
14 | + /** |
|
15 | + * This function is a singleton method used to instantiate the EEM_Attendee object |
|
16 | + * |
|
17 | + * @access public |
|
18 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
19 | + * @return EEM_System_Status |
|
20 | + */ |
|
21 | + public static function instance() |
|
22 | + { |
|
23 | 23 | |
24 | - // check if instance of EEM_System_Status already exists |
|
25 | - if (self::$_instance === null) { |
|
26 | - // instantiate EEM_System_Status |
|
27 | - self::$_instance = new self(); |
|
28 | - } |
|
29 | - return self::$_instance; |
|
30 | - } |
|
31 | - private function __construct() |
|
32 | - { |
|
33 | - } |
|
34 | - /** |
|
35 | - * |
|
36 | - * @return array where each key is a function name on this class, and each value is SOMETHING-- |
|
37 | - * it might be a value, an array, or an object |
|
38 | - */ |
|
39 | - public function get_system_stati() |
|
40 | - { |
|
41 | - return apply_filters( |
|
42 | - 'FHEE__EEM_System_Status__get_system_stati', |
|
43 | - array( |
|
44 | - 'ee_version'=>$this->get_ee_version(), |
|
45 | - 'ee_activation_history'=>$this->get_ee_activation_history(), |
|
46 | - 'ee_config'=>$this->get_ee_config(), |
|
47 | - 'ee_migration_history'=>$this->get_ee_migration_history(), |
|
48 | - 'active_plugins'=>$this->get_active_plugins(), |
|
49 | - 'wp_settings'=>$this->get_wp_settings(), |
|
50 | - 'wp_maintenance_mode' => $this->get_wp_maintenance_mode(), |
|
51 | - 'https_enabled'=>$this->get_https_enabled(), |
|
52 | - 'logging_enabled' => $this->get_logging_enabled(), |
|
53 | - 'remote_posting' => $this->get_remote_posting(), |
|
54 | - 'php_version'=>$this->php_version(), |
|
55 | - 'php.ini_settings'=>$this->get_php_ini_all(), |
|
56 | - 'php_info'=>$this->get_php_info(), |
|
57 | - ), |
|
58 | - $this |
|
59 | - ); |
|
60 | - } |
|
61 | - /** |
|
62 | - * |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function get_ee_version() |
|
66 | - { |
|
67 | - return espresso_version(); |
|
68 | - } |
|
69 | - /** |
|
70 | - * |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function php_version() |
|
74 | - { |
|
75 | - return phpversion(); |
|
76 | - } |
|
77 | - /** |
|
78 | - * |
|
79 | - * @return array, where each key is a plugin name (lower-cased), values are sub-arrays. |
|
80 | - * Sub-arrays like described in wp function get_plugin_data. Ie, * |
|
81 | - * 'Name' => 'Plugin Name', |
|
24 | + // check if instance of EEM_System_Status already exists |
|
25 | + if (self::$_instance === null) { |
|
26 | + // instantiate EEM_System_Status |
|
27 | + self::$_instance = new self(); |
|
28 | + } |
|
29 | + return self::$_instance; |
|
30 | + } |
|
31 | + private function __construct() |
|
32 | + { |
|
33 | + } |
|
34 | + /** |
|
35 | + * |
|
36 | + * @return array where each key is a function name on this class, and each value is SOMETHING-- |
|
37 | + * it might be a value, an array, or an object |
|
38 | + */ |
|
39 | + public function get_system_stati() |
|
40 | + { |
|
41 | + return apply_filters( |
|
42 | + 'FHEE__EEM_System_Status__get_system_stati', |
|
43 | + array( |
|
44 | + 'ee_version'=>$this->get_ee_version(), |
|
45 | + 'ee_activation_history'=>$this->get_ee_activation_history(), |
|
46 | + 'ee_config'=>$this->get_ee_config(), |
|
47 | + 'ee_migration_history'=>$this->get_ee_migration_history(), |
|
48 | + 'active_plugins'=>$this->get_active_plugins(), |
|
49 | + 'wp_settings'=>$this->get_wp_settings(), |
|
50 | + 'wp_maintenance_mode' => $this->get_wp_maintenance_mode(), |
|
51 | + 'https_enabled'=>$this->get_https_enabled(), |
|
52 | + 'logging_enabled' => $this->get_logging_enabled(), |
|
53 | + 'remote_posting' => $this->get_remote_posting(), |
|
54 | + 'php_version'=>$this->php_version(), |
|
55 | + 'php.ini_settings'=>$this->get_php_ini_all(), |
|
56 | + 'php_info'=>$this->get_php_info(), |
|
57 | + ), |
|
58 | + $this |
|
59 | + ); |
|
60 | + } |
|
61 | + /** |
|
62 | + * |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function get_ee_version() |
|
66 | + { |
|
67 | + return espresso_version(); |
|
68 | + } |
|
69 | + /** |
|
70 | + * |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function php_version() |
|
74 | + { |
|
75 | + return phpversion(); |
|
76 | + } |
|
77 | + /** |
|
78 | + * |
|
79 | + * @return array, where each key is a plugin name (lower-cased), values are sub-arrays. |
|
80 | + * Sub-arrays like described in wp function get_plugin_data. Ie, * |
|
81 | + * 'Name' => 'Plugin Name', |
|
82 | 82 | 'PluginURI' => 'Plugin URI', |
83 | 83 | 'Version' => 'Version', |
84 | 84 | 'Description' => 'Description', |
@@ -87,221 +87,221 @@ discard block |
||
87 | 87 | 'TextDomain' => 'Text Domain', |
88 | 88 | 'DomainPath' => 'Domain Path', |
89 | 89 | 'Network' => 'Network', |
90 | - */ |
|
91 | - public function get_active_plugins() |
|
92 | - { |
|
93 | - $active_plugins = (array) get_option('active_plugins', array()); |
|
94 | - if (is_multisite()) { |
|
95 | - $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array())); |
|
96 | - } |
|
97 | - $active_plugins = array_map('strtolower', $active_plugins); |
|
98 | - $plugin_info = array(); |
|
99 | - foreach ($active_plugins as $plugin) { |
|
100 | - $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
90 | + */ |
|
91 | + public function get_active_plugins() |
|
92 | + { |
|
93 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
94 | + if (is_multisite()) { |
|
95 | + $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array())); |
|
96 | + } |
|
97 | + $active_plugins = array_map('strtolower', $active_plugins); |
|
98 | + $plugin_info = array(); |
|
99 | + foreach ($active_plugins as $plugin) { |
|
100 | + $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
101 | 101 | |
102 | - $plugin_info[ $plugin ] = $plugin_data; |
|
103 | - } |
|
104 | - return $plugin_info; |
|
105 | - } |
|
102 | + $plugin_info[ $plugin ] = $plugin_data; |
|
103 | + } |
|
104 | + return $plugin_info; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * |
|
109 | - * @return array with keys 'home_url' and 'site_url' |
|
110 | - */ |
|
111 | - public function get_wp_settings() |
|
112 | - { |
|
113 | - $wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT); |
|
114 | - if ($wp_memory_int < 67108864) { |
|
115 | - $wp_memory_to_display = '<mark class="error">' . sprintf(__('%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', 'event_espresso'), WP_MEMORY_LIMIT, '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', '</a>"') . '</mark>'; |
|
116 | - } else { |
|
117 | - $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>'; |
|
118 | - } |
|
119 | - return array( |
|
120 | - 'name'=>get_bloginfo('name', 'display'), |
|
121 | - 'is_multisite'=>is_multisite(), |
|
122 | - 'version'=> get_bloginfo('version', 'display'), |
|
123 | - 'home_url'=>home_url(), |
|
124 | - 'site_url'=>site_url(), |
|
125 | - 'WP_DEBUG'=>WP_DEBUG, |
|
126 | - 'permalink_structure'=>get_option('permalink_structure'), |
|
127 | - 'theme'=>wp_get_theme(), |
|
128 | - 'gmt_offset'=>get_option('gmt_offset'), |
|
129 | - 'timezone_string'=>get_option('timezone_string'), |
|
130 | - 'admin_email'=> get_bloginfo('admin_email', 'display'), |
|
131 | - 'language'=>get_bloginfo('language', 'display'), |
|
132 | - 'wp_max_upload_size' => size_format(wp_max_upload_size()), |
|
133 | - 'wp_memory' => $wp_memory_to_display |
|
134 | - ); |
|
135 | - } |
|
107 | + /** |
|
108 | + * |
|
109 | + * @return array with keys 'home_url' and 'site_url' |
|
110 | + */ |
|
111 | + public function get_wp_settings() |
|
112 | + { |
|
113 | + $wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT); |
|
114 | + if ($wp_memory_int < 67108864) { |
|
115 | + $wp_memory_to_display = '<mark class="error">' . sprintf(__('%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', 'event_espresso'), WP_MEMORY_LIMIT, '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', '</a>"') . '</mark>'; |
|
116 | + } else { |
|
117 | + $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>'; |
|
118 | + } |
|
119 | + return array( |
|
120 | + 'name'=>get_bloginfo('name', 'display'), |
|
121 | + 'is_multisite'=>is_multisite(), |
|
122 | + 'version'=> get_bloginfo('version', 'display'), |
|
123 | + 'home_url'=>home_url(), |
|
124 | + 'site_url'=>site_url(), |
|
125 | + 'WP_DEBUG'=>WP_DEBUG, |
|
126 | + 'permalink_structure'=>get_option('permalink_structure'), |
|
127 | + 'theme'=>wp_get_theme(), |
|
128 | + 'gmt_offset'=>get_option('gmt_offset'), |
|
129 | + 'timezone_string'=>get_option('timezone_string'), |
|
130 | + 'admin_email'=> get_bloginfo('admin_email', 'display'), |
|
131 | + 'language'=>get_bloginfo('language', 'display'), |
|
132 | + 'wp_max_upload_size' => size_format(wp_max_upload_size()), |
|
133 | + 'wp_memory' => $wp_memory_to_display |
|
134 | + ); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Gets an array of information about the history of ee versions installed |
|
139 | - * @return array |
|
140 | - */ |
|
141 | - public function get_ee_activation_history() |
|
142 | - { |
|
143 | - return get_option('espresso_db_update'); |
|
144 | - } |
|
137 | + /** |
|
138 | + * Gets an array of information about the history of ee versions installed |
|
139 | + * @return array |
|
140 | + */ |
|
141 | + public function get_ee_activation_history() |
|
142 | + { |
|
143 | + return get_option('espresso_db_update'); |
|
144 | + } |
|
145 | 145 | |
146 | 146 | |
147 | - /** |
|
148 | - * Gets an array where keys are ee versions, and their values are arrays indicating all the different times that version was installed |
|
149 | - * @return EE_Data_Migration_Script_Base[] |
|
150 | - */ |
|
151 | - public function get_ee_migration_history() |
|
152 | - { |
|
153 | - $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options(); |
|
154 | - $presentable_migration_scripts = array(); |
|
155 | - foreach ($options as $option_array) { |
|
156 | - $presentable_migration_scripts[ str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name']) ] = maybe_unserialize($option_array['option_value']); |
|
157 | - } |
|
158 | - return $presentable_migration_scripts; |
|
147 | + /** |
|
148 | + * Gets an array where keys are ee versions, and their values are arrays indicating all the different times that version was installed |
|
149 | + * @return EE_Data_Migration_Script_Base[] |
|
150 | + */ |
|
151 | + public function get_ee_migration_history() |
|
152 | + { |
|
153 | + $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options(); |
|
154 | + $presentable_migration_scripts = array(); |
|
155 | + foreach ($options as $option_array) { |
|
156 | + $presentable_migration_scripts[ str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name']) ] = maybe_unserialize($option_array['option_value']); |
|
157 | + } |
|
158 | + return $presentable_migration_scripts; |
|
159 | 159 | // return get_option(EE_Data_Migration_Manager::data_migrations_option_name);//EE_Data_Migration_Manager::instance()->get_data_migrations_ran(); |
160 | - } |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * |
|
164 | - * @return array like EE_Config class |
|
165 | - */ |
|
166 | - public function get_ee_config() |
|
167 | - { |
|
168 | - return EE_Config::instance(); |
|
169 | - } |
|
162 | + /** |
|
163 | + * |
|
164 | + * @return array like EE_Config class |
|
165 | + */ |
|
166 | + public function get_ee_config() |
|
167 | + { |
|
168 | + return EE_Config::instance(); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Gets an array of php setup info, pilfered from http://www.php.net/manual/en/function.phpinfo.php#87463 |
|
173 | - * @return array like the output of phpinfo(), but in an array |
|
174 | - */ |
|
175 | - public function get_php_info() |
|
176 | - { |
|
177 | - ob_start(); |
|
178 | - phpinfo(-1); |
|
171 | + /** |
|
172 | + * Gets an array of php setup info, pilfered from http://www.php.net/manual/en/function.phpinfo.php#87463 |
|
173 | + * @return array like the output of phpinfo(), but in an array |
|
174 | + */ |
|
175 | + public function get_php_info() |
|
176 | + { |
|
177 | + ob_start(); |
|
178 | + phpinfo(-1); |
|
179 | 179 | |
180 | - $pi = preg_replace( |
|
181 | - array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms', |
|
182 | - '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#', |
|
183 | - "#[ \t]+#", '# #', '# +#', '# class=".*?"#', '%'%', |
|
184 | - '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>' |
|
185 | - .'<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#', |
|
186 | - '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#', |
|
187 | - '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#', |
|
188 | - "# +#", '#<tr>#', '#</tr>#'), |
|
189 | - array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ', |
|
190 | - '<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'. |
|
191 | - "\n".'<tr><td>PHP Egg</td><td>$1</td></tr>', |
|
192 | - '<tr><td>PHP Credits Egg</td><td>$1</td></tr>', |
|
193 | - '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" . |
|
194 | - '<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'), |
|
195 | - ob_get_clean() |
|
196 | - ); |
|
180 | + $pi = preg_replace( |
|
181 | + array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms', |
|
182 | + '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#', |
|
183 | + "#[ \t]+#", '# #', '# +#', '# class=".*?"#', '%'%', |
|
184 | + '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>' |
|
185 | + .'<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#', |
|
186 | + '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#', |
|
187 | + '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#', |
|
188 | + "# +#", '#<tr>#', '#</tr>#'), |
|
189 | + array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ', |
|
190 | + '<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'. |
|
191 | + "\n".'<tr><td>PHP Egg</td><td>$1</td></tr>', |
|
192 | + '<tr><td>PHP Credits Egg</td><td>$1</td></tr>', |
|
193 | + '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" . |
|
194 | + '<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'), |
|
195 | + ob_get_clean() |
|
196 | + ); |
|
197 | 197 | |
198 | - $sections = explode('<h2>', strip_tags($pi, '<h2><th><td>')); |
|
199 | - unset($sections[0]); |
|
198 | + $sections = explode('<h2>', strip_tags($pi, '<h2><th><td>')); |
|
199 | + unset($sections[0]); |
|
200 | 200 | |
201 | - $pi = array(); |
|
202 | - foreach ($sections as $section) { |
|
203 | - $n = substr($section, 0, strpos($section, '</h2>')); |
|
204 | - preg_match_all( |
|
205 | - '#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#', |
|
206 | - $section, |
|
207 | - $askapache, |
|
208 | - PREG_SET_ORDER |
|
209 | - ); |
|
210 | - foreach ($askapache as $m) { |
|
211 | - $m2 = isset($m[2]) ? $m[2] : null; |
|
212 | - } |
|
213 | - $pi[ $n ][ $m[1] ]=(!isset($m[3])||$m2==$m[3]) ? $m2 : array_slice($m, 2); |
|
214 | - } |
|
201 | + $pi = array(); |
|
202 | + foreach ($sections as $section) { |
|
203 | + $n = substr($section, 0, strpos($section, '</h2>')); |
|
204 | + preg_match_all( |
|
205 | + '#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#', |
|
206 | + $section, |
|
207 | + $askapache, |
|
208 | + PREG_SET_ORDER |
|
209 | + ); |
|
210 | + foreach ($askapache as $m) { |
|
211 | + $m2 = isset($m[2]) ? $m[2] : null; |
|
212 | + } |
|
213 | + $pi[ $n ][ $m[1] ]=(!isset($m[3])||$m2==$m[3]) ? $m2 : array_slice($m, 2); |
|
214 | + } |
|
215 | 215 | |
216 | - return $pi; |
|
217 | - } |
|
216 | + return $pi; |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * Checks if site responds ot HTTPS |
|
221 | - * @return boolean |
|
222 | - */ |
|
223 | - public function get_https_enabled() |
|
224 | - { |
|
225 | - $home = str_replace("http://", "https://", home_url()); |
|
226 | - $response = wp_remote_get($home); |
|
227 | - if ($response instanceof WP_Error) { |
|
228 | - $error_string = ''; |
|
229 | - foreach ($response->errors as $short_name => $description_array) { |
|
230 | - $error_string .= "<b>$short_name</b>: ".implode(", ", $description_array); |
|
231 | - } |
|
232 | - return $error_string; |
|
233 | - } |
|
234 | - return "ok!"; |
|
235 | - } |
|
236 | - /** |
|
237 | - * Whether or not a .maintenance file is detected |
|
238 | - * @return string descripting wp_maintenance_mode status |
|
239 | - */ |
|
240 | - public function get_wp_maintenance_mode() |
|
241 | - { |
|
242 | - $opened = file_exists(ABSPATH . '.maintenance'); |
|
243 | - return $opened ? sprintf(__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : __('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso') ; |
|
244 | - } |
|
245 | - /** |
|
246 | - * Whether or not logging is enabled |
|
247 | - * @return string descripting logging's status |
|
248 | - */ |
|
249 | - public function get_logging_enabled() |
|
250 | - { |
|
251 | - $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a'); |
|
252 | - return $opened ? __('Log Directory is writable', 'event_espresso') : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>') ; |
|
253 | - } |
|
254 | - /** |
|
255 | - * Whether curl ro fsock works |
|
256 | - * @return string describing posting's status |
|
257 | - */ |
|
258 | - public function get_remote_posting() |
|
259 | - { |
|
260 | - $fsock_works = function_exists('fsockopen'); |
|
261 | - $curl_works = function_exists('curl_init'); |
|
262 | - if ($fsock_works && $curl_works) { |
|
263 | - $status = __('Your server has fsockopen and cURL enabled.', 'event_espresso'); |
|
264 | - } elseif ($fsock_works) { |
|
265 | - $status = __('Your server has fsockopen enabled, cURL is disabled.', 'event_espresso'); |
|
266 | - } elseif ($curl_works) { |
|
267 | - $status = __('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso'); |
|
268 | - } else { |
|
269 | - $status = __('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso'). '</mark>'; |
|
270 | - } |
|
271 | - return $status; |
|
272 | - } |
|
273 | - /** |
|
274 | - * Gets all the php.ini settings |
|
275 | - * @return array |
|
276 | - */ |
|
277 | - public function get_php_ini_all() |
|
278 | - { |
|
279 | - return ini_get_all(); |
|
280 | - } |
|
281 | - /** |
|
282 | - * Transforms the php.ini notation for numbers (like '2M') to an integer. |
|
283 | - * |
|
284 | - * @param type $size |
|
285 | - * @return int |
|
286 | - */ |
|
287 | - public function let_to_num($size) |
|
288 | - { |
|
289 | - $l = substr($size, -1); |
|
290 | - $ret = substr($size, 0, -1); |
|
291 | - // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
292 | - switch (strtoupper($l)) { |
|
293 | - case 'P': |
|
294 | - $ret *= 1024; |
|
295 | - case 'T': |
|
296 | - $ret *= 1024; |
|
297 | - case 'G': |
|
298 | - $ret *= 1024; |
|
299 | - case 'M': |
|
300 | - $ret *= 1024; |
|
301 | - case 'K': |
|
302 | - $ret *= 1024; |
|
303 | - } |
|
304 | - // phpcs:enable |
|
305 | - return $ret; |
|
306 | - } |
|
219 | + /** |
|
220 | + * Checks if site responds ot HTTPS |
|
221 | + * @return boolean |
|
222 | + */ |
|
223 | + public function get_https_enabled() |
|
224 | + { |
|
225 | + $home = str_replace("http://", "https://", home_url()); |
|
226 | + $response = wp_remote_get($home); |
|
227 | + if ($response instanceof WP_Error) { |
|
228 | + $error_string = ''; |
|
229 | + foreach ($response->errors as $short_name => $description_array) { |
|
230 | + $error_string .= "<b>$short_name</b>: ".implode(", ", $description_array); |
|
231 | + } |
|
232 | + return $error_string; |
|
233 | + } |
|
234 | + return "ok!"; |
|
235 | + } |
|
236 | + /** |
|
237 | + * Whether or not a .maintenance file is detected |
|
238 | + * @return string descripting wp_maintenance_mode status |
|
239 | + */ |
|
240 | + public function get_wp_maintenance_mode() |
|
241 | + { |
|
242 | + $opened = file_exists(ABSPATH . '.maintenance'); |
|
243 | + return $opened ? sprintf(__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : __('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso') ; |
|
244 | + } |
|
245 | + /** |
|
246 | + * Whether or not logging is enabled |
|
247 | + * @return string descripting logging's status |
|
248 | + */ |
|
249 | + public function get_logging_enabled() |
|
250 | + { |
|
251 | + $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a'); |
|
252 | + return $opened ? __('Log Directory is writable', 'event_espresso') : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>') ; |
|
253 | + } |
|
254 | + /** |
|
255 | + * Whether curl ro fsock works |
|
256 | + * @return string describing posting's status |
|
257 | + */ |
|
258 | + public function get_remote_posting() |
|
259 | + { |
|
260 | + $fsock_works = function_exists('fsockopen'); |
|
261 | + $curl_works = function_exists('curl_init'); |
|
262 | + if ($fsock_works && $curl_works) { |
|
263 | + $status = __('Your server has fsockopen and cURL enabled.', 'event_espresso'); |
|
264 | + } elseif ($fsock_works) { |
|
265 | + $status = __('Your server has fsockopen enabled, cURL is disabled.', 'event_espresso'); |
|
266 | + } elseif ($curl_works) { |
|
267 | + $status = __('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso'); |
|
268 | + } else { |
|
269 | + $status = __('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso'). '</mark>'; |
|
270 | + } |
|
271 | + return $status; |
|
272 | + } |
|
273 | + /** |
|
274 | + * Gets all the php.ini settings |
|
275 | + * @return array |
|
276 | + */ |
|
277 | + public function get_php_ini_all() |
|
278 | + { |
|
279 | + return ini_get_all(); |
|
280 | + } |
|
281 | + /** |
|
282 | + * Transforms the php.ini notation for numbers (like '2M') to an integer. |
|
283 | + * |
|
284 | + * @param type $size |
|
285 | + * @return int |
|
286 | + */ |
|
287 | + public function let_to_num($size) |
|
288 | + { |
|
289 | + $l = substr($size, -1); |
|
290 | + $ret = substr($size, 0, -1); |
|
291 | + // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
292 | + switch (strtoupper($l)) { |
|
293 | + case 'P': |
|
294 | + $ret *= 1024; |
|
295 | + case 'T': |
|
296 | + $ret *= 1024; |
|
297 | + case 'G': |
|
298 | + $ret *= 1024; |
|
299 | + case 'M': |
|
300 | + $ret *= 1024; |
|
301 | + case 'K': |
|
302 | + $ret *= 1024; |
|
303 | + } |
|
304 | + // phpcs:enable |
|
305 | + return $ret; |
|
306 | + } |
|
307 | 307 | } |
@@ -32,8 +32,6 @@ |
||
32 | 32 | * ) |
33 | 33 | * ) |
34 | 34 | * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
35 | - * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is |
|
36 | - * set to true, it will be stored as an INT |
|
37 | 35 | */ |
38 | 36 | public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array()) |
39 | 37 | { |
@@ -3,114 +3,114 @@ |
||
3 | 3 | class EE_WP_Post_Status_Field extends EE_Enum_Text_Field |
4 | 4 | { |
5 | 5 | |
6 | - protected $_wp_post_stati; |
|
6 | + protected $_wp_post_stati; |
|
7 | 7 | |
8 | 8 | |
9 | - /** |
|
10 | - * constructor |
|
11 | - * |
|
12 | - * @param string $table_column column on table |
|
13 | - * @param string $nicename nice name for column(field) |
|
14 | - * @param bool $nullable is this field nullable |
|
15 | - * @param string $default_value default status |
|
16 | - * @param array $new_stati If additional stati are to be used other than the default WP statuses then |
|
17 | - * they can be registered via this property. The format of the array should be |
|
18 | - * as follows: array( |
|
19 | - * 'status_reference' => array( |
|
20 | - * 'label' => __('Status Reference Label', 'event_espresso') |
|
21 | - * 'public' => true, //'Whether posts of this status should be shown on the |
|
22 | - * frontend of the site' |
|
23 | - * 'exclude_from_search' => false, //'Whether posts of this status should be |
|
24 | - * excluded from wp searches' |
|
25 | - * 'show_in_admin_all_list' => true, //whether posts of this status are included |
|
26 | - * in queries for the admin "all" view in list table views. |
|
27 | - * 'show_in_admin_status_list' => true, //Show in the list of statuses with post |
|
28 | - * counts at the top of the admin list tables (i.e. Status Reference(2) ) |
|
29 | - * 'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>', |
|
30 | - * 'Status References <span class="count">(%s)</span>' ), //the text to display |
|
31 | - * on the admin screen( or you won't see your status count ). |
|
32 | - * ) |
|
33 | - * ) |
|
34 | - * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
|
35 | - * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is |
|
36 | - * set to true, it will be stored as an INT |
|
37 | - */ |
|
38 | - public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array()) |
|
39 | - { |
|
40 | - $this->_register_new_stati($new_stati); |
|
41 | - $this->_set_allowed_enum_values(); |
|
42 | - parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values); |
|
43 | - } |
|
9 | + /** |
|
10 | + * constructor |
|
11 | + * |
|
12 | + * @param string $table_column column on table |
|
13 | + * @param string $nicename nice name for column(field) |
|
14 | + * @param bool $nullable is this field nullable |
|
15 | + * @param string $default_value default status |
|
16 | + * @param array $new_stati If additional stati are to be used other than the default WP statuses then |
|
17 | + * they can be registered via this property. The format of the array should be |
|
18 | + * as follows: array( |
|
19 | + * 'status_reference' => array( |
|
20 | + * 'label' => __('Status Reference Label', 'event_espresso') |
|
21 | + * 'public' => true, //'Whether posts of this status should be shown on the |
|
22 | + * frontend of the site' |
|
23 | + * 'exclude_from_search' => false, //'Whether posts of this status should be |
|
24 | + * excluded from wp searches' |
|
25 | + * 'show_in_admin_all_list' => true, //whether posts of this status are included |
|
26 | + * in queries for the admin "all" view in list table views. |
|
27 | + * 'show_in_admin_status_list' => true, //Show in the list of statuses with post |
|
28 | + * counts at the top of the admin list tables (i.e. Status Reference(2) ) |
|
29 | + * 'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>', |
|
30 | + * 'Status References <span class="count">(%s)</span>' ), //the text to display |
|
31 | + * on the admin screen( or you won't see your status count ). |
|
32 | + * ) |
|
33 | + * ) |
|
34 | + * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
|
35 | + * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is |
|
36 | + * set to true, it will be stored as an INT |
|
37 | + */ |
|
38 | + public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array()) |
|
39 | + { |
|
40 | + $this->_register_new_stati($new_stati); |
|
41 | + $this->_set_allowed_enum_values(); |
|
42 | + parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * This registers any new statuses sent via the $new_stati array on construct |
|
48 | - * |
|
49 | - * @access protected |
|
50 | - * @param array $new_stati statuses |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - protected function _register_new_stati($new_stati) |
|
54 | - { |
|
46 | + /** |
|
47 | + * This registers any new statuses sent via the $new_stati array on construct |
|
48 | + * |
|
49 | + * @access protected |
|
50 | + * @param array $new_stati statuses |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + protected function _register_new_stati($new_stati) |
|
54 | + { |
|
55 | 55 | |
56 | - foreach ((array) $new_stati as $status_key => $status_args) { |
|
57 | - $args = array( |
|
58 | - 'label' => isset($status_args['label']) ? $status_args['label'] : $status_key, |
|
59 | - 'public' => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true, |
|
60 | - 'exclude_from_search' => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false, |
|
61 | - 'show_in_admin_all_list' => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false, |
|
62 | - 'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true, |
|
63 | - 'label_count' => isset($status_args['label_count']) ? $status_args['label_count'] : '', |
|
64 | - ); |
|
65 | - register_post_status($status_key, $status_args); |
|
66 | - } |
|
67 | - } |
|
56 | + foreach ((array) $new_stati as $status_key => $status_args) { |
|
57 | + $args = array( |
|
58 | + 'label' => isset($status_args['label']) ? $status_args['label'] : $status_key, |
|
59 | + 'public' => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true, |
|
60 | + 'exclude_from_search' => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false, |
|
61 | + 'show_in_admin_all_list' => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false, |
|
62 | + 'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true, |
|
63 | + 'label_count' => isset($status_args['label_count']) ? $status_args['label_count'] : '', |
|
64 | + ); |
|
65 | + register_post_status($status_key, $status_args); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - /** |
|
71 | - * This sets the _allowed_enum_values property using the $wp_post_stati array |
|
72 | - * |
|
73 | - * @access protected |
|
74 | - * @regurn void |
|
75 | - */ |
|
76 | - protected function _set_allowed_enum_values() |
|
77 | - { |
|
78 | - // first let's get the post_statuses |
|
79 | - global $wp_post_statuses; |
|
80 | - $this->_wp_post_stati = $wp_post_statuses; |
|
70 | + /** |
|
71 | + * This sets the _allowed_enum_values property using the $wp_post_stati array |
|
72 | + * |
|
73 | + * @access protected |
|
74 | + * @regurn void |
|
75 | + */ |
|
76 | + protected function _set_allowed_enum_values() |
|
77 | + { |
|
78 | + // first let's get the post_statuses |
|
79 | + global $wp_post_statuses; |
|
80 | + $this->_wp_post_stati = $wp_post_statuses; |
|
81 | 81 | |
82 | - foreach ($this->_wp_post_stati as $post_status => $args_object) { |
|
83 | - $this->_allowed_enum_values[ $post_status ] = $args_object->label; |
|
84 | - } |
|
85 | - } |
|
82 | + foreach ($this->_wp_post_stati as $post_status => $args_object) { |
|
83 | + $this->_allowed_enum_values[ $post_status ] = $args_object->label; |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Before calling parent, first double-checks our list of acceptable post |
|
89 | - * types is up-to-date |
|
90 | - * |
|
91 | - * @param string $value_inputted_for_field_on_model_object |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
95 | - { |
|
96 | - $this->_set_allowed_enum_values(); |
|
97 | - return parent::prepare_for_set($value_inputted_for_field_on_model_object); |
|
98 | - } |
|
87 | + /** |
|
88 | + * Before calling parent, first double-checks our list of acceptable post |
|
89 | + * types is up-to-date |
|
90 | + * |
|
91 | + * @param string $value_inputted_for_field_on_model_object |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
95 | + { |
|
96 | + $this->_set_allowed_enum_values(); |
|
97 | + return parent::prepare_for_set($value_inputted_for_field_on_model_object); |
|
98 | + } |
|
99 | 99 | |
100 | 100 | |
101 | 101 | |
102 | - // helper methods for getting various $wp_post_statuses stuff. |
|
102 | + // helper methods for getting various $wp_post_statuses stuff. |
|
103 | 103 | |
104 | - /** |
|
105 | - * This just returns the status object for the given status |
|
106 | - * |
|
107 | - * @access public |
|
108 | - * @see wp_register_post_status in wp-includes/post.php for a list of properties of the status object |
|
109 | - * @param string $status What status object you want |
|
110 | - * @return std_object the status object or FALSE if it doesn't exist. |
|
111 | - */ |
|
112 | - public function get_status_object($status) |
|
113 | - { |
|
114 | - return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false; |
|
115 | - } |
|
104 | + /** |
|
105 | + * This just returns the status object for the given status |
|
106 | + * |
|
107 | + * @access public |
|
108 | + * @see wp_register_post_status in wp-includes/post.php for a list of properties of the status object |
|
109 | + * @param string $status What status object you want |
|
110 | + * @return std_object the status object or FALSE if it doesn't exist. |
|
111 | + */ |
|
112 | + public function get_status_object($status) |
|
113 | + { |
|
114 | + return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false; |
|
115 | + } |
|
116 | 116 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $this->_wp_post_stati = $wp_post_statuses; |
81 | 81 | |
82 | 82 | foreach ($this->_wp_post_stati as $post_status => $args_object) { |
83 | - $this->_allowed_enum_values[ $post_status ] = $args_object->label; |
|
83 | + $this->_allowed_enum_values[$post_status] = $args_object->label; |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
@@ -111,6 +111,6 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function get_status_object($status) |
113 | 113 | { |
114 | - return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false; |
|
114 | + return isset($this->_wp_post_stati[$status]) ? $this->_wp_post_stati[$status] : false; |
|
115 | 115 | } |
116 | 116 | } |