Drupal 7 - User Restrictions Batch Module

This module extends the existing user_restrictions module by providing a mechanism for the bulk import of prohibited words in the screen name during user registration. This is useful to ensure that on a community site no users attempt to create accounts with offensive names. Without this module, any admin wishing to add a few hundred words to the user_restrictions list would face quite an onerous chore to type them all in. With the module, they can be cut and pasted from an existing source into a textarea in one go. The textarea allows for carriage return / linefeeds and will also remove commas between words.

The module was very easy to put together, so I don't believe there is anything requiring further expansion. If you disagree, drop me a line and I'll answer your questions. Smile

user_resitrictions_batch.module

<?php
/*
* File         : user_restrictions_batch.module
* Title        : Batch add of user restrictions
* Sponsor      : Hangar Seven Digital
* Author       : Badzilla <a href="http://www.badzilla.co.uk" title="www.badzilla.co.uk">www.badzilla.co.uk</a> @badzillacouk
*
* This work is copyright Badzilla under the GPL licence terms and conditions
*
*/




/**
* Implements hook_menu().
*/
function user_restrictions_batch_menu() {

   
$edit_restrictions = array('edit user restriction rules');
   
$items = array();

   
$items['admin/config/people/user-restrictions/batch-input'] = array(
           
'title' => 'Batch input ',
           
'page callback' => 'drupal_get_form',
           
'page arguments' => array('user_restrictions_batch_input_form', 4),
           
'access arguments' => $edit_restrictions,
           
'type' => MENU_LOCAL_ACTION,
    );

    return
$items;
}




function
user_restrictions_batch_input_form($form, &$form_state) {

   
$form = array();

   
$form['banned'] = array(
       
'#type' => 'textarea',
       
'#title' => t('Enter prohibited words'),
       
'#required' => TRUE,
       
'#weight' => 0
   
);
   
   
$form['submit'] = array(
       
'#type' => 'submit',
       
'#value' => t('Save rule'),
    );

    return
$form;   
}


function
user_restrictions_batch_input_form_submit($form, &$form_state) {

   
$lines = explode("\r\n", $form_state['values']['banned']);
    if (
count($lines))
        foreach(
$lines as $line) {
           
$phrases = explode(",", $line);

            if (
count($phrases))
                foreach(
$phrases as $phrase)
                    if (
$phrase = trim($phrase))
                       
db_insert('user_restrictions')
                            ->
fields(array('urid' => NULL, 'mask' => $phrase, 'type' => 'name', 'subtype' => '', 'status' => 0, 'expire' => 0))
                            ->
execute();
        }   
}
?>

user_resitrictions_batch.info

name = User restrictions_batch
description = Brute force batch insertion of restricted words.
core = 7.x
project = "user_restrictions"


AttachmentSize
user_restrictions_batch.tar.gz1.06 KB