PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/the-events-calendar/views/table-mini.php

https://bitbucket.org/codemen_iftekhar/codemen
PHP | 133 lines | 101 code | 20 blank | 12 comment | 27 complexity | 6dd1a59d300e9195a40dd68a1c9c39e7 MD5 | raw file
  1. <?php
  2. /**
  3. * The calendar widget display.
  4. *
  5. * You can customize this view by putting a replacement file of the same name (table-mini.php) in the events/ directory of your theme.
  6. */
  7. // Don't load directly
  8. if ( !defined('ABSPATH') ) { die('-1'); }
  9. $tribe_ecp = TribeEvents::instance();
  10. global $wp_query;
  11. $old_date = null;
  12. if ( !defined( "DOING_AJAX" ) || !DOING_AJAX ) {
  13. $current_date = date_i18n( TribeDateUtils::DBYEARMONTHTIMEFORMAT ) . "-01";
  14. if ( isset( $wp_query->query_vars['eventDate'] ) ) {
  15. $old_date = $wp_query->query_vars['eventDate'];
  16. $wp_query->query_vars['eventDate'] = $current_date;
  17. }
  18. }else{
  19. $current_date = $tribe_ecp->date;
  20. }
  21. $eventPosts = tribe_get_events(array( 'eventDisplay'=>'month' ) );
  22. if ( !$current_date ) {
  23. $current_date = $tribe_ecp->date;
  24. }
  25. $daysInMonth = isset($date) ? date("t", $date) : date("t");
  26. $startOfWeek = get_option( 'start_of_week', 0 );
  27. list( $year, $month ) = split( '-', $current_date );
  28. $date = mktime(12, 0, 0, $month, 1, $year); // 1st day of month as unix stamp
  29. $rawOffset = date("w", $date) - $startOfWeek;
  30. $offset = ( $rawOffset < 0 ) ? $rawOffset + 7 : $rawOffset; // month begins on day x
  31. $rows = 1;
  32. $monthView = tribe_sort_by_month( $eventPosts, $current_date );
  33. // the div tribe-events-widget-nav controls ajax navigation for the calendar widget. Modify with care and do not remove any class names or elements inside that element if you wish to retain ajax functionality.
  34. ?>
  35. <div class="tribe-events-widget-nav">
  36. <span id="tribe-mini-ajax-month">
  37. <?php echo $tribe_ecp->monthsShort[date('M',$date)]; echo date(' Y',$date); ?>
  38. </span>
  39. </div>
  40. <table class="tribe-events-calendar tribe-events-calendar-widget" id="small">
  41. <thead>
  42. <tr>
  43. <?php
  44. for( $n = $startOfWeek; $n < count($tribe_ecp->daysOfWeekMin) + $startOfWeek; $n++ ) {
  45. $dayOfWeek = ( $n >= 7 ) ? $n - 7 : $n;
  46. echo '<th id="tribe-events-' . strtolower($tribe_ecp->daysOfWeekMin[$dayOfWeek]) . '" title="' . $tribe_ecp->daysOfWeek[$dayOfWeek] . '">' . $tribe_ecp->daysOfWeekMin[$dayOfWeek] . '</th>';
  47. }
  48. ?>
  49. </tr>
  50. </thead>
  51. <tbody>
  52. <tr>
  53. <?php
  54. // skip last month
  55. for( $i = 1; $i <= $offset; $i++ ){
  56. echo "<td class='tribe-events-othermonth'></td>";
  57. }
  58. // output this month
  59. for( $day = 1; $day <= date("t", $date); $day++ ) {
  60. if( ($day + $offset - 1) % 7 == 0 && $day != 1) {
  61. echo "</tr>\n\t<tr>";
  62. $rows++;
  63. }
  64. // Var'ng up days, months and years
  65. $current_day = date_i18n( 'd' );
  66. $current_month = date_i18n( 'm' );
  67. $current_year = date_i18n( 'Y' );
  68. if ( $current_month == $month && $current_year == $year) {
  69. // Past, Present, Future class
  70. if ($current_day == $day ) {
  71. $ppf = ' tribe-events-present';
  72. } elseif ($current_day > $day) {
  73. $ppf = ' tribe-events-past';
  74. } elseif ($current_day < $day) {
  75. $ppf = ' tribe-events-future';
  76. }
  77. } elseif ( $current_month > $month && $current_year == $year || $current_year > $year ) {
  78. $ppf = ' tribe-events-past';
  79. } elseif ( $current_month < $month && $current_year == $year || $current_year < $year ) {
  80. $ppf = ' tribe-events-future';
  81. } else { $ppf = false; }
  82. echo "<td class='tribe-events-thismonth" . $ppf . "'>" . tribe_mini_display_day( $day, $monthView ) . "\n";
  83. echo "</td>";
  84. }
  85. // skip next month
  86. while( ($day + $offset) <= $rows * 7)
  87. {
  88. echo "<td class='tribe-events-othermonth'></td>";
  89. $day++;
  90. }
  91. ?>
  92. </tr>
  93. </tbody>
  94. </table>
  95. <a class="tribe-view-all-events" href="<?php echo tribe_get_events_link(); ?>"><?php _e('View all &raquo;', 'tribe-events-calendar'); ?></a>
  96. <?php
  97. if ($old_date){
  98. $wp_query->query_vars['eventDate'] = $old_date;
  99. }
  100. function tribe_mini_display_day( $day, $monthView ) {
  101. $return = "<div class='daynum tribe-events-event' id='daynum_$day'>";
  102. $return .= ( count($monthView[$day]) ) ? "<a class='tribe-events-mini-has-event'>$day</a>" : $day;
  103. $return .= "<div id='tooltip_day_$day' class='tribe-events-tooltip' style='display:none;'>";
  104. for( $i = 0; $i < count( $monthView[$day] ); $i++ ) {
  105. $post = $monthView[$day][$i];
  106. setup_postdata( $post );
  107. $return .= '<h5 class="tribe-events-event-title-mini"><a href="'. tribe_get_event_link($post) .'">' . $post->post_title . '</a></h5>';
  108. }
  109. $return .= '<span class="tribe-events-arrow"></span>';
  110. $return .= '</div>';
  111. $return .= "</div>";
  112. return $return;
  113. }