public
Created

  • Download Gist
date.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
<?php
/**
* Date Functions
*
* Display functions (template-tags) for use in WordPress templates.
*/
 
// Don't load directly
if ( !defined('ABSPATH') ) { die('-1'); }
 
if( class_exists( 'TribeEvents' ) ) {
 
/**
* Start Date
*
* Returns the event start date and time
*
* @param int $postId (optional) This only works for non recurring events
* @param bool $displayTime If true shows date and time, if false only shows date
* @param string $dateFormat Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
* @return string Date
* @todo support $postId for recurring events.
* @since 2.0
*/
function tribe_get_start_date( $postId = null, $displayTime = true, $dateFormat = '' ) {
$postId = TribeEvents::postIdHelper( $postId );
if (!$postId || ( function_exists('tribe_is_recurring_event') && tribe_is_recurring_event( $postId ) ) ) {
global $post;
} else {
$post = get_post($postId);
}
 
if( tribe_get_all_day( $postId ) )
$displayTime = false;
 
if( empty($post->EventStartDate) )
$post->EventStartDate = tribe_get_event_meta( $postId, '_EventStartDate', true );
 
if( isset($post->EventStartDate) ){
$date = strtotime( $post->EventStartDate );
}else{
return; // '&mdash;';
}
 
return tribe_event_format_date($date, $displayTime, $dateFormat );
}
 
/**
* End Date
*
* Returns the event end date
*
* @param int $postId (optional) this only works for non recurring events
* @param bool $displayTime If true shows date and time, if false only shows date
* @param string $dateFormat Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
* @return string Date
* @todo support $postId for recurring events.
* @since 2.0
*/
function tribe_get_end_date( $postId = null, $displayTime = 'true', $dateFormat = '', $displayDate = true ) {
$postId = TribeEvents::postIdHelper( $postId );
if (!$postId || ( function_exists('tribe_is_recurring_event') && tribe_is_recurring_event( $postId ) ) ) {
global $post;
} else {
$post = get_post($postId);
}
if( tribe_get_all_day( $postId ) )
$displayTime = false;
 
if( empty($post->EventEndDate) )
$post->EventEndDate = tribe_get_event_meta( $postId, '_EventEndDate', true );
 
if( isset($post->EventEndDate) ){
$date = strtotime( $post->EventEndDate );
}else{
return; // '&mdash;';
}
 
return tribe_event_format_date($date, $displayTime, $dateFormat, $displayDate );
}
 
/**
* Formatted Date
*
* Returns formatted date
*
* @param string $date
* @param bool $displayTime If true shows date and time, if false only shows date
* @param string $dateFormat Allows date and time formating using standard php syntax (http://php.net/manual/en/function.date.php)
* @return string
* @since 2.0
*/
function tribe_event_format_date($date, $displayTime = true, $dateFormat = '', $displayDate = true) {
$tribe_ecp = TribeEvents::instance();
if( $displayDate )
if( $dateFormat ) $format = $dateFormat;
else $format = get_option( 'date_format', TribeDateUtils::DATEONLYFORMAT );
 
if ( $displayTime )
$format = $tribe_ecp->getTimeFormat( $format );
 
$shortMonthNames = ( strstr( $format, 'M' ) ) ? true : false;
$date = date_i18n ( $format, $date );
return str_replace( array_keys($tribe_ecp->monthNames( $shortMonthNames )), $tribe_ecp->monthNames( $shortMonthNames ), $date);
}
 
}
?>
events-list-load-widget-display.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
<?php
/**
* This is the template for the output of the events list widget.
* All the items are turned on and off through the widget admin.
* There is currently no default styling, which is highly needed.
*
* You can customize this view by putting a replacement file of the same name (events-list-load-widget-display.php) in the events/ directory of your theme.
*
* @return string
*/
 
// Vars set:
// '$event->AllDay',
// '$event->StartDate',
// '$event->EndDate',
// '$event->ShowMapLink',
// '$event->ShowMap',
// '$event->Cost',
// '$event->Phone',
 
// Don't load directly
if ( !defined('ABSPATH') ) { die('-1'); }
 
$event = array();
$tribe_ecp = TribeEvents::instance();
reset($tribe_ecp->metaTags); // Move pointer to beginning of array.
foreach($tribe_ecp->metaTags as $tag){
$var_name = str_replace('_Event','',$tag);
$event[$var_name] = tribe_get_event_meta( $post->ID, $tag, true );
}
 
$event = (object) $event; //Easier to work with.
 
ob_start();
if ( !isset($alt_text) ) { $alt_text = ''; }
post_class($alt_text,$post->ID);
$class = ob_get_contents();
ob_end_clean();
?>
<li <?php echo $class ?>>
<div class="when">
<?php
$space = false;
$output = '';
echo tribe_get_start_date( $post->ID );
 
if( tribe_is_multiday( $post->ID ) ) {
echo ' – <br/>'. tribe_get_end_date($post->ID, 'true', '', true);
}
elseif( !$event->AllDay ) {
echo ' – '. tribe_get_end_date($post->ID, 'true', '', false);
}
 
if( $event->AllDay ) {
echo ' <small><em>('.__('All Day','tribe-events-calendar').')</em></small>';
}
?>
</div>
<div class="event">
<a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a>
</div>
</li>
<?php $alt_text = ( empty( $alt_text ) ) ? 'alt' : ''; ?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.