This is an interface to add/delete/modify bbcode, and handle parsing
Author: Kilandor
Submitted by: Kilandor
Date: 2008-03-18 02:42
Comments: (0)
Ratings:
 
Description
This is designed, to hopefully be approved to be placed into Seditio Core.

This is more than just a plugin, Its an Interface which allows, you to Add, Delete and Modify BBCode, without making any extra core hacks(Granted until included into the core, a core hack is required). It also handles the parsing outside the core, giving the option for people to modify it for their own needs, without being required to re-apply core hacks every patch. This also has future options, to be able to, be integrated into Textboxer, along with making it possible for users, to more easily if they chose use their own, or other textboxer, WYSIWYG editor, etc, and Allow for them to handle and do anything with BBCode as they see fit.

What does it do?
  • Gives an interface to add/delete/modify BBCode

  • Moves the parsing of BBCode, outside the core

  • Stores the BBCode, in the sql, instead of a file.

  • Builds an array, for the BBCode, which is cached and used to handle parsing.

  • BBcode is cached, for one year, unless its modified/added/deleted.


How is this usefull?
  • You can now, add BBCode, modify it, or even delete it without having to modify your core files every update(soon as it gets included in core)

  • Easily make multi-lingual BBCode, leaving all the old BBCcode to function, but making BBCode to fit the language of your site.

  • Handle BBCode however you want, have it parse, or completely rework how it works to suit your needs.

  • The ability at any time to go in and add more BBCode, without the work of editing files.

  • Modify BBcode to change how it functions.

  • With the parsing handled outside, it would be easier to integrate different forms of Textboxer, or WYSIWYG editors, of your choice.


How to setup
You may use the patch file I've created with the SVN, to do the main work for you if you want. There are 2 links, to guides on how to use it.
Download: BBCode Plugin Parser, v1beta, SVN Patch
Guide to using SVN with Windows
Guide to using SVN with *nix

If you do not wish yo use the SVN patch you may follow these instructions.

Open datats/config.php
Find
PHP Code:

$db_users       = 'sed_users';

After it add
PHP Code:

$db_bbcode      = 'sed_bbcode';


Open system/functions.php
Find
PHP Code:

function sed_bbcode($text)
    {
    global $L, $skin, $sys, $cfg, $sed_groups;

    $text = sed_bbcode_autourls($text);
    $text = " ".$text;
    /* removed the core of the function so its not so huge */
    return(substr($text,1));
    }


Replace with (functions are sperated with /* ------------------ */ Replace the full function with what is below)
PHP Code:

function sed_bbcode($text)
    {
    global $cfg, $db_bbcode, $bbcode_str, $bbcode_reg, $bbcode_vid;

    $text = sed_bbcode_autourls($text);
    $text = " ".$text;
    require("plugins/bbcode/parser/bbcode.php");
    return(substr($text,1));
    }


Find
PHP Code:

function sed_bbcode_autourls($text)
    {
    $text = ' '.$text;
    $text = preg_replace("#([\n ])([a-z0-9]+?)://([^\t \n\r]+)#i", "\1[url]\2://\3[/url]", $text);
    $text = preg_replace("#([\n ])([a-z0-9-_.]+?@[A-z0-9-]+\.[^,\t \n\r]+)#i", "\1[email]\2[/email]", $text);
    return(substr($text,1));
    }


Replace with (functions are sperated with /* ------------------ */ Replace the full function with what is below)
PHP Code:

function sed_bbcode_autourls($text)
    {
    $text = ' '.$text;
    require("plugins/bbcode/parser/bbcode_autourl.php");
    return(substr($text,1));
    }


Find
PHP Code:

function sed_bbcode_urls($text)
    {
    global $cfg;
    $bbcodes = array(
    '\[img\]([^\\'\;\?([]*)\.(jpg|jpeg|gif|png)\[/img\]' => '\1.\2',
    '\[thumb=([^\\'\;\?([]*)\.(jpg|jpeg|gif|png)\]([^\[]*)\.(jpg|jpeg|gif|png)\[/thumb\]' => '\1.\2',
    '\[pfs]([^\[]*)\[/pfs\]' => $cfg['pfs_dir'].'\1',
        );

    foreach($bbcodes as $bbcode => $bbcodehtml)
        { $text = eregi_replace($bbcode,$bbcodehtml,$text); }

    return($text);
    }


Replace with (functions are sperated with /* ------------------ */ Replace the full function with what is below)
PHP Code:

