BBCODE Only for Staff

Go down

Solved BBCODE Only for Staff

Post by Simone Boi February 8th 2021, 12:18 pm

Hi guys! Like always I want to thank you all for helping me.

Today my question is about BBCode.

I added these BBCode with a nice look:

BBCODE Only for Staff GMTQ9kC

and buttons:

BBCODE Only for Staff BkeB4Ox

But how can make them work only for staff? (admin+moderators)
I want that guest or normal users can't see the bbcode buttons in SCeditor, and they can't even manually add them just typing the code "[success=Risolto][/success]"

Is that possible?

Here's the codes:

Spoiler:
Code:
jQuery(function(){
      jQuery(function(){
        jQuery('<a class="sceditor-button sceditor-button-sucesso" unselectable="on" title="Sucesso"><div unselectable="on" style="background-image:url(https://i.imgur.com/EISZPwN.png)">Sucesso</div></a>').insertBefore('.sceditor-button-size').click(function(){
                jQuery('#text_editor_textarea').sceditor("instance").insertText("[success=Risolto]","[/success]");
        });
        jQuery('<a class="sceditor-button sceditor-button-alerta" unselectable="on" title="Alerta"><div unselectable="on" style="background-image:url(https://i.imgur.com/lMsD0nE.png)">Alerta</div></a>').insertAfter('.sceditor-button-sucesso').click(function(){
                jQuery('#text_editor_textarea').sceditor("instance").insertText("[alert=Avverimento]","[/alert]");
        });
        jQuery('<a class="sceditor-button sceditor-button-aviso" unselectable="on" title="Aviso"><div unselectable="on" style="background-image:url(https://i.imgur.com/cI8SnOI.png)">Aviso</div></a>').insertAfter('.sceditor-button-alerta').click(function(){
                jQuery('#text_editor_textarea').sceditor("instance").insertText("[warn=Attenzione]","[/warn]");
        });
        jQuery('<a class="sceditor-button sceditor-button-info" unselectable="on" title="Informação"><div unselectable="on" style="background-image:url(https://i.imgur.com/40zM1qS.png)">Informação</div></a>').insertAfter('.sceditor-button-aviso').click(function(){
                jQuery('#text_editor_textarea').sceditor("instance").insertText("[info=Informazioni]","[/info]");
        });
        });
      });

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: 'guest',
                close: true,
                replacement: '<div class="guest">{content}</div>',
                replace: function(option, content) {
                    if (_userdata.session_logged_in < 1) {
                        return 'You need to be logged in to view this content';
                        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()
})();

