Index: pm_block_user/pm_block_user.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/privatemsg/pm_block_user/pm_block_user.module,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 pm_block_user.module
--- pm_block_user/pm_block_user.module	20 Feb 2009 00:34:27 -0000	1.1.2.3
+++ pm_block_user/pm_block_user.module	6 Mar 2009 23:56:16 -0000
@@ -14,13 +14,76 @@ function pm_block_user_menu() {
     'title'            => 'Block user messages',
     'page callback'    => 'drupal_get_form',
     'page arguments'   => array('pm_block_user_form', 2),
-    'access callback'  => 'privatemsg_user_access',
+    'access callback'  => '_pm_block_user_access',
+    'access arguments' => array(2),
     'type'             => MENU_CALLBACK,
     'weight'           => -10,
   );
+
+  $items['admin/settings/messages/block'] = array(
+    'title'            => 'Block author settings',
+    'description'      => 'Configure block author settings.',
+    'page callback'    => 'drupal_get_form',
+    'page arguments'   => array('pm_block_user_settings'),
+    'access arguments' => array('administer privatemsg settings'),
+    'type'             => MENU_LOCAL_TASK,
+  );
   return $items;
 }
 
+function pm_block_user_settings(&$form_state) {
+  $form['pm_block_user_unblockable_roles'] = array(
+    '#type'           => 'checkboxes',
+    '#title'          => t('Select roles which cannot be blocked'),
+    '#description'    => t("Members of the selected roles can't be blocked by other users"),
+    '#options'        => user_roles(TRUE),
+    '#default_value'  => variable_get('pm_block_user_unblockable_roles', array()),
+  );
+
+  return system_settings_form($form);
+}
+
+/**
+ * Provides access argument for blocking user menu item.
+ *
+ * @param $account
+ *   User object representing the account the menu item will block private
+ *   messages from.
+ *
+ * @return
+ *   TRUE if the user is allowed to block $account, or FALSE if not.
+ */
+function _pm_block_user_access($account) {
+  global $user;
+  if (!user_access('read privatemsg', $user)) {
+    return FALSE;
+  }
+  if (!_pm_block_user_checkrole($account)) {
+    return FALSE;
+  }
+  return TRUE;
+}
+
+/**
+ * Checks whether it is possible to block private messages from a given user.
+ *
+ * @param $account
+ *   User object representing the user account to check.
+ *
+ * @return
+ *   Boolean value which is FALSE if it is not possible to block the user and
+ *   TRUE if the user can be blocked.
+ */
+function _pm_block_user_checkrole($account) {
+  if ($account->uid == 1) {
+    return FALSE;
+  }
+  if (array_intersect(array_keys((array) $account->roles), variable_get('pm_block_user_unblockable_roles', array()))) {
+    return FALSE;
+  }
+  return TRUE;
+}
+
 function pm_block_user_form($form_state, $author) {
   global $user;
 
@@ -69,8 +132,13 @@ function pm_block_user_form($form_state,
   }
 }
 
+/**
+ * Implementation of hook_form_submit().
+ */
 function pm_block_user_form_submit($form, &$form_state) {
-
+  if (!_pm_block_user_checkrole(user_load($author_id))) {
+    return;
+  }
   if ($form_state['values']['confirm']) {
     switch ($form_state['values']['block_action']) {
       case 'block_user':
@@ -90,7 +158,9 @@ function pm_block_user_form_submit($form
  * Implementation of hook_privatemsg_block_message.
  */
  function pm_block_user_privatemsg_block_message($author, $recipient) {
-  global $user;
+  if (_pm_block_user_checkrole($recipient)) {
+    return;
+  }
   $result = db_result(db_query('SELECT COUNT(*) FROM {pm_block_user} WHERE author = %d AND recipient = %d', $author->uid, $recipient->uid));
   if ($result <> 0) {
     return t('!name has chosen to not recieve any more messages from you.', array('!name' => $recipient->name));
@@ -107,10 +177,13 @@ function pm_block_user_privatemsg_sql_lo
 /**
  * Implementation of hook_privatemsg_message_view_alter.
  */
- function pm_block_user_privatemsg_message_view_alter(&$vars) {
+function pm_block_user_privatemsg_message_view_alter(&$vars) {
   global $user;
 
   $author_id = $vars['message']['author']->uid;
+  if (!_pm_block_user_checkrole(user_load($author_id))) {
+    return;
+  }
   if (!isset($vars['message']['thread_id'])) {
     // No thread id, this is probably only a preview
     return;
@@ -125,4 +198,4 @@ function pm_block_user_privatemsg_sql_lo
       $vars['message_actions'][] = array('title' => t('Block author'), 'href' => 'messages/block/'. $author_id, array('query' => 'destination=messages/view/' . $thread_id));
     }
   }
-}
\ No newline at end of file
+}
