Problem with "onlyto"

Go down

Solved Problem with "onlyto"

Post by Sn0w on April 5th 2020, 3:55 am

Hi,
A month ago I wrote a topic "how to add bbcode" where I search for advance hide. So.
Today this code have got broken. Someone have a solution?

Code:
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 && _userdata.user_level != 2 && _userdata.user_level != 3) {
                        return 'Only ' + myArray.join(", ").replace(/,([^,]*)$/, ' and $1', ' and $2', ' and $3') + ' 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()
})();

Screenshot of problem:
Problem with "onlyto" DJ3KsTD

PS. if it will helps: I had change my forum design.
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: Problem with "onlyto"

Post by skouliki on April 5th 2020, 8:51 am

hello

did you change your version too?
skouliki
skouliki
Manager
Manager

Female Posts : 9092
Reputation : 1188
Language : English,Greek
Location : Greece

View user profile http://iconskouliki.forumgreek.com

Back to top Go down

Solved Re: Problem with "onlyto"

Post by pedxz on April 5th 2020, 9:32 am

Hey @Sn0w,

Welcome to Support Forumotion! Can you give access to a topic. It is in maintenance, the Forum.


- pedxz
pedxz
pedxz
Forumember

Male Posts : 310
Reputation : 83
Language : Português
Location : Forumeiros

View user profile https://www.forumotion.com/create-forum/modernbb

Back to top Go down

Solved Re: Problem with "onlyto"

Post by Sn0w on April 5th 2020, 3:05 pm

@skouliki wrote:hello

did you change your version too?
Yeah. I had Phpbb2, now modernbb.
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: Problem with "onlyto"

Post by Neptune- on April 5th 2020, 3:31 pm

Hello ^^


No warranty, but can you try that script ?

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 && _userdata.user_level != 2 && _userdata.user_level != 3) {
                                return 'Only ' + myArray.join(", ").replace(/,([^,]*)$/, ' and $1', ' and $2', ' and $3') + ' 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 = $("div.content");
                    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()
        })();
Neptune-
Neptune-
Forumember

Male Posts : 394
Reputation : 83
Language : French (10), English (8), CSS (5), HTML (4), Javascript (4)
Location : France

View user profile https://www.galaxie-series.net/

Back to top Go down

Solved Re: Problem with "onlyto"

Post by skouliki on April 5th 2020, 4:26 pm

@Sn0w wrote:
@skouliki wrote:hello

did you change your version too?
Yeah. I had Phpbb2, now modernbb.

The codes are not for all versions
Each version haS different elements so when you change version you have to adjust all your codes
skouliki
skouliki
Manager
Manager

Female Posts : 9092
Reputation : 1188
Language : English,Greek
Location : Greece

View user profile http://iconskouliki.forumgreek.com

Back to top Go down

Solved Re: Problem with "onlyto"

Post by Sn0w on April 5th 2020, 5:19 pm

@Neptune- wrote:Hello ^^


No warranty, but can you try that script ?

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 && _userdata.user_level != 2 && _userdata.user_level != 3) {
                                return 'Only ' + myArray.join(", ").replace(/,([^,]*)$/, ' and $1', ' and $2', ' and $3') + ' 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 = $("div.content");
                    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()
        })();
Unfortunately, It doesn't work.
@skouliki wrote:
@Sn0w wrote:
@skouliki wrote:hello

did you change your version too?
Yeah. I had Phpbb2, now modernbb.

The codes are not for all versions
Each version haS different elements so when you change version you have to adjust all your codes
Oh, now I get it. The clue of problem is - how? It's possible to do it myself, if I didn't know any codes like java?
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: Problem with "onlyto"

Post by skouliki on April 5th 2020, 5:35 pm

our tutorials with codes have instructions for all versions

we cant modify a code that someone else has made you have to wait for that member
unless someone else can volunteer to help you
skouliki
skouliki
Manager
Manager

Female Posts : 9092
Reputation : 1188
Language : English,Greek
Location : Greece

View user profile http://iconskouliki.forumgreek.com

Back to top Go down

Solved Re: Problem with "onlyto"

Post by Sn0w on April 5th 2020, 7:31 pm

@pedxz wrote:Hey @Sn0w,

Welcome to Support Forumotion! Can you give access to a topic. It is in maintenance, the Forum.


- pedxz
done
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: Problem with "onlyto"

Post by SLGray on April 5th 2020, 11:01 pm

Do you have a section where guests can post?  If yes, please post the link to it.


Problem with "onlyto" Slgray10
Problem with "onlyto" 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 : 47967
Reputation : 3373
Language : English
Location : United States

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

Back to top Go down

Solved Re: Problem with "onlyto"

Post by Neptune- on April 6th 2020, 7:56 am

@Sn0w wrote:Unfortunately, It doesn't work.

I just tried it to be sure
-> My code (with line 85 modified) perfectly works on modernBB
-> The original code (in first post) also works fine. (so i modified it for nothing Sad )

If you still have a problem, you should disable all your javascripts codes except this one
Neptune-
Neptune-
Forumember

Male Posts : 394
Reputation : 83
Language : French (10), English (8), CSS (5), HTML (4), Javascript (4)
Location : France

