首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >添加到网站的gCal按钮

添加到网站的gCal按钮
EN

Stack Overflow用户
提问于 2015-10-28 19:49:29
回答 1查看 107关注 0票数 1

我正在寻找一种方法,使按钮出现在我的网站上,以便用户可以自动添加事件到他们的谷歌日历,类似于什么是由http://www.addthisevent.com/做的(目前我正在使用)。

到目前为止,我已经在网上查看过了,但是我只能通过将它添加到我的日历中并从中生成代码来找到一种手动的方法。不过,我想用PHP自动完成它。

我不想继续下去的理由是让自己控制网站上加载的所有资源。

编辑:我正在寻找一个链接,用户可以点击和一个新的选项卡将打开添加日历约会打开和预先填充(就像add事件所做的那样)。解决方案应该是PHP,并且接受google日历所需的所有变量。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-29 00:47:15

下面的一些代码可能会有所帮助:

谷歌日历:

代码语言:javascript
复制
<?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:

代码语言:javascript
复制
<?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;

?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33400326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档