MyBB Community Forums

Full Version: Help with a bit PHP code to assign permissions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I am using the buttoncheck.php plugin from here to hide New Thread and New Reply buttons from guests. This is the code that does the trick:

<?php

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("forumdisplay_thread", "buttoncheck_forum");
$plugins->add_hook("showthread_end", "buttoncheck_thread");


function buttoncheck_info()
{
        return array(
                "name" => "Button Check",
                "description" => "Hide button if user have no permission",
                "website" => "http://mybbhacks.zingaburga.com",
                "author" => "TriTop",
                "version" => "1.0",
        );
}


function buttoncheck_forum()
{
        global $newthread, $fpermissions;
        if ($fpermissions['canpostthreads'] == 0)
        {
                $newthread = "";
        }
}


function buttoncheck_thread()
{
        global $newthread, $newreply, $showthread, $forumpermissions;

        if ($forumpermissions['canpostthreads'] == 0)
        {
                $newthread = "";
        }

        if ($forumpermissions['canpostreplys'] == 0)
        {
                $newreply = "";
        }
}
?>

I was thinking if it is possible to hide specific HTML code from guests instead of just $newreply and $newthread.

In particular I want to hide this piece of code from all guests:

<div class="threadBottom">
	<ul class="thread_tools">
		<li class="subscription_{$add_remove_subscription}">
			<a href="usercp2.php?action={$add_remove_subscription}subscription&amp;tid={$tid}&amp;my_post_key={$mybb->post_code}">{$add_remove_subscription_text}
			</a>
		</li>
	</ul>
</div>

I have tried to add the following beneth "$newreply = "";" :

"\<div class=\"threadBottom\"></div>" = "";

In the end I had this:

function buttoncheck_thread()
{
        global $newthread, $newreply, $showthread, $forumpermissions;

        if ($forumpermissions['canpostthreads'] == 0)
        {
                $newthread = "";
        }

        if ($forumpermissions['canpostreplys'] == 0)
        {
                $newreply = "";
                "\<div class=\"threadBottom\"></div>" = "";
        }
}

I thought that this way the whole <div class="threadBottom"> container won't be visible for guests, but this actually resulted in a white page/php error.

Can anyone tell me what my mistake was and how to do it correctly if possible? Thanks in advance.
you can't just assign a string to a string like that. if you just want to hide the bit and not remove it from the output, then you can try the pre_output_page hook and alter the $contents variable by doing a string replace from

<div class="threadBottom">
to
<div class="threadBottom" style="display: none">
Hi,

oh I want to remove it completly from the output. Isn't there anything I can put beneth $newreply = ""; to remove the particular div container with its content from the output?
then use a preg_replace() using <div class="threadBottom"> as the start and </div> as the end of the pattern (You'd need to figure out the regex yoruself unless someone else will offer it up) and the make the replacement blank, "".

Use the same pre_output_page hook.
(2012-02-09, 09:02 PM)pavemen Wrote: [ -> ]then use a preg_replace() using <div class="threadBottom"> as the start and </div> as the end of the pattern (You'd need to figure out the regex yoruself unless someone else will offer it up) and the make the replacement blank, "".

Use the same pre_output_page hook.

Thanks, but I really don't understand this as I am new to php Blush

However I have half-solved this problem through a different method.

First I have created another template with the name "showthread_test" and put the particular code from above inside.

Then I have opened the showthread.php file and placed

eval("\$test = \"".$templates->get("showthread_test")."\";");

right beneth

eval("\$newreply = \"".$templates->get("showthread_newreply")."\";");

Then I have put {$test} in the showthread template to test if it worked, and it indeed worked however with one major issue: The subscribe to thread button was not there because something unexpected happend with the html output.

This is the output that I got:

<div class="threadBottom">
	<ul class="thread_tools">
		<li class="subscription_">
			<a href="usercp2.php?action=subscription&amp;tid=1&amp;my_post_key=8f34f50e180178bb329ae97716214d52">
			</a>
		</li>
	</ul>
</div>

The correct outbut should be this:

<div class="threadBottom">
	<ul class="thread_tools">
		<li class="subscription_add">
			<a href="usercp2.php?action=addsubscription&amp;tid=1&amp;my_post_key=8f34f50e180178bb329ae97716214d52">Subscribe to this thread
			</a>
		</li>
	</ul>
</div>

I get the correct output only if I place the particular HTML code directly in the showthread template.

If this issue can be solved, then the whole issue is solved.
as i mentioned above, these would have been the manual template edits required.

the location you added the new eval() line is likely before the code is generated that you need.

remove the part you added and stick it in your plugin and hook into showthread_end and just be sure to global the $test variable.
Hi, the buttoncheck.php plugin I am using is not part of the problem I am experiencing at this time. First I have to make sure that the variable $test is working, then I have to deal with the buttoncheck plugin. The problem I figured is that the variable

{$add_remove_subscription}

from the showthread_test template is being ignored. It only works if it's physically existent in the showthread template :/

EDIT: I have given up. For now I placed rel="nofollow" inside the a tag of the subscribe to thread link to prevent something like that:

[Image: yuwmlel9.png]