Use BBCode with custom text field?

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
BMonkey
Registered User
Posts: 3
Joined: Wed Jun 21, 2006 2:40 am

Use BBCode with custom text field?

Post by BMonkey »

Please forgive me if this has already been addressed or is in the knowledge database, but I could not find it there nor is search behaving for me at the moment.

I have been working on a custom modification/add-on and I’ve come to the point that I need to take user input from a textarea form field and format it to accept BBCode use. I’ve dug around the files (bbcode.php, functions_post.php, and functions.php) and have yet to understand how this works. Could someone please explain to me how to take data from a textarea that a user has input and make it recognize BBCode? And in turn how to display it when editing in the future with BBCode tags?


Thank you very much in advance.

J. Miller (BMonkey)
Mondego
Registered User
Posts: 129
Joined: Sun Jan 23, 2005 1:24 am
Location: 127.0.0.1
Contact:

Post by Mondego »

i'm not sure what you mean. do you mean you want to utilize the built-in bbcode features in your own <textarea> field?
BMonkey
Registered User
Posts: 3
Joined: Wed Jun 21, 2006 2:40 am

Post by BMonkey »

Yea...

I need to know how to take user input (a user who uses bbcode in a textarea) and make it display like it should with the bbcode tags... I know there is the whole first and second pass functions and a way to convert it back to that for editing, but I'm not sure how to use them....

This, I suppose, is not so easy to explain.
User avatar
UseLess
Registered User
Posts: 521
Joined: Mon Jul 22, 2002 7:26 pm
Location: North East UK

Post by UseLess »

Greetings,

The quick explanation...
  1. Get data from form
  2. Get a bbcode_uid, function for this is in 'includes/bbcode.php'
  3. Run the text from the textarea through 'bbencode_first_pass' and then store it in the db, along with the 'bbcode_uid'.
  4. To display the text run it through 'bbencode_second_pass' and optionally 'smilies_pass' before displaying it
  5. To edit the text run the message through the following if the 'bbcode_uid' is not empty;

    Code: Select all

    if ( $bbcode_uid != '' )
    {
    	$message = preg_replace('/\:(([a-z0-9]:)?)' . $bbcode_uid . '/s', '', $message);
    }
    Where '$message' holds the message text and '$bbcode_uid' holds the stored ID, this will then strip out the 'bbcode_uid' leaving the BBCode Tags as they were originally entered.
Movie Quote:
It's not the years honey, it's the mileage...
phpBB 3 Mods @ phpBBStyles
BMonkey
Registered User
Posts: 3
Joined: Wed Jun 21, 2006 2:40 am

Post by BMonkey »

Thank you very much!

I had, through searching 25+ pages of this forum and digging in various phpbb files, gotten to where it would display. But I kept getting hung up on getting it to reduce it to the bbcode tags for editing...

My mistake was that I was 'bbencode_second_pass' ing it before storing... those files really read like greek some times >.<

Well I got it working now so THANK YOU again!

J. Miller (BMonkey)
Mondego
Registered User
Posts: 129
Joined: Sun Jan 23, 2005 1:24 am
Location: 127.0.0.1
Contact:

Post by Mondego »

UseLess wrote: Greetings,

The quick explanation...
  1. Get data from form
  2. Get a bbcode_uid, function for this is in 'includes/bbcode.php'
  3. Run the text from the textarea through 'bbencode_first_pass' and then store it in the db, along with the 'bbcode_uid'.
  4. To display the text run it through 'bbencode_second_pass' and optionally 'smilies_pass' before displaying it
  5. To edit the text run the message through the following if the 'bbcode_uid' is not empty;

    Code: Select all

    if ( $bbcode_uid != '' )
    {
    	$message = preg_replace('/\:(([a-z0-9]:)?)' . $bbcode_uid . '/s', '', $message);
    }
    Where '$message' holds the message text and '$bbcode_uid' holds the stored ID, this will then strip out the 'bbcode_uid' leaving the BBCode Tags as they were originally entered.


thanks useless. i kept wondering about the bbcode uid thing. i guess if anything's going in the db than you need an id.
Post Reply

Return to “[2.0.x] MOD Writers Discussion”