-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathwpt_event.php
1501 lines (1284 loc) · 38.3 KB
/
wpt_event.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/** Usage:
*
* $event = new WPT_Event();
* $event = new WPT_Event($post_id);
* $event = new WPT_Event($post);
*
* echo $event->html(); // output the details of an event as HTML
*
* echo $event->prices( array('summary'=>true) ) // // a summary of all available ticketprices
* echo $event->datetime() // timestamp of the event
* echo $event->startdate() // localized and formatted date of the event
* echo $event->starttime() // localized and formatted time of the event
*
*/
class WPT_Event {
const post_type_name = 'wp_theatre_event';
const tickets_status_onsale = '_onsale';
const tickets_status_hidden = '_hidden';
const tickets_status_cancelled = '_cancelled';
const tickets_status_soldout = '_soldout';
const tickets_status_other = '_other';
public $ID;
public $PostClass;
public $post;
public $format;
public $city;
public $location;
public $production;
public $remark;
public $title;
public $venue;
function __construct( $ID = false, $PostClass = false ) {
$this->PostClass = $PostClass;
if ( $ID instanceof WP_Post ) {
// $ID is a WP_Post object
if ( ! $PostClass ) {
$this->post = $ID;
}
$ID = $ID->ID;
}
$this->ID = $ID;
$this->format = 'full';
}
function post_type() {
return get_post_type_object( self::post_type_name );
}
function post_class() {
$classes = array();
$classes[] = self::post_type_name;
return implode( ' ',$classes );
}
protected function apply_template_filters( $value, $filters ) {
foreach ( $filters as $filter ) {
$value = $filter->apply_to( $value, $this );
}
return $value;
}
/**
* Event city.
*
* @since 0.4
* @since 0.15.29 Added a filter for the event city value.
* See: https://github.com/slimndap/wp-theatre/issues/254
*
* @return string City.
*/
function city( $args = array() ) {
global $wp_theatre;
$defaults = array(
'html' => false,
'filters' => array(),
);
$args = wp_parse_args( $args, $defaults );
if ( ! isset( $this->city ) ) {
/**
* Filter the value of the event city.
*
* @since 0.15.29
* @param string $city The value of the event city.
* @param WPT_Event $event The event.
*/
$this->city = apply_filters( 'wpt_event_city', get_post_meta( $this->ID, 'city', true ), $this );
}
if ( $args['html'] ) {
$html = '<div class="'.self::post_type_name.'_city">';
$html .= $this->apply_template_filters( $this->city, $args['filters'] );
$html .= '</div>';
return apply_filters( 'wpt_event_city_html', $html, $this );
} else {
return $this->city;
}
}
/**
* Returns value of a custom field.
*
* @since 0.8.3
* @since 0.15 Fixed an error when no production is set for the event.
* @since 0.15.27 Fix: $fallback_to_production was not doing anything.
* Deprecated the $args argument.
* Moved HTML output to WPT_Event::custom_html().
*
* @uses WPT_Event::custom_html() to get the HTM for a custom field.
* @uses WPT_Event::production() to get the production of an event.
*
* @param string $field The custom field.
* @param bool $fallback_to_production Use the value of the production if the value of the event is empty?
* Defaults to <true>.
* @return string The value of a custom field.
*/
function custom( $field, $fallback_to_production = true ) {
// Add backwards compatibility for the deprecated $args argument.
if ( is_array( $fallback_to_production ) && !empty( $fallback_to_production['html'] ) ) {
$filters = array();
if ( !empty( $fallback_to_production['filters'] ) ) {
$filters = $fallback_to_production['filters'];
}
return $this->custom_html( $field, $filters );
}
$value = get_post_meta( $this->ID, $field, true );
/**
* Filter the value of a custom field.
*
* @since 0.8.3
* @param string $value The value of a custom field.
* @param string $field The custom field.
* @param WPT_Event $event The event.
*/
$value = apply_filters( 'wpt_event_'.$field, $value, $field, $this );
if ( empty($value) && $fallback_to_production && $production = $this->production() ) {
$value = $production->custom( $field );
}
return $value;
}
/**
* Gets the HTML for a custom field.
*
* @since 0.15.27
*
* @uses WPT_Event::custom() to get the value of a custom field.
* @uses WPT_Event::apply_template_filters() to apply template filters to the custom field value.
*
* @param string $field The custom field.
* @param array $filters The template filters to apply.
* @param bool $fallback_to_production Use the value of the production if the value of the event is empty?
* @return string The HTML for a custom field.
*/
function custom_html( $field, $filters = array(), $fallback_to_production = true ) {
$value = $this->custom( $field, $fallback_to_production );
ob_start();
?><div class="<?php echo self::post_type_name; ?>_<?php echo $field; ?>"><?php
echo $this->apply_template_filters( $value, $filters );
?></div><?php
$html = ob_get_clean();
/**
* Filter the HTML for a custom field.
*
* @since 0.8.3
*
* @param string $html The HTML for a custom field.
* @param string $field The custom field.
* @param WPT_Event $event The event.
*/
$html = apply_filters( 'wpt_event_'.$field.'_html', $html, $field, $this );
return $html;
}
/**
* Gets the event timestamp.
*
* @since 0.4
* @since 0.10.15 Always return the datetime in UTC.
* @since 0.12.7 Moved HTML output to WPT_Event::datetime_html().
*
* @param bool $enddate Wheter to return the end datetime instead of the start endtime.
* @return datetime The event timestamp.
* Returns false if no date is set.
*/
function datetime( $enddate = false ) {
if ( ! empty( $enddate['html'] ) ) {
$filters = array();
if ( ! empty( $enddate['filters'] ) ) {
$filters = $enddate['filters'];
}
return $this->datetime_html( $filters );
}
if ( ! empty( $enddate['start'] ) ) {
$enddate = false;
}
if ( false === $enddate ) {
$date = get_post_meta( $this->ID, 'event_date', true );
} else {
$date = get_post_meta( $this->ID, 'enddate', true );
}
if ( empty( $date ) ) {
return false;
}
$datetime = date_i18n( 'U', strtotime( $date, current_time( 'timestamp' ) ) - get_option( 'gmt_offset' ) * 3600 );
/**
* Filter the event datetime.
*
* @since 0.12.7
* @param datetime $datetime The event timestamp.
* @param WPT_Event $event The event.
*/
$datetime = apply_filters( 'wpt/event/datetime', $datetime, $this );
$datetime = apply_filters( 'wpt_event_datetime', $datetime, $this );
return $datetime;
}
/**
* Gets the HTML for the event timestamp.
*
* @since 0.12.7
* @param array $filters The template filters to apply.
* @return sring The HTML for the event timestamp.
*/
function datetime_html( $filters = array() ) {
$html = '<div class="'.self::post_type_name.'_datetime">';
$datetime_html = $this->startdate_html().$this->starttime_html();
foreach ( $filters as $filter ) {
if ( 'date' == $filter->name ) {
$datetime_html = $filter->apply_to( $this->datetime(), $this );
} else {
$datetime_html = $filter->apply_to( $datetime_html, $this );
}
}
$html .= $datetime_html;
$html .= '</div>';
/**
* Filter the HTML for the event timestamp.
*
* @since 0.12.7
* @param string $html The HTML for the event timestamp.
* @param array $filters The template filters to apply.
* @param WPT_Event $event The event.
*/
$html = apply_filters( 'wpt/event/datetime/html', $html, $filters, $this );
return $html;
}
/**
* Gets the duration of an event.
*
* @since 0.?
* @since 0.15.16 Fixed call to apply_template_filters(). '$this->' was missing.
* See: https://github.com/slimndap/wp-theatre/pull/231
* @param array $args (default: array())
* @return string
*/
function duration( $args = array() ) {
global $wp_theatre;
$defaults = array(
'html' => false,
'filters' => array(),
);
$args = wp_parse_args( $args, $defaults );
if (
! isset( $this->duration ) &&
! empty( $this->post()->enddate ) &&
$this->post()->enddate > $this->post()->event_date
) {
// Don't use human_time_diff until filters are added.
// See: https://core.trac.wordpress.org/ticket/27271
// $this->duration = apply_filters('wpt_event_duration',human_time_diff(strtotime($this->post()->enddate), strtotime($this->post()->event_date)),$this);
$seconds = abs( strtotime( $this->post()->enddate ) - strtotime( $this->post()->event_date ) );
$minutes = (int) $seconds / 60;
$text = $minutes.' '._n( 'minute','minutes', $minutes, 'theatre' );
$this->duration = apply_filters( 'wpt_event_duration',$text,$this );
}
if ( $args['html'] ) {
$html = '';
$html .= '<div class="'.self::post_type_name.'_duration">';
$html .= $this->apply_template_filters( $this->duration, $args['filters'] );
$html .= '</div>';
return $html;
} else {
return $this->duration;
}
}
/**
* Gets the event enddate.
*
* @since 0.12
* @since 0.12.7 Now returns <false> is no endate is set.
* See: https://github.com/slimndap/wp-theatre/issues/165
* @return string The event enddate.
* Returns <false> if no endate is set.
*/
function enddate() {
$enddate = false;
if ( $datetime = $this->datetime( true ) ) {
$enddate = date_i18n(
get_option( 'date_format' ),
$datetime + get_option( 'gmt_offset' ) * 3600
);
}
$enddate = apply_filters( 'wpt/event/enddate', $enddate, $this );
return $enddate;
}
/**
* Gets the HTML for the event enddate.
*
* @since 0.12
* @since 0.12.7 No longer returns a date when no enddate is set.
* See: https://github.com/slimndap/wp-theatre/issues/165
* @param array $filters The template filters to apply.
* @return sring The HTML for the event enddate.
*/
function enddate_html( $filters = array() ) {
$html = '<div class="'.self::post_type_name.'_date '.self::post_type_name.'_enddate">';
if ( $enddate_html = $this->enddate() ) {
foreach ( $filters as $filter ) {
if ( 'date' == $filter->name ) {
$enddate_html = $filter->apply_to(
$this->datetime( true ) + get_option( 'gmt_offset' ) * 3600,
$this
);
} else {
$enddate_html = $filter->apply_to( $enddate_html, $this );
}
}
$html .= $enddate_html;
}
$html .= '</div>';
$html = apply_filters( 'wpt/event/enddate/html', $html, $filters, $this );
return $html;
}
/**
* Gets the event endtime.
*
* @since 0.12
* @since 0.12.7 Now returns <false> is no endate is set.
* See: https://github.com/slimndap/wp-theatre/issues/165
* @return string The event endtime.
* Returns <false> if no endate is set.
*/
function endtime() {
$endtime = false;
if ( $datetime = $this->datetime( true ) ) {
$endtime = date_i18n(
get_option( 'time_format' ),
$datetime + get_option( 'gmt_offset' ) * 3600
);
}
$endtime = apply_filters( 'wpt/event/endtime', $endtime, $this );
return $endtime;
}
/**
* Gets the HTML for the event endtime.
*
* @since 0.12
* @since 0.12.7 No longer returns a time when no enddate is set.
* See: https://github.com/slimndap/wp-theatre/issues/165
* @param array $filters The template filters to apply.
* @return sring The HTML for the event endtime.
*/
function endtime_html( $filters = array() ) {
global $wp_theatre;
$html = '<div class="'.self::post_type_name.'_time '.self::post_type_name.'_endtime">';
if ( $endtime_html = $this->endtime() ) {
foreach ( $filters as $filter ) {
if ( 'date' == $filter->name ) {
$endtime_html = $filter->apply_to( $this->datetime( true ) + get_option( 'gmt_offset' ) * 3600, $this );
} else {
$endtime_html = $filter->apply_to( $endtime_html, $this );
}
}
$html .= $endtime_html;
}
$html .= '</div>';
$html = apply_filters( 'wpt/event/endtime/html', $html, $filters, $this );
return $html;
}
/**
* Event location.
*
* Returns the event venue and city combined as plain text or as an HTML element.
*
* @since 0.4
*
* @param array $args {
* @type bool $html Return HTML? Default <false>.
* }
*
* @see WPT_Event::venue().
* @see WPT_Event::city().
*
* @return string text or HTML.
*/
function location( $args = array() ) {
global $wp_theatre;
$defaults = array(
'html' => false,
'filters' => array(),
);
$args = wp_parse_args( $args, $defaults );
if ( ! isset( $this->location ) ) {
$location = '';
$venue = $this->venue();
$city = $this->city();
if ( ! empty( $venue ) ) {
$location .= $this->venue();
}
if ( ! empty( $city ) ) {
if ( ! empty( $venue ) ) {
$location .= ' ';
}
$location .= $this->city();
}
$this->location = apply_filters( 'wpt_event_location',$location,$this );
}
if ( $args['html'] ) {
$venue = $this->venue();
$city = $this->city();
$html = '';
$html .= '<div class="'.self::post_type_name.'_location">';
$html .= $this->venue( $args );
$html .= $this->city( $args );
$html .= '</div>'; // .location
return apply_filters( 'wpt_event_location_html', $html, $this );
} else {
return $this->location;
}
}
/**
* Get the event permalink.
*
* The permalink is inherited from the parent production.
*
* @since 0.?
* @since 0.13.6 Added a 'wpt/event/permalink' filter.
* Moved HTML version to separate function.
* @return string The permalink.
*/
function permalink( $deprecated = array() ) {
if ( ! empty( $deprecated['html'] ) ) {
return $this->permalink_html( $deprecated );
}
$permalink = $this->production()->permalink( $deprecated );
/**
* Filter the event permalink.
*
* @since 0.13.6
* @param string $permalink The event permalink.
* @param WPT_Event $event The event.
*/
$permalink = apply_filters( 'wpt/event/permalink', $permalink, $this );
return $permalink;
}
/**
* Get the HTML for the event permalink.
*
* The permalink is inherited from the parent production.
*
* @since 0.13.6
* @return string The HTML for the event permalink.
*/
function permalink_html( $args = array() ) {
$args['html'] = true;
$html = $this->production()->permalink( $args );
/**
* Filter the HTML for the event permalink.
*
* @since 0.13.6
* @param string $html The HTML for the event permalink.
* @param WPT_Event $event The event.
*/
$html = apply_filters( 'wpt/event/permalink/html', $html, $this );
return $html;
}
/**
* Gets the event prices.
*
* @since 0.4
* @since 0.10.14 Deprecated the HTML argument.
* Use @see WPT_Event::prices_html() instead.
*
* @return array The event prices.
*/
function prices( $deprecated = array() ) {
if ( ! empty( $deprecated['html'] ) ) {
return $this->prices_html();
}
if ( ! empty( $deprecated['summary'] ) ) {
return $this->prices_summary();
}
$prices = get_post_meta( $this->ID,'_wpt_event_tickets_price' );
for ( $p = 0;$p < count( $prices );$p++ ) {
$price_parts = explode( '|',$prices[ $p ] );
$prices[ $p ] = (float) $price_parts[0];
}
/**
* Filter the event prices.
*
* @since 0.10.14
* @param array $prices The current prices.
* @param WPT_Event $event The event.
*/
$prices = apply_filters( 'wpt/event/prices',$prices, $this );
/**
* @deprecated 0.10.14
*/
$prices = apply_filters( 'wpt_event_prices',$prices, $this );
return $prices;
}
/**
* Gets the HTML for the event prices.
*
* @since 0.10.14
* @see WPT_Event::prices_summary_html()
* @return string The HTML.
*/
public function prices_html() {
$html = '';
$prices_summary_html = $this->prices_summary_html();
if ( ! empty( $prices_summary_html ) ) {
$html = '<div class="'.self::post_type_name.'_prices">'.$prices_summary_html.'</div>';
}
/**
* Filter the HTML for the event prices.
*
* @since 0.10.14
* @param string $html The current html.
* @param WPT_Event $event The event.
*/
$html = apply_filters( 'wpt/event/prices/html', $html, $this );
/**
* @deprecated 0.10.14
*/
$html = apply_filters( 'wpt_event_prices_html', $html, $this );
return $html;
}
/**
* Gets a summary of event prices.
*
* @since 0.10.14
* @see WPT_Event::prices()
* @return array A summary of event prices.
*/
public function prices_summary() {
global $wp_theatre;
$prices = $this->prices();
$prices_summary = '';
if ( count( $prices ) ) {
if ( count( $prices ) > 1 ) {
$prices_summary .= __( 'from','theatre' ).' ';
}
if ( ! empty( $wp_theatre->wpt_tickets_options['currencysymbol'] ) ) {
$prices_summary .= $wp_theatre->wpt_tickets_options['currencysymbol'].' ';
}
$prices_summary .= number_format_i18n( (float) min( $prices ), 2 );
}
/**
* Filter the summary of event prices.
*
* @since 0.10.14
* @param string $prices_summary The current summary.
* @param WPT_Event $event The event.
*/
$prices_summary = apply_filters( 'wpt/event/prices/summary',$prices_summary, $this );
return $prices_summary;
}
/**
* Gets the HTML for the summary of event prices.
*
* @since 0.10.14
* @see WPT_Event::prices_summary()
* @return string The HTML.
*/
public function prices_summary_html() {
$html = $this->prices_summary();
$html = esc_html( $html );
$html = str_replace( ' ', ' ', $html );
/**
* Filter the HTML for the summary of event prices.
*
* @since 0.10.14
* @param string $html The current html.
* @param WPT_Event $event The event.
*/
$html = apply_filters( 'wpt/event/prices/summary/html', $html, $this );
return $html;
}
/**
* Event production.
*
* Returns the production of the event as a WPT_Production object.
*
* @since 0.4
* @since 0.15 Removed local caching of event production.
* Return <false> if no production is set.
*
* @return WPT_Production The production.
* Returns <false> if no production is set.
*/
function production() {
$production_id = get_post_meta( $this->ID,WPT_Production::post_type_name, true );
// Bail if no production ID is set.
if (empty($production_id)) {
return false;
}
/*
* Bail if production doesn't exist.
* See: https://tommcfarlin.com/wordpress-post-exists-by-id/
*/
if (FALSE === get_post_status( $production_id )) {
return false;
}
$production = new WPT_Production( $production_id, $this->PostClass );
return $production;
}
/**
* Event remark.
*
* Returns the event remark as plain text of as an HTML element.
*
* @since 0.4
*
* @param array $args {
* @type bool $html Return HTML? Default <false>.
* }
* @return string text or HTML.
*/
function remark( $args = array() ) {
global $wp_theatre;
$defaults = array(
'html' => false,
'text' => false,
'filters' => array(),
);
$args = wp_parse_args( $args, $defaults );
if ( ! isset( $this->remark ) ) {
$this->remark = apply_filters( 'wpt_event_remark',get_post_meta( $this->ID,'remark',true ), $this );
}
if ( $args['html'] ) {
$html = '';
$html .= '<div class="'.self::post_type_name.'_remark">';
$html .= $this->apply_template_filters( $this->remark, $args['filters'] );
$html .= '</div>';
return apply_filters( 'wpt_event_remark_html', $html, $this );
} else {
return $this->remark;
}
}
/**
* Gets a valid event tickets link.
*
* Returns a valid event tickets URL for events that are on sales and take
* place in the future.
*
* @since 0.4
* @since 0.10.14 Deprecated the HTML argument.
* Use @see WPT_Event::tickets_html() instead.
* @since 0.13.1 Check for upcoming event now accounts for timezones.
* Fixes #167.
*
* @return string The tickets URL or ''.
*/
function tickets( $deprecated = array() ) {
if ( ! empty( $deprecated['html'] ) ) {
return $this->tickets_html();
}
$tickets = '';
if (
self::tickets_status_onsale == $this->tickets_status() &&
$this->datetime() > current_time( 'timestamp', true )
) {
$tickets = $this->tickets_url();
}
/**
* Filter the valid event tickets link.
*
* @since 0.10.14
* @param array $prices The current valid event tickets link.
* @param WPT_Event $event The event.
*/
$tickets = apply_filters( 'wpt/event/tickets',$tickets,$this );
/**
* @deprecated 0.10.14
*/
$tickets = apply_filters( 'wpt_event_tickets',$tickets,$this );
return $tickets;
}
/**
* Gets the text for the event tickets link.
*
* @since 0.10.14
* @return string The text for the event tickets link.
*/
public function tickets_button() {
$tickets_button = get_post_meta( $this->ID,'tickets_button',true );
if ( empty( $tickets_button ) ) {
$tickets_button = __( 'Tickets', 'theatre' );
}
/**
* Filter the text for the event tickets link.
*
* @since 0.10.14
* @param string $tickets_button The current text for the event tickets link.
* @param WPT_Event $event The event.
*/
$tickets_button = apply_filters( 'wpt/event/tickets/button', $tickets_button, $this );
return ($tickets_button);
}
/**
* Gets the HTML for a valid event tickets link.
*
* @since 0.10.14
* @since 0.11.10 Don't return anything for historic events with an 'on sale' status.
* Fixes #118.
* @since 0.13.1 Check for upcoming event now accounts for timezones.
* Fixes #167.
*
* @return string The HTML for a valid event tickets link.
*/
public function tickets_html() {
$html = '';
$tickets_status = $this->tickets_status();
$html .= '<div class="'.self::post_type_name.'_tickets">';
if ( self::tickets_status_onsale == $this->tickets_status() ) {
if ( $this->datetime() > current_time( 'timestamp', true ) ) {
$html .= $this->tickets_url_html();
$prices_html = $this->prices_html();
$prices_html = apply_filters( 'wpt_event_tickets_prices_html', $prices_html, $this );
$html .= $prices_html;
}
} else {
$html .= $this->tickets_status_html();
}
$html .= '</div>'; // .tickets
/**
* Filter the HTML for the valid event tickets link.
*
* @since 0.10.14
* @param string $html The current HTML.
* @param WPT_Event $event The event.
*/
$html = apply_filters( 'wpt/event/tickets/html', $html, $this );
/**
* @deprecated 0.10.14
*/
$html = apply_filters( 'wpt_event_tickets_html', $html, $this );
return $html;
}
/**
* Gets the event tickets status.
*
* @since 0.10.14
* @return string The event tickets status.
*/
public function tickets_status() {
$tickets_status = get_post_meta( $this->ID,'tickets_status',true );
if ( empty( $tickets_status ) ) {
$tickets_status = self::tickets_status_onsale;
}
/**
* Filter the tickets status value for an event.
*
* @since 0.10.14 Renamed filter.
*
* @param string $status The current value of the tickets status.
* @param WPT_Event $this The event object.
*/
$tickets_status = apply_filters( 'wpt/event/tickets/status', $tickets_status, $this );
/**
* @since 0.10.9
* @deprecated 0.10.14
*/
$tickets_status = apply_filters( 'wpt_event_tickets_status', $tickets_status, $this );
return $tickets_status;
}
/**
* Get the HTML for the event tickets status.
*
* @since 0.10.14
* @return string The HTML for the event tickets status.
*/
public function tickets_status_html() {
$tickets_status = $this->tickets_status();
switch ( $tickets_status ) {
case self::tickets_status_onsale :
$label = __( 'On sale','theatre' );
break;
case self::tickets_status_soldout :
$label = __( 'Sold out','theatre' );
break;
case self::tickets_status_cancelled :
$label = __( 'Cancelled','theatre' );
break;
case self::tickets_status_hidden :
$label = '';
break;
default :
$label = $tickets_status;
$tickets_status = self::tickets_status_other;
}
$html = '';
if ( ! empty( $label ) ) {
$html .= '<span class="'.self::post_type_name.'_tickets_status '.self::post_type_name.'_tickets_status'.$tickets_status.'">'.$label.'</span>';
}
/**
* Filter the HTML for the event tickets status.
*
* @since 0.10.14
* @param string $html The current HTML.
* @param WPT_Event $event The event.
*/
$html = apply_filters( 'wpt/event/tickets/status/html', $html, $this );
return $html;
}
/**
* Gets the event tickets URL.
*
* @since 0.8.3
* @since 0.10.14 Deprecated the HTML argument.
* Use @see WPT_Event::tickets_url_html() instead.
* @since 0.12 Moved the iframe url to a new method.
* @see WPT_Event::tickets_url_iframe().
* @return string The event tickets URL.
*/
function tickets_url( $deprecated = array() ) {
global $wp_theatre;
if ( ! empty( $deprecated['html'] ) ) {
return $this->tickets_url_html();
}
$tickets_url = get_post_meta( $this->ID,'tickets_url',true );
if (
! empty( $wp_theatre->wpt_tickets_options['integrationtype'] ) &&
'iframe' == $wp_theatre->wpt_tickets_options['integrationtype'] &&
! empty( $tickets_url ) &&
$tickets_url_iframe = $this->tickets_url_iframe()
) {
$tickets_url = $tickets_url_iframe;
}
/**
* Filter the event tickets URL.
*
* @since 0.10.14
*
* @param string $status The current value of the event tickets URL.
* @param WPT_Event $this The event object.
*/
$tickets_url = apply_filters( 'wpt/event/tickets/url',$tickets_url,$this );
/**
* @deprecated 0.10.14
*/
$tickets_url = apply_filters( 'wpt_event_tickets_url',$tickets_url,$this );
return $tickets_url;
}
/**
* Gets the event tickets iframe URL.
*
* @since 0.12