1<?php 2/** 3 * Noticeboard Plugin 4 * 5 * @author Zaruba Tomas <zatomik@gmail.com> 6 */ 7 8// must be run within Dokuwiki 9if(!defined('DOKU_INC')) die(); 10 11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 12require_once(DOKU_PLUGIN.'syntax.php'); 13 14 15require_once(DOKU_PLUGIN."noticeboard/classes/Notice.php"); 16require_once(DOKU_PLUGIN."noticeboard/classes/NoticeList.php"); 17require_once(DOKU_PLUGIN."noticeboard/classes/ArrayList.php"); 18 19/** 20 * All DokuWiki plugins to extend the parser/rendering mechanism 21 * need to inherit from this class 22 */ 23class syntax_plugin_noticeboard extends DokuWiki_Syntax_Plugin { 24 25 private $noticeList; 26 27 /** 28 * return some info 29 */ 30 function getInfo() { 31 return array( 32 'author' => 'Gina HäuĂźge, Michael Klier, Esther Brunner', 33 'email' => 'dokuwiki@chimeric.de', 34 'date' => @file_get_contents(DOKU_PLUGIN.'discussion/VERSION'), 35 'name' => 'Discussion Plugin (comments component)', 36 'desc' => 'Enables discussion features', 37 'url' => 'http://wiki.splitbrain.org/plugin:discussion', 38 ); 39 } 40 41 function getType() { return 'substition'; } 42 function getPType() { return 'block'; } 43 function getSort() { return 230; } 44 45 /** 46 * Connect pattern to lexer 47 */ 48 function connectTo($mode) { 49 if ($mode == 'base') { 50 $this->Lexer->addSpecialPattern('~~NOTICEBOARD~~', $mode, 'plugin_noticeboard'); 51 } 52 } 53 54 /** 55 * Handle the match 56 */ 57 function handle($match, $state, $pos, &$handler) { 58 59 } 60 61 function render($mode, &$renderer, $status) { 62 Global $ID; 63 Global $INFO; 64 $renderer->info['cache'] = false; 65 $renderer->doc .= "<div class='noticeboard-show'>"; 66 $renderer->doc .= "<div class='noticeboard-modeButtons'>"; 67 $renderer->doc .= $this->_showModeListButton(); 68 $renderer->doc .= $this->_showModeCalendarButton(); 69 $renderer->doc .= $this->_showRSSButton(); 70 $renderer->doc .= $this->_showIcalButton(); 71 if($INFO['perm'] >= 2){ 72 $renderer->doc .= '<a href="' . wl($ID.":NewNotice", array('do' => 'edit','noticeboard_newnotice'=> 'true')) . '" class="button2" title="">'.$this->getLang('addEvent').'</a>'; 73 } 74 $renderer->doc .= "</div>"; 75 $renderer->doc .= $this->_showFilter(); 76 77 78 79 if($_SESSION['noticeboard_mode']== 'list'){ //mode list 80 $renderer->doc .= $this->_showList(); 81 }else{ 82 $renderer->doc .= $this->_showCalendar(); 83 84 } 85 86 87 $renderer->doc .= "</div>"; 88 89 return true; // do nothing -> everything is handled in action component 90 } 91 92 93 private function _showModeListButton(){ 94 Global $ID; 95 $script = script(); 96 97 $out; 98 $out .= "<form action='".$script."' method='post'> 99 <input type='hidden' name='id' value='".$ID."' /> 100 <input type='hidden' name='noticeboard_mode' value='list' /> 101 <input type='submit' class='button' name='submit' value='".$this->getLang('list')."' /></form>"; 102 return $out; 103 } 104 105 private function _showModeCalendarButton(){ 106 Global $ID; 107 $script = script(); 108 109 $out; 110 $out .= "<form action='".$script."' method='post'> 111 <input type='hidden' name='id' value='".$ID."' /> 112 <input type='hidden' name='noticeboard_mode' value='calendar' /> 113 <input type='submit' class='button' name='submit' value='".$this->getLang('calendar')."' /></form>"; 114 return $out; 115 } 116 private function _showRSSButton(){ 117 Global $ID; 118 $script = script(); 119 120 $out; 121 $out .= "<form action='".$script."' method='get'> 122 <input type='hidden' name='id' value='".$ID."' /> 123 <input type='hidden' name='noticeboard_rss_category' value='"; 124 if($_SESSION['noticeboard_list_category']){ 125 $out .= $_SESSION['noticeboard_list_category']; 126 }else{ 127 $out .= 7; 128 } 129 $out .= "' /> 130 <input type='hidden' name='parent' value='".$ID."' /> 131 <input type='submit' class='button' name='submit' value='".$this->getLang('getRSS')."' /></form>"; 132 return $out; 133 } 134 135 private function _showIcalButton(){ 136 Global $ID; 137 $script = script(); 138 139 $out; 140 $out .= "<form action='".$script."' method='get'> 141 <input type='hidden' name='id' value='".$ID."' /> 142 <input type='hidden' name='noticeboard_get_ical' value='1' /> 143 <input type='submit' class='button' name='submit' value='".$this->getLang('iCal')."' /></form>"; 144 return $out; 145 } 146 147 148 private function _showFilter(){ 149 Global $ID; 150 Global $INFO; 151 $script = script(); 152 $out; 153 $category = $_SESSION['noticeboard_list_category']; 154 $timeFilter = $_SESSION['noticeboard_show_time']; 155 $sortFilter = $_SESSION['noticeboard_sort']; 156 $sortOrder = $_SESSION['noticeboard_sort_order']; 157 158 $out .="<form method='post' action='".$script."' class='noticeboard-listForm'><p><strong>".$this->getLang('category').":</strong>"; 159 $out .= "<label for='noticeboard_show_category_all'>".$this->getLang('all')." </label> <input type='checkbox' value='8' id='noticeboard_show_category_all' name='noticeboard_show_category_all'"; 160 if($category > 7 || !$category){ 161 $category -=8; 162 $out .="checked"; 163 } 164 $out .= "/> "; 165 $out .= "<label for='noticeboard_show_category_meeting'>".$this->getLang('meeting')." </label> <input type='checkbox' value='4' id='noticeboard_show_category_meeting' name='noticeboard_show_category_meeting'"; 166 if($category > 3){ 167 $category -=4; 168 $out .="checked"; 169 } 170 $out .= "/> "; 171 $out .= "<label for='noticeboard_show_category_event'>".$this->getLang('event')." </label> <input type='checkbox' value='2' id='noticeboard_show_category_event' name='noticeboard_show_category_event'"; 172 if($category > 1){ 173 $category -=2; 174 $out .="checked"; 175 } 176 $out .= "/> "; 177 $out .= "<label for='noticeboard_show_category_event'>".$this->getLang('conference')." </label> <input type='checkbox' value='1' id='noticeboard_show_category_conference' name='noticeboard_show_category_conference'"; 178 if($category == 1){ 179 $out .="checked"; 180 } 181 $out .= "/> "; 182 $out .="</p><p><strong>".$this->getLang('time').":</strong>"; 183 $out .= "<label for='noticeboard_show_time_future'>".$this->getLang('future')." </label> <input type='radio' value='1' id='noticeboard_show_time_future' name='noticeboard_show_time'"; 184 185 if($timeFilter == 1 || !$timeFilter){ 186 $out .="checked"; 187 } 188 $out .= "/> "; 189 $out .= "<label for='noticeboard_show_time_past'>".$this->getLang('past')." </label> <input type='radio' value='2' id='noticeboard_show_time_past' name='noticeboard_show_time'"; 190 if($timeFilter == 2){ 191 $out .="checked"; 192 } 193 $out .= "/> "; 194 $out .= "<label for='noticeboard_show_time_all'>".$this->getLang('all')." </label> <input type='radio' value='3' id='noticeboard_show_time_all' name='noticeboard_show_time'"; 195 if($timeFilter == 3){ 196 $out .="checked"; 197 } 198 $out .= "/> "; 199 $out .="</p><input type='submit' class='button submit' value='".$this->getLang('filter')."' /><p><strong>".$this->getLang('sort').": </strong> "; 200 $out .= "<select name='noticeboard_sort'>"; 201 $out .= "<option value='1' "; 202 if(!$sortFilter || $sortFilter == 1){ 203 $out .="selected"; 204 } 205 $out .= ">".$this->getLang('startDate')."</option>"; 206 $out .= "<option value='3' "; 207 if( $sortFilter == 3){ 208 $out .="selected"; 209 } 210 $out .= ">".$this->getLang('name')."</option>"; 211 $out .= "<option value='4' "; 212 if( $sortFilter == '4'){ 213 214 $out .="selected"; 215 } 216 $out .= ">".$this->getLang('place')." </option>"; 217 $out .= "<option value='2' "; 218 if( $sortFilter == 2){ 219 $out .="selected"; 220 } 221 $out .= ">".$this->getLang('deadline')."</option>"; 222 $out .= "</select> "; 223 224 $out .= " <select name='noticeboard_sort_order'>"; 225 $out .= "<option value='0' "; 226 if(!$sortOrder || $sortOrder == 0){ 227 $out .="selected"; 228 } 229 $out .= ">".$this->getLang('desc')."</option>"; 230 $out .= "<option value='1' "; 231 if( $sortOrder == 1){ 232 $out .="selected"; 233 } 234 $out .= ">".$this->getLang('asc')."</option>"; 235 $out .= "</select>"; 236 $out .="</p>"; 237 $out .="<input type='hidden' name='noticeboard_list_filter' value='1'/> 238 <input type='hidden' name='id' value='".$ID."' /> 239 </form>"; 240 return $out; 241 } 242 243 private function _showList(){ 244 Global $ID; 245 Global $INFO; 246 $script = script(); 247 $out; 248 $category = $_SESSION['noticeboard_list_category']; 249 $timeFilter = $_SESSION['noticeboard_show_time']; 250 $sortFilter = $_SESSION['noticeboard_sort']; 251 $sortOrder = $_SESSION['noticeboard_sort_order']; 252 253 254 $noticeList = new helper_plugin_noticeboard_NoticeList($ID); 255 256 //set list position 257 $start = ($_SESSION['noticeboard_list_start'])?$_SESSION['noticeboard_list_start']:'0'; 258 259 260 //set category filter 261 if($_SESSION['noticeboard_list_category']){ 262 $noticeList->setCategoryFilter($_SESSION['noticeboard_list_category']); 263 }else{ 264 $noticeList->setCategoryFilter(8); 265 } 266 267 //set time filter 268 if($_SESSION['noticeboard_show_time']){ 269 $noticeList->setTimeFilter($_SESSION['noticeboard_show_time']); 270 }else{ 271 $noticeList->setTimeFilter(1); 272 } 273 274 //set sort filter 275 if($_SESSION['noticeboard_sort']){ 276 $noticeList->setSortFilter($_SESSION['noticeboard_sort']); 277 }else{ 278 $noticeList->setSortFilter(1); 279 } 280 281 //set sort order 282 if($_SESSION['noticeboard_sort_order']){ 283 $noticeList->setSortOrder($_SESSION['noticeboard_sort_order']); 284 }else{ 285 $noticeList->setSortOrder(0); 286 } 287 288 //get notice list + print 289 $noticeList; 290 $arrayList = $noticeList->getNoticeList($start,$start + $this->getConf('listSize')); 291 while(($arrayList && $arrayList->hasNext()) ){ 292 $notice = $arrayList->next(); 293 294 $out .= "<table class='noticeboard-event' cellspacing='0'><thead><tr><th colspan='2'>"; 295 $out .= '<a href="' . wl($notice->getId(), array('do' => 'show')) . '" class="" title="">'.$notice->getName().'</a>'; 296 297 if($INFO['perm'] >= 2){ 298 299 $out .= "<form action='".$script."' method='post'> 300 <input type='hidden' name='id' value='".$ID."' /> 301 <input type='hidden' name='noticeboard_delete' value='".$notice->getId()."' /> 302 <input type='submit' class='button small' name='submit' value='".$this->getLang('delete')."' /></form>"; 303 // $out .= '<a href="' . wl($ID, array('do' => 'show','noticeboard-delete' => $notice->getId())) . '" class="button small" title="">'.$this->getLang('delete').'</a>'; 304 $out .= '<a href="' . wl($notice->getId(), array('do' => 'edit')) . '" class="button small" title="">'.$this->getLang('edit').'</a>'; 305 } 306 307 $out .= "</th><th width='80' class='cat'>"; 308 $out .= $this->getLang($notice->getCategory()); 309 $out .= "</th></tr></thead><tbody><tr><td class='left'>"; 310 $out .= "<strong>".$this->getLang('startTime').":</strong></td><td colspan='2'> "; 311 if($notice->hasStartTime()){ 312 $out .= date("d.m.Y H:i",$notice->getStartTime()); 313 }else{ 314 $out .= date("d.m.Y",$notice->getStartTime()); 315 } 316 $out .= "</td></tr>"; 317 318 if($notice->getEndTime()){ 319 $out .= "<tr><td class='left'><strong>".$this->getLang('endTime').":</strong></td><td colspan='2'>"; 320 if($notice->hasEndTime()){ 321 $out .= date("d.m.Y H:i",$notice->getEndTime()); 322 }else{ 323 $out .= date("d.m.Y",$notice->getEndTime()); 324 } 325 $out .= "</td></tr>"; 326 } 327 328 if($notice->getDeadline()){ 329 $out .= "<tr><td class='left'><strong>".$this->getLang('deadline').":</strong></td><td colspan='2'>"; 330 $out .= date("d.m.Y",$notice->getDeadline()); 331 $out .= "</td></tr>"; 332 } 333 334 if($notice->getPlace()){ 335 $out .= "<tr><td class='left'><strong>".$this->getLang('place').":</strong></td><td colspan='2'>"; 336 $out .= $notice->getPlace(); 337 $out .= "</td></tr>"; 338 } 339 340 $out .= "</tbody></table>"; 341 342 343 //$out .= "Jméno: ".$notice->getName(); 344 } 345 346 //show previous button 347 if($noticeList->hasPrevious){ 348 $out .= "<form action='".$script."' method='post'> 349 <input type='hidden' name='id' value='".$ID."' /> 350 <input type='hidden' name='noticeboard_list_start' value='".($noticeList->start - $this->getConf('listSize'))."' /> 351 <input type='submit' class='button' name='submit' value='".$this->getLang('previous')."' /></form>"; 352 } 353 354 //show next button 355 if($noticeList->hasNext){ 356 $out .= "<form action='".$script."' method='post'> 357 <input type='hidden' name='id' value='".$ID."' /> 358 <input type='hidden' name='noticeboard_list_start' value='".$noticeList->end."' /> 359 <input type='submit' class='button' name='submit' value='".$this->getLang('next')."' /></form>"; 360 } 361 return $out; 362 } 363 364 365 public function _showCalendar(){ 366 global $ID; 367 $script = script(); 368 $calendar_ns = ($data[0]) ? $data[0] : $ID; 369 $langDays = $this->getLang('days'); 370 $langMonth = $this->getLang('month'); 371 $curDate = getdate(time()); 372 $showMonth = (is_numeric($_SESSION['noticeboard_month'])) ? $_SESSION['noticeboard_month'] : $curDate['mon']; 373 $showYear = (is_numeric($_SESSION['noticeboard_year'])) ? $_SESSION['noticeboard_year'] : $curDate['year']; 374 $gTimestamp = mktime(0,0,0,$showMonth,1,$showYear); 375 $numDays = date('t',$gTimestamp); 376 $viewDate = getdate($gTimestamp); 377 $today = ($viewDate['mon'] == $curDate['mon'] && 378 $viewDate['year'] == $curDate['year']) ? 379 $curDate['mday'] : null; 380 $monthStart = ($viewDate['wday'] == 0) ? 7 : $viewDate['wday']; 381 $monthStart = ($monthStart -1) %7; 382 $prevMonth = ($showMonth-1 > 0) ? ($showMonth-1) : 12; 383 $nextMonth = ($showMonth+1 < 13) ? ($showMonth+1) : 1; 384 $out; 385 386 switch(true) { 387 case($prevMonth == 12): 388 $prevYear = ($showYear-1); 389 $nextYear = $showYear; 390 break; 391 case($nextMonth == 1): 392 $nextYear = ($showYear+1); 393 $prevYear = $showYear; 394 break; 395 default: 396 $prevYear = $showYear; 397 $nextYear = $showYear; 398 break; 399 } 400 $out .= "<table border='0' class='noticeboard_calendar_header'> 401 <tr> 402 <th width='33%' class='left'> 403 <form action='".$script."' method='post' class='prevnext'> 404 <input type='hidden' name='id' value='".$ID."' /> 405 <input type='hidden' name='noticeboard_year' value='".$prevYear."' /> 406 <input type='hidden' name='noticeboard_month' value='".$prevMonth."' /> 407 <input type='submit' class='button button-left' name='submit' value='".$this->getLang('previous')."' /> 408 </form> 409 </th> 410 <th width='33%'>".$langMonth[$viewDate['mon']]." ".$showYear."<br /></th> 411 412 <th width='33%' class='right'> 413 <form action='".$script."' method='post' class='prevnext'> 414 <input type='hidden' name='id' value='".$ID."' /> 415 <input type='hidden' name='noticeboard_year' value='".$nextYear."' /> 416 <input type='hidden' name='noticeboard_month' value='".$nextMonth."' /> 417 <input type='submit' class='button' name='submit' value='".$this->getLang('next')."' /> 418 </form> 419 </th> 420 </tr></table>"; 421 422 // week days 423 $out .= "<table class='noticeboard_calendar' cellspacing='0'><tr>"; 424 425 foreach($langDays as $day) { 426 $out .= "<th>".$day."</th>"; 427 } 428 $out .= "</tr>\n"; 429 430 // create calendar-body 431 for($i=1;$i<=$numDays;$i++) { 432 $day = $i; 433 434 // close row at end of week 435 if($wd == 7) $out .= "</tr>"; 436 // set weekday 437 if(!isset($wd) or $wd == 7) { $wd = 0; } 438 // start new row when new week starts 439 if($wd == 0) $out .= "<tr>"; 440 441 // create blank fields up to the first day of the month 442 if(!$firstWeek) { 443 while($wd < $monthStart) { 444 $out .= "<td class='blank'> </td>"; 445 $wd++; 446 } 447 // ok - first week is printet 448 $firstWeek = true; 449 } 450 451 452 $time = mktime(0,0,0,$viewDate['mon'],$day,$showYear); 453 // check for today 454 if($today == $day) { 455 $out .= "<td class='today' valign='top'><span class='day-number'>".$day."</span>"; 456 $out .= $this->_getDayEvent($time); 457 $out .= "</td>"; 458 } else { 459 $out .= "<td width='14%' valign='top'><span class='day-number'>".$day."</span>"; 460 $out .= $this->_getDayEvent($time); 461 $out .= "</td>"; 462 } 463 464 // fill remaining days with blanks 465 if($i == $numDays && $wd < 7) { 466 while($wd<6) { 467 $out .= '<td class="blank"> </td>'; 468 $wd++; 469 } 470 $out .= '</tr>'; 471 } 472 473 //weekdays 474 $wd++; 475 } 476 477 $out .="</table>"; 478 479 $out .= '<form action="'.script().'" method="post">'; 480 $out .= '<label>'.$this->getLang('year').':</label> '; 481 $out .= ' <select id="year" name="noticeboard_year">'; 482 483 $year_start = ($showYear != $curDate['year']) ? $showYear - 10 : $curDate['year'] - 5; 484 $year_end = $showYear + 10; 485 486 for($i=$year_start;$i<=$year_end;$i++) { 487 if($i == $showYear || $i == $curDate['year']) { 488 $out .= '<option value="'.$i.'" selected="selected">'.$i.'</option>'; 489 } else { 490 $out .= '<option value="'.$i.'">'.$i.'</option>'; 491 } 492 } 493 494 $out .= '</select>'; 495 $out .= ' <label for="noticeboard_month">'.$this->getLang('mon').': </label>'; 496 $out .= ' <select id="noticeboard_month" name="noticeboard_month">'; 497 498 for($i=1;$i<=12;$i++) { 499 if($i == $showMonth) { 500 $out .= '<option value="'.$i.'" selected="selected">'.$langMonth[$i].'</option>' . DOKU_LF; 501 } else { 502 $out .= '<option value="'.$i.'">'.$langMonth[$i].'</option>'; 503 } 504 } 505 506 $out .= '</select>'; 507 $out .= '<input type="hidden" name="id" value="'.$ID.'" />'; 508 $out .= ' <input type="submit" class="button" value="'.$this->getLang('select').'" />' . DOKU_LF; 509 $out .= '</form>'; 510 511 return $out; 512 } 513 514 private function _getDayEvent($time){ 515 Global $ID; 516 $noticeList = new helper_plugin_noticeboard_NoticeList($ID); 517 //set category filter 518 if($_SESSION['noticeboard_list_category']){ 519 $noticeList->setCategoryFilter($_SESSION['noticeboard_list_category']); 520 }else{ 521 $noticeList->setCategoryFilter(8); 522 } 523 524 //set time filter 525 if($_SESSION['noticeboard_show_time']){ 526 $noticeList->setTimeFilter($_SESSION['noticeboard_show_time']); 527 }else{ 528 $noticeList->setTimeFilter(1); 529 } 530 531 //set sort filter 532 if($_SESSION['noticeboard_sort']){ 533 $noticeList->setSortFilter($_SESSION['noticeboard_sort']); 534 }else{ 535 $noticeList->setSortFilter(1); 536 } 537 538 //set sort order 539 if($_SESSION['noticeboard_sort_order']){ 540 $noticeList->setSortOrder($_SESSION['noticeboard_sort_order']); 541 }else{ 542 $noticeList->setSortOrder(0); 543 } 544 545 $out .="<ul>"; 546 $arrayList = $noticeList->getNoticeAtDay($time); 547 while(($arrayList && $arrayList->hasNext()) ){ 548 $notice = $arrayList->next(); 549 550 551 $out .= '<li><a href="' . wl($notice->getId(), array('do' => 'show')) . '" class="" title="">'.$notice->getName().$notice->hasStartTime().'</a> '; 552 /*if($notice->hasStartTime()){ 553 $out .= date("H:i",$notice->getStartTime()); 554 }*/ 555 $out .= '</li>'; 556 557 558 559 } 560 $out .="</ul>"; 561 562 return $out; 563 } 564 565 566} 567// vim:ts=4:sw=4:et:enc=utf-8: 568