| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | if (!function_exists("wakka2callback")) |
|---|
| 5 | { |
|---|
| 6 | function wakka2callback($things) |
|---|
| 7 | { |
|---|
| 8 | $thing = $things[1]; |
|---|
| 9 | $result=''; |
|---|
| 10 | global $Wiki; |
|---|
| 11 | |
|---|
| 12 | static $oldIndentLevel = 0; |
|---|
| 13 | static $oldIndentLength= 0; |
|---|
| 14 | static $indentClosers = array(); |
|---|
| 15 | static $newIndentSpace= array(); |
|---|
| 16 | static $br = 1; |
|---|
| 17 | global $token; |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | if (preg_match("/^\"\"(.*)\"\"$/s", $thing, $matches)) |
|---|
| 23 | { |
|---|
| 24 | |
|---|
| 25 | return $matches[1]; |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | else if ($thing == "<") |
|---|
| 29 | return "<"; |
|---|
| 30 | else if ($thing == ">") |
|---|
| 31 | return ">"; |
|---|
| 32 | |
|---|
| 33 | else if ($thing == "**") |
|---|
| 34 | { |
|---|
| 35 | return (++$token['bold'] % 2 ? "<strong>" : "</strong>"); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | else if ($thing == "//") |
|---|
| 39 | { |
|---|
| 40 | return (++$token['italic'] % 2 ? "<em>" : "</em>"); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | else if ($thing == "__") |
|---|
| 44 | { |
|---|
| 45 | return (++$token['underline'] % 2 ? "<em class='underline'>" : "</em>"); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | else if ($thing == "##") |
|---|
| 49 | { |
|---|
| 50 | return (++$token['monospace'] % 2 ? "<tt>" : "</tt>"); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | else if ($thing == "||") |
|---|
| 55 | { |
|---|
| 56 | return (++$token['warning'] % 2 ? "<span class='warning'>" : "</span>"); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | else if ($thing == "@@") |
|---|
| 62 | { |
|---|
| 63 | return (++$token['deleted'] % 2 ? "<span class=\"del\">" : "</span>"); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | else if ($thing == "££") |
|---|
| 67 | { |
|---|
| 68 | return (++$token['inserted'] % 2 ? "<span class=\"add\">" : "</span>"); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | else if (preg_match("/^([a-z]+:\/\/\S+?)([^[:alnum:]^\/])?$/", $thing, $matches)) { |
|---|
| 72 | $url = $matches[1]; |
|---|
| 73 | |
|---|
| 74 | return "<a href=\"$url\">$url</a>".$matches[2]; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | else if ($thing == "==") |
|---|
| 78 | { |
|---|
| 79 | $br = 0; |
|---|
| 80 | return (++$token['l5'] % 2 ? "<h5>" : "</h5>"); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | else if ($thing == "===") |
|---|
| 84 | { |
|---|
| 85 | $br = 0; |
|---|
| 86 | return (++$token['l4'] % 2 ? "<h4>" : "</h4>"); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | else if ($thing == "====") |
|---|
| 90 | { |
|---|
| 91 | $br = 0; |
|---|
| 92 | return (++$token['l3'] % 2 ? "<h3>" : "</h3>"); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | else if ($thing == "=====") |
|---|
| 96 | { |
|---|
| 97 | $br = 0; |
|---|
| 98 | return (++$token['l2'] % 2 ? "<h2>" : "</h2>"); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | else if ($thing == "======") |
|---|
| 102 | { |
|---|
| 103 | $br = 0; |
|---|
| 104 | return (++$token['l1'] % 2 ? "<h1>" : "</h1>"); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | else if (preg_match("/^-{4,}$/", $thing, $matches)) |
|---|
| 108 | { |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | $br = 0; |
|---|
| 112 | return '<hr noshade="noshade" size="1" />'; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | else if ($thing == "---") |
|---|
| 116 | { |
|---|
| 117 | return "<br />"; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | else if (preg_match("/^\%\%(.*)\%\%$/s", $thing, $matches)) |
|---|
| 121 | { |
|---|
| 122 | |
|---|
| 123 | $code = $matches[1]; |
|---|
| 124 | if (preg_match("/^\((.+?)\)(.*)$/s", $code, $matches)) |
|---|
| 125 | { |
|---|
| 126 | list(, $language, $code) = $matches; |
|---|
| 127 | } |
|---|
| 128 | switch ($language) |
|---|
| 129 | { |
|---|
| 130 | case "php": |
|---|
| 131 | case "table": |
|---|
| 132 | case "wakka": |
|---|
| 133 | $formatter = $language; |
|---|
| 134 | break; |
|---|
| 135 | default: |
|---|
| 136 | $formatter = "code"; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | $output .= Wikise(trim($code), $formatter); |
|---|
| 140 | |
|---|
| 141 | return $output; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | else if (preg_match("/^\[\[(\S*)(\s+(.+))?\]\]$/", $thing, $matches)) |
|---|
| 145 | { |
|---|
| 146 | list (, $url, , $text) = $matches; |
|---|
| 147 | if ($url) |
|---|
| 148 | { |
|---|
| 149 | if ($url!=($url=(preg_replace("/@@|££||\[\[/","",$url))))$result="</span>"; |
|---|
| 150 | if (!$text) $text = $url; |
|---|
| 151 | $text=preg_replace("/@@|££|\[\[/","",$text); |
|---|
| 152 | return $result.$Wiki->WikiLink($url, "", $text); |
|---|
| 153 | } |
|---|
| 154 | else |
|---|
| 155 | { |
|---|
| 156 | return ""; |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | else if (preg_match("/\n(\t+|([ ]{1})+)(-|([0-9,a-z,A-Z]+)\))?/s", $thing, $matches)) |
|---|
| 161 | { |
|---|
| 162 | |
|---|
| 163 | $result .= ($br ? "<br />\n" : ""); |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | $br = 0; |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | $newIndentType = $matches[3]; |
|---|
| 170 | if (!$newIndentType) { $opener = "<div class=\"indent\">"; $closer = "</div>"; $br = 1; } |
|---|
| 171 | else if ($newIndentType == "-") { $opener = "\n<ul>\n"; $closer = "</li>\n</ul>"; $li = 1; } |
|---|
| 172 | else { $opener = "<ol type=\"".$matches[4]."\">\n"; $closer = "</li>\n</ol>"; $li = 1; } |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | if (strpos($matches[1],"\t")) $newIndentLevel = strlen($matches[1]); |
|---|
| 177 | else |
|---|
| 178 | { |
|---|
| 179 | $newIndentLevel=$oldIndentLevel; |
|---|
| 180 | $newIndentLength = strlen($matches[1]); |
|---|
| 181 | if ($newIndentLength>$oldIndentLength) |
|---|
| 182 | { |
|---|
| 183 | $newIndentLevel++; |
|---|
| 184 | $newIndentSpace[$newIndentLength]=$newIndentLevel; |
|---|
| 185 | } |
|---|
| 186 | else if ($newIndentLength<$oldIndentLength) |
|---|
| 187 | $newIndentLevel=$newIndentSpace[$newIndentLength]; |
|---|
| 188 | } |
|---|
| 189 | $op=0; |
|---|
| 190 | if ($newIndentLevel > $oldIndentLevel) |
|---|
| 191 | { |
|---|
| 192 | for ($i = 0; $i < $newIndentLevel - $oldIndentLevel; $i++) |
|---|
| 193 | { |
|---|
| 194 | $result .= $opener; |
|---|
| 195 | $op=1; |
|---|
| 196 | array_push($indentClosers, $closer); |
|---|
| 197 | } |
|---|
| 198 | } |
|---|
| 199 | else if ($newIndentLevel < $oldIndentLevel) |
|---|
| 200 | { |
|---|
| 201 | for ($i = 0; $i < $oldIndentLevel - $newIndentLevel; $i++) |
|---|
| 202 | { |
|---|
| 203 | $op=1; |
|---|
| 204 | $result .= array_pop($indentClosers); |
|---|
| 205 | if ($oldIndentLevel && $li) $result .= "</li>"; |
|---|
| 206 | } |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | if (isset($li) && $op) $result .= "<li>"; |
|---|
| 210 | else if (isset($li)) |
|---|
| 211 | $result .= "</li>\n<li>"; |
|---|
| 212 | |
|---|
| 213 | $oldIndentLevel = $newIndentLevel; |
|---|
| 214 | $oldIndentLength= $newIndentLength; |
|---|
| 215 | |
|---|
| 216 | return $result; |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | else if ($thing == "\n") |
|---|
| 220 | { |
|---|
| 221 | |
|---|
| 222 | $c = count($indentClosers); |
|---|
| 223 | for ($i = 0; $i < $c; $i++) |
|---|
| 224 | { |
|---|
| 225 | $result .= array_pop($indentClosers); |
|---|
| 226 | $br = 0; |
|---|
| 227 | } |
|---|
| 228 | $oldIndentLevel = 0; |
|---|
| 229 | $oldIndentLength= 0; |
|---|
| 230 | $newIndentSpace=array(); |
|---|
| 231 | |
|---|
| 232 | $result .= ($br ? "<br />\n" : "\n"); |
|---|
| 233 | $br = 1; |
|---|
| 234 | return $result; |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | else if (preg_match("/^\{\{(.*?)\}\}$/s", $thing, $matches)) |
|---|
| 238 | { |
|---|
| 239 | if ($matches[1]) |
|---|
| 240 | return $Wiki->Action($matches[1]); |
|---|
| 241 | else |
|---|
| 242 | return "{{}}"; |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | else if (preg_match("/^[A-Z][A-Z,a-z]+[:]([A-Z,a-z,0-9]*)$/s", $thing)) |
|---|
| 246 | |
|---|
| 247 | { |
|---|
| 248 | return $Wiki->WikiLink($thing); |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | else if (preg_match("/^[A-Z][a-z]+[A-Z,0-9][A-Z,a-z,0-9]*$/s", $thing)) |
|---|
| 252 | { |
|---|
| 253 | return $Wiki->WikiLink($thing); |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | return $thing; |
|---|
| 257 | } |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | $text = str_replace("\r", "", $text); |
|---|
| 262 | $text = trim($text)."\n"; |
|---|
| 263 | unset($token); |
|---|
| 264 | $token = array(); |
|---|
| 265 | $text = preg_replace_callback( |
|---|
| 266 | "/(\%\%.*?\%\%|". |
|---|
| 267 | "\"\".*?\"\"|". |
|---|
| 268 | "\[\[.*?\]\]|". |
|---|
| 269 | "\b[a-z]+:\/\/\S+|". |
|---|
| 270 | "\*\*|\#\#|@@|££|__|<|>|\/\/|\|\||". |
|---|
| 271 | "======|=====|====|===|==|". |
|---|
| 272 | "-{4,}|---|". |
|---|
| 273 | "\n(\t+|([ ]{1})+)(-|[0-9,a-z,A-Z]+\))?|". |
|---|
| 274 | "\{\{.*?\}\}|". |
|---|
| 275 | "\b[A-Z][A-Z,a-z]+[:]([A-Z,a-z,0-9]*)\b|". |
|---|
| 276 | "\b([A-Z][a-z]+[A-Z,0-9][A-Z,a-z,0-9]*)\b|". |
|---|
| 277 | "\n)/ms", "wakka2callback", $text); |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | $text = preg_replace("/<br \/>$/","", trim($text)); |
|---|
| 296 | print($text); |
|---|
| 297 | ?> |
|---|