-
Notifications
You must be signed in to change notification settings - Fork 0
/
ical.php
57 lines (57 loc) · 2.38 KB
/
ical.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Ical format of card to create Google calendar
*
* PHP version 5
*
* @category PHP
* @package Restyaboard
* @subpackage Core
* @author Restya <info@restya.com>
* @copyright 2014 Restya
* @license http://restya.com/ Restya Licence
* @link http://restya.com/
*/
require_once 'config.inc.php';
if (!empty($_GET['id']) && !empty($_GET['hash'])) {
$md5_hash = md5(SECURITYSALT . $_GET['id']);
if ($md5_hash == $_GET['hash']) {
$val_array = array(
$_GET['id']
);
$stm = $db_lnk->prepare('SELECT board.name, card.id, card.name as card_name, card.description, card.due_date FROM boards board LEFT JOIN cards card ON card.board_id = board.id WHERE card.is_archived = FALSE AND card.due_date IS NOT NULL AND board.id = ?');
$stm->execute($val_array);
$all = $stm->fetchAll(PDO::FETCH_ASSOC);
$count = count($all);
$ical = 'BEGIN:VCALENDAR' . "\r\n";
$ical.= 'VERSION:2.0' . "\r\n";
$ical.= 'PRODID:-//' . SITE_NAME . '//EN' . "\r\n";
$ical.= 'X-PUBLISHED-TTL:PT1H' . "\r\n";
$ical.= 'X-ORIGINAL-URL:http://' . $_SERVER['HTTP_HOST'] . "\r\n";
$ical.= 'CALSCALE:GREGORIAN' . "\r\n";
$ical.= 'METHOD:PUBLISH' . "\r\n";
if ($count > 0) {
$event = $board_name = '';
foreach ($all as $row) {
$board_name = $row['name'];
$event.= 'BEGIN:VEVENT' . "\r\n";
$event.= 'UID:' . $row['id'] . "\r\n";
$event.= 'DTSTART:' . date('Ymd\THis\Z', strtotime($row['due_date'])) . "\r\n";
$event.= 'DTEND:' . date('Ymd\THis\Z', strtotime($row['due_date'])) . "\r\n";
$event.= 'SUMMARY:' . $row['card_name'] . "\r\n";
$event.= 'URL:http://' . $_SERVER['HTTP_HOST'] . '/client/#/board/' . $_GET['id'] . "\r\n";
$event.= 'END:VEVENT' . "\r\n";
}
$ical.= 'X-WR-CALNAME:' . $board_name . ' (via ' . SITE_NAME . ')' . "\r\n";
$ical.= $event;
}
$ical.= 'END:VCALENDAR';
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=calendar.ics');
echo $ical;
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404);
}
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404);
}