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.

change for punbb

+2
SLGray
Rafa1804
6 posters

Go down

In progress change for punbb

Post by Rafa1804 August 7th 2021, 2:22 am

I found this code for phpbb3 to hide messages, tested it and it worked in phpbb3.

However, I use PunBB, can you help me to change the variables here to work in PunBB?

Code:
"use strict";
$(function() {

    var title = $('h2.topic-title');

    var isAdmin = function() {
        var level = _userdata["user_level"];
        if (level === 1 || level === 2) return true;
    };


    title.each(function() {
        if (this.textContent == ' > only_admin') {
            $(this).children('a').text('This post is only visible for moderation.');
            $(this).parents('.post').addClass('admin_only');
        }
    });

    var admin_only = $('.post.admin_only');

    if (isAdmin()) {

        $('ul.profile-icons').prepend(
            '<li><a href="#hide" class="hide-post">Hide post</a></li>'
        );

        if (admin_only.length) {
            admin_only.css({
                'opacity': '.5'
            });
        }


        $('.hide-post').click(function() {

            var post = $(this).parents('div.post').attr('id').split('p')[1],
                content = $(this).parents('.postbody').find('.content').html();

            $.post("/post", {
                p: post,
                mode: 'editpost',
                subject: '> only_admin',
                message: content,
                edit_reason: '',
                attach_sig: '0',
                notify: "0",
                post: 1
            }).done(function() {
                location.reload();
            }).fail(function() {
                alert('[Erro]: Something went wrong when editing the post');
            });
        });

    } else {
        if (admin_only.length) admin_only.remove();
    };


});

Thanks
Rafa1804
Rafa1804
Forumember

Posts : 25
Reputation : 1
Language : EN

https://punbb.forumotion.com/

Back to top Go down

In progress Re: change for punbb

Post by SLGray August 7th 2021, 2:49 am

Where did you found the code?


punbb - change for punbb 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

In progress Re: change for punbb

Post by Rafa1804 August 7th 2021, 2:52 am

SLGray wrote:Where did you found the code?

I found the code on a forum but I can't remember which one, I went back to Forumotion now and had it saved.

Can you help me?
Rafa1804
Rafa1804
Forumember

Posts : 25
Reputation : 1
Language : EN

https://punbb.forumotion.com/

Back to top Go down

In progress Re: change for punbb

Post by skouliki August 7th 2021, 7:19 am

please provide your forum url
skouliki
skouliki
Manager
Manager

Female Posts : 15133
Reputation : 1696
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

In progress Re: change for punbb

Post by Rafa1804 August 7th 2021, 11:10 am

skouliki wrote:please provide your forum url

My forum is
https://ob-forum.forumeiros.com/
Rafa1804
Rafa1804
Forumember

Posts : 25
Reputation : 1
Language : EN

https://punbb.forumotion.com/

Back to top Go down

In progress Re: change for punbb

Post by skouliki August 7th 2021, 4:54 pm

we need the forum to be viewable to guests in order to be able to help
skouliki
skouliki
Manager
Manager

Female Posts : 15133
Reputation : 1696
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

In progress Re: change for punbb

Post by Rafa1804 August 7th 2021, 7:24 pm

skouliki wrote:we need the forum to be viewable to guests in order to be able to help

Sorry, here is the link

https://ob-forum.forumeiros.com/t6-forumotion#10
Rafa1804
Rafa1804
Forumember

Posts : 25
Reputation : 1
Language : EN

https://punbb.forumotion.com/

Back to top Go down

In progress Re: change for punbb

Post by BlackScorpion August 8th 2021, 11:54 pm

Rafa1804 wrote:
skouliki wrote:we need the forum to be viewable to guests in order to be able to help

Sorry, here is the link

https://ob-forum.forumeiros.com/t6-forumotion#10

what exactly is this code used for ? are you trying to hide messages from members and is only viewable by admins?
BlackScorpion
BlackScorpion
Graphic Designer
Graphic Designer

Male Posts : 7010
Reputation : 919
Language : English
Location : USA

https://help.forumotion.com/f6-graphic-design-section

Back to top Go down

In progress Re: change for punbb

Post by Rafa1804 August 9th 2021, 2:54 am

BlackScorpion wrote:
Rafa1804 wrote:
skouliki wrote:we need the forum to be viewable to guests in order to be able to help

Sorry, here is the link

https://ob-forum.forumeiros.com/t6-forumotion#10

what exactly is this code used for ? are you trying to hide messages from members and is only viewable by admins?