View user profile https://www.galaxie-series.net/

Back to top Go down

Solved Re: Problem with "onlyto"

Post by Sn0w on April 6th 2020, 8:29 pm

@SLGray wrote:Do you have a section where guests can post?  If yes, please post the link to it.
https://wonderful-world.forumpolish.com/t402-test#1281 here.
@Neptune- wrote:
@Sn0w wrote:Unfortunately, It doesn't work.

I just tried it to be sure
-> My code (with line 85 modified) perfectly works on modernBB
-> The original code (in first post) also works fine. (so i modified it for nothing Sad )

If you still have a problem, you should disable all your javascripts codes except this one
I disabled all javascripts and forum has become empty. Same, when I aplicate code, which you sended in this topic.
I think that my forum template is problem.
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: Problem with "onlyto"

Post by SLGray on April 6th 2020, 8:49 pm

So you have heavy modified templates?


Problem with "onlyto" Slgray10
Problem with "onlyto" 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 : 47967
Reputation : 3373
Language : English
Location : United States

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

Back to top Go down

Solved Re: Problem with "onlyto"

Post by Sn0w on April 6th 2020, 8:51 pm

@SLGray wrote:So you have heavy modified templates?
Yeah. Unfortunetly.
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: Problem with "onlyto"

Post by SLGray on April 6th 2020, 8:53 pm

Try this:  force the default templates and see if the issue disappears.


Problem with "onlyto" Slgray10
Problem with "onlyto" 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 : 47967
Reputation : 3373
Language : English
Location : United States

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

Back to top Go down

Solved Re: Problem with "onlyto"

Post by Sn0w on April 6th 2020, 8:58 pm

@SLGray wrote:Try this:  force the default templates and see if the issue disappears.
Doesn't work. Sad
Update: when I use [onlyto=NICKNAME] - It works, but when I use [onlyto] (without nickname) - Doesn't work.
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: Problem with "onlyto"

Post by SLGray on April 6th 2020, 9:10 pm

Is that not what you want?


Problem with "onlyto" Slgray10
Problem with "onlyto" 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 : 47967
Reputation : 3373
Language : English
Location : United States

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

Back to top Go down

Solved Re: Problem with "onlyto"

Post by Sn0w on April 6th 2020, 9:18 pm

@SLGray wrote:Is that not what you want?
Half by half. I would like to have [onlyto=] and [only to]. But if it's not possible, I'll be still satisfiable.
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: Problem with "onlyto"

Post by SLGray on April 6th 2020, 9:22 pm

So you want 2 options that really have the same ID or name?


Problem with "onlyto" Slgray10
Problem with "onlyto" 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 : 47967
Reputation : 3373
Language : English
Location : United States

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

Back to top Go down

Solved Re: Problem with "onlyto"

Post by Sn0w on April 6th 2020, 9:34 pm

@SLGray wrote:So you want 2 options that really have the same ID or name?
Rather: [onlyto] - This content see only administrators, [onlyto=name] - content see administrator and user "name".
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: Problem with "onlyto"

Post by pedxz on April 7th 2020, 12:08 am

So the error was from the code, not a conflict by a template or a script!
Try change your code to:
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.
                  if(option) {
                      myArray = option.split(",").map(function(el) {
                          return el.trim();
                      });
                    }
                    if ($.inArray(_userdata.username, myArray) == -1 && _userdata.user_level != 1 && _userdata.user_level != 2) {
                        return 'Only ' + ( myArray.length ? myArray.join(", ").replace(/,([^,]*)$/, ' and $1', ' and $2', ' and $3') : 'Administrator and Moderator' ) + ' can view this message';
                        return content;
                    } else if (_userdata.user_level !== 1 && _userdata.user_level !== 2) {
                        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();
})();


but I will quote @Daemon
pedxz
pedxz
Forumember

Male Posts : 310
Reputation : 83
Language : Português
Location : Forumeiros

View user profile https://www.forumotion.com/create-forum/modernbb

Back to top Go down

Solved Re: Problem with "onlyto"

Post by Sn0w on April 7th 2020, 12:41 am

@pedxz wrote:So the error was from the code, not a conflict by a template or a script!
Try change your code to:
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.
                  if(option) {
                      myArray = option.split(",").map(function(el) {
                          return el.trim();
                      });
                    }
                    if ($.inArray(_userdata.username, myArray) == -1 && _userdata.user_level != 1 && _userdata.user_level != 2) {
                        return 'Only ' + ( myArray.length ? myArray.join(", ").replace(/,([^,]*)$/, ' and $1', ' and $2', ' and $3') : 'Administrator and Moderator' ) + ' can view this message';
                        return content;
                    } else if (_userdata.user_level !== 1 && _userdata.user_level !== 2) {
                        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();
})();


but I will quote @Daemon

Omg, now It's work perfectly fine. Really thank you! You're my god. Very Happy
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: Problem with "onlyto"

Post by SLGray on April 7th 2020, 3:43 am

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


Problem with "onlyto" Slgray10
Problem with "onlyto" 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 : 47967
Reputation : 3373
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