Created
May 27, 2015 19:38
-
-
Save loulou2u/d3c5a65a12182bba6c06 to your computer and use it in GitHub Desktop.
The PHP code that constructs the actual widget code that pulls events from LWC
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 | |
/** | |
* The template used for displaying an inline list of events. Used in side columns on landing page templates, mostly. | |
* | |
* | |
* @package bsu2014 | |
*/ | |
if( get_field('show_event_list') ) : | |
$extra_args = ''; | |
$transient_name = 'lwc2'; // LWCal + widget ID, will add options to this name below. "lwc" for "LiveWhale Calendar" because the max length on these is 64 characters. | |
if( get_field( 'groups' ) != 'all' ) { | |
$extra_args .= '/group/' . rawurlencode( trim( get_field( 'groups' ) ) ); | |
$transient_name .= '_group_'.str_replace(array(' ',',','&'),array('_','','_'),strtolower( trim( get_field( 'groups' ) ) )); | |
} else { | |
$transient_name .= '_allgroups'; | |
} | |
if( get_field( 'max_events' ) ) { | |
$extra_args .= '/max/' . trim( get_field( 'max_events' ) ); | |
$transient_name .= '_max' . trim( get_field( 'max_events' ) ); | |
} | |
if( get_field( 'tags' ) ) { | |
$events_tags = explode(',', get_field('tags')); | |
$transient_name .= '_tags'; | |
foreach($events_tags as $tag){ | |
$extra_args .= '/tag/' . rawurlencode(trim($tag)); | |
$transient_name .= '_' . str_replace(array(' ',',','&'),array('_','','_'),trim($tag)); | |
} | |
} | |
$transient_name = substr( $transient_name, 0, 64 ); // transient names limited to 64 characters, so let's not go over. | |
// Check the transient, and if it's expired/empty, refresh it: | |
$events_transient = get_site_transient( $transient_name ); | |
if( empty( $events_transient ) ){ | |
$url='http://your-calendar.lwcal.com/live/widget/2'.$extra_args.'?external_widget=1'; | |
$response = wp_remote_retrieve_body(wp_remote_get( $url )); | |
echo $response; | |
set_site_transient( $transient_name, $response, 60*60*1 ); // 1 hour | |
} else { | |
echo $events_transient; | |
} | |
endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment