PDA

View Full Version : Add-On Releases - Banlog Stats


jredrum
08-13-2008, 10:00 PM
What it does? - Adds a simple banlog to show who has been banned, for what reason, and how long until that ban is up.

Demo - http://www.theboredspot.com/banlog.php



Instructions:
First, create a file called 'banlog.php' in your forum root. Copy/paste this in that file

<?php

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

define('THIS_SCRIPT', 'banlist');

// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
'my_banlist'
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');

// #################### HARD CODE JAVASCRIPT PATHS ########################
$headinclude = str_replace('clientscript', $vbulletin->options['bburl'] . '/clientscript', $headinclude);

// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################

$navbits = array();

$navbits[$parent] = 'The Ban Log';

$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');

$querygroups = array();
foreach ($vbulletin->usergroupcache AS $usergroupid => $usergroup)
{
if (!($usergroup['genericoptions'] & $vbulletin->bf_ugp_genericoptions['isnotbannedgroup']))
{
$querygroups["$usergroupid"] = $usergroup['title'];
}
}
if (!empty($querygroups))
{
// now query users from the specified groups
$getusers = $db->query_read("
SELECT user.userid, user.username, user.usergroupid AS busergroupid,
userban.usergroupid AS ousergroupid,
IF(userban.displaygroupid = 0, userban.usergroupid, userban.displaygroupid) AS odisplaygroupid,
bandate, liftdate, reason,
adminuser.userid AS adminid, adminuser.username AS adminname
FROM " . TABLE_PREFIX . "user AS user
LEFT JOIN " . TABLE_PREFIX . "userban AS userban ON(userban.userid = user.userid)
LEFT JOIN " . TABLE_PREFIX . "user AS adminuser ON(adminuser.userid = userban.adminid)
WHERE user.usergroupid IN(" . implode(',', array_keys($querygroups)) . ")
ORDER BY userban.liftdate ASC, user.username
");
if ($db->num_rows($getusers))
{
$users = array();
while ($user = $db->fetch_array($getusers))
{
$temporary = iif($user['liftdate'], 1, 0);
$users["$temporary"][] = $user;
}
}
$db->free_result($getusers);

// show temporarily banned users
if (!empty($users[1]))
{
foreach ($users[1] AS $user)
{
if ($user['liftdate'] == 0)
{
$user['banperiod'] = $vbphrase['permanent'];
$user['banlift'] = $vbphrase['never'];
$user['banremaining'] = $vbphrase['forever'];
}
else
{
$user['banlift'] = vbdate($vbulletin->options['dateformat'] . ', ~' . $vbulletin->options['timeformat'], $user['liftdate']);
$user['banperiod'] = ceil(($user['liftdate'] - $user['bandate']) / 86400);
if ($user['banperiod'] == 1)
{
$user['banperiod'] .= " $vbphrase[day]";
}
else
{
$user['banperiod'] .= " $vbphrase[days]";
}

$remain = $user['liftdate'] - TIMENOW;
$remain_days = floor($remain / 86400);
$remain_hours = ceil(($remain - ($remain_days * 86400)) / 3600);
if ($remain_hours == 24)
{
$remain_days += 1;
$remain_hours = 0;
}

if ($remain_days < 0)
{
$user['banremaining'] = "<i>$vbphrase[will_be_lifted_soon]</i>";
}
else
{
if ($remain_days == 1)
{
$day_word = $vbphrase['day'];
}
else
{
$day_word = $vbphrase['days'];
}
if ($remain_hours == 1)
{
$hour_word = $vbphrase['hour'];
}
else
{
$hour_word = $vbphrase['hours'];
}
$user['banremaining'] = "$remain_days $day_word, $remain_hours $hour_word";
}
}
$lista .= "<tr>
<td valign=\"top\" class=\"alt1\">
<div class=\"smallfont\">".$user['username']."</div>
</td>
<td align=\"center\" valign=\"top\" class=\"alt1\">
<div class=\"smallfont\">".$user['adminname']."</div>
</td>
<td align=\"right\" valign=\"top\" class=\"alt1\">
<div class=\"smallfont\">".vbdate($vbulletin->options['dateformat'], $user['bandate'])."</div>
</td>
<td align=\"center\" valign=\"top\" class=\"alt1\">
<div class=\"smallfont\">".$user['banperiod']."</div>
</td>
<td align=\"right\" valign=\"top\" class=\"alt1\">
<div class=\"smallfont\">".$user['banlift']."</div>
</td>
<td align=\"center\" valign=\"top\" class=\"alt1\">
<div class=\"smallfont\">".$user['banremaining']."</div>
</td>
<td align=\"right\" valign=\"top\" class=\"alt1\">
<div class=\"smallfont\">".$user['reason']."</div>
</td>
</tr>";
}
}

// show permanently banned users
if (!empty($users[0]))
{
foreach ($users[0] AS $user)
{
if ($user['liftdate'] == 0)
{
$user['banperiod'] = "Permanent";
$user['banlift'] = "Never";
$user['banremaining'] = "Forever";
}
else
{
$user['banlift'] = vbdate($vbulletin->options['dateformat'] . ', ~' . $vbulletin->options['timeformat'], $user['liftdate']);
$user['banperiod'] = ceil(($user['liftdate'] - $user['bandate']) / 86400);
if ($user['banperiod'] == 1)
{
$user['banperiod'] .= " $vbphrase[day]";
}
else
{
$user['banperiod'] .= " $vbphrase[days]";
}

$remain = $user['liftdate'] - TIMENOW;
$remain_days = floor($remain / 86400);
$remain_hours = ceil(($remain - ($remain_days * 86400)) / 3600);
if ($remain_hours == 24)
{
$remain_days += 1;
$remain_hours = 0;
}

if ($remain_days < 0)
{
$user['banremaining'] = "<i>$vbphrase[will_be_lifted_soon]</i>";
}
else
{
if ($remain_days == 1)
{
$day_word = $vbphrase['day'];
}
else
{
$day_word = $vbphrase['days'];
}
if ($remain_hours == 1)
{
$hour_word = $vbphrase['hour'];
}
else
{
$hour_word = $vbphrase['hours'];
}
$user['banremaining'] = "$remain_days $day_word, $remain_hours $hour_word";
}
}
$listb .= "<tr>
<td valign=\"top\" class=\"alt1\">
<div class=\"smallfont\">".$user['username']."</div>
</td>
<td align=\"center\" valign=\"top\" class=\"alt1\">
<div class=\"smallfont\">".$user['adminname']."</div>
</td>
<td align=\"right\" valign=\"top\" class=\"alt1\">
<div class=\"smallfont\">".vbdate($vbulletin->options['dateformat'], $user['bandate'])."</div>
</td>
<td align=\"center\" valign=\"top\" class=\"alt1\">
<div class=\"smallfont\">".$user['banperiod']."</div>
</td>
<td align=\"center\" valign=\"top\" class=\"alt1\">
<div class=\"smallfont\">".$user['banlift']."</div>
</td>
<td align=\"center\" valign=\"top\" class=\"alt1\">
<div class=\"smallfont\">".$user['banremaining']."</div>
</td>
<td align=\"right\" valign=\"top\" class=\"alt1\">
<div class=\"smallfont\">".$user['reason']."</div>
</td>
</tr>";
}
}
}

eval('print_output("' . fetch_template('my_banlist') . '");');

?>

Next, create a new template for each style you have called 'my_banlist'

Copy/paste this code:

$stylevar[htmldoctype]
<html xmlns="http://www.w3.org/1999/xhtml" dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
$headinclude
<title>Banlog - $vboptions[bbtitle]</title>
</head>
<body>

$header
$navbar

<table class="tborder" align="center" border="0" cellpadding="3" cellspacing="2" width="100%">
<tr>
<td colspan="7" class="tcat">
<strong>Banned Users: Temporary Bans</strong>
</td>
</tr>
<tr>
<td align="center" class="alt1">
<strong>User Name</strong>
</td><br />
<td align="center" class="alt1">
<strong>Banned By</strong>
</td>
<td align="center" class="alt1">
<strong>Banned On</strong>
</td>
<td align="center" class="alt1">
<strong>Ban Period</strong>
</td>
<td align="center" class="alt1">
<strong>Ban Will Be Lifted On</strong>
</td>
<td align="center" class="alt1">
<strong>Ban Time Remaining</strong>
</td>
<td align="center" class="alt1">
<strong>Ban Reason</strong>
</td>
</tr>

<if condition="$lista == ''">

</table><br />

<div align="center"><strong>No one is currently banned... Hmmmm... Must be a good day!</strong></div>

<else />

$lista

</table><br />

</if>



<table class="tborder" align="center" border="0" cellpadding="3" cellspacing="2" width="100%">
<tr>
<td colspan="7" class="tcat">
<strong>Banned Users: Permanent Bans</strong>
</td>
</tr>
<tr>
<td align="center" class="alt1">
<strong>User Name</strong>
</td><br />
<td align="center" class="alt1">
<strong>Banned By</strong>
</td>
<td align="center" class="alt1">
<strong>Banned On</strong>
</td>
<td align="center" class="alt1">
<strong>Ban Period</strong>
</td>
<td align="center" class="alt1">
<strong>Ban Will Be Lifted On</strong>
</td>
<td align="center" class="alt1">
<strong>Ban Time Remaining</strong>
</td>
<td align="center" class="alt1">
<strong>Ban Reason</strong>
</td>
</tr>


<if condition="$listb == ''">

</table><br />

<div align="center"><strong>No one is currently banned... Hmmmm... Must be a good day!</strong></div>

<else />

$listb

</table><br />

</if>

$footer
</body>
</html>


That's it. :)

This should work for any version, though I have only tested it on 3.7

This mod is not supported.

GaiLoan
08-14-2008, 06:17 PM
thanks and install

ssslippy
08-14-2008, 06:51 PM
This should really be a product. Very nicely laid out though.

jredrum
08-14-2008, 11:59 PM
This should really be a product. Very nicely laid out though.

Thanks, wasn't sure where it should be. lol

lostguy
08-15-2008, 02:14 AM
what a mess here ! ...U need have XML for us to install dude . Alot risk doing this change with our php . Try prepare it well before share.

I do like your IDEA but still more to do with this one

lg

Rat1972
08-15-2008, 04:07 AM
what a mess here ! ...U need have XML for us to install dude . Alot risk doing this change with our php . Try prepare it well before share.

I do like your IDEA but still more to do with this one

lg

Why does he need a XML? That is for lazy people.
Only thing what you have to do, is those two steps and it's finished.....

GoTTi
08-15-2008, 04:20 AM
nice i have been looking for this for a long time. should make it a plugin though and make it maybe viewable by usergroups with specific permissions only...

GoTTi
08-15-2008, 04:21 AM
need to make the whos online show that a user is viewing banlog or something...how do i do that again?

Hornstar
08-15-2008, 05:10 AM
nice idea, not sure ill use it tho. but thanks for sharing.

KURTZ
08-15-2008, 10:52 AM
really useful ... :)