function sed_bbcode_urls($text)
    {
    global $cfg;
    require("plugins/bbcode/parser/bbcode_urls.php");
    return($text);
    }

After these changes, download the attached plugin files, and copy them into your plugin folder.
After, either method import the sql file, in the bbcode folder into your SQL Database.
Then install the plugin.

How to use
To access the control panel, goto Admin > Tools > BBcode

How to Add/Modify/Delete BBCode

  • Name: This is the name listed on in the control panel to identify the BBCode.

  • Enabled: This is used to enable BBCode to be used in parsing, if disabled that bbcode will not function.

  • Type: This Determins how BBCode is parsed.

    • Type 1, This uses str_replace to handle the parsing, its designed for single individual tags that do not have a partner closing tag.

      • Code: The BBCode to be found (ex. [ br])

      • Output: What the BBcode is to be replaced with (ex. <br />)

    • Type 2, This uses str_replace to handle the parsing, its designed for double tags that have a partner closing tag. These are treated a little differently and use comma separation which are split later on. This is used, to prevent having to have 2 Entries for each set.

      • Code: The BBCode to be found (ex. [ b],[ /b])

      • Output: What the BBcode is to be replaced with (ex. <strong>,</strong>)

    • Type 3, This uses eregi_replace to handle the parsing, its designed for using regex, to handle, special searching in the text to meet requirements.

      • Code: The BBCode to be found (ex. \[img\]([^\\';?([]*).(jpg|jpeg|gif|png)\[/img\])

      • Output: What the BBcode is to be replaced with (ex. <img src="\1.\2" alt="" />)

    • Type 4, This uses eregi_replace to handle the parsing, its designed for using regex, to handle, special searching in the text to meet requirements. This is used, special to handle Video Emeded Parsing, due to it having a specific config option to enable/disable it (Though this should become obsolete in the future due to this plugin, since specfic BBCode can be enabled and Disabled)

      • Code: The BBCode to be found (ex. \[img\]([^\\';?([]*).(jpg|jpeg|gif|png)\[/img\])

      • Output: What the BBcode is to be replaced with (ex. <img src="\1.\2" alt="" />)

  • Textboxer Enabled: This is used to enable BBCode to be used in Textboxer, if disabled that bbcode will not show up in Textboxer.

  • Structure: (No Function yet)This will be used by textboxer, to determine the order/depth the bbcode should be ordered in.

  • Textboxer Text: (No Function yet)This is the main text used by Textboxer to show the button.

  • Textboxer Icon: (No Function yet)This will be the icon used by Textboxer for the BBcode, (must be web accessible)

  • Textboxer HoverText: (No Function yet)This is the text that shows up, with a little more info when you hover over the icon.

  • Code: This, is where the BBcode, is put. Details for the types are listed above, but note for regex, You do not have to Escape
    everything, due to it not being in PHP. (ex. This would work, "\[img\]([^\\';?([]*).(jpg|jpeg|gif|png)\[/img\]", However, this would not work and be incorect "\\[img\\]([^\\\'\;\?([]*)\.(jpg|jpeg|gif|png)\\[/img\\]")

  • output: This, is where the what the BBCode is to be replaced with is put. Details for the types are listed above, but note for regex, You do not have to Escape everything, due to it not being in PHP. (ex. This would work, "<img src="\1.\2" alt="" />", However, this would not work and be incorect "<img src="\\1.\\2" alt="" />")

  • Delete: (Found in modify only) Used to permanently delete the BBCode from the SQL


Updates
If updating with SVN patch file, delete all your "bbcode" folder, in /plugins/
If updating with the downloadable files just overwrite all your files

  • March 6 2008:

    • [bug] - Fixed, Enabled/Disable Options on Front Page

    • [minor] - Removed a couple lines of debug and useless code

  • March 18 2008:

    • [bug] - Fixed, missing global variables for sed_bbcode function, causing it to query and build the array every sed_bbcode - reapply the function sed_bbcode with the above section highlighted in orange this fix is listed on the page


Notes
This, is considered beta, it should be perfectly fine to use on live sites. In my tests everything worked fine.
Currently there is no integration into Textboxer, this will be the next main goal.
If you have any problems, bugs, questions, etc feel free to ask. You may post here.
http://www.seditioforge.com/forums/plug-ins-and-modifications-s5.html



Download : BBCode
Size: 11KB, downloaded 152 times
Copyright © 2008 Domain.Com. All Rights Reserved.
Page created in 0.499 seconds