Commit | Line | Data |
---|---|---|
3ee590a9 | 1 | <?php |
2 | /******************************************************************************** | |
73d5bf46 | 3 | * include/misc.inc.php : Misc functions |
4 | * ------------------------- | |
5 | * | |
6 | * This file is part of the banana distribution | |
7 | * Copyright: See COPYING files that comes with this distribution | |
8 | ********************************************************************************/ | |
9 | ||
10 | /******************************************************************************** | |
2dbc0167 | 11 | * MISC |
73d5bf46 | 12 | */ |
13 | ||
0ca6e016 | 14 | function _b_($str) { return utf8_decode(dgettext('banana', utf8_encode($str))); } |
0a65ec9d | 15 | |
987299b4 | 16 | function to_entities($str) { |
6918d66a | 17 | require_once dirname(__FILE__).'/utf8.php'; |
987299b4 | 18 | return utf8entities(htmlentities($str, ENT_NOQUOTES, 'UTF-8')); |
382606fb PHM |
19 | } |
20 | ||
c42efe2f PHM |
21 | function is_utf8($s) { return iconv('utf-8', 'utf-8', $s) == $s; } |
22 | ||
8f6f50fb | 23 | function textFormat_translate($format) |
24 | { | |
25 | switch (strtolower($format)) { | |
26 | case 'plain': return _b_('Texte brut'); | |
27 | case 'richtext': return _b_('Texte enrichi'); | |
28 | case 'html': return _b_('HTML'); | |
29 | default: return $format; | |
30 | } | |
31 | } | |
32 | ||
0eb1e7ef | 33 | /** Redirect to the page with the given parameter |
34 | * @ref makeLink | |
35 | */ | |
e8de34ae | 36 | function redirectInBanana($params) |
9cac5c87 | 37 | { |
d5588318 | 38 | header('Location: ' . makeLink($params)); |
9cac5c87 | 39 | } |
40 | ||
0eb1e7ef | 41 | /** Make a link using the given parameters |
42 | * @param ARRAY params, the parameters with | |
43 | * key => value | |
44 | * Known key are: | |
45 | * - group = group name | |
46 | * - artid/first = article id the the group | |
47 | * - subscribe = to show the subscription page | |
48 | * - action = action to do (new, cancel, view) | |
49 | * - part = to show the given MIME part of the article | |
50 | * - pj = to get the given attachment | |
261210bc | 51 | * - xface = to make a link to an xface |
0eb1e7ef | 52 | * |
53 | * Can be overloaded by defining a hook_makeLink function | |
54 | */ | |
9cac5c87 | 55 | function makeLink($params) |
56 | { | |
d5588318 | 57 | if (function_exists('hook_makeLink') |
58 | && $res = hook_makeLink($params)) { | |
59 | return $res; | |
60 | } | |
0eb1e7ef | 61 | $proto = empty($_SERVER['HTTPS']) ? 'http://' : 'https://'; |
9cac5c87 | 62 | $host = $_SERVER['HTTP_HOST']; |
63 | $file = $_SERVER['PHP_SELF']; | |
64 | ||
261210bc | 65 | if (isset($params['xface'])) { |
66 | $file = dirname($file) . '/xface.php'; | |
8948d347 | 67 | $get = 'face=' . urlencode(base64_encode($params['xface'])); |
261210bc | 68 | } else if (count($params) != 0) { |
d5588318 | 69 | $get = '?'; |
70 | foreach ($params as $key=>$value) { | |
71 | if (strlen($get) != 1) { | |
72 | $get .= '&'; | |
73 | } | |
74 | $get .= $key . '=' . $value; | |
75 | } | |
76 | } else { | |
77 | $get = ''; | |
78 | } | |
79 | ||
80 | return $proto . $host . $file . $get; | |
0eb1e7ef | 81 | } |
82 | ||
83 | /** Format a link to be use in a link | |
84 | * @ref makeLink | |
85 | */ | |
937a36cf | 86 | function makeHREF($params, $text = null, $popup = null) |
0eb1e7ef | 87 | { |
d5588318 | 88 | $link = makeLink($params); |
89 | if (is_null($text)) { | |
90 | $text = $link; | |
91 | } | |
937a36cf | 92 | if (!is_null($popup)) { |
93 | $popup = ' title="' . $popup . '"'; | |
94 | } | |
d5588318 | 95 | $target = null; |
96 | if (isset($params['action']) && $params['action'] == 'view') { | |
97 | $target = ' target="_blank"'; | |
98 | } | |
937a36cf | 99 | return '<a href="' . htmlentities($link) . $target . '"' . $popup . '>' . $text . '</a>'; |
9cac5c87 | 100 | } |
101 | ||
d7632010 | 102 | /** Format tree images links |
103 | * @param img STRING Image name (without extension) | |
104 | * @param alt STRING alternative string | |
105 | * @param width INT to force width of the image (null if not defined) | |
106 | * | |
107 | * This function can be overloaded by defining hook_makeImg() | |
108 | */ | |
4ccaaeb7 | 109 | function makeImg($img, $alt, $height = null, $width = null) |
d7632010 | 110 | { |
111 | if (function_exists('hook_makeImg') | |
9419816d | 112 | && $res = hook_makeImg($img, $alt, $height, $width)) { |
d7632010 | 113 | return $res; |
114 | } | |
115 | ||
116 | if (!is_null($width)) { | |
117 | $width = ' width="' . $width . '"'; | |
118 | } | |
4ccaaeb7 | 119 | if (!is_null($height)) { |
120 | $height = ' height="' . $height . '"'; | |
121 | } | |
122 | ||
d7632010 | 123 | $proto = empty($_SERVER['HTTPS']) ? 'http://' : 'https://'; |
124 | $host = $_SERVER['HTTP_HOST']; | |
125 | $file = dirname($_SERVER['PHP_SELF']) . '/img/' . $img . '.gif'; | |
126 | $url = $proto . $host . $file; | |
127 | ||
4ccaaeb7 | 128 | return '<img src="' . $url . '"' . $height . $width . ' alt="' . $alt . '" />'; |
d7632010 | 129 | } |
130 | ||
8f6f50fb | 131 | /******************************************************************************** |
132 | * HTML STUFF | |
133 | * Taken from php.net | |
134 | */ | |
135 | ||
5d133234 | 136 | /** |
8f6f50fb | 137 | * @return string |
138 | * @param string | |
139 | * @desc Strip forbidden tags and delegate tag-source check to removeEvilAttributes() | |
140 | */ | |
141 | function removeEvilTags($source) | |
142 | { | |
73ab762c | 143 | $allowedTags = '<h1><b><i><a><ul><li><pre><hr><blockquote><img><br><font><p><small><big><sup><sub><code><em>'; |
76032c26 | 144 | $source = preg_replace('|</div>|i', '<br />', $source); |
8f6f50fb | 145 | $source = strip_tags($source, $allowedTags); |
146 | return preg_replace('/<(.*?)>/ie', "'<'.removeEvilAttributes('\\1').'>'", $source); | |
147 | } | |
148 | ||
149 | /** | |
150 | * @return string | |
151 | * @param string | |
152 | * @desc Strip forbidden attributes from a tag | |
153 | */ | |
154 | function removeEvilAttributes($tagSource) | |
155 | { | |
156 | $stripAttrib = 'javascript:|onclick|ondblclick|onmousedown|onmouseup|onmouseover|'. | |
157 | 'onmousemove|onmouseout|onkeypress|onkeydown|onkeyup'; | |
158 | return stripslashes(preg_replace("/$stripAttrib/i", '', $tagSource)); | |
159 | } | |
160 | ||
5d133234 | 161 | /** Convert html to plain text |
162 | */ | |
163 | function htmlToPlainText($res) | |
164 | { | |
76032c26 | 165 | $res = trim(html_entity_decode(strip_tags($res, '<div><br><p>'))); |
166 | $res = preg_replace("@</?(br|p|div)[^>]*>@i", "\n", $res); | |
e27ae1a3 | 167 | if (!is_utf8($res)) { |
168 | $res = utf8_encode($res); | |
169 | } | |
5d133234 | 170 | return $res; |
171 | } | |
172 | ||
1fb11000 | 173 | /** Match **, // and __ to format plain text |
174 | */ | |
175 | function formatPlainText($text) | |
176 | { | |
177 | $formatting = Array('\*' => 'strong', | |
178 | '_' => 'u', | |
179 | '/' => 'em'); | |
180 | foreach ($formatting as $limit=>$mark) { | |
181 | $text = preg_replace('@(^|\W)' . $limit . '(\w+)' . $limit . '(\W|$)@' | |
182 | ,'\1<' . $mark . '>\2</' . $mark . '>\3' | |
183 | , $text); | |
184 | } | |
185 | return $text; | |
186 | } | |
187 | ||
5d133234 | 188 | /******************************************************************************** |
189 | * RICHTEXT STUFF | |
190 | */ | |
191 | ||
192 | /** Convert richtext to html | |
193 | */ | |
194 | function richtextToHtml($source) | |
195 | { | |
196 | $tags = Array('bold' => 'b', | |
197 | 'italic' => 'i', | |
198 | 'smaller' => 'small', | |
199 | 'bigger' => 'big', | |
200 | 'underline' => 'u', | |
201 | 'subscript' => 'sub', | |
202 | 'superscript' => 'sup', | |
203 | 'excerpt' => 'blockquote', | |
204 | 'paragraph' => 'p', | |
205 | 'nl' => 'br' | |
206 | ); | |
207 | ||
208 | // clean unsupported tags | |
209 | $protectedTags = '<signature><lt><comment><'.join('><', array_keys($tags)).'>'; | |
210 | $source = strip_tags($source, $protectedTags); | |
211 | ||
212 | // convert richtext tags to html | |
213 | foreach (array_keys($tags) as $tag) { | |
214 | $source = preg_replace('@(</?)'.$tag.'([^>]*>)@i', '\1'.$tags[$tag].'\2', $source); | |
215 | } | |
216 | ||
217 | // some special cases | |
218 | $source = preg_replace('@<signature>@i', '<br>-- <br>', $source); | |
219 | $source = preg_replace('@</signature>@i', '', $source); | |
220 | $source = preg_replace('@<lt>@i', '<', $source); | |
221 | $source = preg_replace('@<comment[^>]*>((?:[^<]|<(?!/comment>))*)</comment>@i', '<!-- \1 -->', $source); | |
222 | return removeEvilAttributes($source); | |
223 | } | |
224 | ||
73d5bf46 | 225 | /******************************************************************************** |
226 | * HEADER STUFF | |
227 | */ | |
228 | ||
dd7d1c59 | 229 | function _headerdecode($charset, $c, $str) { |
67d2dcfc | 230 | $s = ($c == 'Q' || $c == 'q') ? quoted_printable_decode($str) : base64_decode($str); |
dd7d1c59 | 231 | $s = iconv($charset, 'iso-8859-15', $s); |
232 | return str_replace('_', ' ', $s); | |
233 | } | |
234 | ||
235 | function headerDecode($value) { | |
67d2dcfc | 236 | $val = preg_replace('/(=\?[^?]*\?[BQbq]\?[^?]*\?=) (=\?[^?]*\?[BQbq]\?[^?]*\?=)/', '\1\2', $value); |
237 | return preg_replace('/=\?([^?]*)\?([BQbq])\?([^?]*)\?=/e', '_headerdecode("\1", "\2", "\3")', $val); | |
dd7d1c59 | 238 | } |
239 | ||
9cf3f056 PHM |
240 | function headerEncode($value, $trim = 0) { |
241 | if ($trim) { | |
d752880f PHM |
242 | if (strlen($value) > $trim) { |
243 | $value = substr($value, 0, $trim) . "[...]"; | |
244 | } | |
9cf3f056 PHM |
245 | } |
246 | return "=?UTF-8?B?".base64_encode($value)."?="; | |
247 | } | |
248 | ||
e2cae7e3 | 249 | function header_translate($hdr) { |
d4c19591 | 250 | switch ($hdr) { |
0a65ec9d | 251 | case 'from': return _b_('De'); |
252 | case 'subject': return _b_('Sujet'); | |
253 | case 'newsgroups': return _b_('Forums'); | |
d4c19591 | 254 | case 'followup-to': return _b_('Suivi-ŕ'); |
0a65ec9d | 255 | case 'date': return _b_('Date'); |
256 | case 'organization': return _b_('Organisation'); | |
257 | case 'references': return _b_('Références'); | |
d4c19591 | 258 | case 'x-face': return _b_('Image'); |
e2cae7e3 | 259 | default: |
559be3d6 | 260 | if (function_exists('hook_headerTranslate') |
261 | && $res = hook_headerTranslate($hdr)) { | |
262 | return $res; | |
2dbc0167 | 263 | } |
e2cae7e3 | 264 | return $hdr; |
265 | } | |
266 | } | |
267 | ||
2dbc0167 | 268 | function formatDisplayHeader($_header,$_text) { |
269 | global $banana; | |
1fb11000 | 270 | if (function_exists('hook_formatDisplayHeader') |
271 | && $res = hook_formatDisplayHeader($_header, $_text)) { | |
272 | return $res; | |
273 | } | |
274 | ||
2dbc0167 | 275 | switch ($_header) { |
276 | case "date": | |
277 | return formatDate($_text); | |
278 | ||
279 | case "followup-to": | |
280 | case "newsgroups": | |
281 | $res = ""; | |
282 | $groups = preg_split("/[\t ]*,[\t ]*/",$_text); | |
283 | foreach ($groups as $g) { | |
0eb1e7ef | 284 | $res .= makeHREF(Array('group' => $g), $g) . ', '; |
2dbc0167 | 285 | } |
286 | return substr($res,0, -2); | |
287 | ||
288 | case "from": | |
289 | return formatFrom($_text); | |
290 | ||
291 | case "references": | |
292 | $rsl = ""; | |
293 | $ndx = 1; | |
294 | $text = str_replace("><","> <",$_text); | |
295 | $text = preg_split("/[ \t]/",strtr($text,$banana->spool->ids)); | |
296 | $parents = preg_grep("/^\d+$/",$text); | |
297 | $p = array_pop($parents); | |
58d1740e | 298 | $par_ok = Array(); |
2dbc0167 | 299 | |
300 | while ($p) { | |
58d1740e | 301 | $par_ok[]=$p; |
2dbc0167 | 302 | $p = $banana->spool->overview[$p]->parent; |
303 | } | |
58d1740e | 304 | foreach (array_reverse($par_ok) as $p) { |
4840f22b | 305 | $rsl .= makeHREF(Array('group' => $banana->spool->group), $ndx) . ' '; |
2dbc0167 | 306 | $ndx++; |
307 | } | |
308 | return $rsl; | |
309 | ||
310 | case "x-face": | |
8948d347 | 311 | return '<img src="' . makeLink(Array('xface' => headerDecode($_text))) .'" alt="x-face" />'; |
1fb11000 | 312 | |
313 | case "subject": | |
72afc3ec | 314 | $link = null; |
315 | if (function_exists('hook_getSubject')) { | |
316 | $link = hook_getSubject($_text); | |
317 | } | |
318 | return formatPlainText($_text) . $link; | |
1fb11000 | 319 | |
2dbc0167 | 320 | default: |
2dbc0167 | 321 | return htmlentities($_text); |
322 | } | |
323 | } | |
324 | ||
73d5bf46 | 325 | /******************************************************************************** |
326 | * FORMATTING STUFF | |
327 | */ | |
328 | ||
e2cae7e3 | 329 | function formatDate($_text) { |
330 | return strftime("%A %d %B %Y, %H:%M (fuseau serveur)", strtotime($_text)); | |
331 | } | |
332 | ||
333 | function fancyDate($stamp) { | |
334 | $today = intval(time() / (24*3600)); | |
335 | $dday = intval($stamp / (24*3600)); | |
336 | ||
337 | if ($today == $dday) { | |
338 | $format = "%H:%M"; | |
339 | } elseif ($today == 1 + $dday) { | |
0a65ec9d | 340 | $format = _b_('hier')." %H:%M"; |
e2cae7e3 | 341 | } elseif ($today < 7 + $dday) { |
1248ebac | 342 | $format = '%a %H:%M'; |
e2cae7e3 | 343 | } else { |
344 | $format = '%a %e %b'; | |
345 | } | |
346 | return strftime($format, $stamp); | |
347 | } | |
348 | ||
dd7d1c59 | 349 | function formatFrom($text) { |
350 | # From: mark@cbosgd.ATT.COM | |
351 | # From: mark@cbosgd.ATT.COM (Mark Horton) | |
352 | # From: Mark Horton <mark@cbosgd.ATT.COM> | |
353 | $mailto = '<a href="mailto:'; | |
354 | ||
355 | $result = htmlentities($text); | |
356 | if (preg_match("/^([^ ]+)@([^ ]+)$/",$text,$regs)) { | |
357 | $result="$mailto{$regs[1]}@{$regs[2]}\">".htmlentities($regs[1]."@".$regs[2])."</a>"; | |
358 | } | |
359 | if (preg_match("/^([^ ]+)@([^ ]+) \((.*)\)$/",$text,$regs)) { | |
360 | $result="$mailto{$regs[1]}@{$regs[2]}\">".htmlentities($regs[3])."</a>"; | |
361 | } | |
362 | if (preg_match("/^\"?([^<>\"]+)\"? +<(.+)@(.+)>$/",$text,$regs)) { | |
363 | $result="$mailto{$regs[2]}@{$regs[3]}\">".htmlentities($regs[1])."</a>"; | |
364 | } | |
365 | return preg_replace("/\\\(\(|\))/","\\1",$result); | |
366 | } | |
367 | ||
f78f34d2 | 368 | function displayshortcuts($first = -1) { |
41cf00eb | 369 | global $banana; |
8d99c683 | 370 | extract($banana->state); |
371 | ||
559be3d6 | 372 | $res = '<div class="banana_scuts">'; |
0eb1e7ef | 373 | $res .= '[' . makeHREF(Array(), _b_('Liste des forums')) . '] '; |
8d99c683 | 374 | if (is_null($group)) { |
0eb1e7ef | 375 | return $res.'[' . makeHREF(Array('subscribe' => 1), _b_('Abonnements')) . ']</div>'; |
8d99c683 | 376 | } |
377 | ||
0eb1e7ef | 378 | $res .= '[' . makeHREF(Array('group' => $group), $group) . '] '; |
8d99c683 | 379 | |
380 | if (is_null($artid)) { | |
0eb1e7ef | 381 | $res .= '[' . makeHREF(Array('group' => $group, |
d5588318 | 382 | 'action' => 'new'), |
383 | _b_('Nouveau message')) | |
384 | . '] '; | |
8d99c683 | 385 | if (sizeof($banana->spool->overview)>$banana->tmax) { |
937a36cf | 386 | $res .= '<br />Page : '; |
8d99c683 | 387 | $n = intval(log(count($banana->spool->overview), 10))+1; |
937a36cf | 388 | $i = 1; |
389 | for ($ndx = 1 ; $ndx <= sizeof($banana->spool->overview) ; $ndx += $banana->tmax) { | |
8d99c683 | 390 | if ($first==$ndx) { |
937a36cf | 391 | $fmt = $i . ' '; |
8d99c683 | 392 | } else { |
937a36cf | 393 | $fmt = makeHREF(Array('group' => $group, |
394 | 'first' => $ndx), | |
395 | $i, | |
396 | '%0' . $n . 'u-%0' . $n . 'u') | |
397 | . ' '; | |
f78f34d2 | 398 | } |
937a36cf | 399 | $i++; |
8d99c683 | 400 | $res .= sprintf($fmt, $ndx, min($ndx+$banana->tmax-1,sizeof($banana->spool->overview))); |
f78f34d2 | 401 | } |
8d99c683 | 402 | } |
403 | } else { | |
0eb1e7ef | 404 | $res .= '[' . makeHREF(Array('group' => $group, |
d5588318 | 405 | 'artid' => $artid, |
406 | 'action' => 'new'), | |
407 | _b_('Répondre')) | |
408 | . '] '; | |
940ae667 | 409 | if ($banana->post && $banana->post->checkcancel()) { |
0eb1e7ef | 410 | $res .= '[' . makeHREF(Array('group' => $group, |
d5588318 | 411 | 'artid' => $artid, |
412 | 'action' => 'cancel'), | |
413 | _b_('Annuler ce message')) | |
414 | . '] '; | |
8d99c683 | 415 | } |
f78f34d2 | 416 | } |
8d99c683 | 417 | return $res.'</div>'; |
f78f34d2 | 418 | } |
419 | ||
420 | /******************************************************************************** | |
421 | * FORMATTING STUFF : BODY | |
422 | */ | |
423 | ||
28fb1083 | 424 | function autoformat($text) |
425 | { | |
426 | global $banana; | |
427 | $length = $banana->wrap; | |
428 | ||
429 | $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$length, all=>1 };'"; | |
430 | exec($cmd, $result, $ret); | |
431 | if ($ret != 0) { | |
9ee36ea4 | 432 | $result = split("\n", $text); |
28fb1083 | 433 | } |
434 | return $result; | |
435 | } | |
436 | ||
e04e6059 | 437 | function wrap($text, $_prefix="", $_force=false) |
cced14b6 | 438 | { |
dd7d1c59 | 439 | $parts = preg_split("/\n-- ?\n/", $text); |
276debfc | 440 | if (count($parts) >1) { |
441 | $sign = "\n-- \n" . array_pop($parts); | |
442 | $text = join("\n-- \n", $parts); | |
3ee590a9 | 443 | } else { |
276debfc | 444 | $sign = ''; |
3ee590a9 | 445 | } |
2dbc0167 | 446 | |
447 | global $banana; | |
e04e6059 | 448 | $url = $banana->url_regexp; |
2dbc0167 | 449 | $length = $banana->wrap; |
e04e6059 | 450 | $max = $length + ($length/10); |
451 | $splits = split("\n", $text); | |
28fb1083 | 452 | $result = array(); |
453 | $next = array(); | |
454 | $format = false; | |
e04e6059 | 455 | foreach ($splits as $line) { |
456 | if ($_force || strlen($line) > $max) { | |
28fb1083 | 457 | if (preg_match("!^(.*)($url)(.*)!i", $line, $matches) && strlen($matches[2]) > $length && strlen($matches) < 900) { |
458 | if (strlen($matches[1]) != 0) { | |
459 | array_push($next, rtrim($matches[1])); | |
460 | if (strlen($matches[1]) > $max) { | |
461 | $format = true; | |
462 | } | |
463 | } | |
464 | ||
465 | if ($format) { | |
466 | $result = array_merge($result, autoformat(join("\n", $next))); | |
467 | } else { | |
468 | $result = array_merge($result, $next); | |
469 | } | |
470 | $format = false; | |
471 | $next = array(); | |
472 | array_push($result, $matches[2]); | |
473 | ||
474 | if (strlen($matches[6]) != 0) { | |
475 | array_push($next, ltrim($matches[6])); | |
476 | if (strlen($matches[6]) > $max) { | |
477 | $format = true; | |
478 | } | |
479 | } | |
480 | } else { | |
481 | $format = true; | |
482 | array_push($next, $line); | |
e04e6059 | 483 | } |
28fb1083 | 484 | } else { |
485 | array_push($next, $line); | |
e04e6059 | 486 | } |
487 | } | |
28fb1083 | 488 | if ($format) { |
489 | $result = array_merge($result, autoformat(join("\n", $next))); | |
490 | } else { | |
491 | $result = array_merge($result, $next); | |
ee4709c7 | 492 | } |
3ee590a9 | 493 | |
f8e23519 | 494 | return $_prefix.join("\n$_prefix", $result).($_prefix ? '' : $sign); |
3ee590a9 | 495 | } |
496 | ||
e04e6059 | 497 | function cutlink($link) |
498 | { | |
499 | global $banana; | |
500 | ||
501 | if (strlen($link) > $banana->wrap) { | |
502 | $link = substr($link, 0, $banana->wrap - 3)."..."; | |
503 | } | |
504 | return $link; | |
505 | } | |
506 | ||
4c921acf | 507 | function cleanurl($url) |
508 | { | |
509 | $url = str_replace('@', '%40', $url); | |
510 | return '<a href="'.$url.'" title="'.$url.'">'.cutlink($url).'</a>'; | |
511 | } | |
512 | ||
e04e6059 | 513 | function formatbody($_text, $format='plain', $flowed=false) |
8f6f50fb | 514 | { |
515 | if ($format == 'html') { | |
76032c26 | 516 | $res = '<br/>'.html_entity_decode(to_entities(removeEvilTags($_text))).'<br/>'; |
5d133234 | 517 | } else if ($format == 'richtext') { |
09f71105 | 518 | $res = '<br/>'.html_entity_decode(to_entities(richtextToHtml($_text))).'<br/>'; |
8f6f50fb | 519 | } else { |
e04e6059 | 520 | $res = "\n\n" . to_entities(wrap($_text, "", $flowed))."\n\n"; |
1fb11000 | 521 | $res = formatPlainText($res); |
d5588318 | 522 | } |
8f6f50fb | 523 | |
09f71105 | 524 | if ($format != 'html') { |
525 | global $banana; | |
526 | $url = $banana->url_regexp; | |
527 | $res = preg_replace("/(<|>|")/", " \\1 ", $res); | |
4c921acf | 528 | $res = preg_replace("!$url!ie", "'\\1'.cleanurl('\\2').'\\3'", $res); |
09f71105 | 529 | $res = preg_replace('/(["\[])?(?:mailto:)?([a-z0-9.\-+_]+@[a-z0-9.\-+_]+)(["\]])?/i', '\1<a href="mailto:\2">\2</a>\3', $res); |
530 | $res = preg_replace("/ (<|>|") /", "\\1", $res); | |
531 | ||
532 | if ($format == 'richtext') { | |
533 | $format = 'html'; | |
534 | } | |
535 | } | |
e04e6059 | 536 | |
8f6f50fb | 537 | if ($format == 'html') { |
9c192e03 | 538 | $res = preg_replace("@(</p>)\n?-- ?\n?(<p[^>]*>|<br[^>]*>)@", "\\1<br/>-- \\2", $res); |
539 | $res = preg_replace("@<br[^>]*>\n?-- ?\n?(<p[^>]*>)@", "<br/>-- <br/>\\2", $res); | |
540 | $res = preg_replace("@(<pre[^>]*>)\n?-- ?\n@", "<br/>-- <br/>\\1", $res); | |
541 | $parts = preg_split("@(:?<p[^>]*>\n?-- ?\n?</p>|<br[^>]*>\n?-- ?\n?<br[^>]*>)@", $res); | |
f5eb6c66 | 542 | } else { |
9ee36ea4 | 543 | while (preg_match("@(^|<pre>|\n)>@i", $res)) { |
b7a8ff33 | 544 | $res = preg_replace("@(^|<pre>|\n)((>[^\n]*\n)+)@ie", |
9ee36ea4 | 545 | "'\\1</pre><blockquote><pre>'" |
d5588318 | 546 | .".stripslashes(preg_replace('@(^|<pre>|\n)>[ \\t\\r]*@i', '\\1', '\\2'))" |
547 | .".'</pre></blockquote><pre>'", | |
548 | $res); | |
73afa785 | 549 | } |
d5588318 | 550 | $res = preg_replace("@<pre>-- ?\n@", "<pre>\n-- \n", $res); |
f5eb6c66 | 551 | $parts = preg_split("/\n-- ?\n/", $res); |
8f6f50fb | 552 | } |
553 | ||
dd7d1c59 | 554 | if (count($parts) > 1) { |
f5eb6c66 | 555 | $sign = array_pop($parts); |
556 | if ($format == 'html') { | |
557 | $res = join('<br/>-- <br/>', $parts); | |
73afa785 | 558 | $sign = '<hr style="width: 100%; margin: 1em 0em; " />'.$sign.'<br/>'; |
f5eb6c66 | 559 | } else { |
560 | $res = join('\n-- \n', $parts); | |
561 | $sign = '</pre><hr style="width: 100%; margin: 1em 0em; " /><pre>'.$sign; | |
562 | } | |
563 | return $res.$sign; | |
dd7d1c59 | 564 | } else { |
565 | return $res; | |
566 | } | |
cced14b6 | 567 | } |
568 | ||
d5588318 | 569 | // vim:set et sw=4 sts=4 ts=4 |
3ee590a9 | 570 | ?> |