/events/table.php

https://github.com/mertonium/Welcome-America-WP-Theme · PHP · 149 lines · 129 code · 5 blank · 15 comment · 32 complexity · b1fadc85e7e3fd12a8a71d36b2dd71cf MD5 · raw file

  1. <?php
  2. global $spEvents;
  3. //print_r($spEvents);
  4. $eventPosts = get_events();
  5. $startOfWeek = get_option( 'start_of_week', 0 );
  6. list( $year, $month ) = split( '-', $spEvents->date );
  7. $date = mktime(12, 0, 0, $month, 1, $year); // 1st day of month as unix stamp
  8. $daysInMonth = date("t", $date);
  9. $monthView = events_by_month( $eventPosts, $spEvents->date );
  10. $rawOffset = date("w", $date) - $startOfWeek;
  11. $offset = ( $rawOffset < 0 ) ? $rawOffset + 7 : $rawOffset; // month begins on day x
  12. $rows = 1;
  13. $monthView = events_by_month( $eventPosts, $spEvents->date );
  14. ?>
  15. <table class="tec-calendar" id="big">
  16. <thead>
  17. <tr>
  18. <?php
  19. for( $n = $startOfWeek; $n < count($spEvents->daysOfWeek) + $startOfWeek; $n++ ) {
  20. $dayOfWeek = ( $n >= 7 ) ? $n - 7 : $n;
  21. echo '<th id="tec-' . strtolower($spEvents->daysOfWeek[$dayOfWeek]) . '">' . $spEvents->daysOfWeekShort[$dayOfWeek] . '</th>';
  22. }
  23. ?>
  24. </tr>
  25. </thead>
  26. <tbody>
  27. <tr>
  28. <?php
  29. // skip last month
  30. for( $i = 1; $i <= $offset; $i++ ){
  31. echo "<td class='tec-othermonth'></td>";
  32. }
  33. // output this month
  34. for( $day = 1; $day <= date("t", $date); $day++ ) {
  35. if( ($day + $offset - 1) % 7 == 0 && $day != 1) {
  36. echo "</tr>\n\t<tr>";
  37. $rows++;
  38. }
  39. // Var'ng up days, months and years
  40. $current_day = date_i18n( 'd' );
  41. $current_month = date_i18n( 'm' );
  42. $current_year = date_i18n( 'Y' );
  43. if ( $current_month == $month && $current_year == $year) {
  44. // Past, Present, Future class
  45. if ($current_day == $day ) {
  46. $ppf = ' tec-present';
  47. } elseif ($current_day > $day) {
  48. $ppf = ' tec-past';
  49. } elseif ($current_day < $day) {
  50. $ppf = ' tec-future';
  51. }
  52. } elseif ( $current_month > $month && $current_year == $year || $current_year > $year ) {
  53. $ppf = ' tec-past';
  54. } elseif ( $current_month < $month && $current_year == $year || $current_year < $year ) {
  55. $ppf = ' tec-future';
  56. } else { $ppf = false; }
  57. echo "<td class='tec-thismonth" . $ppf . "'>" . display_day_title( $day, $monthView ) . "\n";
  58. echo display_day( $day, $monthView );
  59. echo "</td>";
  60. }
  61. // skip next month
  62. while( ($day + $offset) <= $rows * 7)
  63. {
  64. echo "<td class='tec-othermonth'></td>";
  65. $day++;
  66. }
  67. ?>
  68. </tr>
  69. </tbody>
  70. </table>
  71. <?php
  72. /**
  73. * Each day in the calendar grid view will only display posts_per_page events.
  74. * If the day has more events than will be displayed, we show all of the events
  75. * as a tooltip in the day header
  76. */
  77. function display_day_title( $day, $monthView ) {
  78. $return = "<div class='daynum tec-event' id='daynum_$day'>";
  79. if( !count( $monthView[$day] ) || count( $monthView[$day] ) < get_option( 'posts_per_page' ) ) {
  80. $return .= $day;
  81. } else {
  82. global $post;
  83. $return .= "<a class='tec-multi-event-day'>$day</a>";
  84. $return .= "<div id='tooltip_day_$day' class='tec-tooltip' style='display:none;'>";
  85. for( $i = 0; $i < count( $monthView[$day] ); $i++ ) {
  86. $post = $monthView[$day][$i];
  87. setup_postdata( $post );
  88. $return .= '<h5 class="tec-event-title">' . get_the_title() . '</h5>';
  89. }
  90. $return .= '<span class="tec-arrow"></span>';
  91. $return .= '</div>';
  92. }
  93. $return .= "</div>";
  94. return $return;
  95. }
  96. /**
  97. * Each day in the calendar grid view will only display posts_per_page events.
  98. * Each event will have a tooltip for more information on that event.
  99. */
  100. function display_day( $day, $monthView ) {
  101. global $post;
  102. $output = '';
  103. $posts_per_page = get_option( 'posts_per_page' );
  104. for( $i = 0; $i < count( $monthView[$day] ) && $i < $posts_per_page; $i++ ) {
  105. $post = $monthView[$day][$i];
  106. setup_postdata( $post );
  107. $eventId = $post->ID.'-'.$day;
  108. $start = the_event_start_date( $post->ID );
  109. $end = the_event_end_date( $post->ID );
  110. $cost = the_event_cost( $post->ID );
  111. $address = the_event_address( $post->ID );
  112. $city = the_event_city( $post->ID );
  113. $state = the_event_state( $post->ID );
  114. $province = the_event_province( $post->ID );
  115. $country = the_event_country( $post->ID );
  116. ?>
  117. <div id='event_<?php echo $eventId; ?>' class="tec-event
  118. <?php
  119. foreach((get_the_category()) as $category) {
  120. echo 'cat_' . $category->cat_name . ' ';
  121. }
  122. ?>
  123. ">
  124. <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  125. <div id='tooltip_<?php echo $eventId; ?>' class="tec-tooltip" style="display:none;">
  126. <h5 class="tec-event-title"><?php the_title();?></h5>
  127. <div class="tec-event-body">
  128. <?php if ( !the_event_all_day($post->ID) ) : ?>
  129. <div class="tec-event-date">
  130. <?php if ( !empty( $start ) ) echo $start; ?>
  131. <?php if ( !empty( $end ) && $start !== $end ) echo " – " . $end . '<br />'; ?>
  132. </div>
  133. <?php endif; ?>
  134. <?php echo The_Events_Calendar::truncate(get_the_content(), 30); ?>
  135. </div>
  136. <span class="tec-arrow"></span>
  137. </div>
  138. </div>
  139. <?php
  140. if( $i < $posts_per_page - 1 && $i < count( $monthView[$day] ) - 1 ) {
  141. echo "<hr />";
  142. }
  143. }
  144. }