How to add bbcode?

Go down

Solved How to add bbcode?

Post by Sn0w on February 7th 2020, 1:15 am

Hello!
I've a few problems and questions. So let me describe them.
1. It is possible to add my own bbcode?

2. If yes, so, what I can edit/add them? To be honest I really want to implement something like hide, but not like this which is "basic" on forumotion. I search for option which allowing create "hide", but not as "comment and see". Just for example,
Code:
 [Hide=USERNICK][/HIDE]
where only that "USERNICK" can see content.

PS. If this category is wrong, sorry. Im newbie.
Sn0w
Sn0w
New Member

Posts : 21
Reputation : 1
Language : English, Polish

View user profile http://wonderful-world.forumpolish.com

Back to top Go down

Solved Re: How to add bbcode?

Post by Draxion on February 7th 2020, 2:30 am

Hello.

So let me ask this just so I'm on the correct page of what you are trying to implement. You want to use a BBcode to where you can hide content within the brackets to all users except the user indicated in the BBcode?


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as How to add bbcode? Solved11 when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

How to add bbcode? Draxio14
Draxion
Draxion
Support Moderator
Support Moderator

Male Posts : 2455
Reputation : 312
Language : English
Location : USA

View user profile https://www.talesoftellene.com/

Back to top Go down

Solved Re: How to add bbcode?

Post by Sn0w on February 7th 2020, 2:46 am

@Draxion wrote:Hello.

So let me ask this just so I'm on the correct page of what you are trying to implement. You want to use a BBcode to where you can hide content within the brackets to all users except the user indicated in the BBcode?
I'll just explain this by image
How to add bbcode? H2Rs8sV
We've there a lot of icons represents bbcode. And this what I want is add option for code. Of course if it possible to add bbcode that I mention in topic. And this is the most important thing.

To answer your question - yes, exactly.
Sn0w
Sn0w
New Member

Posts : 21
Reputation : 1
Language : English, Polish

View user profile http://wonderful-world.forumpolish.com

Back to top Go down

Solved Re: How to add bbcode?

Post by Daemon on February 7th 2020, 4:58 pm

First read the following topic: https://help.forumotion.com/t153342-tutorial-create-new-bbcode-tags?highlight=bbcode

After reading the topic and understanding how it works. Create a new JavaScript file and add:
(Placement: All Pages)
Code:
/*
 *  Application: Create New BBCode Tags
 *  Date: 18/05/2018
 *  Version: 1.321052018
 *  Copyright (c) 2018 Daemon <help.forumotion.com>
 *  This work is free. You can redistribute it and/or modify it
 */
