LEPTON CMS 7.2.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
function.create_iCal_file.php
Go to the documentation of this file.
1<?php
2
19// include secure.php to protect this file and the whole CMS!
20if(!defined("SEC_FILE")){define("SEC_FILE",'/framework/secure.php' );}
21if (defined('LEPTON_PATH')) {
22 include LEPTON_PATH.SEC_FILE;
23} else {
24 $oneback = "../";
25 $root = $oneback;
26 $level = 1;
27 while (($level < 10) && (!file_exists($root.SEC_FILE))) {
28 $root .= $oneback;
29 $level += 1;
30 }
31 if (file_exists($root.SEC_FILE)) {
32 include $root.SEC_FILE;
33 } else {
34 trigger_error(sprintf("[ <b>%s</b> ] Can't include secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
35 }
36}
37// end include secure file
38
39
59 string $title,
60 string $location = 'Anywhere',
61 string $startdate = '2025-01-01',
62 string $starttime = '10:30:00',
63 string $enddate = '2025-01-01',
64 string $endtime = '12:00:00',
65 string $description = 'Description',
66 string $reminder = '60',
67 string $reminder_text = 'Reminder',
68 string $filename = LEPTON_PATH.MEDIA_DIRECTORY.'/event.ics'
69): int
70{
71
72 // format data
73 $startdate = str_replace('-','',$startdate);
74 $enddate = str_replace('-','',$enddate);
75 $starttime = str_replace(':','',$starttime).'00';
76 $endtime = str_replace(':','',$endtime).'00';
77
78
79 // start iCal function
80 $eol = "\r\n";
81 $sICalContent =
82 'BEGIN:VCALENDAR'.$eol.
83 'CHARSET:'.strtoupper(DEFAULT_CHARSET).$eol.
84 'VERSION:2.0'.$eol.
85 'TZNAME:UTC'.$eol.
86 'TZID:'.DEFAULT_TIMEZONE_STRING.$eol.
87 'X-LIC-LOCATION:'.DEFAULT_TIMEZONE_STRING.$eol.
88 'PRODID:LEPTON-CMS,https://lepton-cms.org, '.LANGUAGE.$eol.
89 'CALSCALE:GREGORIAN'.$eol.
90 'BEGIN:VEVENT'.$eol.
91 'CLASS:PUBLIC'.$eol.
92 'UID:'.LEPTON_URL.'_'.time().$eol.
93 'DTSTART:'.$startdate.'T'.$starttime.$eol.
94 'DTEND:'.$enddate.'T'.$endtime.$eol.
95 'LOCATION:'.$location.$eol.
96 'DTSTAMP:'.date('Ymd',time()).'T'.date('his',time()).$eol.
97 'SUMMARY:'.$title.$eol.
98 'URL;VALUE=URI:'.LEPTON_URL.$eol.
99 'DESCRIPTION:'.$description.$eol.
100 'BEGIN:VALARM'.$eol.
101 'ACTION:DISPLAY'.$eol.
102 'TRIGGER:-PT'.$reminder.'M'.$eol.
103 'DESCRIPTION:'.$reminder_text.$eol.
104 'END:VALARM'.$eol.
105 'END:VEVENT'.$eol.
106 'END:VCALENDAR';
107 $result = file_put_contents($filename,$sICalContent);
108
109 if($result === false)
110 {
111 echo(LEPTON_tools::display('Something went wrong, ics file not written!','pre','ui red message'));
112 }
113 return $result;
114}
static display(mixed $something_to_display="", string $tag="pre", string|null $css_class=null, bool|null $useVarDump=null)
create_iCal_file(string $title, string $location='Anywhere', string $startdate='2025-01-01', string $starttime='10:30:00', string $enddate='2025-01-01', string $endtime='12:00:00', string $description='Description', string $reminder='60', string $reminder_text='Reminder', string $filename=LEPTON_PATH.MEDIA_DIRECTORY.'/event.ics')