| 1 |
<?php |
<?php |
| 2 |
// $Id: wordfilter.module,v 1.7.2.9.2.11 2008/12/10 16:29:39 jaydub Exp $ |
// $Id: wordfilter.module,v 1.7.2.9.2.12 2009/04/14 08:12:03 jaydub Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 268 |
switch ($delta) { |
switch ($delta) { |
| 269 |
case 0: |
case 0: |
| 270 |
$block['subject'] = t('Filtered words'); |
$block['subject'] = t('Filtered words'); |
| 271 |
$block['content'] = $GLOBALS['display_wordfilter_block'] ? wordfilter_table() : ''; |
$block['content'] = $GLOBALS['display_wordfilter_block'] ? _wordfilter_table() : ''; |
| 272 |
return $block; |
return $block; |
| 273 |
} |
} |
| 274 |
} |
} |
| 275 |
} |
} |
| 276 |
|
|
| 277 |
/** |
/** |
| 278 |
* @return string |
* Displays a list of words that will be filtered as an HTML table. |
| 279 |
*/ |
*/ |
| 280 |
function wordfilter_filter_tips($delta, $format, $long = FALSE) { |
function _wordfilter_table() { |
|
if ($long) { |
|
|
return t('If you include a word in your post that\'s filtered (usually foul language), it will be replaced by the filtered version of the word.') .'<br />'; |
|
|
} |
|
|
else { |
|
|
$GLOBALS['display_wordfilter_block'] = TRUE; |
|
|
return t('Filtered words will be replaced with the filtered version of the word.'); |
|
|
} |
|
|
} |
|
|
|
|
|
function wordfilter_table() { |
|
| 281 |
$content .= '<div align="center">'; |
$content .= '<div align="center">'; |
| 282 |
$content .= '<table border="0" cellspacing="1" cellpadding="0">'; |
$content .= '<table border="0" cellspacing="1" cellpadding="0">'; |
| 283 |
$list = _wordfilter_list(); |
$list = _wordfilter_list(); |
| 289 |
return $content; |
return $content; |
| 290 |
} |
} |
| 291 |
|
|
| 292 |
|
/** |
| 293 |
|
* Implementation of hook_filter_tips(). |
| 294 |
|
*/ |
| 295 |
|
function wordfilter_filter_tips($delta, $format, $long = FALSE) { |
| 296 |
|
if ($long) { |
| 297 |
|
return t('If you include a word in your post that\'s filtered (usually foul language), it will be replaced by the filtered version of the word.') .'<br />'; |
| 298 |
|
} |
| 299 |
|
else { |
| 300 |
|
$GLOBALS['display_wordfilter_block'] = TRUE; |
| 301 |
|
return t('Filtered words will be replaced with the filtered version of the word.'); |
| 302 |
|
} |
| 303 |
|
} |
| 304 |
|
|
| 305 |
|
/** |
| 306 |
|
* Implementation of hook_filter(). |
| 307 |
|
*/ |
| 308 |
function wordfilter_filter($op, $delta = 0, $format = -1, $text = '') { |
function wordfilter_filter($op, $delta = 0, $format = -1, $text = '') { |
| 309 |
switch ($op) { |
switch ($op) { |
| 310 |
case 'list': |
case 'list': |
| 325 |
} |
} |
| 326 |
} |
} |
| 327 |
|
|
| 328 |
|
/** |
| 329 |
|
* hook_filter process operation callback. |
| 330 |
|
*/ |
| 331 |
function wordfilter_filter_process($text) { |
function wordfilter_filter_process($text) { |
| 332 |
$text = ' '. $text .' '; |
$text = ' '. $text .' '; |
| 333 |
$list = _wordfilter_list(); |
$list = _wordfilter_list(); |
| 381 |
} |
} |
| 382 |
|
|
| 383 |
/** |
/** |
| 384 |
* wordfilter admin settings page |
* Wordfilter admin settings page callback. |
| 385 |
*/ |
*/ |
| 386 |
function wordfilter_admin_list() { |
function wordfilter_admin_list() { |
| 387 |
$header = array( |
$header = array( |
| 408 |
return $output; |
return $output; |
| 409 |
} |
} |
| 410 |
|
|
| 411 |
|
/** |
| 412 |
|
* Edit word filter form. |
| 413 |
|
*/ |
| 414 |
function wordfilter_admin_edit_form($form, $word_id = NULL) { |
function wordfilter_admin_edit_form($form, $word_id = NULL) { |
| 415 |
if (!isset($word_id) || !is_numeric($word_id)) { |
if (!isset($word_id) || !is_numeric($word_id)) { |
| 416 |
drupal_set_message(t('The wordfilter ID of the word or phrase you are trying to edit is missing or is not a number.'), 'error'); |
drupal_set_message(t('The wordfilter ID of the word or phrase you are trying to edit is missing or is not a number.'), 'error'); |
| 461 |
return $form; |
return $form; |
| 462 |
} |
} |
| 463 |
|
|
| 464 |
|
/** |
| 465 |
|
* Edit word filter form submit handler. |
| 466 |
|
*/ |
| 467 |
function wordfilter_admin_edit_form_submit($form, &$form_state) { |
function wordfilter_admin_edit_form_submit($form, &$form_state) { |
| 468 |
$row = new stdClass; |
$row = new stdClass; |
| 469 |
$row->id = $form_state['values']['id']; |
$row->id = $form_state['values']['id']; |
| 478 |
} |
} |
| 479 |
|
|
| 480 |
/** |
/** |
| 481 |
* @return array |
* Add word filter form. |
| 482 |
*/ |
*/ |
| 483 |
function wordfilter_admin_add_form() { |
function wordfilter_admin_add_form() { |
| 484 |
$form = array(); |
$form = array(); |
| 520 |
return $form; |
return $form; |
| 521 |
} |
} |
| 522 |
|
|
| 523 |
|
/** |
| 524 |
|
* Add word filter form submit handler. |
| 525 |
|
*/ |
| 526 |
function wordfilter_admin_add_form_submit($form, &$form_state) { |
function wordfilter_admin_add_form_submit($form, &$form_state) { |
| 527 |
$pairs = explode("\n", $form_state['values']['words']); |
$pairs = explode("\n", $form_state['values']['words']); |
| 528 |
$pairs = array_map('trim', $pairs); |
$pairs = array_map('trim', $pairs); |
| 544 |
$form_state['redirect'] = 'admin/settings/wordfilter'; |
$form_state['redirect'] = 'admin/settings/wordfilter'; |
| 545 |
} |
} |
| 546 |
|
|
| 547 |
|
/** |
| 548 |
|
* Test word filter form. |
| 549 |
|
*/ |
| 550 |
function wordfilter_admin_test_filter_form($form_state) { |
function wordfilter_admin_test_filter_form($form_state) { |
| 551 |
$form = array(); |
$form = array(); |
| 552 |
$form['#redirect'] = FALSE; |
$form['#redirect'] = FALSE; |
| 577 |
return $form; |
return $form; |
| 578 |
} |
} |
| 579 |
|
|
| 580 |
|
/** |
| 581 |
|
* Test word filter form submit handler. |
| 582 |
|
*/ |
| 583 |
function wordfilter_admin_test_filter_form_submit($form, &$form_state) { |
function wordfilter_admin_test_filter_form_submit($form, &$form_state) { |
| 584 |
$form_state['rebuild'] = TRUE; |
$form_state['rebuild'] = TRUE; |
| 585 |
} |
} |
| 586 |
|
|
| 587 |
|
/** |
| 588 |
|
* Test word filter page callback. |
| 589 |
|
*/ |
| 590 |
function _wordfilter_test_filter($word) { |
function _wordfilter_test_filter($word) { |
| 591 |
$filtered_word = wordfilter_filter_process($word); |
$filtered_word = wordfilter_filter_process($word); |
| 592 |
if ($word == $filtered_word) { |
if ($word == $filtered_word) { |