<?php
/**
 * The Template for displaying all single posts.
 *
 * @package sparkling
 */

get_header(); ?>

	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">
		

		<?php while ( have_posts() ) : the_post(); ?>

		
		
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
	<?php the_post_thumbnail( 'sparkling-featured', array( 'class' => 'single-featured' )); ?>
	<div class="post-inner-content">
		<header class="entry-header page-header">

			<h1 class="entry-title "><?php the_title(); ?></h1>

			<div class="entry-meta">
				<span class="fa fa-calendar"></span> 
				<a href="<?php echo site_url('/shows/on/');  eo_the_start('Y/m/d/');?>"><?php eo_the_start('M j, Y');?></a>
				
				<span class="byline">
					<i class="fa fa-user"></i>
					<?php 
					// set third value to true, to prevent getting an array returned.
					$rating = get_post_meta(get_the_ID(), 'rating', true);
					if($rating){
						// if(is_array($rating)){$rating = $rating[0];}
						printf('Rated %s', $rating);
					}
					echo ' &nbsp;';
					$minors =  get_post_meta(get_the_ID(), 'minors', true);// note, this has not been automated yet.
					if($minors){
						
						printf('%s', $minors);
					}
					?>
					
				</span>

				<?php
					// this differs from the parent theme.
					$categories = get_the_terms($post->ID, 'event-category');
	
					if($categories && !is_wp_error($categories)){
	
						// _e('<p class="category-list">Filed under ', 'sparkling');
						
						
					// $categories_list = get_the_category_list( __( ', ', 'sparkling' ) );
					// if ( $categories_list && sparkling_categorized_blog() ) :
				?>
				<span class="cat-links"><i class="fa fa-folder-open-o"></i>
					<?php 
					
					$arr = array();
					
					foreach($categories as $obj){
						$arr[] = $obj->name;
					}
					
					//var_dump($categories);
					
					
					 $categories = implode(', ', $arr);
					
					printf('%s', $categories);
					
					// printf( __( ' %1$s', 'sparkling' ), $categories ); 
					
					?>
				</span>
				<?php } // End if categories ?>
				<?php edit_post_link( __( 'Edit', 'sparkling' ), '<i class="fa fa-pencil-square-o"></i><span class="edit-link">', '</span>' ); ?>

			</div><!-- .entry-meta -->
		</header><!-- .entry-header -->

		<div class="entry-content">
			<?php the_content(); ?>
			<?php
				wp_link_pages( array(
					'before'            => '<div class="page-links">'.__( 'Pages:', 'sparkling' ),
					'after'             => '</div>',
					'link_before'       => '<span>',
					'link_after'        => '</span>',
					'pagelink'          => '%',
					'echo'              => 1
	       		) );
	    	?>
		</div><!-- .entry-content -->

		<footer class="entry-meta">

	    	<?php if(has_tag()) : ?>
	      <!-- tags -->
	      <div class="tagcloud">

	          <?php
	              $tags = get_the_tags(get_the_ID());
	              foreach($tags as $tag){
	                  echo '<a href="'.get_tag_link($tag->term_id).'">'.$tag->name.'</a> ';
	              } ?>

	      </div>
	      <!-- end tags -->
	      <?php endif; ?>

		</footer><!-- .entry-meta -->
	</div>
				<div class="post-inner-content secondary-content-box">

				<p>Showtime: <?php eo_the_start('g:iA \o\n M j, Y');?></p>
				
				<?php 
				
				$screen = get_post_meta(get_the_ID(), 'screen', true);
				if($screen){
					printf('<p>Screen number: %s</p>', $screen);
				}
				
				
				$buy_link = get_post_meta(get_the_ID(), 'buy_link', true);
				
				if(!$buy_link){
					
					$rts_id = get_post_meta(get_the_ID(), 'rts_id', true);
					if($rts_id){
						$buy_link = 'http://66511.formovietickets.com:2235/Tickets.ASP?WCI=buyticket&amp;Page=PickTickets&amp;SHOWID=' . $rts_id;					
					}
				}
				
				if($buy_link){
					printf('<a href="%s" title="Buy Tickets" class="buy btn buy-tickets">Buy Tickets</a>', $buy_link);			
				}

				?>
				
			</div>
</article><!-- #post-## -->

		
			
			<?php 
			/*
				if(function_exists('eo_get_events')){
					
				}
			*/	
			
			// $data = get_metadata('post', get_the_ID(), true);
			?>

			<?php
				// If comments are open or we have at least one comment, load up the comment template
				
				// Fuck comments.
				/*
				if ( comments_open() || '0' != get_comments_number() ) :
					comments_template();
				endif;
				*/
			?>

			<?php sparkling_post_nav(); ?>

		<?php endwhile; // end of the loop. ?>

		</main><!-- #main -->
	</div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>