Guest User

table.php

a guest
Jul 13th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.87 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  
  5. * This file outputs the actual days of the month in the TEC calendar view
  6.  
  7. *
  8.  
  9. * You can customize this view by putting a replacement file of the same name (table.php) in the events/ directory of your theme.
  10.  
  11. */
  12.  
  13.  
  14.  
  15. // Don't load directly
  16.  
  17. if ( !defined('ABSPATH') ) { die('-1'); }
  18.  
  19.  
  20.  
  21. $tribe_ecp = TribeEvents::instance();
  22.  
  23. /*
  24. if(isset($myCity)){
  25. $eventCat=get_category_id($myCity);
  26. $eventPosts = tribe_get_events( array( 'eventCat' => $eventCat, 'time_order' => 'ASC', 'eventDisplay'=>'month' ) );
  27. }*/
  28.  
  29. // in an events cat
  30.  
  31. if ( is_tax( $tribe_ecp->get_event_taxonomy() ) ) {
  32.  
  33.     $cat = get_term_by( 'slug', get_query_var('term'), $tribe_ecp->get_event_taxonomy() );
  34.  
  35.     $eventCat = (int) $cat->term_id;
  36.  
  37.     $eventPosts = tribe_get_events( array( 'eventCat' => $eventCat, 'time_order' => 'ASC', 'eventDisplay'=>'month' ) );
  38.  
  39. }
  40.  
  41.  
  42. // not in a cat
  43.  
  44. else {
  45.  
  46.     $eventPosts = tribe_get_events(array( 'eventDisplay'=>'month' ));
  47.  
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54. $daysInMonth = isset($date) ? date("t", $date) : date("t");
  55.  
  56. $startOfWeek = get_option( 'start_of_week', 0 );
  57.  
  58. list( $year, $month ) = split( '-', $tribe_ecp->date );
  59.  
  60. $date = mktime(12, 0, 0, $month, 1, $year); // 1st day of month as unix stamp
  61.  
  62. $rawOffset = date("w", $date) - $startOfWeek;
  63.  
  64. $offset = ( $rawOffset < 0 ) ? $rawOffset + 7 : $rawOffset; // month begins on day x
  65.  
  66. $rows = 1;
  67.  
  68.  
  69.  
  70. $monthView = tribe_sort_by_month( $eventPosts, $tribe_ecp->date );
  71.  
  72.  
  73.  
  74. ?>
  75.  
  76. <table class="tribe-events-calendar" id="big">
  77.  
  78.     <thead>
  79.  
  80.             <tr>
  81.  
  82.                 <?php
  83.  
  84.                 for( $n = $startOfWeek; $n < count($tribe_ecp->daysOfWeek) + $startOfWeek; $n++ ) {
  85.  
  86.                     $dayOfWeek = ( $n >= 7 ) ? $n - 7 : $n;
  87.  
  88.                    
  89.  
  90.                     echo '<th id="tribe-events-' . strtolower($tribe_ecp->daysOfWeek[$dayOfWeek]) . '" abbr="' . $tribe_ecp->daysOfWeek[$dayOfWeek] . '">' . $tribe_ecp->daysOfWeekShort[$dayOfWeek] . '</th>';
  91.  
  92.                 }
  93.  
  94.                 ?>
  95.  
  96.             </tr>
  97.  
  98.     </thead>
  99.  
  100.  
  101.  
  102.     <tbody>
  103.  
  104.         <tr>
  105.  
  106.         <?php
  107.  
  108.             // skip last month
  109.  
  110.             for( $i = 1; $i <= $offset; $i++ ){
  111.  
  112.                 echo "<td class='tribe-events-othermonth'></td>";
  113.  
  114.             }
  115.  
  116.             // output this month
  117.  
  118.          $days_in_month = date("t", intval($date));
  119.  
  120.             for( $day = 1; $day <= $days_in_month; $day++ ) {
  121.  
  122.                 if( ($day + $offset - 1) % 7 == 0 && $day != 1) {
  123.  
  124.                     echo "</tr>\n\t<tr>";
  125.  
  126.                     $rows++;
  127.  
  128.                 }
  129.  
  130.            
  131.  
  132.                 // Var'ng up days, months and years
  133.  
  134.                 $current_day = date_i18n( 'd' );
  135.  
  136.                 $current_month = date_i18n( 'm' );
  137.  
  138.                 $current_year = date_i18n( 'Y' );
  139.  
  140.             $date = "$year-$month-$day";
  141.  
  142.                
  143.  
  144.                 if ( $current_month == $month && $current_year == $year) {
  145.  
  146.                     // Past, Present, Future class
  147.  
  148.                     if ($current_day == $day ) {
  149.  
  150.                         $ppf = ' tribe-events-present';
  151.  
  152.                     } elseif ($current_day > $day) {
  153.  
  154.                         $ppf = ' tribe-events-past';
  155.  
  156.                     } elseif ($current_day < $day) {
  157.  
  158.                         $ppf = ' tribe-events-future';
  159.  
  160.                     }
  161.  
  162.                 } elseif ( $current_month > $month && $current_year == $year || $current_year > $year ) {
  163.  
  164.                     $ppf = ' tribe-events-past';
  165.  
  166.                 } elseif ( $current_month < $month && $current_year == $year || $current_year < $year ) {
  167.  
  168.                     $ppf = ' tribe-events-future';
  169.  
  170.                 } else { $ppf = false; }
  171.  
  172.                
  173.  
  174.                 echo "<td class='tribe-events-thismonth" . $ppf . "'>" . display_day_title( $day, $monthView, $date ) . "\n";
  175.  
  176.                 echo display_day( $day, $monthView );
  177.  
  178.                 echo "</td>";
  179.  
  180.             }
  181.  
  182.             // skip next month
  183.  
  184.             while( ($day + $offset) <= $rows * 7)
  185.  
  186.             {
  187.  
  188.                 echo "<td class='tribe-events-othermonth'></td>";
  189.  
  190.                 $day++;
  191.  
  192.             }
  193.  
  194.         ?>
  195.  
  196.         </tr>
  197.  
  198.     </tbody>
  199.  
  200. </table>
  201.  
  202. <?php
  203.  
  204.  
  205.  
  206. function display_day_title( $day, $monthView, $date ) {
  207.  
  208.     $return = "<div class='daynum tribe-events-event' id='daynum_$day'>";
  209.  
  210.     if( function_exists('tribe_get_linked_day') && count( $monthView[$day] ) > 0 ) {
  211.  
  212.         $return .= tribe_get_linked_day($date, $day); // premium
  213.  
  214.     } else {
  215.  
  216.         $return .= $day;
  217.  
  218.     }
  219.  
  220.     $return .= "<div id='tooltip_day_$day' class='tribe-events-tooltip' style='display:none;'>";
  221.  
  222.     for( $i = 0; $i < count( $monthView[$day] ); $i++ ) {
  223.  
  224.         $post = $monthView[$day][$i];
  225.  
  226.         setup_postdata( $post );
  227.  
  228.         $return .= '<h5 class="tribe-events-event-title">' . get_the_title() . '</h5>';
  229.  
  230.     }
  231.  
  232.     $return .= '<span class="tribe-events-arrow"></span>';
  233.  
  234.     $return .= '</div>';
  235.  
  236.  
  237.  
  238.     $return .= "</div>";
  239.  
  240.     return $return;
  241.  
  242. }
  243.  
  244.  
  245.  
  246. function display_day( $day, $monthView ) {
  247.  
  248.     global $post;
  249.  
  250.     $output = '';
  251.  
  252.     $posts_per_page = tribe_get_option( 'postsPerPage', 10 );
  253.  
  254.     for ( $i = 0; $i < count( $monthView[$day] ); $i++ ) {
  255.  
  256.         $post = $monthView[$day][$i];
  257.  
  258.         setup_postdata( $post );
  259.  
  260.         $eventId    = $post->ID.'-'.$day;
  261.  
  262.         $start      = tribe_get_start_date( $post->ID, false, 'U' );
  263.  
  264.         $end        = tribe_get_end_date( $post->ID, false, 'U' );
  265.  
  266.         $cost       = tribe_get_cost( $post->ID );
  267.  
  268.         $address    = tribe_get_address( $post->ID );
  269.  
  270.         $city       = tribe_get_city( $post->ID );
  271.  
  272.         $state      = tribe_get_state( $post->ID );
  273.  
  274.         $province   = tribe_get_province( $post->ID );
  275.  
  276.         $country    = tribe_get_country( $post->ID );
  277.  
  278.         ?>
  279.  
  280.         <div id='event_<?php echo $eventId; ?>' <?php post_class('tribe-events-event tribe-events-real-event') ?>>
  281.  
  282.             <a href="<?php tribe_event_link(); ?>"><?php the_title(); ?></a>
  283.  
  284.             <div id='tooltip_<?php echo $eventId; ?>' class="tribe-events-tooltip" style="display:none;">
  285.  
  286.                 <h5 class="tribe-events-event-title"><?php the_title();?></h5>
  287.  
  288.                 <div class="tribe-events-event-body">
  289.  
  290.                     <div class="tribe-events-event-date">
  291.  
  292.                         <?php if ( !empty( $start ) )   echo date_i18n( get_option('date_format', 'F j, Y'), $start);
  293.  
  294.                         if ( !tribe_get_event_meta($post->ID, '_EventAllDay', true) )
  295.  
  296.                             echo ' ' . date_i18n( get_option('time_format', 'g:i a'), $start); ?>
  297.  
  298.                         <?php if ( !empty( $end )  && $start !== $end ) {
  299.  
  300.                             if ( date_i18n( 'Y-m-d', $start ) == date_i18n( 'Y-m-d', $end ) ) {
  301.  
  302.                                 $time_format = get_option( 'time_format', 'g:i a' );
  303.  
  304.                                 if ( !tribe_get_event_meta($post->ID, '_EventAllDay', true) )
  305.  
  306.                                     echo " – " . date_i18n( $time_format, $end );
  307.  
  308.                             } else {
  309.  
  310.                                 echo " – " . date_i18n( get_option('date_format', 'F j, Y'), $end);
  311.  
  312.                                 if ( !tribe_get_event_meta($post->ID, '_EventAllDay', true) )
  313.  
  314.                                     echo ' ' . date_i18n( get_option('time_format', 'g:i a'), $end) . '<br />';
  315.  
  316.                             }
  317.  
  318.                         } ?>
  319.  
  320.                     </div>
  321.  
  322.                     <?php if ( function_exists('has_post_thumbnail') && has_post_thumbnail() ) { ?>
  323.  
  324.                         <div class="tribe-events-event-thumb"><?php the_post_thumbnail( array(75,75));?></div>
  325.  
  326.                     <?php } ?>
  327.  
  328.                     <?php echo has_excerpt() ? TribeEvents::truncate($post->post_excerpt) : TribeEvents::truncate(get_the_content(), 30); ?>
  329.  
  330.  
  331.  
  332.                 </div>
  333.  
  334.                 <span class="tribe-events-arrow"></span>
  335.  
  336.             </div>
  337.  
  338.         </div>
  339.  
  340.         <?php
  341.  
  342.         if( $i < count( $monthView[$day] ) - 1 ) {
  343.  
  344.             echo "<hr />";
  345.  
  346.         }
  347.  
  348.     }
  349.  
  350. }
  351.  
  352. ?>
Advertisement
Add Comment
Please, Sign In to add comment