@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | 'base_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'base', $this->_variation), |
260 | 260 | 'print_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'print', $this->_variation), |
261 | 261 | 'main_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'main', $this->_variation), |
262 | - 'extra_css' => EE_LIBRARIES_URL . 'messages/defaults/default/variations/pdf_base_default.css', |
|
262 | + 'extra_css' => EE_LIBRARIES_URL.'messages/defaults/default/variations/pdf_base_default.css', |
|
263 | 263 | 'main_body' => apply_filters('FHEE__EE_Pdf_messenger___send_message__main_body', wpautop($this->_content), $this->_content) |
264 | 264 | ); |
265 | 265 | $this->_deregister_wp_hooks(); |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | $invoice_name = $this->_subject; |
324 | 324 | |
325 | 325 | // only load dompdf if nobody else has yet... |
326 | - if (! class_exists('Dompdf\Dompdf')) { |
|
327 | - require_once(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php'); |
|
326 | + if ( ! class_exists('Dompdf\Dompdf')) { |
|
327 | + require_once(EE_THIRD_PARTY.'dompdf/src/Autoloader.php'); |
|
328 | 328 | Dompdf\Autoloader::register(); |
329 | 329 | } |
330 | 330 | $options = new Dompdf\Options(); |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | $dompdf->loadHtml($content); |
337 | 337 | $dompdf->render(); |
338 | 338 | // forcing the browser to open a download dialog. |
339 | - $dompdf->stream($invoice_name . ".pdf", array('Attachment' => true)); |
|
339 | + $dompdf->stream($invoice_name.".pdf", array('Attachment' => true)); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 |
@@ -15,345 +15,345 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * The following are the properties that this messenger requires for generating pdf |
|
20 | - */ |
|
21 | - |
|
22 | - /** |
|
23 | - * This is the pdf body generated by the template via the message type. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $_content; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * This is for the page title that gets displayed. This will end up being the filename for the generated pdf. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $_subject; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @return EE_Pdf_messenger |
|
40 | - */ |
|
41 | - public function __construct() |
|
42 | - { |
|
43 | - // set properties |
|
44 | - $this->name = 'pdf'; |
|
45 | - $this->description = __('This messenger is used for generating a pdf version of the message.', 'event_espresso'); |
|
46 | - $this->label = array( |
|
47 | - 'singular' => __('PDF', 'event_espresso'), |
|
48 | - 'plural' => __('PDFs', 'event_espresso') |
|
49 | - ); |
|
50 | - $this->activate_on_install = true; |
|
51 | - |
|
52 | - parent::__construct(); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * PDF Messenger desires execution immediately. |
|
58 | - * @see parent::send_now() for documentation. |
|
59 | - * @since 4.9.0 |
|
60 | - * @return bool |
|
61 | - */ |
|
62 | - public function send_now() |
|
63 | - { |
|
64 | - return true; |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * HTML Messenger allows an empty to field. |
|
70 | - * @see parent::allow_empty_to_field() for documentation |
|
71 | - * @since 4.9.0 |
|
72 | - * @return bool |
|
73 | - */ |
|
74 | - public function allow_empty_to_field() |
|
75 | - { |
|
76 | - return true; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @see abstract declaration in EE_messenger for details. |
|
82 | - */ |
|
83 | - protected function _set_admin_pages() |
|
84 | - { |
|
85 | - $this->admin_registered_pages = array('events_edit' => false); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * @see abstract declaration in EE_messenger for details. |
|
91 | - */ |
|
92 | - protected function _set_valid_shortcodes() |
|
93 | - { |
|
94 | - $this->_valid_shortcodes = array(); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @see abstract declaration in EE_messenger for details. |
|
100 | - */ |
|
101 | - protected function _set_validator_config() |
|
102 | - { |
|
103 | - $this->_validator_config = array( |
|
104 | - 'subject' => array( |
|
105 | - 'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime') |
|
106 | - ), |
|
107 | - 'content' => array( |
|
108 | - 'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime') |
|
109 | - ), |
|
110 | - 'attendee_list' => array( |
|
111 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
112 | - 'required' => array('[ATTENDEE_LIST]') |
|
113 | - ), |
|
114 | - 'event_list' => array( |
|
115 | - 'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'venue', 'datetime_list', 'attendee', 'primary_registration_details', 'primary_registration_list', 'event_author', 'recipient_details', 'recipient_list'), |
|
116 | - 'required' => array('[EVENT_LIST]') |
|
117 | - ), |
|
118 | - 'ticket_list' => array( |
|
119 | - 'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'primary_registration_details', 'recipient_details'), |
|
120 | - 'required' => array('[TICKET_LIST]') |
|
121 | - ), |
|
122 | - 'datetime_list' => array( |
|
123 | - 'shortcodes' => array('datetime'), |
|
124 | - 'required' => array('[DATETIME_LIST]') |
|
125 | - ), |
|
126 | - ); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this messenger can add their own js. |
|
132 | - * |
|
133 | - * @return void. |
|
134 | - */ |
|
135 | - public function enqueue_scripts_styles() |
|
136 | - { |
|
137 | - parent::enqueue_scripts_styles(); |
|
138 | - do_action('AHEE__EE_Pdf_messenger__enqueue_scripts_styles'); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * _set_template_fields |
|
144 | - * This sets up the fields that a messenger requires for the message to go out. |
|
145 | - * |
|
146 | - * @access protected |
|
147 | - * @return void |
|
148 | - */ |
|
149 | - protected function _set_template_fields() |
|
150 | - { |
|
151 | - // any extra template fields that are NOT used by the messenger but will get used by a messenger field for shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field they relate to. This is important for the Messages_admin to know what fields to display to the user. Also, notice that the "values" are equal to the field type that messages admin will use to know what kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and will not be displayed/parsed. |
|
152 | - $this->_template_fields = array( |
|
153 | - 'subject' => array( |
|
154 | - 'input' => 'text', |
|
155 | - 'label' => __('Page Title', 'event_espresso'), |
|
156 | - 'type' => 'string', |
|
157 | - 'required' => true, |
|
158 | - 'validation' => true, |
|
159 | - 'css_class' => 'large-text', |
|
160 | - 'format' => '%s' |
|
161 | - ), |
|
162 | - 'content' => '', // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
163 | - 'extra' => array( |
|
164 | - 'content' => array( |
|
165 | - 'main' => array( |
|
166 | - 'input' => 'wp_editor', |
|
167 | - 'label' => __('Main Content', 'event_espresso'), |
|
168 | - 'type' => 'string', |
|
169 | - 'required' => true, |
|
170 | - 'validation' => true, |
|
171 | - 'format' => '%s', |
|
172 | - 'rows' => '15' |
|
173 | - ), |
|
174 | - 'event_list' => array( |
|
175 | - 'input' => 'wp_editor', |
|
176 | - 'label' => '[EVENT_LIST]', |
|
177 | - 'type' => 'string', |
|
178 | - 'required' => true, |
|
179 | - 'validation' => true, |
|
180 | - 'format' => '%s', |
|
181 | - 'rows' => '15', |
|
182 | - 'shortcodes_required' => array('[EVENT_LIST]') |
|
183 | - ), |
|
184 | - 'attendee_list' => array( |
|
185 | - 'input' => 'textarea', |
|
186 | - 'label' => '[ATTENDEE_LIST]', |
|
187 | - 'type' => 'string', |
|
188 | - 'required' => true, |
|
189 | - 'validation' => true, |
|
190 | - 'format' => '%s', |
|
191 | - 'css_class' => 'large-text', |
|
192 | - 'rows' => '5', |
|
193 | - 'shortcodes_required' => array('[ATTENDEE_LIST]') |
|
194 | - ), |
|
195 | - 'ticket_list' => array( |
|
196 | - 'input' => 'textarea', |
|
197 | - 'label' => '[TICKET_LIST]', |
|
198 | - 'type' => 'string', |
|
199 | - 'required' => true, |
|
200 | - 'validation' => true, |
|
201 | - 'format' => '%s', |
|
202 | - 'css_class' => 'large-text', |
|
203 | - 'rows' => '10', |
|
204 | - 'shortcodes_required' => array('[TICKET_LIST]') |
|
205 | - ), |
|
206 | - 'datetime_list' => array( |
|
207 | - 'input' => 'textarea', |
|
208 | - 'label' => '[DATETIME_LIST]', |
|
209 | - 'type' => 'string', |
|
210 | - 'required' => true, |
|
211 | - 'validation' => true, |
|
212 | - 'format' => '%s', |
|
213 | - 'css_class' => 'large-text', |
|
214 | - 'rows' => '10', |
|
215 | - 'shortcodes_required' => array('[DATETIME_LIST]') |
|
216 | - ) |
|
217 | - ) |
|
218 | - ) |
|
219 | - ); |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * @see definition of this method in parent |
|
225 | - * |
|
226 | - * @since 4.5.0 |
|
227 | - * |
|
228 | - */ |
|
229 | - protected function _set_default_message_types() |
|
230 | - { |
|
231 | - // note currently PDF is only a secondary messenger so it never has any associated message types. |
|
232 | - $this->_default_message_types = array(); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * @see definition of this method in parent |
|
238 | - * |
|
239 | - * @since 4.5.0 |
|
240 | - */ |
|
241 | - protected function _set_valid_message_types() |
|
242 | - { |
|
243 | - $this->_valid_message_types = array(); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Generates html version of the message content and then sends it to the pdf generator. |
|
249 | - * |
|
250 | - * |
|
251 | - * @since 4.5.0 |
|
252 | - * |
|
253 | - * @return string. |
|
254 | - */ |
|
255 | - protected function _send_message() |
|
256 | - { |
|
257 | - $this->_template_args = array( |
|
258 | - 'page_title' => $this->_subject, |
|
259 | - 'base_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'base', $this->_variation), |
|
260 | - 'print_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'print', $this->_variation), |
|
261 | - 'main_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'main', $this->_variation), |
|
262 | - 'extra_css' => EE_LIBRARIES_URL . 'messages/defaults/default/variations/pdf_base_default.css', |
|
263 | - 'main_body' => apply_filters('FHEE__EE_Pdf_messenger___send_message__main_body', wpautop($this->_content), $this->_content) |
|
264 | - ); |
|
265 | - $this->_deregister_wp_hooks(); |
|
266 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
267 | - $content = $this->_get_main_template(); |
|
18 | + /** |
|
19 | + * The following are the properties that this messenger requires for generating pdf |
|
20 | + */ |
|
21 | + |
|
22 | + /** |
|
23 | + * This is the pdf body generated by the template via the message type. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $_content; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * This is for the page title that gets displayed. This will end up being the filename for the generated pdf. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $_subject; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @return EE_Pdf_messenger |
|
40 | + */ |
|
41 | + public function __construct() |
|
42 | + { |
|
43 | + // set properties |
|
44 | + $this->name = 'pdf'; |
|
45 | + $this->description = __('This messenger is used for generating a pdf version of the message.', 'event_espresso'); |
|
46 | + $this->label = array( |
|
47 | + 'singular' => __('PDF', 'event_espresso'), |
|
48 | + 'plural' => __('PDFs', 'event_espresso') |
|
49 | + ); |
|
50 | + $this->activate_on_install = true; |
|
51 | + |
|
52 | + parent::__construct(); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * PDF Messenger desires execution immediately. |
|
58 | + * @see parent::send_now() for documentation. |
|
59 | + * @since 4.9.0 |
|
60 | + * @return bool |
|
61 | + */ |
|
62 | + public function send_now() |
|
63 | + { |
|
64 | + return true; |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * HTML Messenger allows an empty to field. |
|
70 | + * @see parent::allow_empty_to_field() for documentation |
|
71 | + * @since 4.9.0 |
|
72 | + * @return bool |
|
73 | + */ |
|
74 | + public function allow_empty_to_field() |
|
75 | + { |
|
76 | + return true; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @see abstract declaration in EE_messenger for details. |
|
82 | + */ |
|
83 | + protected function _set_admin_pages() |
|
84 | + { |
|
85 | + $this->admin_registered_pages = array('events_edit' => false); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * @see abstract declaration in EE_messenger for details. |
|
91 | + */ |
|
92 | + protected function _set_valid_shortcodes() |
|
93 | + { |
|
94 | + $this->_valid_shortcodes = array(); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @see abstract declaration in EE_messenger for details. |
|
100 | + */ |
|
101 | + protected function _set_validator_config() |
|
102 | + { |
|
103 | + $this->_validator_config = array( |
|
104 | + 'subject' => array( |
|
105 | + 'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime') |
|
106 | + ), |
|
107 | + 'content' => array( |
|
108 | + 'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime') |
|
109 | + ), |
|
110 | + 'attendee_list' => array( |
|
111 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
112 | + 'required' => array('[ATTENDEE_LIST]') |
|
113 | + ), |
|
114 | + 'event_list' => array( |
|
115 | + 'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'venue', 'datetime_list', 'attendee', 'primary_registration_details', 'primary_registration_list', 'event_author', 'recipient_details', 'recipient_list'), |
|
116 | + 'required' => array('[EVENT_LIST]') |
|
117 | + ), |
|
118 | + 'ticket_list' => array( |
|
119 | + 'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'primary_registration_details', 'recipient_details'), |
|
120 | + 'required' => array('[TICKET_LIST]') |
|
121 | + ), |
|
122 | + 'datetime_list' => array( |
|
123 | + 'shortcodes' => array('datetime'), |
|
124 | + 'required' => array('[DATETIME_LIST]') |
|
125 | + ), |
|
126 | + ); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this messenger can add their own js. |
|
132 | + * |
|
133 | + * @return void. |
|
134 | + */ |
|
135 | + public function enqueue_scripts_styles() |
|
136 | + { |
|
137 | + parent::enqueue_scripts_styles(); |
|
138 | + do_action('AHEE__EE_Pdf_messenger__enqueue_scripts_styles'); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * _set_template_fields |
|
144 | + * This sets up the fields that a messenger requires for the message to go out. |
|
145 | + * |
|
146 | + * @access protected |
|
147 | + * @return void |
|
148 | + */ |
|
149 | + protected function _set_template_fields() |
|
150 | + { |
|
151 | + // any extra template fields that are NOT used by the messenger but will get used by a messenger field for shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field they relate to. This is important for the Messages_admin to know what fields to display to the user. Also, notice that the "values" are equal to the field type that messages admin will use to know what kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and will not be displayed/parsed. |
|
152 | + $this->_template_fields = array( |
|
153 | + 'subject' => array( |
|
154 | + 'input' => 'text', |
|
155 | + 'label' => __('Page Title', 'event_espresso'), |
|
156 | + 'type' => 'string', |
|
157 | + 'required' => true, |
|
158 | + 'validation' => true, |
|
159 | + 'css_class' => 'large-text', |
|
160 | + 'format' => '%s' |
|
161 | + ), |
|
162 | + 'content' => '', // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
163 | + 'extra' => array( |
|
164 | + 'content' => array( |
|
165 | + 'main' => array( |
|
166 | + 'input' => 'wp_editor', |
|
167 | + 'label' => __('Main Content', 'event_espresso'), |
|
168 | + 'type' => 'string', |
|
169 | + 'required' => true, |
|
170 | + 'validation' => true, |
|
171 | + 'format' => '%s', |
|
172 | + 'rows' => '15' |
|
173 | + ), |
|
174 | + 'event_list' => array( |
|
175 | + 'input' => 'wp_editor', |
|
176 | + 'label' => '[EVENT_LIST]', |
|
177 | + 'type' => 'string', |
|
178 | + 'required' => true, |
|
179 | + 'validation' => true, |
|
180 | + 'format' => '%s', |
|
181 | + 'rows' => '15', |
|
182 | + 'shortcodes_required' => array('[EVENT_LIST]') |
|
183 | + ), |
|
184 | + 'attendee_list' => array( |
|
185 | + 'input' => 'textarea', |
|
186 | + 'label' => '[ATTENDEE_LIST]', |
|
187 | + 'type' => 'string', |
|
188 | + 'required' => true, |
|
189 | + 'validation' => true, |
|
190 | + 'format' => '%s', |
|
191 | + 'css_class' => 'large-text', |
|
192 | + 'rows' => '5', |
|
193 | + 'shortcodes_required' => array('[ATTENDEE_LIST]') |
|
194 | + ), |
|
195 | + 'ticket_list' => array( |
|
196 | + 'input' => 'textarea', |
|
197 | + 'label' => '[TICKET_LIST]', |
|
198 | + 'type' => 'string', |
|
199 | + 'required' => true, |
|
200 | + 'validation' => true, |
|
201 | + 'format' => '%s', |
|
202 | + 'css_class' => 'large-text', |
|
203 | + 'rows' => '10', |
|
204 | + 'shortcodes_required' => array('[TICKET_LIST]') |
|
205 | + ), |
|
206 | + 'datetime_list' => array( |
|
207 | + 'input' => 'textarea', |
|
208 | + 'label' => '[DATETIME_LIST]', |
|
209 | + 'type' => 'string', |
|
210 | + 'required' => true, |
|
211 | + 'validation' => true, |
|
212 | + 'format' => '%s', |
|
213 | + 'css_class' => 'large-text', |
|
214 | + 'rows' => '10', |
|
215 | + 'shortcodes_required' => array('[DATETIME_LIST]') |
|
216 | + ) |
|
217 | + ) |
|
218 | + ) |
|
219 | + ); |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * @see definition of this method in parent |
|
225 | + * |
|
226 | + * @since 4.5.0 |
|
227 | + * |
|
228 | + */ |
|
229 | + protected function _set_default_message_types() |
|
230 | + { |
|
231 | + // note currently PDF is only a secondary messenger so it never has any associated message types. |
|
232 | + $this->_default_message_types = array(); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * @see definition of this method in parent |
|
238 | + * |
|
239 | + * @since 4.5.0 |
|
240 | + */ |
|
241 | + protected function _set_valid_message_types() |
|
242 | + { |
|
243 | + $this->_valid_message_types = array(); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Generates html version of the message content and then sends it to the pdf generator. |
|
249 | + * |
|
250 | + * |
|
251 | + * @since 4.5.0 |
|
252 | + * |
|
253 | + * @return string. |
|
254 | + */ |
|
255 | + protected function _send_message() |
|
256 | + { |
|
257 | + $this->_template_args = array( |
|
258 | + 'page_title' => $this->_subject, |
|
259 | + 'base_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'base', $this->_variation), |
|
260 | + 'print_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'print', $this->_variation), |
|
261 | + 'main_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'main', $this->_variation), |
|
262 | + 'extra_css' => EE_LIBRARIES_URL . 'messages/defaults/default/variations/pdf_base_default.css', |
|
263 | + 'main_body' => apply_filters('FHEE__EE_Pdf_messenger___send_message__main_body', wpautop($this->_content), $this->_content) |
|
264 | + ); |
|
265 | + $this->_deregister_wp_hooks(); |
|
266 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
267 | + $content = $this->_get_main_template(); |
|
268 | 268 | // die( $content ); |
269 | - $this->_do_pdf($content); |
|
270 | - exit(0); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't interfere with our templates. If users want to add any custom styles or scripts they must use the AHEE__EE_Pdf_messenger__enqueue_scripts_styles hook. |
|
276 | - * |
|
277 | - * @since 4.5.0 |
|
278 | - * |
|
279 | - * @return void |
|
280 | - */ |
|
281 | - protected function _deregister_wp_hooks() |
|
282 | - { |
|
283 | - remove_all_actions('wp_head'); |
|
284 | - remove_all_actions('wp_footer'); |
|
285 | - remove_all_actions('wp_print_footer_scripts'); |
|
286 | - remove_all_actions('wp_enqueue_scripts'); |
|
287 | - global $wp_scripts, $wp_styles; |
|
288 | - $wp_scripts = $wp_styles = array(); |
|
289 | - |
|
290 | - // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load. |
|
291 | - add_action('wp_head', 'wp_enqueue_scripts'); |
|
292 | - add_action('wp_footer', 'wp_print_footer_scripts'); |
|
293 | - add_action('wp_print_footer_scripts', '_wp_footer_scripts'); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Overwrite parent _get_main_template for pdf purposes. |
|
299 | - * |
|
300 | - * @since 4.5.0 |
|
301 | - * |
|
302 | - * @param bool $preview |
|
303 | - * @return string |
|
304 | - */ |
|
305 | - protected function _get_main_template($preview = false) |
|
306 | - { |
|
307 | - $wrapper_template = $this->_tmp_pack->get_wrapper('html', 'main'); |
|
308 | - // add message type to template_args |
|
309 | - $this->_template_args['message_type'] = $this->_incoming_message_type; |
|
310 | - return EEH_Template::display_template($wrapper_template, $this->_template_args, true); |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * This takes care of loading the dompdf library and generating the actual pdf |
|
316 | - * |
|
317 | - * @param string $content This is the generated html content being converted into a pdf. |
|
318 | - * |
|
319 | - * @return void |
|
320 | - */ |
|
321 | - protected function _do_pdf($content = '') |
|
322 | - { |
|
323 | - $invoice_name = $this->_subject; |
|
324 | - |
|
325 | - // only load dompdf if nobody else has yet... |
|
326 | - if (! class_exists('Dompdf\Dompdf')) { |
|
327 | - require_once(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php'); |
|
328 | - Dompdf\Autoloader::register(); |
|
329 | - } |
|
330 | - $options = new Dompdf\Options(); |
|
331 | - $options->set('isRemoteEnabled', true); |
|
332 | - $options->set('isJavascriptEnabled', false); |
|
333 | - if (defined('DOMPDF_FONT_DIR')) { |
|
334 | - $options->setFontDir(DOMPDF_FONT_DIR); |
|
335 | - $options->setFontCache(DOMPDF_FONT_DIR); |
|
336 | - } |
|
337 | - $dompdf = new Dompdf\Dompdf($options); |
|
338 | - // Remove all spaces between HTML tags |
|
339 | - $content = preg_replace('/>\s+</', '><', $content); |
|
340 | - $dompdf->loadHtml($content); |
|
341 | - $dompdf->render(); |
|
342 | - // forcing the browser to open a download dialog. |
|
343 | - $dompdf->stream($invoice_name . ".pdf", array('Attachment' => true)); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * @return string |
|
349 | - */ |
|
350 | - protected function _preview() |
|
351 | - { |
|
352 | - return $this->_send_message(); |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - protected function _set_admin_settings_fields() |
|
357 | - { |
|
358 | - } |
|
269 | + $this->_do_pdf($content); |
|
270 | + exit(0); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't interfere with our templates. If users want to add any custom styles or scripts they must use the AHEE__EE_Pdf_messenger__enqueue_scripts_styles hook. |
|
276 | + * |
|
277 | + * @since 4.5.0 |
|
278 | + * |
|
279 | + * @return void |
|
280 | + */ |
|
281 | + protected function _deregister_wp_hooks() |
|
282 | + { |
|
283 | + remove_all_actions('wp_head'); |
|
284 | + remove_all_actions('wp_footer'); |
|
285 | + remove_all_actions('wp_print_footer_scripts'); |
|
286 | + remove_all_actions('wp_enqueue_scripts'); |
|
287 | + global $wp_scripts, $wp_styles; |
|
288 | + $wp_scripts = $wp_styles = array(); |
|
289 | + |
|
290 | + // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load. |
|
291 | + add_action('wp_head', 'wp_enqueue_scripts'); |
|
292 | + add_action('wp_footer', 'wp_print_footer_scripts'); |
|
293 | + add_action('wp_print_footer_scripts', '_wp_footer_scripts'); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Overwrite parent _get_main_template for pdf purposes. |
|
299 | + * |
|
300 | + * @since 4.5.0 |
|
301 | + * |
|
302 | + * @param bool $preview |
|
303 | + * @return string |
|
304 | + */ |
|
305 | + protected function _get_main_template($preview = false) |
|
306 | + { |
|
307 | + $wrapper_template = $this->_tmp_pack->get_wrapper('html', 'main'); |
|
308 | + // add message type to template_args |
|
309 | + $this->_template_args['message_type'] = $this->_incoming_message_type; |
|
310 | + return EEH_Template::display_template($wrapper_template, $this->_template_args, true); |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * This takes care of loading the dompdf library and generating the actual pdf |
|
316 | + * |
|
317 | + * @param string $content This is the generated html content being converted into a pdf. |
|
318 | + * |
|
319 | + * @return void |
|
320 | + */ |
|
321 | + protected function _do_pdf($content = '') |
|
322 | + { |
|
323 | + $invoice_name = $this->_subject; |
|
324 | + |
|
325 | + // only load dompdf if nobody else has yet... |
|
326 | + if (! class_exists('Dompdf\Dompdf')) { |
|
327 | + require_once(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php'); |
|
328 | + Dompdf\Autoloader::register(); |
|
329 | + } |
|
330 | + $options = new Dompdf\Options(); |
|
331 | + $options->set('isRemoteEnabled', true); |
|
332 | + $options->set('isJavascriptEnabled', false); |
|
333 | + if (defined('DOMPDF_FONT_DIR')) { |
|
334 | + $options->setFontDir(DOMPDF_FONT_DIR); |
|
335 | + $options->setFontCache(DOMPDF_FONT_DIR); |
|
336 | + } |
|
337 | + $dompdf = new Dompdf\Dompdf($options); |
|
338 | + // Remove all spaces between HTML tags |
|
339 | + $content = preg_replace('/>\s+</', '><', $content); |
|
340 | + $dompdf->loadHtml($content); |
|
341 | + $dompdf->render(); |
|
342 | + // forcing the browser to open a download dialog. |
|
343 | + $dompdf->stream($invoice_name . ".pdf", array('Attachment' => true)); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * @return string |
|
349 | + */ |
|
350 | + protected function _preview() |
|
351 | + { |
|
352 | + return $this->_send_message(); |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + protected function _set_admin_settings_fields() |
|
357 | + { |
|
358 | + } |
|
359 | 359 | } |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | 7 => "union.css", |
84 | 84 | ); |
85 | 85 | // Get the CSS file |
86 | - if (isset($themes[ $theme_requested ])) { |
|
87 | - $template_args['invoice_css'] = $themes[ $theme_requested ]; |
|
86 | + if (isset($themes[$theme_requested])) { |
|
87 | + $template_args['invoice_css'] = $themes[$theme_requested]; |
|
88 | 88 | } else { |
89 | 89 | $template_args['invoice_css'] = $this->invoice_payment_method->get_extra_meta( |
90 | 90 | 'legacy_invoice_css', |
@@ -93,17 +93,17 @@ discard block |
||
93 | 93 | ); |
94 | 94 | } |
95 | 95 | |
96 | - if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) { |
|
97 | - $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/'; |
|
96 | + if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR.'/invoice')) { |
|
97 | + $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL.'Invoice/lib/templates/'; |
|
98 | 98 | } else { |
99 | - $template_args['base_url'] = EE_GATEWAYS . '/Invoice/lib/templates/'; |
|
99 | + $template_args['base_url'] = EE_GATEWAYS.'/Invoice/lib/templates/'; |
|
100 | 100 | } |
101 | 101 | $primary_attendee = $this->transaction->primary_registration()->attendee(); |
102 | 102 | |
103 | 103 | $template_args['organization'] = $EE->CFG->organization->get_pretty('name'); |
104 | 104 | $template_args['street'] = empty($EE->CFG->organization->address_2) ? $EE->CFG->organization->get_pretty( |
105 | 105 | 'address_1' |
106 | - ) : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty('address_2'); |
|
106 | + ) : $EE->CFG->organization->get_pretty('address_1').'<br>'.$EE->CFG->organization->get_pretty('address_2'); |
|
107 | 107 | $template_args['city'] = $EE->CFG->organization->get_pretty('city'); |
108 | 108 | $template_args['state'] = EE_Registry::instance()->load_model('State')->get_one_by_ID( |
109 | 109 | $EE->CFG->organization->STA_ID |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | if ($template_args['amount_pd'] != $template_args['total_cost']) { |
150 | 150 | // $template_args['net_total'] = $this->espressoInvoiceTotals( __('SubTotal', 'event_espresso'), $this->transaction->total());//$this->session_data['cart']['REG']['sub_total']); |
151 | 151 | $tax_items = $this->transaction->tax_items(); |
152 | - if (! empty($tax_items)) { |
|
152 | + if ( ! empty($tax_items)) { |
|
153 | 153 | foreach ($tax_items as $tax) { |
154 | 154 | $template_args['net_total'] .= $this->espressoInvoiceTotals($tax->name(), $tax->total()); |
155 | 155 | } |
@@ -183,13 +183,13 @@ discard block |
||
183 | 183 | $line_items_for_this_event = EEM_Line_Item::instance()->get_all( |
184 | 184 | array(array('Ticket.Datetime.EVT_ID' => $event_id, 'TXN_ID' => $this->transaction->ID())) |
185 | 185 | ); |
186 | - $ticket_line_items_per_event[ $event_id ] = $line_items_for_this_event; |
|
186 | + $ticket_line_items_per_event[$event_id] = $line_items_for_this_event; |
|
187 | 187 | foreach ($line_items_for_this_event as $line_item_id => $line_item) { |
188 | 188 | $ticket = $line_item->ticket(); |
189 | 189 | $registrations_for_this_ticket = EEM_Registration::instance()->get_all( |
190 | 190 | array(array('TKT_ID' => $ticket->ID(), 'TXN_ID' => $this->transaction->ID())) |
191 | 191 | ); |
192 | - $registrations_per_line_item[ $line_item_id ] = $registrations_for_this_ticket; |
|
192 | + $registrations_per_line_item[$line_item_id] = $registrations_for_this_ticket; |
|
193 | 193 | } |
194 | 194 | $venues_for_events = array_merge($venues_for_events, $event->venues()); |
195 | 195 | } |
@@ -219,21 +219,21 @@ discard block |
||
219 | 219 | // Get the HTML as an object |
220 | 220 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
221 | 221 | $template_header = EEH_Template::locate_template( |
222 | - $templates_relative_path . 'invoice_header.template.php', |
|
222 | + $templates_relative_path.'invoice_header.template.php', |
|
223 | 223 | $template_args, |
224 | 224 | true, |
225 | 225 | true |
226 | 226 | ); |
227 | 227 | if (isset($_GET['receipt'])) { |
228 | 228 | $template_body = EEH_Template::locate_template( |
229 | - $templates_relative_path . 'receipt_body.template.php', |
|
229 | + $templates_relative_path.'receipt_body.template.php', |
|
230 | 230 | $template_args, |
231 | 231 | true, |
232 | 232 | true |
233 | 233 | ); |
234 | 234 | } else { |
235 | 235 | $template_body = EEH_Template::locate_template( |
236 | - $templates_relative_path . 'invoice_body.template.php', |
|
236 | + $templates_relative_path.'invoice_body.template.php', |
|
237 | 237 | $template_args, |
238 | 238 | true, |
239 | 239 | true |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | |
243 | 243 | |
244 | 244 | $template_footer = EEH_Template::locate_template( |
245 | - $templates_relative_path . 'invoice_footer.template.php', |
|
245 | + $templates_relative_path.'invoice_footer.template.php', |
|
246 | 246 | $template_args, |
247 | 247 | true, |
248 | 248 | true |
@@ -257,22 +257,22 @@ discard block |
||
257 | 257 | $content .= $this->espresso_replace_invoice_shortcodes($template_footer); |
258 | 258 | |
259 | 259 | // Check if debugging or mobile is set |
260 | - if (! empty($_REQUEST['html'])) { |
|
260 | + if ( ! empty($_REQUEST['html'])) { |
|
261 | 261 | echo $content; |
262 | 262 | exit(0); |
263 | 263 | } |
264 | - $invoice_name = $template_args['organization'] . ' ' . __( |
|
264 | + $invoice_name = $template_args['organization'].' '.__( |
|
265 | 265 | 'Invoice #', |
266 | 266 | 'event_espresso' |
267 | - ) . $template_args['registration_code'] . __(' for ', 'event_espresso') . $template_args['name']; |
|
267 | + ).$template_args['registration_code'].__(' for ', 'event_espresso').$template_args['name']; |
|
268 | 268 | $invoice_name = str_replace(' ', '_', $invoice_name); |
269 | 269 | // Create the PDF |
270 | 270 | if (array_key_exists('html', $_GET)) { |
271 | 271 | echo $content; |
272 | 272 | } else { |
273 | 273 | // only load dompdf if nobody else has yet... |
274 | - if (! class_exists('Dompdf\Dompdf')) { |
|
275 | - require_once(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php'); |
|
274 | + if ( ! class_exists('Dompdf\Dompdf')) { |
|
275 | + require_once(EE_THIRD_PARTY.'dompdf/src/Autoloader.php'); |
|
276 | 276 | Dompdf\Autoloader::register(); |
277 | 277 | } |
278 | 278 | $options = new Dompdf\Options(); |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | $dompdf = new Dompdf\Dompdf($options); |
282 | 282 | $dompdf->loadHtml($content); |
283 | 283 | $dompdf->render(); |
284 | - $dompdf->stream($invoice_name . ".pdf", array('Attachment' => $download)); |
|
284 | + $dompdf->stream($invoice_name.".pdf", array('Attachment' => $download)); |
|
285 | 285 | } |
286 | 286 | exit(0); |
287 | 287 | } |
@@ -319,9 +319,9 @@ discard block |
||
319 | 319 | true, |
320 | 320 | $EE->CFG->organization->logo_url |
321 | 321 | ); |
322 | - if (! empty($invoice_logo_url)) { |
|
322 | + if ( ! empty($invoice_logo_url)) { |
|
323 | 323 | $image_size = getimagesize($invoice_logo_url); |
324 | - $invoice_logo_image = '<img class="logo screen" src="' . $invoice_logo_url . '" ' . $image_size[3] . ' alt="logo" /> '; |
|
324 | + $invoice_logo_image = '<img class="logo screen" src="'.$invoice_logo_url.'" '.$image_size[3].' alt="logo" /> '; |
|
325 | 325 | } else { |
326 | 326 | $invoice_logo_image = ''; |
327 | 327 | } |
@@ -354,14 +354,14 @@ discard block |
||
354 | 354 | $this->registration->reg_code(), |
355 | 355 | $this->transaction->ID(), |
356 | 356 | $primary_attendee->full_name(), |
357 | - (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) ? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/' |
|
358 | - : EE_GATEWAYS_URL . 'Invoice/lib/templates/', |
|
357 | + (is_dir(EVENT_ESPRESSO_GATEWAY_DIR.'/invoice')) ? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/' |
|
358 | + : EE_GATEWAYS_URL.'Invoice/lib/templates/', |
|
359 | 359 | $this->registration->invoice_url(), |
360 | 360 | // home_url() . '/?download_invoice=true&id=' . $this->registration->reg_url_link(), |
361 | 361 | $invoice_logo_image, |
362 | 362 | empty($EE->CFG->organization->address_2) |
363 | 363 | ? $EE->CFG->organization->get_pretty('address_1') |
364 | - : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty( |
|
364 | + : $EE->CFG->organization->get_pretty('address_1').'<br>'.$EE->CFG->organization->get_pretty( |
|
365 | 365 | 'address_2' |
366 | 366 | ), |
367 | 367 | $EE->CFG->organization->get_pretty('city'), |
@@ -398,9 +398,9 @@ discard block |
||
398 | 398 | $find = array(' '); |
399 | 399 | $replace = array('-'); |
400 | 400 | $row_id = strtolower(str_replace($find, $replace, $text)); |
401 | - $html .= '<tr id="' . $row_id . '-tr"><td colspan="4"> </td>'; |
|
402 | - $html .= '<td class="item_r">' . $text . '</td>'; |
|
403 | - $html .= '<td class="item_r">' . $total_cost . '</td>'; |
|
401 | + $html .= '<tr id="'.$row_id.'-tr"><td colspan="4"> </td>'; |
|
402 | + $html .= '<td class="item_r">'.$text.'</td>'; |
|
403 | + $html .= '<td class="item_r">'.$total_cost.'</td>'; |
|
404 | 404 | $html .= '</tr>'; |
405 | 405 | return $html; |
406 | 406 | } |
@@ -9,403 +9,403 @@ |
||
9 | 9 | class Invoice |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * |
|
14 | - * @var EE_Registration |
|
15 | - */ |
|
16 | - private $registration; |
|
17 | - /** |
|
18 | - * |
|
19 | - * @var EE_Transaction |
|
20 | - */ |
|
21 | - private $transaction; |
|
22 | - /** |
|
23 | - * |
|
24 | - * @var EE_Payment_Method |
|
25 | - */ |
|
26 | - private $invoice_payment_method; |
|
27 | - private $EE; |
|
12 | + /** |
|
13 | + * |
|
14 | + * @var EE_Registration |
|
15 | + */ |
|
16 | + private $registration; |
|
17 | + /** |
|
18 | + * |
|
19 | + * @var EE_Transaction |
|
20 | + */ |
|
21 | + private $transaction; |
|
22 | + /** |
|
23 | + * |
|
24 | + * @var EE_Payment_Method |
|
25 | + */ |
|
26 | + private $invoice_payment_method; |
|
27 | + private $EE; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * Invoice constructor. |
|
32 | - * |
|
33 | - * @deprecated 4.9.13 |
|
34 | - * @param int $url_link |
|
35 | - */ |
|
36 | - public function __construct($url_link = 0) |
|
37 | - { |
|
38 | - EE_Error::doing_it_wrong( |
|
39 | - __CLASS__, |
|
40 | - esc_html__( |
|
41 | - 'This class has been deprecated and replaced by the new Messages library.', |
|
42 | - 'event_espresso' |
|
43 | - ), |
|
44 | - '4.9.12', |
|
45 | - '5.0.0' |
|
46 | - ); |
|
47 | - if ($this->registration = EE_Registry::instance()->load_model( |
|
48 | - 'Registration' |
|
49 | - )->get_registration_for_reg_url_link($url_link)) { |
|
50 | - $this->transaction = $this->registration->transaction(); |
|
51 | - // get_user_meta(EE_Registry::instance()->CFG->wp_user, 'payment_settings', TRUE); |
|
52 | - $payment_settings = EE_Config::instance()->gateway->payment_settings; |
|
53 | - $this->invoice_payment_method = EEM_Payment_Method::instance()->get_one_of_type('Invoice'); |
|
54 | - } else { |
|
55 | - EE_Error::add_error( |
|
56 | - __( |
|
57 | - 'Your request appears to be missing some required data, and no information for your transaction could be retrieved.', |
|
58 | - 'event_espresso' |
|
59 | - ), |
|
60 | - __FILE__, |
|
61 | - __FUNCTION__, |
|
62 | - __LINE__ |
|
63 | - ); |
|
64 | - } |
|
65 | - } |
|
30 | + /** |
|
31 | + * Invoice constructor. |
|
32 | + * |
|
33 | + * @deprecated 4.9.13 |
|
34 | + * @param int $url_link |
|
35 | + */ |
|
36 | + public function __construct($url_link = 0) |
|
37 | + { |
|
38 | + EE_Error::doing_it_wrong( |
|
39 | + __CLASS__, |
|
40 | + esc_html__( |
|
41 | + 'This class has been deprecated and replaced by the new Messages library.', |
|
42 | + 'event_espresso' |
|
43 | + ), |
|
44 | + '4.9.12', |
|
45 | + '5.0.0' |
|
46 | + ); |
|
47 | + if ($this->registration = EE_Registry::instance()->load_model( |
|
48 | + 'Registration' |
|
49 | + )->get_registration_for_reg_url_link($url_link)) { |
|
50 | + $this->transaction = $this->registration->transaction(); |
|
51 | + // get_user_meta(EE_Registry::instance()->CFG->wp_user, 'payment_settings', TRUE); |
|
52 | + $payment_settings = EE_Config::instance()->gateway->payment_settings; |
|
53 | + $this->invoice_payment_method = EEM_Payment_Method::instance()->get_one_of_type('Invoice'); |
|
54 | + } else { |
|
55 | + EE_Error::add_error( |
|
56 | + __( |
|
57 | + 'Your request appears to be missing some required data, and no information for your transaction could be retrieved.', |
|
58 | + 'event_espresso' |
|
59 | + ), |
|
60 | + __FILE__, |
|
61 | + __FUNCTION__, |
|
62 | + __LINE__ |
|
63 | + ); |
|
64 | + } |
|
65 | + } |
|
66 | 66 | |
67 | - public function send_invoice($download = false) |
|
68 | - { |
|
69 | - $template_args = array(); |
|
70 | - $EE = EE_Registry::instance(); |
|
67 | + public function send_invoice($download = false) |
|
68 | + { |
|
69 | + $template_args = array(); |
|
70 | + $EE = EE_Registry::instance(); |
|
71 | 71 | |
72 | - // allow the request to override the default theme defined in the invoice settings |
|
73 | - $theme_requested = (isset($_REQUEST['theme']) && $_REQUEST['theme'] > 0 && $_REQUEST['theme'] < 8) ? absint( |
|
74 | - $_REQUEST['theme'] |
|
75 | - ) : null; |
|
76 | - $themes = array( |
|
77 | - 1 => "simple.css", |
|
78 | - 2 => "bauhaus.css", |
|
79 | - 3 => "ejs.css", |
|
80 | - 4 => "horizon.css", |
|
81 | - 5 => "lola.css", |
|
82 | - 6 => "tranquility.css", |
|
83 | - 7 => "union.css", |
|
84 | - ); |
|
85 | - // Get the CSS file |
|
86 | - if (isset($themes[ $theme_requested ])) { |
|
87 | - $template_args['invoice_css'] = $themes[ $theme_requested ]; |
|
88 | - } else { |
|
89 | - $template_args['invoice_css'] = $this->invoice_payment_method->get_extra_meta( |
|
90 | - 'legacy_invoice_css', |
|
91 | - true, |
|
92 | - 'simple.css' |
|
93 | - ); |
|
94 | - } |
|
72 | + // allow the request to override the default theme defined in the invoice settings |
|
73 | + $theme_requested = (isset($_REQUEST['theme']) && $_REQUEST['theme'] > 0 && $_REQUEST['theme'] < 8) ? absint( |
|
74 | + $_REQUEST['theme'] |
|
75 | + ) : null; |
|
76 | + $themes = array( |
|
77 | + 1 => "simple.css", |
|
78 | + 2 => "bauhaus.css", |
|
79 | + 3 => "ejs.css", |
|
80 | + 4 => "horizon.css", |
|
81 | + 5 => "lola.css", |
|
82 | + 6 => "tranquility.css", |
|
83 | + 7 => "union.css", |
|
84 | + ); |
|
85 | + // Get the CSS file |
|
86 | + if (isset($themes[ $theme_requested ])) { |
|
87 | + $template_args['invoice_css'] = $themes[ $theme_requested ]; |
|
88 | + } else { |
|
89 | + $template_args['invoice_css'] = $this->invoice_payment_method->get_extra_meta( |
|
90 | + 'legacy_invoice_css', |
|
91 | + true, |
|
92 | + 'simple.css' |
|
93 | + ); |
|
94 | + } |
|
95 | 95 | |
96 | - if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) { |
|
97 | - $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/'; |
|
98 | - } else { |
|
99 | - $template_args['base_url'] = EE_GATEWAYS . '/Invoice/lib/templates/'; |
|
100 | - } |
|
101 | - $primary_attendee = $this->transaction->primary_registration()->attendee(); |
|
96 | + if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) { |
|
97 | + $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/'; |
|
98 | + } else { |
|
99 | + $template_args['base_url'] = EE_GATEWAYS . '/Invoice/lib/templates/'; |
|
100 | + } |
|
101 | + $primary_attendee = $this->transaction->primary_registration()->attendee(); |
|
102 | 102 | |
103 | - $template_args['organization'] = $EE->CFG->organization->get_pretty('name'); |
|
104 | - $template_args['street'] = empty($EE->CFG->organization->address_2) ? $EE->CFG->organization->get_pretty( |
|
105 | - 'address_1' |
|
106 | - ) : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty('address_2'); |
|
107 | - $template_args['city'] = $EE->CFG->organization->get_pretty('city'); |
|
108 | - $template_args['state'] = EE_Registry::instance()->load_model('State')->get_one_by_ID( |
|
109 | - $EE->CFG->organization->STA_ID |
|
110 | - ); |
|
111 | - $template_args['country'] = EE_Registry::instance()->load_model('Country')->get_one_by_ID( |
|
112 | - $EE->CFG->organization->CNT_ISO |
|
113 | - ); |
|
114 | - $template_args['zip'] = $EE->CFG->organization->get_pretty('zip'); |
|
115 | - $template_args['email'] = $EE->CFG->organization->get_pretty('email'); |
|
103 | + $template_args['organization'] = $EE->CFG->organization->get_pretty('name'); |
|
104 | + $template_args['street'] = empty($EE->CFG->organization->address_2) ? $EE->CFG->organization->get_pretty( |
|
105 | + 'address_1' |
|
106 | + ) : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty('address_2'); |
|
107 | + $template_args['city'] = $EE->CFG->organization->get_pretty('city'); |
|
108 | + $template_args['state'] = EE_Registry::instance()->load_model('State')->get_one_by_ID( |
|
109 | + $EE->CFG->organization->STA_ID |
|
110 | + ); |
|
111 | + $template_args['country'] = EE_Registry::instance()->load_model('Country')->get_one_by_ID( |
|
112 | + $EE->CFG->organization->CNT_ISO |
|
113 | + ); |
|
114 | + $template_args['zip'] = $EE->CFG->organization->get_pretty('zip'); |
|
115 | + $template_args['email'] = $EE->CFG->organization->get_pretty('email'); |
|
116 | 116 | |
117 | - $template_args['registration_code'] = $this->registration->reg_code(); |
|
118 | - $template_args['registration_date'] = $this->registration->date(); |
|
119 | - $template_args['name'] = $primary_attendee->full_name(); |
|
120 | - $template_args['attendee_address'] = $primary_attendee->address(); |
|
121 | - $template_args['attendee_address2'] = $primary_attendee->address2(); |
|
122 | - $template_args['attendee_city'] = $primary_attendee->city(); |
|
123 | - $attendee_state = $primary_attendee->state_obj(); |
|
124 | - if ($attendee_state) { |
|
125 | - $attendee_state_name = $attendee_state->name(); |
|
126 | - } else { |
|
127 | - $attendee_state_name = ''; |
|
128 | - } |
|
129 | - $template_args['attendee_state'] = $attendee_state_name; |
|
130 | - $template_args['attendee_zip'] = $primary_attendee->zip(); |
|
117 | + $template_args['registration_code'] = $this->registration->reg_code(); |
|
118 | + $template_args['registration_date'] = $this->registration->date(); |
|
119 | + $template_args['name'] = $primary_attendee->full_name(); |
|
120 | + $template_args['attendee_address'] = $primary_attendee->address(); |
|
121 | + $template_args['attendee_address2'] = $primary_attendee->address2(); |
|
122 | + $template_args['attendee_city'] = $primary_attendee->city(); |
|
123 | + $attendee_state = $primary_attendee->state_obj(); |
|
124 | + if ($attendee_state) { |
|
125 | + $attendee_state_name = $attendee_state->name(); |
|
126 | + } else { |
|
127 | + $attendee_state_name = ''; |
|
128 | + } |
|
129 | + $template_args['attendee_state'] = $attendee_state_name; |
|
130 | + $template_args['attendee_zip'] = $primary_attendee->zip(); |
|
131 | 131 | |
132 | - $template_args['ship_name'] = $template_args['name']; |
|
133 | - $template_args['ship_address'] = $template_args['attendee_address']; |
|
134 | - $template_args['ship_city'] = $template_args['attendee_city']; |
|
135 | - $template_args['ship_state'] = $template_args['attendee_state']; |
|
136 | - $template_args['ship_zip'] = $template_args['attendee_zip']; |
|
132 | + $template_args['ship_name'] = $template_args['name']; |
|
133 | + $template_args['ship_address'] = $template_args['attendee_address']; |
|
134 | + $template_args['ship_city'] = $template_args['attendee_city']; |
|
135 | + $template_args['ship_state'] = $template_args['attendee_state']; |
|
136 | + $template_args['ship_zip'] = $template_args['attendee_zip']; |
|
137 | 137 | |
138 | - $template_args['total_cost'] = number_format($this->transaction->total(), 2, '.', ''); |
|
139 | - $template_args['transaction'] = $this->transaction; |
|
140 | - $template_args['amount_pd'] = $this->transaction->paid(); |
|
141 | - $template_args['amount_owed'] = $this->transaction->total() - $this->transaction->paid(); |
|
142 | - $template_args['payments'] = $this->transaction->approved_payments(); |
|
143 | - $template_args['net_total'] = ''; |
|
144 | - $template_args['edit_reg_info_url'] = $this->registration->edit_attendee_information_url(); |
|
145 | - $template_args['retry_payment_url'] = $this->registration->payment_overview_url(); |
|
146 | - $template_args['show_line_item_description'] = $this->check_if_any_line_items_have_a_description( |
|
147 | - $this->transaction->total_line_item() |
|
148 | - ); |
|
149 | - if ($template_args['amount_pd'] != $template_args['total_cost']) { |
|
150 | - // $template_args['net_total'] = $this->espressoInvoiceTotals( __('SubTotal', 'event_espresso'), $this->transaction->total());//$this->session_data['cart']['REG']['sub_total']); |
|
151 | - $tax_items = $this->transaction->tax_items(); |
|
152 | - if (! empty($tax_items)) { |
|
153 | - foreach ($tax_items as $tax) { |
|
154 | - $template_args['net_total'] .= $this->espressoInvoiceTotals($tax->name(), $tax->total()); |
|
155 | - } |
|
156 | - } |
|
138 | + $template_args['total_cost'] = number_format($this->transaction->total(), 2, '.', ''); |
|
139 | + $template_args['transaction'] = $this->transaction; |
|
140 | + $template_args['amount_pd'] = $this->transaction->paid(); |
|
141 | + $template_args['amount_owed'] = $this->transaction->total() - $this->transaction->paid(); |
|
142 | + $template_args['payments'] = $this->transaction->approved_payments(); |
|
143 | + $template_args['net_total'] = ''; |
|
144 | + $template_args['edit_reg_info_url'] = $this->registration->edit_attendee_information_url(); |
|
145 | + $template_args['retry_payment_url'] = $this->registration->payment_overview_url(); |
|
146 | + $template_args['show_line_item_description'] = $this->check_if_any_line_items_have_a_description( |
|
147 | + $this->transaction->total_line_item() |
|
148 | + ); |
|
149 | + if ($template_args['amount_pd'] != $template_args['total_cost']) { |
|
150 | + // $template_args['net_total'] = $this->espressoInvoiceTotals( __('SubTotal', 'event_espresso'), $this->transaction->total());//$this->session_data['cart']['REG']['sub_total']); |
|
151 | + $tax_items = $this->transaction->tax_items(); |
|
152 | + if (! empty($tax_items)) { |
|
153 | + foreach ($tax_items as $tax) { |
|
154 | + $template_args['net_total'] .= $this->espressoInvoiceTotals($tax->name(), $tax->total()); |
|
155 | + } |
|
156 | + } |
|
157 | 157 | |
158 | - $difference = $template_args['amount_pd'] - $template_args['total_cost']; |
|
159 | - if ($difference < 0) { |
|
160 | - $text = __('Discount', 'event_espresso'); |
|
161 | - } else { |
|
162 | - $text = __('Extra', 'event_espresso'); |
|
163 | - } |
|
164 | - $template_args['discount'] = $this->espressoInvoiceTotals($text, $difference); |
|
165 | - } |
|
158 | + $difference = $template_args['amount_pd'] - $template_args['total_cost']; |
|
159 | + if ($difference < 0) { |
|
160 | + $text = __('Discount', 'event_espresso'); |
|
161 | + } else { |
|
162 | + $text = __('Extra', 'event_espresso'); |
|
163 | + } |
|
164 | + $template_args['discount'] = $this->espressoInvoiceTotals($text, $difference); |
|
165 | + } |
|
166 | 166 | |
167 | - $template_args['currency_symbol'] = $EE->CFG->currency->sign; |
|
168 | - $template_args['template_payment_instructions'] = wpautop( |
|
169 | - stripslashes_deep( |
|
170 | - html_entity_decode($this->invoice_payment_method->get_extra_meta('pdf_instructions', true), ENT_QUOTES) |
|
171 | - ) |
|
172 | - ); |
|
173 | - $template_args['shameless_plug'] = apply_filters('FHEE_Invoice__send_invoice__shameless_plug', true); |
|
174 | - if (isset($_GET['receipt'])) { |
|
175 | - // receipt-specific stuff |
|
176 | - $events_for_txn = EEM_Event::instance()->get_all( |
|
177 | - array(array('Registration.TXN_ID' => $this->transaction->ID())) |
|
178 | - ); |
|
179 | - $ticket_line_items_per_event = array(); |
|
180 | - $registrations_per_line_item = array(); |
|
181 | - $venues_for_events = array(); |
|
182 | - foreach ($events_for_txn as $event_id => $event) { |
|
183 | - $line_items_for_this_event = EEM_Line_Item::instance()->get_all( |
|
184 | - array(array('Ticket.Datetime.EVT_ID' => $event_id, 'TXN_ID' => $this->transaction->ID())) |
|
185 | - ); |
|
186 | - $ticket_line_items_per_event[ $event_id ] = $line_items_for_this_event; |
|
187 | - foreach ($line_items_for_this_event as $line_item_id => $line_item) { |
|
188 | - $ticket = $line_item->ticket(); |
|
189 | - $registrations_for_this_ticket = EEM_Registration::instance()->get_all( |
|
190 | - array(array('TKT_ID' => $ticket->ID(), 'TXN_ID' => $this->transaction->ID())) |
|
191 | - ); |
|
192 | - $registrations_per_line_item[ $line_item_id ] = $registrations_for_this_ticket; |
|
193 | - } |
|
194 | - $venues_for_events = array_merge($venues_for_events, $event->venues()); |
|
195 | - } |
|
196 | - $tax_total_line_item = EEM_Line_Item::instance()->get_one( |
|
197 | - array(array('TXN_ID' => $this->transaction->ID(), 'LIN_type' => EEM_Line_Item::type_tax_sub_total)) |
|
198 | - ); |
|
199 | - $questions_to_skip = array( |
|
200 | - EEM_Attendee::system_question_fname, |
|
201 | - EEM_Attendee::system_question_lname, |
|
202 | - EEM_Attendee::system_question_email, |
|
203 | - ); |
|
167 | + $template_args['currency_symbol'] = $EE->CFG->currency->sign; |
|
168 | + $template_args['template_payment_instructions'] = wpautop( |
|
169 | + stripslashes_deep( |
|
170 | + html_entity_decode($this->invoice_payment_method->get_extra_meta('pdf_instructions', true), ENT_QUOTES) |
|
171 | + ) |
|
172 | + ); |
|
173 | + $template_args['shameless_plug'] = apply_filters('FHEE_Invoice__send_invoice__shameless_plug', true); |
|
174 | + if (isset($_GET['receipt'])) { |
|
175 | + // receipt-specific stuff |
|
176 | + $events_for_txn = EEM_Event::instance()->get_all( |
|
177 | + array(array('Registration.TXN_ID' => $this->transaction->ID())) |
|
178 | + ); |
|
179 | + $ticket_line_items_per_event = array(); |
|
180 | + $registrations_per_line_item = array(); |
|
181 | + $venues_for_events = array(); |
|
182 | + foreach ($events_for_txn as $event_id => $event) { |
|
183 | + $line_items_for_this_event = EEM_Line_Item::instance()->get_all( |
|
184 | + array(array('Ticket.Datetime.EVT_ID' => $event_id, 'TXN_ID' => $this->transaction->ID())) |
|
185 | + ); |
|
186 | + $ticket_line_items_per_event[ $event_id ] = $line_items_for_this_event; |
|
187 | + foreach ($line_items_for_this_event as $line_item_id => $line_item) { |
|
188 | + $ticket = $line_item->ticket(); |
|
189 | + $registrations_for_this_ticket = EEM_Registration::instance()->get_all( |
|
190 | + array(array('TKT_ID' => $ticket->ID(), 'TXN_ID' => $this->transaction->ID())) |
|
191 | + ); |
|
192 | + $registrations_per_line_item[ $line_item_id ] = $registrations_for_this_ticket; |
|
193 | + } |
|
194 | + $venues_for_events = array_merge($venues_for_events, $event->venues()); |
|
195 | + } |
|
196 | + $tax_total_line_item = EEM_Line_Item::instance()->get_one( |
|
197 | + array(array('TXN_ID' => $this->transaction->ID(), 'LIN_type' => EEM_Line_Item::type_tax_sub_total)) |
|
198 | + ); |
|
199 | + $questions_to_skip = array( |
|
200 | + EEM_Attendee::system_question_fname, |
|
201 | + EEM_Attendee::system_question_lname, |
|
202 | + EEM_Attendee::system_question_email, |
|
203 | + ); |
|
204 | 204 | |
205 | 205 | |
206 | - $template_args['events_for_txn'] = $events_for_txn; |
|
207 | - $template_args['ticket_line_items_per_event'] = $ticket_line_items_per_event; |
|
208 | - $template_args['registrations_per_line_item'] = $registrations_per_line_item; |
|
209 | - $template_args['venues_for_events'] = $venues_for_events; |
|
210 | - $template_args['tax_total_line_item'] = $tax_total_line_item; |
|
211 | - $template_args['questions_to_skip'] = $questions_to_skip; |
|
212 | - // d($template_args); |
|
213 | - $template_args['download_link'] = $this->registration->receipt_url('download'); |
|
214 | - } else { |
|
215 | - // it's just an invoice we're accessing |
|
216 | - $template_args['download_link'] = $this->registration->invoice_url('download'); |
|
217 | - } |
|
206 | + $template_args['events_for_txn'] = $events_for_txn; |
|
207 | + $template_args['ticket_line_items_per_event'] = $ticket_line_items_per_event; |
|
208 | + $template_args['registrations_per_line_item'] = $registrations_per_line_item; |
|
209 | + $template_args['venues_for_events'] = $venues_for_events; |
|
210 | + $template_args['tax_total_line_item'] = $tax_total_line_item; |
|
211 | + $template_args['questions_to_skip'] = $questions_to_skip; |
|
212 | + // d($template_args); |
|
213 | + $template_args['download_link'] = $this->registration->receipt_url('download'); |
|
214 | + } else { |
|
215 | + // it's just an invoice we're accessing |
|
216 | + $template_args['download_link'] = $this->registration->invoice_url('download'); |
|
217 | + } |
|
218 | 218 | |
219 | - // Get the HTML as an object |
|
220 | - $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
221 | - $template_header = EEH_Template::locate_template( |
|
222 | - $templates_relative_path . 'invoice_header.template.php', |
|
223 | - $template_args, |
|
224 | - true, |
|
225 | - true |
|
226 | - ); |
|
227 | - if (isset($_GET['receipt'])) { |
|
228 | - $template_body = EEH_Template::locate_template( |
|
229 | - $templates_relative_path . 'receipt_body.template.php', |
|
230 | - $template_args, |
|
231 | - true, |
|
232 | - true |
|
233 | - ); |
|
234 | - } else { |
|
235 | - $template_body = EEH_Template::locate_template( |
|
236 | - $templates_relative_path . 'invoice_body.template.php', |
|
237 | - $template_args, |
|
238 | - true, |
|
239 | - true |
|
240 | - ); |
|
241 | - } |
|
219 | + // Get the HTML as an object |
|
220 | + $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
221 | + $template_header = EEH_Template::locate_template( |
|
222 | + $templates_relative_path . 'invoice_header.template.php', |
|
223 | + $template_args, |
|
224 | + true, |
|
225 | + true |
|
226 | + ); |
|
227 | + if (isset($_GET['receipt'])) { |
|
228 | + $template_body = EEH_Template::locate_template( |
|
229 | + $templates_relative_path . 'receipt_body.template.php', |
|
230 | + $template_args, |
|
231 | + true, |
|
232 | + true |
|
233 | + ); |
|
234 | + } else { |
|
235 | + $template_body = EEH_Template::locate_template( |
|
236 | + $templates_relative_path . 'invoice_body.template.php', |
|
237 | + $template_args, |
|
238 | + true, |
|
239 | + true |
|
240 | + ); |
|
241 | + } |
|
242 | 242 | |
243 | 243 | |
244 | - $template_footer = EEH_Template::locate_template( |
|
245 | - $templates_relative_path . 'invoice_footer.template.php', |
|
246 | - $template_args, |
|
247 | - true, |
|
248 | - true |
|
249 | - ); |
|
244 | + $template_footer = EEH_Template::locate_template( |
|
245 | + $templates_relative_path . 'invoice_footer.template.php', |
|
246 | + $template_args, |
|
247 | + true, |
|
248 | + true |
|
249 | + ); |
|
250 | 250 | |
251 | - $copies = ! empty($_REQUEST['copies']) ? $_REQUEST['copies'] : 1; |
|
251 | + $copies = ! empty($_REQUEST['copies']) ? $_REQUEST['copies'] : 1; |
|
252 | 252 | |
253 | - $content = $this->espresso_replace_invoice_shortcodes($template_header); |
|
254 | - for ($x = 1; $x <= $copies; $x++) { |
|
255 | - $content .= $this->espresso_replace_invoice_shortcodes($template_body); |
|
256 | - } |
|
257 | - $content .= $this->espresso_replace_invoice_shortcodes($template_footer); |
|
253 | + $content = $this->espresso_replace_invoice_shortcodes($template_header); |
|
254 | + for ($x = 1; $x <= $copies; $x++) { |
|
255 | + $content .= $this->espresso_replace_invoice_shortcodes($template_body); |
|
256 | + } |
|
257 | + $content .= $this->espresso_replace_invoice_shortcodes($template_footer); |
|
258 | 258 | |
259 | - // Check if debugging or mobile is set |
|
260 | - if (! empty($_REQUEST['html'])) { |
|
261 | - echo $content; |
|
262 | - exit(0); |
|
263 | - } |
|
264 | - $invoice_name = $template_args['organization'] . ' ' . __( |
|
265 | - 'Invoice #', |
|
266 | - 'event_espresso' |
|
267 | - ) . $template_args['registration_code'] . __(' for ', 'event_espresso') . $template_args['name']; |
|
268 | - $invoice_name = str_replace(' ', '_', $invoice_name); |
|
269 | - // Create the PDF |
|
270 | - if (array_key_exists('html', $_GET)) { |
|
271 | - echo $content; |
|
272 | - } else { |
|
273 | - // only load dompdf if nobody else has yet... |
|
274 | - if (! class_exists('Dompdf\Dompdf')) { |
|
275 | - require_once(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php'); |
|
276 | - Dompdf\Autoloader::register(); |
|
277 | - } |
|
278 | - $options = new Dompdf\Options(); |
|
279 | - $options->set('isRemoteEnabled', true); |
|
280 | - $options->set('isJavascriptEnabled', false); |
|
281 | - if (defined('DOMPDF_FONT_DIR')) { |
|
282 | - $options->setFontDir(DOMPDF_FONT_DIR); |
|
283 | - $options->setFontCache(DOMPDF_FONT_DIR); |
|
284 | - } |
|
285 | - $dompdf = new Dompdf\Dompdf($options); |
|
286 | - $dompdf->loadHtml($content); |
|
287 | - $dompdf->render(); |
|
288 | - $dompdf->stream($invoice_name . ".pdf", array('Attachment' => $download)); |
|
289 | - } |
|
290 | - exit(0); |
|
291 | - } |
|
259 | + // Check if debugging or mobile is set |
|
260 | + if (! empty($_REQUEST['html'])) { |
|
261 | + echo $content; |
|
262 | + exit(0); |
|
263 | + } |
|
264 | + $invoice_name = $template_args['organization'] . ' ' . __( |
|
265 | + 'Invoice #', |
|
266 | + 'event_espresso' |
|
267 | + ) . $template_args['registration_code'] . __(' for ', 'event_espresso') . $template_args['name']; |
|
268 | + $invoice_name = str_replace(' ', '_', $invoice_name); |
|
269 | + // Create the PDF |
|
270 | + if (array_key_exists('html', $_GET)) { |
|
271 | + echo $content; |
|
272 | + } else { |
|
273 | + // only load dompdf if nobody else has yet... |
|
274 | + if (! class_exists('Dompdf\Dompdf')) { |
|
275 | + require_once(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php'); |
|
276 | + Dompdf\Autoloader::register(); |
|
277 | + } |
|
278 | + $options = new Dompdf\Options(); |
|
279 | + $options->set('isRemoteEnabled', true); |
|
280 | + $options->set('isJavascriptEnabled', false); |
|
281 | + if (defined('DOMPDF_FONT_DIR')) { |
|
282 | + $options->setFontDir(DOMPDF_FONT_DIR); |
|
283 | + $options->setFontCache(DOMPDF_FONT_DIR); |
|
284 | + } |
|
285 | + $dompdf = new Dompdf\Dompdf($options); |
|
286 | + $dompdf->loadHtml($content); |
|
287 | + $dompdf->render(); |
|
288 | + $dompdf->stream($invoice_name . ".pdf", array('Attachment' => $download)); |
|
289 | + } |
|
290 | + exit(0); |
|
291 | + } |
|
292 | 292 | |
293 | - /** |
|
294 | - * Checks if this line item, or any of its children, actually has a description. |
|
295 | - * If none do, then the template can decide to not show any description column |
|
296 | - * |
|
297 | - * @param EE_Line_Item $line_item |
|
298 | - * @return boolean |
|
299 | - */ |
|
300 | - public function check_if_any_line_items_have_a_description(EE_Line_Item $line_item) |
|
301 | - { |
|
302 | - if ($line_item->desc()) { |
|
303 | - return true; |
|
304 | - } else { |
|
305 | - foreach ($line_item->children() as $child_line_item) { |
|
306 | - if ($this->check_if_any_line_items_have_a_description($child_line_item)) { |
|
307 | - return true; |
|
308 | - } |
|
309 | - } |
|
310 | - // well, if I and my children don't have descriptions, I guess not |
|
311 | - return false; |
|
312 | - } |
|
313 | - } |
|
293 | + /** |
|
294 | + * Checks if this line item, or any of its children, actually has a description. |
|
295 | + * If none do, then the template can decide to not show any description column |
|
296 | + * |
|
297 | + * @param EE_Line_Item $line_item |
|
298 | + * @return boolean |
|
299 | + */ |
|
300 | + public function check_if_any_line_items_have_a_description(EE_Line_Item $line_item) |
|
301 | + { |
|
302 | + if ($line_item->desc()) { |
|
303 | + return true; |
|
304 | + } else { |
|
305 | + foreach ($line_item->children() as $child_line_item) { |
|
306 | + if ($this->check_if_any_line_items_have_a_description($child_line_item)) { |
|
307 | + return true; |
|
308 | + } |
|
309 | + } |
|
310 | + // well, if I and my children don't have descriptions, I guess not |
|
311 | + return false; |
|
312 | + } |
|
313 | + } |
|
314 | 314 | |
315 | 315 | // Perform the shortcode replacement |
316 | - public function espresso_replace_invoice_shortcodes($content) |
|
317 | - { |
|
316 | + public function espresso_replace_invoice_shortcodes($content) |
|
317 | + { |
|
318 | 318 | |
319 | - $EE = EE_Registry::instance(); |
|
320 | - // Create the logo |
|
321 | - $invoice_logo_url = $this->invoice_payment_method->get_extra_meta( |
|
322 | - 'pdf_logo_image', |
|
323 | - true, |
|
324 | - $EE->CFG->organization->logo_url |
|
325 | - ); |
|
326 | - if (! empty($invoice_logo_url)) { |
|
327 | - $image_size = getimagesize($invoice_logo_url); |
|
328 | - $invoice_logo_image = '<img class="logo screen" src="' . $invoice_logo_url . '" ' . $image_size[3] . ' alt="logo" /> '; |
|
329 | - } else { |
|
330 | - $invoice_logo_image = ''; |
|
331 | - } |
|
332 | - $SearchValues = array( |
|
333 | - "[organization]", |
|
334 | - "[registration_code]", |
|
335 | - "[transaction_id]", |
|
336 | - "[name]", |
|
337 | - "[base_url]", |
|
338 | - "[download_link]", |
|
339 | - "[invoice_logo_image]", |
|
340 | - "[street]", |
|
341 | - "[city]", |
|
342 | - "[state]", |
|
343 | - "[zip]", |
|
344 | - "[email]", |
|
345 | - "[vat]", |
|
346 | - "[registration_date]", |
|
347 | - "[instructions]", |
|
348 | - ); |
|
349 | - $primary_attendee = $this->transaction->primary_registration()->attendee(); |
|
350 | - $org_state = EE_Registry::instance()->load_model('State')->get_one_by_ID($EE->CFG->organization->STA_ID); |
|
351 | - if ($org_state) { |
|
352 | - $org_state_name = $org_state->name(); |
|
353 | - } else { |
|
354 | - $org_state_name = ''; |
|
355 | - } |
|
356 | - $ReplaceValues = array( |
|
357 | - $EE->CFG->organization->get_pretty('name'), |
|
358 | - $this->registration->reg_code(), |
|
359 | - $this->transaction->ID(), |
|
360 | - $primary_attendee->full_name(), |
|
361 | - (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) ? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/' |
|
362 | - : EE_GATEWAYS_URL . 'Invoice/lib/templates/', |
|
363 | - $this->registration->invoice_url(), |
|
364 | - // home_url() . '/?download_invoice=true&id=' . $this->registration->reg_url_link(), |
|
365 | - $invoice_logo_image, |
|
366 | - empty($EE->CFG->organization->address_2) |
|
367 | - ? $EE->CFG->organization->get_pretty('address_1') |
|
368 | - : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty( |
|
369 | - 'address_2' |
|
370 | - ), |
|
371 | - $EE->CFG->organization->get_pretty('city'), |
|
372 | - $org_state_name, |
|
373 | - $EE->CFG->organization->get_pretty('zip'), |
|
374 | - $EE->CFG->organization->get_pretty('email'), |
|
375 | - $EE->CFG->organization->vat, |
|
376 | - $this->registration->get_i18n_datetime('REG_date', get_option('date_format')), |
|
377 | - $this->invoice_payment_method->get_extra_meta('pdf_instructions', true), |
|
378 | - ); |
|
319 | + $EE = EE_Registry::instance(); |
|
320 | + // Create the logo |
|
321 | + $invoice_logo_url = $this->invoice_payment_method->get_extra_meta( |
|
322 | + 'pdf_logo_image', |
|
323 | + true, |
|
324 | + $EE->CFG->organization->logo_url |
|
325 | + ); |
|
326 | + if (! empty($invoice_logo_url)) { |
|
327 | + $image_size = getimagesize($invoice_logo_url); |
|
328 | + $invoice_logo_image = '<img class="logo screen" src="' . $invoice_logo_url . '" ' . $image_size[3] . ' alt="logo" /> '; |
|
329 | + } else { |
|
330 | + $invoice_logo_image = ''; |
|
331 | + } |
|
332 | + $SearchValues = array( |
|
333 | + "[organization]", |
|
334 | + "[registration_code]", |
|
335 | + "[transaction_id]", |
|
336 | + "[name]", |
|
337 | + "[base_url]", |
|
338 | + "[download_link]", |
|
339 | + "[invoice_logo_image]", |
|
340 | + "[street]", |
|
341 | + "[city]", |
|
342 | + "[state]", |
|
343 | + "[zip]", |
|
344 | + "[email]", |
|
345 | + "[vat]", |
|
346 | + "[registration_date]", |
|
347 | + "[instructions]", |
|
348 | + ); |
|
349 | + $primary_attendee = $this->transaction->primary_registration()->attendee(); |
|
350 | + $org_state = EE_Registry::instance()->load_model('State')->get_one_by_ID($EE->CFG->organization->STA_ID); |
|
351 | + if ($org_state) { |
|
352 | + $org_state_name = $org_state->name(); |
|
353 | + } else { |
|
354 | + $org_state_name = ''; |
|
355 | + } |
|
356 | + $ReplaceValues = array( |
|
357 | + $EE->CFG->organization->get_pretty('name'), |
|
358 | + $this->registration->reg_code(), |
|
359 | + $this->transaction->ID(), |
|
360 | + $primary_attendee->full_name(), |
|
361 | + (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) ? EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/' |
|
362 | + : EE_GATEWAYS_URL . 'Invoice/lib/templates/', |
|
363 | + $this->registration->invoice_url(), |
|
364 | + // home_url() . '/?download_invoice=true&id=' . $this->registration->reg_url_link(), |
|
365 | + $invoice_logo_image, |
|
366 | + empty($EE->CFG->organization->address_2) |
|
367 | + ? $EE->CFG->organization->get_pretty('address_1') |
|
368 | + : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty( |
|
369 | + 'address_2' |
|
370 | + ), |
|
371 | + $EE->CFG->organization->get_pretty('city'), |
|
372 | + $org_state_name, |
|
373 | + $EE->CFG->organization->get_pretty('zip'), |
|
374 | + $EE->CFG->organization->get_pretty('email'), |
|
375 | + $EE->CFG->organization->vat, |
|
376 | + $this->registration->get_i18n_datetime('REG_date', get_option('date_format')), |
|
377 | + $this->invoice_payment_method->get_extra_meta('pdf_instructions', true), |
|
378 | + ); |
|
379 | 379 | |
380 | - return str_replace($SearchValues, $ReplaceValues, $content); |
|
381 | - } |
|
380 | + return str_replace($SearchValues, $ReplaceValues, $content); |
|
381 | + } |
|
382 | 382 | |
383 | - public function espressoLoadData($items) |
|
384 | - { |
|
385 | - $lines = $items; |
|
386 | - $data = array(); |
|
387 | - foreach ($lines as $line) { |
|
388 | - $data[] = explode(';', chop($line)); |
|
389 | - } |
|
383 | + public function espressoLoadData($items) |
|
384 | + { |
|
385 | + $lines = $items; |
|
386 | + $data = array(); |
|
387 | + foreach ($lines as $line) { |
|
388 | + $data[] = explode(';', chop($line)); |
|
389 | + } |
|
390 | 390 | |
391 | - return $data; |
|
392 | - } |
|
391 | + return $data; |
|
392 | + } |
|
393 | 393 | |
394 | 394 | |
395 | - public function espressoInvoiceTotals($text, $total_cost) |
|
396 | - { |
|
395 | + public function espressoInvoiceTotals($text, $total_cost) |
|
396 | + { |
|
397 | 397 | |
398 | - $html = ''; |
|
399 | - if ($total_cost < 0) { |
|
400 | - $total_cost = (-1) * $total_cost; |
|
401 | - } |
|
402 | - $find = array(' '); |
|
403 | - $replace = array('-'); |
|
404 | - $row_id = strtolower(str_replace($find, $replace, $text)); |
|
405 | - $html .= '<tr id="' . $row_id . '-tr"><td colspan="4"> </td>'; |
|
406 | - $html .= '<td class="item_r">' . $text . '</td>'; |
|
407 | - $html .= '<td class="item_r">' . $total_cost . '</td>'; |
|
408 | - $html .= '</tr>'; |
|
409 | - return $html; |
|
410 | - } |
|
398 | + $html = ''; |
|
399 | + if ($total_cost < 0) { |
|
400 | + $total_cost = (-1) * $total_cost; |
|
401 | + } |
|
402 | + $find = array(' '); |
|
403 | + $replace = array('-'); |
|
404 | + $row_id = strtolower(str_replace($find, $replace, $text)); |
|
405 | + $html .= '<tr id="' . $row_id . '-tr"><td colspan="4"> </td>'; |
|
406 | + $html .= '<td class="item_r">' . $text . '</td>'; |
|
407 | + $html .= '<td class="item_r">' . $total_cost . '</td>'; |
|
408 | + $html .= '</tr>'; |
|
409 | + return $html; |
|
410 | + } |
|
411 | 411 | } |
@@ -16,445 +16,445 @@ |
||
16 | 16 | class EE_CPT_Strategy extends EE_Base |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var EE_CPT_Strategy $_instance |
|
21 | - */ |
|
22 | - private static $_instance; |
|
23 | - |
|
24 | - /** |
|
25 | - * the current page, if it utilizes CPTs |
|
26 | - * |
|
27 | - * @var array $CPT |
|
28 | - */ |
|
29 | - protected $CPT; |
|
30 | - |
|
31 | - /** |
|
32 | - * return value from CustomPostTypeDefinitions::getDefinitions() |
|
33 | - * |
|
34 | - * @var array $_CPTs |
|
35 | - */ |
|
36 | - protected $_CPTs = array(); |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array $_CPT_taxonomies |
|
40 | - */ |
|
41 | - protected $_CPT_taxonomies = array(); |
|
42 | - |
|
43 | - /** |
|
44 | - * @var array $_CPT_terms |
|
45 | - */ |
|
46 | - protected $_CPT_terms = array(); |
|
47 | - |
|
48 | - /** |
|
49 | - * @var array $_CPT_endpoints |
|
50 | - */ |
|
51 | - protected $_CPT_endpoints = array(); |
|
52 | - |
|
53 | - /** |
|
54 | - * @var EEM_Base $CPT_model |
|
55 | - */ |
|
56 | - protected $CPT_model; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier |
|
60 | - */ |
|
61 | - protected $query_modifier; |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @singleton method used to instantiate class object |
|
66 | - * @param CustomPostTypeDefinitions|null $custom_post_types |
|
67 | - * @param CustomTaxonomyDefinitions|null $taxonomies |
|
68 | - * @return EE_CPT_Strategy |
|
69 | - */ |
|
70 | - public static function instance( |
|
71 | - CustomPostTypeDefinitions $custom_post_types = null, |
|
72 | - CustomTaxonomyDefinitions $taxonomies = null |
|
73 | - ) { |
|
74 | - // check if class object is instantiated |
|
75 | - if (! self::$_instance instanceof EE_CPT_Strategy |
|
76 | - && $custom_post_types instanceof CustomPostTypeDefinitions |
|
77 | - && $taxonomies instanceof CustomTaxonomyDefinitions |
|
78 | - ) { |
|
79 | - self::$_instance = new self($custom_post_types, $taxonomies); |
|
80 | - } |
|
81 | - return self::$_instance; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @param CustomPostTypeDefinitions $custom_post_types |
|
87 | - * @param CustomTaxonomyDefinitions $taxonomies |
|
88 | - */ |
|
89 | - protected function __construct( |
|
90 | - CustomPostTypeDefinitions $custom_post_types, |
|
91 | - CustomTaxonomyDefinitions $taxonomies |
|
92 | - ) { |
|
93 | - // get CPT data |
|
94 | - $this->_CPTs = $custom_post_types->getDefinitions(); |
|
95 | - $this->_CPT_endpoints = $this->_set_CPT_endpoints(); |
|
96 | - $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions(); |
|
97 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 5); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - public function get_CPT_endpoints() |
|
105 | - { |
|
106 | - return $this->_CPT_endpoints; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @return array |
|
112 | - */ |
|
113 | - public function get_CPT_taxonomies() |
|
114 | - { |
|
115 | - return $this->_CPT_taxonomies; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * add CPT "slugs" to array of default espresso "pages" |
|
121 | - * |
|
122 | - * @return array |
|
123 | - */ |
|
124 | - private function _set_CPT_endpoints() |
|
125 | - { |
|
126 | - $_CPT_endpoints = array(); |
|
127 | - if (is_array($this->_CPTs)) { |
|
128 | - foreach ($this->_CPTs as $CPT_type => $CPT) { |
|
129 | - $_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type; |
|
130 | - } |
|
131 | - } |
|
132 | - return $_CPT_endpoints; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to |
|
138 | - * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and |
|
139 | - * adding EE objects to the post to facilitate further querying of related data etc) |
|
140 | - * |
|
141 | - * @param WP_Query $WP_Query |
|
142 | - * @return void |
|
143 | - * @throws \EE_Error |
|
144 | - * @throws \InvalidArgumentException |
|
145 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
146 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
147 | - */ |
|
148 | - public function pre_get_posts($WP_Query) |
|
149 | - { |
|
150 | - // check that post-type is set |
|
151 | - if (! $WP_Query instanceof WP_Query) { |
|
152 | - return; |
|
153 | - } |
|
154 | - // add our conditionals |
|
155 | - $this->_set_EE_tags_on_WP_Query($WP_Query); |
|
156 | - // check for terms |
|
157 | - $this->_set_post_type_for_terms($WP_Query); |
|
158 | - // make sure paging is always set |
|
159 | - $this->_set_paging($WP_Query); |
|
160 | - // is a taxonomy set ? |
|
161 | - $this->_set_CPT_taxonomies_on_WP_Query($WP_Query); |
|
162 | - // loop thru post_types if set |
|
163 | - $this->_process_WP_Query_post_types($WP_Query); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @param WP_Query $WP_Query |
|
169 | - * @return void |
|
170 | - */ |
|
171 | - private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query) |
|
172 | - { |
|
173 | - $WP_Query->is_espresso_event_single = false; |
|
174 | - $WP_Query->is_espresso_event_archive = false; |
|
175 | - $WP_Query->is_espresso_event_taxonomy = false; |
|
176 | - $WP_Query->is_espresso_venue_single = false; |
|
177 | - $WP_Query->is_espresso_venue_archive = false; |
|
178 | - $WP_Query->is_espresso_venue_taxonomy = false; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @return void |
|
184 | - * @throws EE_Error |
|
185 | - * @throws InvalidArgumentException |
|
186 | - * @throws InvalidDataTypeException |
|
187 | - * @throws InvalidInterfaceException |
|
188 | - */ |
|
189 | - private function _set_CPT_terms() |
|
190 | - { |
|
191 | - if (empty($this->_CPT_terms)) { |
|
192 | - $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
|
193 | - foreach ($terms as $term) { |
|
194 | - if ($term instanceof EE_Term) { |
|
195 | - $this->_CPT_terms[ $term->slug() ] = $term; |
|
196 | - } |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @param WP_Query $WP_Query |
|
204 | - * @return void |
|
205 | - * @throws EE_Error |
|
206 | - * @throws InvalidArgumentException |
|
207 | - * @throws InvalidDataTypeException |
|
208 | - * @throws InvalidInterfaceException |
|
209 | - */ |
|
210 | - private function _set_post_type_for_terms(WP_Query $WP_Query) |
|
211 | - { |
|
212 | - // is a tag set ? |
|
213 | - if (isset($WP_Query->query['tag'])) { |
|
214 | - // get term for tag |
|
215 | - $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($WP_Query->query['tag']); |
|
216 | - // verify the term |
|
217 | - if ($term instanceof EE_Term) { |
|
218 | - $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type); |
|
219 | - $term->post_type = apply_filters( |
|
220 | - 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', |
|
221 | - $term->post_type, |
|
222 | - $term |
|
223 | - ); |
|
224 | - // if a post type is already set |
|
225 | - if (isset($WP_Query->query_vars['post_type'])) { |
|
226 | - // add to existing array |
|
227 | - $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type); |
|
228 | - } |
|
229 | - // just set post_type to our CPT |
|
230 | - $WP_Query->set('post_type', array_unique($term->post_type)); |
|
231 | - } |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * @param WP_Query $WP_Query |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - public function _set_paging($WP_Query) |
|
241 | - { |
|
242 | - if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) { |
|
243 | - $page = get_query_var('page') ? get_query_var('page') : null; |
|
244 | - $paged = get_query_var('paged') ? get_query_var('paged') : $page; |
|
245 | - $WP_Query->set('paged', $paged); |
|
246 | - } |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param \WP_Query $WP_Query |
|
252 | - */ |
|
253 | - protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query) |
|
254 | - { |
|
255 | - // is a taxonomy set ? |
|
256 | - if ($WP_Query->is_tax) { |
|
257 | - // loop thru our taxonomies |
|
258 | - foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
|
259 | - // check if one of our taxonomies is set as a query var |
|
260 | - if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
261 | - // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
|
262 | - foreach ($this->_CPTs as $post_type => $CPT) { |
|
263 | - // verify our CPT has args, is public and has taxonomies set |
|
264 | - if (isset($CPT['args']['public']) |
|
265 | - && $CPT['args']['public'] |
|
266 | - && ! empty($CPT['args']['taxonomies']) |
|
267 | - && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true) |
|
268 | - ) { |
|
269 | - // if so, then add this CPT post_type to the current query's array of post_types' |
|
270 | - $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type']) |
|
271 | - ? (array) $WP_Query->query_vars['post_type'] |
|
272 | - : array(); |
|
273 | - $WP_Query->query_vars['post_type'][] = $post_type; |
|
274 | - switch ($post_type) { |
|
275 | - case 'espresso_events': |
|
276 | - $WP_Query->is_espresso_event_taxonomy = true; |
|
277 | - break; |
|
278 | - case 'espresso_venues': |
|
279 | - $WP_Query->is_espresso_venue_taxonomy = true; |
|
280 | - break; |
|
281 | - default: |
|
282 | - do_action( |
|
283 | - 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
284 | - $WP_Query, |
|
285 | - $this |
|
286 | - ); |
|
287 | - } |
|
288 | - } |
|
289 | - } |
|
290 | - } |
|
291 | - } |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * @param \WP_Query $WP_Query |
|
298 | - * @throws InvalidArgumentException |
|
299 | - * @throws InvalidDataTypeException |
|
300 | - * @throws InvalidInterfaceException |
|
301 | - */ |
|
302 | - protected function _process_WP_Query_post_types(WP_Query $WP_Query) |
|
303 | - { |
|
304 | - if (isset($WP_Query->query_vars['post_type'])) { |
|
305 | - // loop thru post_types as array |
|
306 | - foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
|
307 | - // is current query for an EE CPT ? |
|
308 | - if (isset($this->_CPTs[ $post_type ])) { |
|
309 | - // is EE on or off ? |
|
310 | - if (EE_Maintenance_Mode::instance()->level()) { |
|
311 | - // reroute CPT template view to maintenance_mode.template.php |
|
312 | - if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
313 | - add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
|
314 | - } |
|
315 | - if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
|
316 | - add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1); |
|
317 | - } |
|
318 | - return; |
|
319 | - } |
|
320 | - $this->_generate_CptQueryModifier($WP_Query, $post_type); |
|
321 | - } |
|
322 | - } |
|
323 | - } |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * @param \WP_Query $WP_Query |
|
329 | - * @param string $post_type |
|
330 | - * @throws InvalidArgumentException |
|
331 | - * @throws InvalidDataTypeException |
|
332 | - * @throws InvalidInterfaceException |
|
333 | - */ |
|
334 | - protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type) |
|
335 | - { |
|
336 | - $this->query_modifier = LoaderFactory::getLoader()->getShared( |
|
337 | - 'EventEspresso\core\CPTs\CptQueryModifier', |
|
338 | - array( |
|
339 | - $post_type, |
|
340 | - $this->_CPTs[ $post_type ], |
|
341 | - $WP_Query, |
|
342 | - ) |
|
343 | - ); |
|
344 | - $this->_CPT_taxonomies = $this->query_modifier->taxonomies(); |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * inject_EE_shortcode_placeholder |
|
350 | - * in order to display the M-Mode notice on our CPT routes, |
|
351 | - * we need to first inject what looks like one of our shortcodes, |
|
352 | - * so that it can be replaced with the actual M-Mode notice |
|
353 | - * |
|
354 | - * @return string |
|
355 | - */ |
|
356 | - public function inject_EE_shortcode_placeholder() |
|
357 | - { |
|
358 | - return '[ESPRESSO_'; |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * @deprecated |
|
364 | - * @since 4.8.41 |
|
365 | - * @return void |
|
366 | - */ |
|
367 | - public function _possibly_set_ee_request_var() |
|
368 | - { |
|
369 | - $this->query_modifier->setRequestVarsIfCpt(); |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * @deprecated |
|
375 | - * @since 4.8.41 |
|
376 | - * @param $SQL |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - public function posts_fields($SQL) |
|
380 | - { |
|
381 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
382 | - return $this->query_modifier->postsFields($SQL); |
|
383 | - } |
|
384 | - return $SQL; |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * @deprecated |
|
390 | - * @since 4.8.41 |
|
391 | - * @param $SQL |
|
392 | - * @return string |
|
393 | - */ |
|
394 | - public function posts_join($SQL) |
|
395 | - { |
|
396 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
397 | - return $this->query_modifier->postsJoin($SQL); |
|
398 | - } |
|
399 | - return $SQL; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * @deprecated |
|
405 | - * @since 4.8.41 |
|
406 | - * @param \WP_Post[] $posts |
|
407 | - * @return \WP_Post[] |
|
408 | - */ |
|
409 | - public function the_posts($posts) |
|
410 | - { |
|
411 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
412 | - $this->query_modifier->thePosts($posts); |
|
413 | - } |
|
414 | - return $posts; |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * @deprecated |
|
420 | - * @since 4.8.41 |
|
421 | - * @param $url |
|
422 | - * @param $ID |
|
423 | - * @return string |
|
424 | - */ |
|
425 | - public function get_edit_post_link($url, $ID) |
|
426 | - { |
|
427 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
428 | - return $this->query_modifier->getEditPostLink($url, $ID); |
|
429 | - } |
|
430 | - return ''; |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * @deprecated |
|
436 | - * @since 4.8.41 |
|
437 | - * @param null $WP_Query |
|
438 | - */ |
|
439 | - protected function _do_template_filters($WP_Query = null) |
|
440 | - { |
|
441 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
442 | - $this->query_modifier->addTemplateFilters(); |
|
443 | - } |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * @deprecated |
|
449 | - * @since 4.8.41 |
|
450 | - * @param string $current_template Existing default template path derived for this page call. |
|
451 | - * @return string the path to the full template file. |
|
452 | - */ |
|
453 | - public function single_cpt_template($current_template) |
|
454 | - { |
|
455 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
456 | - return $this->query_modifier->singleCptTemplate($current_template); |
|
457 | - } |
|
458 | - return $current_template; |
|
459 | - } |
|
19 | + /** |
|
20 | + * @var EE_CPT_Strategy $_instance |
|
21 | + */ |
|
22 | + private static $_instance; |
|
23 | + |
|
24 | + /** |
|
25 | + * the current page, if it utilizes CPTs |
|
26 | + * |
|
27 | + * @var array $CPT |
|
28 | + */ |
|
29 | + protected $CPT; |
|
30 | + |
|
31 | + /** |
|
32 | + * return value from CustomPostTypeDefinitions::getDefinitions() |
|
33 | + * |
|
34 | + * @var array $_CPTs |
|
35 | + */ |
|
36 | + protected $_CPTs = array(); |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array $_CPT_taxonomies |
|
40 | + */ |
|
41 | + protected $_CPT_taxonomies = array(); |
|
42 | + |
|
43 | + /** |
|
44 | + * @var array $_CPT_terms |
|
45 | + */ |
|
46 | + protected $_CPT_terms = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * @var array $_CPT_endpoints |
|
50 | + */ |
|
51 | + protected $_CPT_endpoints = array(); |
|
52 | + |
|
53 | + /** |
|
54 | + * @var EEM_Base $CPT_model |
|
55 | + */ |
|
56 | + protected $CPT_model; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier |
|
60 | + */ |
|
61 | + protected $query_modifier; |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @singleton method used to instantiate class object |
|
66 | + * @param CustomPostTypeDefinitions|null $custom_post_types |
|
67 | + * @param CustomTaxonomyDefinitions|null $taxonomies |
|
68 | + * @return EE_CPT_Strategy |
|
69 | + */ |
|
70 | + public static function instance( |
|
71 | + CustomPostTypeDefinitions $custom_post_types = null, |
|
72 | + CustomTaxonomyDefinitions $taxonomies = null |
|
73 | + ) { |
|
74 | + // check if class object is instantiated |
|
75 | + if (! self::$_instance instanceof EE_CPT_Strategy |
|
76 | + && $custom_post_types instanceof CustomPostTypeDefinitions |
|
77 | + && $taxonomies instanceof CustomTaxonomyDefinitions |
|
78 | + ) { |
|
79 | + self::$_instance = new self($custom_post_types, $taxonomies); |
|
80 | + } |
|
81 | + return self::$_instance; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @param CustomPostTypeDefinitions $custom_post_types |
|
87 | + * @param CustomTaxonomyDefinitions $taxonomies |
|
88 | + */ |
|
89 | + protected function __construct( |
|
90 | + CustomPostTypeDefinitions $custom_post_types, |
|
91 | + CustomTaxonomyDefinitions $taxonomies |
|
92 | + ) { |
|
93 | + // get CPT data |
|
94 | + $this->_CPTs = $custom_post_types->getDefinitions(); |
|
95 | + $this->_CPT_endpoints = $this->_set_CPT_endpoints(); |
|
96 | + $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions(); |
|
97 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 5); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + public function get_CPT_endpoints() |
|
105 | + { |
|
106 | + return $this->_CPT_endpoints; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @return array |
|
112 | + */ |
|
113 | + public function get_CPT_taxonomies() |
|
114 | + { |
|
115 | + return $this->_CPT_taxonomies; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * add CPT "slugs" to array of default espresso "pages" |
|
121 | + * |
|
122 | + * @return array |
|
123 | + */ |
|
124 | + private function _set_CPT_endpoints() |
|
125 | + { |
|
126 | + $_CPT_endpoints = array(); |
|
127 | + if (is_array($this->_CPTs)) { |
|
128 | + foreach ($this->_CPTs as $CPT_type => $CPT) { |
|
129 | + $_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type; |
|
130 | + } |
|
131 | + } |
|
132 | + return $_CPT_endpoints; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to |
|
138 | + * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and |
|
139 | + * adding EE objects to the post to facilitate further querying of related data etc) |
|
140 | + * |
|
141 | + * @param WP_Query $WP_Query |
|
142 | + * @return void |
|
143 | + * @throws \EE_Error |
|
144 | + * @throws \InvalidArgumentException |
|
145 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
146 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
147 | + */ |
|
148 | + public function pre_get_posts($WP_Query) |
|
149 | + { |
|
150 | + // check that post-type is set |
|
151 | + if (! $WP_Query instanceof WP_Query) { |
|
152 | + return; |
|
153 | + } |
|
154 | + // add our conditionals |
|
155 | + $this->_set_EE_tags_on_WP_Query($WP_Query); |
|
156 | + // check for terms |
|
157 | + $this->_set_post_type_for_terms($WP_Query); |
|
158 | + // make sure paging is always set |
|
159 | + $this->_set_paging($WP_Query); |
|
160 | + // is a taxonomy set ? |
|
161 | + $this->_set_CPT_taxonomies_on_WP_Query($WP_Query); |
|
162 | + // loop thru post_types if set |
|
163 | + $this->_process_WP_Query_post_types($WP_Query); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @param WP_Query $WP_Query |
|
169 | + * @return void |
|
170 | + */ |
|
171 | + private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query) |
|
172 | + { |
|
173 | + $WP_Query->is_espresso_event_single = false; |
|
174 | + $WP_Query->is_espresso_event_archive = false; |
|
175 | + $WP_Query->is_espresso_event_taxonomy = false; |
|
176 | + $WP_Query->is_espresso_venue_single = false; |
|
177 | + $WP_Query->is_espresso_venue_archive = false; |
|
178 | + $WP_Query->is_espresso_venue_taxonomy = false; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @return void |
|
184 | + * @throws EE_Error |
|
185 | + * @throws InvalidArgumentException |
|
186 | + * @throws InvalidDataTypeException |
|
187 | + * @throws InvalidInterfaceException |
|
188 | + */ |
|
189 | + private function _set_CPT_terms() |
|
190 | + { |
|
191 | + if (empty($this->_CPT_terms)) { |
|
192 | + $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
|
193 | + foreach ($terms as $term) { |
|
194 | + if ($term instanceof EE_Term) { |
|
195 | + $this->_CPT_terms[ $term->slug() ] = $term; |
|
196 | + } |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @param WP_Query $WP_Query |
|
204 | + * @return void |
|
205 | + * @throws EE_Error |
|
206 | + * @throws InvalidArgumentException |
|
207 | + * @throws InvalidDataTypeException |
|
208 | + * @throws InvalidInterfaceException |
|
209 | + */ |
|
210 | + private function _set_post_type_for_terms(WP_Query $WP_Query) |
|
211 | + { |
|
212 | + // is a tag set ? |
|
213 | + if (isset($WP_Query->query['tag'])) { |
|
214 | + // get term for tag |
|
215 | + $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($WP_Query->query['tag']); |
|
216 | + // verify the term |
|
217 | + if ($term instanceof EE_Term) { |
|
218 | + $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type); |
|
219 | + $term->post_type = apply_filters( |
|
220 | + 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', |
|
221 | + $term->post_type, |
|
222 | + $term |
|
223 | + ); |
|
224 | + // if a post type is already set |
|
225 | + if (isset($WP_Query->query_vars['post_type'])) { |
|
226 | + // add to existing array |
|
227 | + $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type); |
|
228 | + } |
|
229 | + // just set post_type to our CPT |
|
230 | + $WP_Query->set('post_type', array_unique($term->post_type)); |
|
231 | + } |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * @param WP_Query $WP_Query |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + public function _set_paging($WP_Query) |
|
241 | + { |
|
242 | + if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) { |
|
243 | + $page = get_query_var('page') ? get_query_var('page') : null; |
|
244 | + $paged = get_query_var('paged') ? get_query_var('paged') : $page; |
|
245 | + $WP_Query->set('paged', $paged); |
|
246 | + } |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param \WP_Query $WP_Query |
|
252 | + */ |
|
253 | + protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query) |
|
254 | + { |
|
255 | + // is a taxonomy set ? |
|
256 | + if ($WP_Query->is_tax) { |
|
257 | + // loop thru our taxonomies |
|
258 | + foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
|
259 | + // check if one of our taxonomies is set as a query var |
|
260 | + if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
261 | + // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
|
262 | + foreach ($this->_CPTs as $post_type => $CPT) { |
|
263 | + // verify our CPT has args, is public and has taxonomies set |
|
264 | + if (isset($CPT['args']['public']) |
|
265 | + && $CPT['args']['public'] |
|
266 | + && ! empty($CPT['args']['taxonomies']) |
|
267 | + && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true) |
|
268 | + ) { |
|
269 | + // if so, then add this CPT post_type to the current query's array of post_types' |
|
270 | + $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type']) |
|
271 | + ? (array) $WP_Query->query_vars['post_type'] |
|
272 | + : array(); |
|
273 | + $WP_Query->query_vars['post_type'][] = $post_type; |
|
274 | + switch ($post_type) { |
|
275 | + case 'espresso_events': |
|
276 | + $WP_Query->is_espresso_event_taxonomy = true; |
|
277 | + break; |
|
278 | + case 'espresso_venues': |
|
279 | + $WP_Query->is_espresso_venue_taxonomy = true; |
|
280 | + break; |
|
281 | + default: |
|
282 | + do_action( |
|
283 | + 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
284 | + $WP_Query, |
|
285 | + $this |
|
286 | + ); |
|
287 | + } |
|
288 | + } |
|
289 | + } |
|
290 | + } |
|
291 | + } |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * @param \WP_Query $WP_Query |
|
298 | + * @throws InvalidArgumentException |
|
299 | + * @throws InvalidDataTypeException |
|
300 | + * @throws InvalidInterfaceException |
|
301 | + */ |
|
302 | + protected function _process_WP_Query_post_types(WP_Query $WP_Query) |
|
303 | + { |
|
304 | + if (isset($WP_Query->query_vars['post_type'])) { |
|
305 | + // loop thru post_types as array |
|
306 | + foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
|
307 | + // is current query for an EE CPT ? |
|
308 | + if (isset($this->_CPTs[ $post_type ])) { |
|
309 | + // is EE on or off ? |
|
310 | + if (EE_Maintenance_Mode::instance()->level()) { |
|
311 | + // reroute CPT template view to maintenance_mode.template.php |
|
312 | + if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
313 | + add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
|
314 | + } |
|
315 | + if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
|
316 | + add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1); |
|
317 | + } |
|
318 | + return; |
|
319 | + } |
|
320 | + $this->_generate_CptQueryModifier($WP_Query, $post_type); |
|
321 | + } |
|
322 | + } |
|
323 | + } |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * @param \WP_Query $WP_Query |
|
329 | + * @param string $post_type |
|
330 | + * @throws InvalidArgumentException |
|
331 | + * @throws InvalidDataTypeException |
|
332 | + * @throws InvalidInterfaceException |
|
333 | + */ |
|
334 | + protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type) |
|
335 | + { |
|
336 | + $this->query_modifier = LoaderFactory::getLoader()->getShared( |
|
337 | + 'EventEspresso\core\CPTs\CptQueryModifier', |
|
338 | + array( |
|
339 | + $post_type, |
|
340 | + $this->_CPTs[ $post_type ], |
|
341 | + $WP_Query, |
|
342 | + ) |
|
343 | + ); |
|
344 | + $this->_CPT_taxonomies = $this->query_modifier->taxonomies(); |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * inject_EE_shortcode_placeholder |
|
350 | + * in order to display the M-Mode notice on our CPT routes, |
|
351 | + * we need to first inject what looks like one of our shortcodes, |
|
352 | + * so that it can be replaced with the actual M-Mode notice |
|
353 | + * |
|
354 | + * @return string |
|
355 | + */ |
|
356 | + public function inject_EE_shortcode_placeholder() |
|
357 | + { |
|
358 | + return '[ESPRESSO_'; |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * @deprecated |
|
364 | + * @since 4.8.41 |
|
365 | + * @return void |
|
366 | + */ |
|
367 | + public function _possibly_set_ee_request_var() |
|
368 | + { |
|
369 | + $this->query_modifier->setRequestVarsIfCpt(); |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * @deprecated |
|
375 | + * @since 4.8.41 |
|
376 | + * @param $SQL |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + public function posts_fields($SQL) |
|
380 | + { |
|
381 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
382 | + return $this->query_modifier->postsFields($SQL); |
|
383 | + } |
|
384 | + return $SQL; |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * @deprecated |
|
390 | + * @since 4.8.41 |
|
391 | + * @param $SQL |
|
392 | + * @return string |
|
393 | + */ |
|
394 | + public function posts_join($SQL) |
|
395 | + { |
|
396 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
397 | + return $this->query_modifier->postsJoin($SQL); |
|
398 | + } |
|
399 | + return $SQL; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * @deprecated |
|
405 | + * @since 4.8.41 |
|
406 | + * @param \WP_Post[] $posts |
|
407 | + * @return \WP_Post[] |
|
408 | + */ |
|
409 | + public function the_posts($posts) |
|
410 | + { |
|
411 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
412 | + $this->query_modifier->thePosts($posts); |
|
413 | + } |
|
414 | + return $posts; |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * @deprecated |
|
420 | + * @since 4.8.41 |
|
421 | + * @param $url |
|
422 | + * @param $ID |
|
423 | + * @return string |
|
424 | + */ |
|
425 | + public function get_edit_post_link($url, $ID) |
|
426 | + { |
|
427 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
428 | + return $this->query_modifier->getEditPostLink($url, $ID); |
|
429 | + } |
|
430 | + return ''; |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * @deprecated |
|
436 | + * @since 4.8.41 |
|
437 | + * @param null $WP_Query |
|
438 | + */ |
|
439 | + protected function _do_template_filters($WP_Query = null) |
|
440 | + { |
|
441 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
442 | + $this->query_modifier->addTemplateFilters(); |
|
443 | + } |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * @deprecated |
|
449 | + * @since 4.8.41 |
|
450 | + * @param string $current_template Existing default template path derived for this page call. |
|
451 | + * @return string the path to the full template file. |
|
452 | + */ |
|
453 | + public function single_cpt_template($current_template) |
|
454 | + { |
|
455 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
456 | + return $this->query_modifier->singleCptTemplate($current_template); |
|
457 | + } |
|
458 | + return $current_template; |
|
459 | + } |
|
460 | 460 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | CustomTaxonomyDefinitions $taxonomies = null |
73 | 73 | ) { |
74 | 74 | // check if class object is instantiated |
75 | - if (! self::$_instance instanceof EE_CPT_Strategy |
|
75 | + if ( ! self::$_instance instanceof EE_CPT_Strategy |
|
76 | 76 | && $custom_post_types instanceof CustomPostTypeDefinitions |
77 | 77 | && $taxonomies instanceof CustomTaxonomyDefinitions |
78 | 78 | ) { |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $_CPT_endpoints = array(); |
127 | 127 | if (is_array($this->_CPTs)) { |
128 | 128 | foreach ($this->_CPTs as $CPT_type => $CPT) { |
129 | - $_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type; |
|
129 | + $_CPT_endpoints [$CPT['plural_slug']] = $CPT_type; |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | return $_CPT_endpoints; |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | public function pre_get_posts($WP_Query) |
149 | 149 | { |
150 | 150 | // check that post-type is set |
151 | - if (! $WP_Query instanceof WP_Query) { |
|
151 | + if ( ! $WP_Query instanceof WP_Query) { |
|
152 | 152 | return; |
153 | 153 | } |
154 | 154 | // add our conditionals |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
193 | 193 | foreach ($terms as $term) { |
194 | 194 | if ($term instanceof EE_Term) { |
195 | - $this->_CPT_terms[ $term->slug() ] = $term; |
|
195 | + $this->_CPT_terms[$term->slug()] = $term; |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | } |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | // loop thru our taxonomies |
258 | 258 | foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
259 | 259 | // check if one of our taxonomies is set as a query var |
260 | - if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
260 | + if (isset($WP_Query->query[$CPT_taxonomy])) { |
|
261 | 261 | // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
262 | 262 | foreach ($this->_CPTs as $post_type => $CPT) { |
263 | 263 | // verify our CPT has args, is public and has taxonomies set |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | break; |
281 | 281 | default: |
282 | 282 | do_action( |
283 | - 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
283 | + 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_'.$post_type.'_post_type', |
|
284 | 284 | $WP_Query, |
285 | 285 | $this |
286 | 286 | ); |
@@ -305,11 +305,11 @@ discard block |
||
305 | 305 | // loop thru post_types as array |
306 | 306 | foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
307 | 307 | // is current query for an EE CPT ? |
308 | - if (isset($this->_CPTs[ $post_type ])) { |
|
308 | + if (isset($this->_CPTs[$post_type])) { |
|
309 | 309 | // is EE on or off ? |
310 | 310 | if (EE_Maintenance_Mode::instance()->level()) { |
311 | 311 | // reroute CPT template view to maintenance_mode.template.php |
312 | - if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
312 | + if ( ! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
313 | 313 | add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
314 | 314 | } |
315 | 315 | if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | 'EventEspresso\core\CPTs\CptQueryModifier', |
338 | 338 | array( |
339 | 339 | $post_type, |
340 | - $this->_CPTs[ $post_type ], |
|
340 | + $this->_CPTs[$post_type], |
|
341 | 341 | $WP_Query, |
342 | 342 | ) |
343 | 343 | ); |
@@ -14,263 +14,263 @@ |
||
14 | 14 | class EEM_Term extends EEM_Base |
15 | 15 | { |
16 | 16 | |
17 | - // private instance of the Attendee object |
|
18 | - protected static $_instance = null; |
|
17 | + // private instance of the Attendee object |
|
18 | + protected static $_instance = null; |
|
19 | 19 | |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - *__construct |
|
24 | - * |
|
25 | - * @param string $timezone |
|
26 | - */ |
|
27 | - protected function __construct($timezone = null) |
|
28 | - { |
|
29 | - $this->singular_item = __('Term', 'event_espresso'); |
|
30 | - $this->plural_item = __('Terms', 'event_espresso'); |
|
31 | - $this->_tables = array( |
|
32 | - 'Term' => new EE_Primary_Table('terms', 'term_id'), |
|
33 | - ); |
|
34 | - $this->_fields = array( |
|
35 | - 'Term' => array( |
|
36 | - 'term_id' => new EE_Primary_Key_Int_Field('term_id', __('Term ID', 'event_espresso')), |
|
37 | - 'name' => new EE_Plain_Text_Field('name', __('Term Name', 'event_espresso'), false, ''), |
|
38 | - 'slug' => new EE_Slug_Field('slug', __('Term Slug', 'event_espresso'), false), |
|
39 | - 'term_group' => new EE_Integer_Field('term_group', __("Term Group", "event_espresso"), false, 0), |
|
40 | - ), |
|
41 | - ); |
|
42 | - $this->_model_relations = array( |
|
43 | - 'Term_Taxonomy' => new EE_Has_Many_Relation(), |
|
44 | - ); |
|
45 | - $this->_wp_core_model = true; |
|
46 | - $path_to_tax_model = 'Term_Taxonomy'; |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
49 | - $path_to_tax_model |
|
50 | - ); |
|
51 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
52 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
53 | - $path_to_tax_model = $path_to_tax_model . '.'; |
|
54 | - // add cap restrictions for editing relating to the "ee_edit_*" |
|
55 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
56 | - array( |
|
57 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
58 | - ) |
|
59 | - ); |
|
60 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
61 | - array( |
|
62 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
63 | - ) |
|
64 | - ); |
|
65 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
66 | - array( |
|
67 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
68 | - ) |
|
69 | - ); |
|
70 | - // add cap restrictions for deleting relating to the "ee_deleting_*" |
|
71 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
72 | - array( |
|
73 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
74 | - ) |
|
75 | - ); |
|
76 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
77 | - array( |
|
78 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
79 | - ) |
|
80 | - ); |
|
81 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
82 | - array( |
|
83 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
84 | - ) |
|
85 | - ); |
|
86 | - parent::__construct($timezone); |
|
87 | - add_filter('FHEE__Read__create_model_query_params', array('EEM_Term', 'rest_api_query_params'), 10, 3); |
|
88 | - } |
|
22 | + /** |
|
23 | + *__construct |
|
24 | + * |
|
25 | + * @param string $timezone |
|
26 | + */ |
|
27 | + protected function __construct($timezone = null) |
|
28 | + { |
|
29 | + $this->singular_item = __('Term', 'event_espresso'); |
|
30 | + $this->plural_item = __('Terms', 'event_espresso'); |
|
31 | + $this->_tables = array( |
|
32 | + 'Term' => new EE_Primary_Table('terms', 'term_id'), |
|
33 | + ); |
|
34 | + $this->_fields = array( |
|
35 | + 'Term' => array( |
|
36 | + 'term_id' => new EE_Primary_Key_Int_Field('term_id', __('Term ID', 'event_espresso')), |
|
37 | + 'name' => new EE_Plain_Text_Field('name', __('Term Name', 'event_espresso'), false, ''), |
|
38 | + 'slug' => new EE_Slug_Field('slug', __('Term Slug', 'event_espresso'), false), |
|
39 | + 'term_group' => new EE_Integer_Field('term_group', __("Term Group", "event_espresso"), false, 0), |
|
40 | + ), |
|
41 | + ); |
|
42 | + $this->_model_relations = array( |
|
43 | + 'Term_Taxonomy' => new EE_Has_Many_Relation(), |
|
44 | + ); |
|
45 | + $this->_wp_core_model = true; |
|
46 | + $path_to_tax_model = 'Term_Taxonomy'; |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
48 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
49 | + $path_to_tax_model |
|
50 | + ); |
|
51 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
52 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
53 | + $path_to_tax_model = $path_to_tax_model . '.'; |
|
54 | + // add cap restrictions for editing relating to the "ee_edit_*" |
|
55 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
56 | + array( |
|
57 | + $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
58 | + ) |
|
59 | + ); |
|
60 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
61 | + array( |
|
62 | + $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
63 | + ) |
|
64 | + ); |
|
65 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
66 | + array( |
|
67 | + $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
68 | + ) |
|
69 | + ); |
|
70 | + // add cap restrictions for deleting relating to the "ee_deleting_*" |
|
71 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
72 | + array( |
|
73 | + $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
74 | + ) |
|
75 | + ); |
|
76 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
77 | + array( |
|
78 | + $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
79 | + ) |
|
80 | + ); |
|
81 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
82 | + array( |
|
83 | + $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
84 | + ) |
|
85 | + ); |
|
86 | + parent::__construct($timezone); |
|
87 | + add_filter('FHEE__Read__create_model_query_params', array('EEM_Term', 'rest_api_query_params'), 10, 3); |
|
88 | + } |
|
89 | 89 | |
90 | 90 | |
91 | 91 | |
92 | - /** |
|
93 | - * retrieves a list of all EE event categories |
|
94 | - * |
|
95 | - * @access public |
|
96 | - * @param bool $show_uncategorized |
|
97 | - * @return \EE_Base_Class[] |
|
98 | - */ |
|
99 | - public function get_all_ee_categories($show_uncategorized = false) |
|
100 | - { |
|
101 | - $where_params = array( |
|
102 | - 'Term_Taxonomy.taxonomy' => 'espresso_event_categories', |
|
103 | - 'NOT' => array('name' => __('Uncategorized', 'event_espresso')), |
|
104 | - ); |
|
105 | - if ($show_uncategorized) { |
|
106 | - unset($where_params['NOT']); |
|
107 | - } |
|
108 | - return EEM_Term::instance()->get_all( |
|
109 | - array( |
|
110 | - $where_params, |
|
111 | - 'order_by' => array('name' => 'ASC'), |
|
112 | - ) |
|
113 | - ); |
|
114 | - } |
|
92 | + /** |
|
93 | + * retrieves a list of all EE event categories |
|
94 | + * |
|
95 | + * @access public |
|
96 | + * @param bool $show_uncategorized |
|
97 | + * @return \EE_Base_Class[] |
|
98 | + */ |
|
99 | + public function get_all_ee_categories($show_uncategorized = false) |
|
100 | + { |
|
101 | + $where_params = array( |
|
102 | + 'Term_Taxonomy.taxonomy' => 'espresso_event_categories', |
|
103 | + 'NOT' => array('name' => __('Uncategorized', 'event_espresso')), |
|
104 | + ); |
|
105 | + if ($show_uncategorized) { |
|
106 | + unset($where_params['NOT']); |
|
107 | + } |
|
108 | + return EEM_Term::instance()->get_all( |
|
109 | + array( |
|
110 | + $where_params, |
|
111 | + 'order_by' => array('name' => 'ASC'), |
|
112 | + ) |
|
113 | + ); |
|
114 | + } |
|
115 | 115 | |
116 | 116 | |
117 | 117 | |
118 | - /** |
|
119 | - * retrieves a list of all post_tags associated with an EE CPT |
|
120 | - * |
|
121 | - * @access public |
|
122 | - * @param string $post_type |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public function get_all_CPT_post_tags($post_type = '') |
|
126 | - { |
|
127 | - switch ($post_type) { |
|
128 | - case 'espresso_events': |
|
129 | - return $this->get_all_event_post_tags(); |
|
130 | - break; |
|
131 | - case 'espresso_venues': |
|
132 | - return $this->get_all_venue_post_tags(); |
|
133 | - break; |
|
134 | - default: |
|
135 | - $event_tags = $this->get_all_event_post_tags(); |
|
136 | - $venue_tags = $this->get_all_venue_post_tags(); |
|
137 | - return array_merge($event_tags, $venue_tags); |
|
138 | - } |
|
139 | - } |
|
118 | + /** |
|
119 | + * retrieves a list of all post_tags associated with an EE CPT |
|
120 | + * |
|
121 | + * @access public |
|
122 | + * @param string $post_type |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public function get_all_CPT_post_tags($post_type = '') |
|
126 | + { |
|
127 | + switch ($post_type) { |
|
128 | + case 'espresso_events': |
|
129 | + return $this->get_all_event_post_tags(); |
|
130 | + break; |
|
131 | + case 'espresso_venues': |
|
132 | + return $this->get_all_venue_post_tags(); |
|
133 | + break; |
|
134 | + default: |
|
135 | + $event_tags = $this->get_all_event_post_tags(); |
|
136 | + $venue_tags = $this->get_all_venue_post_tags(); |
|
137 | + return array_merge($event_tags, $venue_tags); |
|
138 | + } |
|
139 | + } |
|
140 | 140 | |
141 | 141 | |
142 | - /** |
|
143 | - * returns an EE_Term object for the given tag |
|
144 | - * if it has been utilized by any EE_Events or EE_Venues |
|
145 | - * |
|
146 | - * @param string $tag |
|
147 | - * @return EE_Term|null |
|
148 | - * @throws EE_Error |
|
149 | - * @throws InvalidArgumentException |
|
150 | - * @throws InvalidDataTypeException |
|
151 | - * @throws InvalidInterfaceException |
|
152 | - */ |
|
153 | - public function get_post_tag_for_event_or_venue($tag) |
|
154 | - { |
|
155 | - $post_tag_results = $this->get_all_wpdb_results( |
|
156 | - array( |
|
157 | - array( |
|
158 | - 'slug' => $tag, |
|
159 | - 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
160 | - 'OR' => array( |
|
161 | - 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
162 | - 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
163 | - ), |
|
164 | - ), |
|
165 | - 'default_where_conditions' => 'none', |
|
166 | - 'extra_selects' => array( |
|
167 | - 'event_post_type' => array('Term_Taxonomy___Event_CPT.post_type', '%s'), |
|
168 | - 'venue_post_type' => array('Term_Taxonomy___Venue_CPT.post_type', '%s') |
|
169 | - ), |
|
170 | - 'group_by' => array( |
|
171 | - 'event_post_type', |
|
172 | - 'venue_post_type', |
|
173 | - ), |
|
174 | - 'limit' => 2 |
|
175 | - ) |
|
176 | - ); |
|
142 | + /** |
|
143 | + * returns an EE_Term object for the given tag |
|
144 | + * if it has been utilized by any EE_Events or EE_Venues |
|
145 | + * |
|
146 | + * @param string $tag |
|
147 | + * @return EE_Term|null |
|
148 | + * @throws EE_Error |
|
149 | + * @throws InvalidArgumentException |
|
150 | + * @throws InvalidDataTypeException |
|
151 | + * @throws InvalidInterfaceException |
|
152 | + */ |
|
153 | + public function get_post_tag_for_event_or_venue($tag) |
|
154 | + { |
|
155 | + $post_tag_results = $this->get_all_wpdb_results( |
|
156 | + array( |
|
157 | + array( |
|
158 | + 'slug' => $tag, |
|
159 | + 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
160 | + 'OR' => array( |
|
161 | + 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
162 | + 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
163 | + ), |
|
164 | + ), |
|
165 | + 'default_where_conditions' => 'none', |
|
166 | + 'extra_selects' => array( |
|
167 | + 'event_post_type' => array('Term_Taxonomy___Event_CPT.post_type', '%s'), |
|
168 | + 'venue_post_type' => array('Term_Taxonomy___Venue_CPT.post_type', '%s') |
|
169 | + ), |
|
170 | + 'group_by' => array( |
|
171 | + 'event_post_type', |
|
172 | + 'venue_post_type', |
|
173 | + ), |
|
174 | + 'limit' => 2 |
|
175 | + ) |
|
176 | + ); |
|
177 | 177 | |
178 | - $post_types = array(); |
|
179 | - foreach ((array) $post_tag_results as $row) { |
|
180 | - if ($row['event_post_type'] === 'espresso_events') { |
|
181 | - $post_types[] = EEM_Event::instance()->post_type(); |
|
182 | - } elseif ($row['venue_post_type'] === 'espresso_venues') { |
|
183 | - $post_types[] = EEM_Venue::instance()->post_type(); |
|
184 | - } |
|
185 | - } |
|
186 | - $post_tag_row = reset($post_tag_results); |
|
187 | - $post_tag = $this->instantiate_class_from_array_or_object($post_tag_row); |
|
188 | - if (! $post_tag instanceof EE_Term) { |
|
189 | - return null; |
|
190 | - } |
|
178 | + $post_types = array(); |
|
179 | + foreach ((array) $post_tag_results as $row) { |
|
180 | + if ($row['event_post_type'] === 'espresso_events') { |
|
181 | + $post_types[] = EEM_Event::instance()->post_type(); |
|
182 | + } elseif ($row['venue_post_type'] === 'espresso_venues') { |
|
183 | + $post_types[] = EEM_Venue::instance()->post_type(); |
|
184 | + } |
|
185 | + } |
|
186 | + $post_tag_row = reset($post_tag_results); |
|
187 | + $post_tag = $this->instantiate_class_from_array_or_object($post_tag_row); |
|
188 | + if (! $post_tag instanceof EE_Term) { |
|
189 | + return null; |
|
190 | + } |
|
191 | 191 | |
192 | - if ($post_tag->post_type === null) { |
|
193 | - $post_tag->post_type = array(); |
|
194 | - } |
|
195 | - $post_tag->post_type = array_merge($post_tag->post_type, array_unique($post_types)); |
|
196 | - return $post_tag; |
|
197 | - } |
|
192 | + if ($post_tag->post_type === null) { |
|
193 | + $post_tag->post_type = array(); |
|
194 | + } |
|
195 | + $post_tag->post_type = array_merge($post_tag->post_type, array_unique($post_types)); |
|
196 | + return $post_tag; |
|
197 | + } |
|
198 | 198 | |
199 | 199 | |
200 | 200 | |
201 | - /** |
|
202 | - * get_all_event_post_tags |
|
203 | - * |
|
204 | - * @return EE_Base_Class[] |
|
205 | - */ |
|
206 | - public function get_all_event_post_tags() |
|
207 | - { |
|
208 | - $post_tags = EEM_Term::instance()->get_all( |
|
209 | - array( |
|
210 | - array( |
|
211 | - 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
212 | - 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
213 | - ), |
|
214 | - 'order_by' => array('name' => 'ASC'), |
|
215 | - 'force_join' => array('Term_Taxonomy.Event'), |
|
216 | - ) |
|
217 | - ); |
|
218 | - foreach ($post_tags as $key => $post_tag) { |
|
219 | - if (! isset($post_tags[ $key ]->post_type)) { |
|
220 | - $post_tags[ $key ]->post_type = array(); |
|
221 | - } |
|
222 | - $post_tags[ $key ]->post_type[] = 'espresso_events'; |
|
223 | - } |
|
224 | - return $post_tags; |
|
225 | - } |
|
201 | + /** |
|
202 | + * get_all_event_post_tags |
|
203 | + * |
|
204 | + * @return EE_Base_Class[] |
|
205 | + */ |
|
206 | + public function get_all_event_post_tags() |
|
207 | + { |
|
208 | + $post_tags = EEM_Term::instance()->get_all( |
|
209 | + array( |
|
210 | + array( |
|
211 | + 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
212 | + 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
213 | + ), |
|
214 | + 'order_by' => array('name' => 'ASC'), |
|
215 | + 'force_join' => array('Term_Taxonomy.Event'), |
|
216 | + ) |
|
217 | + ); |
|
218 | + foreach ($post_tags as $key => $post_tag) { |
|
219 | + if (! isset($post_tags[ $key ]->post_type)) { |
|
220 | + $post_tags[ $key ]->post_type = array(); |
|
221 | + } |
|
222 | + $post_tags[ $key ]->post_type[] = 'espresso_events'; |
|
223 | + } |
|
224 | + return $post_tags; |
|
225 | + } |
|
226 | 226 | |
227 | 227 | |
228 | 228 | |
229 | - /** |
|
230 | - * get_all_venue_post_tags |
|
231 | - * |
|
232 | - * @return EE_Base_Class[] |
|
233 | - */ |
|
234 | - public function get_all_venue_post_tags() |
|
235 | - { |
|
236 | - $post_tags = EEM_Term::instance()->get_all( |
|
237 | - array( |
|
238 | - array( |
|
239 | - 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
240 | - 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
241 | - ), |
|
242 | - 'order_by' => array('name' => 'ASC'), |
|
243 | - 'force_join' => array('Term_Taxonomy'), |
|
244 | - ) |
|
245 | - ); |
|
246 | - foreach ($post_tags as $key => $post_tag) { |
|
247 | - if (! isset($post_tags[ $key ]->post_type)) { |
|
248 | - $post_tags[ $key ]->post_type = array(); |
|
249 | - } |
|
250 | - $post_tags[ $key ]->post_type[] = 'espresso_venues'; |
|
251 | - } |
|
252 | - return $post_tags; |
|
253 | - } |
|
229 | + /** |
|
230 | + * get_all_venue_post_tags |
|
231 | + * |
|
232 | + * @return EE_Base_Class[] |
|
233 | + */ |
|
234 | + public function get_all_venue_post_tags() |
|
235 | + { |
|
236 | + $post_tags = EEM_Term::instance()->get_all( |
|
237 | + array( |
|
238 | + array( |
|
239 | + 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
240 | + 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
241 | + ), |
|
242 | + 'order_by' => array('name' => 'ASC'), |
|
243 | + 'force_join' => array('Term_Taxonomy'), |
|
244 | + ) |
|
245 | + ); |
|
246 | + foreach ($post_tags as $key => $post_tag) { |
|
247 | + if (! isset($post_tags[ $key ]->post_type)) { |
|
248 | + $post_tags[ $key ]->post_type = array(); |
|
249 | + } |
|
250 | + $post_tags[ $key ]->post_type[] = 'espresso_venues'; |
|
251 | + } |
|
252 | + return $post_tags; |
|
253 | + } |
|
254 | 254 | |
255 | 255 | |
256 | 256 | |
257 | - /** |
|
258 | - * Makes sure that during REST API queries, we only return terms |
|
259 | - * for term taxonomies which should be shown in the rest api |
|
260 | - * |
|
261 | - * @param array $model_query_params |
|
262 | - * @param array $querystring_query_params |
|
263 | - * @param EEM_Base $model |
|
264 | - * @return array |
|
265 | - */ |
|
266 | - public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
267 | - { |
|
268 | - if ($model === EEM_Term::instance()) { |
|
269 | - $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
270 | - if (! empty($taxonomies)) { |
|
271 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
272 | - } |
|
273 | - } |
|
274 | - return $model_query_params; |
|
275 | - } |
|
257 | + /** |
|
258 | + * Makes sure that during REST API queries, we only return terms |
|
259 | + * for term taxonomies which should be shown in the rest api |
|
260 | + * |
|
261 | + * @param array $model_query_params |
|
262 | + * @param array $querystring_query_params |
|
263 | + * @param EEM_Base $model |
|
264 | + * @return array |
|
265 | + */ |
|
266 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
267 | + { |
|
268 | + if ($model === EEM_Term::instance()) { |
|
269 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
270 | + if (! empty($taxonomies)) { |
|
271 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
272 | + } |
|
273 | + } |
|
274 | + return $model_query_params; |
|
275 | + } |
|
276 | 276 | } |
@@ -44,43 +44,43 @@ discard block |
||
44 | 44 | ); |
45 | 45 | $this->_wp_core_model = true; |
46 | 46 | $path_to_tax_model = 'Term_Taxonomy'; |
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
49 | 49 | $path_to_tax_model |
50 | 50 | ); |
51 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
52 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
53 | - $path_to_tax_model = $path_to_tax_model . '.'; |
|
51 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
|
52 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
|
53 | + $path_to_tax_model = $path_to_tax_model.'.'; |
|
54 | 54 | // add cap restrictions for editing relating to the "ee_edit_*" |
55 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
55 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
56 | 56 | array( |
57 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
57 | + $path_to_tax_model.'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
58 | 58 | ) |
59 | 59 | ); |
60 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
60 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
61 | 61 | array( |
62 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
62 | + $path_to_tax_model.'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
63 | 63 | ) |
64 | 64 | ); |
65 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
65 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
66 | 66 | array( |
67 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
67 | + $path_to_tax_model.'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
68 | 68 | ) |
69 | 69 | ); |
70 | 70 | // add cap restrictions for deleting relating to the "ee_deleting_*" |
71 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
71 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
72 | 72 | array( |
73 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
73 | + $path_to_tax_model.'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
74 | 74 | ) |
75 | 75 | ); |
76 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
76 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
77 | 77 | array( |
78 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
78 | + $path_to_tax_model.'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
79 | 79 | ) |
80 | 80 | ); |
81 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
81 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
82 | 82 | array( |
83 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
83 | + $path_to_tax_model.'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
84 | 84 | ) |
85 | 85 | ); |
86 | 86 | parent::__construct($timezone); |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | } |
186 | 186 | $post_tag_row = reset($post_tag_results); |
187 | 187 | $post_tag = $this->instantiate_class_from_array_or_object($post_tag_row); |
188 | - if (! $post_tag instanceof EE_Term) { |
|
188 | + if ( ! $post_tag instanceof EE_Term) { |
|
189 | 189 | return null; |
190 | 190 | } |
191 | 191 | |
@@ -216,10 +216,10 @@ discard block |
||
216 | 216 | ) |
217 | 217 | ); |
218 | 218 | foreach ($post_tags as $key => $post_tag) { |
219 | - if (! isset($post_tags[ $key ]->post_type)) { |
|
220 | - $post_tags[ $key ]->post_type = array(); |
|
219 | + if ( ! isset($post_tags[$key]->post_type)) { |
|
220 | + $post_tags[$key]->post_type = array(); |
|
221 | 221 | } |
222 | - $post_tags[ $key ]->post_type[] = 'espresso_events'; |
|
222 | + $post_tags[$key]->post_type[] = 'espresso_events'; |
|
223 | 223 | } |
224 | 224 | return $post_tags; |
225 | 225 | } |
@@ -244,10 +244,10 @@ discard block |
||
244 | 244 | ) |
245 | 245 | ); |
246 | 246 | foreach ($post_tags as $key => $post_tag) { |
247 | - if (! isset($post_tags[ $key ]->post_type)) { |
|
248 | - $post_tags[ $key ]->post_type = array(); |
|
247 | + if ( ! isset($post_tags[$key]->post_type)) { |
|
248 | + $post_tags[$key]->post_type = array(); |
|
249 | 249 | } |
250 | - $post_tags[ $key ]->post_type[] = 'espresso_venues'; |
|
250 | + $post_tags[$key]->post_type[] = 'espresso_venues'; |
|
251 | 251 | } |
252 | 252 | return $post_tags; |
253 | 253 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | { |
268 | 268 | if ($model === EEM_Term::instance()) { |
269 | 269 | $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
270 | - if (! empty($taxonomies)) { |
|
270 | + if ( ! empty($taxonomies)) { |
|
271 | 271 | $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
272 | 272 | } |
273 | 273 | } |
@@ -12,274 +12,274 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * generates JSON-based linked data for an event |
|
17 | - * |
|
18 | - * @param EE_Event $event |
|
19 | - * @throws EE_Error |
|
20 | - */ |
|
21 | - public static function add_json_linked_data_for_event(EE_Event $event) |
|
22 | - { |
|
23 | - // Check we have a valid datetime for the event |
|
24 | - if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | - return; |
|
26 | - } |
|
27 | - |
|
28 | - $template_args = array( |
|
29 | - 'event_permalink' => '', |
|
30 | - 'event_name' => '', |
|
31 | - 'event_description' => '', |
|
32 | - 'event_start' => '', |
|
33 | - 'event_end' => '', |
|
34 | - 'currency' => '', |
|
35 | - 'event_tickets' => array(), |
|
36 | - 'venue_name' => '', |
|
37 | - 'venue_url' => '', |
|
38 | - 'venue_locality' => '', |
|
39 | - 'venue_region' => '', |
|
40 | - 'event_image' => '', |
|
41 | - ); |
|
42 | - $template_args['event_permalink'] = $event->get_permalink(); |
|
43 | - $template_args['event_name'] = $event->name(); |
|
44 | - $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
45 | - // clone datetime so that date formats don't override those for the original datetime |
|
46 | - $primary_datetime = clone $event->primary_datetime(); |
|
47 | - $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
48 | - $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
49 | - unset($primary_datetime); |
|
50 | - $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
51 | - foreach ($event->tickets() as $original_ticket) { |
|
52 | - // clone tickets so that date formats don't override those for the original ticket |
|
53 | - $ticket= clone $original_ticket; |
|
54 | - $ID = $ticket->ID(); |
|
55 | - $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
56 | - $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
57 | - $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
58 | - $ticket->price(), |
|
59 | - EE_Registry::instance()->CFG->currency->dec_plc, |
|
60 | - EE_Registry::instance()->CFG->currency->dec_mrk, |
|
61 | - EE_Registry::instance()->CFG->currency->thsnds |
|
62 | - ); |
|
63 | - switch ($ticket->ticket_status()) { |
|
64 | - case 'TKO': |
|
65 | - $availability = 'InStock'; |
|
66 | - break; |
|
67 | - case 'TKS': |
|
68 | - $availability = 'SoldOut'; |
|
69 | - break; |
|
70 | - default: |
|
71 | - $availability = null; |
|
72 | - break; |
|
73 | - } |
|
74 | - $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
75 | - unset($ticket); |
|
76 | - } |
|
77 | - $VNU_ID = espresso_venue_id(); |
|
78 | - if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
79 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
80 | - $template_args['venue_name'] = get_the_title($VNU_ID); |
|
81 | - $template_args['venue_url'] = get_permalink($VNU_ID); |
|
82 | - $template_args['venue_locality'] = $venue->city(); |
|
83 | - $template_args['venue_region'] = $venue->state_name(); |
|
84 | - } |
|
85 | - $template_args['event_image'] = $event->feature_image_url(); |
|
86 | - $template_args = apply_filters( |
|
87 | - 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
88 | - $template_args, |
|
89 | - $event, |
|
90 | - $VNU_ID |
|
91 | - ); |
|
92 | - extract($template_args, EXTR_OVERWRITE); |
|
93 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * location |
|
99 | - * The location of the event, organization or action. |
|
100 | - * Should include the Venue name AND schema formatted address info |
|
101 | - * |
|
102 | - * @access public |
|
103 | - * @param string $location |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public static function location($location = null) |
|
107 | - { |
|
108 | - return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
109 | - . $location |
|
110 | - . '</div>' : ''; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * name |
|
117 | - * The name of the Event or Venue. |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * @param string $name |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public static function name($name = null) |
|
124 | - { |
|
125 | - return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * streetAddress |
|
132 | - * The street address. For example, 1600 Amphitheatre Pkwy. |
|
133 | - * |
|
134 | - * @access public |
|
135 | - * @param EEI_Address $obj_with_address |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - public static function streetAddress(EEI_Address $obj_with_address = null) |
|
139 | - { |
|
140 | - return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
|
141 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * postOfficeBoxNumber |
|
148 | - * The post office box number for PO box addresses. |
|
149 | - * |
|
150 | - * @access public |
|
151 | - * @param EEI_Address $obj_with_address |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) |
|
155 | - { |
|
156 | - // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
157 | - if (preg_match( |
|
158 | - "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
159 | - $obj_with_address->address2() |
|
160 | - ) ) { |
|
161 | - return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
|
162 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
163 | - } else { |
|
164 | - return $obj_with_address->address2(); |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * addressLocality |
|
172 | - * The locality (city, town, etc). For example, Mountain View. |
|
173 | - * |
|
174 | - * @access public |
|
175 | - * @param EEI_Address $obj_with_address |
|
176 | - * @return string |
|
177 | - */ |
|
178 | - public static function addressLocality(EEI_Address $obj_with_address = null) |
|
179 | - { |
|
180 | - return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
|
181 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * addressRegion |
|
188 | - * The region (state, province, etc). For example, CA. |
|
189 | - * |
|
190 | - * @access public |
|
191 | - * @param EEI_Address $obj_with_address |
|
192 | - * @return string |
|
193 | - */ |
|
194 | - public static function addressRegion(EEI_Address $obj_with_address = null) |
|
195 | - { |
|
196 | - $state = $obj_with_address->state_name(); |
|
197 | - if (! empty($state)) { |
|
198 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
199 | - } else { |
|
200 | - return ''; |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * addressCountry |
|
208 | - * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
209 | - * |
|
210 | - * @access public |
|
211 | - * @param EEI_Address $obj_with_address |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - public static function addressCountry(EEI_Address $obj_with_address = null) |
|
215 | - { |
|
216 | - $country = $obj_with_address->country_name(); |
|
217 | - if (! empty($country)) { |
|
218 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
219 | - } else { |
|
220 | - return ''; |
|
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * postalCode |
|
228 | - * The postal code. For example, 94043. |
|
229 | - * |
|
230 | - * @access public |
|
231 | - * @param EEI_Address $obj_with_address |
|
232 | - * @return string |
|
233 | - */ |
|
234 | - public static function postalCode(EEI_Address $obj_with_address = null) |
|
235 | - { |
|
236 | - return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
|
237 | - . $obj_with_address->zip() |
|
238 | - . '</span>' : ''; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * telephone |
|
245 | - * The telephone number. |
|
246 | - * |
|
247 | - * @access public |
|
248 | - * @param string $phone_nmbr |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public static function telephone($phone_nmbr = null) |
|
252 | - { |
|
253 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
254 | - : ''; |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * URL |
|
261 | - * URL of the item as a clickable link |
|
262 | - * |
|
263 | - * @access public |
|
264 | - * @param string $url - the URL that the link will resolve to |
|
265 | - * @param string $text - the text that will be used for the visible link |
|
266 | - * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
|
267 | - * @return string (link) |
|
268 | - */ |
|
269 | - public static function url($url = null, $text = null, $attributes = array()) |
|
270 | - { |
|
271 | - // Check the URL includes a scheme |
|
272 | - $parsed_url = parse_url($url); |
|
273 | - if (empty($parsed_url['scheme'])) { |
|
274 | - $url = 'http://' . ltrim($url, '/'); |
|
275 | - } |
|
276 | - |
|
277 | - $atts = ''; |
|
278 | - foreach ($attributes as $attribute => $value) { |
|
279 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
280 | - } |
|
281 | - $text = $text !== null && $text !== '' ? $text : $url; |
|
282 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
283 | - : ''; |
|
284 | - } |
|
15 | + /** |
|
16 | + * generates JSON-based linked data for an event |
|
17 | + * |
|
18 | + * @param EE_Event $event |
|
19 | + * @throws EE_Error |
|
20 | + */ |
|
21 | + public static function add_json_linked_data_for_event(EE_Event $event) |
|
22 | + { |
|
23 | + // Check we have a valid datetime for the event |
|
24 | + if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | + return; |
|
26 | + } |
|
27 | + |
|
28 | + $template_args = array( |
|
29 | + 'event_permalink' => '', |
|
30 | + 'event_name' => '', |
|
31 | + 'event_description' => '', |
|
32 | + 'event_start' => '', |
|
33 | + 'event_end' => '', |
|
34 | + 'currency' => '', |
|
35 | + 'event_tickets' => array(), |
|
36 | + 'venue_name' => '', |
|
37 | + 'venue_url' => '', |
|
38 | + 'venue_locality' => '', |
|
39 | + 'venue_region' => '', |
|
40 | + 'event_image' => '', |
|
41 | + ); |
|
42 | + $template_args['event_permalink'] = $event->get_permalink(); |
|
43 | + $template_args['event_name'] = $event->name(); |
|
44 | + $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
45 | + // clone datetime so that date formats don't override those for the original datetime |
|
46 | + $primary_datetime = clone $event->primary_datetime(); |
|
47 | + $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
48 | + $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
49 | + unset($primary_datetime); |
|
50 | + $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
51 | + foreach ($event->tickets() as $original_ticket) { |
|
52 | + // clone tickets so that date formats don't override those for the original ticket |
|
53 | + $ticket= clone $original_ticket; |
|
54 | + $ID = $ticket->ID(); |
|
55 | + $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
56 | + $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
57 | + $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
58 | + $ticket->price(), |
|
59 | + EE_Registry::instance()->CFG->currency->dec_plc, |
|
60 | + EE_Registry::instance()->CFG->currency->dec_mrk, |
|
61 | + EE_Registry::instance()->CFG->currency->thsnds |
|
62 | + ); |
|
63 | + switch ($ticket->ticket_status()) { |
|
64 | + case 'TKO': |
|
65 | + $availability = 'InStock'; |
|
66 | + break; |
|
67 | + case 'TKS': |
|
68 | + $availability = 'SoldOut'; |
|
69 | + break; |
|
70 | + default: |
|
71 | + $availability = null; |
|
72 | + break; |
|
73 | + } |
|
74 | + $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
75 | + unset($ticket); |
|
76 | + } |
|
77 | + $VNU_ID = espresso_venue_id(); |
|
78 | + if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
79 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
80 | + $template_args['venue_name'] = get_the_title($VNU_ID); |
|
81 | + $template_args['venue_url'] = get_permalink($VNU_ID); |
|
82 | + $template_args['venue_locality'] = $venue->city(); |
|
83 | + $template_args['venue_region'] = $venue->state_name(); |
|
84 | + } |
|
85 | + $template_args['event_image'] = $event->feature_image_url(); |
|
86 | + $template_args = apply_filters( |
|
87 | + 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
88 | + $template_args, |
|
89 | + $event, |
|
90 | + $VNU_ID |
|
91 | + ); |
|
92 | + extract($template_args, EXTR_OVERWRITE); |
|
93 | + include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * location |
|
99 | + * The location of the event, organization or action. |
|
100 | + * Should include the Venue name AND schema formatted address info |
|
101 | + * |
|
102 | + * @access public |
|
103 | + * @param string $location |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public static function location($location = null) |
|
107 | + { |
|
108 | + return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
109 | + . $location |
|
110 | + . '</div>' : ''; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * name |
|
117 | + * The name of the Event or Venue. |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * @param string $name |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public static function name($name = null) |
|
124 | + { |
|
125 | + return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * streetAddress |
|
132 | + * The street address. For example, 1600 Amphitheatre Pkwy. |
|
133 | + * |
|
134 | + * @access public |
|
135 | + * @param EEI_Address $obj_with_address |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + public static function streetAddress(EEI_Address $obj_with_address = null) |
|
139 | + { |
|
140 | + return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
|
141 | + ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * postOfficeBoxNumber |
|
148 | + * The post office box number for PO box addresses. |
|
149 | + * |
|
150 | + * @access public |
|
151 | + * @param EEI_Address $obj_with_address |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) |
|
155 | + { |
|
156 | + // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
157 | + if (preg_match( |
|
158 | + "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
159 | + $obj_with_address->address2() |
|
160 | + ) ) { |
|
161 | + return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
|
162 | + ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
163 | + } else { |
|
164 | + return $obj_with_address->address2(); |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * addressLocality |
|
172 | + * The locality (city, town, etc). For example, Mountain View. |
|
173 | + * |
|
174 | + * @access public |
|
175 | + * @param EEI_Address $obj_with_address |
|
176 | + * @return string |
|
177 | + */ |
|
178 | + public static function addressLocality(EEI_Address $obj_with_address = null) |
|
179 | + { |
|
180 | + return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
|
181 | + ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * addressRegion |
|
188 | + * The region (state, province, etc). For example, CA. |
|
189 | + * |
|
190 | + * @access public |
|
191 | + * @param EEI_Address $obj_with_address |
|
192 | + * @return string |
|
193 | + */ |
|
194 | + public static function addressRegion(EEI_Address $obj_with_address = null) |
|
195 | + { |
|
196 | + $state = $obj_with_address->state_name(); |
|
197 | + if (! empty($state)) { |
|
198 | + return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
199 | + } else { |
|
200 | + return ''; |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * addressCountry |
|
208 | + * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
209 | + * |
|
210 | + * @access public |
|
211 | + * @param EEI_Address $obj_with_address |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + public static function addressCountry(EEI_Address $obj_with_address = null) |
|
215 | + { |
|
216 | + $country = $obj_with_address->country_name(); |
|
217 | + if (! empty($country)) { |
|
218 | + return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
219 | + } else { |
|
220 | + return ''; |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * postalCode |
|
228 | + * The postal code. For example, 94043. |
|
229 | + * |
|
230 | + * @access public |
|
231 | + * @param EEI_Address $obj_with_address |
|
232 | + * @return string |
|
233 | + */ |
|
234 | + public static function postalCode(EEI_Address $obj_with_address = null) |
|
235 | + { |
|
236 | + return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
|
237 | + . $obj_with_address->zip() |
|
238 | + . '</span>' : ''; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * telephone |
|
245 | + * The telephone number. |
|
246 | + * |
|
247 | + * @access public |
|
248 | + * @param string $phone_nmbr |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public static function telephone($phone_nmbr = null) |
|
252 | + { |
|
253 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
254 | + : ''; |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * URL |
|
261 | + * URL of the item as a clickable link |
|
262 | + * |
|
263 | + * @access public |
|
264 | + * @param string $url - the URL that the link will resolve to |
|
265 | + * @param string $text - the text that will be used for the visible link |
|
266 | + * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
|
267 | + * @return string (link) |
|
268 | + */ |
|
269 | + public static function url($url = null, $text = null, $attributes = array()) |
|
270 | + { |
|
271 | + // Check the URL includes a scheme |
|
272 | + $parsed_url = parse_url($url); |
|
273 | + if (empty($parsed_url['scheme'])) { |
|
274 | + $url = 'http://' . ltrim($url, '/'); |
|
275 | + } |
|
276 | + |
|
277 | + $atts = ''; |
|
278 | + foreach ($attributes as $attribute => $value) { |
|
279 | + $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
280 | + } |
|
281 | + $text = $text !== null && $text !== '' ? $text : $url; |
|
282 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
283 | + : ''; |
|
284 | + } |
|
285 | 285 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | public static function add_json_linked_data_for_event(EE_Event $event) |
22 | 22 | { |
23 | 23 | // Check we have a valid datetime for the event |
24 | - if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
24 | + if ( ! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | 25 | return; |
26 | 26 | } |
27 | 27 | |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
51 | 51 | foreach ($event->tickets() as $original_ticket) { |
52 | 52 | // clone tickets so that date formats don't override those for the original ticket |
53 | - $ticket= clone $original_ticket; |
|
53 | + $ticket = clone $original_ticket; |
|
54 | 54 | $ID = $ticket->ID(); |
55 | - $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
56 | - $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
57 | - $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
55 | + $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
56 | + $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
57 | + $template_args['event_tickets'][$ID]['price'] = number_format( |
|
58 | 58 | $ticket->price(), |
59 | 59 | EE_Registry::instance()->CFG->currency->dec_plc, |
60 | 60 | EE_Registry::instance()->CFG->currency->dec_mrk, |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | $availability = null; |
72 | 72 | break; |
73 | 73 | } |
74 | - $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
74 | + $template_args['event_tickets'][$ID]['availability'] = $availability; |
|
75 | 75 | unset($ticket); |
76 | 76 | } |
77 | 77 | $VNU_ID = espresso_venue_id(); |
78 | - if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
78 | + if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
79 | 79 | $venue = EEH_Venue_View::get_venue($VNU_ID); |
80 | 80 | $template_args['venue_name'] = get_the_title($VNU_ID); |
81 | 81 | $template_args['venue_url'] = get_permalink($VNU_ID); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $VNU_ID |
91 | 91 | ); |
92 | 92 | extract($template_args, EXTR_OVERWRITE); |
93 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
93 | + include EE_TEMPLATES.'json_linked_data_for_event.template.php'; |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public static function name($name = null) |
124 | 124 | { |
125 | - return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
125 | + return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : ''; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | public static function streetAddress(EEI_Address $obj_with_address = null) |
139 | 139 | { |
140 | 140 | return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
141 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
141 | + ? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : ''; |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | if (preg_match( |
158 | 158 | "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
159 | 159 | $obj_with_address->address2() |
160 | - ) ) { |
|
160 | + )) { |
|
161 | 161 | return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
162 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
162 | + ? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : ''; |
|
163 | 163 | } else { |
164 | 164 | return $obj_with_address->address2(); |
165 | 165 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | public static function addressLocality(EEI_Address $obj_with_address = null) |
179 | 179 | { |
180 | 180 | return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
181 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
181 | + ? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : ''; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | public static function addressRegion(EEI_Address $obj_with_address = null) |
195 | 195 | { |
196 | 196 | $state = $obj_with_address->state_name(); |
197 | - if (! empty($state)) { |
|
198 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
197 | + if ( ! empty($state)) { |
|
198 | + return '<span itemprop="addressRegion">'.$state.'</span>'; |
|
199 | 199 | } else { |
200 | 200 | return ''; |
201 | 201 | } |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | public static function addressCountry(EEI_Address $obj_with_address = null) |
215 | 215 | { |
216 | 216 | $country = $obj_with_address->country_name(); |
217 | - if (! empty($country)) { |
|
218 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
217 | + if ( ! empty($country)) { |
|
218 | + return '<span itemprop="addressCountry">'.$country.'</span>'; |
|
219 | 219 | } else { |
220 | 220 | return ''; |
221 | 221 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | */ |
251 | 251 | public static function telephone($phone_nmbr = null) |
252 | 252 | { |
253 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
253 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>' |
|
254 | 254 | : ''; |
255 | 255 | } |
256 | 256 | |
@@ -271,15 +271,15 @@ discard block |
||
271 | 271 | // Check the URL includes a scheme |
272 | 272 | $parsed_url = parse_url($url); |
273 | 273 | if (empty($parsed_url['scheme'])) { |
274 | - $url = 'http://' . ltrim($url, '/'); |
|
274 | + $url = 'http://'.ltrim($url, '/'); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | $atts = ''; |
278 | 278 | foreach ($attributes as $attribute => $value) { |
279 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
279 | + $atts .= ' '.$attribute.'="'.$value.'"'; |
|
280 | 280 | } |
281 | 281 | $text = $text !== null && $text !== '' ? $text : $url; |
282 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
282 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="'.$url.'"'.$atts.'>'.$text.'</a>' |
|
283 | 283 | : ''; |
284 | 284 | } |
285 | 285 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | "url": "<?php echo $event_permalink; ?>", |
25 | 25 | "offers": [ |
26 | 26 | <?php |
27 | - foreach ($event_tickets as $ticket) {?> |
|
27 | + foreach ($event_tickets as $ticket) {?> |
|
28 | 28 | { |
29 | 29 | "@type": "Offer", |
30 | 30 | "url": "<?php echo $event_permalink; ?>", |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | "price": "<?php echo $ticket['price']; ?>", |
34 | 34 | "priceCurrency": "<?php echo $currency; ?>" |
35 | 35 | <?php if (isset($ticket['availability'])) { |
36 | - ?>,"availability": "http://schema.org/<?php echo $ticket['availability']; ?>" |
|
36 | + ?>,"availability": "http://schema.org/<?php echo $ticket['availability']; ?>" |
|
37 | 37 | <?php } ?> |
38 | 38 | }<?php |
39 | - if (is_array($event_tickets) && end($event_tickets) !== $ticket) { |
|
40 | - echo ','; |
|
41 | - } |
|
42 | - } |
|
43 | - ?> |
|
39 | + if (is_array($event_tickets) && end($event_tickets) !== $ticket) { |
|
40 | + echo ','; |
|
41 | + } |
|
42 | + } |
|
43 | + ?> |
|
44 | 44 | ]<?php |
45 | - if ($venue_name) { |
|
46 | - ?>, |
|
45 | + if ($venue_name) { |
|
46 | + ?>, |
|
47 | 47 | "location": { |
48 | 48 | "@type": "Place", |
49 | 49 | "name": <?php echo wp_json_encode($venue_name); ?>, |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | } |
56 | 56 | } |
57 | 57 | <?php |
58 | - } ?> |
|
58 | + } ?> |
|
59 | 59 | <?php |
60 | - if ($event_image) { |
|
61 | - ?>, |
|
60 | + if ($event_image) { |
|
61 | + ?>, |
|
62 | 62 | "image": "<?php echo $event_image; ?>" |
63 | 63 | <?php |
64 | - } ?> |
|
64 | + } ?> |
|
65 | 65 | <?php do_action('AHEE__json_linked_data_for_event__template'); ?> |
66 | 66 | } |
67 | 67 |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.69.rc.006'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.69.rc.006'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |