MyBB Community Forums

Full Version: Plugins, markup, and a new form field
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
A question or perhaps partly a feature request. I don't know the state of how 1.2 handles things too (which is what I'm waiting for), so...

I want the ability to offer users a choice of markup, where you'd have a set of radio inputs in the post form.

Now, what I'm looking for is the MyBB-specific info to accomplish this.

In 1.1.x, I noticed a couple things, and have some questions.

- Would it be possible to move all the post parsing within postify() to a pre-supplied (but internal) plugin? That way it could be overridden by users without hacking.

For example:

function postify($message, $allowhtml = 'no', $allowmycode = 'yes', $allowsmilies = 'yes', $allowimgcode = 'yes', $archive = 0)
{
  global $db, $mybb, $theme, $plugins;

  return $plugins->run_hooks('parse_message', $message);
}

$plugins->add_hook('parse_message', 'mybb_markup');

function mybb_markup($message)
{
  global $db, $mybb, $theme, $plugins, $allowhtml, $allowmycode, $allowsmilies, $allowimgcode, $archive;

  $message = dobadwords($message);

  if ($allowhtml != 'yes')
  {
    // fix & but allow unicode
    $message = preg_replace("#&(?!\#[0-9]+;)#si", '&', $message);

    $message = str_replace(array('<','>'), array('&lt;','&gt;'), $message);
 
    if ($allowimgcode != 'yes')
    {
      $message = str_replace('<img', '&lt;img', $message);
    }
  }

  if ($allowsmilies != 'no')
  {
    if ($archive == 'yes')
    {
      $message = dosmilies($message, $mybb->settings['bburl']);
    }

    else
    {
      $message = dosmilies($message);
    }
  }

  if ($allowmycode != 'no')
  {
    $message = domycode($message, $allowimgcode);
  }

  $message = nl2br($message);

  return $message;
}

(Code modified to use CraKteR's suggestion.)

- The remove_hook function is commented out?

- What would be the procedure (hooks? etc) to add the radios and check their contents before parsing? Or perhaps I need to just add to some templates? (which ones?)

- For this markup "post preference" I'll need to add a new column to the posts table. I think I'll need to alter the table myself, correct?

- I'm pretty sure as far as the PHP side goes, I've otherwise got all the hooks I need?

Hopefully it's clear what I'm talking about. Smile
Hello? Echo...

Perhaps it isn't clear what I'm talking about?
sunspark Wrote:- Would it be possible to move all the post parsing within postify() to a pre-supplied (but internal) plugin? That way it could be overridden by users without hacking.
You can use something like this:
$plugins->add_hook('parse_message', 'mybb_markup');

function mybb_markup($message)
{
  global $db, $mybb, $theme, $plugins, $allowhtml, $allowmycode, $allowsmilies, $allowimgcode, $archive;

  $message = dobadwords($message);

  if ($allowhtml != 'yes')
  {
    // fix & but allow unicode
    $message = preg_replace("#&(?!\#[0-9]+;)#si", '&amp;', $message);

    $message = str_replace(array('<','>'), array('&lt;','&gt;'), $message);
 
    if ($allowimgcode != 'yes')
    {
      $message = str_replace('<img', '&lt;img', $message);
    }
  }

  if ($allowsmilies != 'no')
  {
    if ($archive == 'yes')
    {
      $message = dosmilies($message, $mybb->settings['bburl']);
    }

    else
    {
      $message = dosmilies($message);
    }
  }

  if ($allowmycode != 'no')
  {
    $message = domycode($message, $allowimgcode);
  }

  $message = nl2br($message);

  return $message;
}
Adding the variables to global.
Quote:- The remove_hook function is commented out?
Not in 1.2 Smile
Quote:- For this markup "post preference" I'll need to add a new column to the posts table. I think I'll need to alter the table myself, correct?
Easily done with an ALTER TABLE query, check the mysql manual.
Quote:- I'm pretty sure as far as the PHP side goes, I've otherwise got all the hooks I need?
What do you mean?
Thanks CraKteR.

Re-stated: I want the ability to offer users a choice of markup (BBCode and Textile), where you'd have a set of radio inputs in the post form. That means I'd need a way to intercept the message posting and parse it accordingly before it is inserted into the database, and also when you edit a post. Are the necessary hooks available? or will I need to modify files?
If you look at this page you'll see all the hooks that is used in 1.1.x series.
Thanks. Must be having troubles with your site? (I can't get access to it, it just sits there forever loading...)

Edit: Ah, now it's working. Smile
This is also over at the MyBB wiki. [Wiki: MyBB_Plugin_Hooks] (Broken link, head over to docs.mybb.com instead)