jammer_messages.module in Jammer 6
Same filename and directory in other branches
Filter status messages set by drupal_set_message().
File
jammer_messages.moduleView source
<?php
/**
* @file
* Filter status messages set by drupal_set_message().
*/
/**
* Implements hook_boot().
*/
function jammer_messages_boot() {
if (!empty($_SESSION['messages'])) {
$results = db_query("SELECT message_string FROM {jammer_messages}");
while ($message_filter = db_fetch_object($results)) {
$message_filter = $message_filter->message_string;
foreach ($_SESSION['messages'] as $type => $messages) {
$grep_results = preg_grep('/' . $message_filter . '/', $_SESSION['messages'][$type]);
foreach ($grep_results as $key => $match) {
unset($_SESSION['messages'][$type][$key]);
}
if (empty($_SESSION['messages'][$type])) {
unset($_SESSION['messages'][$type]);
}
}
}
}
}
/**
* Implements hook_menu().
*
* @return An array of menu items.
*/
function jammer_messages_menu() {
$items = array();
$items['admin/settings/jammer/jammer_messages'] = array(
'title' => 'Message Jammer',
'description' => 'Filter status messages.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'_jammer_messages_settings',
),
'access arguments' => array(
'administer site configuration',
),
);
$items['admin/settings/jammer/jammer_messages/delete/%jammer_message'] = array(
'title' => 'Message jammer delete',
'description' => 'Delete filter on status messages.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'jammer_messages_settings_confirm_delete',
5,
),
'access arguments' => array(
'administer site configuration',
),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Load jammed message to verify they exist.
*
* @return object
*/
function jammer_message_load($mid) {
$result = db_query_range('SELECT mid, message_string FROM {jammer_messages} WHERE mid = %d', $mid, 0, 1);
return $result ? db_fetch_object($result) : FALSE;
}
function _jammer_messages_settings() {
$form = array();
$form['jammer_messages_string'] = array(
'#type' => 'textfield',
'#title' => t('Message to jam'),
'#required' => TRUE,
'#description' => t('The message format is processed in regular expression form. Enter either an exact string to suppress, ' . 'or one which matches !PCRE formatting.', array(
'!PCRE' => l('PCRE', 'http://us3.php.net/manual/en/book.pcre.php', array(
'external' => TRUE,
)),
)),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Jam message',
);
$current_settings = db_query("SELECT mid, message_string FROM {jammer_messages}");
$headers = array(
t('Message Pattern ID'),
t('Message Pattern'),
t('Delete'),
);
$data = array();
while ($setting = db_fetch_object($current_settings)) {
$data[] = array(
$setting->mid,
$setting->message_string,
l(t('Delete'), 'admin/settings/jammer/jammer_messages/delete/' . $setting->mid),
);
}
if (!empty($data)) {
$form['configured'] = array(
'#type' => 'fieldset',
'#title' => 'Jammed messages',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['configured']['table'] = array(
'#type' => 'item',
'#value' => theme('table', $headers, $data),
);
}
return $form;
}
function _jammer_messages_settings_submit($form, &$form_state) {
$form_values = $form_state['values'];
if ($form_values['jammer_messages_string'] == '') {
drupal_set_message(t('Empty strings are not an accepted match string.'));
return;
}
$message = new stdClass();
$message->message_string = $form_values['jammer_messages_string'];
drupal_write_record('jammer_messages', $message);
}
/**
* Returns a confirmation page for deleting a jammed message setting.
*
* @return array
*/
function jammer_messages_settings_confirm_delete(&$form_state, $message) {
$confirm_form['message'] = array(
'#type' => 'value',
'#value' => $message,
);
return confirm_form($confirm_form, t('Are you sure you want to un-jam this message?'), 'admin/settings/jammer/jammer_messages', t('Deleting this setting will cause previously hidden messages containing %message to display again. To review the settings on this message, please visit <a href="@content">Message Jammer administration</a> first. This action cannot be undone.', array(
'@content' => url('admin/settings/jammer/jammer_messages'),
'%message' => $message->message_string,
)), t('Delete'), t('Cancel'));
}
function jammer_messages_settings_confirm_delete_submit($form, &$form_state) {
db_query('DELETE FROM {jammer_messages} WHERE mid = %d', $form_state['values']['message']->mid);
drupal_set_message(t('The filter for %message was deleted.', array(
'%message' => $form_state['values']['message']->message_string,
)));
watchdog('jammer_messages', '%message filter deleted.', array(
'%message' => $form_state['values']['message']->message_string,
), WATCHDOG_INFO);
$form_state['redirect'] = 'admin/settings/jammer/jammer_messages';
}
Functions
Name | Description |
---|---|
jammer_messages_boot | Implements hook_boot(). |
jammer_messages_menu | Implements hook_menu(). |
jammer_messages_settings_confirm_delete | Returns a confirmation page for deleting a jammed message setting. |
jammer_messages_settings_confirm_delete_submit | |
jammer_message_load | Load jammed message to verify they exist. |
_jammer_messages_settings | |
_jammer_messages_settings_submit |