From e7aa66fe5edf8dea9bf47c48efc197535c570962 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Wed, 10 Dec 2008 16:27:32 -0500 Subject: Created own bbcode system To be able to test for Internet Explorer troubles, the dependency on the bbcode PECL module had to be dropped, and so it has been. Hopefully this BBCode module works. --- includes/bbcode.php | 193 ++++++++++++++++++++-------------------------------- 1 file changed, 75 insertions(+), 118 deletions(-) (limited to 'includes/bbcode.php') diff --git a/includes/bbcode.php b/includes/bbcode.php index 4a1870a..e4b3d7f 100755 --- a/includes/bbcode.php +++ b/includes/bbcode.php @@ -22,130 +22,87 @@ if (!defined('S_INCLUDE_FILE')) {define('S_INCLUDE_FILE',1);} require('headerproc.php'); -$bbcode = bbcode_create(array('' => array('type' => BBCODE_TYPE_ROOT))); - -// [b][/b] - Bold -bbcode_add_element($bbcode,'b',array( 'type' => BBCODE_TYPE_NOARG, - 'open_tag' => '', - 'close_tag' => '')); - -// [i][/i] - Italic -bbcode_add_element($bbcode,'i',array( 'type' => BBCODE_TYPE_NOARG, - 'open_tag' => '', - 'close_tag' => '')); - -// [url][/url] - [url=][/url] - Link -bbcode_add_element($bbcode,'url',array( 'type' => BBCODE_TYPE_OPTARG, - 'open_tag' => '', - 'close_tag' => '', - 'default_arg' => '{CONTENT}')); - -// [img][/img] - [img=][/img] - Image -bbcode_add_element($bbcode,'img',array( 'type' => BBCODE_TYPE_OPTARG, - 'open_tag' => '{PARAM}', - 'default_tag' => '{CONTENT}')); - -// [big][/big] - Big -bbcode_add_element($bbcode,'big',array( 'type' => BBCODE_TYPE_NOARG, - 'open_tag' => '', - 'close_tag' => '')); - -// [small][/small] - Small -bbcode_add_element($bbcode,'small',array( 'type' => BBCODE_TYPE_NOARG, - 'open_tag' => '', - 'close_tag' => '')); - -// [ul][/ul] - Unordered List -bbcode_add_element($bbcode,'ul',array( 'type' => BBCODE_TYPE_NOARG, - 'open_tag' => '', - 'childs' => 'li')); - -// [ol][/ol] - Ordered List -bbcode_add_element($bbcode,'ol',array( 'type' => BBCODE_TYPE_NOARG, - 'open_tag' => '
    ', - 'close_tag' => '
