2015-10-28 53 views
1

我正在寻找一种方法在我的网站上显示一个按钮,以便用户可以自动将事件添加到他们的Google日历中,类似于http://www.addthisevent.com/(目前我正在使用的功能)。为网站添加gCal按钮

到目前为止,我在网上看过,但我只能找到一个手动的方式做到这一点,将它添加到我的日历并从中生成代码。不过,我想用PHP自动执行此操作。

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

编辑:我正在寻找一个链接,用户可以点击和一个新的选项卡将打开与添加日历约会打开并预先填充(如由addthisevent完成)。 该解决方案应该仅适用于PHP,并接受Google日历所需的所有变量。

回答

1

下面是一些代码也许可以帮助:

谷歌日历:

<?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; 

?> 
+0

谢谢,我会尝试当我得到一分钟 –

+0

它的工作?我认为这都是工作:) –

+0

请让我知道它! –