The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How to add bbcode?

5 posters

Go down

Solved How to add bbcode?

Post by Sn0w 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

http://wonderful-world.forumpolish.com

Back to top Go down

Solved Re: How to add bbcode?

Post by Draxion 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?
Draxion
Draxion
Helper
Helper

Male Posts : 2518
Reputation : 321
Language : English
Location : USA

https://www.talesoftellene.com/

Back to top Go down

Solved Re: How to add bbcode?

Post by Sn0w 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

http://wonderful-world.forumpolish.com

Back to top Go down

Solved Re: How to add bbcode?

Post by Daemon 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 : 91
Language : Português

Back to top Go down

Solved Re: How to add bbcode?

Post by Sn0w 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

http://wonderful-world.forumpolish.com

Back to top Go down

Solved Re: How to add bbcode?

Post by Daemon 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 : 91
Language : Português

Back to top Go down

Solved Re: How to add bbcode?

Post by Daemon 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 : 91
Language : Português

Back to top Go down

Solved Re: How to add bbcode?

Post by brandon_g 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


How to add bbcode? Brando10
Remember to mark your topic How to add bbcode? Solved15 when a solution is found.
General Rules | Tips & Tricks | FAQ | Forgot Founder Password?

How to add bbcode? Scre1476
Team Leader
Review Section Rules | Request A Review | Sticker Points
brandon_g
brandon_g
Manager
Manager

Male Posts : 10106
Reputation : 923
Language : English
Location : USA

https://www.broadcastingduo.com

Back to top Go down

Solved Re: How to add bbcode?

Post by Sn0w 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

http://wonderful-world.forumpolish.com

Back to top Go down

Solved Re: How to add bbcode?

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

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


How to add bbcode? Slgray10

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

Male Posts : 51489
Reputation : 3519
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Back to top

- Similar topics

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