Yes, exactly, the problem is that this version is in phpbb3 and it's working which I've already tested, however, I wanted it to work in punbb, it shouldn't be too difficult but I don't understand anything about Javascript, can you help me?
Rafa1804
Rafa1804
Forumember

Posts : 25
Reputation : 1
Language : EN

https://punbb.forumotion.com/

Back to top Go down

In progress Re: change for punbb

Post by skouliki August 9th 2021, 12:20 pm

you have to locate the creator of that code
skouliki
skouliki
Manager
Manager

Female Posts : 15133
Reputation : 1696
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

In progress Re: change for punbb

Post by Ape August 9th 2021, 2:50 pm

Just to let you know not all Codes can be changed that easy as #punbb has a lot of codes that have the same fields.


punbb - change for punbb Left1212punbb - change for punbb Center11punbb - change for punbb Right112
punbb - change for punbb Ape_b110
punbb - change for punbb Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 19122
Reputation : 1993
Language : fluent in dork / mumbojumbo & English haha

http://chatworld.forumotion.co.uk/

Back to top Go down

In progress Re: change for punbb

Post by Rafa1804 August 11th 2021, 8:10 am

The script works perfectly to adapt, I tried to make some changes and it already showed results, but it was still buggy.

If you understand Javascript and reformulate the code, you will be able to put it in the PunBB version for sure.
Rafa1804
Rafa1804
Forumember

Posts : 25
Reputation : 1
Language : EN

https://punbb.forumotion.com/

Back to top Go down

In progress Re: change for punbb

Post by Rafa1804 August 17th 2021, 6:30 am

upp
Rafa1804
Rafa1804
Forumember

Posts : 25
Reputation : 1
Language : EN

https://punbb.forumotion.com/

Back to top Go down

In progress Re: change for punbb

Post by tikky August 26th 2021, 3:55 pm

Hello @Rafa1804,

Change your code to:
Code:
(function($) {
    'use strict';

    $(function() {

        if (! /^\/t(\d+)(p\d+-|-).*$/i.test(location.pathname)) {
            return;
        }

        $('.post').each(function() {
            var $post = $(this);
            var config = {
                link: $post.find('a[href^="/post?p="][href$="&mode=editpost"]'),
                message: (_userdata.user_level ? $post.find('a[href^="/post?p="][href$="&mode=editpost"]').attr('href').split('p=')[1].split('&')[0] : $post.attr('class').split('--')[1]),
                title: $post.find('.posthead a[href^="/t"]'),
                content: $post.find('.entry-content').html()
            };


            if (/> only_admin/.test(config.title.text())) {

                config.title
                    .html('This post is <b>only visible for moderation</b>.')
                ;

                $post
                    .attr('id', 'only_admin-' + config.message)
                    .css('opacity', '.5')
                    .find('.entry-content')
                    .html((_userdata.user_level ? config.content : '<span style="font-weight: 700; color: red;">[ You cannot see this message ]</span>'))
                ;
            }


            if (_userdata.user_level !== 1 && _userdata.user_level !== 2) {
                return;
            }

            if (!config.link.length) {
                return;
            }

            $.get(config.link.attr('href'))
                .done(function(context) {

                    var $textarea = $('#text_editor_textarea', context);

                    if (!$textarea.length) return;
                    if ($('#only_admin-' + config.message).length) return;

                    $('<button>', {
                            'class': 'button1 rep-button',
                            'role': 'button',
                            'title': 'Hide this post',
                            'text': 'Hide post'
                        })
                        .appendTo(config.title.parent().parent().parent().find('.post-options'))
                        .on('click', function(event) {
                            event.preventDefault();
                            $.post("/post", {
                                p: config.message,
                                mode: 'editpost',
                                subject: '> only_admin',
                                message: $textarea.val(),
                                edit_reason: '',
                                attach_sig: 0,
                                notify: 0,
                                post: 1
                            }).done(function() {
                                location.reload(true);
                            }).fail(function() {
                                alert('[Erro]: Something went wrong when editing the post');
                            });

                        });
                });
        });

    });
}(jQuery));
Notice that: I haven't worked in codes for some time if there is any inconvenience just say silent and see if javascript is disabled from the browser any member can see the post Very good You can use the portuguese support forum blackeye

Demonstration
Members
punbb - change for punbb Rj6SZVU

Admin or Mod
punbb - change for punbb U6Ky1p3
tikky
tikky
Forumember

Posts : 897
Reputation : 157
Language : 🇵🇹

https://www.forumotion.com/create-forum/modernbb

Sir Chivas™, SarkZKalie and TonnyKamper like this post

Back to top Go down

Back to top

- Similar topics

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