Theater for WordPress Code Reference
  • Package
  • Class

Packages

  • Theater
    • Abstracts
    • Events

Classes

  • Theater
  • Theater_Event
  • Theater_Event_Date
  • Theater_Event_Date_Link
  • Theater_Event_Date_List
  • Theater_Event_Field
  • Theater_Event_List
  • Theater_Item
  • Theater_List

Functions

  • Theater
   1 <?php
   2 
   3 /**
   4  * Handles individual event dates.
   5  *
   6  * Each event can have one or more event dates.
   7  *
   8  * ##Usage
   9  *
  10  * <code>
  11  * // Output an event date as HTML.
  12  * $date = new Theater_Event_Date( 123 );
  13  * echo $date;
  14  * </code>
  15  * <code>
  16  * // Output an event date as HTML with a custom template:
  17  * $date = new Theater_Event_Date( 123, '{{title}}{{startdate}}{{city}}{{tickets}}' );
  18  * echo $date;
  19  * </code>
  20  * <code>
  21  * // Get the value of an event date field:
  22  * $date = new Theater_Event_Date( 123 );
  23  * $startdate = $date->startdate(); // Eg. '05-06-2017'.
  24  * $prices = $date->prices(); // An array of all ticket prices for this date.
  25  * $title = $date->title(); // Eg. 'Sound of Music'.
  26  * </code>
  27  * <code>
  28  * // Output the value of an event date field as HTML:
  29  * $date = new Theater_Event_Date( 123 );
  30  * echo $date->startdate;
  31  * echo $date->prices;
  32  * echo $date->title;
  33  * </code>
  34  *
  35  * ## Fields
  36  *
  37  * Event dates have the following fields:
  38  * | field | description |
  39  * |---|---|
  40  * | `duration` | The duration, based on the starttime and endtime. |
  41  * | `enddate` | The end date |
  42  * | `endtime` | The end time |
  43  * | `enddatetime` | The timestamp of the end |
  44  * | `location` | The location, based on the venue and the city.
  45  * | `prices` | The different prices.
  46  * | `startdate` | The start date |
  47  * | `starttime` | The start time |
  48  * | `startdatetime` | The timestamp of the start |
  49  * | `tickets` | The tickets link.
  50  * | `venue` | The venue.
  51  * | `city` | The city.
  52  * 
  53  * Additionally, the following fields are inherited from the parent event:
  54  *
  55  * | field | description |
  56  * |---|---|
  57  * | `categories` | The categories of the event.
  58  * | `cities` | A summary of all the cities that the event takes place.
  59  * | `content` | The post content of the event.
  60  * | `dates` | A summary of all the dates of the event.
  61  * | `excerpt` | The excerpt of the event.
  62  * | `summary` | A summary of the event.
  63  * | `permalink` | The permalink of the event.
  64  * | `title` | The title of the event.
  65  * | `thumbnail` | The thumbnail image of the event.
  66  *
  67  * ## HTML template
  68  *
  69  * The default template for the HTML output of an event date is:
  70  * `{{thumbnail|permalink}} {{title|permalink}} {{remark}} {{startdatetime}} {{location}} {{tickets}}`
  71  *
  72  * @package Theater/Events
  73  * @since   0.16
  74  *
  75  */
  76 
  77 class Theater_Event_Date extends Theater_Item {
  78 
  79     const name = 'date';
  80     const post_type_name = 'wp_theatre_event';
  81 
  82     const tickets_status_onsale = '_onsale';
  83     const tickets_status_hidden = '_hidden';
  84     const tickets_status_cancelled = '_cancelled';
  85     const tickets_status_soldout = '_soldout';
  86     const tickets_status_other = '_other';
  87 
  88     function get_fields() {
  89 
  90         $fields = array(
  91             'duration',
  92             'enddate',
  93             'enddatetime',
  94             'endtime',
  95             'event',
  96             'location',
  97             'prices',
  98             'prices_summary',
  99             'startdate',
 100             'startdatetime',
 101             'starttime',
 102             'tickets',
 103             'tickets_button',
 104             'tickets_status',
 105             'tickets_url',
 106             'venue',
 107             'city',
 108         );
 109 
 110         return $fields;
 111     }
 112 
 113     /**
 114      * Gets the duration of an event date.
 115      *
 116      * @since   0.x?
 117      * @internal
 118      * @uses    Theater_Event_Date::get_field() to get the start of an event date.
 119      * @uses    Theater_Event_Date::get_field() to get the end of an event date.
 120      * @return  string  The duration of an event date.
 121      */
 122     function get_duration() {
 123 
 124         $startdate = $this->get_field( 'startdatetime' );
 125         $enddate = $this->get_field( 'enddatetime' );
 126 
 127         if ( empty( $enddate ) ) {
 128             return '';
 129         }
 130 
 131         if ( $enddate < $startdate ) {
 132             return '';
 133         }
 134 
 135         $seconds = $enddate - $startdate;
 136         $minutes = (int) $seconds / 60;
 137         $value = $minutes.' '._n( 'minute','minutes', $minutes, 'theatre' );
 138 
 139         return $value;
 140 
 141     }
 142 
 143     /**
 144      * Gets the event enddate.
 145      *
 146      * @since   0.12
 147      * @since   0.12.7  Now returns <false> is no endate is set.
 148      *                  See [#165](https://github.com/slimndap/wp-theatre/issues/165).
 149      * @uses    Theater_Event_Date::get_field() to get the end of an event date.
 150      * @internal
 151      * @return  string  The event enddate.
 152      *                  Returns <false> if no endate is set.
 153      */
 154     function get_enddate() {
 155 
 156         $enddate = false;
 157         if ( $datetime = $this->get_field( 'enddatetime' ) ) {
 158             $enddate = date_i18n(
 159                 get_option( 'date_format' ),
 160                 $datetime + get_option( 'gmt_offset' ) * 3600
 161             );
 162         }
 163         return $enddate;
 164     }
 165 
 166     /**
 167      * Gets the HTML for the event date enddate.
 168      *
 169      * @since   0.12
 170      * @uses    Theater_Item::get_post_type() to add the post type to the classes of the HTML output.
 171      * @uses    Theater_Event_Date::get_field() to get the raw end time of an event date for use with the 'date' filter.
 172      * @uses    Theater_Event_Date::get_field() to get the end date of an event date.
 173      * @uses    WPT_Template_Placeholder_Filter::apply_to() to apply filters to the field value.
 174      * @internal
 175      * @param   WPT_Template_Placeholder_Filter[]   $filters    An array of filters to apply to the value if the field.
 176      * @return  string              The HTML for the event date enddate.
 177      */
 178     function get_enddate_html( $filters = array() ) {
 179 
 180         ob_start();
 181         ?><div class="<?php echo $this->get_post_type();?>_date <?php echo $this->get_post_type(); ?>_enddate"><?php
 182 
 183 if ( $value = $this->get_field( 'enddate' ) ) {
 184 
 185     foreach ( $filters as $filter ) {
 186         if ( 'date' == $filter->name ) {
 187             $value = $filter->apply_to( $this->get_field( 'enddatetime' ), $this );
 188         } else {
 189             $value = $filter->apply_to( $value, $this );
 190         }
 191     }
 192 
 193     echo $value;
 194 
 195 }
 196 
 197         ?></div><?php
 198 
 199         $html = ob_get_clean();
 200 
 201         return $html;
 202     }
 203 
 204     /**
 205      * Gets the event date endtime.
 206      *
 207      * @since   0.12
 208      * @uses    Theater_Event_Date::get_field() to get the end of an event date.
 209      * @internal
 210      * @return  string|bool The event endtime.
 211      *                      Returns <false> if no endate is set.
 212      */
 213     function get_endtime() {
 214 
 215         $endtime = false;
 216         if ( $datetime = $this->get_field( 'enddatetime' ) ) {
 217             $endtime = date_i18n(
 218                 get_option( 'time_format' ),
 219                 $datetime + get_option( 'gmt_offset' ) * 3600
 220             );
 221         }
 222         return $endtime;
 223 
 224     }
 225 
 226     /**
 227      * Gets the HTML for the event endtime.
 228      *
 229      * @since   0.12
 230      * @uses    Theater_Item::get_post_type() to add the post type to the classes of the HTML output.
 231      * @uses    Theater_Event_Date::get_field() to get the raw end time of an event date for use with the 'date' filter.
 232      * @uses    Theater_Event_Date::get_field() to get the end time of an event date.
 233      * @uses    WPT_Template_Placeholder_Filter::apply_to() to apply filters to the field value.
 234      * @internal
 235      * @param   WPT_Template_Placeholder_Filter[]   $filters    An array of filters to apply to the value if the field.
 236      * @return  string              The HTML for the event endtime.
 237      */
 238     function get_endtime_html( $filters = array() ) {
 239 
 240         ob_start();
 241         ?><div class="<?php echo $this->get_post_type();?>_time <?php echo $this->get_post_type(); ?>_endtime"><?php
 242 
 243 if ( $value = $this->get_field( 'endtime' ) ) {
 244 
 245     foreach ( $filters as $filter ) {
 246         if ( 'date' == $filter->name ) {
 247             $value = $filter->apply_to( $this->get_field( 'enddatetime' ), $this );
 248         } else {
 249             $value = $filter->apply_to( $value, $this );
 250         }
 251     }
 252 
 253     echo $value;
 254 
 255 }
 256 
 257         ?></div><?php
 258 
 259         $html = ob_get_clean();
 260 
 261         return $html;
 262     }
 263 
 264     /**
 265      * Gets the event that this date belongs to.
 266      *
 267      * @since   0.4
 268      * @since   0.15    Removed local caching of event production.
 269      *                  Return <false> if no production is set.
 270      *
 271      * @uses    WPT_Production::post_type_name
 272      * @return  WPT_Production|bool The event or <false> if no event is set.
 273      */
 274     function get_event() {
 275 
 276         $event_id = get_post_meta( $this->ID, WPT_Production::post_type_name, true );
 277 
 278         // Bail if no production ID is set.
 279         if ( empty( $event_id ) ) {
 280             return false;
 281         }
 282 
 283         /*
 284          * Bail if production doesn't exist.
 285          * See: https://tommcfarlin.com/wordpress-post-exists-by-id/
 286          */
 287         if ( false === get_post_status( $event_id ) ) {
 288             return false;
 289         }
 290 
 291         $event = new Theater_Event( $event_id );
 292         return $event;
 293 
 294     }
 295 
 296     /**
 297      * Get the event permalink.
 298      *
 299      * The permalink is inherited from the parent production.
 300      *
 301      * @since   0.?
 302      * @since   0.13.6  Added a 'wpt/event/permalink' filter.
 303      *                  Moved HTML version to separate function.
 304      * @uses    WPT_Production::permalink() to get the permalink for an event.
 305      * @internal
 306      * @return  string  The permalink.
 307      */
 308     function permalink( $deprecated = array() ) {
 309 
 310         if ( ! empty( $deprecated['html'] ) ) {
 311             return $this->permalink_html( $deprecated );
 312         }
 313 
 314         $permalink = $this->event()->permalink( $deprecated );
 315 
 316         /**
 317          * Filter the event permalink.
 318          *
 319          * @since   0.13.6
 320          * @param   string      $permalink  The event permalink.
 321          * @param   WPT_Event   $event      The event.
 322          */
 323         $permalink = apply_filters( 'wpt/event/permalink', $permalink, $this );
 324         return $permalink;
 325     }
 326 
 327     /**
 328      * Get the HTML for the event permalink.
 329      *
 330      * The permalink is inherited from the parent production.
 331      *
 332      * @since   0.13.6
 333      * @uses    WPT_Production::permalink() to get the HTML for the permalink for an event.
 334      * @internal
 335      * @return  string  The HTML for the event permalink.
 336      */
 337     function permalink_html( $args = array() ) {
 338 
 339         $args['html'] = true;
 340         $html = $this->event()->permalink( $args );
 341 
 342         /**
 343          * Filter the HTML for the event permalink.
 344          *
 345          * @since   0.13.6
 346          * @param   string      $html   The HTML for the event permalink.
 347          * @param   WPT_Event   $event  The event.
 348          */
 349         $html = apply_filters( 'wpt/event/permalink/html', $html, $this );
 350         return $html;
 351     }
 352 
 353     /**
 354      * Gets the event prices.
 355      *
 356      * @since   0.4
 357      * @internal
 358      * @return  array   The event prices.
 359      */
 360     function get_prices() {
 361 
 362         $prices = array();
 363 
 364         $prices_named = get_post_meta( $this->ID,'_wpt_event_tickets_price' );
 365 
 366         foreach ( $prices_named as $price_named ) {
 367             $price_parts = explode( '|',$price_named );
 368             $prices[] = (float) $price_parts[0];
 369         }
 370 
 371         return $prices;
 372     }
 373 
 374     /**
 375      * Gets the HTML for the event prices.
 376      *
 377      * @since   0.10.14
 378      * @uses    Theater_Event_Date::get_field_html() to get a summary of the prices for an event date.
 379      * @uses    Theater_Item::get_post_type() to add the post type to the classes of the HTML output.
 380      * @internal
 381      * @return  string  The HTML for the event prices.
 382      */
 383     public function get_prices_html() {
 384 
 385         $html = '';
 386 
 387         $prices_summary_html = $this->get_field_html( 'prices_summary' );
 388 
 389         if ( '' != $prices_summary_html ) {
 390             $html = '<div class="'.$this->get_post_type().'_prices">'.$prices_summary_html.'</div>';
 391         }
 392 
 393         return $html;
 394 
 395     }
 396 
 397     /**
 398      * Gets a summary of event date prices.
 399      *
 400      * @since   0.10.14
 401      * @uses    Theater_Event_Date::get_field() to get all prices for an event date.
 402      * @internal
 403      * @return  string  A summary of event date prices.
 404      */
 405     public function get_prices_summary() {
 406 
 407         global $wp_theatre;
 408 
 409         $prices = $this->get_field( 'prices' );
 410 
 411         $prices_summary = '';
 412 
 413         if ( ! empty( $prices ) ) {
 414             if ( count( $prices ) > 1 ) {
 415                 $prices_summary .= __( 'from','theatre' ).' ';
 416             }
 417             if ( ! empty( $wp_theatre->wpt_tickets_options['currencysymbol'] ) ) {
 418                 $prices_summary .= $wp_theatre->wpt_tickets_options['currencysymbol'].' ';
 419             }
 420 
 421             $prices_summary .= number_format_i18n( (float) min( (array) $prices ), 2 );
 422         }
 423 
 424         return $prices_summary;
 425 
 426     }
 427 
 428     /**
 429      * Gets the HTML for the summary of event date prices.
 430      *
 431      * @since   0.10.14
 432      * @uses    Theater_Event_Date::get_field() to get the summary of prices for the event date.
 433      * @internal
 434      * @return  string  The HTML.
 435      */
 436     public function get_prices_summary_html() {
 437 
 438         $html = $this->get_field( 'prices_summary' );
 439         $html = esc_html( $html );
 440         $html = str_replace( ' ', '&nbsp;', $html );
 441 
 442         return $html;
 443     }
 444 
 445     /**
 446      * Gets a valid event date tickets URL.
 447      *
 448      * Only returns a tickets URL for event dates that are on sale and take
 449      * place in the future.
 450      *
 451      * @since   0.4
 452      * @since   0.10.14 Deprecated the HTML argument.
 453      *                  Use @see WPT_Event::tickets_html() instead.
 454      * @since   0.13.1  Check for upcoming event now accounts for timezones.
 455      *                  Fixes #167.
 456      *
 457      * @uses    Theater_Event_Date::get_field() to check if an event date is on sale.
 458      * @uses    Theater_Event_Date::get_field() to check if the event date takes place int he future.
 459      * @uses    Theater_Event_Date::get_field() to get the the event date tickets URL.
 460      * @internal
 461      * @return  string  The tickets URL or ''.
 462      */
 463     function get_tickets() {
 464         $tickets = '';
 465 
 466         if (
 467             self::tickets_status_onsale == $this->get_field( 'tickets_status' ) &&
 468             $this->get_field( 'startdatetime' ) > current_time( 'timestamp', true )
 469         ) {
 470             $tickets = $this->get_field( 'tickets_url' );
 471         }
 472 
 473         return $tickets;
 474     }
 475 
 476     /**
 477      * Gets the text for the event tickets link.
 478      *
 479      * @since   0.10.14
 480      * @internal
 481      * @return  string  The text for the event tickets link.
 482      */
 483     function get_tickets_button() {
 484         $tickets_button = get_post_meta( $this->ID,'tickets_button',true );
 485 
 486         if ( empty( $tickets_button ) ) {
 487             $tickets_button = __( 'Tickets', 'theatre' );
 488         }
 489 
 490         return $tickets_button;
 491     }
 492 
 493     /**
 494      * Gets the HTML for a valid event tickets link.
 495      *
 496      * @since   0.10.14
 497      * @since   0.11.10 Don't return anything for historic events with an 'on sale' status.
 498      *                  Fixes #118.
 499      * @since   0.13.1  Check for upcoming event now accounts for timezones.
 500      *                  Fixes #167.
 501      *
 502      * @uses    Theater_Item::get_post_type() to add the post type to the classes of the HTML output.
 503      * @uses    Theater_Event_Date::get_field() to check if an event date is on sale.
 504      * @uses    Theater_Event_Date::get_field() to check if the event date takes place int he future.
 505      * @uses    Theater_Event_Date::get_field_html() to get the HTML output of the tickets URL of an event date.
 506      * @uses    Theater_Event_Date::get_field_html() to get the HTML output of the tickets prices of an event date.
 507      * @uses    Theater_Event_Date::get_field_html() to get the HTML output of the tickets status of an event date when
 508      *          the event date is not on sale.
 509      * @internal
 510      * @return  string  The HTML for a valid event tickets link.
 511      */
 512     public function get_tickets_html() {
 513         $html = '';
 514 
 515         $html .= '<div class="'.$this->get_post_type().'_tickets">';
 516         if ( self::tickets_status_onsale == $this->get_field( 'tickets_status' ) ) {
 517 
 518             if ( $this->get_field( 'startdatetime' ) > current_time( 'timestamp', true ) ) {
 519                 $html .= $this->get_field_html( 'tickets_url' );
 520 
 521                 $prices_html = $this->get_field_html( 'prices' );
 522                 $prices_html = apply_filters( 'wpt_event_tickets_prices_html', $prices_html, $this );
 523                 $html .= $prices_html;
 524             }
 525         } else {
 526             $html .= $this->get_field_html( 'tickets_status' );
 527         }
 528         $html .= '</div>'; // .tickets
 529 
 530         return $html;
 531     }
 532 
 533     /**
 534      * Gets the event tickets URL.
 535      *
 536      * @since   0.8.3
 537      * @since   0.10.14 Deprecated the HTML argument.
 538      *                  Use @see WPT_Event::tickets_url_html() instead.
 539      * @since   0.12    Moved the iframe url to a new method.
 540      *                  @see WPT_Event::tickets_url_iframe().
 541      * @uses    WP_Theatre::$wpt_tickets_options to check if the tickets URL uses an iframe.
 542      * @uses    Theater_Event_Date::tickets_url_iframe() to get the URL of the iframe page for this event date.
 543      * @internal
 544      * @return  string  The event tickets URL.
 545      */
 546 
 547     function get_tickets_url() {
 548 
 549         global $wp_theatre;
 550 
 551         $tickets_url = get_post_meta( $this->ID,'tickets_url',true );
 552 
 553         if (
 554             ! empty( $wp_theatre->wpt_tickets_options['integrationtype'] ) &&
 555             'iframe' == $wp_theatre->wpt_tickets_options['integrationtype']  &&
 556             ! empty( $tickets_url ) &&
 557             $tickets_url_iframe = $this->tickets_url_iframe()
 558         ) {
 559             $tickets_url = $tickets_url_iframe;
 560         }
 561 
 562         return $tickets_url;
 563     }
 564 
 565     /**
 566      * Gets the event tickets iframe URL.
 567      *
 568      * @since   0.12
 569      * @uses    Theater_Event_Date::$wpt_tickets_options to get the ID of the iframe page.
 570      * @uses    Theater_Event_Date::get_post_type   to add the post type to the iframe page URL.
 571      * @uses    Theater_Event_Date::$ID to add the post ID to the iframe page URL.
 572      * @uses    Theater_Event_Date::get_event() to get the event of the event date.
 573      * @internal
 574      * @return  string|bool     The event tickets iframe URL or
 575      *                          <false> if no iframe page is set.
 576      */
 577     public function tickets_url_iframe() {
 578 
 579         global $wp_theatre;
 580 
 581         if ( empty( $wp_theatre->wpt_tickets_options['iframepage'] ) ) {
 582             return false;
 583         }
 584 
 585         $tickets_iframe_page = get_post( $wp_theatre->wpt_tickets_options['iframepage'] );
 586 
 587         if ( is_null( $tickets_iframe_page ) ) {
 588             return false;
 589         }
 590 
 591         $tickets_url_iframe = get_permalink( $tickets_iframe_page );
 592         if ( get_option( 'permalink_structure' ) && $event = $this->get_event() ) {
 593             $tickets_url_iframe = trailingslashit( $tickets_url_iframe ).$this->get_post_type().'/'.$this->ID;
 594         } else {
 595             $tickets_url_iframe = add_query_arg( 'wpt_event_tickets', $this->ID, $tickets_url_iframe );
 596         }
 597 
 598         /**
 599          * Filter the event tickets iframe URL.
 600          *
 601          * @since   0.12
 602          * @param   string      $tickets_url_iframe     The event tickets iframe URL.
 603          * @param   WPT_Event   $this                   The event object.
 604          */
 605         $tickets_url_iframe = apply_filters( 'wpt/event/tickets/url/iframe', $tickets_url_iframe, $this );
 606 
 607         return $tickets_url_iframe;
 608 
 609     }
 610 
 611     /**
 612      * Get the HTML for the event date tickets URL.
 613      *
 614      * @since 0.10.14
 615      * @uses    Theater_Event_Date::get_field() to get the the event date tickets URL.
 616      * @uses    WP_Theatre::$wpt_tickets_options to check if the tickets URL uses an iframe.
 617      * @uses    Theater_Item::get_post_type() to add the post type to the classes of the HTML output.
 618      * @uses    Theater_Event_Date::get_field() to get the text inside the event date tickets URL.
 619      * @internal
 620      * @return string   The HTML for the event date tickets URL.
 621      */
 622     public function get_tickets_url_html() {
 623         global $wp_theatre;
 624 
 625         $html = '';
 626 
 627         $tickets_url = $this->get_field( 'tickets_url' );
 628 
 629         if ( ! empty( $tickets_url ) ) {
 630 
 631             $html .= '<a href="'.$tickets_url.'" rel="nofollow"';
 632 
 633             /**
 634              * Add classes to tickets link.
 635              */
 636 
 637             $classes = array();
 638             $classes[] = $this->get_post_type().'_tickets_url';
 639             if ( ! empty( $wp_theatre->wpt_tickets_options['integrationtype'] ) ) {
 640                 $classes[] = 'wp_theatre_integrationtype_'.$wp_theatre->wpt_tickets_options['integrationtype'];
 641             }
 642 
 643             /**
 644              * Filter the CSS classes of the HTML for the event tickets URL.
 645              *
 646              * @since   0.10.14
 647              * @param   array       $classes    The current CSS classes.
 648              * @param   WPT_Event   $event      The event.
 649              */
 650             $classes = apply_filters( 'wpt/event/tickets/url/classes',$classes,$this );
 651 
 652             /**
 653              * @deprecated  0.10.14
 654              */
 655             $classes = apply_filters( 'wpt_event_tickets__url_classes',$classes,$this );
 656 
 657             $html .= ' class="'.implode( ' ' ,$classes ).'"';
 658 
 659             $html .= '>';
 660             $html .= $this->get_field( 'tickets_button' );
 661             $html .= '</a>';
 662 
 663         }
 664 
 665         return $html;
 666     }
 667 
 668     /**
 669      * Gets the HTML for an event date.
 670      *
 671      * @since   0.4
 672      * @since   0.10.8  Added a filter to the default template.
 673      * @since   0.14.7  Added the $args parameter.
 674      * @since   0.15.2  Removed the $args parameter.
 675      *
 676      * @uses    Theater_Item::get_post_type() to get the post type for an event date.
 677      * @uses    WPT_Event_Template::get_merged() to get the merged HTML for an event date.
 678      * @return  string  The HTML for an event date.
 679      */
 680     function get_html() {
 681 
 682         $classes = array();
 683         $classes[] = $this->get_post_type();
 684 
 685         $template = new WPT_Event_Template( $this, $this->template );
 686         $html = $template->get_merged();
 687 
 688         /**
 689          * Filter the HTML output for an event.
 690          *
 691          * @since   0.14.7
 692          * @param   string              $html       The HTML output for an event.
 693          * @param   WPT_Event_Template  $template   The event template.
 694          * @param   array               $args       The listing args (if the event is part of a listing).
 695          * @param   WPT_Event           $event      The event.
 696          */
 697         $html = apply_filters( 'wpt/event/html',$html, $template, $this );
 698 
 699         /**
 700          * @deprecated  0.14.7
 701          */
 702         $html = apply_filters( 'wpt_event_html',$html, $this );
 703 
 704         /**
 705          * Filter the classes for an event.
 706          *
 707          * @since   0.?
 708          * @param   array       $classes    The classes for an event.
 709          * @param   WPT_Event   $event      The event.
 710          */
 711         $classes = apply_filters( 'wpt_event_classes',$classes, $this );
 712 
 713         // Wrapper
 714         $html = '<div class="'.implode( ' ',$classes ).'">'.$html.'</div>';
 715 
 716         return $html;
 717     }
 718 
 719     /**
 720      * Gets the location of an event date.
 721      *
 722      * The location is a combination of the event date venue and city.
 723      *
 724      * @since   0.x
 725      * @uses    Theater_Event_Date::get_field() to get the venue of an event date.
 726      * @uses    Theater_Event_Date::get_field() to get the city of an event date.
 727      * @internal
 728      * @return  string The location of an event date.
 729      */
 730     function get_location() {
 731 
 732         $location_parts = array();
 733 
 734         $venue = $this->get_field( 'venue' );
 735         $city = $this->get_field( 'city' );
 736 
 737         if ( ! empty( $venue ) ) {
 738             $location_parts[] = $venue;
 739         }
 740 
 741         if ( ! empty( $city ) ) {
 742             $location_parts[] = $city;
 743         }
 744 
 745         $value = implode( ' ', $location_parts );
 746         return $value;
 747 
 748     }
 749 
 750     /**
 751      * Gets the HTML for a location of an event date.
 752      *
 753      * The location is a combination of the event date venue and city.
 754      *
 755      * @since   0.16
 756      * @uses    Theater_Event_Date::get_field_html() to get the HTML for a venue of an event date.
 757      * @uses    Theater_Event_Date::get_field_html() to get the HTML for a city of an event date.
 758      * @param   WPT_Template_Placeholder_Filter[]   $filters    An array of filters to apply to the value if the field.
 759      * @internal
 760      * @return  string The location of an event date.
 761      */
 762     function get_location_html( $filters = array() ) {
 763 
 764         ob_start();
 765         ?><div class="<?php echo Theater_Event_Date::post_type_name; ?>_location"><?php
 766             echo $this->get_field_html( 'venue', $filters );
 767             echo $this->get_field_html( 'city', $filters );
 768         ?></div><?php
 769         $html = ob_get_clean();
 770 
 771         return $html;
 772     }
 773 
 774     /**
 775      * Gets the tickets status of an event date.
 776      *
 777      * @since   0.x
 778      * @internal
 779      * @return  string
 780      */
 781     function get_tickets_status() {
 782 
 783         $value = get_post_meta( $this->ID,'tickets_status',true );
 784 
 785         if ( empty( $value ) ) {
 786             $value = self::tickets_status_onsale;
 787         }
 788 
 789         return $value;
 790 
 791     }
 792 
 793     /**
 794      * Get the HTML for the tickets status of an event date.
 795      *
 796      * @since   0.x
 797      * @uses    Theater_Event_Date::get_field() to get the tickets status of an event.
 798      * @uses    Theater_Item::get_post_type() to add the post type to the classes of the HTML output.
 799      * @internal
 800      * @return  string  The HTML for the tickets status of an event date.
 801      */
 802     function get_tickets_status_html() {
 803         $tickets_status = $this->get_field( 'tickets_status' );
 804 
 805         switch ( $tickets_status ) {
 806             case self::tickets_status_onsale :
 807                 $label = __( 'On sale','theatre' );
 808                 break;
 809             case self::tickets_status_soldout :
 810                 $label = __( 'Sold out','theatre' );
 811                 break;
 812             case self::tickets_status_cancelled :
 813                 $label = __( 'Cancelled','theatre' );
 814                 break;
 815             case self::tickets_status_hidden :
 816                 $label = '';
 817                 break;
 818             default :
 819                 $label = $tickets_status;
 820                 $tickets_status = self::tickets_status_other;
 821         }
 822 
 823         $html = '';
 824 
 825         if ( ! empty( $label ) ) {
 826             $html .= '<span class="'.$this->get_post_type().'_tickets_status '.$this->get_post_type().'_tickets_status'.$tickets_status.'">'.$label.'</span>';
 827         }
 828 
 829         return $html;
 830     }
 831 
 832     /**
 833      * Gets the end timestamp of an event date.
 834      *
 835      * @since   0.16
 836      * @internal
 837      * @return  int The end timestamp of an event date.
 838      */
 839     function get_enddatetime() {
 840         $enddate = get_post_meta( $this->ID, 'enddate', true );
 841 
 842         if ( empty( $enddate ) ) {
 843             return false;
 844         }
 845 
 846         $value = date_i18n( 'U', strtotime( $enddate, current_time( 'timestamp' ) ) - get_option( 'gmt_offset' ) * 3600 );
 847 
 848         return $value;
 849     }
 850 
 851     /**
 852      * Gets the HTML for the end date and time of an event date.
 853      *
 854      * @since   0.16
 855      * @param   WPT_Template_Placeholder_Filter[]   $filters    An array of filters to apply to the value if the field.
 856      * @internal
 857      * @return  string  The HTML for the end date and time of an event date.
 858      */
 859     function get_enddatetime_html( $filters = array() ) {
 860 
 861         ob_start();
 862         ?><div class="<?php echo Theater_Event_Date::post_type_name; ?>_datetime <?php echo Theater_Event_Date::post_type_name; ?>_startdatetime"><?php
 863 
 864             $value = $this->enddate.$this->endtime;
 865 foreach ( $filters as $filter ) {
 866     if ( 'date' == $filter->name ) {
 867         $value = $filter->apply_to( $this->enddatetime(), $this );
 868     } else {
 869         $value = $filter->apply_to( $value, $this );
 870     }
 871 }
 872             echo $value;
 873 
 874         ?></div><?php
 875 
 876         $html = ob_get_clean();
 877 
 878         return $html;
 879     }
 880 
 881     /**
 882      * Gets the event date startdate.
 883      *
 884      * @since   0.12
 885      * @uses    Theater_Event_Date::get_field() to get the start timestamp of an event date.
 886      * @internal
 887      * @return  string The event date startdate.
 888      */
 889     function get_startdate() {
 890         $startdate = date_i18n(
 891             get_option( 'date_format' ),
 892             $this->get_field( 'startdatetime' ) + get_option( 'gmt_offset' ) * 3600
 893         );
 894 
 895         return $startdate;
 896     }
 897 
 898     /**
 899      * Gets the HTML for the event date startdate.
 900      *
 901      * @since   0.12
 902      * @since   0.15.1  Fix: No longer compensates for the timezone when applying the 'date'-filter.
 903      *                  This is already handled by WPT_Template_Placeholder_Filter::callback_date() and
 904      *                  resulted in double compensations.
 905      * @uses    Theater_Item::get_post_type() to add the post type to the classes of the HTML output.
 906      * @uses    Theater_Event_Date::get_field() to get the start date of an event date.
 907      * @uses    Theater_Event_Date::get_field() to get the raw start time of an event date for use with the 'date' filter.
 908      * @uses    WPT_Template_Placeholder_Filter::apply_to() to apply filters to the field value.
 909      * @param   WPT_Template_Placeholder_Filter[]   $filters    An array of filters to apply to the value if the field.
 910      * @internal
 911      * @return  string              The HTML for the event date startdate.
 912      */
 913     function get_startdate_html( $filters = array() ) {
 914 
 915         ob_start();
 916         ?><div class="<?php echo $this->get_post_type();?>_date <?php echo $this->get_post_type(); ?>_startdate"><?php
 917 
 918         $value = $this->get_field( 'startdate' );
 919 
 920 foreach ( $filters as $filter ) {
 921     if ( 'date' == $filter->name ) {
 922         $value = $filter->apply_to( $this->get_field( 'startdatetime' ), $this );
 923     } else {
 924         $value = $filter->apply_to( $value, $this );
 925     }
 926 }
 927 
 928         echo $value;
 929 
 930         ?></div><?php
 931 
 932         $html = ob_get_clean();
 933 
 934         return $html;
 935     }
 936 
 937     /**
 938      * Gets the start timestamp of an event date.
 939      *
 940      * @since   0.16
 941      * @internal
 942      * @return  int|bool    The start timestamp of an event date.
 943      *                      Returns <false> if not startdate is set.
 944      */
 945     function get_startdatetime() {
 946         $startdate = get_post_meta( $this->ID, 'event_date', true );
 947 
 948         if ( empty( $startdate ) ) {
 949             return false;
 950         }
 951 
 952         $value = date_i18n( 'U', strtotime( $startdate, current_time( 'timestamp' ) ) - get_option( 'gmt_offset' ) * 3600 );
 953 
 954         return $value;
 955     }
 956 
 957     /**
 958      * Gets the HTMl for the start date and time of an event date.
 959      *
 960      * @since   0.16
 961      * @param   WPT_Template_Placeholder_Filter[]   $filters    An array of filters to apply to the value if the field.
 962      * @uses    Theater_Item::get_post_type() to add the post type to the classes of the HTML output.
 963      * @uses    Theater_Event_Date::get_field_html() to get the HTML for the start date of an event date.
 964      * @uses    Theater_Event_Date::get_field_html() to get the HTML for the start time of an event date.
 965      * @uses    Theater_Event_Date::get_field() to get the raw start time of an event date for use with the 'date' filter.
 966      * @internal
 967      * @return  string  Tthe HTMl for the start date and time of an event date.
 968      */
 969     function get_startdatetime_html( $filters = array() ) {
 970 
 971         ob_start();
 972         ?><div class="<?php echo $this->get_post_type(); ?>_datetime <?php echo $this->get_post_type(); ?>_startdatetime"><?php
 973 
 974             $value = $this->get_field_html( 'startdate' ).$this->get_field_html( 'starttime' );
 975 foreach ( $filters as $filter ) {
 976     if ( 'date' == $filter->name ) {
 977         $value = $filter->apply_to( $this->get_field( 'startdatetime' ), $this );
 978     } else {
 979         $value = $filter->apply_to( $value, $this );
 980     }
 981 }
 982             echo $value;
 983 
 984         ?></div><?php
 985 
 986         $html = ob_get_clean();
 987 
 988         return $html;
 989     }
 990 
 991 
 992     /**
 993      * Gets the event date starttime.
 994      *
 995      * @since   0.12
 996      * @uses    Theater_Event_Date::get_field() to get the start timestamp of an event date.
 997      * @internal
 998      * @return  string The event date starttime.
 999      */
1000     function get_starttime() {
1001         $starttime = date_i18n(
1002             get_option( 'time_format' ),
1003             $this->get_field( 'startdatetime' ) + get_option( 'gmt_offset' ) * 3600
1004         );
1005 
1006         return $starttime;
1007     }
1008 
1009     /**
1010      * Gets the HTML for the event starttime.
1011      *
1012      * @since   0.12
1013      * @param   array   $filters    The template filters to apply.
1014      * @uses    Theater_Item::get_post_type() to add the post type to the classes of the HTML output.
1015      * @uses    Theater_Event_Date::get_field() to get the start time of an event date.
1016      * @uses    Theater_Event_Date::get_field() to get the raw start time of an event date for use with the 'date' filter.
1017      * @uses    WPT_Template_Placeholder_Filter::apply_to() to apply filters to the field value.
1018      * @internal
1019      * @return  string              The HTML for the event starttime.
1020      */
1021     function get_starttime_html( $filters = array() ) {
1022 
1023         ob_start();
1024         ?><div class="<?php echo $this->get_post_type();?>_time <?php echo $this->get_post_type(); ?>_starttime"><?php
1025 
1026         $value = $this->starttime();
1027 
1028 foreach ( $filters as $filter ) {
1029     if ( 'date' == $filter->name ) {
1030         $value = $filter->apply_to( $this->startdatetime(), $this );
1031     } else {
1032         $value = $filter->apply_to( $value, $this );
1033     }
1034 }
1035 
1036         echo $value;
1037 
1038         ?></div><?php
1039 
1040         $html = ob_get_clean();
1041 
1042         return $html;
1043     }
1044 
1045     /**
1046      * @deprecated 0.4
1047      * @internal
1048      */
1049     function get_production() {
1050         _deprecated_function( 'Theater_Event_Date::get_production()', '0.4', 'Theater_Event_Dates::get_event()' );
1051         return $this->get_event();
1052     }
1053 
1054     /**
1055      * @deprecated 0.16
1056      * @internal
1057      */
1058     function production() {
1059         //_deprecated_function( 'Theater_Event_Date::production()', '0.16', 'Theater_Event_Dates::get_event()' );
1060         return $this->event();
1061     }
1062 
1063     /**
1064      * @deprecated 0.4 Use $event->prices() instead.
1065      * @internal
1066      */
1067     function summary() {
1068         global $wp_theatre;
1069         if ( ! isset( $this->summary ) ) {
1070             $args = array(
1071             'summary' => true,
1072             );
1073             $this->summary = array(
1074             'prices' => $this->prices( $args ),
1075             );
1076         }
1077         return $this->summary;
1078     }
1079 
1080     /**
1081      * @deprecated  0.16
1082      * @internal
1083      */
1084     function datetime( $enddate = false ) {
1085 
1086         if ( true === $enddate ) {
1087             $value = $this->enddatetime();
1088         } else {
1089             $value = $this->startdatetime( $enddate );
1090         }
1091 
1092         /**
1093          * Filter the event datetime.
1094          *
1095          * @since   0.12.7
1096          * @param   datetime    $datetime   The event timestamp.
1097          * @param   WPT_Event   $event      The event.
1098          */
1099         $value = apply_filters( 'wpt/event/datetime', $value, $this );
1100         $value = apply_filters( 'wpt_event_datetime', $value, $this );
1101 
1102         return $value;
1103     }
1104 
1105     /**
1106      * @deprecated  0.16
1107      * @internal
1108      */
1109     function datetime_html( $filters = array() ) {
1110         $html = $this->get_field_html( 'startdatetime', $filters );
1111 
1112         /**
1113          * Filter the HTML for the event timestamp.
1114          *
1115          * @since   0.12.7
1116          * @param   string      $html       The HTML for the event timestamp.
1117          * @param   array       $filters    The template filters to apply.
1118          * @param   WPT_Event   $event      The event.
1119          */
1120         $html = apply_filters( 'wpt/event/datetime/html', $html, $filters, $this );
1121 
1122         return $html;
1123     }
1124 }
1125 
1126 ?>
1127 
Theater for WordPress Code Reference API documentation generated by ApiGen