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