Advertisement
Guest User

function_pm_block.php

a guest
Jan 2nd, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.88 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @author mtrs
  6. * @version $Id$ functions_pm_block.php 1.0.0 - 04.12.2009
  7. * @copyrigh(c) 2009 mtrs
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. *
  10. */
  11. /**
  12. * @ignore
  13. */
  14.  
  15. if (!defined('IN_PHPBB'))
  16. {
  17. exit();
  18. }
  19.  
  20. function pm_block_on_profile_link(&$to_user_id, &$error)
  21. {
  22. //If blocked user tries to send pm by clicking on PM link in user profile, trigger error
  23. global $db, $user, $config, $auth;
  24.  
  25. if (!$config['pm_blocking_enable'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_') || $to_user_id == 0)
  26. {
  27. return;
  28. }
  29.  
  30. if ($config['pm_foe_friend_enable'])
  31. {
  32. //Block PMs by users who are not PM friends
  33. $sql = 'SELECT zebra_pm_id
  34. FROM ' . ZEBRA_PM_TABLE . '
  35. WHERE user_id = ' . $to_user_id . '
  36. AND friend = 1';
  37. $result = $db->sql_query($sql);
  38.  
  39. $friend_list = array();
  40. while ($row = $db->sql_fetchrow($result))
  41. {
  42. $friend_list[] = $row['zebra_pm_id'];
  43. }
  44. $db->sql_freeresult($result);
  45.  
  46. if (sizeof($friend_list))
  47. {
  48. if (!in_array($user->data['user_id'], $friend_list))
  49. {
  50. $error[] = $user->lang['PM_RECEIVE_BLOCKED_NOT_WHITELIST'];
  51. $to_user_id = 0;
  52. return;
  53. }
  54. }
  55.  
  56. //Block PMs by users who are PM foes
  57. $sql = 'SELECT z.foe, z.zebra_pm_reason, u.username
  58. FROM ' . ZEBRA_PM_TABLE . ' z, ' . USERS_TABLE . ' u
  59. WHERE foe = 1
  60. AND z.user_id = ' . $to_user_id . '
  61. AND z.zebra_pm_id = ' . $user->data['user_id'] . '
  62. AND u.user_id = z.user_id';
  63. $result = $db->sql_query_limit($sql, 1);
  64. $row = $db->sql_fetchrow($result);
  65. $db->sql_freeresult($result);
  66.  
  67. if ($row)
  68. {
  69. if (!empty($row['zebra_pm_reason']) && $config['pm_foe_reason_enable'])
  70. {
  71. //This is the custom pm block reason message entered by user
  72. $message = sprintf($user->lang['PM_BLOCK_REASON_BY_USER'], $row['username'], censor_text($row['zebra_pm_reason']));
  73. add_log('user', $user->data['user_id'], 'LOG_USER_PM_BLOCKED', $user->data['username'], $row['username'], $row['zebra_pm_reason']);
  74. }
  75. else
  76. {
  77. //This case, user didn't enter a reason, so we show default block reason
  78. $message = $user->lang['PM_RECEIVE_BLOCKED_FROM_BLACKLIST'];
  79. }
  80. $error[] = $message;
  81. $to_user_id = 0;
  82. return;
  83. }
  84. }
  85.  
  86. if ($config['pm_zebra_enable'])
  87. {
  88. //We control forum foes to block private messages
  89. $sql = 'SELECT foe
  90. FROM ' . ZEBRA_TABLE . '
  91. WHERE foe = 1
  92. AND user_id = ' . $to_user_id . '
  93. AND zebra_id = ' . $user->data['user_id'];
  94. $result = $db->sql_query_limit($sql, 1);
  95. $row = $db->sql_fetchrow($result);
  96. $db->sql_freeresult($result);
  97.  
  98. if ($row)
  99. {
  100. //This case we controll zebra table if user is foe, if so block pm
  101. $error[] = $user->lang['PM_RECEIVE_BLOCKED_FROM_FOES'];
  102. $to_user_id = 0;
  103. return;
  104. }
  105. }
  106.  
  107. if (isset($user->data['user_no_pms_to']) && $config['pm_admin_block_enable'])
  108. {
  109. //This is the admin controlled user IDs block list at ACP user_overview
  110. $user_no_pms_to = ($user->data['user_no_pms_to']) ? explode(",", $user->data['user_no_pms_to']) : array();
  111. if (in_array($to_user_id,$user_no_pms_to))
  112. {
  113. $error[] = $user->lang['PM_NOT_ALLOWED_TO_SOME_USERS'];
  114. $to_user_id = 0;
  115. return;
  116. }
  117. }
  118.  
  119. return;
  120. }
  121.  
  122. function pm_block_add_control(&$user_id_ary, &$error, $reply)
  123. {
  124. //We controll if user tries to add a dissallowed username
  125. global $db, $user, $config, $auth;
  126.  
  127. if (empty($user_id_ary) || !$config['pm_blocking_enable'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))
  128. {
  129. return;
  130. }
  131.  
  132. if ($config['pm_foe_friend_enable'])
  133. {
  134. //We controll the list, if only some users allowed to send private messages
  135. $sql = 'SELECT user_id, zebra_pm_id
  136. FROM ' . ZEBRA_PM_TABLE . '
  137. WHERE ' . $db->sql_in_set('user_id', $user_id_ary) . '
  138. AND friend = 1';
  139. $result = $db->sql_query($sql);
  140.  
  141. $friend_ids_list = $user_id_friends = $not_friend = $user_foe_ary = array();
  142. while ($row = $db->sql_fetchrow($result))
  143. {
  144. $friend_ids_list[$row['user_id']][$row['zebra_pm_id']] = 1;
  145. $user_id_friends[] = $row['user_id'];
  146. }
  147. $db->sql_freeresult($result);
  148.  
  149. $user_id_friends = array_unique($user_id_friends);
  150. if (sizeof($user_id_friends))
  151. {
  152. for ($i = 0, $j = sizeof($user_id_friends); $i < $j; $i++)
  153. {
  154. if (isset($friend_ids_list[$user_id_friends[$i]][$user->data['user_id']]))
  155. {
  156. return false;
  157. }
  158. else
  159. {
  160. $not_friend[] = $user_id_friends[$i];
  161. }
  162. }
  163.  
  164. }
  165.  
  166. if (sizeof($not_friend))
  167. {
  168. $user_id_ary = array_diff($user_id_ary, $not_friend);
  169. $error[] = ($reply) ? $user->lang['PM_SUBMIT_BLOCKED_NOT_WHITELIST'] : $user->lang['PM_RECEIVE_BLOCKED_NOT_WHITELIST'];
  170. }
  171. if (sizeof($error))
  172. {
  173. return;
  174. }
  175. //We controll pm dissallowed users in list
  176. $sql = 'SELECT z.user_id, z.zebra_pm_reason, u.username
  177. FROM ' . ZEBRA_PM_TABLE . ' z, ' . USERS_TABLE . ' u
  178. WHERE foe = 1
  179. AND ' . $db->sql_in_set('z.user_id', $user_id_ary) . '
  180. AND z.zebra_pm_id = ' . $user->data['user_id'] . '
  181. AND u.user_id = z.user_id';
  182. $result = $db->sql_query($sql);
  183.  
  184. //We show user specified block reason if there is only one user in address list
  185. $user_count = 1;
  186. while ($row = $db->sql_fetchrow($result))
  187. {
  188. if (!empty($row['zebra_pm_reason']) && $user_count == 1 && $config['pm_foe_reason_enable'])
  189. {
  190. //This is the custom pm block reason message entered by user
  191. add_log('user', $user->data['user_id'], 'LOG_USER_PM_BLOCKED', $user->data['username'], $row['username'], censor_text($row['zebra_pm_reason']));
  192. $error[] = sprintf($user->lang['PM_BLOCK_REASON_BY_USER'], $row['username'], $row['zebra_pm_reason']);
  193. }
  194. else
  195. {
  196. //This case, user didn't enter a reason, so we show default reason
  197. $error[] = ($reply) ? $user->lang['PM_SUBMIT_BLOCKED_FROM_BLACKLIST'] : $user->lang['PM_RECEIVE_BLOCKED_FROM_BLACKLIST'];
  198. }
  199. $user_count++;
  200. $user_foe_ary[] = $row['user_id'];
  201. }
  202. $db->sql_freeresult($result);
  203. $user_id_ary = array_diff($user_id_ary, $user_foe_ary);
  204. }
  205.  
  206. if(!sizeof($error) && $config['pm_zebra_enable'])
  207. {
  208. $sql = 'SELECT user_id
  209. FROM ' . ZEBRA_TABLE . '
  210. WHERE foe = 1
  211. AND ' . $db->sql_in_set('user_id', $user_id_ary) . '
  212. AND zebra_id = ' . $user->data['user_id'];
  213. $result = $db->sql_query($sql);
  214.  
  215. while ($row = $db->sql_fetchrow($result))
  216. {
  217. //In this case we show the default reason
  218. $error[] = ($reply) ? $user->lang['PM_SUBMIT_BLOCKED_FROM_FOES'] : $user->lang['PM_RECEIVE_BLOCKED_FROM_FOES'];
  219. $user_foe_ary[] = $row['user_id'];
  220. }
  221. $db->sql_freeresult($result);
  222. $user_id_ary = array_diff($user_id_ary, $user_foe_ary);
  223. }
  224.  
  225. if (isset($user->data['user_no_pms_to']) && $config['pm_admin_block_enable'])
  226. {
  227. $user_no_pms_to = ($user->data['user_no_pms_to']) ? explode(",", $user->data['user_no_pms_to']) : array();
  228. for ($i = 0, $j = sizeof($user_no_pms_to); $i < $j; $i++)
  229. {
  230. if (in_array($user_no_pms_to[$i], $user_id_ary))
  231. {
  232. $error[] = $user->lang['PM_NOT_ALLOWED_TO_SOME_USERS'];
  233. }
  234. $user_id_ary = array_diff($user_id_ary, $user_no_pms_to);
  235. }
  236. }
  237. return;
  238. }
  239.  
  240.  
  241. function pm_reply_submit_block(&$address_list, &$error, $reply)
  242. {
  243. //We control before submitting private message or reply, whether user is blocked or not
  244. global $user, $config, $auth;
  245.  
  246. if (!isset($address_list['u']) || !$config['pm_blocking_enable'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))
  247. {
  248. return;
  249. }
  250.  
  251. $user_id_ary_old = array_keys($address_list['u']);
  252. $user_id_ary = $user_id_ary_old;
  253.  
  254. pm_block_add_control($user_id_ary, $error, $reply);
  255.  
  256. $user_id_remove_ary = array_diff($user_id_ary_old, $user_id_ary);
  257.  
  258. if(sizeof($user_id_remove_ary))
  259. {
  260. for ($i = 0, $j = sizeof($user_id_remove_ary); $i < $j; $i++)
  261. {
  262. unset($address_list['u'][$user_id_remove_ary[$i]]);
  263. }
  264. }
  265. }
  266.  
  267. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement