-
Notifications
You must be signed in to change notification settings - Fork 0
/
ical.php
95 lines (76 loc) · 2.89 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
// In order to keep your tasklist secure for just yourself I would suggest adding a small
// layer of security to this file. Perhaps a password. Remove the /* and */ below to activate
// a password that has to be available in the GET-parameters of the request:
/*
$iCal_password = "myUnh4ck4bl3_password";
if($_GET['pass'] != $iCal_password)
{
die("iCal is currently unavailable");
}
*/
// By using the above security to this fill, you should add the ical to your agenda using the URL:
// http://www.yourdomain.com/folder-to-wrapper/ical.php?pass=myUnh4ck4ble_password
// Login Credits
// This file should be removed if you use it yourself
// Change $wlUser and $wlPass on line 15 to your own login data
// Or create a "credits.php" file outside the github folder containing both variables
// A future release will have this option inside the Wunderlist API Wrapper, for now it's meant to be used quickly
require_once("../credits.php");
// Header
header('Content-Type: text/html; charset=utf-8');
// Require Class
require_once('api.class.php');
// Setup Wunderlist
$wunderlist = new Wunderlist($wlUser, $wlPass);
// Set iCal Date
define('DATE_ICAL', 'Ymd\THis');
$output = "BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
PRODID:-//Wunderlist2-PHP//Tasks//NL\n";
// Get all tasks and lists: we need some of this information in the ical
// we can also do $tasks = $wunderlist->getTasks(false); to have completed tasks not included in the ical
$tasks = $wunderlist->getTasks();
$lists = $wunderlist->getLists();
// Loop all tasks
foreach($tasks as $task)
{
// Only view tasks with a due date
if($task['due_date'] !== NULL)
{
// Start ical output for the parent task
$output .= "BEGIN:VEVENT
SUMMARY:".$wunderlist->lists[ $task['list_id'] ]['title']." - ".$task['title']."
UID:".$task['id']."
STATUS: CONFIRMED
DTSTART:" . date(DATE_ICAL, strtotime($task['due_date'])) . "
DTEND:" . date(DATE_ICAL, strtotime($task['due_date'])) . "
LAST-MODIFIED:" . date(DATE_ICAL, (strtotime($task['updated_at']))) . "
LOCATION: Wunderlist2-PHP
END:VEVENT\n";
// Loop all subtasks if there are any
if( count($task['subtasks']) > 0) {
foreach($task['subtasks'] as $subtask)
{
// Subtask due date is the same as the head task
// Maybe in the future subtasks will have due dates aswel
// Start ical output for the subtask
$output .= "BEGIN:VEVENT
SUMMARY:".$wunderlist->lists[ $task['list_id'] ]['title']." - ".$task['title']." - ".$subtask['title']."
UID:".$subtask['id']."
STATUS: CONFIRMED
DTSTART:" . date(DATE_ICAL, strtotime($task['due_date'])) . "
DTEND:" . date(DATE_ICAL, strtotime($task['due_date'])) . "
LAST-MODIFIED:" . date(DATE_ICAL, (strtotime($subtask['updated_at']))) . "
LOCATION: Wunderlist2-PHP
END:VEVENT\n";
}
}
}
}
// Close calendar
$output .= "END:VCALENDAR";
// Output the ical file to your screen
echo $output;
?>