-
-
Save darkterminal/183394d9f316221a34eb974d537a7253 to your computer and use it in GitHub Desktop.
add event to google calendar
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 | |
// add event to google calendar | |
echo '<a href="' . addToGoogleCalendar("Let's test this", "next wednesday 2pm", "next wednesday 4pm", "right here, right now", "bla blah rhubarb http://axwax.de") . '">next weds 2pm</a><br/>'; | |
echo '<a href="' . addToGoogleCalendar("Breakfast at Tiffany's", "tomorrow 8am") . '">Breakfast at Tiffany\'s</a>'; | |
function addToGoogleCalendar($title='', $startdate='', $enddate='', $location='', $details='') | |
{ | |
$startdate = ($startdate ? $startdate : time()); | |
$startdate = (is_numeric($startdate) ? $startdate : strtotime($startdate)); | |
$enddate = ($enddate ? $enddate : $startdate + 3600); | |
$enddate = (is_numeric($enddate) ? $enddate : strtotime($enddate)); | |
$google_url = "http://www.google.com/calendar/event"; | |
$action = "?action=TEMPLATE"; | |
$title = ( $title ? ("&text=" . urlencode($title)) : "") ; | |
$dates = "&dates=" . getIcalDate($startdate) . "Z/" . getIcalDate($enddate) . "Z"; | |
$location = ( $location ? ("&location=" . urlencode($location)) : "") ; | |
$details = ( $details ? ("&details=" . urlencode($details)) : "") ; | |
$out = $google_url . $action . $title . $dates . $location . $details; | |
return $out; | |
} | |
function getIcalDate($time, $incl_time = true) | |
{ | |
return $incl_time ? date('Ymd\THis', $time) : date('Ymd', $time); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment