Uutiset:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu
Advertisement:

Adding custom (parsing) function to BB code

Aloittaja Dusicka, huhtikuu 12, 2012, 02:36:23 AP

« edellinen - seuraava »

Dusicka

Hi, is there any way how to add custom function which will parse text inside custom BB code tag?

Here is what I'm trying to do:


function customtag_bbc_codes(&$codes)
{
$codes[] = array(
'tag' => 'customtag', 
'type' => 'unparsed_content',
'content' => custom_function($1)
);
}


Even when I use:

add_integration_function('integrate_pre_include', '$sourcedir/Subs-CustomFunctionSource.php', true);

I'm still getting error that I'm trying to call an undefined function.

For example. I want BBC tag which will convert text in tags to a table with some data from database (name of image, item description, etc.)).

[customtag]
2x Orange
5x Banana
10x Apple
[/customtag]


And the result will be something like this:


<table>
<tr><th>Image</th><th>Item name</th><th>Count</th></tr>
<tr><td><img src="1115.png" /></td><td>Orange (Item description)</td><td>2</td></tr>
<tr><td><img src="1116.png" /></td><td>Banana (Item description)</td><td>5</td></tr>
<tr><td><img src="1118.png" /></td><td>Apple (Item description)</td><td>10</td></tr>
</table>


Is that posible? What I'm doing wrong?

emanuele

Hello Dusicka and welcome to sm.org!

I'd suggest you to have a look at the already exists tags in Subs.php.
In order to set a custom function you need to use 'validate' and create_function.

For example, in your case you could do something like:
function customtag_bbc_codes(&$codes)
{
$codes[] = array(
'tag' => 'customtag', 
'type' => 'unparsed_content',
'content' => '$1',
'validate' => create_function('&$tag, &$data, $disabled', '
// here your code
$data = $your_table;
'),
);
}[/cde]


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Dusicka

Thank you very much! It's working now exactly how I want it.

emanuele



Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

altdot

I have a follow-up question to this. I've got a function that I originally wrote as an ssi_include. It's an enhancement to an old tagging mod, that will load a list of topics tagged with a given tag. (Sorry! Too many "tags"-- I know it's confusing.)

Example
function ssi_tagged_topics( $tag )

Called like this:
ssi_tagged_topics( 'BBC support topics' );

This creates a bullet list of linked topics that have been tagged with $tag:

I would like to call it something like this:


[taglist]BBC support topics[/taglist]


It's a reasonably complex function, not really appropriate to dumping into Subs.php. Is there a way I can call it from within Subs, when I'm defining my bbcode tag? (I can put the custom function elsewhere, it was just first used as SSI.)

Thanks!

ETA: to clarify, this would be called manually by moderators when they add a topic note via the Topic and Board Note mod; it's not going to be added to the message textbox icons.

All Colours Sam

SMF allows for standalone tags like [hr]

You can define a single code tag like [tag]

Using the 'validate' option you can build an on-the-fly function via create_function()

create_function('&$tag, &$data, $disabled', '
            
$data = function ssi_tagged_topics( $tag );

         '),

if you want a specific tags then build a normal bbc tag: [tag]tag[/tag]

Of course this will seriously gonna hurt your server.
Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

altdot

Thanks! That worked. (And I've also worked out an alternate way to implement the related tagged topics view.)

Advertisement: