3 Replies - 2198 Views - Last Post: 01 March 2011 - 03:44 PM

#1 f1sh   User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 16-October 07

BBCode Class

Posted 18 October 2007 - 07:34 AM

Description: Use coverparse() to make sure there is bbcode to parse (for performance) Enjoy :DThis function will parse BBCode Tags.
class bbcode
{
        // Send all text to be parsed here!
	function coverpass($text)
	{
		// Checks if there are any BBCode Tags
		$istag = strrpos($text, "]");
		if($istag == 0)
			return $text; // Nope, return the text
		else
			return $this->parsetags($text); // Yup, Parse Them
	}
	
	function parsetags($text)
	{
		// This is used in some blogging applications, can be uncommented for that application
		//$text = str_replace("[more]", "Continued...", $text);
		
		// Lets do some generic checks
		$text = preg_replace("([b](.+?)[/b])is", '$1', $text); // Bold
		$text = preg_replace("([i](.+?)[/i])is", '$1', $text); // Italics
		$text = preg_replace("([u](.+?)[/u])is", '$1', $text); // Underline
		$text = preg_replace("([s](.+?)[/s])is", '$1', $text); // Strike through
		$text = preg_replace("([o](.+?)[/o])is", '$1', $text); // Overline
		$text = preg_replace("([font=(.+?)](.+?)[/font])", '$2', $text); // Font
		$text = preg_replace("([color=(.+?)](.+?)[/color])is", '$2', $text); // Color
		$text = preg_replace("([size=(.+?)](.+?)[/size])is", '$2', $text); // Font-Size
		$text = preg_replace("/[list](.+?)[/list]/is", '
    $1
', $text); // List $text = str_replace("[*]", "
  • ", $text); // List-Item // Code and Quote Tags $text = preg_replace("([code](.+?)[/code])is", '$1', $text); // Code $text = preg_replace("([quote](.+?)[/quote])is", '$1', $text); // Quote // Allow images? if(isset($GLOBALS['allow_image']) && ($GLOBALS['allow_image'] == 1)) { $text = preg_replace("/[img](.+?)[/img]/", '', $text); // Image $text = preg_replace("/[img=([0-9]*)x([0-9]*)](.+?)[/img]/", '', $text); //Image with width and height } else { $text = preg_replace("/[img](.+?)[/img]/", 'Admin has not allowed images!', $text); // Image $text = preg_replace("/[img=([0-9]*)x([0-9]*)](.+?)[/img]/", 'Admin has not allowed images!', $text); //Image with width and height } // Allowed Links? if(isset($GLOBALS['allow_href']) && ($GLOBALS['allow_href'] == 1)) { $text = preg_replace("/[url]([ a-zA-Z0-9:/-?&.=_~#']*)[/url]/", '$1', $text); // Url $text = preg_replace("([url=([ a-zA-Z0-9:/-?&.=_~#']*)](.+?)[/url])", '$2', $text); // Url with text } else { $text = preg_replace("/[url]([ a-zA-Z0-9:/-?&.=_~#']*)[/url]/", 'Admin has not allowed links!', $text); // Url $text = preg_replace("([url=([ a-zA-Z0-9:/-?&.=_~#']*)](.+?)[/url])", 'Admin has not allowed links!', $text); // Url with text } // Allow EMail Links? if(isset($GLOBALS['allow_mail']) && ($GLOBALS['allow_mail'] == 1)) { $text = preg_replace("([mail]([ a-zA-Z0-9:/-?&.=_~#' [email protected]]*)[/mail])", '$1', $text); // Mail $text = preg_replace("/[mail=([ a-zA-Z0-9:/-?&.=_~#' [email protected]]*)](.+?)[/mail]/", '$2', $text); // Mail with text } else { $text = preg_replace("([mail]([ a-zA-Z0-9:/-?&.=_~#' [email protected]]*)[/mail])", 'Admin has not allowed mail links!', $text); // Mail $text = preg_replace("/[mail=([ a-zA-Z0-9:/-?&.=_~#' [email protected]]*)](.+?)[/mail]/", 'Admin has not allowed mail links!', $text); // Mail with text } // Allow Videos? if(isset($GLOBALS['allow_videos']) && ($GLOBALS['allow_videos'] == 1)) { $youtube_replacement = ' '; $text = preg_replace("/[youtube](.+?)[/youtube]/", $youtube_replacement, $text); // YouTube $youtube_replacement = ' '; $text = preg_replace("/[youtube=([0-9]*)x([0-9]*)](.+?)[/youtube]/", $youtube_replacement, $text); // YouTube with width/height $googlevid_replacement = ' '; $text = preg_replace("/[googlevid](.+?)[/googlevid]/", $googlevid_replacement, $text); // Google Video $googlevid_replacement = ' '; $text = preg_replace("/[googlevid=([0-9]*)x([0-9]*)](.+?)[/googlevid]/", $googlevid_replacement, $text); // Google Video with width/height } else { $text = preg_replace("/[youtube](.+?)[/youtube]/", 'Admin has not allowed videos!', $text); // YouTube $text = preg_replace("/[youtube=([0-9]*)x([0-9]*)](.+?)[/youtube]/", 'Admin has not allowed videos!', $text); // YouTube with width/height $text = preg_replace("/[googlevid](.+?)[/googlevid]/", 'Admin has not allowed videos!', $text); // Google Video $text = preg_replace("/[googlevid=([0-9]*)x([0-9]*)](.+?)[/googlevid]/", 'Admin has not allowed videos!', $text); // Google Video with width/height } } }

    Is This A Good Question/Topic? 0
    • +

    Replies To: BBCode Class

    #2 TogaOga   User is offline

    • New D.I.C Head

    Reputation: 0
    • View blog
    • Posts: 0
    • Joined: 20-March 08

    Re: BBCode Class

    Posted 20 March 2008 - 09:59 AM

    i'm still not sure how to translate
    Was This Post Helpful? 0
    • +
    • -

    #3 coaster3000   User is offline

    • D.I.C Head
    • member icon

    Reputation: 1
    • View blog
    • Posts: 99
    • Joined: 28-August 08

    Re: BBCode Class

    Posted 04 January 2010 - 02:43 PM

    i dont get this code either :P
    Was This Post Helpful? 0
    • +
    • -

    #4 huzi8t9   User is offline

    • D.I.C Regular
    • member icon

    Reputation: 25
    • View blog
    • Posts: 369
    • Joined: 11-July 07

    Re: BBCode Class

    Posted 01 March 2011 - 03:44 PM

    This is a really complicated way of doing BB. I, personally, use a single function in a global file.
    Was This Post Helpful? 0
    • +
    • -

    Page 1 of 1