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('