Skip to content

Instantly share code, notes, and snippets.

@nhaskins
Created March 6, 2013 16:35
Show Gist options
  • Save nhaskins/5100705 to your computer and use it in GitHub Desktop.
Save nhaskins/5100705 to your computer and use it in GitHub Desktop.
PHP function to generate Google Calendar 'add event' links
//this function returns a URL that when clicked, attempts to add a gcal event
function gcal_evt_href($data)
{
//return a gcal href link for anchors
//encode the data in the array for url formatting
foreach($data as &$xx)
{
$xx = urlencode($xx);
}
$href = 'https://www.google.com/calendar/render?action=TEMPLATE&text='
.$data['event_name'].'&dates='
.$data['datetime_start'].'/'
.$data['datetime_end'].'&details='
.$data['description'].'&location='
.$data['location_text'].'&trp=false&sprop='
.$data['sprop_website'].'&sprop=name:'
.$data['sprop_name'].'&pli=1&sf=true&output=xml';
return $href;
} //end gcal_event_button
//example data to feed to the function
$data = array(
'event_name' => 'event_name',
'datetime_start' => '20130221', //YYYYMMDD
'datetime_end' => '20130222', //YYYYMMDD
'location_text' => 'name and address is fine',
'description' => 'longer desc for the details',
'sprop_website' => 'http://organization.com',
'sprop_name' => 'organization name'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment