[ Index ] |
|
Code source de WikiNi 0.4.4 |
1 <?php 2 /* 3 wakka.php 4 Copyright (c) 2002, Hendrik Mans <hendrik@mans.de> 5 Copyright 2002, 2003 David DELON 6 Copyright 2002, 2003 Charles NEPOTE 7 Copyright 2002, 2003 Patrick PAUL 8 Copyright 2003 Eric DELORD 9 Copyright 2003 Eric FELDSTEIN 10 Copyright 2006 Didier Loiseau 11 All rights reserved. 12 Redistribution and use in source and binary forms, with or without 13 modification, are permitted provided that the following conditions 14 are met: 15 1. Redistributions of source code must retain the above copyright 16 notice, this list of conditions and the following disclaimer. 17 2. Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions and the following disclaimer in the 19 documentation and/or other materials provided with the distribution. 20 3. The name of the author may not be used to endorse or promote products 21 derived from this software without specific prior written permission. 22 23 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 // This may look a bit strange, but all possible formatting tags have to be in a single regular expression for this to work correctly. Yup! 35 36 if (!function_exists("wakka2callback")) 37 { 38 function wakka2callback($things) 39 { 40 $thing = $things[1]; 41 $result=''; 42 43 static $oldIndentLevel = 0; 44 static $oldIndentLength= 0; 45 static $indentClosers = array(); 46 static $newIndentSpace= array(); 47 static $br = 1; 48 49 $brf=0; 50 global $wiki; 51 52 // convert HTML thingies 53 if ($thing == "<") 54 return "<"; 55 else if ($thing == ">") 56 return ">"; 57 // bold 58 else if ($thing == "**") 59 { 60 static $bold = 0; 61 return (++$bold % 2 ? "<b>" : "</b>"); 62 } 63 // italic 64 else if ($thing == "//") 65 { 66 static $italic = 0; 67 return (++$italic % 2 ? "<i>" : "</i>"); 68 } 69 // underlinue 70 else if ($thing == "__") 71 { 72 static $underline = 0; 73 return (++$underline % 2 ? "<u>" : "</u>"); 74 } 75 // monospace 76 else if ($thing == "##") 77 { 78 static $monospace = 0; 79 return (++$monospace % 2 ? "<tt>" : "</tt>"); 80 } 81 // Deleted 82 else if ($thing == "@@") 83 { 84 static $deleted = 0; 85 return (++$deleted % 2 ? "<span class=\"del\">" : "</span>"); 86 } 87 // Inserted 88 else if ($thing == "££") 89 { 90 static $inserted = 0; 91 return (++$inserted % 2 ? "<span class=\"add\">" : "</span>"); 92 } 93 // urls 94 else if (preg_match("/^([a-z]+:\/\/\S+?)([^[:alnum:]^\/])?$/", $thing, $matches)) { 95 // Retrieve url and transform it into valid HTML (htmlentities) 96 $url = htmlentities ($matches[1]); 97 if (!isset($matches[2])) $matches[2] = ''; 98 return "<a href=\"$url\">$url</a>".$matches[2]; 99 } 100 // header level 5 101 else if ($thing == "==") 102 { 103 static $l5 = 0; 104 $br = 0; 105 return (++$l5 % 2 ? "<h5>" : "</h5>\n"); 106 } 107 // header level 4 108 else if ($thing == "===") 109 { 110 static $l4 = 0; 111 $br = 0; 112 return (++$l4 % 2 ? "<h4>" : "</h4>\n"); 113 } 114 // header level 3 115 else if ($thing == "====") 116 { 117 static $l3 = 0; 118 $br = 0; 119 return (++$l3 % 2 ? "<h3>" : "</h3>\n"); 120 } 121 // header level 2 122 else if ($thing == "=====") 123 { 124 static $l2 = 0; 125 $br = 0; 126 return (++$l2 % 2 ? "<h2>" : "</h2>\n"); 127 } 128 // header level 1 129 else if ($thing == "======") 130 { 131 static $l1 = 0; 132 $br = 0; 133 return (++$l1 % 2 ? "<h1>" : "</h1>\n"); 134 } 135 // forced line breaks 136 else if ($thing == "---") 137 { 138 return "<br />\n"; 139 } 140 // escaped text 141 else if (preg_match("/^\"\"(.*)\"\"$/s", $thing, $matches)) 142 { 143 if ($wiki->getConfigValue('allow_raw_html')) 144 { 145 return $matches[1]; 146 } 147 $res = htmlentities($matches[1]); 148 return preg_replace('/&(\\#[xX][a-fA-F0-9]+|\\#[0-9]+|[a-zA-Z0-9]+);/', '&$1;', $res); 149 } 150 // code text 151 else if (preg_match("/^\%\%(.*)\%\%$/s", $thing, $matches)) 152 { 153 // check if a language has been specified 154 $code = $matches[1]; 155 $language=''; 156 if (preg_match("/^\((.+?)\)(.*)$/s", $code, $matches)) 157 { 158 list(, $language, $code) = $matches; 159 } 160 //Select formatter for syntaxe hightlighting 161 if (file_exists("formatters/coloration_".$language.".php")){ 162 $formatter = "coloration_".$language; 163 }else{ 164 $formatter = "code"; 165 } 166 167 $output = "<div class=\"code\">"; 168 $output .= $wiki->Format(trim($code), $formatter); 169 $output .= "</div>\n"; 170 171 return $output; 172 } 173 // raw inclusion from another wiki 174 // (regexp documentation : see "forced link" below) 175 else if (preg_match("/^\[\[\|(\S*)(\s+(.+))?\]\]$/", $thing, $matches)) 176 { 177 if (isset($matches[3])) 178 { 179 list (, $url, , $text) = $matches; 180 } 181 else 182 { 183 $url = $matches[1]; 184 $text = '404'; 185 } 186 if ($url) 187 { 188 $url.="/wakka.php?wiki=".$text."/raw"; 189 return $wiki->Format($wiki->Format($url, "raw"),"wakka"); 190 } 191 else 192 { 193 return ""; 194 } 195 } 196 // forced links 197 // \S : any character that is not a whitespace character 198 // \s : any whitespace character 199 else if (preg_match("/^\[\[(\S*)(\s+(.+))?\]\]$/", $thing, $matches)) 200 { 201 if (isset($matches[3])) 202 { 203 list (, $url, , $text) = $matches; 204 } 205 else 206 { 207 $url = $matches[1]; 208 } 209 if ($url) 210 { 211 if ($url!=($url=(preg_replace("/@@|££|\[\[/","",$url))))$result="</span>"; 212 if (empty($text)) $text = $url; 213 $text=preg_replace("/@@|££|\[\[/","",$text); 214 return $result.$wiki->Link($url, "", $text); 215 } 216 else 217 { 218 return ""; 219 } 220 } 221 // indented text 222 else if ((preg_match("/\n(\t+|([ ]{1})+)(-|([0-9,a-z,A-Z]+)\))?/s", $thing, $matches)) 223 || (preg_match("/^(\t+|([ ]{1})+)(-|([0-9,a-z,A-Z]+)\))?/s", $thing, $matches) && $brf=1)) 224 { 225 // new line 226 if ($brf) $br=0; 227 $result .= ($br ? "<br />\n" : ""); 228 229 // we definitely want no line break in this one. 230 $br = 0; 231 232 // find out which indent type we want 233 if (!isset($matches[3])) $matches[3] = ''; 234 $newIndentType = $matches[3]; 235 if (!$newIndentType) { $opener = "<div class=\"indent\">"; $closer = "</div>"; $br = 1; } 236 else if ($newIndentType == "-") { $opener = "<ul>\n"; $closer = "</li>\n</ul>"; $li = 1; } 237 else { $opener = "<ol type=\"".$matches[4]."\">\n"; $closer = "</li>\n</ol>"; $li = 1; } 238 239 // get new indent level 240 241 if (strpos($matches[1],"\t")) $newIndentLevel = strlen($matches[1]); 242 else 243 { 244 $newIndentLevel=$oldIndentLevel; 245 $newIndentLength = strlen($matches[1]); 246 if ($newIndentLength>$oldIndentLength) 247 { 248 $newIndentLevel++; 249 $newIndentSpace[$newIndentLength]=$newIndentLevel; 250 } 251 else if ($newIndentLength<$oldIndentLength) 252 $newIndentLevel=$newIndentSpace[$newIndentLength]; 253 } 254 $op=0; 255 if ($newIndentLevel > $oldIndentLevel) 256 { 257 for ($i = 0; $i < $newIndentLevel - $oldIndentLevel; $i++) 258 { 259 $result .= $opener; 260 $op=1; 261 array_push($indentClosers, $closer); 262 } 263 } 264 else if ($newIndentLevel < $oldIndentLevel) 265 { 266 for ($i = 0; $i < $oldIndentLevel - $newIndentLevel; $i++) 267 { 268 $op=1; 269 $result .= array_pop($indentClosers); 270 if ($oldIndentLevel && isset($li)) $result .= "</li>"; 271 } 272 } 273 274 if (isset($li) && $op) $result .= "<li>"; 275 else if (isset($li)) 276 $result .= "</li>\n<li>"; 277 278 $oldIndentLevel = $newIndentLevel; 279 $oldIndentLength= $newIndentLength; 280 281 return $result; 282 } 283 // new lines 284 else if ($thing == "\n") 285 { 286 // if we got here, there was no tab in the next line; this means that we can close all open indents. 287 $c = count($indentClosers); 288 for ($i = 0; $i < $c; $i++) 289 { 290 $result .= array_pop($indentClosers); 291 $br = 0; 292 } 293 $oldIndentLevel = 0; 294 $oldIndentLength= 0; 295 $newIndentSpace=array(); 296 297 $result .= ($br ? "<br />\n" : "\n"); 298 $br = 1; 299 return $result; 300 } 301 // events 302 else if (preg_match("/^\{\{(.*?)\}\}$/s", $thing, $matches)) 303 { 304 if ($matches[1]) 305 return $wiki->Action($matches[1]); 306 else 307 return "{{}}"; 308 } 309 // interwiki links! 310 else if (preg_match("/^[A-Z][A-Za-z]+[:]([A-Za-z0-9]*)$/s", $thing)) 311 312 { 313 return $wiki->Link($thing); 314 } 315 // wiki links! 316 else if (preg_match("/^[A-Z][a-z]+[A-Z0-9][A-Za-z0-9]*$/s", $thing)) 317 { 318 return $wiki->Link($thing); 319 } 320 // separators 321 else if (preg_match("/-{4,}/", $thing, $matches)) 322 { 323 // TODO: This could probably be improved for situations where someone puts text on the same line as a separator. 324 // Which is a stupid thing to do anyway! HAW HAW! Ahem. 325 $br = 0; 326 return "<hr />\n"; 327 } 328 // if we reach this point, it must have been an accident. 329 return $thing; 330 } 331 } 332 333 334 $text = str_replace("\r", "", $text); 335 $text = chop($text)."\n"; 336 $text = preg_replace_callback( 337 "/(\%\%.*?\%\%|". 338 "\"\".*?\"\"|". 339 "\[\[.*?\]\]|". 340 "\b[a-z]+:\/\/\S+|". 341 "\*\*|\#\#|@@|££|__|<|>|\/\/|". 342 "======|=====|====|===|==|". 343 "-{4,}|---|". 344 "\n(\t+|([ ]{1})+)(-|[0-9,a-z,A-Z]+\))?|". 345 "^(\t+|([ ]{1})+)(-|[0-9,a-z,A-Z]+\))?|". 346 "\{\{.*?\}\}|". 347 "\b[A-Z][A-Za-z]+[:]([A-Za-z0-9]*)\b|". 348 "\b([A-Z][a-z]+[A-Z0-9][A-Za-z0-9]*)\b|". 349 "\n)/ms", "wakka2callback", $text); 350 351 // we're cutting the last <br /> 352 $text = preg_replace("/<br \/>$/","", trim($text)); 353 echo $text ; 354 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:05:46 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |