Guest User

Untitled

a guest
May 15th, 2013
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. <?php
  2. /**
  3. * This file outputs the actual days of the month in the TEC calendar view
  4. *
  5. * You can customize this view by putting a replacement file of the same name (table.php) in the events/ directory of your theme.
  6. */
  7.  
  8. // Don't load directly
  9. if ( !defined('ABSPATH') ) { die('-1'); }
  10.  
  11. $tribe_ecp = TribeEvents::instance();
  12.  
  13. // in an events cat
  14. if ( is_tax( $tribe_ecp->get_event_taxonomy() ) ) {
  15. $cat = get_term_by( 'slug', get_query_var('term'), $tribe_ecp->get_event_taxonomy() );
  16. $eventCat = (int) $cat->term_id;
  17. $eventPosts = tribe_get_events( array( 'eventCat' => $eventCat, 'time_order' => 'ASC', 'eventDisplay'=>'month' ) );
  18. } // not in a cat
  19. else {
  20. $eventPosts = tribe_get_events(array( 'eventDisplay'=>'month' ));
  21. }
  22.  
  23.  
  24. $daysInMonth = isset($date) ? date("t", $date) : date("t");
  25. $startOfWeek = get_option( 'start_of_week', 0 );
  26. list( $year, $month ) = split( '-', $tribe_ecp->date );
  27. $date = mktime(12, 0, 0, $month, 1, $year); // 1st day of month as unix stamp
  28. $rawOffset = date("w", $date) - $startOfWeek;
  29. $offset = ( $rawOffset < 0 ) ? $rawOffset + 7 : $rawOffset; // month begins on day x
  30. $rows = 1;
  31.  
  32. $monthView = tribe_sort_by_month( $eventPosts, $tribe_ecp->date );
  33.  
  34. ?>
  35. <table class="tribe-events-calendar" id="big">
  36. <thead>
  37. <tr>
  38. <?php
  39. for( $n = $startOfWeek; $n < count($tribe_ecp->daysOfWeek) + $startOfWeek; $n++ ) {
  40. $dayOfWeek = ( $n >= 7 ) ? $n - 7 : $n;
  41.  
  42. echo '<th id="tribe-events-' . strtolower($tribe_ecp->daysOfWeek[$dayOfWeek]) . '" abbr="' . $tribe_ecp->daysOfWeek[$dayOfWeek] . '">' . $tribe_ecp->daysOfWeekShort[$dayOfWeek] . '</th>';
  43. }
  44. ?>
  45. </tr>
  46. </thead>
  47.  
  48. <tbody>
  49. <tr>
  50. <?php
  51. // skip last month
  52. for( $i = 1; $i <= $offset; $i++ ){
  53. echo "<td class='tribe-events-othermonth'></td>";
  54. }
  55. // output this month
  56. $days_in_month = date("t", intval($date));
  57. for( $day = 1; $day <= $days_in_month; $day++ ) {
  58. if( ($day + $offset - 1) % 7 == 0 && $day != 1) {
  59. echo "</tr>\n\t<tr>";
  60. $rows++;
  61. }
  62.  
  63. // Var'ng up days, months and years
  64. $current_day = date_i18n( 'd' );
  65. $current_month = date_i18n( 'm' );
  66. $current_year = date_i18n( 'Y' );
  67. $date = "$year-$month-$day";
  68.  
  69. if ( $current_month == $month && $current_year == $year) {
  70. // Past, Present, Future class
  71. if ($current_day == $day ) {
  72. $ppf = ' tribe-events-present';
  73. } elseif ($current_day > $day) {
  74. $ppf = ' tribe-events-past';
  75. } elseif ($current_day < $day) {
  76. $ppf = ' tribe-events-future';
  77. }
  78. } elseif ( $current_month > $month && $current_year == $year || $current_year > $year ) {
  79. $ppf = ' tribe-events-past';
  80. } elseif ( $current_month < $month && $current_year == $year || $current_year < $year ) {
  81. $ppf = ' tribe-events-future';
  82. } else { $ppf = false; }
  83.  
  84. echo "<td class='tribe-events-thismonth" . $ppf . "'>" . display_day_title( $day, $monthView, $date ) . "\n";
  85. echo display_day( $day, $monthView );
  86. echo "</td>";
  87. }
  88. // skip next month
  89. while( ($day + $offset) <= $rows * 7)
  90. {
  91. echo "<td class='tribe-events-othermonth'></td>";
  92. $day++;
  93. }
  94. ?>
  95. </tr>
  96. </tbody>
  97. </table>
  98. <?php
  99.  
  100. function display_day_title( $day, $monthView, $date ) {
  101. $return = "<div class='daynum tribe-events-event' id='daynum_$day'>";
  102. if( function_exists('tribe_get_linked_day') && count( $monthView[$day] ) > 0 ) {
  103. $return .= tribe_get_linked_day($date, $day); // premium
  104. } else {
  105. $return .= $day;
  106. }
  107. $return .= "<div id='tooltip_day_$day' class='tribe-events-tooltip' style='display:none;'>";
  108. for( $i = 0; $i < count( $monthView[$day] ); $i++ ) {
  109. $post = $monthView[$day][$i];
  110. setup_postdata( $post );
  111. $return .= '<h5 class="tribe-events-event-title">' . get_the_title() . '</h5>';
  112. }
  113. $return .= '<span class="tribe-events-arrow"></span>';
  114. $return .= '</div>';
  115.  
  116. $return .= "</div>";
  117. return $return;
  118. }
  119.  
  120. function display_day( $day, $monthView ) {
  121. global $post;
  122. $output = '';
  123. $posts_per_page = tribe_get_option( 'postsPerPage', 10 );
  124. for ( $i = 0; $i < count( $monthView[$day] ); $i++ ) {
  125. $post = $monthView[$day][$i];
  126. setup_postdata( $post );
  127. $eventId = $post->ID.'-'.$day;
  128. $start = tribe_get_start_date( $post->ID, false, 'U' );
  129. $end = tribe_get_end_date( $post->ID, false, 'U' );
  130. $cost = tribe_get_cost( $post->ID );
  131. ?>
  132. <div id='event_<?php echo $eventId; ?>' <?php post_class('tribe-events-event tribe-events-real-event') ?>>
  133. <?php the_post_thumbnail( thumbnail, $attr ); ?>
  134. <center><?php if( class_exists( 'TribeEventsPro' ) ): ?>
  135. <?php tribe_get_venue_link( $post->ID, class_exists( 'TribeEventsPro' ) ); ?>
  136. <?php else: ?>
  137. <?php echo tribe_get_venue( $post->ID ); ?>
  138. <?php endif; ?><br><a href="<?php tribe_event_link(); ?>"><?php the_title(); ?></a><br>
  139. <div class="button-wrap "><div class="red button "><a href="<?php tribe_event_link(); ?>" alt="Purchase tickets for <?php the_title(); ?>">Purchase Ticket</a></div></div></center>
  140. <?php
  141. /**
  142. * Returns an array of all WooTicket products associated with the event.
  143. *
  144. * @param null $post_id
  145. * @return array
  146. */
  147. function get_wooticket_products($post_id = null) {
  148. global $wpdb;
  149. $id = TribeEvents::postIdHelper($post_id);
  150. $products = array();
  151.  
  152. $product_ids = $wpdb->get_col($wpdb->prepare(
  153. "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d",
  154. '_tribe_wooticket_for_event', $id
  155. ));
  156.  
  157. if ($product_ids) foreach ($product_ids as $id)
  158. $products[] = new WC_Product_Simple($id);
  159.  
  160. return $products;
  161. } ?>
  162. <div id='tooltip_<?php echo $eventId; ?>' class="tribe-events-tooltip" style="display:none;">
  163. <div class="tribe-events-event-title"><?php the_title();?></div>
  164. <div class="tribe-events-event-subtitle">Venue: <?php if( class_exists( 'TribeEventsPro' ) ): ?>
  165. <?php tribe_get_venue_link( $post->ID, class_exists( 'TribeEventsPro' ) ); ?>
  166. <?php else: ?>
  167. <?php echo tribe_get_venue( $post->ID ); ?>
  168. <?php endif; ?></div>
  169. <div class="tribe-events-event-body">
  170. <div class="tribe-events-event-date">
  171. <?php if ( !empty( $start ) ) echo date_i18n( get_option('date_format', 'F j, Y'), $start);
  172. if ( !tribe_get_event_meta($post->ID, '_EventAllDay', true) )
  173. echo ' ' . date_i18n( get_option('time_format', 'g:i a'), $start); ?>
  174. <?php if ( !empty( $end ) && $start !== $end ) {
  175. if ( date_i18n( 'Y-m-d', $start ) == date_i18n( 'Y-m-d', $end ) ) {
  176. $time_format = get_option( 'time_format', 'g:i a' );
  177. if ( !tribe_get_event_meta($post->ID, '_EventAllDay', true) )
  178. echo " – " . date_i18n( $time_format, $end );
  179. } else {
  180. echo " – " . date_i18n( get_option('date_format', 'F j, Y'), $end);
  181. if ( !tribe_get_event_meta($post->ID, '_EventAllDay', true) )
  182. echo ' ' . date_i18n( get_option('time_format', 'g:i a'), $end) . '<br />';
  183. }
  184. } ?>
  185. </div>
  186. <a href="<?php tribe_event_link(); ?>" alt="View more info on <?php the_title(); ?>" style="text-decoration: none">
  187. <?php if ( function_exists('has_post_thumbnail') && has_post_thumbnail() ) { ?>
  188. <div class="tribe-events-event-thumb"><?php the_post_thumbnail( array(75,75));?></div>
  189. <?php } ?>
  190. <?php echo has_excerpt() ? TribeEvents::truncate($post->post_excerpt) : TribeEvents::truncate(get_the_content(), 30); ?>
  191. </a>
  192. </div>
  193.  
  194. <span class="tribe-events-arrow"></span>
  195. </div>
  196. </div>
  197. <?php
  198. if( $i < count( $monthView[$day] ) - 1 ) {
  199. echo "<hr />";
  200. }
  201. }
  202. }
  203. ?>
Advertisement
Add Comment
Please, Sign In to add comment