Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $infoUrl = "https://hplanning2019.umons.ac.be/Telechargements/ical/Edt__Bloc_compl__MA___Sc__informatiques.ics?version=2019.0.4.0&idICal=FD9359EA644C91D7986857F73C12D3AD¶m=643d5b312e2e36325d2666683d3126663d3131303030";
- $copyInfoFile = dirname(__FILE__)."/copyInfo.ics";
- $restUrl = [];
- $restUrl[] = ["https://hplanning2019.umons.ac.be/Telechargements/ical/Edt_OptmLin.ics?version=2019.0.4.0&idICal=64759DF405E76003FE2D93D12CE75CD9¶m=643d5b312e2e36325d2666683d3126663d31", "copyOpti.ics", "OptmLin"];
- $restUrl[] = ["https://hplanning2019.umons.ac.be/Telechargements/ical/Edt_GraphOptComb.ics?version=2019.0.4.0&idICal=424A11296D9F258CA2F7CDB93028AAEE¶m=643d5b312e2e36325d2666683d3126663d31", "copyGraph.ics", "GraphOptComb"];
- // Download file from UMons
- $content = @file_get_contents($infoUrl, false, stream_context_create([
- 'http' => [
- 'timeout' => 10
- ]
- ]));
- if (!$content) {
- // Use copy file if cannot download from the server
- $content = file_get_contents($copyInfoFile);
- } else {
- // Save file
- file_put_contents($copyInfoFile, $content);
- }
- // Remove "END:VCALENDAR" from the string
- $content = substr($content, 0, strpos($content, "END:VCALENDAR"));
- echo $content;
- echo "\n";
- foreach ($restUrl as $item) {
- // Download file
- $download = @file_get_contents($item[0], false, stream_context_create([
- 'http' => [
- 'timeout' => 10
- ]
- ]));
- if (!$download) {
- // Use copy file if cannot download from the server
- $download = file_get_contents($item[1]);
- } else {
- // Save file
- file_put_contents($item[1], $download);
- }
- // Remove before first "BEGIN:VEVENT"
- $download = strstr($download, "BEGIN:VEVENT");
- $download = substr($download, 0, strpos($download, "END:VCALENDAR"));
- // print
- $split = explode("\n", $download);
- foreach($split as $line){
- if (substr($line, 0, 24) == "DESCRIPTION;LANGUAGE=fr:") {
- echo "DESCRIPTION;LANGUAGE=fr:Matière : ".$item[2]."\\n".substr($line, 24);
- } else if (substr($line, 0, 20) == "SUMMARY;LANGUAGE=fr:") {
- echo "SUMMARY;LANGUAGE=fr:".$item[2]." - ".substr($line, 20);
- } else
- echo $line."\n";
- }
- //echo $download;
- echo "\n";
- }
- echo "END:VCALENDAR";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement