1<?php 2/** 3 * DokuWiki Plugin multiselect (Syntax Component) 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author lisps 7 */ 8 9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once(DOKU_PLUGIN.'syntax.php'); 12 13/* 14 * All DokuWiki plugins to extend the parser/rendering mechanism 15 * need to inherit from this class 16 */ 17class syntax_plugin_multiselect extends DokuWiki_Syntax_Plugin { 18 19 private $_itemPos = array(); 20 function incItemPos() { 21 global $ID; 22 if(array_key_exists($ID,$this->_itemPos)) { 23 return $this->_itemPos[$ID]++; 24 } else { 25 $this->_itemPos[$ID] = 1; 26 return 0; 27 } 28 } 29 function getItemPos(){ 30 global $ID; 31 if(array_key_exists($ID,$this->_itemPos)) { 32 $this->_itemPos[$ID]; 33 } else { 34 return 0; 35 } 36 } 37 /* 38 * What kind of syntax are we? 39 */ 40 function getType() { 41 return 'substition'; 42 } 43 44 /* 45 * Where to sort in? 46 */ 47 function getSort() { 48 return 155; 49 } 50 51 /* 52 * Paragraph Type 53 */ 54 function getPType() { 55 return 'normal'; 56 } 57 58 /* 59 * Connect pattern to lexer 60 */ 61 function connectTo($mode) { 62 $this->Lexer->addSpecialPattern("<multiselect[^>]*>",$mode,'plugin_multiselect'); 63 } 64 65 /* 66 * Handle the matches 67 */ 68 function handle($match, $state, $pos, Doku_Handler $handler) { 69 global $ID; 70 71 //extract payload 72 $match=trim($match); 73 $match=trim(substr($match,13,strlen($match)-13-1)); 74 //$opts["smileys"]=explode(" ",$match); 75 $ret = preg_match_all('/[\w\[\]\(\)\{\}\|\?\+\-\*\^\$\\\.:!\/;,+#~&%]+|"[\w\[\]\(\)\{\}\|\?\+\-\*\^\$\\\.:!\/;,+#~&%\s]+"/u',$match,$matches); 76 77 $smileys=str_replace('"','',$matches[0]); 78 $itemPos=$this->incItemPos(); 79 $page=$ID; 80 81 return array( 82 $smileys, 83 $itemPos, 84 $page 85 ); 86 } 87 88 function iswriter() { 89 global $conf; 90 global $INFO; 91 92 return($conf['useacl'] && $INFO['perm'] > AUTH_READ); 93 } 94 /* 95 * Create output 96 */ 97 function render($mode, Doku_Renderer $renderer, $opt) { 98 global $INFO; 99 100 list($smileys, 101 $itemPos, 102 $page) = $opt; 103 //dbg($opt); 104 //dbg(1); 105 if($mode == 'metadata') { 106 $renderer->smiley(reset($smileys)); 107 } else if ($mode == 'xhtml') { 108 //$renderer->nocache(); 109 $Hajax = $this->loadHelper('ajaxedit'); 110 111 if(!reset($smileys)) { 112 $renderer->doc .= 'empty'; 113 return true; 114 } 115 //insert selector if writable 116 if ($Hajax && $page == $INFO['id']) { 117 $htmlid = hsc($page).'_'.$itemPos; 118 119 $renderer->cdata("\n"); 120 $renderer->doc .= '<span id="multiselect_'.$htmlid.'" class="multiselector" style="display:none" data-plugin-multiselect-idx="'.$itemPos.'">'; 121 122 //insert all other smileys clickable 123 $count=0; 124 foreach($smileys as $smiley) { 125 $renderer->cdata("\n"); 126 $renderer->doc .= '<span id="multiclick_'.$htmlid."_".$count.'" class="multiclicker" onclick="multiclickclick(\''.hsc($page).'\',\''.$htmlid.'\','.$count.')">'; 127 $renderer->smiley($smiley); 128 $renderer->doc .= '</span>'; 129 $count++; 130 } 131 $renderer->cdata("\n"); 132 $renderer->doc .= "</span>"; 133 $renderer->doc .= '<span id="multismiley_'.$htmlid.'" title="multiselect:['.implode(', ',array_map('hsc',$smileys)).']" class="multismiley multismiley_'.hsc($page).'" onclick="multiselectclick(\''.$htmlid.'\')">'; 134 $renderer->smiley(reset($smileys)); 135 $renderer->doc .= '</span>'; 136 } else { 137 $renderer->doc .= '<span title="multiselect:['.implode(', ',array_map('hsc',$smileys)).']" class="multismiley">'; 138 $renderer->smiley(reset($smileys)); 139 $renderer->doc .= '</span>'; 140 } 141 142 //show first smiley 143 $renderer->cdata("\n"); 144 145 } else if ($mode == 'odt'){ 146 $renderer->smiley(reset($smileys)); 147 } 148 return true; 149 } 150 151} 152 153//Setup VIM: ex: et ts=4 enc=utf-8 : 154