Created
January 22, 2011 19:29
-
-
Save erikfrerejean/791379 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function hook_tabitha(&$hook) | |
{ | |
global $db, $template, $user; | |
if (empty($template->_tpldata['postrow'])) | |
{ | |
return; | |
} | |
// Founders can always warn | |
if ($user->data['user_type'] == USER_FOUNDER) | |
{ | |
return; | |
} | |
// First loop throught the template rows and create a map that links | |
// the "postrow" to the ID of the actual poster | |
$postrow_posterid = array(); | |
foreach ($template->_tpldata['postrow'] as $row => $data) | |
{ | |
$postrow_posterid[$row] = $data['POSTER_ID']; | |
} | |
// Now we know the user ids, select their `group_warn` status | |
$userid_groupwarn = array(); | |
$sql_array = array( | |
'SELECT' => 'g.group_id, g.group_warn, u.user_id, u.group_id', | |
'FROM' => array( | |
USERS_TABLE => 'u', | |
), | |
'LEFT_JOIN' => array( | |
array( | |
'FROM' => array(GROUPS_TABLE => 'g'), | |
'ON' => 'g.group_id = u.group_id' | |
), | |
), | |
'WHERE' => $db->sql_in_set('u.user_id', $postrow_posterid), | |
); | |
$sql = $db->sql_build_query('SELECT', $sql_array); | |
$result = $db->sql_query($sql); | |
while ($row = $db->sql_fetchrow($result)) | |
{ | |
$userid_groupwarn[$row['user_id']] = $row['group_warn']; | |
} | |
$db->sql_freeresult($result); | |
// At this point we've got all information we need, loop once again through | |
// the `postrow` and inject a new template variable into the row. | |
// This variable will be accessable through `postrow.S_GROUP_WARN` | |
foreach ($postrow_posterid as $row => $id) | |
{ | |
if (!$userid_groupwarn[$id]) | |
{ | |
// Alterblock array love ^^ | |
$template->alter_block_array('postrow', array( | |
'U_WARN' => false, | |
), $row, 'change'); | |
} | |
} | |
} | |
$phpbb_hook->register(array('template', 'display'), 'hook_tabitha'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function hook_tabitha_mcp(&$hook) | |
{ | |
global $db, $module, $user; | |
// Skip founders always | |
if ($user->data['user_type'] == USER_FOUNDER) | |
{ | |
return; | |
} | |
// No Module, certainly no MCP | |
if (!isset($module) || ($module instanceof p_master) === false) | |
{ | |
return; | |
} | |
// No MCP | |
if ($module->p_class != 'mcp') | |
{ | |
return; | |
} | |
// Make sure that we're either on the warning or banning tab | |
if ($module->p_name != 'warn' && $module->p_name != 'ban') | |
{ | |
return; | |
} | |
// When bansubmitting | |
if ((isset($_REQUEST['bansubmit']) && $module->p_mode == 'user') || ($module->p_mode == 'warn_user' && isset($_REQUEST['action']['add_warning']) && $_REQUEST['action']['add_warning'] == 'Submit')) | |
{ | |
// See if the user is part of a non ban group | |
if (isset($_REQUEST['bansubmit'])) | |
{ | |
$ban = utf8_normalize_nfc(request_var('ban', '', true)); | |
$list = array_unique(explode("\n", $ban)); | |
array_walk($list, 'utf8_clean_string'); | |
$sql = 'SELECT u.username, g.group_ban | |
FROM (' . USERS_TABLE . ' u, ' . GROUPS_TABLE . ' g) | |
WHERE ' . $db->sql_in_set('u.username_clean', $list) . ' | |
AND g.group_id = u.group_id'; | |
} | |
else | |
{ | |
$user_id = request_var('u', 0); | |
$sql = 'SELECT u.username, g.group_ban | |
FROM (' . USERS_TABLE . ' u, ' . GROUPS_TABLE . " g) | |
WHERE u.user_id = {$user_id} | |
AND g.group_id = u.group_id"; | |
} | |
$result = $db->sql_query($sql); | |
$gbs = $db->sql_fetchrowset($result); | |
$db->sql_freeresult($result); | |
// See whether there is a user in the ban list that can't be banned | |
foreach ($gbs as $gb) | |
{ | |
if ($gb['group_ban'] == 0) | |
{ | |
trigger_error("Can't ban: {$gb['username']}", E_USER_ERROR); | |
} | |
} | |
} | |
} | |
// Need this hook to be executed *before* the module code | |
$phpbb_hook->register(array('template', 'display'), 'hook_tabitha_mcp'); |
Yez, its for /me super sekredt tabitha project ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hook_tabitha?