Created
February 10, 2014 19:04
-
-
Save huntlyc/8922090 to your computer and use it in GitHub Desktop.
simple-events-custom-table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Setup the shortcode: | |
// [rse_custom_events] - this works the same as the normal one | |
add_shortcode( 'rse_custom_events' , 'customised_event_table' ); | |
/** | |
* Parses the shortcode and displays the events. The defalt is to only show | |
* events which are happening from the current time onwards. To change this | |
* the user can suppy the 'showevents' attribute with one of the following | |
* values: | |
* | |
* 'all' - past AND upcoming events will be displayed | |
* 'past' - past events only will be displayed | |
* 'upcoming' only upcoming events will be displayed (the default action) | |
* | |
* Note: Adding '-reverse' will reverse the order of any of these values | |
* | |
* For advanced useers there's also the 'noassets' attribute which when set to | |
* 'true' will not include the custom js and css to make the showing and hiding | |
* of the extra info work. | |
* | |
* @global type $wpdb | |
* @param type $attibutes | |
* @return string | |
*/ | |
function customised_event_table( $attibutes ){ | |
global $wpdb; | |
$defaultColList = array( 'date','time','title','moreinfo'); | |
$showevents = ''; | |
$noassets = ''; | |
$columns = ''; | |
$numevents = -1; | |
extract( shortcode_atts( array( 'showevents' => 'upcoming' , | |
'noassets' => 'false', | |
'columns' => 'date,time,title,link,moreinfo', | |
'numevents' => -1, | |
'startdate' => -1, | |
'enddate' => -1 | |
) , | |
$attibutes | |
) | |
); | |
$showevents = strip_tags($showevents); | |
$upcoming_events = hc_rse_get_events( $showevents , $numevents, $startdate, $enddate ); | |
//By default DONT include the custom CSS and JS | |
if( $noassets == 'false' ){ | |
wp_enqueue_style( "hc_rse_styles" , | |
plugins_url() . '/really-simple-events/style.css' ); | |
wp_enqueue_script( "hc_rse_event_table" , | |
plugins_url() . '/really-simple-events/js/event-table.js', | |
array( 'jquery' ) , | |
'1' , | |
true ); | |
wp_localize_script( "hc_rse_event_table" , | |
'objectL10n' , | |
array( 'MoreInfo' => stripslashes ( get_option( 'hc_rse_more_info_link' , __( 'More Info' , 'hc_rse' ) ) ), | |
'HideInfo' => stripslashes ( get_option( 'hc_rse_hide_info_link' , __( 'Hide Info' , 'hc_rse' ) ) ) | |
) | |
); | |
} | |
//If the user has passed something into the columns argument, use it | |
$useDefaultColumns = false; | |
if ($columns !== '' ){ | |
//If we've got a list of cols, split them out | |
if( mb_strpos( $columns , ',' ) === false ){ | |
//We might only have one column to show, make sure it's valid | |
if( !in_array( $columns , $defaultColList ) ){ | |
$useDefaultColumns = true; | |
} | |
}elseif( mb_strpos( $columns , ',' ) !== 0 ){ | |
$columns = explode( ',' , $columns ); | |
}else{ | |
$useDefaultColumns = true; | |
} | |
}else{ //Default to showing everything | |
$useDefaultColumns = true; | |
} | |
//Something's not right, just show the defaults | |
if( $useDefaultColumns ){ | |
$columns = $defaultColList; | |
} | |
$eventHTML = ""; | |
if( $upcoming_events ){ | |
$eventHTML .= '<table class="hc_rse_events_table">'; | |
$isShowingATime = false; | |
//Loop through and see if we're showing a time | |
foreach( $upcoming_events as $event ){ | |
foreach( $columns as $column ){ | |
if( $column == 'time' && $event->show_time == 1 ){ | |
$isShowingATime = true; | |
} | |
} | |
} | |
//For each event, output the correct columns | |
foreach( $upcoming_events as $event ){ | |
//Show only the relevent columns | |
$showMoreInfo = false; | |
$eventHTML .= '<tr>'; | |
foreach( $columns as $column ) { | |
switch( $column ){ | |
case 'date': | |
$eventHTML .= ' <td class="hc_rse_date">'; | |
$eventHTML .= date_i18n( get_option( 'hc_rse_date_format' ) , | |
strtotime( $event->start_date ) ); | |
$eventHTML .= ' </td>'; | |
break; | |
case 'time': | |
//Add column if we're showing a time | |
if( $isShowingATime ) $eventHTML .= ' <td class="hc_rse_time">'; | |
//Only show time if it has been set in the event settings | |
if( $event->show_time == 1 ){ | |
$eventHTML .= date_i18n( get_option( 'hc_rse_time_format' ) , | |
strtotime( $event->start_date ) ); | |
} | |
//close column if we're showing a time | |
if( $isShowingATime ) $eventHTML .= ' </td>'; | |
break; | |
case 'title': | |
$eventHTML .= ' <td class="hc_rse_title">'; | |
$eventHTML .= apply_filters( 'the_content' , stripslashes( $event->title ) ); | |
$eventHTML .= ' </td>'; | |
break; | |
case 'link': | |
$eventHTML .= ' <td class="hc_rse_link">'; | |
$eventHTML .= hc_rse_display_link( $event->link ); | |
$eventHTML .= ' </td>'; | |
break; | |
case 'moreinfo': | |
$showMoreInfo = true; | |
$eventHTML .= ' <td class="hc_rse_more_info_link"> </td>'; | |
break; | |
} | |
} | |
//Add the info if we're showing it... | |
if( $showMoreInfo ){ | |
$eventHTML .= '</tr>'; | |
$eventHTML .= '<tr>'; | |
$eventHTML .= ' <td colspan="4" id="hc_rse_extra_info_' . $showevents . '_' . $event->id . '" class="hc_rse_extra_info">'; | |
$eventHTML .= apply_filters( 'the_content' , stripslashes( $event->extra_info ) ); | |
$eventHTML .= ' </td>'; | |
} | |
$eventHTML .= '</tr>'; | |
} | |
$eventHTML .= '</table>'; | |
} | |
return $eventHTML; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment