PluginProbe
Order Tracking – WordPress Status Tracking Plugin / 3.2.2
Order Tracking – WordPress Status Tracking Plugin v3.2.2
3.5.4 3.5.3 3.5.2 3.5.1 3.5.0 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.3.0 3.3.1 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.15 All 235 releases
order-tracking / views / View.class.php

View.class.php in Order Tracking – WordPress Status Tracking Plugin 3.2.2, at views/View.class.php

526 lines 20.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Base class for any view requested on the front end.
5 *
6 * @since 3.0.0
7 */
8 class ewdotpView extends ewdotpBase {
9
10 /**
11 * Post type to render
12 */
13 public $post_type = null;
14
15 /**
16 * Map types of content to the template which will render them
17 */
18 public $content_map = array(
19 'title' => 'content/title',
20 );
21
22 /**
23 * Initialize the class
24 * @since 3.0.0
25 */
26 public function __construct( $args ) {
27
28 // Parse the values passed
29 $this->parse_args( $args );
30
31 // Filter the content map so addons can customize what and how content
32 // is output. Filters are specific to each view, so for this base view
33 // you would use the filter 'us_content_map_ewdotpView'
34 $this->content_map = apply_filters( 'ewd_otp_content_map_' . get_class( $this ), $this->content_map );
35
36 }
37
38 /**
39 * Render the view and enqueue required stylesheets
40 *
41 * @note This function should always be overridden by an extending class
42 * @since 3.0.0
43 */
44 public function render() {
45
46 $this->set_error(
47 array(
48 'type' => 'render() called on wrong class'
49 )
50 );
51 }
52
53 /**
54 * Load a template file for views
55 *
56 * First, it looks in the current theme's /ewd-otp-templates/ directory. Then it
57 * will check a parent theme's /ewd-otp-templates/ directory. If nothing is found
58 * there, it will retrieve the template from the plugin directory.
59
60 * @since 3.0.0
61 * @param string template Type of template to load (eg - reviews, review)
62 */
63 function find_template( $template ) {
64
65 $this->template_dirs = array(
66 get_stylesheet_directory() . '/' . EWD_OTP_TEMPLATE_DIR . '/',
67 get_template_directory() . '/' . EWD_OTP_TEMPLATE_DIR . '/',
68 EWD_OTP_PLUGIN_DIR . '/' . EWD_OTP_TEMPLATE_DIR . '/'
69 );
70
71 $this->template_dirs = apply_filters( 'ewd_otp_template_directories', $this->template_dirs );
72
73 foreach ( $this->template_dirs as $dir ) {
74 if ( file_exists( $dir . $template . '.php' ) ) {
75 return $dir . $template . '.php';
76 }
77 }
78
79 return false;
80 }
81
82 /**
83 * Enqueue stylesheets
84 */
85 public function enqueue_assets() {
86
87 //enqueue assets here
88 }
89
90 /**
91 * Print the details of an order, if one is selected
92 *
93 * @since 3.0.0
94 */
95 public function maybe_print_order_tracking() {
96
97 if ( empty( $this->order ) ) { return; }
98
99 $template = $this->find_template( 'order-results' );
100
101 if ( $template ) {
102 include( $template );
103 }
104 }
105
106 /**
107 * Prints an action notification, if any action has happened
108 *
109 * @since 3.0.0
110 */
111 public function maybe_print_update_message() {
112
113 if ( empty( $this->update_message ) ) { return; }
114
115 $template = $this->find_template( 'update-message' );
116
117 if ( $template ) {
118 include( $template );
119 }
120 }
121
122 public function print_error_message()
123 {
124 if( empty( $this->error_message ) ) { return; }
125
126 $template = $this->find_template( 'error-message' );
127
128 if ( $template ) {
129 include( $template );
130 }
131 }
132
133 /**
134 * Print the details of an order, if one is selected
135 *
136 * @since 3.0.0
137 */
138 public function print_custom_field() {
139
140 if ( empty( $this->custom_field ) ) { return; }
141
142 if ( $this->custom_field->type == 'file' ) { $template = $this->find_template( 'custom-field-file' ); }
143 elseif ( $this->custom_field->type == 'image' ) { $template = $this->find_template( 'custom-field-image' ); }
144 elseif ( $this->custom_field->type == 'link' ) { $template = $this->find_template( 'custom-field-link' ); }
145 else { $template = $this->find_template( 'custom-field-default' ); }
146
147 if ( $template ) {
148 include( $template );
149 }
150 }
151
152 /**
153 * Returns the custom fields designated for orders
154 *
155 * @since 3.0.0
156 */
157 public function get_order_fields() {
158 global $ewd_otp_controller;
159
160 return $ewd_otp_controller->settings->get_order_custom_fields();
161 }
162
163 /**
164 * Returns whether the order number field should be displayed or not
165 *
166 * @since 3.0.0
167 */
168 public function get_order_number_display() {
169 global $ewd_otp_controller;
170
171 if ( ! in_array( 'order_number', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return false ; }
172
173 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->order ) or empty( $this->order->number ) ) ) { return false; }
174
175 return true;
176 }
177
178 /**
179 * Returns whether the order name field should be displayed or not
180 *
181 * @since 3.0.0
182 */
183 public function get_order_name_display() {
184 global $ewd_otp_controller;
185
186 if ( ! in_array( 'order_name', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return false ; }
187
188 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->order ) or empty( $this->order->name ) ) ) { return false; }
189
190 return true;
191 }
192
193 /**
194 * Returns whether the public order notes field should be displayed or not
195 *
196 * @since 3.0.0
197 */
198 public function get_order_notes_display() {
199 global $ewd_otp_controller;
200
201 if ( ! in_array( 'order_notes', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return false ; }
202
203 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->order ) or empty( $this->order->notes_public ) ) ) { return false; }
204
205 return true;
206 }
207
208 /**
209 * Returns whether the customer notes field should be displayed or not
210 *
211 * @since 3.0.0
212 */
213 public function get_order_customer_notes_display() {
214 global $ewd_otp_controller;
215
216 if ( ! in_array( 'customer_notes', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return false ; }
217
218 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->order ) or empty( $this->order->customer_notes ) ) ) { return false; }
219
220 return true;
221 }
222
223 /**
224 * Returns whether the customer name field should be displayed or not
225 *
226 * @since 3.0.0
227 */
228 public function get_order_customer_name_display() {
229 global $ewd_otp_controller;
230
231 if ( ! in_array( 'customer_name', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return false ; }
232
233 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->customer ) or empty( $this->customer->name ) ) ) { return false; }
234
235 return true;
236 }
237
238 /**
239 * Returns whether the customer email field should be displayed or not
240 *
241 * @since 3.0.0
242 */
243 public function get_order_customer_email_display() {
244 global $ewd_otp_controller;
245
246 if ( ! in_array( 'customer_email', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return false ; }
247
248 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->customer ) or empty( $this->customer->email ) ) ) { return false; }
249
250 return true;
251 }
252
253 /**
254 * Returns whether the sales rep first name field should be displayed or not
255 *
256 * @since 3.0.0
257 */
258 public function get_order_sales_rep_first_name_display() {
259 global $ewd_otp_controller;
260
261 if ( ! in_array( 'sales_rep_first_name', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return false ; }
262
263 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->sales_rep ) or empty( $this->sales_rep->first_name ) ) ) { return false; }
264
265 return true;
266 }
267
268 /**
269 * Returns whether the sales rep last name field should be displayed or not
270 *
271 * @since 3.0.0
272 */
273 public function get_order_sales_rep_last_name_display() {
274 global $ewd_otp_controller;
275
276 if ( ! in_array( 'sales_rep_last_name', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return false ; }
277
278 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->sales_rep ) or empty( $this->sales_rep->last_name ) ) ) { return false; }
279
280 return true;
281 }
282
283 /**
284 * Returns whether the sales rep email field should be displayed or not
285 *
286 * @since 3.0.0
287 */
288 public function get_order_sales_rep_email_display() {
289 global $ewd_otp_controller;
290
291 if ( ! in_array( 'sales_rep_email', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return false ; }
292
293 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->sales_rep ) or empty( $this->sales_rep->email ) ) ) { return false; }
294
295 return true;
296 }
297
298 /**
299 * Returns whether a custom field should be displayed or not
300 *
301 * @since 3.0.0
302 */
303 public function get_order_custom_field_display( $custom_field ) {
304 global $ewd_otp_controller;
305
306 if ( ! $custom_field->display ) { return false; }
307
308 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->order ) or empty( $this->order->custom_fields[ $custom_field->id ] ) ) ) { return false; }
309
310 return true;
311 }
312
313 /**
314 * Returns whether the order status field should be displayed or not
315 *
316 * @since 3.0.0
317 */
318 public function get_order_status_display() {
319 global $ewd_otp_controller;
320
321 if ( ! in_array( 'order_status', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return false ; }
322
323 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->order ) or empty( $this->order->external_status ) ) ) { return false; }
324
325 return true;
326 }
327
328 /**
329 * Returns whether the order location field should be displayed or not
330 *
331 * @since 3.0.0
332 */
333 public function get_order_location_display() {
334 global $ewd_otp_controller;
335
336 if ( ! in_array( 'order_location', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return false ; }
337
338 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->order ) or empty( $this->order->location ) ) ) { return false; }
339
340 return true;
341 }
342
343 /**
344 * Returns whether the order updated datetime field should be displayed or not
345 *
346 * @since 3.0.0
347 */
348 public function get_order_updated_display() {
349 global $ewd_otp_controller;
350
351 if ( ! in_array( 'order_updated', $ewd_otp_controller->settings->get_setting( 'order-information' ) ) ) { return false ; }
352
353 if ( $ewd_otp_controller->settings->get_setting( 'hide-blank-fields' ) and ( empty( $this->order ) or empty( $this->order->status_updated ) ) ) { return false; }
354
355 return true;
356 }
357
358 /**
359 * Return the name of the customer for this order, if any
360 *
361 * @since 3.0.13
362 */
363 public function get_customer_name() {
364
365 return empty( $this->customer->name ) ? '' : $this->customer->name;
366 }
367
368 /**
369 * Return the email of the customer for this order, if any
370 *
371 * @since 3.0.13
372 */
373 public function get_customer_email() {
374
375 return empty( $this->customer->email ) ? '' : $this->customer->email;
376 }
377
378 /**
379 * Return the first name of the sales rep for this order, if any
380 *
381 * @since 3.0.13
382 */
383 public function get_sales_rep_first_name() {
384
385 return empty( $this->sales_rep->first_name ) ? '' : $this->sales_rep->first_name;
386 }
387
388 /**
389 * Return the last name of the sales rep for this order, if any
390 *
391 * @since 3.0.13
392 */
393 public function get_sales_rep_last_name() {
394
395 return empty( $this->sales_rep->last_name ) ? '' : $this->sales_rep->last_name;
396 }
397
398 /**
399 * Return the email of the sales rep for this order, if any
400 *
401 * @since 3.0.13
402 */
403 public function get_sales_rep_email() {
404
405 return empty( $this->sales_rep->email ) ? '' : $this->sales_rep->email;
406 }
407
408 /**
409 * Returns the target attribute for a shortcode form
410 *
411 * @since 3.0.0
412 */
413 public function get_form_target() {
414 global $ewd_otp_controller;
415
416 return $ewd_otp_controller->settings->get_setting( 'new-window' ) ? 'target="_blank"' : '';
417 }
418
419 public function get_option( $option_name ) {
420 global $ewd_otp_controller;
421
422 return ! empty( $this->$option_name ) ? $this->$option_name : $ewd_otp_controller->settings->get_setting( $option_name );
423 }
424
425 public function get_label( $label_name ) {
426 global $ewd_otp_controller;
427
428 if ( empty( $this->label_defaults ) ) { $this->set_label_defaults(); }
429
430 return ! empty( $ewd_otp_controller->settings->get_setting( $label_name ) ) ? $ewd_otp_controller->settings->get_setting( $label_name ) : $this->label_defaults[ $label_name ];
431 }
432
433 public function set_label_defaults() {
434
435 $this->label_defaults = array(
436 'label-order-form-title' => __( 'Track an Order', 'order-tracking' ),
437 'label-order-form-number' => __( 'Order Number', 'order-tracking' ),
438 'label-order-form-number-placeholder' => __( '', 'order-tracking' ),
439 'label-order-form-email' => __( 'Order E-mail Address', 'order-tracking' ),
440 'label-order-form-email-placeholder' => __( '', 'order-tracking' ),
441 'label-order-form-button' => __( 'Track', 'order-tracking' ),
442 'label-retrieving-results' => __( 'Retrieving results...', 'order-tracking' ),
443 'label-customer-form-title' => __( 'Track Your Orders', 'order-tracking' ),
444 'label-customer-form-instructions' => __( 'Enter your customer number in the form below to track your orders.', 'order-tracking' ),
445 'label-customer-form-number' => __( 'Customer Number', 'order-tracking' ),
446 'label-customer-form-number-placeholder' => __( '', 'order-tracking' ),
447 'label-customer-form-email' => __( 'Customer Email', 'order-tracking' ),
448 'label-customer-form-email-placeholder' => __( '', 'order-tracking' ),
449 'label-customer-form-button' => __( 'Find Customer', 'order-tracking' ),
450 'label-sales-rep-form-title' => __( 'Track Your Orders', 'order-tracking' ),
451 'label-sales-rep-form-instructions' => __( 'Enter your sales rep number in the form below to track your orders.', 'order-tracking' ),
452 'label-sales-rep-form-number' => __( 'Sales Rep Number', 'order-tracking' ),
453 'label-sales-rep-form-number-placeholder' => __( 'Sales Rep Number', 'order-tracking' ),
454 'label-sales-rep-form-email' => __( 'Sales Rep Email', 'order-tracking' ),
455 'label-sales-rep-form-email-placeholder' => __( 'Sales Rep Email', 'order-tracking' ),
456 'label-sales-rep-form-button' => __( 'Find Sales Rep', 'order-tracking' ),
457 'label-order-information' => __( 'Order Information', 'order-tracking' ),
458 'label-order-number' => __( 'Order Number', 'order-tracking' ),
459 'label-order-name' => __( 'Order Name', 'order-tracking' ),
460 'label-order-notes' => __( 'Order Notes', 'order-tracking' ),
461 'label-customer-notes' => __( 'Customer Notes', 'order-tracking' ),
462 'label-order-status' => __( 'Order Status', 'order-tracking' ),
463 'label-order-location' => __( 'Order Location', 'order-tracking' ),
464 'label-order-updated' => __( 'Order Updated', 'order-tracking' ),
465 'label-order-current-location' => __( 'Current Location', 'order-tracking' ),
466 'label-order-print-button' => __( 'Print', 'order-tracking' ),
467 'label-order-add-note-button' => __( 'Add Note', 'order-tracking' ),
468 'label-order-update-status' => __( 'Update Status', 'order-tracking' ),
469 'label-customer-display-number' => __( 'Customer Number', 'order-tracking' ),
470 'label-customer-display-name' => __( 'Customer Name', 'order-tracking' ),
471 'label-customer-display-email' => __( 'Customer Email', 'order-tracking' ),
472 'label-customer-display-download' => __( 'Download All Orders', 'order-tracking' ),
473 'label-sales-rep-display-number' => __( 'Sales Rep Number', 'order-tracking' ),
474 'label-sales-rep-display-first-name' => __( 'Sales Rep First Name', 'order-tracking' ),
475 'label-sales-rep-display-last-name' => __( 'Sales Rep Last Name', 'order-tracking' ),
476 'label-sales-rep-display-email' => __( 'Sales Rep Email', 'order-tracking' ),
477 'label-sales-rep-display-download' => __( 'Download All Orders', 'order-tracking' ),
478 'label-customer-order-name' => __( 'Order Name', 'order-tracking' ),
479 'label-customer-order-email' => __( 'Order Email Address', 'order-tracking' ),
480 'label-customer-order-notes' => __( 'Customer Notes', 'order-tracking' ),
481 'label-customer-order-button' => __( 'Send Order', 'order-tracking' ),
482 'label-customer-order-thank-you' => __( 'Thank you. Your order number is:', 'order-tracking' ),
483 'label-customer-order-email-instructions' => __( 'The email address to send order updates to, if the site administrator has selected that option.', 'order-tracking' ),
484
485 );
486 }
487
488 public function add_custom_styling() {
489 global $ewd_otp_controller;
490
491 $css = '';
492
493 if ( $ewd_otp_controller->settings->get_setting( 'styling-title-font' ) != '' ) { $css .= '.ewd-otp-order-tracking-form-div h3 { font-family: ' . $ewd_otp_controller->settings->get_setting( 'styling-title-font' ) . ' !important; }'; }
494 if ( $ewd_otp_controller->settings->get_setting( 'styling-title-font-size' ) != '' ) { $css .= '.ewd-otp-order-tracking-form-div h3 { font-size: ' . $ewd_otp_controller->settings->get_setting( 'styling-title-font-size' ) . ' !important; }'; }
495 if ( $ewd_otp_controller->settings->get_setting( 'styling-title-font-color' ) != '' ) { $css .= '.ewd-otp-order-tracking-form-div h3 { color: ' . $ewd_otp_controller->settings->get_setting( 'styling-title-font-color' ) . ' !important; }'; }
496 if ( $ewd_otp_controller->settings->get_setting( 'styling-title-margin' ) != '' ) { $css .= '.ewd-otp-order-tracking-form-div h3 { margin: ' . $ewd_otp_controller->settings->get_setting( 'styling-title-margin' ) . ' !important; }'; }
497 if ( $ewd_otp_controller->settings->get_setting( 'styling-title-padding' ) != '' ) { $css .= '.ewd-otp-order-tracking-form-div h3 { padding: ' . $ewd_otp_controller->settings->get_setting( 'styling-title-padding' ) . ' !important; }'; }
498
499 if ( $ewd_otp_controller->settings->get_setting( 'styling-label-font' ) != '' ) { $css .= '.ewd-otp-tracking-results-label { font-family: ' . $ewd_otp_controller->settings->get_setting( 'styling-label-font' ) . ' !important; }'; }
500 if ( $ewd_otp_controller->settings->get_setting( 'styling-label-font-size' ) != '' ) { $css .= '.ewd-otp-tracking-results-label { font-size: ' . $ewd_otp_controller->settings->get_setting( 'styling-label-font-size' ) . ' !important; }'; }
501 if ( $ewd_otp_controller->settings->get_setting( 'styling-label-font-color' ) != '' ) { $css .= '.ewd-otp-tracking-results-label { color: ' . $ewd_otp_controller->settings->get_setting( 'styling-label-font-color' ) . ' !important; }'; }
502 if ( $ewd_otp_controller->settings->get_setting( 'styling-label-margin' ) != '' ) { $css .= '.ewd-otp-tracking-results-label { margin: ' . $ewd_otp_controller->settings->get_setting( 'styling-label-margin' ) . ' !important; }'; }
503 if ( $ewd_otp_controller->settings->get_setting( 'styling-label-padding' ) != '' ) { $css .= '.ewd-otp-tracking-results-label { padding: ' . $ewd_otp_controller->settings->get_setting( 'styling-label-padding' ) . ' !important; }'; }
504
505 if ( $ewd_otp_controller->settings->get_setting( 'styling-content-font' ) != '' ) { $css .= '.ewd-otp-tracking-results-value { font-family: ' . $ewd_otp_controller->settings->get_setting( 'styling-content-font' ) . ' !important; }'; }
506 if ( $ewd_otp_controller->settings->get_setting( 'styling-content-font-size' ) != '' ) { $css .= '.ewd-otp-tracking-results-value { font-size: ' . $ewd_otp_controller->settings->get_setting( 'styling-content-font-size' ) . ' !important; }'; }
507 if ( $ewd_otp_controller->settings->get_setting( 'styling-content-font-color' ) != '' ) { $css .= '.ewd-otp-tracking-results-value { color: ' . $ewd_otp_controller->settings->get_setting( 'styling-content-font-color' ) . ' !important; }'; }
508 if ( $ewd_otp_controller->settings->get_setting( 'styling-content-margin' ) != '' ) { $css .= '.ewd-otp-tracking-results-value { margin: ' . $ewd_otp_controller->settings->get_setting( 'styling-content-margin' ) . ' !important; }'; }
509 if ( $ewd_otp_controller->settings->get_setting( 'styling-content-padding' ) != '' ) { $css .= '.ewd-otp-tracking-results-value { padding: ' . $ewd_otp_controller->settings->get_setting( 'styling-content-padding' ) . ' !important; }'; }
510
511 if ( $ewd_otp_controller->settings->get_setting( 'styling-button-font-color' ) != '' ) { $css .= '.ewd-otp-submit { color: ' . $ewd_otp_controller->settings->get_setting( 'styling-button-font-color' ) . ' !important; }'; }
512 if ( $ewd_otp_controller->settings->get_setting( 'styling-button-background-color' ) != '' ) { $css .= '.ewd-otp-submit { background-color: ' . $ewd_otp_controller->settings->get_setting( 'styling-button-background-color' ) . ' !important; }'; }
513 if ( $ewd_otp_controller->settings->get_setting( 'styling-button-border' ) != '' ) { $css .= '.ewd-otp-submit { border: ' . $ewd_otp_controller->settings->get_setting( 'styling-button-border' ) . ' !important; }'; }
514 if ( $ewd_otp_controller->settings->get_setting( 'styling-button-margin' ) != '' ) { $css .= '.ewd-otp-submit { margin: ' . $ewd_otp_controller->settings->get_setting( 'styling-button-margin' ) . ' !important; }'; }
515 if ( $ewd_otp_controller->settings->get_setting( 'styling-button-padding' ) != '' ) { $css .= '.ewd-otp-submit { padding: ' . $ewd_otp_controller->settings->get_setting( 'styling-button-padding' ) . ' !important; }'; }
516
517 $css .= $ewd_otp_controller->settings->get_setting( 'custom-css' );
518
519 if( ! empty( $css ) ) {
520 echo '<style>';
521 echo $css;
522 echo '</style>';
523 }
524 }
525
526 }