edit: there is an alignment trouble ... check the attachment ... :) (fixed into my banlog.php attached)

also can you provide a new release with a redirect to the user profile that is banned?

logicuk
08-15-2008, 11:52 AM
Nice idea but please make as a plugin :)

lostguy
08-15-2008, 12:48 PM
Why does he need a XML? That is for lazy people.
Only thing what you have to do, is those two steps and it's finished.....

Well VB have provided us options for Product and Plugin sections thats what it use for ! We not lazy just that we do worry our own board and database .

Stupid people always make the first move but i do appreciated people like you for a TESTER .

lg

jredrum
08-15-2008, 01:10 PM
I'm not doing any more on this. It's a simple thing to addon. If you don't want to do it, then don't.

KURTZ
08-15-2008, 02:55 PM
just a question: but only admins are logged into this log?

jredrum
08-15-2008, 03:32 PM
just a question: but only admins are logged into this log?

Any mod that has banning ability will show as the person who banned a particular user.

john102774
08-15-2008, 04:31 PM
really useful ... :)

edit: there is an alignment trouble ... check the attachment ... :) (fixed into my banlog.php attached)

also can you provide a new release with a redirect to the user profile that is banned?

This works. Thanks!

nexus_dublin
08-16-2008, 07:51 AM
Thanks mate, very nice and very easy! Thumbs up! :up::up::up:

Small note - I went one extra step and removed the three columns from the permanent bans table (banperiod, banlift and banremaining) as they are really redundant in that context.