', - 'childs' => 'li')); - -// [li][/li] - List Item -bbcode_add_element($bbcode,'li',array( 'type' => BBCODE_TYPE_NOARG, - 'open_tag' => '
  • ', - 'close_tag' => '
  • ')); - -// [code][/code] - Code -bbcode_add_element($bbcode,'code',array( 'type' => BBCODE_TYPE_NOARG, - 'open_tag' => '', - 'close_tag' => '')); - -// [pre][/pre] - Preformatted Code -bbcode_add_element($bbcode,'pre',array( 'type' => BBCODE_TYPE_NOARG, - 'open_tag' => '

    ',
    -					'close_tag' => '
    ')); - -function bb_fixCode($string) +class BBCode { - $he = htmlentities($string); - $br = nl2br($he); - $sp = str_replace(' ',' $nbsp;',$br); - $ta = str_replace(' ','      ',$sp); - return($ta); + var $init = false; + var $bbcodes; + var $bbcodes2; + + function init() + { + $this->bbcodes['b'] = '{CONTENT}'; + $this->bbcodes['i'] = '{CONTENT}'; + $this->bbcodes['url'] = '{CONTENT}'; + $this->bbcodes2['url'] = '{CONTENT}'; + $this->bbcodes['img'] = ''; + $this->bbcodes2['img'] = '{PARAM}'; + $this->bbcodes['big'] = '{CONTENT}'; + $this->bbcodes['small'] = '{CONTENT}'; + $this->bbcodes['ul'] = ''; + $this->bbcodes['ol'] = '
      {CONTENT}
    '; + $this->bbcodes['li'] = '
  • {CONTENT}
  • '; + $this->bbcodes['code'] = '{CONTENT}'; + $this->bbcodes['pre'] = '

    {CONTENT}
    '; + $this->bbcodes2['blog'] = '{CONTENT}'; + $this->bbcodes['ins'] = '{CONTENT}'; + $this->bbcodes['del'] = '{CONTENT}'; + $this->bbcodes['bquote'] = '

    {CONTENT}
    Anonymous
    '; + $this->bbcodes2['bquote'] = '

    {CONTENT}
    {PARAM}
    '; + $this->bbcodes2['abbr'] = '{CONTENT}'; + $this->bbcodes['hidden'] = '
    {CONTENT}
    '; + + $this->init = true; + } + + function parseBBCode($text) + { + if (!$this->init) + { + $this->init(); + } + + $to_parse = str_replace("\n",'[br]',htmlentities($text)); + + foreach ($this->bbcodes as $name => $value) + { + while (strpos($to_parse, '[' . $name . ']') !== FALSE) + { + $bbcode_uid = unique_id(); + $to_parse = substr_replace($to_parse, '[' . $name . ':' . $bbcode_uid . ']', strpos($to_parse, '[' . $name . ']'), strlen($name) + 2); + $to_parse = substr_replace($to_parse, '[/' . $name . ':' . $bbcode_uid . ']', strpos($to_parse, '[/' . $name . ']'), strlen($name) + 3); + + $value = str_replace('{CONTENT}', '\1', $value); + $to_parse = preg_replace('/\[' . $name . ':' . $bbcode_uid . '\](.*)\[\/' . $name . ':' . $bbcode_uid . '\]/', $value, $to_parse); + } + } + + foreach ($this->bbcodes2 as $name => $value) + { + while (strpos($to_parse, '[' . $name . '=') !== FALSE) + { + $bbcode_uid = unique_id(); + $to_parse = substr_replace($to_parse, '[' . $name . ':' . $bbcode_uid . '=', strpos($to_parse, '[' . $name . '='), strlen($name) + 2); + $to_parse = substr_replace($to_parse, '[/' . $name . ':' . $bbcode_uid . ']', strpos($to_parse, '[/' . $name . ']'), strlen($name) + 3); + + $value = str_replace('{PARAM}', '\1', $value); + $value = str_replace('{CONTENT}', '\2', $value); + $to_parse = preg_replace('/\[' . $name . ':' . $bbcode_uid . '=([^\]]*)\](.*)\[\/' . $name . ':' . $bbcode_uid . '\]/', $value, $to_parse); + } + } + + return str_replace('[br]','
    ',$to_parse); + } } -// [blog][/blog] - Blog Link -bbcode_add_element($bbcode,'blog',array( 'type' => BBCODE_TYPE_OPTARG, - 'open_tag' => (isset($oldBlog) ? '' : ''), - 'close_tag' => '', - 'default_arg' => '{CONTENT}')); - -// [quote][/quote] - Quotes DB Link -bbcode_add_element($bbcode,'quote',array( 'type' => BBCODE_TYPE_NOARG, - 'open_tag' => (isset($oldBlog) ? '#' : '#'), - 'close_tag' => '')); - -// [ins][/ins] - Insert -bbcode_add_element($bbcode,'ins',array( 'type' => BBCODE_TYPE_NOARG, - 'open_tag' => '', - 'close_tag' => '')); - -// [del][/del] - Delete -bbcode_add_element($bbcode,'del',array( 'type' => BBCODE_TYPE_NOARG, - 'open_tag' => '', - 'close_tag' => '')); - -// [bquote][/bquote] - Blockquote -bbcode_add_element($bbcode,'bquote',array( 'type' => BBCODE_TYPE_OPTARG, - 'open_tag' => '

    ', - 'close_tag' => '
    {PARAM}
    ', - 'default_arg' => 'Anonymous')); - -// [project][/project] - Project Link -bbcode_add_element($bbcode,'project',array( 'type' => BBCODE_TYPE_NOARG, - 'open_tag' => (isset($oldBlog) ? '' : ''), - 'close_tag' => '')); - -// [abbr][/abbr] - Abbreviation -bbcode_add_element($bbcode,'abbr',array( 'type' => BBCODE_TYPE_OPTARG, - 'open_tag' => '', - 'close_tag' => '', - 'default_arg' => '')); - -// [br] - Line Break -bbcode_add_element($bbcode,'br',array( 'type' => BBCODE_TYPE_SINGLE, - 'open_tag' => '
    ')); - -// [hidden][/hidden] - Hidden Text -bbcode_add_element($bbcode,'hidden',array( 'type' => BBCODE_TYPE_OPTARG, - 'open_tag' => '
    ', - 'close_tag' => '
    ', - 'default_arg' => '')); - function parseBBCode($text) { global $bbcode; - $to_parse = str_replace("\n",'[br]',htmlentities($text)); - $to_parse = bbcode_parse($bbcode,$to_parse); - return str_replace('[br]','',$to_parse); + if (!isset($bbcode)) + { + $bbcode = new BBCode(); + } + + return $bbcode->parseBBCode($text); } ?> -- cgit 1.4.1