' . $dispname . ''; else return '' . $dispname . ''; } function make_edit_link($match) { list($pagename, $dispname) = explode('|', $match[1], 2); if (!isset($dispname)) $dispname = $pagename; $page = urlencode(trim($pagename)); return '' . $dispname . ''; } $toc = array(); $toc_entries = 0; function make_h1($match) { global $toc, $toc_entries; $toc_entries++; $toc['s_' . $toc_entries] = $match[1]; return '

' . $match[1] . '



'; } function make_h2($match) { return '

' . trim($match[1]) . '



'; } function make_h3($match) { return '

' . trim($match[1]) . '


'; } function convert_urls($text) { $text = preg_replace('!(^|([^\'"]\s*))((http|ftp|https|ftps):\/\/[^\s<>"\'()]{4,})!mi', '$2external link $3', $text); $text = preg_replace('!!', '', $text); $text = preg_replace('!([\.:,\]])!', '$1', $text); return $text; } $list_count = 0; function make_list($match) { global $list_count; if ($match[0] == '[list]') { $list_count++; return ''; } else if ($match[0] == '[end#list]') { if ($list_count == 0) return ''; $list_count--; return ''; } } function make_li($match) { return '
  • ' . trim($match[2]) . '
  • '; } $cbnum = 0; function code_block($match) { global $cbnum; $cbnum++; $geshi =& new GeSHi(trim(str_replace('
    ', '', $match[2])), $match[1]); $geshi->set_header_type(GESHI_HEADER_NONE); $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); $geshi->set_line_style('color: #666699', 'color: #000000;'); switch ($match[1]) { case 'php': $cbclass = '_php'; break; case 'html4strict': $cbclass = '_html'; break; case 'c': case 'cpp': $cbclass = '_c'; break; case 'asm': $cbclass = '_asm'; break; } return '
    ' . '
    ' . $geshi->parse_code() . '
    ' . '' . '
    '; } function parse_smileys($text) { $result = mysql_query('SELECT * FROM smileys;'); for ($i = 0; $i < mysql_num_rows($result); $i++) { $row = mysql_fetch_assoc($result); $text = str_replace($row['text'], '' . $row['text'] . '', $text); } return $text; } function parse($text) { $text = strip_tags($text, '
    '); // bold, italic, underline, and strikethrough // These are worse than sed. Not only do you have to escape stuff, you have to // escape it again for PHP. $text = preg_replace('/(?\1', $text); $text = preg_replace('/%\*\*/', '**', $text); $text = preg_replace('/(?\1', $text); $text = preg_replace('/(\\\\)\/\//', '//', $text); $text = preg_replace('/(?\1', $text); $text = preg_replace('/(\\\\)__/', '__', $text); $text = preg_replace('/(?\1', $text); $text = preg_replace('/(\\\\)--/', '--', $text); // lists $text = preg_replace_callback('/\[(end)?(#)?list\]/m', 'make_list', $text); $text = preg_replace_callback('/(\s*)\*(.+)$/smU', 'make_li', $text); // external links $text = convert_urls($text); // links to wiki pages $text = preg_replace_callback('/(?', $text); // headers $text = preg_replace_callback('/(?', $text); $text = str_replace('
    ', '', $text); // code blocks $text = preg_replace_callback('/\[code=(.+)\](.+)\[endcode\]/smU', 'code_block', $text); $text = preg_replace_callback('/~~(.*)~~/sU', 'get_tag', $text); return $text; } ?>