[ Index ] |
|
Code source de Plume CMS 1.2.2 |
1 <?php 2 /** 3 * Éléments de configuration pour WikiRenderer 4 */ 5 6 7 require_once dirname(__FILE__).'/WikiRenderer.conf.php'; 8 9 class WikiRenderer_w2text extends WikiRendererConfig { 10 /** 11 * @var array liste des tags inline 12 */ 13 var $inlinetags= array( 14 'strong' =>array('__','__', null,'wikibuild_emphase_w2t'), 15 'em' =>array('\'\'','\'\'', null,'wikibuild_emphase_w2t'), 16 'code' =>array('@@','@@', null,'wikibuild_code_w2t'), 17 'q' =>array('^^','^^', array('lang','cite'),'wikibuild_q_w2t'), 18 'cite' =>array('{{','}}', array('title'),'wikibuild_cite_w2t'), 19 'acronym'=>array('??','??', array('title'),'wikibuild_acronym_w2t'), 20 'link' =>array('[',']', array('href','lang','title'),'wikibuild_link_w2t'), 21 'image' =>array('((','))', array('src','alt','align','longdesc'),'wikibuild_image_w2t'), 22 'anchor' =>array('~~','~~', array('id'),'wikibuild_anchor_w2t') 23 ); 24 25 /** 26 * liste des balises de type bloc autorisées. 27 * Attention, ordre important (p en dernier, car c'est le bloc par defaut..) 28 */ 29 var $bloctags = array('title_w2t'=>true, 'list_w2t'=>true, 30 'pre_w2t'=>true, 'hr_w2t'=>true, 'blockquote_w2t'=>true,'definition_w2t'=>true, 31 'table_w2t'=>true, 'p_w2t'=>true); 32 33 34 35 var $simpletags = array('%%%'=>"\n"); 36 37 /** 38 * @var integer niveau minimum pour les balises titres 39 */ 40 var $minHeaderLevel=3; 41 42 /** 43 * indique le sens dans lequel il faut interpreter le nombre de signe de titre 44 * true -> ! = titre , !! = sous titre, !!! = sous-sous-titre 45 * false-> !!! = titre , !! = sous titre, ! = sous-sous-titre 46 */ 47 var $headerOrder=false; 48 49 } 50 51 52 function wikibuild_emphase_w2t($contents, $attr){ 53 return $contents[0]; 54 } 55 56 function wikibuild_code_w2t($contents, $attr){ 57 return '['.$contents[0].']'; 58 } 59 60 61 function wikibuild_q_w2t($contents, $attr){ 62 if(count($contents) > 2) 63 return '"'.$contents[0].'" ('.$contents[2].')'; 64 else 65 return '"'.$contents[0].'"'; 66 } 67 68 function wikibuild_cite_w2t($contents, $attr){ 69 if(count($contents) > 1) 70 return '"'.$contents[0].'" ('.$contents[1].')'; 71 else 72 return '"'.$contents[0].'"'; 73 74 } 75 76 function wikibuild_acronym_w2t($contents, $attr){ 77 if(count($contents) > 1) 78 return $contents[0].' ('.$contents[1].')'; 79 else 80 return $contents[0]; 81 } 82 83 84 function wikibuild_link_w2t($contents, $attr){ 85 $cnt=count($contents); 86 $result=''; 87 88 if($cnt >1){ 89 if($cnt> count($attr)) 90 $cnt=count($attr)+1; 91 if(strpos($contents[1],'javascript:')!==false) // for security reason 92 $contents[1]='#'; 93 $result=$contents[0].' ('.$contents[1].')'; 94 }else{ 95 if(strpos($contents[0],'javascript:')!==false) // for security reason 96 $contents[0]='#'; 97 $result=$contents[0]; 98 99 } 100 return $result; 101 102 } 103 104 function wikibuild_anchor_w2t($contents, $attr){ 105 return ''; 106 } 107 108 function wikibuild_image_w2t($contents, $attr){ 109 return ''; 110 } 111 112 113 114 // ===================================== déclaration des différents bloc wiki 115 // on declare des blocs dérivant des blocs initiaux 116 // comme on n'autorise pas le texte preformaté (debutant par des espaces) 117 // on autorise des espaces en début de ligne pour les blocs. 118 119 /** 120 * traite les signes de types liste 121 */ 122 class WRB_list_w2t extends WikiRendererBloc { 123 124 var $type='list'; 125 var $regexp="/^([\*#-]+)(.*)/"; 126 127 function getRenderedLine(){ 128 return $this->_detectMatch[1].$this->_renderInlineTag($this->_detectMatch[2]); 129 } 130 } 131 132 133 /** 134 * traite les signes de types table 135 */ 136 class WRB_table_w2t extends WikiRendererBloc { 137 var $type='table'; 138 var $regexp="/^\| ?(.*)/"; 139 var $_openTag="--------------------------------------------"; 140 var $_closeTag="--------------------------------------------\n"; 141 142 var $_colcount=0; 143 144 function open(){ 145 $this->_colcount=0; 146 return $this->_openTag; 147 } 148 149 150 function getRenderedLine(){ 151 152 $result=explode(' | ',trim($this->_detectMatch[1])); 153 $str=''; 154 $t=''; 155 156 if((count($result) != $this->_colcount) && ($this->_colcount!=0)) 157 $t="--------------------------------------------\n"; 158 $this->_colcount=count($result); 159 160 for($i=0; $i < $this->_colcount; $i++){ 161 $str.=$this->_renderInlineTag($result[$i])."\t| "; 162 } 163 $str=$t."| ".$str; 164 165 return $str; 166 } 167 168 } 169 170 /** 171 * traite les signes de types hr 172 */ 173 class WRB_hr_w2t extends WikiRendererBloc { 174 175 var $type='hr'; 176 var $regexp='/^={4,} *$/'; 177 var $_closeNow=true; 178 179 function getRenderedLine(){ 180 return "=======================================================\n"; 181 } 182 183 } 184 185 /** 186 * traite les signes de types titre 187 */ 188 class WRB_title_w2t extends WikiRendererBloc { 189 var $type='title'; 190 var $regexp="/^(\!{1,3})(.*)/"; 191 var $_closeNow=true; 192 var $_minlevel=1; 193 var $_order=false; 194 195 function WRB_title_w2t(&$wr){ 196 $this->_minlevel = $wr->config->minHeaderLevel; 197 $this->_order = $wr->config->headerOrder; 198 parent::WikiRendererBloc($wr); 199 } 200 201 function getRenderedLine(){ 202 if($this->_order){ 203 $repeat= 4- strlen($this->_detectMatch[1]); 204 if($repeat <1) $repeat=1; 205 }else 206 $repeat= strlen($this->_detectMatch[1]); 207 return str_repeat("\n",$repeat)."\t".$this->_renderInlineTag($this->_detectMatch[2]).""; 208 } 209 } 210 211 /** 212 * traite les signes de types pre (pour afficher du code..) 213 */ 214 class WRB_pre_w2t extends WikiRendererBloc { 215 216 var $type='pre'; 217 var $regexp="/^ (.*)/"; 218 var $_openTag=''; 219 var $_closeTag=''; 220 221 function getRenderedLine(){ 222 return ' '.$this->_renderInlineTag($this->_detectMatch[1]); 223 } 224 225 } 226 227 /** 228 * traite les signes de type paragraphe 229 */ 230 class WRB_p_w2t extends WikiRendererBloc { 231 var $type='p'; 232 var $regexp="/(.*)/"; 233 } 234 235 236 237 /** 238 * traite les signes de type blockquote 239 */ 240 class WRB_blockquote_w2t extends WikiRendererBloc { 241 var $type='bq'; 242 var $regexp="/^(\>+)(.*)/"; 243 244 245 function getRenderedLine(){ 246 return $this->_detectMatch[1].$this->_renderInlineTag($this->_detectMatch[2]); 247 } 248 } 249 250 /** 251 * traite les signes de type blockquote 252 */ 253 class WRB_definition_w2t extends WikiRendererBloc { 254 255 var $type='dfn'; 256 var $regexp="/^;(.*) : (.*)/i"; 257 258 function getRenderedLine(){ 259 $dt=$this->_renderInlineTag($this->_detectMatch[1]); 260 $dd=$this->_renderInlineTag($this->_detectMatch[2]); 261 return "$dt :\n\t$dd"; 262 } 263 } 264 265 266 267 268 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 11:57:01 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |