Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @package phpBB3
- * @author mtrs
- * @version $Id$ functions_pm_block.php 1.0.0 - 04.12.2009
- * @copyrigh(c) 2009 mtrs
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- *
- */
- /**
- * @ignore
- */
- if (!defined('IN_PHPBB'))
- {
- exit();
- }
- function pm_block_on_profile_link(&$to_user_id, &$error)
- {
- //If blocked user tries to send pm by clicking on PM link in user profile, trigger error
- global $db, $user, $config, $auth;
- if (!$config['pm_blocking_enable'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_') || $to_user_id == 0)
- {
- return;
- }
- if ($config['pm_foe_friend_enable'])
- {
- //Block PMs by users who are not PM friends
- $sql = 'SELECT zebra_pm_id
- FROM ' . ZEBRA_PM_TABLE . '
- WHERE user_id = ' . $to_user_id . '
- AND friend = 1';
- $result = $db->sql_query($sql);
- $friend_list = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $friend_list[] = $row['zebra_pm_id'];
- }
- $db->sql_freeresult($result);
- if (sizeof($friend_list))
- {
- if (!in_array($user->data['user_id'], $friend_list))
- {
- $error[] = $user->lang['PM_RECEIVE_BLOCKED_NOT_WHITELIST'];
- $to_user_id = 0;
- return;
- }
- }
- //Block PMs by users who are PM foes
- $sql = 'SELECT z.foe, z.zebra_pm_reason, u.username
- FROM ' . ZEBRA_PM_TABLE . ' z, ' . USERS_TABLE . ' u
- WHERE foe = 1
- AND z.user_id = ' . $to_user_id . '
- AND z.zebra_pm_id = ' . $user->data['user_id'] . '
- AND u.user_id = z.user_id';
- $result = $db->sql_query_limit($sql, 1);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- if ($row)
- {
- if (!empty($row['zebra_pm_reason']) && $config['pm_foe_reason_enable'])
- {
- //This is the custom pm block reason message entered by user
- $message = sprintf($user->lang['PM_BLOCK_REASON_BY_USER'], $row['username'], censor_text($row['zebra_pm_reason']));
- add_log('user', $user->data['user_id'], 'LOG_USER_PM_BLOCKED', $user->data['username'], $row['username'], $row['zebra_pm_reason']);
- }
- else
- {
- //This case, user didn't enter a reason, so we show default block reason
- $message = $user->lang['PM_RECEIVE_BLOCKED_FROM_BLACKLIST'];
- }
- $error[] = $message;
- $to_user_id = 0;
- return;
- }
- }
- if ($config['pm_zebra_enable'])
- {
- //We control forum foes to block private messages
- $sql = 'SELECT foe
- FROM ' . ZEBRA_TABLE . '
- WHERE foe = 1
- AND user_id = ' . $to_user_id . '
- AND zebra_id = ' . $user->data['user_id'];
- $result = $db->sql_query_limit($sql, 1);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
- if ($row)
- {
- //This case we controll zebra table if user is foe, if so block pm
- $error[] = $user->lang['PM_RECEIVE_BLOCKED_FROM_FOES'];
- $to_user_id = 0;
- return;
- }
- }
- if (isset($user->data['user_no_pms_to']) && $config['pm_admin_block_enable'])
- {
- //This is the admin controlled user IDs block list at ACP user_overview
- $user_no_pms_to = ($user->data['user_no_pms_to']) ? explode(",", $user->data['user_no_pms_to']) : array();
- if (in_array($to_user_id,$user_no_pms_to))
- {
- $error[] = $user->lang['PM_NOT_ALLOWED_TO_SOME_USERS'];
- $to_user_id = 0;
- return;
- }
- }
- return;
- }
- function pm_block_add_control(&$user_id_ary, &$error, $reply)
- {
- //We controll if user tries to add a dissallowed username
- global $db, $user, $config, $auth;
- if (empty($user_id_ary) || !$config['pm_blocking_enable'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))
- {
- return;
- }
- if ($config['pm_foe_friend_enable'])
- {
- //We controll the list, if only some users allowed to send private messages
- $sql = 'SELECT user_id, zebra_pm_id
- FROM ' . ZEBRA_PM_TABLE . '
- WHERE ' . $db->sql_in_set('user_id', $user_id_ary) . '
- AND friend = 1';
- $result = $db->sql_query($sql);
- $friend_ids_list = $user_id_friends = $not_friend = $user_foe_ary = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $friend_ids_list[$row['user_id']][$row['zebra_pm_id']] = 1;
- $user_id_friends[] = $row['user_id'];
- }
- $db->sql_freeresult($result);
- $user_id_friends = array_unique($user_id_friends);
- if (sizeof($user_id_friends))
- {
- for ($i = 0, $j = sizeof($user_id_friends); $i < $j; $i++)
- {
- if (isset($friend_ids_list[$user_id_friends[$i]][$user->data['user_id']]))
- {
- return false;
- }
- else
- {
- $not_friend[] = $user_id_friends[$i];
- }
- }
- }
- if (sizeof($not_friend))
- {
- $user_id_ary = array_diff($user_id_ary, $not_friend);
- $error[] = ($reply) ? $user->lang['PM_SUBMIT_BLOCKED_NOT_WHITELIST'] : $user->lang['PM_RECEIVE_BLOCKED_NOT_WHITELIST'];
- }
- if (sizeof($error))
- {
- return;
- }
- //We controll pm dissallowed users in list
- $sql = 'SELECT z.user_id, z.zebra_pm_reason, u.username
- FROM ' . ZEBRA_PM_TABLE . ' z, ' . USERS_TABLE . ' u
- WHERE foe = 1
- AND ' . $db->sql_in_set('z.user_id', $user_id_ary) . '
- AND z.zebra_pm_id = ' . $user->data['user_id'] . '
- AND u.user_id = z.user_id';
- $result = $db->sql_query($sql);
- //We show user specified block reason if there is only one user in address list
- $user_count = 1;
- while ($row = $db->sql_fetchrow($result))
- {
- if (!empty($row['zebra_pm_reason']) && $user_count == 1 && $config['pm_foe_reason_enable'])
- {
- //This is the custom pm block reason message entered by user
- add_log('user', $user->data['user_id'], 'LOG_USER_PM_BLOCKED', $user->data['username'], $row['username'], censor_text($row['zebra_pm_reason']));
- $error[] = sprintf($user->lang['PM_BLOCK_REASON_BY_USER'], $row['username'], $row['zebra_pm_reason']);
- }
- else
- {
- //This case, user didn't enter a reason, so we show default reason
- $error[] = ($reply) ? $user->lang['PM_SUBMIT_BLOCKED_FROM_BLACKLIST'] : $user->lang['PM_RECEIVE_BLOCKED_FROM_BLACKLIST'];
- }
- $user_count++;
- $user_foe_ary[] = $row['user_id'];
- }
- $db->sql_freeresult($result);
- $user_id_ary = array_diff($user_id_ary, $user_foe_ary);
- }
- if(!sizeof($error) && $config['pm_zebra_enable'])
- {
- $sql = 'SELECT user_id
- FROM ' . ZEBRA_TABLE . '
- WHERE foe = 1
- AND ' . $db->sql_in_set('user_id', $user_id_ary) . '
- AND zebra_id = ' . $user->data['user_id'];
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
- {
- //In this case we show the default reason
- $error[] = ($reply) ? $user->lang['PM_SUBMIT_BLOCKED_FROM_FOES'] : $user->lang['PM_RECEIVE_BLOCKED_FROM_FOES'];
- $user_foe_ary[] = $row['user_id'];
- }
- $db->sql_freeresult($result);
- $user_id_ary = array_diff($user_id_ary, $user_foe_ary);
- }
- if (isset($user->data['user_no_pms_to']) && $config['pm_admin_block_enable'])
- {
- $user_no_pms_to = ($user->data['user_no_pms_to']) ? explode(",", $user->data['user_no_pms_to']) : array();
- for ($i = 0, $j = sizeof($user_no_pms_to); $i < $j; $i++)
- {
- if (in_array($user_no_pms_to[$i], $user_id_ary))
- {
- $error[] = $user->lang['PM_NOT_ALLOWED_TO_SOME_USERS'];
- }
- $user_id_ary = array_diff($user_id_ary, $user_no_pms_to);
- }
- }
- return;
- }
- function pm_reply_submit_block(&$address_list, &$error, $reply)
- {
- //We control before submitting private message or reply, whether user is blocked or not
- global $user, $config, $auth;
- if (!isset($address_list['u']) || !$config['pm_blocking_enable'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))
- {
- return;
- }
- $user_id_ary_old = array_keys($address_list['u']);
- $user_id_ary = $user_id_ary_old;
- pm_block_add_control($user_id_ary, $error, $reply);
- $user_id_remove_ary = array_diff($user_id_ary_old, $user_id_ary);
- if(sizeof($user_id_remove_ary))
- {
- for ($i = 0, $j = sizeof($user_id_remove_ary); $i < $j; $i++)
- {
- unset($address_list['u'][$user_id_remove_ary[$i]]);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement