View source
<?php
function nodejs_watchdog_form_dblog_filter_form_alter(&$form, &$form_state, $form_id) {
nodejs_send_content_channel_token('watchdog_dblog');
drupal_add_js(drupal_get_path('module', 'nodejs_watchdog') . '/nodejs.watchdog.js', array(
'type' => 'file',
));
}
function nodejs_watchdog_watchdog(array $entry) {
$classes = array(
WATCHDOG_DEBUG => 'dblog-debug',
WATCHDOG_INFO => 'dblog-info',
WATCHDOG_NOTICE => 'dblog-notice',
WATCHDOG_WARNING => 'dblog-warning',
WATCHDOG_ERROR => 'dblog-error',
WATCHDOG_CRITICAL => 'dblog-critical',
WATCHDOG_ALERT => 'dblog-alert',
WATCHDOG_EMERGENCY => 'dblog-emerg',
);
$entry['variables'] = isset($entry['variables']) ? serialize($entry['variables']) : serialize(array());
if (module_exists('dblog')) {
$query = db_select('watchdog', 'wd')
->fields('wd', array(
'wid',
))
->condition('uid', $entry['uid'])
->condition('type', $entry['type'])
->condition('message', $entry['message'])
->condition('hostname', $entry['ip'])
->condition('timestamp', $entry['timestamp'])
->execute()
->fetchAssoc();
if (isset($query['wid'])) {
$entry['wid'] = $query['wid'];
}
}
$row = array(
'data' => array(
array(
'class' => 'icon',
),
t($entry['type']),
format_date($entry['timestamp'], 'short'),
theme('dblog_message', array(
'event' => (object) $entry,
'link' => TRUE,
)),
theme('username', array(
'account' => $entry['user'],
)),
$entry['link'],
),
'class' => array(
drupal_html_class('dblog-' . $entry['type']),
$classes[$entry['severity']],
),
);
$commands[] = ajax_command_before('#admin-dblog tr:eq(1)', nodejs_watchdog_theme_row($row));
$message = (object) array(
'channel' => 'watchdog_dblog',
'commands' => $commands,
'callback' => 'nodejsWatchdog',
);
nodejs_send_content_channel_message($message);
}
function nodejs_watchdog_theme_row($row) {
$attributes = array();
$flip = array(
'even' => 'odd',
'odd' => 'even',
);
$class = 'even';
$output = "";
if (isset($row['data'])) {
foreach ($row as $key => $value) {
if ($key == 'data') {
$cells = $value;
}
else {
$attributes[$key] = $value;
}
}
}
else {
$cells = $row;
}
if (count($cells)) {
$output .= '<tr' . drupal_attributes($attributes) . '>';
$i = 0;
foreach ($cells as $cell) {
$output .= _theme_table_cell($cell);
}
$output .= "</tr>";
}
return $output;
}
function nodejs_watchdog_nodejs_user_channels($account) {
if (user_access('access site reports', $account)) {
return array(
'watchdog_dblog',
);
}
return array();
}
function nodejs_watchdog_nodejs_handlers_info() {
return array(
drupal_get_path('module', 'nodejs_watchdog') . '/nodejs.watchdog.js',
);
}
function nodejs_watchdog_module_implements_alter(&$implementations, $hook) {
if ($hook == 'watchdog' && isset($implementations['nodejs_watchdog'])) {
$group = $implementations['nodejs_watchdog'];
unset($implementations['nodejs_watchdog']);
$implementations['nodejs_watchdog'] = $group;
}
}