-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.php
More file actions
184 lines (143 loc) · 4.52 KB
/
Copy pathview.php
File metadata and controls
184 lines (143 loc) · 4.52 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
// Initialization
header("Content-Type: text/calendar;charset=utf-8");
//echo get_include_path() . "\n";
//echo("\n");
$path = realpath("icalendar/zapcallib.php");
//set_include_path(realpath("icalendar"));
//echo $path;
require $path ;
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
require_once("secret.php");
if(!isset($_GET["key"])) {
exit("ERROR - Missing API Key");
}
$apiKey = $_GET["key"];
$numItems = 50;
if(isset($_GET["num_items"]) and is_int(intval($_GET["num_items"]))) {
$numItems = intval($_GET["num_items"]);
}
// Create calendar
$icalobj = new ZCiCal();
//echo("IMPORTED CALENDAR");
// Track Usage
curl_setopt_array($curl, [
CURLOPT_URL => "https://in.logs.betterstack.com/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Authorization: " . $BETTERSTACK_API_TOKEN
],
CURLOPT_POSTFIELDS => json_encode(array(
"IP" => $_SERVER['REMOTE_ADDR'],
"User Agent" => $_SERVER['HTTP_USER_AGENT']
)),
]);
$response = curl_exec($curl);
$err = curl_error($curl);
//echo var_dump($response);
// Get User's ID and Workspace ID
$url = "https://api.clockify.me/api/v1/user";
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-Api-Key: $apiKey"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
if ($err) {
exit("ERROR (cURL) - " . $err);
}
if (curl_getinfo($curl)['http_code'] != 200 and curl_getinfo($curl)['http_code'] != 202) {
exit("ERROR - LOGGING");
}
$res = json_decode($response, true);
//echo var_dump($res);
if (!isset($res["defaultWorkspace"]) or !isset($res["id"])) {
exit("ERROR - Wrong Clockify response! they lied to us:(");
}
$workspaceID = $res["defaultWorkspace"];
$userID = $res["id"];
// Get projects list
$url = "https://api.clockify.me/api/v1/workspaces/$workspaceID/projects?page-size=1000";
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-Api-Key: $apiKey"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
if ($err) {
exit("ERROR (cURL) - " . $err);
}
if (curl_getinfo($curl)['http_code'] != 200) {
exit("ERROR - No Projects!");
}
$res = json_decode($response, true);
$projects = array();
foreach ($res as $project) {
$projects[$project["id"]] = $project["name"];
}
//var_dump($projects);
// Get time entries
$url = "https://api.clockify.me/api/v1/workspaces/$workspaceID/user/$userID/time-entries?page-size=$numItems&in-progress=False";
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-Api-Key: $apiKey"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
if ($err) {
exit("ERROR (cURL) - " . $err);
}
if (curl_getinfo($curl)['http_code'] != 200) {
exit("ERROR - Something weird went wrong");
}
$res = json_decode($response, true);
//echo var_dump($res);
foreach ($res as $time_entry) {
/*echo "Title: " . $projects[$time_entry["projectId"]] . "<br/>";
echo "Description: " . $time_entry["description"] . "<br/>";
echo "Start: " . $time_entry["timeInterval"]["start"] . "<br/>";
echo "End: " . $time_entry["timeInterval"]["end"] . "<br/><br/>";*/
$eventobj = new ZCiCalNode("VEVENT", $icalobj->curnode);
$eventobj->addNode(new ZCiCalDataNode("SUMMARY:" . $projects[$time_entry["projectId"]]));
$eventobj->addNode(new ZCiCalDataNode("DESCRIPTION:" . $time_entry["description"]));
$eventobj->addNode(new ZCiCalDataNode("DTSTART:" . ZCiCal::fromSqlDateTime($time_entry["timeInterval"]["start"])));
$eventobj->addNode(new ZCiCalDataNode("DTEND:" . ZCiCal::fromSqlDateTime($time_entry["timeInterval"]["end"])));
$eventobj->addNode(new ZCiCalDataNode("DTSTAMP:" . ZCiCal::fromSqlDateTime()));
$uid = date('Y-m-d-H-i-s') . random_int(111111,1000000000000) . "@clockifytoical.com";
$eventobj->addNode(new ZCiCalDataNode("UID:" . $uid));
}
// Close
curl_close($curl);
echo $icalobj->export();
?>