View source
<?php
function nodejs_notify_init() {
drupal_add_css(drupal_get_path('module', 'nodejs_notify') . '/libraries/jgrowl/jquery.jgrowl.css');
drupal_add_js(drupal_get_path('module', 'nodejs_notify') . '/libraries/jgrowl/jquery.jgrowl.js');
drupal_add_js(array(
'nodejs_notify' => array(
'notification_time' => variable_get('nodejs_notify_notification_lifetime_seconds', 3),
),
), 'setting');
}
function nodejs_notify_nodejs_handlers_info() {
return array(
drupal_get_path('module', 'nodejs_notify') . '/nodejs.notify.js',
);
}
function nodejs_notify_perm() {
return array(
'Perform system-wide broadcasts.',
'Administer Node.js Notification Configuration',
);
}
function nodejs_notify_menu() {
return array(
'admin/settings/nodejs/nodejs_notify' => array(
'title' => t('Node.js Notification Settings'),
'description' => t('Settings for node.js notify.'),
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array(
'access administration pages',
),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
'position' => 'left',
'weight' => 1,
),
'admin/settings/nodejs/nodejs_notify/settings' => array(
'title' => t('Node.js Notification Settings'),
'description' => t('Settings for node.js notify.'),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'nodejs_notify_settings_form',
),
'access arguments' => array(
'Administer Node.js Notification Configuration',
),
),
'admin/settings/nodejs/nodejs_notify/broadcast' => array(
'title' => t('System-wide broadcast'),
'description' => t('Do a system-wide broadcast notification that all users see.'),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'nodejs_notify_broadcast_form',
),
'access arguments' => array(
'Perform system-wide broadcasts.',
),
),
);
}
function nodejs_notify_settings_form() {
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Node.js Notify Settings'),
);
$form['settings']['notification_lifetime'] = array(
'#type' => 'textfield',
'#title' => t('Notification Lifetime'),
'#description' => t('The number of seconds a notification will live before fading automatically. (Set to 0 for sticky notifications that do not fade.)'),
'#default_value' => variable_get('nodejs_notify_notification_lifetime_seconds', 3),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit Configuration'),
'#submit' => array(
'nodejs_notify_settings_form_submit',
),
);
return $form;
}
function nodejs_notify_settings_form_validate($form, &$form_state) {
if (!preg_match('/^\\d+$/', $form_state['values']['notification_lifetime'])) {
form_set_error('notification_lifetime', t('The notification lifetime must be a number.'));
}
}
function nodejs_notify_settings_form_submit(&$form, &$form_state) {
variable_set('nodejs_notify_notification_lifetime_seconds', $form_state['values']['notification_lifetime']);
drupal_set_message(t("Notification settings saved."));
}
function nodejs_notify_broadcast_form() {
$form['broadcast_form'] = array(
'#type' => 'fieldset',
'#title' => t('System-wide Broadcast Notification'),
);
$form['broadcast_form']['broadcast_subject'] = array(
'#type' => 'textfield',
'#title' => t('Broadcast notification subject'),
'#required' => TRUE,
);
$form['broadcast_form']['broadcast_message'] = array(
'#type' => 'textarea',
'#title' => t('Broadcast notification message'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Broadcast'),
'#submit' => array(
'nodejs_notify_broadcast_form_submit',
),
);
return $form;
}
function nodejs_notify_broadcast_form_submit(&$form, &$form_state) {
nodejs_broadcast_message($form_state['values']['broadcast_subject'], $form_state['values']['broadcast_message']);
drupal_set_message(t("Message broadcast to all users"));
}