The ignore_user module allows users to choose to ignore node and comment content created by other users. A link is provided in the content to show or hide the content from the ignored user in the node or comment view.

'); } } /** * Implementation of hook_perm(). */ function ignore_user_perm() { return array('ignore user'); } /** * Implementation of hook_menu(). */ function ignore_user_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array( 'path' => 'ignore_user/list', 'title' => t('My ignore list'), 'description' => t('Add or remove users that you wish to ignore.'), 'callback' => 'drupal_get_form', 'callback arguments' => 'ignore_user_ignore_list_form', 'access' => user_access('ignore user'), ); $items[] = array( 'path' => 'ignore_user/add', 'title' => t('Add to ignore list'), 'description' => t('Add user that you wish to ignore.'), 'callback' => 'ignore_user_add_user', 'access' => user_access('ignore user'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'ignore_user/remove', 'title' => t('Remove from ignore list'), 'description' => t('Remove user from your ignore list.'), 'callback' => 'ignore_user_remove_user', 'access' => user_access('ignore user'), 'type' => MENU_CALLBACK, ); } else { drupal_add_js(drupal_get_path('module', 'ignore_user') .'/ignore_user.js', 'module'); } return $items; } /** * This form allows the user to add/remove other users to/from * their ignored users list. */ function ignore_user_ignore_list_form() { $form = array(); $form['add_user'] = array( '#type' => 'fieldset', '#title' => t('Add user to Ignore List'), ); $form['add_user']['username'] = array( '#type' => 'textfield', '#title' => t('Username'), '#description' => t('To lookup a username start typing in the box above. A list of usernames will appear as you type.'), '#size' => 40, '#maxlength' => 60, '#autocomplete_path' => 'user/autocomplete', ); $form['add_user']['submit'] = array( '#type' => 'submit', '#value' => t('Ignore user'), ); $form['current_list'] = array( '#type' => 'fieldset', '#title' => t('Current users on your Ignore List'), ); $form['current_list']['ignored_users'] = array( '#type' => 'markup', '#value' => '', ); $ignored_users = _ignore_user_ignored_users(); foreach ($ignored_users as $ignored_user) { $form['username'][$ignored_user['iuid']] = array( '#value' => $ignored_user['username'], ); $form['delete'][$ignored_user['iuid']] = array( '#value' => l(t('delete'), 'ignore_user/remove/'. $ignored_user['iuid'], array()), ); } $form['pager'] = array('#value' => theme('pager', NULL, 10, 0)); return $form; } /** * Theme the form where user's can manage their ignore list */ function theme_ignore_user_ignore_list_form($form) { $output = drupal_render($form['add_user']); $header = array(t('Username'), t('Operations')); if (isset($form['username']) && is_array($form['username'])) { foreach (element_children($form['username']) as $key) { $row = array(); $row[] = drupal_render($form['username'][$key]); $row[] = drupal_render($form['delete'][$key]); $rows[] = $row; } } else { $rows[] = array(array('data' => t('You have not added any users to your Ignore List'), 'colspan' => '2')); } $form['current_list']['ignored_users']['#value'] = theme('table', $header, $rows); $output .= drupal_render($form['current_list']); if ($form['pager']['#value']) { $output .= drupal_render($form['pager']); } $output .= drupal_render($form); return $output; } /** * ignore user form submit handler */ function ignore_user_ignore_list_form_submit($form_id, $form_values) { if ($form_values['op'] == t('Ignore user')) { ignore_user_add_user_username($form_values['username']); drupal_set_message(t('%username has been added to your ignore list', array('%username' => $form_values['username']))); } } /** * Implementation of hook_user(). */ function ignore_user_user($op, &$edit, &$account, $category = NULL) { global $user; switch ($op) { case 'delete': db_query('DELETE FROM {ignore_user} WHERE uid = %d OR iuid = %d', $account->uid); break; case 'view': if ($user->uid == $account->uid && user_access('ignore user')) { $count = _ignore_user_ignored_users_count(); $items['ignore_user'] = array( 'title' => t('You have @count on your ignore list', array('@count' => format_plural($count, '1 user', '@count users'))), 'value' => l(t('View your ignored users'), 'ignore_user/list', array('title' => t('View your list of ignored users'))), 'class' => 'ignore-user', ); return array(t('Ignored Users') => $items); } break; } } /** * Implementation of hook_link(). */ function ignore_user_link($type, $object = NULL, $teaser = FALSE) { global $user; if (!$user || !$user->uid) { return; } static $ignored; $links = array(); if ($type == 'node' && $user->uid != $object->uid && $object->uid != 0 && user_access('ignore user')) { if (!isset($ignored[$object->uid])) { $ignored[$object->uid] = db_result(db_query('SELECT COUNT(*) FROM {ignore_user} WHERE uid = %d AND iuid = %d', $user->uid, $object->uid)); } if ($ignored[$object->uid] == 0) { $links['ignore_user'] = array( 'title' => t('Ignore user'), 'href' => 'ignore_user/add/'. $object->uid, 'query' => 'destination='. $_GET['q'], 'attributes' => array( 'class' => 'ignore-user', 'title' => t('Add user to your ignore list'), ), ); } } else if ($type == 'comment' && $user->uid != $object->uid && $object->uid != 0 && user_access('ignore user')) { if (!isset($ignored[$object->uid])) { $ignored[$object->uid] = db_result(db_query('SELECT COUNT(*) FROM {ignore_user} WHERE uid = %d AND iuid = %d', $user->uid, $object->uid)); } if ($ignored[$object->uid] == 0) { $links['ignore_user'] = array( 'title' => t('Ignore user'), 'href' => 'ignore_user/add/'. $object->uid, 'query' => 'destination='. $_GET['q'], 'attributes' => array( 'class' => 'ignore-user', 'title' => t('Add user to your ignore list'), ), ); } } return $links; } /** * Implementation of hook_nodeapi(). */ function ignore_user_nodeapi(&$node, $op, $teaser = NULL, $page = FALSE) { global $user; static $authors; if (!$user || !$user->uid || !$node->uid) { return; } switch ($op) { case 'alter': if (_ignore_user_ignored_user($node->uid) == "blocked") { $output = t('
!username is blocked by the webmaster and their content hidden by default. Click here to view this post.', array('!username' => theme('username', $authors[$node->uid]), '!ignore_list' => '/ignore_user/list', '!node' => '/node/'. $node->nid)); $output .= '
'. ($teaser ? $node->teaser : $node->body) .'
'; $teaser ? $node->teaser = $output : $node->body = $output; } else if (_ignore_user_ignored_user($node->uid) == "ignored") { if (!$authors[$node->uid]) { $authors[$node->uid] = user_load(array('uid' => $node->uid)); } $output = t('
!username is on your ignore list. Click here to view this post.', array('!username' => theme('username', $authors[$node->uid]), '!ignore_list' => '/ignore_user/list', '!node' => '/node/'. $node->nid)); $output .= '
'. ($teaser ? $node->teaser : $node->body) .'
'; $teaser ? $node->teaser = $output : $node->body = $output; } break; } } /** * Implementation of hook_comment(). */ function ignore_user_comment($comment, $op) { global $user; static $authors; if (!$user || !$user->uid || !$comment->uid) { return; } switch ($op) { case 'view': if (_ignore_user_ignored_user($comment->uid) == "ignored" ) { if (!$authors[$comment->uid]) { $authors[$comment->uid] = user_load(array('uid' => $comment->uid)); } $output = t('
!username is on your ignore list. Click here to view this post.', array('!username' => theme('username', $authors[$comment->uid]), '!ignore_list' => '/ignore_user/list', '!comment' => '/node/'. $comment->nid .'#comment-'. $comment->cid)); $output .= '
'. $comment->comment .'
'; $comment->comment = $output; } else if (_ignore_user_ignored_user($comment->uid) == "blocked" ) { if (!$authors[$comment->uid]) { $authors[$comment->uid] = user_load(array('uid' => $comment->uid)); } $output = t('
Comment from blocked user. Take a peek?', array('!comment' => '/node/'. $comment->nid .'#comment-'. $comment->cid)); $output .= '
'. $comment->comment .'
'; $comment->comment = $output; } break; } } /** * Add other user to user's ignore list by username */ function ignore_user_add_user_username($name = NULL) { global $user; if (isset($name)) { $iuid = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $name)); if ($user->uid == $iuid) { drupal_set_message(t("You can't add yourself to your own ignore list")); drupal_goto('ignore_user/list'); } if (!empty($iuid)) { db_query('DELETE FROM {ignore_user} WHERE uid = %d AND iuid = %d', $user->uid, $iuid); db_query('INSERT INTO {ignore_user} (uid, iuid) VALUES (%d, %d)', $user->uid, $iuid); } } } /** * Add other user to user's ignore list by user ID */ function ignore_user_add_user($iuid = NULL) { global $user; if ($user->uid == $iuid) { drupal_set_message(t("You can't add yourself to your own ignore list")); drupal_goto('ignore_user/list'); } if (is_numeric($iuid) && $iuid > 0) { db_query('DELETE FROM {ignore_user} WHERE uid = %d AND iuid = %d', $user->uid, $iuid); db_query('INSERT INTO {ignore_user} (uid, iuid) VALUES (%d, %d)', $user->uid, $iuid); drupal_goto(); } else { drupal_not_found(); } } /** * Remove other user from user's ignore list */ function ignore_user_remove_user($iuid = NULL) { global $user; db_query('DELETE FROM {ignore_user} WHERE uid = %d AND iuid = %d', $user->uid, $iuid); drupal_goto('ignore_user/list'); } /** * Check if specified user is on user's ignore list */ function _ignore_user_ignored_user($iuid) { global $user; static $users; if (user_is_blocked(db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $iuid)))) { return "blocked"; } if (db_result(db_query('SELECT COUNT(*) FROM {ignore_user} WHERE uid = %d AND iuid = %d', $user->uid, $iuid))) { return "ignored"; } return FALSE; } /** * Return list of ignored users */ function _ignore_user_ignored_users() { global $user; $ignored_users = array(); $result = db_query('SELECT iuid FROM {ignore_user} WHERE uid = %d', $user->uid); while ($row = db_fetch_object($result)) { $ignored_users[] = array( 'iuid' => $row->iuid, 'username' => theme('username', user_load(array('uid' => $row->iuid))), ); } return $ignored_users; } /** * Return count of ignored users for a given user */ function _ignore_user_ignored_users_count() { global $user; $count = db_result(db_query('SELECT COUNT(*) AS count FROM {ignore_user} WHERE uid = %d', $user->uid)); return $count; }