Uutiset:

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

Main Menu
Advertisement:

How do I add custom BBcode to SMF 2.0 RC1 ?

Aloittaja vitalik82, maaliskuu 13, 2009, 03:28:48 IP

« edellinen - seuraava »

vitalik82

I am running SMF 2.0 RC1. I want to add more BBCode tags, but I don't know which file to edit.

onepiece

BBC tags are all in Subs.php file, parse_bbc() function.

vitalik82

There should I add the custom code in Subs.php file?

onepiece

Exactly. There is a quick documentation about creating custom BBC between lines 918-999.

Gringoire

#4
SomeBody could help me with this custom bbcode?
array(
'tag' => 'rand',
'type' => 'unparsed_content',
'content' => '<script language="JavaScript" type="text/javascript"><!--var string = "$1";var img = string.split(",");var aCaso = Math.floor(Math.random() * img.length);document.write("<img src='"+img[aCaso]+"' />");// --></script>',
),

When i put this code in my subs.php, the board is just a blank page.
I can't understand very well the quick guide to see where i'm wrong... Thank you so much.

Edit: i'm on RC4.

Edit2: I want the code give me a random image froma a provided list.
For example: [rand]IMGlink1,IMGlink2,...,IMGlinkn[/rand]

DoctorMalboro

It's kind of complicated the code you're trying to use... what would be the original javascript?

Gringoire

<script language='JavaScript' type='text/javascript'>
<!--
var string = 'links separated by commas';
var img = string.split(',');
var aCaso = Math.floor(Math.random() * img.length);
document.write("<img src='"+img[aCaso]+"' />");
// -->
</script>

DoctorMalboro

Try with this...

array(
'tag' => 'rand',
'type' => 'unparsed_content',
'content' => '<script language="JavaScript" type="text/javascript"><!--var string = "$1";var img = string.split(",");var aCaso = Math.floor(Math.random() * img.length);document.write("<img src=\'"+img[aCaso]+"\' />");// --></script>',
),

Gringoire

#8
Now i can see my board, but no image is displayed by the code... Any idea?

DoctorMalboro

what input do you put to the bbcode? this:
[rand=img1, img2, img3][/rand]

or this:
[rand]img1, img2, img3[/rand]

Gringoire

#10
this:
[rand]img1,img2,img3[/rand]

is it wrong?
edit:
I tryed the other one, and the rand bbcode is not parsed, so i don't think this is the problem.

[rand]img1,img2,img3[/rand]

should be correct, but it seems that document.write does nothing...

DoctorMalboro

            array(
                'tag' => 'rand',
                'before' => '<script language="JavaScript" type="text/javascript">
                <!--
                var string = \'$1\';
                var img = string.split(\',\');',
                'after' => 'var aCaso = Math.floor(Math.random() * img.length);
                document.write("<img src=\'"+img[aCaso]+"\' />");
                // -->
                </script>',
            ),


try without type...

Gringoire

Lainaus käyttäjältä: DoctorMalboro - tammikuu 06, 2011, 12:29:02 IP
            array(
                'tag' => 'rand',
                'before' => '<script language="JavaScript" type="text/javascript">
                <!--
                var string = \'$1\';
                var img = string.split(\',\');',
                'after' => 'var aCaso = Math.floor(Math.random() * img.length);
                document.write("<img src=\'"+img[aCaso]+"\' />");
                // -->
                </script>',
            ),


try without type...

Nothing has changed... should i give up?

DoctorMalboro

not yet, buddy... we could try changing the code...

            array(
                'tag' => 'rand',
                'type' => 'unparsed_equals',
                'parameters' > array('amount' => array('optional' => false),),
                'before' => '$images = "$1";

                $separate = explode(" ", $images);',
                'after' => '
                $i = rand(1, {amount});

                <img src="\'.$separate[$i].\'" alt="" />',
                'block_level' => false,
            ),


and it should work like this [rand amount=(amount of images)]img1 img2 img3[/rand].

Gringoire

#14
[rand=2]http://www.lanuovaera.org/MGalleryItem.php?id=103 http://www.lanuovaera.org/MGalleryItem.php?id=104[/rand]
give me this:


$images = "2";                $separate = explode(" ", $images);hxxp:www.lanuovaera.org/MGalleryItem.php?id=103 [nonactive] hxxp:www.lanuovaera.org/MGalleryItem.php?id=104 [nonactive]                $i = rand(1, {amount});               

Edit:
I tryed to do this:
            array(
                'tag' => 'rand',
                'before' => '<script language="JavaScript" type="text/javascript">
                <!--
                       document.write("<p>Hello World</p>");
                // -->
                </script>',
            ),

With no result. I think there is a problem with javascript language.

DoctorMalboro

Try this... it's not as simple as it looks to add PHP code into a BBCode:

            array(
                'tag' => 'rand',
                'type' => 'unparsed_content',
                'parameters' => array('amount' => array('optional' => false),),
                'content' => '$1',
                'validate' => '$images = "$1";

                $separate = explode(" ", $images);

                $i = rand(1, {amount});

                if(is_numeric($i))
                <img src="\'.$separate[$i].\'" alt="" />',
                'block_level' => false,
            ),


Gringoire

I DID IT!

That was a real stupid Error.
<script language='JavaScript' type='text/javascript'>
var string = 'links separated by commas';
var img = string.split(',');
var aCaso = Math.floor(Math.random() * img.length);
document.write("<img src='"+img[aCaso]+"' />");
</script>

This is the solution.

DoctorMalboro

Oh, cool... never figured it out, it's not my best javascript :)

Could you leave the code so if someone else have this issue it can find this post?

Gringoire

array(
'tag' => 'rand',
'type' => 'unparsed_content',
'content' => '<script language="JavaScript" type="text/javascript">var string = "$1";var img = string.split(",");var aCaso = Math.floor(Math.random() * img.length);document.write("<img src=\'"+img[aCaso]+"\' />");</script>',
),


This Should Work.

Advertisement: