Dave serves us with his work on https://daveismyname.com/adding-events-to-microsoft-outlook-from-php-using-ical-bp regarding how to create a ics file form a link. Thanks to him!
I tried to ask him my question but had problems in display my code so I put it here on stack.
Could anyone be so kind and not down vote my even if it is stupid question (for everytime I try to ask something about php this happens)? I am a php newbie and trying my best to be precise! Thanks for patience!
So here my attempt with Daves code:
I use the following in my php calendar template page (WP using “Advanced Custom Fields Pro” plugin to set the data (which works just fine):
<div id="wrapper">
<?php
$rows = get_field('events');
if($rows)
{
foreach($rows as $row)
{
echo '<a class="entry-meta-area" href="ical.php?date=' . $row['date_short'] . '&subject=' . $row['event'] .'&">
<div class="left-div">
<div>
<span>' . $row['date_long'] . '</span>
</div>
</div>
<div class="right-div">
<div>
<span>' . $row['event'] .'</span>
</div>
</div>
</a>';
}
}
$date = $_GET['date'];
$subject = $_GET['subject'];
$ical = " BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "myspecificwebsite.com
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART:".$date."T100000Z
DTEND:".$date."T100000Z
SUMMARY:".$subject."
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;
?>
</div>
This creates 3 problems on loading the page:
1) Opens my calendar (Mac) on page load instead of on click the row where the data should be collected 2) My calendar gives a warning “could not read the file because no event is defined“ 3) Clicking the link leads to (404) page: …myspecificwebsite.com/calendar-template/ical.php?date=02/26/2016&subject=Annual%20Turnover (should stay on the same page, yet)