MyBB Community Forums

Full Version: MyBB $thread
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
http://docs.mybb.com/Plugin_Methods.html is incomplete, so I couldn't find this.

I have a little group of moderators that are restricted to doing certain things. They can move posts, close threads and also "junk" them. For now though, I'm just adding buttons for ease of access for staff members.

At the moment I have this;

	<div class="float_right" style="padding-bottom: 8px;">
		{$selfclose}{$newreply}
	</div>
<if $mybb->user['usergroup'] == 4 || $mybb->user['usergroup'] == 3 then>
        <div class="float_right" style="padding-bottom; 8px;">
<form action="{$mybb->settings['bburl']}/moderation.php" method="post">
    <input type="hidden" name="modtype" value="thread" />
    <input type="hidden" name="tid" value="{$thread['tid']}" />
    <input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
    <input type="hidden" name="action" value="1" />
    <input type="submit" class="button" value="Junk" />
</form>
        </div>
</if>
<if $mybb->user['usergroup'] == 4 || $mybb->user['usergroup'] == 3 then>
<if $thread['open'] == 1 then>
        <div class="float_right" style="padding-bottom; 8px;">
<form action="{$mybb->settings['bburl']}/moderation.php" method="post">
    <input type="hidden" name="modtype" value="thread" />
    <input type="hidden" name="tid" value="{$thread['tid']}" />
    <input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
    <input type="hidden" name="action" value="4" />
    <input type="submit" class="button" value="Close" />
</form>
        </div>
<else>
        <div class="float_right" style="padding-bottom; 8px;">
<form action="{$mybb->settings['bburl']}/moderation.php" method="post">
    <input type="hidden" name="modtype" value="thread" />
    <input type="hidden" name="tid" value="{$thread['tid']}" />
    <input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
    <input type="hidden" name="action" value="4" />
    <input type="submit" class="button" value="Open" />
</form>
        </div>
</if>
</if>

The Junk button works like a charm, however the Open/close one doesn't work properly. I think, possibly, the $thread isn't being used properly. It displays Open regardless, the button works but it just shows the <else>, also tried with just $thread['open']. What's the correct way to check this?

BTW, I'm using Template Conditionals.
Well, first of all, $thread doesn't seem to be global a object for me. Probably a mistake in the documentation - it's not really the best source of knowledge right know.

Secondly, since it's impossible to describe what each of thousands of variables in different MyBB files does, you need to be able to find that out yourself. $thread in showthread.php:
// Get the thread details from the database.
$thread = get_thread($mybb->input['tid']);
Then the database threads table: http://docs.mybb.com/Database_Tables-mybb_threads.html
And you will see that open column doesn't exist, so $thread['open'] == 1 will return always false. Use $thread['closed'] instead, but watch out as it can also store moved status.
(2014-06-08, 09:53 AM)Destroy666 Wrote: [ -> ]Well, first of all, $thread doesn't seem to be global a object for me. Probably a mistake in the documentation - it's not really the best source of knowledge right know.

Secondly, since it's impossible to describe what each of thousands of variables in different MyBB files does, you need to be able to find that out yourself. $thread in showthread.php:
// Get the thread details from the database.
$thread = get_thread($mybb->input['tid']);
Then the database threads table: http://docs.mybb.com/Database_Tables-mybb_threads.html
And you will see that open column doesn't exist, so $thread['open'] == 1 will return always false. Use $thread['closed'] instead, but watch out as it can also store moved status.

If it stores moved status too then is there any way to only track thread open/closed status (apparently not due to columns, but I mean any alternative options/checks I can for accurate info).
You might look into using the intval function. Something like this:
$thread['closed'] = intval($thread['closed']);
if($thread['closed'] == 1)
{
// locked thread
}
if(!$thread['closed'])
{
// open thread
}
(2014-06-08, 08:48 PM)dragonexpert Wrote: [ -> ]You might look into using the intval function. Something like this:
$thread['closed'] = intval($thread['closed']);
if($thread['closed'] == 1)
{
// locked thread
}
if(!$thread['closed'])
{
// open thread
}

That would be fantastic in showthread.php, but I'm just adding this to the template, dunno if that's the best way and it's probably better to have them in the file, but I'm not too good of a PHP programmer so I have no idea how to do that, unless you'd rather explain that I just threw the following into a template file:

<if $mybb->user['usergroup'] == 4 || $mybb->user['usergroup'] == 3 then>
$thread['closed'] = intval($thread['closed']);
<if $thread['closed'] == 1 then>
        <div class="float_right" style="padding-bottom; 8px;">
<form action="{$mybb->settings['bburl']}/moderation.php" method="post">
    <input type="hidden" name="modtype" value="thread" />
    <input type="hidden" name="tid" value="{$thread['tid']}" />
    <input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
    <input type="hidden" name="action" value="4" />
    <input type="submit" class="button" value="Open" />
</form>
        </div>
<else>
        <div class="float_right" style="padding-bottom; 8px;">
<form action="{$mybb->settings['bburl']}/moderation.php" method="post">
    <input type="hidden" name="modtype" value="thread" />
    <input type="hidden" name="tid" value="{$thread['tid']}" />
    <input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
    <input type="hidden" name="action" value="4" />
    <input type="submit" class="button" value="Close" />
</form>
        </div>
</if>
</if>

And it left me with a white page. I'd prefer to put it in showthread.php but I dunno if I'd do it correctly.
You said you use Template Conditionals. dragonexpert's code for Template conditionals (just use function in condition):
<if intval($thread['closed']) == 1 then>
thread is closed
<else>
thread is open
</if>

Or you can use the setvar functionality, read more here: http://mybbhacks.zingaburga.com/showthread.php?tid=464
(2014-06-09, 02:36 PM)Destroy666 Wrote: [ -> ]You said you use Template Conditionals. dragonexpert's code for Template conditionals (just use function in condition):
<if intval($thread['closed']) == 1 then>
thread is closed
<else>
thread is open
</if>

Or you can use the setvar functionality, read more here: http://mybbhacks.zingaburga.com/showthread.php?tid=464

Cool, I can do that. By the way, for future reference (and cleaner templates) I'd like to ask how it's done in the actual file, I can easily do buttons and options if I knew how to do that, if you wouldn't mind giving me an example of course. Hate to be a pain.
Not sure what you mean. As I said in my first post here, you need to be able to find such things yourself in the source code because there are thousands of variables being used (or ask a direct question for each if you can't find them). I can't give you an example because I have no idea what you're looking for and there is no universal code for buttons/options.
(2014-06-09, 03:23 PM)Destroy666 Wrote: [ -> ]Not sure what you mean. As I said in my first post here, you need to be able to find such things yourself in the source code because there are thousands of variables being used (or ask a direct question for each if you can't find them). I can't give you an example because I have no idea what you're looking for and there is no universal code for buttons/options.

I mean if I wanted to code this directly into showthread.php (I'm assuming) and have {$openclosebutton} instead in the template (cleaner imo) how would I go around doing that?
It's not recommended to do it in files because you can lose your changes (if you have many and you don't use Patches plugin) during upgrades. But if you really want to, just assign your HTML to a variable inside the conditional (before a template is eval'd) and then add the variable to that template.

You can also make a plugin and hook to showthread_end: http://docs.mybb.com/MyBB_Plugin_Hooks.html then again assign HTML to variable in conditional. Then automatically insert the variable to template with find_replace_templatesets() function in activate/install function. This is much more efficient than editing files directly, in my opinion.
Pages: 1 2 3