-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp2ics.php
More file actions
96 lines (84 loc) · 2.3 KB
/
Copy pathphp2ics.php
File metadata and controls
96 lines (84 loc) · 2.3 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
<?php
class php2ics
{
private static string $ics = "";
public function __construct(string $organisation, string $product)
{
$organisation = htmlspecialchars($organisation);
$product = htmlspecialchars($product);
$this->Init($organisation,$product);
}
//fonction d'initialisation de l'ICS
private function Init(string $organisation, ?string $product): void
{
$organisation = htmlspecialchars($organisation);
if(isset($product)) {
$product = htmlspecialchars($product);
} else {
$product = "none";
}
$this::$ics .= "BEGIN:VCALENDAR\n";
$this::$ics .= "VERSION:2.0\n";
$this::$ics .= "PRODID:-//".$organisation."//NONSGML ".$product."\n";
$this::$ics .= "CALSCALE:GREGORIAN\n";
$this::$ics .= "METHOD:PUBLISH\n";
}
//fonction de création d'évenement
public function AddEvent(
string $title,
?string $description,
int $begin_date,
int $end_date,
?string $location,
?string $url
): void
{
$title = htmlspecialchars($title);
$begin_date = htmlspecialchars($begin_date);
$end_date = htmlspecialchars($end_date);
$this::$ics .= "BEGIN:VEVENT\n";
$this::$ics .= "SUMMARY:".$title."\n";
$this::$ics .= "DTSTART:".date('Ymd',$begin_date)."T".date('His',$begin_date)."\n";
$this::$ics .= "DTEND:".date('Ymd',$end_date)."T".date('His',$end_date)."\n";
if(isset($location)) {
$location = htmlspecialchars($location);
$this::$ics .= "LOCATION:".$location."\n";
}
if(isset($description)) {
$description = htmlspecialchars($description);
$this::$ics .= "DESCRIPTION:".$description."\n";
}
if(isset($url)) {
$url = htmlspecialchars($url);
$this::$ics .= "URL:".$url."\n";
}
$this::$ics .= "END:VEVENT\n";
}
//fonction de fin d'ICS
public function End(): void
{
$this::$ics .= "END:VCALENDAR";
}
//fonction qui permet de récupérer le code ICS
public function GetICS(): string
{
$getICS = $this::$ics;
return $getICS;
}
//fonction qui permet de télécharger le fichier ICS
public function DownloadICS(?string $fichier): void
{
if(!isset($fichier)) {
$fichier = 'calend';
} else {
$fichier = htmlspecialchars($fichier);
}
$fichier .= ".ics";
header('Content-Type: text/ics');
header('Content-Transfer-Encoding: Binary');
header('Content-Disposition:attachment; filename='.$fichier);
echo $this::$ics;
exit;
}
}
?>