BBC.pm - Bulletin Board Code Parser


NAME

BBC.pm - Bulletin Board Code Parser


SYNOPSIS

To use this module, create a new object. Then, pump text through it :)

    use YaBB3::BBC;
    my $BBC = YaBB3::BBC->new;
    #parse the message's text
    my $message          = $BBC->parseText("[b]Hi[/b] :)","John Doe");
    print "$message";
    #get the BBC and Smiley bar for the post page
    my $BBCbarforpage    = $BBC->imageBar;
    my $Smileybarforpage = $BBC->smileyBar;
    print qq!
      $BBCbarforpage <br />
      $Smileybarforpage
    !;
    #get the BBC javascript
    my $javascript       = $BBC->bbcjavascript;
    print qq!
      <script language=\"javascript\">
        $javascript
      </script>
    !;
    
    
    #get the custom save handler for tinymce
    my $javascript       = $BBC->html2bbcJavascript;
    print qq!
                <script language="javascript" type="text/javascript">
                                var YaBBURL = "<% Settings.YaBBURL %>";  // required for tinymce - emotion-plugin
                                $javascript
                </script>
    !;


DESCRIPTION

This grabs the codes and smilies from a database, and then parses them out of a message.


METHODS

 new
   creates a new BBC object
 parseText ($string_to_parse [, $substitue_for_me])
   parses a string for codes and smileys, returns the parsed string
 imageBar ()
   returns a bar of images for the BBC code
 smileyBar ()
   returns a bar of smileys
 smileyarray( $caller)
   returns an array of smilies for the side scroll down menu or smilies pop-up
   window
   $caller can be 'show_in_popup' or 'show_in_sidescroll'
 bbcjavascript ( $caller )
   returns the javascript for the BBC bar and Smiley Bar
   $caller can be IM or POST
 html2bbcJavascript
   returns a JS function that can be used as a customSaveContent-handler for tinymce
   it just converts HTML to bbc


TODO

write the following methods:

 clean
   can parse bad stuff out of a parameter


DATABASE INFO

The database needs to have the following for BBC/smilies:

  codes table needs to following fields:
      cid     -- doesn't really matter, needs to autoincrement
      code    -- what goes here [code][/code]
      output  -- what the output looks like:
        <thingy alt="PARAM" size="PARAM">DATA</thingy>
      vals    -- default values for BBC with parameters
      params  -- how many parameters there are, must match
                 the number of PARAMs in the output field
      codein  -- "no" to turn off smileys and BBC in this code block
      clean   -- a list of characters to nuke out of this code after it
                 has been parsed like --> :;"'></\}{][ <-- for example
      image   -- image to show on the post page
                 MUST be in YaBBImages directory
      simage  -- "no" to not show an image in the image bar
  smileys table needs to have the following fields
      sid     -- doesn't really matter, needs to autoincrement
      package_id -- smilies set the smiley belongs to
      code    -- what the user types to make the smiley, like :) or >:)
      img     -- what the picture of the smiley's name is
                 MUST be in YaBBImages directory
      simage  -- "no" to not show an image in the image bar

An example entry in the database for an [img] tag would be:

code: img

output: <img src="DATA" width="PARAM" height="PARAM" alt="" />

params: 2

