1<?php 2/** 3 * @license http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html 4 * @author Francois Merciol <dokuplugin@merciol.fr> 5 * 6 * Plugin Schedule: manage events per wiki @groups 7 */ 8 9if (!defined ('DOKU_INC')) 10 define ('DOKU_INC', realpath (__DIR__.'/../../../').'/'); 11if (!defined ('DOKU_PLUGIN')) 12 define ('DOKU_PLUGIN', DOKU_INC.'lib/plugins/'); 13require_once(DOKU_PLUGIN.'syntax.php'); 14 15require_once (realpath (__DIR__.'/..').'/scheduleInseeCities.php'); 16 17// ============================================================ 18class syntax_plugin_schedule_display extends DokuWiki_Syntax_Plugin { 19 20 // ============================================================ 21 function getInfo() { 22 return confToHash (__DIR__.'/../INFO.txt'); 23 } 24 function getType () { return 'substition'; } 25 function getPType () { return 'block'; } 26 function getSort () { return 299; } 27 function connectTo ($mode) { 28 $this->Lexer->addEntryPattern ('<schedule[^>]*>', $mode, 'plugin_schedule_display'); 29 } 30 function postConnect () { 31 $this->Lexer->addExitPattern ('</schedule>', 'plugin_schedule_display'); 32 } 33 34 // ============================================================ 35 function handle ($match, $state, $pos, Doku_Handler $handler) { 36 switch ($state) { 37 case DOKU_LEXER_ENTER: 38 return array ($state, trim (substr ($match, 8, -1))); // "<schedule" => 8 ">" => 1 39 case DOKU_LEXER_UNMATCHED: 40 return array ($state, $match); 41 case DOKU_LEXER_EXIT: 42 return array ($state, ''); 43 } 44 return false; 45 } 46 47 // ============================================================ 48 function render ($mode, Doku_Renderer $renderer, $indata) { 49 if (empty($indata)) 50 return false; 51 if ($mode != 'xhtml') 52 return false; 53 list ($instr, $data) = $indata; 54 switch ($instr) { 55 56 case DOKU_LEXER_ENTER : 57 $mapId = "scheduleMapPOI"; 58 if (preg_match_all ('/("[^"]*")* id="(?<id>[0-9a-zA-Z_]+)" ("[^"]*")*/', strtolower ($args), $dumy) > 0) 59 for ($i = 0; $i < count ($dumy['id']); $i++) 60 $mapId = $dumy ['id'][$i]; 61 $renderer->doc .= 62 '<div class="wrap_left plugin_wrap">'.NL. 63 ' <div class="schedulePOI scheduleScaledMap">'.NL; 64 if ($this->getConf ('useMap')) { 65 if (!is_dir (realpath (__DIR__.'/../../ol3'))) 66 $renderer->doc .= '<p><a href="http://www.dokuwiki.org/plugin:ol3">ol3 plugin</a> not installed (see <a href="http://www.dokuwiki.org/plugin:schedule">doc</a>)</p>'; 67 $renderer->doc .= ' <div id="'.$mapId.'" class="scheduleMap scheduleMapDisplay"></div>'.NL; 68 } 69 break; 70 71 case DOKU_LEXER_UNMATCHED : 72 $data = trim ($data); 73 $address =""; 74 if ($this->getConf ('useMap')) 75 $renderer->doc .= '<span class="wrap_tip wrap_center wrap_centeralign">'.$this->getLang ('reactiveMap').'</span>'.NL; 76 $renderer->doc .= ' <ul style="display:none;" class="poiLatLon">'.NL; 77 78 global $scheduleInseeCities; 79 if (! empty ($data)) 80 foreach (explode ("\n", preg_replace ('%~[eE][nN][dD]~%', "\n", $data)) as $line) { 81 $line = trim (preg_replace ("/#.*$/", "", $line)); 82 if (!$line) 83 continue; 84 $line = preg_replace ("#\s+\|#", "|", $line); 85 $line = preg_replace ("#\|\s+#", "|", $line); 86 $line = trim ($line,'|'); 87 list ($insee, $lat, $lon, $addr) = explode ("|", $line); 88 // XXX vérif des formats (nombres, ...) 89 if (!$insee || !$lon) { 90 if ($insee && $lat) 91 $renderer->doc .= ' <li lat="'.$insee.'" lon="'.$lat.'">56000</li>'.NL; // XXX position par defaut 92 continue; 93 } 94 if ($insee && $lat && $lon) 95 $renderer->doc .= 96 ' <li lat="'.$lat.'" lon="'.$lon.'">'.$insee.'</li>'.NL; 97 $addrHtml = 98 ($addr ? 99 preg_replace ('%\\\\\\\\%', "<br/>", preg_replace ('%~[bB][rR]~%', "<br/>", $addr)) : 100 '<span class="wrap_round wrap_todo">'.$this->lang ('toComplet').'</span><br/>').' '. 101 // XXX all insee ??? 102 (isset ($scheduleInseeCities[$insee]) ? $scheduleInseeCities[$insee][0] : $insee).'<br/>'. 103 (($addr && $lat && $lon) ? 104 '<span style="font-size:50%; background-color:#DDD;">(Lat. : '.$lat.' Long. : '.$lon.')</span>' : 105 ''); 106 $address .= 107 '<div class="scheduleAddresse wrap_left plugin_wrap" location="('.$lat.'|'.$lon.')">'.NL. 108 ' <p onMouseOver="javascript:scheduleHighlightLocation (\'('.$lat.'|'.$lon.')\')" onMouseOut="javascript:scheduleHighlightLocation (null)">'.$addrHtml.' </p>'.NL. 109 '</div>'.NL; 110 } 111 $renderer->doc .= 112 ' </ul>'.NL. 113 ' </div>'.NL. 114 '</div>'.NL. 115 $address. 116 '<div class="wrap_clear plugin_wrap"></div>'.NL; 117 break; 118 case DOKU_LEXER_EXIT : 119 break; 120 } 121 return true; 122 } 123 124 // ============================================================ 125} 126