. * * @license https://www.gnu.org/licenses/gpl-2.0.html GPL2 * @author Tim Ruffing * @author Robert Rackl * @author Elan Ruusamäe * @author Jannes Drost-Tenfelde * */ // We require at least PHP 5.5. if (PHP_VERSION_ID < 50500) return; // must be run within Dokuwiki if (!defined('DOKU_INC')) die(); require_once DOKU_INC . 'inc/parser/renderer.php'; require_once __DIR__ . '/vendor/autoload.php'; // This is a minimal renderer plugin. It ignores everything except // invocations of our syntax plugin component. These invocations are // handled to output VEVENTs. class renderer_plugin_icalevents extends Doku_Renderer { public $info = array( // no caching, because the cache does not honor the UID parameter 'cache' => false, // no table of contents 'toc' => false ); private $eventId = false; function getFormat() { return 'icalevents'; } function plugin($name, $data, $state = '', $match = '') { // Filter syntax plugins that are not our own syntax plugin, // and stop processing if we have exported an event already. // This is necessary to avoid duplicate VEVENTs in the output, // which arise when displaying the same calendar multiple times on the same page. if ($name == 'icalevents' && $this->eventId === false) { return parent::plugin($name, $data, $state, $match); } } function document_start() { $this->doc = "BEGIN:VCALENDAR\r\n"; $this->doc .= "PRODID: -//DokuWiki//NONSGML Plugin iCalEvents//EN" . "\r\n"; $this->doc .= "VERSION:2.0\r\n"; } function document_end() { global $ID; if ($this->eventId === false) { http_status(404); echo "Error: UID not found"; exit; } $filename = SafeFN::encode(strtr($this->eventId, '/:', '--')) . '.ics'; $headers = array( 'Content-Type' => 'text/calendar', 'Content-Disposition' => 'attachment; filename=' . $filename ); p_set_metadata($ID, array('format' => array('icalevents' => $headers))); $this->doc .= "END:VCALENDAR\r\n"; } function setEventId($eventId) { $this->eventId = $eventId; } function reset() { $this->eventId = false; } // Instantiating the class several times is not necessary, // because we have implemented reset(); function isSingleton() { return true; } }