codein: yes {we don't really want to screw up URLS}

clean: "'[]{}

image: img.gif

simage: no

You could also have this one in the same database: code: img

output: <img src="DATA" />

params: 0

codein: yes {we don't really want to screw up URLS}

clean: "'[]{}

image: img.gif

simage: yes

Default Install

This is MySQL, but it should be easy enough to understand. It is the default data put in the database for the BBC module.

 CREATE TABLE `y3_code` (
   `cid` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
   `code` VARCHAR( 100 ) NOT NULL ,
   `output` TEXT NOT NULL ,
   `vals` TEXT NOT NULL,
   `params` INT UNSIGNED DEFAULT '0' NOT NULL ,
   `codein` ENUM( 'yes', 'no' ) DEFAULT 'yes' NOT NULL ,
   `clean` VARCHAR( 255 ) NOT NULL ,
   `image` TEXT NOT NULL ,
   `simage` ENUM( 'yes', 'no' ) DEFAULT 'yes' NOT NULL
 ) TYPE=MyISAM;
 CREATE TABLE `y3_smilies` (
   `sid` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
   `package_id` int(10) DEFAULT 1,
   `code` VARCHAR( 100 ) NOT NULL ,
   `img` VARCHAR( 255 ) NOT NULL ,
   `simage` ENUM( 'yes', 'no' ) NOT NULL
 ) TYPE=MyISAM;
 INSERT INTO `y3_code` VALUES ('', 'image', '<img src="DATA" width="PARAM" height="PARAM" alt="" />', '2', 'yes', '"\'[]{}', '', 'no');
 INSERT INTO `y3_code` VALUES ('', 'image', '<img src="DATA" alt="" />', '0', 'yes', '"\'[]{}', 'img.gif', 'yes');
 INSERT INTO `y3_code` VALUES ('', 'url', '<a href="PARAM">DATA</a>', '1', 'yes', '"\'[]{}', '', 'no');
 INSERT INTO `y3_code` VALUES ('', 'url', '<a href="DATA">DATA</a>', '0', 'yes', '"\'[]{}', 'url.gif', 'yes');
 INSERT INTO `y3_code` VALUES ('', 'quote', '<B>Quote:</B><table cellspacing="1" width="90%" class="borders"><tr><td style="width: 100%"><table cellpadding="2" cellspacing="0" class="quote" width="100%"><tr><td style="width: 100%">DATA</td></tr></table></td></tr></table>', '0', 'yes', '', 'quote.gif', 'yes');
 INSERT INTO `y3_code` VALUES ('', 'quote', '<B>on PARAM, PARAM wrote:</B><table cellspacing="1" width="90%" class="borders"><tr><td style="width: 100%"><table cellpadding="2" cellspacing="0" class="quote" width="100%"><tr><td style="width: 100%">DATA</font></td></tr></table></td></tr>.</table>', '2', 'yes', '', '', 'no');
 INSERT INTO `y3_code` VALUES ('', 'code', '<B>Code:</B><table class="borders" cellspacing="1" width="90%"><tr><td><table cellpadding="2" cellspacing="0" class="code" width="100%"><tr><td>DATA</td></tr></table></td></tr></table>', '0', 'no', '', 'code.gif', 'yes');
 INSERT INTO `y3_code` VALUES ('', 'b', '<b>DATA</b>', '0', 'yes', '', 'bold.gif', 'yes');
 INSERT INTO `y3_code` VALUES ('', 'u', '<u>DATA</u>', '0', 'yes', '', 'italic.gif', 'yes');
 INSERT INTO `y3_code` VALUES ('', 'i', '<i>DATA</i>', '0', 'yes', '', 'underline.gif', 'yes');
 INSERT INTO `y3_code` VALUES ('', 'font', '<font name="PARAM">DATA</font>', '1', 'yes', '', 'font.gif', 'yes');
 INSERT INTO `y3_code` VALUES ('', 'size', '<font size="PARAM">DATA</font>', '1', 'yes', '', 'size.gif', 'yes');
 INSERT INTO `y3_code` VALUES ('', 'allfont', '<font name="PARAM" size="PARAM">DATA</font>', '2', 'yes', '', '', 'no');
 INSERT INTO `y3_smilies` VALUES ('', '::)', 'rolleyes.gif', 'yes');
 INSERT INTO `y3_smilies` VALUES ('', '>:(', 'grumpy.gif', 'yes');
 INSERT INTO `y3_smilies` VALUES ('', '>:)', 'devil.gif', 'yes');
 INSERT INTO `y3_smilies` VALUES ('', '???', 'question.gif', 'yes');
 INSERT INTO `y3_smilies` VALUES ('', ';)', 'wink.gif', 'yes');
 INSERT INTO `y3_smilies` VALUES ('', ';D', 'happy.gif', 'yes');
 INSERT INTO `y3_smilies` VALUES ('', ':D', 'grin.gif', 'yes');
 INSERT INTO `y3_smilies` VALUES ('', ':)', 'smile.gif', 'yes');
 INSERT INTO `y3_smilies` VALUES ('', ':(', 'sad.gif', 'yes');


AUTHORS

Matt Siegman (matt@mattsiegman.com) Torsten Mrotz (tmrotz@yabbforum.com)


COPYRIGHT

Copyright ©2000-2006, YaBB 3 Development Team. All Rights Reserved.
You may distribute this module under the terms of YaBB 3.


SEE ALSO

 BBC.pm - Bulletin Board Code Parser