(function() {
    BBParser = {
        initialize: function() {
            $(function() {
                BBParser.setupBBParser();
            });
        },
        add: [
            /*
            * Note: Add a comma at the end of each new entry
            * '{option}' corresponds to the optional tag title, and '{content}' correspond to the text between the tags
            */
 
            {
                tag: 'success',
                close: true,
                replacement: '<div class="notice notice-success"><h5>{option}</h5><p>{content}</p></div>'
            },
 
            {
                tag: 'warn',
                close: true,
                replacement: '<div class="notice notice-warn"><h5>{option}</h5><p>{content}</p></div>'
            },
 
            {
                tag: 'info',
                close: true,
                replacement: '<div class="notice notice-info"><h5>{option}</h5><p>{content}</p></div>'
            },
 
            {
                tag: 'alert',
                close: true,
                replacement: '<div class="notice notice-alert"><h5>{option}</h5><p>{content}</p></div>'
            },

            {
                tag: 'onlyto',
                close: true,
                replacement: '<div class="onlyto">{content}</div>',
                replace: function(option, content) {
                    if (_userdata.username != option) {
                        return 'Only ' + option + ' can view this message.';
                        return content;
                    }
                }
            },
 
            // Note: Do not add a comma at the end of the last entry
        ],
        // Do not change anything down
        validateTag: function(a) {
            if (!/^\w+$/.test(a)) throw new RangeError("You added an invalid tag: " + a);
        },
        replacers: function(a, b, c) {
            return (a || "").replace(/{option}/g, b || "").replace(/{content}/g, c || "");
        },
        optionReg: /.*?=("|'|)(.*?)\1\]/,
        parsedContent: function(a, b, c) {
            return a.replace(c ? RegExp("(\\[" + b.tag + "[^\\]]*\\])([\\s\\S]*?)\\[/" + b.tag + "]", "g" + (b.insensitive ? "i" : "")) : RegExp("\\[" + b.tag + "[^\\]]*\\]", "g" + (b.insensitive ? "i" : "")), function(d, e, f) {
                c || (e = d);
                e = BBParser.optionReg.test(e) ? e.replace(BBParser.optionReg, "$2") : b.defaultOption;
                if("undefined" !== typeof b.replace) {
                    d = c ? b.replace(e, f) : b.replace(e);
                    "string" === typeof d ? c ? f = d : e = d : d;
                    "object" === typeof d && (e = d.option || e, f = d.content || f);
                }
                return BBParser.replacers(b.replacement, e, f);
            });
        },
        setupBBParser: function() {
            var postBody = $(".postbody, .blog_message");
            for (var i = 0, e;(e = postBody[i++]);) {
                for (var j in BBParser.add) {
                    var item = BBParser.add[j];
                    // Validating tag
                    BBParser.validateTag(item.tag);
                    e.innerHTML = BBParser.parsedContent(e.innerHTML, item, item.close);
                }
            }
        }
    };
    BBParser.initialize()
})();

To use the BBCode, use the following tags: [onlyto="USERNAMEHERE"]YOUR CONTENT TO SHOW HERE[/onlyto]
Daemon
Daemon
Forumember

Posts : 104
Reputation : 90
Language : Português

View user profile

Back to top Go down

Solved Re: How to add bbcode?

Post by Sn0w on February 7th 2020, 7:06 pm

@Daemon wrote:First read the following topic: https://help.forumotion.com/t153342-tutorial-create-new-bbcode-tags?highlight=bbcode

After reading the topic and understanding how it works. Create a new JavaScript file and add:
(Placement: All Pages)
Code:
/*
 *  Application: Create New BBCode Tags
 *  Date: 18/05/2018
 *  Version: 1.321052018
 *  Copyright (c) 2018 Daemon <help.forumotion.com>
 *  This work is free. You can redistribute it and/or modify it
 */
(function() {
    BBParser = {
        initialize: function() {
            $(function() {
                BBParser.setupBBParser();
            });
        },
        add: [
            /*
            * Note: Add a comma at the end of each new entry
            * '{option}' corresponds to the optional tag title, and '{content}' correspond to the text between the tags
            */
 
            {
                tag: 'success',
                close: true,
                replacement: '<div class="notice notice-success"><h5>{option}</h5><p>{content}</p></div>'
            },
 
            {
                tag: 'warn',
                close: true,
                replacement: '<div class="notice notice-warn"><h5>{option}</h5><p>{content}</p></div>'
            },
 
            {
                tag: 'info',
                close: true,
                replacement: '<div class="notice notice-info"><h5>{option}</h5><p>{content}</p></div>'
            },
 
            {
                tag: 'alert',
                close: true,
                replacement: '<div class="notice notice-alert"><h5>{option}</h5><p>{content}</p></div>'
            },

            {
                tag: 'onlyto',
                close: true,
                replacement: '<div class="onlyto">{content}</div>',
                replace: function(option, content) {
                    if (_userdata.username != option) {
                        return 'Only ' + option + ' can view this message.';
                        return content;
                    }
                }
            },
 
            // Note: Do not add a comma at the end of the last entry
        ],
        // Do not change anything down
        validateTag: function(a) {
            if (!/^\w+$/.test(a)) throw new RangeError("You added an invalid tag: " + a);
        },
        replacers: function(a, b, c) {
            return (a || "").replace(/{option}/g, b || "").replace(/{content}/g, c || "");
        },
        optionReg: /.*?=("|'|)(.*?)\1\]/,
        parsedContent: function(a, b, c) {
            return a.replace(c ? RegExp("(\\[" + b.tag + "[^\\]]*\\])([\\s\\S]*?)\\[/" + b.tag + "]", "g" + (b.insensitive ? "i" : "")) : RegExp("\\[" + b.tag + "[^\\]]*\\]", "g" + (b.insensitive ? "i" : "")), function(d, e, f) {
                c || (e = d);
                e = BBParser.optionReg.test(e) ? e.replace(BBParser.optionReg, "$2") : b.defaultOption;
                if("undefined" !== typeof b.replace) {
                    d = c ? b.replace(e, f) : b.replace(e);
                    "string" === typeof d ? c ? f = d : e = d : d;
                    "object" === typeof d && (e = d.option || e, f = d.content || f);
                }
                return BBParser.replacers(b.replacement, e, f);
            });
        },
        setupBBParser: function() {
            var postBody = $(".postbody, .blog_message");
            for (var i = 0, e;(e = postBody[i++]);) {
                for (var j in BBParser.add) {
                    var item = BBParser.add[j];
                    // Validating tag
                    BBParser.validateTag(item.tag);
                    e.innerHTML = BBParser.parsedContent(e.innerHTML, item, item.close);
                }
            }
        }
    };
    BBParser.initialize()
})();

To use the BBCode, use the following tags: [onlyto="USERNAMEHERE"]YOUR CONTENT TO SHOW HERE[/onlyto]

Wow, it really works. Really thank you. I love you Next question, of course this version is good for me but could be better (sorry, i don't mentioned about this in my last post). It is possible to in this "hide" do something like: only this "NICKNAMEUSER" see content + administrator? Whether solely option is to type their nicknames?
Sn0w
Sn0w
New Member

Posts : 21
Reputation : 1
Language : English, Polish

View user profile http://wonderful-world.forumpolish.com

Back to top Go down

Solved Re: How to add bbcode?

Post by Daemon on February 8th 2020, 1:33 pm

I forgot to mention that this script allows you to create other BBCode tags. If you read the topic I sent, you will see some BBCode options.
By default, 4 BBCodes are already added. test the tags:
Code:
[success="OPTIONAL"]Content goes here[/success]
[warn="OPTIONAL"]Content goes here[/warn]
[alert="OPTIONAL"]Content goes here[/alert]
[info="OPTIONAL"]Content goes here[/info]
And add the CSS code that is in the topic i sent earlier to see the result.

And to allow administrators to see the content as well, change your code by this:
Code:
/*
 *  Application: Create New BBCode Tags
 *  Date: 18/05/2018
 *  Version: 1.321052018
 *  Copyright (c) 2018 Daemon <help.forumotion.com>
 *  This work is free. You can redistribute it and/or modify it
 */
(function() {
    BBParser = {
        initialize: function() {
            $(function() {
                BBParser.setupBBParser();
            });
        },
        add: [
            /*
            * Note: Add a comma at the end of each new entry
            * '{option}' corresponds to the optional tag title, and '{content}' correspond to the text between the tags
            */
 
            {
                tag: 'success',
                close: true,
                replacement: '<div class="notice notice-success"><h5>{option}</h5><p>{content}</p></div>'
            },
 
            {
                tag: 'warn',
                close: true,
                replacement: '<div class="notice notice-warn"><h5>{option}</h5><p>{content}</p></div>'
            },
 
            {
                tag: 'info',
                close: true,
                replacement: '<div class="notice notice-info"><h5>{option}</h5><p>{content}</p></div>'
            },
 
            {
                tag: 'alert',
                close: true,
                replacement: '<div class="notice notice-alert"><h5>{option}</h5><p>{content}</p></div>'
            },
 
            {
                tag: 'onlyto',
                close: true,
                replacement: '<div class="onlyto">{content}</div>',
                replace: function(option, content) {
                    if (_userdata.username != option && _userdata.user_level != 1) {
                        return 'Only ' + option + ' can view this message.';
                        return content;
                    }
                }
            },
 
            // Note: Do not add a comma at the end of the last entry
        ],
        // Do not change anything down
        validateTag: function(a) {
            if (!/^\w+$/.test(a)) throw new RangeError("You added an invalid tag: " + a);
        },
        replacers: function(a, b, c) {
            return (a || "").replace(/{option}/g, b || "").replace(/{content}/g, c || "");
        },
        optionReg: /.*?=("|'|)(.*?)\1\]/,
        parsedContent: function(a, b, c) {
            return a.replace(c ? RegExp("(\\[" + b.tag + "[^\\]]*\\])([\\s\\S]*?)\\[/" + b.tag + "]", "g" + (b.insensitive ? "i" : "")) : RegExp("\\[" + b.tag + "[^\\]]*\\]", "g" + (b.insensitive ? "i" : "")), function(d, e, f) {
                c || (e = d);
                e = BBParser.optionReg.test(e) ? e.replace(BBParser.optionReg, "$2") : b.defaultOption;
                if("undefined" !== typeof b.replace) {
                    d = c ? b.replace(e, f) : b.replace(e);
                    "string" === typeof d ? c ? f = d : e = d : d;
                    "object" === typeof d && (e = d.option || e, f = d.content || f);
                }
                return BBParser.replacers(b.replacement, e, f);
            });
        },
        setupBBParser: function() {
            var postBody = $(".postbody, .blog_message");
            for (var i = 0, e;(e = postBody[i++]);) {
                for (var j in BBParser.add) {
                    var item = BBParser.add[j];
                    // Validating tag
                    BBParser.validateTag(item.tag);
                    e.innerHTML = BBParser.parsedContent(e.innerHTML, item, item.close);
                }
            }
        }
    };
    BBParser.initialize()
})();
Daemon
Daemon
Forumember

Posts : 104
Reputation : 90
Language : Português

View user profile

Back to top Go down

Solved Re: How to add bbcode?

Post by Daemon on February 10th 2020, 12:58 pm

Remember to read my last message above.
If you want more than one user to view the content, replace the code with this:
Code:
/*
 *  Application: Create New BBCode Tags
 *  Date: 18/05/2018
 *  Version: 1.321052018
 *  Copyright (c) 2018 Daemon <help.forumotion.com>
 *  This work is free. You can redistribute it and/or modify it
 */
(function() {
    BBParser = {
        initialize: function() {
            $(function() {
                BBParser.setupBBParser();
            });
        },
        add: [
            /*
            * Note: Add a comma at the end of each new entry
            * '{option}' corresponds to the optional tag title, and '{content}' correspond to the text between the tags
            */
 
            {
                tag: 'success',
                close: true,
                replacement: '<div class="notice notice-success"><h5>{option}</h5><p>{content}</p></div>'
            },
 
            {
                tag: 'warn',
                close: true,
                replacement: '<div class="notice notice-warn"><h5>{option}</h5><p>{content}</p></div>'
            },
 
            {
                tag: 'info',
                close: true,
                replacement: '<div class="notice notice-info"><h5>{option}</h5><p>{content}</p></div>'
            },
 
            {
                tag: 'alert',
                close: true,
                replacement: '<div class="notice notice-alert"><h5>{option}</h5><p>{content}</p></div>'
            },
 
            {
                tag: 'onlyto',
                close: true,
                replacement: '<div class="onlyto">{content}</div>',
                replace: function(option, content) {
                    var myArray = new Array();
                    // this will return an array with strings "1", "2", etc.
                    myArray = option.split(",").map(function(el) {
                        return el.trim();
                    });
                    if ($.inArray(_userdata.username, myArray) == -1 && _userdata.user_level != 1) {
                        return 'Only ' + myArray.join(", ").replace(/,([^,]*)$/, ' and $1') + ' can view this message';
                        return content;
                    }
                }
            }
 
            // Note: Do not add a comma at the end of the last entry
        ],
        // Do not change anything down
        validateTag: function(a) {
            if (!/^\w+$/.test(a)) throw new RangeError("You added an invalid tag: " + a);
        },
        replacers: function(a, b, c) {
            return (a || "").replace(/{option}/g, b || "").replace(/{content}/g, c || "");
        },
        optionReg: /.*?=("|'|)(.*?)\1\]/,
        parsedContent: function(a, b, c) {
            return a.replace(c ? RegExp("(\\[" + b.tag + "[^\\]]*\\])([\\s\\S]*?)\\[/" + b.tag + "]", "g" + (b.insensitive ? "i" : "")) : RegExp("\\[" + b.tag + "[^\\]]*\\]", "g" + (b.insensitive ? "i" : "")), function(d, e, f) {
                c || (e = d);
                e = BBParser.optionReg.test(e) ? e.replace(BBParser.optionReg, "$2") : b.defaultOption;
                if("undefined" !== typeof b.replace) {
                    d = c ? b.replace(e, f) : b.replace(e);
                    "string" === typeof d ? c ? f = d : e = d : d;
                    "object" === typeof d && (e = d.option || e, f = d.content || f);
                }
                return BBParser.replacers(b.replacement, e, f);
            });
        },
        setupBBParser: function() {
            var postBody = $(".postbody, .blog_message");
            for (var i = 0, e;(e = postBody[i++]);) {
                for (var j in BBParser.add) {
                    var item = BBParser.add[j];
                    // Validating tag
                    BBParser.validateTag(item.tag);
                    e.innerHTML = BBParser.parsedContent(e.innerHTML, item, item.close);
                }
            }
        }
    };
    BBParser.initialize()
})();

Now you can do this:
Code:
[onlyto="USERNAME1, USERNAME2, USERNAME5"]Content[/onlyto]
separate the names with a comma. Administrators are also able to view the content.
Daemon
Daemon
Forumember

Posts : 104
Reputation : 90
Language : Português

View user profile

Back to top Go down

Solved Re: How to add bbcode?

Post by brandon_g on February 14th 2020, 2:51 pm

@Sn0w is this solved for you?

Also thanks @Daemon for helping out this user. We appreciate the help. Wink

-Brandon
brandon_g
brandon_g
Manager
Manager

Male Posts : 9202
Reputation : 844
Language : English
Location : USA

View user profile https://www.broadcastingduo.com

Back to top Go down

Solved Re: How to add bbcode?

Post by Sn0w on February 22nd 2020, 7:14 pm

@brandon_g wrote:@Sn0w is this solved for you?

Also thanks @Daemon for helping out this user. We appreciate the help. Wink

-Brandon
Yeah, thanks to @Deamon. Good
Sn0w
Sn0w
New Member

Posts : 21
Reputation : 1
Language : English, Polish

View user profile http://wonderful-world.forumpolish.com

Back to top Go down

Solved Re: How to add bbcode?

Post by SLGray on February 22nd 2020, 7:30 pm

Problem solved & topic archived.
Please read our forum rules:  ESF General Rules


How to add bbcode? Slgray10
How to add bbcode? Ssshfm13

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 47954
Reputation : 3370
Language : English
Location : United States

View user profile https://help.forumotion.com/

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum