Advertisement
nciske

The Events Calendar Date Hotfix

Dec 13th, 2011
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.41 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Date Functions
  4.  *
  5.  * Display functions (template-tags) for use in WordPress templates.
  6.  */
  7.  
  8. // Don't load directly
  9. if ( !defined('ABSPATH') ) { die('-1'); }
  10.  
  11. if( class_exists( 'TribeEvents' ) ) {
  12.  
  13.     /**
  14.      * Start Date
  15.      *
  16.      * Returns the event start date and time
  17.      *
  18.      * @param int $postId (optional) This only works for non recurring events
  19.      * @param bool $displayTime If true shows date and time, if false only shows date
  20.      * @param string $dateFormat Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
  21.      * @return string Date
  22.      * @todo support $postId for recurring events.
  23.      * @since 2.0
  24.      */
  25.     function tribe_get_start_date( $postId = null, $displayTime = true, $dateFormat = '' )  {
  26.         $postId = TribeEvents::postIdHelper( $postId );
  27.         if (!$postId || ( function_exists('tribe_is_recurring_event') && tribe_is_recurring_event( $postId ) ) ) {
  28.             global $post;
  29.         } else {
  30.             $post = get_post($postId);
  31.         }
  32.  
  33.         if( tribe_get_all_day( $postId ) )
  34.              $displayTime = false;
  35.  
  36.         if( empty($post->EventStartDate) )
  37.             $post->EventStartDate = tribe_get_event_meta( $postId, '_EventStartDate', true );
  38.  
  39.         if( isset($post->EventStartDate) ){
  40.             $date = strtotime( $post->EventStartDate );
  41.         }else{
  42.             return; // '&mdash;';
  43.         }
  44.  
  45.         return tribe_event_format_date($date, $displayTime, $dateFormat );
  46.     }
  47.  
  48.     /**
  49.      * End Date
  50.      *
  51.      * Returns the event end date
  52.      *
  53.      * @param int $postId (optional) this only works for non recurring events
  54.      * @param bool $displayTime If true shows date and time, if false only shows date
  55.      * @param string $dateFormat Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
  56.      * @return string Date
  57.      * @todo support $postId for recurring events.
  58.      * @since 2.0
  59.      */
  60.     function tribe_get_end_date( $postId = null, $displayTime = 'true', $dateFormat = '' )  {
  61.         $postId = TribeEvents::postIdHelper( $postId );
  62.         if (!$postId || ( function_exists('tribe_is_recurring_event') && tribe_is_recurring_event( $postId ) ) ) {
  63.             global $post;
  64.         } else {
  65.             $post = get_post($postId);
  66.         }
  67.    
  68.         if( tribe_get_all_day( $postId ) )
  69.              $displayTime = false;
  70.  
  71.         if( empty($post->EventEndDate))
  72.             $post->EventEndDate = tribe_get_event_meta( $postId, '_EventEndDate', true );
  73.  
  74.         if( isset($post->EventEndDate) ){
  75.             $date = strtotime( $post->EventEndDate );
  76.         }else{
  77.             return; // '&mdash;';
  78.         }
  79.  
  80.         return tribe_event_format_date($date, $displayTime, $dateFormat );
  81.     }
  82.  
  83.     /**
  84.      * Formatted Date
  85.      *
  86.      * Returns formatted date
  87.      *
  88.      * @param string $date
  89.      * @param bool $displayTime If true shows date and time, if false only shows date
  90.      * @param string $dateFormat Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
  91.      * @return string
  92.      * @since 2.0
  93.      */
  94.     function tribe_event_format_date($date, $displayTime = true,  $dateFormat = '')  {
  95.         $tribe_ecp = TribeEvents::instance();
  96.        
  97.         if( $dateFormat ) $format = $dateFormat;
  98.         else $format = get_option( 'date_format', TribeDateUtils::DATEONLYFORMAT );
  99.  
  100.         if ( $displayTime )
  101.             $format = $tribe_ecp->getTimeFormat( $format );
  102.  
  103.         $shortMonthNames = ( strstr( $format, 'M' ) ) ? true : false;
  104.         $date = date_i18n ( $format, $date );
  105.         return str_replace( array_keys($tribe_ecp->monthNames( $shortMonthNames )), $tribe_ecp->monthNames( $shortMonthNames ), $date);
  106.     }
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement