Created
July 18, 2014 03:51
-
-
Save chrisknepper/cba89754a222695c37e9 to your computer and use it in GitHub Desktop.
PHP Google Calendar Link Generator
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 | |
//Call this with the shown parameters (make sure $time and $end are integers and in Unix timestamp format!) | |
//Get a link that will open a new event in Google Calendar with those details pre-filled | |
function make_google_calendar_link($name, $begin, $end, $location, $details) { | |
$params = array('&dates=', '/', '&details=', '&location=', '&sf=true&output=xml'); | |
$url = 'https://www.google.com/calendar/render?action=TEMPLATE&text='; | |
$arg_list = func_get_args(); | |
for ($i = 0; $i < count($arg_list); $i++) { | |
$current = $arg_list[$i]; | |
if(is_int($current)) { | |
$t = new DateTime('@' . $current, new DateTimeZone('UTC')); | |
$current = $t->format('Ymd\THis\Z'); | |
unset($t); | |
} | |
else { | |
$current = urlencode($current); | |
} | |
$url .= (string) $current . $params[$i]; | |
} | |
return $url; | |
} | |
//Sample link, navigate to it while logged into your Google account | |
//If you aren't logged in, it should redirect properly upon login | |
echo make_google_calendar_link("A Special Event", 1429518000, 1429561200, "612 Wharf Ave. Hoboken, New Jersey", "Descriptions require imagination juice"); | |
?> |
Thank you for this snippet, does the job!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@chrisknepper good job, but you have mixed $location and $details variables.