starting to move code server side

This commit is contained in:
Simon Marcellin 2024-03-18 16:37:50 +01:00
parent 58b3bfa487
commit e4ca4b5e3d
1 changed files with 45 additions and 43 deletions

88
ics.php
View File

@ -11,6 +11,51 @@
header('HTTP/1.0 401 Unauthorized'); header('HTTP/1.0 401 Unauthorized');
die('<p>Access denied.</p></body></html>'); die('<p>Access denied.</p></body></html>');
} }
/*function ics2json($input)
{
$id = 0;
$root = array();
$curr = root;
input.split("\r\n").forEach(l =>
{
var key = l.split(":")[0].split(";")[0];
var val = l.split(":")[1];
if (key == "BEGIN")
{
if (curr[val])
{
val += "_" + (id++);
}
curr[val] = {
parent: curr
};
curr = curr[val];
}
else if (key == "END")
{
var parent = curr.parent;
delete curr.parent;
curr = parent;
}
else
{
curr[key] = key.startsWith("DT") ? dt(val) : val;
}
});
root.VCALENDAR.VEVENTS = [];
Object.keys(root.VCALENDAR)
.filter(k => (k == "VEVENT" || k.startsWith("VEVENT_")))
.forEach(k =>
{
root.VCALENDAR.VEVENTS.push(root.VCALENDAR[k]);
delete root.VCALENDAR[k];
});
return root.VCALENDAR;
}*/
// Get ics file // Get ics file
$curl = curl_init(); $curl = curl_init();
@ -43,50 +88,7 @@
<!-- old --> <!-- old -->
<div id="content">Récupération du calendrier...</div> <div id="content">Récupération du calendrier...</div>
<script type="text/javascript"> <script type="text/javascript">
function ics2json(input)
{
var id = 0;
var root = {};
var curr = root;
input.split("\r\n").forEach(l =>
{
var key = l.split(":")[0].split(";")[0];
var val = l.split(":")[1];
if (key == "BEGIN")
{
if (curr[val])
{
val += "_" + (id++);
}
curr[val] = {
parent: curr
};
curr = curr[val];
}
else if (key == "END")
{
var parent = curr.parent;
delete curr.parent;
curr = parent;
}
else
{
curr[key] = key.startsWith("DT") ? dt(val) : val;
}
});
root.VCALENDAR.VEVENTS = [];
Object.keys(root.VCALENDAR)
.filter(k => (k == "VEVENT" || k.startsWith("VEVENT_")))
.forEach(k =>
{
root.VCALENDAR.VEVENTS.push(root.VCALENDAR[k]);
delete root.VCALENDAR[k];
});
return root.VCALENDAR;
}
function dt(s) function dt(s)
{ {