Created
March 30, 2020 22:43
-
-
Save henno/c56e89b79cf1f19860d4c9581605986a to your computer and use it in GitHub Desktop.
tahvel.edu.ee to Apple and Google calendar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Get current timestamp | |
| $now = date("Ymd\THis"); | |
| // Retrieve data from tahvel.edu.ee | |
| $data = file_get_contents("https://tahvel.edu.ee/hois_back/timetableevents/timetableByTeacher/15/calendar?from=2019-09-02T00:00:00Z&lang=et&teachers=$_GET[teacher]"); | |
| // Convert JSON to PHP array | |
| $data = (array)json_decode($data); | |
| // Create a shortcut to $data['content'] | |
| $content = $data['content']; | |
| // Add DTSTAMP property (not really needed, just makes the validator happy) | |
| $content = str_replace("END:VEVENT","DTSTAMP;X-VOBJ-FLOATINGTIME-ALLOWED=TRUE:{$now}\nEND:VEVENT",$content); | |
| // Google Calendar works even without this and validator does not catch that but Apple Calendar breaks | |
| $content = str_replace("VERSION: 2.0","VERSION:2.0",$content); | |
| // Validator complains that lines are not delimited by CRLF sequence | |
| $content = preg_replace('/[\n\r]+/', "\r\n", $content); | |
| // Validator complains that invalid MIME type detected, should be 'text/calendar' | |
| header('Content-Type: text/calendar;charset=UTF-8'); | |
| // Output content | |
| echo $content; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment