/** * Convert 2 to x line breaks of plain text into correct <p> and <br> */ function plaintext_htmlencode($text = '', $encode_function = 'html_specialchars', $render_bbcode = true) { $text = trim($text); if ($text) { $text = '[p]' . preg_replace('/\\s{0,}\\n\\s{0,}\\n\\s{0,}/s', '[/p][p]', $text) . '[/p]'; $text = preg_replace('/\\s{0,}\\n\\s{0,}/s', '[br]', $text); $text = $encode_function($text); $text = str_replace(array('[/p][p]', '[p]', '[/p]', '[br]'), array("</p>\n<p>", '<p>', '</p>', "<br />\n"), $text); if ($render_bbcode) { return render_bbcode_basics($text); } } return $text; }
function html_parser($string) { // parse the $string and replace all possible // values with $replace if (trim($string) == '') { return $string; } $string = render_bbcode_basics($string, ''); $search = array(); $replace = array(); // page TOP link if (strpos($string, '[TOP]') !== false) { $search[0] = '/\\[TOP\\](.*?)\\[\\/TOP\\]/s'; $replace[0] = '<a href="' . rel_url() . '#top" class="' . $GLOBALS['template_default']['classes']['link-top'] . '">$1</a>'; } // external Link (string) $search[1] = '/\\[EXT (.*?)\\](.*?)\\[\\/EXT\\]/s'; $replace[1] = '<a href="$1" target="_blank" class="' . $GLOBALS['template_default']['classes']['link-external'] . '">$2</a>'; // internal Link (string) $search[2] = '/\\[INT (.*?)\\](.*?)\\[\\/INT\\]/s'; $replace[2] = '<a href="$1" class="' . $GLOBALS['template_default']['classes']['link-internal'] . '">$2</a>'; // insert non db image right $search[3] = '/\\{SPACER:(\\d+)x(\\d+)\\}/'; $replace[3] = '<span class="' . $GLOBALS['template_default']['classes']['spaceholder'] . '" style="width:$1px;height:$2px;display:inline-block;"></span>'; // RSS feed link $search[4] = '/\\[RSS (.*?)\\](.*?)\\[\\/RSS\\]/s'; $replace[4] = '<a href="feeds.php?feed=$1" target="_blank" class="' . $GLOBALS['template_default']['classes']['link-rss'] . '">$2</a>'; // back Link (string) $search[5] = '/\\[BACK\\](.*?)\\[\\/BACK\\]/i'; $replace[5] = '<a href="#" target="_top" title="go back" onclick="history.back();return false;" class="' . $GLOBALS['template_default']['classes']['link-back'] . '">$1</a>'; // span or div style $search[6] = '/\\[(span|div)_style:(.*?)\\](.*?)\\[\\/style\\]/s'; $replace[6] = '<$1 style="$2">$3</$1>'; // span or div class $search[7] = '/\\[(span|div)_class:(.*?)\\](.*?)\\[\\/class\\]/s'; $replace[7] = '<$1 class="$2">$3</$1>'; $search[8] = '/\\[acronym (.*?)\\](.*?)\\[\\/acronym\\]/is'; $replace[8] = '<acronym title="$1">$2</acronym>'; // this parses an E-Mail Link without subject (by Florian, 21-11-2003) $search[9] = '/\\[E{0,1}MAIL (.*?)\\](.*?)\\[\\/E{0,1}MAIL\\]/is'; $replace[9] = '<a href="mailto:$1" class="' . $GLOBALS['template_default']['classes']['link-email'] . '">$2</a>'; $search[10] = '/\\[E{0,1}MAIL\\](.*?)\\[\\/E{0,1}MAIL\\]/is'; $replace[10] = '<a href="mailto:$1" class="' . $GLOBALS['template_default']['classes']['link-email'] . '">$1</a>'; // this tags out a Mailaddress with an predifined subject (by Florian, 21-11-2003) $search[11] = '/\\[MAILSUB (.*?) (.*?)\\](.*?)\\[\\/MAILSUB\\]/is'; $replace[11] = '<a href="mailto:$1?subject=$2" class="' . $GLOBALS['template_default']['classes']['link-email'] . '">$3</a>'; $search[12] = '/\\[blockquote (.*?)\\](.*?)\\[\\/blockquote\\]/is'; $replace[12] = '<blockquote cite="$1">$2</blockquote>'; // create "make bookmark" javascript code $search[13] = '/\\[BOOKMARK\\s{0,}(.*)\\](.*?)\\[\\/BOOKMARK\\]/is'; $replace[13] = '<a href="#" onclick="return BookMark_Page(\'$1\');" title="$1" class="' . $GLOBALS['template_default']['classes']['link-bookmark'] . '">$2</a>'; // ABBreviation $search[14] = '/\\[abbr (.*?)\\](.*?)\\[\\/abbr\\]/is'; $replace[14] = '<abbr title="$1">$2</abbr>'; $search[15] = '/\\[dfn (.*?)\\](.*?)\\[\\/dfn\\]/is'; $replace[15] = '<dfn title="$1">$2</dfn>'; $string = preg_replace($search, $replace, $string); $string = parse_cnt_urlencode($string); // internal Link to article ID or alias $string = preg_replace_callback('/\\[ID (.*?)\\](.*?)\\[\\/ID\\]/s', 'html_parse_idlink', $string); // anchor or page link $string = preg_replace_callback('/\\{[aA]:(.+?)\\}/', 'get_link_anchor', $string); $string = str_replace(array('\'', '&quot;', '-//-', ' class=""', '<br>'), array(''', '"', ' ', '', '<br />'), $string); return $string; }