News:

SMF 2.1.6 has been released! Take it for a spin! Read more.

Main Menu

Adding a new BBC tag + button in a very specific position?

Started by Turrican3, March 30, 2022, 07:28:30 AM

Previous topic - Next topic

Turrican3

Hey there, I've just upgraded my board to SMF 2.1.1 and I'm extremely pleased with the new features!

Since I've always strived for simplicity, I decided to keep plugins to a bare minimum (also to avoid possible future issues)

Now, to keep forum content *and* visuals the same as before, I'd like to reintroduce a spoiler BBC tag.

I already have all the necessary javascript code (I don't want a dedicated box but simply a clickable area that will reveal/hide its content with a mouse button), but looking at the updated SMF sources that the old, pre 2.x SMF plugin wanted to change I understand things should be done a bit differently now, but I'm not sure exactly HOW. What I understand is that there are certain things that are deprecated, but not being very knowledgeable about SMF structure nor PHP I need a bit of help to achieve the desired outcome.

So I'd like to ask:

1. where do I need to put the required changes to keep the modification SMF 2.x-compliant
2. if it is possible to add a dedicated, standalone spoiler button (i.e. not grouped with any other buttons) in the SCeditor window, possibly before the justification section, and how

Any help will be greatly appreciated. :)

Doug Heffernan

I have moved this to the Smf Coding Discussion forum. It will help if you posted the code that you have.

P.s. Is this something that you want to code/develop yourself, or were you using a 2.0.x mod and want to have it upgraded for 2.1.x btw?

Turrican3

Thank you so much, I was unsure to be honest if that was the relevant area or not.

Regarding your question, I guess it's a bit like... both?

Let me explain.

The original mod (Inline Hover Spoiler, still available here) didn't work as I wanted to, so back then (pre-2.x days, many years ago) I changed the code so that the spoilered text worked as I described.

As I said though, the mod apparently isn't doing the things it needs to to stay 2.x-compliant, so I'm willing to change the installation code myself. I believe I can do that (I'm a programmer after all, just not a PHP one), with some help.

Here's the currently installed mod:

<?xml version="1.0"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">

<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
<id>fangs404:inlinehoverspoiler</id>
<version>1.5 modified</version>

<file name="$languagedir/Modifications.english.php">
<operation>
<search position="end" />
<add><![CDATA[$txt['spoiler_post'] = 'Spoiler';]]></add>
</operation>
</file>
<file name="$sourcedir/Subs.php">
<operation>
<search position="after"><![CDATA[
array(
'tag' => 'white',
'before' => '<span style="color: white;" class="bbc_color">',
'after' => '</span>',
),
]]></search>
<add><![CDATA[
array(
'tag' => 'spoiler',
'before' => '<span style="color: #CCCCCC; background: #CCCCCC;" onclick="var colore=this.style.color.toLowerCase(); this.style.color= (colore==\'#000000\' || colore==\'rgb(0, 0, 0)\') ? \'#CCCCCC\' : \'#000000\';">',
'after' => '</span>',
),
]]></add>
</operation>
</file>
<file name="$sourcedir/Subs-Editor.php">
<operation>
<search position="after"><![CDATA[
array(
'code' => 'strike',
'description' => $editortxt['strikethrough']
),]]></search>
<add><![CDATA[
array(
'image' => 'spoiler',
'code' => 'spoiler',
'before' => '[spoiler]',
'after' => '[/spoiler]',
// 'description' => $editortxt['spoiler_post']
),]]></add>
</operation>
</file>
</modification>

Regarding the button, I understand things are very different as well now that the "old" editor has been replaced by SCeditor but I could be mistaken here... anyway, any suggestions on how to put the BBC tag button exactly where I want to would be appreciated, too!

Sesquipedalian

I suggest that you start with a spoiler mod that is compatible with 2.1 and adapt it as necessary for your needs.

In fact, this one should work as a simple drop-in replacement that will be backward compatible with your existing posts without any further changes.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Turrican3

Thanks for your reply.

I've already took note of that mod, unfortunately is not a direct replacement because it puts the spoiler text inside a box. I will try to install it nevertheless, because in my pre-2.1 SMF installation there was a BBC code used to hide pictures, and that mod seems to be perfect for the job.

Back to the "ordinary" spoiler mod, I basically need directions on *where* I need to put the code. I think I already have most, if not all the required pieces, as I said though I understand I shouldn't do it the "old", pre-2.1 way (as a matter of fact the mod is currently installed and working! but again, I'd prefer to implement the function the right, non-deprecated way to avoid possible future issues)

Sesquipedalian

#5
Well, if your goal is simply to get a working spoiler mod that produces output identical to the output of the old mod you used, then just take the mod I suggested and alter its output to match what you want it to be.

If instead your goal is to learn more generally about how to make BBCode mods for SMF 2.1, then I suggest that you look at the code of HtmlButton and Details BBC for "best practices" examples of the way to structure a BBCode mod. The first one only deals with adding a button to the editor toolbar, but that's the trickiest and most obscure part and the mod's code contains lots of explanatory comments. The second one will give you a complete example of every aspect of how to add a new BBCode, although it doesn't have as much internal documentation as the first.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Turrican3


Advertisement: