16fbb086dSAndreas Boehler<?php 26fbb086dSAndreas Boehler/** 36fbb086dSAndreas Boehler * DokuWiki Plugin DAVCal (Calendar Syntax Component) 46fbb086dSAndreas Boehler * 56fbb086dSAndreas Boehler * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 66fbb086dSAndreas Boehler * @author Andreas Böhler <dev@aboehler.at> 76fbb086dSAndreas Boehler */ 86fbb086dSAndreas Boehler 96fbb086dSAndreas Boehlerclass syntax_plugin_davcal_calendar extends DokuWiki_Syntax_Plugin { 106fbb086dSAndreas Boehler 116fbb086dSAndreas Boehler protected $hlp = null; 126fbb086dSAndreas Boehler 136fbb086dSAndreas Boehler // Load the helper plugin 14*0462f62eSGerrit Uitslag public function __construct() { 156fbb086dSAndreas Boehler $this->hlp =& plugin_load('helper', 'davcal'); 166fbb086dSAndreas Boehler } 176fbb086dSAndreas Boehler 186fbb086dSAndreas Boehler 196fbb086dSAndreas Boehler /** 206fbb086dSAndreas Boehler * What kind of syntax are we? 216fbb086dSAndreas Boehler */ 226fbb086dSAndreas Boehler function getType(){ 236fbb086dSAndreas Boehler return 'substition'; 246fbb086dSAndreas Boehler } 256fbb086dSAndreas Boehler 266fbb086dSAndreas Boehler /** 276fbb086dSAndreas Boehler * What about paragraphs? 286fbb086dSAndreas Boehler */ 296fbb086dSAndreas Boehler function getPType(){ 306fbb086dSAndreas Boehler return 'normal'; 316fbb086dSAndreas Boehler } 326fbb086dSAndreas Boehler 336fbb086dSAndreas Boehler /** 346fbb086dSAndreas Boehler * Where to sort in? 356fbb086dSAndreas Boehler */ 366fbb086dSAndreas Boehler function getSort(){ 376fbb086dSAndreas Boehler return 165; 386fbb086dSAndreas Boehler } 396fbb086dSAndreas Boehler 406fbb086dSAndreas Boehler /** 416fbb086dSAndreas Boehler * Connect pattern to lexer 426fbb086dSAndreas Boehler */ 436fbb086dSAndreas Boehler function connectTo($mode) { 446fbb086dSAndreas Boehler $this->Lexer->addSpecialPattern('\{\{davcal>[^}]*\}\}',$mode,'plugin_davcal_calendar'); 451bb22c2bSAndreas Boehler $this->Lexer->addSpecialPattern('\{\{davcalclient>[^}]*\}\}',$mode,'plugin_davcal_calendar'); 466fbb086dSAndreas Boehler } 476fbb086dSAndreas Boehler 486fbb086dSAndreas Boehler /** 496fbb086dSAndreas Boehler * Handle the match 506fbb086dSAndreas Boehler */ 519f1dab8cSAndreas Boehler function handle($match, $state, $pos, Doku_Handler $handler){ 526fbb086dSAndreas Boehler global $ID; 536fbb086dSAndreas Boehler $data = array('name' => $ID, 546fbb086dSAndreas Boehler 'description' => $this->getLang('created_by_davcal'), 556fbb086dSAndreas Boehler 'id' => array(), 566fbb086dSAndreas Boehler 'settings' => 'show', 5782a48dfbSAndreas Boehler 'view' => 'month', 5852010ac7SAndreas Boehler 'forcetimezone' => 'no', 59b0737c19SAndreas Boehler 'forcetimeformat' => 'no', 60b0737c19SAndreas Boehler 'fcoptions' => array(), 616fbb086dSAndreas Boehler ); 621bb22c2bSAndreas Boehler if(strpos($match, '{{davcalclient') === 0) 631bb22c2bSAndreas Boehler { 641bb22c2bSAndreas Boehler $options = trim(substr($match,15,-2)); 651bb22c2bSAndreas Boehler $defaultId = $this->getConf('default_client_id'); 661bb22c2bSAndreas Boehler if(isset($defaultId) && ($defaultId != '')) 671bb22c2bSAndreas Boehler { 68cd2f100dSAndreas Boehler $data['id'][$defaultId] = null; 691bb22c2bSAndreas Boehler $lastid = $defaultId; 701bb22c2bSAndreas Boehler } 711bb22c2bSAndreas Boehler } 721bb22c2bSAndreas Boehler else 731bb22c2bSAndreas Boehler { 741bb22c2bSAndreas Boehler $options = trim(substr($match,9,-2)); 756fbb086dSAndreas Boehler $lastid = $ID; 761bb22c2bSAndreas Boehler } 771bb22c2bSAndreas Boehler $options = explode(',', $options); 781bb22c2bSAndreas Boehler 796fbb086dSAndreas Boehler foreach($options as $option) 806fbb086dSAndreas Boehler { 816fbb086dSAndreas Boehler list($key, $val) = explode('=', $option); 826fbb086dSAndreas Boehler $key = strtolower(trim($key)); 836fbb086dSAndreas Boehler $val = trim($val); 846fbb086dSAndreas Boehler switch($key) 856fbb086dSAndreas Boehler { 866fbb086dSAndreas Boehler case 'id': 876fbb086dSAndreas Boehler $lastid = $val; 886fbb086dSAndreas Boehler if(!in_array($val, $data['id'])) 89cd2f100dSAndreas Boehler $data['id'][$val] = null; 906fbb086dSAndreas Boehler break; 916fbb086dSAndreas Boehler case 'color': 926fbb086dSAndreas Boehler $data['id'][$lastid] = $val; 936fbb086dSAndreas Boehler break; 946fbb086dSAndreas Boehler case 'view': 95f1215668SAndreas Boehler if(in_array($val, array('month', 'basicDay', 'basicWeek', 'agendaWeek', 'agendaDay', 'listWeek', 'listDay', 'listMonth', 'listYear'))) 966fbb086dSAndreas Boehler $data['view'] = $val; 976fbb086dSAndreas Boehler else 986fbb086dSAndreas Boehler $data['view'] = 'month'; 996fbb086dSAndreas Boehler break; 100b0737c19SAndreas Boehler case 'fcoptions': 101b0737c19SAndreas Boehler $fcoptions = explode(';', $val); 102b0737c19SAndreas Boehler foreach($fcoptions as $opt) 103b0737c19SAndreas Boehler { 104b0737c19SAndreas Boehler list($o, $v) = explode(':', $opt, 2); 105b0737c19SAndreas Boehler $data['fcoptions'][$o] = $v; 106b0737c19SAndreas Boehler } 107b0737c19SAndreas Boehler break; 10882a48dfbSAndreas Boehler case 'forcetimezone': 10982a48dfbSAndreas Boehler $tzlist = \DateTimeZone::listIdentifiers(DateTimeZone::ALL); 11082a48dfbSAndreas Boehler if(in_array($val, $tzlist) || $val === 'no') 11182a48dfbSAndreas Boehler $data['forcetimezone'] = $val; 11282a48dfbSAndreas Boehler else 11382a48dfbSAndreas Boehler msg($this->getLang('error_timezone_not_in_list'), -1); 11482a48dfbSAndreas Boehler break; 11552010ac7SAndreas Boehler case 'forcetimeformat': 11652010ac7SAndreas Boehler $tfopt = array('lang', '24h', '12h'); 11752010ac7SAndreas Boehler if(in_array($val, $tfopt) || $val === 'no') 11852010ac7SAndreas Boehler $data['forcetimeformat'] = $val; 11952010ac7SAndreas Boehler else 12052010ac7SAndreas Boehler msg($this->getLang('error_option_error'), -1); 12152010ac7SAndreas Boehler break; 1226fbb086dSAndreas Boehler default: 1236fbb086dSAndreas Boehler $data[$key] = $val; 1246fbb086dSAndreas Boehler } 1256fbb086dSAndreas Boehler } 1266fbb086dSAndreas Boehler // Handle the default case when the user didn't enter a different ID 1276fbb086dSAndreas Boehler if(empty($data['id'])) 1286fbb086dSAndreas Boehler { 129cd2f100dSAndreas Boehler $data['id'] = array($ID => null); 1306fbb086dSAndreas Boehler } 131cd2f100dSAndreas Boehler 132cd2f100dSAndreas Boehler // Fix up the colors, if no color information is given 133cd2f100dSAndreas Boehler foreach($data['id'] as $id => $color) 134cd2f100dSAndreas Boehler { 135cd2f100dSAndreas Boehler if(is_null($color)) 136cd2f100dSAndreas Boehler { 137cd2f100dSAndreas Boehler // If this is the current calendar or a WebDAV calendar, use the 138cd2f100dSAndreas Boehler // default color 139cd2f100dSAndreas Boehler if(($id === $ID) || (strpos($id, 'webdav://') === 0)) 140cd2f100dSAndreas Boehler { 141cd2f100dSAndreas Boehler $data['id'][$id] = '#3a87ad'; 142cd2f100dSAndreas Boehler } 143cd2f100dSAndreas Boehler // Otherwise, retrieve the color information from the calendar settings 144cd2f100dSAndreas Boehler else 145cd2f100dSAndreas Boehler { 146cd2f100dSAndreas Boehler $calid = $this->hlp->getCalendarIdForPage($ID); 147cd2f100dSAndreas Boehler $settings = $this->hlp->getCalendarSettings($calid); 148cd2f100dSAndreas Boehler $color = $settings['calendarcolor']; 149cd2f100dSAndreas Boehler $data['id'][$id] = $color; 150cd2f100dSAndreas Boehler } 151cd2f100dSAndreas Boehler } 152cd2f100dSAndreas Boehler } 153cd2f100dSAndreas Boehler 1546fbb086dSAndreas Boehler // Only update the calendar name/description if the ID matches the page ID. 1556fbb086dSAndreas Boehler // Otherwise, the calendar is included in another page and we don't want 1566fbb086dSAndreas Boehler // to interfere with its data. 1576fbb086dSAndreas Boehler if(in_array($ID, array_keys($data['id']))) 1586fbb086dSAndreas Boehler { 1596fbb086dSAndreas Boehler if(isset($_SERVER['REMOTE_USER']) && !is_null($_SERVER['REMOTE_USER'])) 1606fbb086dSAndreas Boehler $username = $_SERVER['REMOTE_USER']; 1616fbb086dSAndreas Boehler else 1626fbb086dSAndreas Boehler $username = uniqid('davcal-'); 1636fbb086dSAndreas Boehler $this->hlp->setCalendarNameForPage($data['name'], $data['description'], $ID, $username); 1646fbb086dSAndreas Boehler $this->hlp->setCalendarColorForPage($data['id'][$ID], $ID); 16513b16484SAndreas Boehler $this->hlp->enableCalendarForPage($ID); 1666fbb086dSAndreas Boehler } 1676fbb086dSAndreas Boehler 1686fbb086dSAndreas Boehler p_set_metadata($ID, array('plugin_davcal' => $data)); 1696fbb086dSAndreas Boehler 1706fbb086dSAndreas Boehler return $data; 1716fbb086dSAndreas Boehler } 1726fbb086dSAndreas Boehler 1736fbb086dSAndreas Boehler /** 1746fbb086dSAndreas Boehler * Create output 1756fbb086dSAndreas Boehler */ 1769f1dab8cSAndreas Boehler function render($format, Doku_Renderer $R, $data) { 1776fbb086dSAndreas Boehler if($format != 'xhtml') return false; 1786fbb086dSAndreas Boehler global $ID; 1796fbb086dSAndreas Boehler $tzlist = \DateTimeZone::listIdentifiers(DateTimeZone::ALL); 1806fbb086dSAndreas Boehler 1816fbb086dSAndreas Boehler // Render the Calendar. Timezone list is within a hidden div, 1826fbb086dSAndreas Boehler // the calendar ID is in a data-calendarid tag. 18382a48dfbSAndreas Boehler if($data['forcetimezone'] !== 'no') 18482a48dfbSAndreas Boehler $R->doc .= '<div id="fullCalendarTimezoneWarning">'.sprintf($this->getLang('this_calendar_uses_timezone'), $data['forcetimezone']).'</div>'; 1856fbb086dSAndreas Boehler $R->doc .= '<div id="fullCalendar" data-calendarpage="'.$ID.'"></div>'; 1866fbb086dSAndreas Boehler $R->doc .= '<div id="fullCalendarTimezoneList" class="fullCalendarTimezoneList" style="display:none">'; 1876fbb086dSAndreas Boehler $R->doc .= '<select id="fullCalendarTimezoneDropdown">'; 1886fbb086dSAndreas Boehler $R->doc .= '<option value="local">'.$this->getLang('local_time').'</option>'; 1896fbb086dSAndreas Boehler foreach($tzlist as $tz) 1906fbb086dSAndreas Boehler { 1916fbb086dSAndreas Boehler $R->doc .= '<option value="'.$tz.'">'.$tz.'</option>'; 1926fbb086dSAndreas Boehler } 1936fbb086dSAndreas Boehler $R->doc .= '</select></div>'; 1946fbb086dSAndreas Boehler if(($this->getConf('hide_settings') !== 1) && ($data['settings'] !== 'hide')) 1956fbb086dSAndreas Boehler { 1966fbb086dSAndreas 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>'; 1976fbb086dSAndreas Boehler } 1986fbb086dSAndreas Boehler 1996fbb086dSAndreas Boehler } 2006fbb086dSAndreas Boehler 2016fbb086dSAndreas Boehler 2026fbb086dSAndreas Boehler 2036fbb086dSAndreas Boehler} 2046fbb086dSAndreas Boehler 2056fbb086dSAndreas Boehler// vim:ts=4:sw=4:et:enc=utf-8: 206