News:

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

Main Menu

Custom bbcodes

Started by Bounty_y2k, December 27, 2014, 05:50:51 PM

Previous topic - Next topic

Bounty_y2k

Hello again.
Recently I started exploring smf bbcodes I made custom tags like these:

array(
'tag' => 'download',
'type' => 'unparsed_equals',
'before' => '<a href="$1" class="downloadbbc"><div id="downloadcont"><div id="predownload"></div><div id="downloadnasl">Download</div><div id="downloadtext">',
'after' => '</div></div></a>',
),
array(
'tag' => 'sharky',
'type' => 'closed',
'content' => '<a href="(url)" class="downloadbbc">(url)</a>',
),


These works very well.
Still I have an issue with post count based bbcodes.
Is there a way I can show bbcode depending on post count?

Eg.

array(
'tag' => 'download',
'type' => 'unparsed_equals',
'before' => if($user_info['posts'] > 50){'<a href="$1" class="downloadbbc"><div id="downloadcont"><div id="predownload"></div><div id="downloadnasl">Download</div><div id="downloadtext">'}else{'<div id="not_enough_posts"></div>'},
'after' => if($user_info['posts'] > 50){'</div></div></a>'},
),


Arantor

Whose post count? The user viewing it, or the user who made the post? One is trivial enough, the other is vastly complex.
Holder of controversial views, all of which my own.


Bounty_y2k

Oh sorry for not specifying it.
Post count of the user viewing the topic. Ofc I would have to include 'if user is admin or moderator' and 'if user is registered' along with post count more than 50.

Arantor

Untested but I suspect this would do the trick:

array(
'tag' => 'download',
'type' => 'unparsed_equals',
'before' => allowedTo('moderate_board') || $GLOBALS['user_info']['posts'] > 50 ? '<a href="$1" class="downloadbbc"><div id="downloadcont"><div id="predownload"></div><div id="downloadnasl">Download</div><div id="downloadtext">' : '<div id="not_enough_posts"></div>',
'after' => allowedTo('moderate_board') || $GLOBALS['user_info']['posts'] > 50 ? '</div></div></a>' : '',
),


You don't need to do 'user is registered' since guests cannot have a post count nor can they be moderators in a board, so it's just whether they have the right permission or the right post count - which would also be a question of 'why are they moderators if they don't have 50 posts'.

There will be issues in browsers if you have multiple of these bbcode on the page because of the use of id (which is once per page) but that's not really something I can fix :P
Holder of controversial views, all of which my own.


Bounty_y2k

Yep something like that :) , Lets just make it simpler. So if user is moderator and has more than 50 posts show this:

<div id='enough_posts'>
//content
</div>


And if not show this:

<div id='not enough_posts'></div>
//without content


Also lets call it 'bbhide' since I already have 'download' tags.

array(
'tag' => 'bbhide',
'before' => allowedTo('moderate_board') || $GLOBALS['user_info']['posts'] > 50 ? '<div id="enough_posts">' : '<div id="not_enough_posts"></div>',
'after' => allowedTo('moderate_board') || $GLOBALS['user_info']['posts'] > 50 ? '</div>' : '',
),


When trying this with 'type' parameter it fails. And when trying without it it does change the div id but the content stays the same I need it to not be showed at all. :S
I know this could be fixed with simple display:none; styling but that has a huge hole since anyone can see the page source and check for content. What am I missing?

Arantor

Yeah, switching types like that isn't entirely clever.
Holder of controversial views, all of which my own.


Bounty_y2k

Is it hard to achieve what I want? (not showing content at all) If yes i can settle with display:none; :S

Arantor

It's an absolute PITA to do. It's *all* doable, it's just a *lot* of work to actually do it properly since it really requires writing a bbcode with validate set and replacing $tag['content'] from inside the tag. If I get time I'll look at it later.
Holder of controversial views, all of which my own.


Bounty_y2k

Oh sorry didn't realize that its a *lot* of work. Don't worry about it. Ill just hide the content. Thanks for clearing all out. ;)

Arantor

It's not vast amounts of work - it's like 10 lines of code. It's just intricate to get right because of how the parser works.
Holder of controversial views, all of which my own.


Bounty_y2k

If you find something post it here. I will do it with display:none; for now.

Bounty_y2k

Sorry for double-posting.
I am just wondering if its possible to make bbcode icons (just by 'bold', 'italic', 'underline' buttons) but to be shown only to moderators and admins? So regular users can't see them but admins and mods can.

Arantor

That's doable too, but not especially easy. Take a look at Moderator and Administrator Comment Tags for an example of doing that.
Holder of controversial views, all of which my own.


Bounty_y2k

Hmm I'm a error magnet.
This is the current bbcode script:
array(
'tag' => 'bbhide1',
'before' => allowedTo('moderate_board') || $GLOBALS['user_info']['posts'] > 5 ? '<div id="enough_posts">' : '<div id="obavestenje">Some text.</div><div id="not_enough_posts">',
'after' => '</div>',
),


When I do this:
[bbcode1]test[/bbcode1]
It works like its supposed to,tried with my account,other account and like a guest works like a charm. Works with imgs,urls...but it doesn't work with lists.

This:
[bbhide1]
[list]
[li]aaa[/li]
[li]bbb[/li]
[/list]
[/bbhide1]


Becomes:

Some text.

    aaa
    bbb

[/bbhide1]

The closing tag is visible and whole code fails.

Arantor

Try setting 'block_level' => true on that tag.
Holder of controversial views, all of which my own.


Bounty_y2k

You are a magician :D Thank you again.

Bounty_y2k

I did a little research of your posts Arantor and I found a solution to displaying bbc icons only to mods and admins.
I am posting it here if someone else wants to do this.

In Subs-Editor.php find '// Show the toggle?' line. For me its 1696. line.
After that whole block of code (there is one if block) so after '}' on line 1712. add this:

//my custom bbcode images
if (allowedTo('moderate_board')){
$context['bbc_tags'][count($context['bbc_tags']) - 1][] = array(
'image' => 'download',
'code' => 'download',
'before' => '[download=]',
'after' => '[/download]',
'description' => 'your text'
);
}


image tag - name of your .gif in your_theme/images/bbc/
code tag - code name you specified in subs.php
before tag - before cursor text
after tag - after cursor text
description tag - description on hover

Arantor

Glad you found it. I knew I'd done it in that mod originally, but I haven't had the time to dig it back out, dust it off and check how I did it.
Holder of controversial views, all of which my own.


Bounty_y2k

One last thing. I can't find where is 'bbc_bg.gif' is set as background of the icon? It's not in css,not in subs nor subs-editor...it has to be somewhere inside php.
I would like to turn that off since my forum is kinda in black background so I would use different (white) iconsets for bbc.

Arantor

It's set in the bowels of the editor, somewhere inside GenericControls.template.php.

Do NOT remove the entry for it unless you want to have fun rewriting parts of the WYSIWYG editor as well. You can, however, change the image (it points to your theme's images/bbc/ folder for both bbc_bg.gif and bbc_hoverbg.gif) to something else provided that you don't attempt to remove the code that points to it because things will break.

Just change the image itself and overwrite the standard ones on the server.
Holder of controversial views, all of which my own.


Advertisement: