1*6fbb086dSAndreas Boehler<?php 2*6fbb086dSAndreas Boehler/** 3*6fbb086dSAndreas Boehler * DokuWiki Plugin DAVCal (Calendar Syntax Component) 4*6fbb086dSAndreas Boehler * 5*6fbb086dSAndreas Boehler * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6*6fbb086dSAndreas Boehler * @author Andreas Böhler <dev@aboehler.at> 7*6fbb086dSAndreas Boehler */ 8*6fbb086dSAndreas Boehler 9*6fbb086dSAndreas Boehler// must be run within Dokuwiki 10*6fbb086dSAndreas Boehlerif(!defined('DOKU_INC')) die(); 11*6fbb086dSAndreas Boehler 12*6fbb086dSAndreas Boehlerif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13*6fbb086dSAndreas Boehlerrequire_once(DOKU_PLUGIN.'syntax.php'); 14*6fbb086dSAndreas Boehler 15*6fbb086dSAndreas Boehlerclass syntax_plugin_davcal_calendar extends DokuWiki_Syntax_Plugin { 16*6fbb086dSAndreas Boehler 17*6fbb086dSAndreas Boehler protected $hlp = null; 18*6fbb086dSAndreas Boehler 19*6fbb086dSAndreas Boehler // Load the helper plugin 20*6fbb086dSAndreas Boehler public function syntax_plugin_davcal_calendar() { 21*6fbb086dSAndreas Boehler $this->hlp =& plugin_load('helper', 'davcal'); 22*6fbb086dSAndreas Boehler } 23*6fbb086dSAndreas Boehler 24*6fbb086dSAndreas Boehler 25*6fbb086dSAndreas Boehler /** 26*6fbb086dSAndreas Boehler * What kind of syntax are we? 27*6fbb086dSAndreas Boehler */ 28*6fbb086dSAndreas Boehler function getType(){ 29*6fbb086dSAndreas Boehler return 'substition'; 30*6fbb086dSAndreas Boehler } 31*6fbb086dSAndreas Boehler 32*6fbb086dSAndreas Boehler /** 33*6fbb086dSAndreas Boehler * What about paragraphs? 34*6fbb086dSAndreas Boehler */ 35*6fbb086dSAndreas Boehler function getPType(){ 36*6fbb086dSAndreas Boehler return 'normal'; 37*6fbb086dSAndreas Boehler } 38*6fbb086dSAndreas Boehler 39*6fbb086dSAndreas Boehler /** 40*6fbb086dSAndreas Boehler * Where to sort in? 41*6fbb086dSAndreas Boehler */ 42*6fbb086dSAndreas Boehler function getSort(){ 43*6fbb086dSAndreas Boehler return 165; 44*6fbb086dSAndreas Boehler } 45*6fbb086dSAndreas Boehler 46*6fbb086dSAndreas Boehler /** 47*6fbb086dSAndreas Boehler * Connect pattern to lexer 48*6fbb086dSAndreas Boehler */ 49*6fbb086dSAndreas Boehler function connectTo($mode) { 50*6fbb086dSAndreas Boehler $this->Lexer->addSpecialPattern('\{\{davcal>[^}]*\}\}',$mode,'plugin_davcal_calendar'); 51*6fbb086dSAndreas Boehler } 52*6fbb086dSAndreas Boehler 53*6fbb086dSAndreas Boehler /** 54*6fbb086dSAndreas Boehler * Handle the match 55*6fbb086dSAndreas Boehler */ 56*6fbb086dSAndreas Boehler function handle($match, $state, $pos, &$handler){ 57*6fbb086dSAndreas Boehler global $ID; 58*6fbb086dSAndreas Boehler $options = trim(substr($match,9,-2)); 59*6fbb086dSAndreas Boehler $options = explode(',', $options); 60*6fbb086dSAndreas Boehler $data = array('name' => $ID, 61*6fbb086dSAndreas Boehler 'description' => $this->getLang('created_by_davcal'), 62*6fbb086dSAndreas Boehler 'id' => array(), 63*6fbb086dSAndreas Boehler 'settings' => 'show', 64*6fbb086dSAndreas Boehler 'view' => 'month' 65*6fbb086dSAndreas Boehler ); 66*6fbb086dSAndreas Boehler $lastid = $ID; 67*6fbb086dSAndreas Boehler foreach($options as $option) 68*6fbb086dSAndreas Boehler { 69*6fbb086dSAndreas Boehler list($key, $val) = explode('=', $option); 70*6fbb086dSAndreas Boehler $key = strtolower(trim($key)); 71*6fbb086dSAndreas Boehler $val = trim($val); 72*6fbb086dSAndreas Boehler switch($key) 73*6fbb086dSAndreas Boehler { 74*6fbb086dSAndreas Boehler case 'id': 75*6fbb086dSAndreas Boehler $lastid = $val; 76*6fbb086dSAndreas Boehler if(!in_array($val, $data['id'])) 77*6fbb086dSAndreas Boehler $data['id'][$val] = '#3a87ad'; 78*6fbb086dSAndreas Boehler break; 79*6fbb086dSAndreas Boehler case 'color': 80*6fbb086dSAndreas Boehler $data['id'][$lastid] = $val; 81*6fbb086dSAndreas Boehler break; 82*6fbb086dSAndreas Boehler case 'view': 83*6fbb086dSAndreas Boehler if(in_array($val, array('month', 'basicDay', 'basicWeek', 'agendaWeek', 'agendaDay'))) 84*6fbb086dSAndreas Boehler $data['view'] = $val; 85*6fbb086dSAndreas Boehler else 86*6fbb086dSAndreas Boehler $data['view'] = 'month'; 87*6fbb086dSAndreas Boehler break; 88*6fbb086dSAndreas Boehler default: 89*6fbb086dSAndreas Boehler $data[$key] = $val; 90*6fbb086dSAndreas Boehler } 91*6fbb086dSAndreas Boehler } 92*6fbb086dSAndreas Boehler // Handle the default case when the user didn't enter a different ID 93*6fbb086dSAndreas Boehler if(empty($data['id'])) 94*6fbb086dSAndreas Boehler { 95*6fbb086dSAndreas Boehler $data['id'] = array($ID => '#3a87ad'); 96*6fbb086dSAndreas Boehler } 97*6fbb086dSAndreas Boehler // Only update the calendar name/description if the ID matches the page ID. 98*6fbb086dSAndreas Boehler // Otherwise, the calendar is included in another page and we don't want 99*6fbb086dSAndreas Boehler // to interfere with its data. 100*6fbb086dSAndreas Boehler if(in_array($ID, array_keys($data['id']))) 101*6fbb086dSAndreas Boehler { 102*6fbb086dSAndreas Boehler if(isset($_SERVER['REMOTE_USER']) && !is_null($_SERVER['REMOTE_USER'])) 103*6fbb086dSAndreas Boehler $username = $_SERVER['REMOTE_USER']; 104*6fbb086dSAndreas Boehler else 105*6fbb086dSAndreas Boehler $username = uniqid('davcal-'); 106*6fbb086dSAndreas Boehler $this->hlp->setCalendarNameForPage($data['name'], $data['description'], $ID, $username); 107*6fbb086dSAndreas Boehler $this->hlp->setCalendarColorForPage($data['id'][$ID], $ID); 108*6fbb086dSAndreas Boehler } 109*6fbb086dSAndreas Boehler 110*6fbb086dSAndreas Boehler p_set_metadata($ID, array('plugin_davcal' => $data)); 111*6fbb086dSAndreas Boehler 112*6fbb086dSAndreas Boehler return $data; 113*6fbb086dSAndreas Boehler } 114*6fbb086dSAndreas Boehler 115*6fbb086dSAndreas Boehler /** 116*6fbb086dSAndreas Boehler * Create output 117*6fbb086dSAndreas Boehler */ 118*6fbb086dSAndreas Boehler function render($format, &$R, $data) { 119*6fbb086dSAndreas Boehler if($format != 'xhtml') return false; 120*6fbb086dSAndreas Boehler global $ID; 121*6fbb086dSAndreas Boehler $tzlist = \DateTimeZone::listIdentifiers(DateTimeZone::ALL); 122*6fbb086dSAndreas Boehler 123*6fbb086dSAndreas Boehler // Render the Calendar. Timezone list is within a hidden div, 124*6fbb086dSAndreas Boehler // the calendar ID is in a data-calendarid tag. 125*6fbb086dSAndreas Boehler $R->doc .= '<div id="fullCalendar" data-calendarpage="'.$ID.'"></div>'; 126*6fbb086dSAndreas Boehler $R->doc .= '<div id="fullCalendarTimezoneList" class="fullCalendarTimezoneList" style="display:none">'; 127*6fbb086dSAndreas Boehler $R->doc .= '<select id="fullCalendarTimezoneDropdown">'; 128*6fbb086dSAndreas Boehler $R->doc .= '<option value="local">'.$this->getLang('local_time').'</option>'; 129*6fbb086dSAndreas Boehler foreach($tzlist as $tz) 130*6fbb086dSAndreas Boehler { 131*6fbb086dSAndreas Boehler $R->doc .= '<option value="'.$tz.'">'.$tz.'</option>'; 132*6fbb086dSAndreas Boehler } 133*6fbb086dSAndreas Boehler $R->doc .= '</select></div>'; 134*6fbb086dSAndreas Boehler if(($this->getConf('hide_settings') !== 1) && ($data['settings'] !== 'hide')) 135*6fbb086dSAndreas Boehler { 136*6fbb086dSAndreas Boehler $R->doc .= '<div class="fullCalendarSettings"><a href="#" class="fullCalendarSettings"><img src="'.DOKU_URL.'lib/plugins/davcal/images/settings.png'.'">'.$this->getLang('settings').'</a></div>'; 137*6fbb086dSAndreas Boehler } 138*6fbb086dSAndreas Boehler 139*6fbb086dSAndreas Boehler } 140*6fbb086dSAndreas Boehler 141*6fbb086dSAndreas Boehler 142*6fbb086dSAndreas Boehler 143*6fbb086dSAndreas Boehler} 144*6fbb086dSAndreas Boehler 145*6fbb086dSAndreas Boehler// vim:ts=4:sw=4:et:enc=utf-8: 146