Log in

View Full Version : Custom Banned Reason Template


yotsume
11-18-2010, 08:49 PM
Custom Banned Reason Template

How can I pull the banned reason message that we type into the vbAdminCP when we ban a member?

I am trying to create a custom page that has the info but the calls for that phrase show blank when I make my own template for it.

<!-- BANNED REASON -->
<tr>
<td class="$altbgclass">
<table border="0" cellpadding="10"><tr>
<tr><td><phrase argument_list>$vbphrase[nopermission_banned]</phrase></td></tr>
</table>
</td>
</tr>
<!-- BANNED REASON -->How can I code this?

I want to be able to use the info in my attached image in my own template.

kh99
11-19-2010, 08:32 AM
Where is your template used? I'm asking because you can't necessarily just use a phrase in your template and have the reason filled in. You would need to have code (like in a plugin) read the reason from the database first. The exception might be if your template happens to be used in a place where it's already been read (like if you're just trying to replace the standard error message template).

But maybe you already know all that - in that case, check out the function print_no_permission() in includes/functions.php.

yotsume
11-19-2010, 08:54 AM
I plan to use it in a vbadvanced cmps block. I want to pull the banned reason to show inside a vba block. Other VB phrases seem easy to pull but this one is proving to be difficult. :(

kh99
11-19-2010, 09:28 AM
Oh...In that case you did understand all that and I didn't understand the question. Sorry.

yotsume
11-19-2010, 09:33 AM
Oh im with you I just am lost as to how to get the message to show in a vba block. I am gonna need some help with this one.

kh99
11-19-2010, 09:36 AM
...but I think I might know what the problem is: that phrase is in a phrase group that isn't loaded. The error message functions call function fetch_phrase() in includes/functions_misc.php to load it when needed.

yotsume
11-19-2010, 09:43 AM
You I found that out and do not how to proceed. I am guessing I am going to have to code my own plug-in??? to pull the data from the database in a similar manner that is done in the functions.php

I was hoping there was another easier way...

kh99
11-19-2010, 02:13 PM
Well, you didn't ask but I thought I'd do it anyway:


global $vbulletin;

$ugid = $vbulletin->userinfo['usergroupid'];
if (!($vbulletin->usergroupcache["$ugid"]['genericoptions'] & $vbulletin->bf_ugp_genericoptions['isnotbannedgroup']))
{
require_once(DIR . '/includes/functions_misc.php');
$banreason= $vbulletin->db->query_first_slave("
SELECT reason, liftdate
FROM " . TABLE_PREFIX . "userban
WHERE userid = " . $vbulletin->userinfo['userid']
);

// Check for a date or a perm ban
if ($banreason['liftdate'])
{
$unbandate = vbdate($vbulletin->options['dateformat'] . ', ' . $vbulletin->options['timeformat'], $banreason['liftdate']);
}
else
{
$unbandate = $vbphrase['never'];
}
if (!$banreason['reason'])
{
$banreason['reason'] = fetch_phrase('no_reason_specified', 'error');
}
$vbulletin->userinfo['banned_reason_text'] = sprintf(fetch_phrase('nopermission_banned', 'error'), $banreason['reason'], $unbandate );
}


then you can use $bbuserinfo[banned_reason_text] in a template.

I tried this using the global_start hook, I don't know if it's the best hook to use but none of the vba_ hooks I tried worked.

yotsume
11-19-2010, 05:40 PM
Thanks for the help... what am I to do with your code exactly to be able to create a vba block?

kh99
11-19-2010, 05:50 PM
It depends on what kind of vBa module you're working with. It looks like you wanted to use it in a template, so you could create a new plugin with hook location "global_start" and use the above code (remember to select "Yes" to make it active), then put $bbuserinfo[banned_reason_text] in the template where you want the text to appear (it will be blank if the user isn't banned).

If you were making a php-type module you could use the above code directly in the module instead of creating a plugin.

yotsume
11-19-2010, 05:55 PM
Well I am already trying to use your code in a php module. So I placed your entire code in a php file and uploaded it to my modules directory and then created a new center block with it included but your code shows above the block when activated.

kh99
11-19-2010, 05:58 PM
Oh. If you put it in its own php file then the file needs to start with "<?php" on the first line and end with "?>" on the last line. You also will need to include some other stuff. It would probably be best to look at an existing module php file to see what to do, or else make the code a plugin and use a template module. (Creating a plugin is pretty easy, if you've never done it before).

yotsume
11-19-2010, 06:02 PM
So yea I added a new plug-in as you said to do and I am making a new template module in vba with this as my template code:

<!-- BANNED REASON -->
<tr>
<td class="$altbgclass">
<table border="0" cellpadding="10"><tr>
<tr><td>$bbuserinfo[banned_reason_text]</td></tr>
</table>
</td>
</tr>
<!-- BANNED REASON -->

This worked perfectly! THANK YOU!!!

Here is how my sick new YOU HAVE BEEN BANNED page looks when a member logins in:

Do you care if I release this here on vborg with you as credited for it's creation?

Side Note: The last bit I have to work out is I want to remove the vba module template wrapper so it shows without the block around it. However, when I select do not use the wrapper the block breaks and goes off to the side.

kh99
11-21-2010, 01:01 AM
Do you care if I release this here on vborg with you as credited for it's creation?
That's fine with me. You can mention me as having contributed if you want, but I don't care.

furnival
01-31-2011, 11:31 AM
Can anyone help me with a variation of the above please?
What I want to do is display the reason a user was banned under the word 'Banned' in the postbit.
I created a new plugin and inserted kh99's code. I assigned this plugin to the hook postbit_display_complete and made it active.
Then in the postbit template I inserted the code
<if condition="$bbuserinfo[banned_reason_text]"><div class="smallfont">$bbuserinfo[banned_reason_text]</div></if> just below where user titles are displayed. Yet the reason the user was banned does not display. Any ideas why not, please?

kh99
01-31-2011, 11:55 AM
Hey, this looks familiar... Anyway, I think the reason it isn't working is that $vbulletin->userinfo is the "current" user (the one viewing the page), and you need to look up the ban reason for the user who wrote the post. It might work if you use $post['usergroupid'] and $post['userid'] in place of $vbulletin->userinfo. There's also no reason to put the result in $vbulletin->userinfo['banned_reason_text'] - you could use $post there as well (so maybe just change $vbulletin->userinfo to $post everywhere in that code?).

Another thing you could do is to make a plugin on showthread_query and add the ban reason fields to the main post query (you can add to $hook_query_fields and $hook_query_joins in the plugin - see showthread.php around line 985). But I don't know, maybe if there are few users banned it would actually be faster to only do the query when needed rather than add it to every post. I suppose you could build a cache of ban info so that if a user posts a bunch of times on one page you're not doing the same query over and over.