linea21-modules
[ class tree: linea21-modules ] [ index: linea21-modules ] [ all elements ]

Source for file ical.php

Documentation is available at ical.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage workshop
  5.  * @author Simon Georget <simon@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  */
  10.  
  11. // The script is adapted from https://gist.github.com/jakebellacera/635416
  12. // Copyright goes to his author
  13.  
  14. $summary rawurldecode($_GET['summary']);
  15. $description rawurldecode($_GET['description']);
  16. $date rawurldecode($_GET['date']);
  17. $uri rawurldecode($_GET['uri']);
  18. $filename rawurldecode($_GET['filename']).'.ics';
  19.  
  20.  
  21. // Variables used in this script:
  22. //   $summary     - text title of the event
  23. //   $date     - the starting/ending date (in seconds since unix epoch)
  24. //   $uri         - the URL of the event (add http://)
  25. //   $description - text description of the event
  26. //   $filename    - the name of this file for saving (e.g. my-event-name.ics)
  27. //
  28. // Notes:
  29. //  - the UID should be unique to the event, so in this case I'm just using
  30. //    uniqid to create a uid, but you could do whatever you'd like.
  31. //
  32. //  - iCal requires a date format of "yyyymmddThhiissZ". The "T" and "Z"
  33. //    characters are not placeholders, just plain ol' characters. The "T"
  34. //    character acts as a delimeter between the date (yyyymmdd) and the time
  35. //    (hhiiss), and the "Z" states that the date is in UTC time. Note that if
  36. //    you don't want to use UTC time, you must prepend your date-time values
  37. //    with a TZID property. See RFC 5545 section 3.3.5
  38. //
  39. //  - The Content-Disposition: attachment; header tells the browser to save/open
  40. //    the file. The filename param sets the name of the file, so you could set
  41. //    it as "my-event-name.ics" or something similar.
  42. //
  43. //  - Read up on RFC 5545, the iCalendar specification. There is a lot of helpful
  44. //    info in there, such as formatting rules. There are also many more options
  45. //    to set, including alarms, invitees, busy status, etc.
  46. //
  47. //      https://www.ietf.org/rfc/rfc5545.txt
  48.  
  49. // 1. Set the correct headers for this file
  50. header('Content-type: text/calendar; charset=utf-8');
  51. header('Content-Disposition: attachment; filename=' $filename);
  52.  
  53. // 2. Define helper functions
  54.  
  55. // Converts a unix timestamp to an ics-friendly format
  56. // NOTE: "Z" means that this timestamp is a UTC timestamp. If you need
  57. // to set a locale, remove the "\Z" and modify DTEND, DTSTAMP and DTSTART
  58. // with TZID properties (see RFC 5545 section 3.3.5 for info)
  59. //
  60. // Also note that we are using "g" instead of "H" because iCalendar's Time format
  61. // requires 24-hour time (see RFC 5545 section 3.3.12 for info).
  62. function dateToCal($timestamp{
  63.   return date('Ymd\Tgis\Z'$timestamp);
  64. }
  65.  
  66. // Escapes a string of characters
  67. function escapeString($string{
  68.   return preg_replace('/([\,;])/','\\\$1'$string);
  69. }
  70.  
  71. // 3. Echo out the ics file's contents
  72. ?>
  73. BEGIN:VCALENDAR
  74. VERSION:2.0
  75. PRODID:-//hacksw/handcal//NONSGML v1.0//EN
  76. CALSCALE:GREGORIAN
  77. BEGIN:VEVENT
  78. UID:<?php echo uniqid().PHP_EOL ?>
  79. SUMMARY:<?php echo escapeString($summary).PHP_EOL ?>
  80. DESCRIPTION:<?php echo escapeString($description).PHP_EOL ?>
  81. URL;VALUE=URI:<?php echo escapeString($uri).PHP_EOL ?>
  82. DTSTAMP:<?php echo gmdate('Ymd'?>'T<?php echo gmdate('His'?> Z<?php echo ''.PHP_EOL ?>
  83. DTSTART;VALUE=DATE:<?php echo $date.PHP_EOL ?>
  84. DTEND;VALUE=DATE:<?php echo $date.PHP_EOL ?>
  85. END:VEVENT
  86. END:VCALENDAR

Documentation generated on Thu, 20 Mar 2014 16:48:04 +0100 by phpDocumentor 1.4.1