*/ class TICA_Events_Public { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of the plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; } /** * Register the stylesheets for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_styles() { wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/tica-events-public.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_scripts() { wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/tica-events-public.js', array( 'jquery' ), $this->version, false ); } public function the_content( $content ) { global $post; if ( is_single() && TICA_Events::POST_TYPE == $post->post_type && $page = $this->get_page() ) { $back_link = ''; $events_back_url = get_permalink( $page ); $referrer = wp_get_referer(); if ( 0 === strpos( $referrer, $events_back_url ) ) { $events_back_url = $referrer; } if ( $events_back_url ) { $back_link = ''; } $content = $back_link . $content; } return $content; } protected function get_page() { $query = new WP_Query( [ 'post_type' => ['page', 'post'], 'meta_key' => '_wp_page_template', 'meta_value' => 'template-events.php', ] ); return ( $query->have_posts() ) ? reset( $query->posts ) : false; } public function get_the_time( $time, $format, $post ) { if ( TICA_Events::POST_TYPE == $post->post_type ) { $date = get_post_meta( $post->ID, TICA_Events::POST_TYPE . '_from_date', true ); if ( $date ) { $time = mysql2date( $format, $date ); } } return $time; } protected function getEventLocation( $post ) { $type = TICA_Events::POST_TYPE; if ( $type != $post->post_type ) { return ''; } $where = ''; $meta = get_post_meta( $post->ID ); $fields = [ [ 'location_name', 'location_city' ], [ 'location_address', 'location_state', 'location_zip', 'location_country' ] ]; foreach ( $fields as $_fields ) { foreach ( $_fields as $field ) { $value = ( ! empty( $meta["{$type}_{$field}"][0] ) ) ? $meta["{$type}_{$field}"][0] : ''; if ( $value ) { $where .= esc_html( "{$value}, " ); } } $where = trim($where, ", \t\n\r\0\x0B") . '
'; } return $where; } public static function getEventDate( $post, $with_time = true ) { $type = TICA_Events::POST_TYPE; if ( $type != $post->post_type ) { return ''; } $meta = get_post_meta( $post->ID ); $from_date = ( ! empty( $meta["{$type}_from_date"][0] ) ) ? $meta["{$type}_from_date"][0] : ''; $to_date = ( ! empty( $meta["{$type}_to_date"][0] ) ) ? $meta["{$type}_to_date"][0] : ''; $from_time = ( ! empty( $meta["{$type}_from_time"][0] ) ) ? $meta["{$type}_from_time"][0] : ''; $to_time = ( ! empty( $meta["{$type}_to_time"][0] ) ) ? $meta["{$type}_to_time"][0] : ''; if ( ! $from_date || ! $to_date || ! $from_time || ! $to_time ) { return ''; } $when = ''; if ( $from_date == $to_date ) { $when .= date( 'l, F j, Y', strtotime( $from_date ) ); } else { list( $fy, $fm, $fd ) = explode( '-', $from_date ); list( $ty, $tm, $td ) = explode( '-', $to_date ); if ( $fy != $ty) { $when .= date( 'l, F j, Y', strtotime( $from_date ) ); $when .= ' - '; $when .= date( 'l, F j, Y', strtotime( $to_date ) ); } elseif ( $fm != $tm ) { $when .= date( 'l, F j', strtotime( $from_date ) ); $when .= ' - '; $when .= date( 'l, F j', strtotime( $to_date ) ); $when .= ' '; $when .= date( 'Y', strtotime( $to_date ) ); } elseif ($fd != $td) { $when .= date( 'l, F', strtotime( $to_date ) ); $when .= ' '; $when .= date( 'j', strtotime( $from_date ) ); $when .= ' - '; $when .= date( 'j', strtotime( $to_date ) ); $when .= ', '; $when .= date( 'Y', strtotime( $to_date ) ); } } if ( $with_time ) { $when .= PHP_EOL . date( 'g:i a', strtotime( $from_time ) ); $when .= ' - ' . date( 'g:i a', strtotime( $to_time ) ); } return $when; } public function after_title( ) { global $post; $type = TICA_Events::POST_TYPE; if ( $type != $post->post_type ) { return; } $when = self::getEventDate( $post ); if ( $when ) { echo '

' . nl2br( esc_html( $when ) ) . '

'; } $where = $this->getEventLocation( $post ); if ( $where ) { echo '

' . nl2br( $where ) . '

'; } } }