BakerMan

Events Table Tpl (2.0.9)

Oct 18th, 2012
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.13 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.             <a href="<?php tribe_event_link(); ?>"><?php the_title(); ?></a>
  134.             <div id='tooltip_<?php echo $eventId; ?>' class="tribe-events-tooltip" style="display:none;">
  135.                 <h5 class="tribe-events-event-title"><?php the_title();?></h5>
  136.                 <div class="tribe-events-event-body">
  137.                     <div class="tribe-events-event-date">
  138.                         <?php if ( !empty( $start ) )   echo date_i18n( get_option('date_format', 'F j, Y'), $start);
  139.                         if ( !tribe_get_event_meta($post->ID, '_EventAllDay', true) )
  140.                             echo ' ' . date_i18n( get_option('time_format', 'g:i a'), $start); ?>
  141.                         <?php if ( !empty( $end )  && $start !== $end ) {
  142.                             if ( date_i18n( 'Y-m-d', $start ) == date_i18n( 'Y-m-d', $end ) ) {
  143.                                 $time_format = get_option( 'time_format', 'g:i a' );
  144.                                 if ( !tribe_get_event_meta($post->ID, '_EventAllDay', true) )
  145.                                     echo " – " . date_i18n( $time_format, $end );
  146.                             } else {
  147.                                 echo " – " . date_i18n( get_option('date_format', 'F j, Y'), $end);
  148.                                 if ( !tribe_get_event_meta($post->ID, '_EventAllDay', true) )
  149.                                     echo ' ' . date_i18n( get_option('time_format', 'g:i a'), $end) . '<br />';
  150.                             }
  151.                         } ?>
  152.                     </div>
  153.                     <?php if ( function_exists('has_post_thumbnail') && has_post_thumbnail() ) { ?>
  154.                         <div class="tribe-events-event-thumb"><?php the_post_thumbnail( array(75,75));?></div>
  155.                     <?php } ?>
  156.                     <?php echo has_excerpt() ? TribeEvents::truncate($post->post_excerpt) : TribeEvents::truncate(get_the_content(), 30); ?>
  157.  
  158.                 </div>
  159.                 <span class="tribe-events-arrow"></span>
  160.             </div>
  161.         </div>
  162.         <?php
  163.         if( $i < count( $monthView[$day] ) - 1 ) {
  164.             echo "<hr />";
  165.         }
  166.     }
  167. }
  168. ?>
Advertisement
Add Comment
Please, Sign In to add comment