添加到网站的 gCal 按钮
Add to gCal button for website
我正在寻找一种在我的网站上显示按钮的方法,以便用户可以自动将事件添加到他们的 google 日历中,类似于 http://www.addthisevent.com/ 所做的(目前我在用着)。
到目前为止,我已经在网上查看过,但我只能通过将其添加到我的日历并从中生成代码来找到一种手动方法。但是我想用 PHP.
自动完成
我不想继续的理由是让我自己控制网站上加载的所有资源。
编辑:我正在寻找一个 link,用户可以单击它,然后将打开一个新选项卡,其中打开并预填充了添加日历约会(正如 addthisevent[ 所做的那样) =20=]).
解决方案应仅 PHP 并接受 google 日历所需的所有变量。
这里有一些代码可能会有所帮助:
Google 日历:
<?php
function generate_calendar_button($name, $description, DateTime $start, DateTime $end, $location, $mysite_url, $mysite_name) {
$url = 'http://www.google.com/calendar/event?action=TEMPLATE';
$parts = array();
$parts['text'] = urlencode($name);
$parts['details'] = urlencode($description);
$parts['dates'] = urlencode($start->format("Ymd\THis\Z")) . "/" . urlencode($end->format("Ymd\THis\Z"));
$parts['location'] = urlencode($location);
$parts['sprop'] = urlencode($mysite_url);
$full_link = $url;
foreach ($parts as $key => $value) {
$full_link .= "&" . $key . "=" . $value;
}
$full_link .= "&sprop=name:" . urlencode($mysite_name);
return '<a href="' . $full_link . '" target="_blank"><img src="http://www.google.com/calendar/images/ext/gc_button1.gif" border=0></a>';
}
print generate_calendar_button(
"Boulevard Summer Show",
"Starting Friday 15th June, the Boulevard Summer Show 2012 features new sets and musical numbers led by the legendary Betty Legs Diamond, performing alongside established favourites and some rather fetching new faces, all held together by the incomparable Miss Rory.",
new DateTime("2012-07-15 8:00 GMT"),
new DateTime("2012-07-15 10:00 GMT"),
"123 Example Lane, Exampleville",
"http://www.northernpink.co.uk/",
"Northern Pink"
);
?>
苹果 iCal:
<?php // Add a custom button after the event export options that display after the event content
$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "@yourhost.test
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
END:VCALENDAR";
//set correct content-type-header
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=calendar.ics');
echo $ical;
exit;
?>
我正在寻找一种在我的网站上显示按钮的方法,以便用户可以自动将事件添加到他们的 google 日历中,类似于 http://www.addthisevent.com/ 所做的(目前我在用着)。
到目前为止,我已经在网上查看过,但我只能通过将其添加到我的日历并从中生成代码来找到一种手动方法。但是我想用 PHP.
自动完成我不想继续的理由是让我自己控制网站上加载的所有资源。
编辑:我正在寻找一个 link,用户可以单击它,然后将打开一个新选项卡,其中打开并预填充了添加日历约会(正如 addthisevent[ 所做的那样) =20=]). 解决方案应仅 PHP 并接受 google 日历所需的所有变量。
这里有一些代码可能会有所帮助:
Google 日历:
<?php
function generate_calendar_button($name, $description, DateTime $start, DateTime $end, $location, $mysite_url, $mysite_name) {
$url = 'http://www.google.com/calendar/event?action=TEMPLATE';
$parts = array();
$parts['text'] = urlencode($name);
$parts['details'] = urlencode($description);
$parts['dates'] = urlencode($start->format("Ymd\THis\Z")) . "/" . urlencode($end->format("Ymd\THis\Z"));
$parts['location'] = urlencode($location);
$parts['sprop'] = urlencode($mysite_url);
$full_link = $url;
foreach ($parts as $key => $value) {
$full_link .= "&" . $key . "=" . $value;
}
$full_link .= "&sprop=name:" . urlencode($mysite_name);
return '<a href="' . $full_link . '" target="_blank"><img src="http://www.google.com/calendar/images/ext/gc_button1.gif" border=0></a>';
}
print generate_calendar_button(
"Boulevard Summer Show",
"Starting Friday 15th June, the Boulevard Summer Show 2012 features new sets and musical numbers led by the legendary Betty Legs Diamond, performing alongside established favourites and some rather fetching new faces, all held together by the incomparable Miss Rory.",
new DateTime("2012-07-15 8:00 GMT"),
new DateTime("2012-07-15 10:00 GMT"),
"123 Example Lane, Exampleville",
"http://www.northernpink.co.uk/",
"Northern Pink"
);
?>
苹果 iCal:
<?php // Add a custom button after the event export options that display after the event content
$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "@yourhost.test
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
END:VCALENDAR";
//set correct content-type-header
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=calendar.ics');
echo $ical;
exit;
?>