Code:
/*
[tags] Nei post per lo staff
*/
.notice {
    background: url(https://i.imgur.com/VWRy0Mc.png) repeat-x 0 0;
    color: #FFF;
    width: 83%;
    font-weight: normal;
    padding: 13px 15px;
    margin-bottom: 2.5em;
    -moz-border-radius: 6px;
    -webkit-border-radius: 6px;
    border-radius: 6px;
    -moz-box-shadow: 1px 1px 2px rgba(0,0,0,.4);
    -webkit-box-shadow: 1px 1px 2px rgba(0,0,0,.4);
    box-shadow: 1px 1px 2px rgba(0,0,0,.4);
    position: relative;
    left: 34px;
}
 .notice p {
    margin-bottom: 1.5em;
}
 .notice p:last-child {
    margin-bottom: 0;
}
 .notice h5 {
    font-size: 14px;
    font-weight: bold;
    margin-bottom: .65em;
}
 .notice:before {
    content: "";
    background: url(https://i.imgur.com/PcLYd52.png) no-repeat 100% 0;
    width: 33px;
    height: 40px;
    position: absolute;
    left: -34px;
    top: 9px;
}
 .notice-success {
    background-color: #EEF4D4;
    color: #596C26;
    border: 1px solid #8FAD3D;
}
 .notice-success:before {
    background-position: 100% 0;
}
 .notice-warn {
    background-color: #FFEA97;
    color: #796100;
    border: 1px solid #E1B500;
}
 .notice-warn:before {
    background-position: 100% -800px;
}
 .notice-alert {
    background-color: #EFCEC9;
    color: #933628;
    border: 1px solid #AE3F2F;
}
 .notice-alert:before {
    background-position: 100% -400px;
}
 .notice-info {
    background-color: #C6D8F0;
    color: #285797;
    border: 1px solid #4381CD;
}
 .notice-info:before {
    background-position: 100% -1200px;
}
.sucesso, .alerta, .aviso, .infos {
padding: 8px 8px 8px 40px;
width: 99%;
text-shadow: 0 1px 0 #FFFAF1;
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2) inset;
font-weight: bold;
border-radius: 3px 3px 3px 3px;
}
.sucesso {
background: url('http://cdn3.iconfinder.com/data/icons/fatcow/32x32_0020/accept.png') no-repeat 6px #effeb9;
border: 1px solid #9ac601;
color: #4F8A10;
}
.alerta {
background: url('http://cdn1.iconfinder.com/data/icons/nuvola2/32x32/actions/messagebox_warning.png') no-repeat 6px #fccac3;
border: 1px solid #db3f23;
color: #D8000C;
}
.aviso {
background: url('http://cdn3.iconfinder.com/data/icons/fatcow/32x32_0400/error.png') no-repeat 6px #ffeaa9;
border: 1px solid #f9b516;
color: #9F6000;
}
.infos {
background: url('http://cdn1.iconfinder.com/data/icons/musthave/24/Information.png') no-repeat 6px #d1e4f3;
border: 1px solid #4d8fcb;
color: #00529B;
}
avatar
Simone Boi
Forumember

Posts : 65
Reputation : 1
Language : Italian

View user profile https://gamespledge.forumattivo.com/

Back to top Go down

Solved Re: BBCODE Only for Staff

Post by skouliki February 8th 2021, 4:18 pm

hello

did you find this code on the Italian support ?
skouliki
skouliki
Manager
Manager

Female Posts : 10882
Reputation : 1370
Language : English,Greek
Location : Greece

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

Back to top Go down

Solved Re: BBCODE Only for Staff

Post by Simone Boi February 8th 2021, 4:33 pm

Hi! Actually i don't remember, I followed a tutorial long time ago, but I don't think was on the italian forum.
avatar
Simone Boi
Forumember

Posts : 65
Reputation : 1
Language : Italian

View user profile https://gamespledge.forumattivo.com/

Back to top Go down

Solved Re: BBCODE Only for Staff

Post by TheCrow February 8th 2021, 4:42 pm

@Simone Boi replace the first script you posted with this one:
Code:
jQuery(function(){

      if (_userdata.user_level === 0 || !document.getElementById('text_editor_textarea')) return;

      jQuery(function(){
        jQuery('<a class="sceditor-button sceditor-button-sucesso" unselectable="on" title="Sucesso"><div unselectable="on" style="background-image:url(https://i.imgur.com/EISZPwN.png)">Sucesso</div></a>').insertBefore('.sceditor-button-size').click(function(){
                jQuery('#text_editor_textarea').sceditor("instance").insertText("[success=Risolto]","[/success]");
        });
        jQuery('<a class="sceditor-button sceditor-button-alerta" unselectable="on" title="Alerta"><div unselectable="on" style="background-image:url(https://i.imgur.com/lMsD0nE.png)">Alerta</div></a>').insertAfter('.sceditor-button-sucesso').click(function(){
                jQuery('#text_editor_textarea').sceditor("instance").insertText("[alert=Avverimento]","[/alert]");
        });
        jQuery('<a class="sceditor-button sceditor-button-aviso" unselectable="on" title="Aviso"><div unselectable="on" style="background-image:url(https://i.imgur.com/cI8SnOI.png)">Aviso</div></a>').insertAfter('.sceditor-button-alerta').click(function(){
                jQuery('#text_editor_textarea').sceditor("instance").insertText("[warn=Attenzione]","[/warn]");
        });
        jQuery('<a class="sceditor-button sceditor-button-info" unselectable="on" title="Informação"><div unselectable="on" style="background-image:url(https://i.imgur.com/40zM1qS.png)">Informação</div></a>').insertAfter('.sceditor-button-aviso').click(function(){
                jQuery('#text_editor_textarea').sceditor("instance").insertText("[info=Informazioni]","[/info]");
        });
        });
      });

That should make the buttons appear only to moderators. The addition to it is the 3rd line in there.
Code:
if (_userdata.user_level === 0 || !document.getElementById('text_editor_textarea')) return;
This
Code:
if
check, is looking for ordinary members. If the member has level 0 (which is simple members) it returns the editor as the default one. Otherwise it adds the buttons for members who are moderators or administrators.

I hope this is what you were looking for.

Regards,
TC.
TheCrow
TheCrow
Manager
Manager

Male Posts : 6666
Reputation : 778
Language : Greek, English

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

SarkZKalie and Simone Boi like this post

Back to top Go down

Solved Re: BBCODE Only for Staff

Post by Simone Boi February 8th 2021, 4:55 pm

Hi TheCrow! That worked for buttons, thanks a lot! But if an user type the code manually, like "[success=Risolto][/success]", without using the button, still gets the effect, there is a way to negate the code for no-staff users?
avatar
Simone Boi
Forumember

Posts : 65
Reputation : 1
Language : Italian

View user profile https://gamespledge.forumattivo.com/

Back to top Go down

Solved Re: BBCODE Only for Staff

Post by TheCrow February 8th 2021, 5:00 pm

You cannot prevent someone from typing it manually. That will affect your quotes and all afterwards.

If for example, you type the yellow one to say Please don't double post and I use the quote to say Sorry it won't happen again. in the quote it will display as bbcode and not as quote because it is taken as if the member is typing it manually. Therefore that would make a little mess.

My suggestion to you would be to have them as they are now, and if someone uses them, give a fair warning not to use them again otherwise there will be punishments as they are only reserved for staff.

Regards,
TC.
TheCrow
TheCrow
Manager
Manager

Male Posts : 6666
Reputation : 778
Language : Greek, English

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

Simone Boi likes this post

Back to top Go down

Solved Re: BBCODE Only for Staff

Post by Simone Boi February 8th 2021, 5:50 pm

Oh, I guess I should just do like you say then, hope there will be a way to prevent users from use it in future, anyway thank you a lot! Atleast I can hide buttons! I love you I love you I love you
avatar
Simone Boi
Forumember

Posts : 65
Reputation : 1
Language : Italian

View user profile https://gamespledge.forumattivo.com/

Back to top Go down

Solved Re: BBCODE Only for Staff

Post by skouliki February 8th 2021, 6:29 pm

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

Female Posts : 10882
Reputation : 1370
Language : English,Greek
Location : Greece

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

Back to top Go down

Back to top


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