I'm trying to write a mod that lets the user place an attachment within the post. I would like to do this with the integrate_bbc_codes hook, with a bbc code syntax similar to
[attach params]<attachment id>[/attach]
Where <attachment id> is the nth attachment of that message. However, I need the message id of the message that is being run through the parse_bbc function at that time.
The custom code would look something like this:
array(
'tag' => 'attach',
'type' => 'unparsed_content',
'parameters' => array(
'width' => array('optional' => true, 'value' => '$1', 'match' => '(\d+)'),
'height' => array('optional' => true, 'value' => '$1', 'match' => '(\d+)'),
),
'content' => '<div style="width:{width}px;height:{height}px;">$1</div>',
'validate' => create_function('&$tag, &$data, $disabled', '
$file = get_attachment($data, $message_index); //Custom function
if($file)
{
// Process
}
else
{
// Something else
}
'),
'disabled_content' => '($1)',
),
I noticed that in the prepareDisplayContext() function of Display.php, it passes the message index to parse_bbc. However, this parse_bbc function call skips the codes array, so the message index doesn't make it anyway.
What's the best way to get the message index?
Well, it's not elegant but I just referenced an external function from the bbc codes array, then set a global message id variable from Display.php so that I could access it from that function.