0) {
$account = user_load(array('uid' => arg(1)));
if ($account->uid == $user->uid || user_access('administer messaging')) {
$items[] = array(
'path' => 'user/'. $account->uid .'/messagelog',
'type' => MENU_LOCAL_TASK,
'title' => t('Message log'),
'callback' => 'messaging_debug_user_page',
'callback arguments' => array($account)
);
}
}
}
return $items;
}
/**
* Implementation of hook_form_alter()
*/
function messaging_debug_form_alter($form_id, &$form) {
if ($form_id == 'messaging_admin_settings') {
$form['general']['messaging_debug'] = array(
'#title' => t('Debug mode'),
'#type' => 'radios',
'#options' => array(t('Disabled'), t('Enabled')),
'#default_value' => variable_get('messaging_debug', 0),
'#description' => t('If enabled, messages wont be sent out but logged to watchdog, and displayed in the page footer.')
);
}
}
/**
* Menu callback. Display pending messages to the user
*
* Sample Implementation of messaging pull methods
*/
function messaging_debug_user_page($account) {
drupal_set_title(t('Messages for %name', array('%name' => $account->name)));
// Fetch all pending messages.
$output = '';
// Use this method's info for all the messages
$messages = messaging_store('get', array('uid' => $account->uid), array('mqid DESC'), MESSAGING_DEBUG_PAGER, 0);
if ($messages) {
$header = array(t('Method'), t('Subject'), t('Body'));
foreach ($messages as $message) {
// Check plain everything so we can actually see the mark up if any
$rows[] = array($message['method'], check_plain($message['subject']), check_plain($message['body']));
}
$output .= theme('table', $header, $rows);
$output .= theme('pager', array(), MESSAGING_DEBUG_PAGER);
} else {
$output .= t('No logged messages');
}
return $output;
}
/**
* Implementation of hook_messaging
*/
function messaging_debug_messaging($op = 'info') {
switch($op) {
case 'send methods':
$info['debug'] = array(
'name' => t('Debug'),
'destination' => 'name',
'send' => 'messaging_debug_send_msg',
'send_user' => 'messaging_debug_send_user',
'type' => MESSAGING_TYPE_PULL,
'glue' => '
',
'description' => t('The messages will be just logged to watchdog.'),
);
return $info;
}
}
/**
* Just show message title to the user.
*
* This is a pull method though, so this is mainly intended for testing options
*/
function messaging_debug_send_user($account, $message, $method = 'debug') {
$info = messaging_method_info('debug');
$destination = array($account);
return messaging_message_send($destination, $message, $method);
}
/**
* Just show message title to the user.
*
* This is a pull method though, so this is mainly intended for testing options
*/
function messaging_debug_send_msg($destination, $message) {
// Just logs everything.
$text = '';
$count = 0;
$watchdog = array();
$text = t('Message %key for %name: %subject', array('%name' => $destination->name, '%key' => $message['type'], '%subject' => $message['subject']));
messaging_log($text);
$watchdog[] = t('Message body:').'
'.$message['body'].''; // Just log message body at the end watchdog('messaging', implode('
'.print_r($log, TRUE).''; } $output .= implode('