$settings), 'setting');
drupal_add_css(drupal_get_path('module', 'better_messages') . '/skins/' . $settings['skin'] . '/' . $settings['skin'] . '.css');
}
/*
Implementation of hook_menu
*/
function better_messages_menu() {
$items['admin/settings/better-messages'] = array(
'title' => t('Better Messages Settings'),
'description' => t('Better handling of Drupal messages UI'),
'page callback' => 'drupal_get_form',
'page arguments' => array('better_messages_admin'),
'access callback' => 'user_access',
'access arguments' => array('administer site configuration'),
);
return $items;
}
/*
Implementation of hook_theme
*/
function better_messages_theme() {
return array(
'better_messages' => array(
'template' => 'better_messages',
'arguments' => array('messages' => null, 'element_id' => null),
),
);
}
/*
Admin settings menu callback
*/
function better_messages_admin() {
$settings = better_messages_get_settings();
$form['position'] = array(
'#type' => 'fieldset',
'#title' => t('Messages positions and basic properties'),
'#weight' => 0,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['position']['better_messages_id'] = array(
'#type' => 'textfield',
'#title' => t('Messages wrapper id'),
'#description' => t('Leave as is if you are not sure. If you change it you will have to set your own CSS.'),
'#default_value' => $settings['id'],
'#size' => 20,
'#maxlength' => 60,
'#required' => TRUE,
);
$form['position']['better_messages_pos'] = array(
'#type' => 'radios',
'#title' => t('Set position of Message'),
'#default_value' => $settings['position'],
'#description' => t('Position of message relative to screen'),
'#options' => array(
'center' => t('Center screen'),
'tl' => t('Top left'),
'tr' => t('Top right'),
'bl' => t('Bottom left'),
'br' => t('Bottom right')
),
);
$form['position']['better_messages_fixed'] = array(
'#type' => 'checkbox',
'#default_value' => $settings['fixed'],
'#title' => t('Keep fixed position of message as you scroll.'),
);
$form['position']['better_messages_width'] = array(
'#type' => 'textfield',
'#title' => t('Custom width'),
'#description' => t('Width in pixel. Example: 400'),
'#default_value' => $settings['width'],
'#size' => 20,
'#maxlength' => 20,
'#required' => TRUE,
);
$form['position']['better_messages_horizontal'] = array(
'#type' => 'textfield',
'#title' => t('Left/Right spacing'),
'#description' => t('In active when position is set to "center".
In pixel. Example: 10'),
'#default_value' => $settings['horizontal'],
'#size' => 20,
'#maxlength' => 20,
'#required' => TRUE,
);
$form['position']['better_messages_vertical'] = array(
'#type' => 'textfield',
'#title' => t('Top/Down spacing'),
'#description' => t('Inactive when position is set to "center".
In pixel. Example: 10'),
'#default_value' => $settings['vertical'],
'#size' => 20,
'#maxlength' => 20,
'#required' => TRUE,
);
$form['skins'] = array(
'#type' => 'fieldset',
'#title' => t('Messages appearence'),
'#weight' => 0,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['skins']['better_messages_skin'] = array(
'#type' => 'radios',
'#title' => t('Choose a skin'),
'#options' => $settings['skins'],
'#default_value' => $settings['skin'],
'#description' => t('Select the default skin for your popup messages.
You can create your own skin, put your files (CSS and images) in a folder named "skins" in your theme.'),
);
$form['animation'] = array(
'#type' => 'fieldset',
'#title' => t('Messages animation settings'),
'#weight' => 0,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['animation']['better_messages_popin_effect'] = array(
'#type' => 'select',
'#title' => t('Pop-in (show) message box effect'),
'#default_value' => $settings['popin']['effect'],
'#options' => array(
'fadeIn' => t('Fade in'),
'slideDown' => t('Slide down'),
'slideUp' => t('Slide Up'),
),
);
$form['animation']['better_messages_popin_duration'] = array(
'#type' => 'textfield',
'#title' => t('Duration of (show) effect'),
'#description' => t('A string representing one of the three predefined speeds ("slow", "normal", or "fast").
Or the number of milliseconds to run the animation (e.g. 1000).'),
'#default_value' => $settings['popin']['duration'],
'#size' => 20,
'#maxlength' => 20,
);
$form['animation']['better_messages_popout_effect'] = array(
'#type' => 'select',
'#title' => t('Pop-out (close) message box effect'),
'#default_value' => $settings['popout']['effect'],
'#options' => array(
'fadeIn' => t('Fade out'),
'slideDown' => t('Slide down'),
'slideUp' => t('Slide Up'),
),
);
$form['animation']['better_messages_popout_duration'] = array(
'#type' => 'textfield',
'#title' => t('Duration of (close) effect'),
'#description' => t('A string representing one of the three predefined speeds ("slow", "normal", or "fast").
Or the number of milliseconds to run the animation (e.g. 1000).'),
'#default_value' => $settings['popout']['duration'],
'#size' => 20,
'#maxlength' => 20,
);
$form['animation']['better_messages_autoclose'] = array(
'#type' => 'textfield',
'#title' => t('Number of seconds to auto close after the page has loaded'),
'#description' => t('0 for never. You can set it as 0.25 for quarter second'),
'#default_value' => $settings['autoclose'],
'#size' => 20,
'#maxlength' => 20,
);
$form['animation']['better_messages_open_delay'] = array(
'#type' => 'textfield',
'#title' => t('Number of seconds to delay message after the page has loaded'),
'#description' => t('0 for never. You can set it as 0.25 for quarter second'),
'#default_value' => $settings['opendelay'],
'#size' => 20,
'#maxlength' => 20,
);
return system_settings_form($form);
}
/*
Implementation of hook_better_messages_skins to add skins from othor modules
*/
function better_messages_better_messages_skins() {
$default_theme = variable_get('theme_default', 'none');
// Call skins in modules skins directory
$default_skins_directory = drupal_get_path('module', 'better_messages') .'/skins';
$files = file_scan_directory($default_skins_directory, '\.css$');
// Now we call skins in the default theme skins directory
$theme_skins_directory = drupal_get_path('theme', $default_theme) . '/skins';
$theme_files = file_scan_directory($theme_skins_directory, '\.css$');
// Merge the options and make the names readable.
$files = array_merge($files, $theme_files);
$skins = array();
foreach ($files as $file) {
$skins[$file->filename] = drupal_ucfirst($file->name);
}
return $skins;
}
/*
Implementation of hook_theme_registry_alter to add better_messages theme function
*/
function better_messages_theme_registry_alter(&$theme_registry) {
$theme_registry['page']['preprocess functions'][] = 'better_messages_proprocess_page';
}
/*
Preprocess the default status_messages so we add our template file here
*/
function better_messages_preprocess_page(&$variables) {
if ($variables['messages']) {
$settings = better_messages_get_settings();
$variables['closure'] .= theme('better_messages', $variables['messages'], $settings['id']);
}
}
/*
Helper function to get the settings, that way we wont call variable_get() from almost every where
*/
function better_messages_get_settings() {
// Invoke hook_better_messages_skins
$skins = module_invoke_all('better_messages_skins');
foreach ($skins as $skin) {
$skin_options[strtolower($skin)] = $skin;
}
ksort($skin_options);
// Settings
$settings = array(
'position' => variable_get('better_messages_pos', 'center'),
'vertical' => variable_get('better_messages_vertical', 0),
'horizontal' => variable_get('better_messages_horizontal', 10),
'fixed' => variable_get('better_messages_fixed', 1),
'width' => variable_get('better_messages_width', 400),
'id' => variable_get('better_messages_id', 'messages-wrapper'),
'skin' => variable_get('better_messages_skin', 'default'),
'autoclose' => variable_get('better_messages_autoclose', 0),
'opendelay' => variable_get('better_messages_open_delay', 0.3),
'popin' => array(
'effect' => variable_get('better_messages_popin_effect', 'fadeIn'),
'duration' => variable_get('better_messages_popin_duration', 'slow')
),
'popout' => array(
'effect' => variable_get('better_messages_popout_effect', 'fadeOut'),
'duration' => variable_get('better_messages_popout_duration', 'slow')
),
'skins' => $skin_options,
);
return $settings;
}