View source
<?php
function better_messages_admin_overview_form() {
$skins = _better_messages_get_settings(null, TRUE);
$form = array();
$options = array();
foreach ($skins as $skin => $skins_settings) {
$options[$skin] = '';
$form['name'][$skin] = array(
'#markup' => check_plain($skins_settings['admin']['title']),
);
}
$form['default_skin'] = array(
'#type' => 'radios',
'#title' => t('Default skin'),
'#title_display' => 'invisible',
'#options' => $options,
'#default_value' => variable_get('better_messages_default'),
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
$form['#theme'] = 'better_messages_admin_overview_list';
return $form;
}
function theme_better_messages_admin_overview_list($variables) {
$form = $variables['form'];
$rows = array();
foreach ($form['name'] as $skin => $skin_settings) {
if (is_array($skin_settings) && element_child($skin)) {
$row = array();
$settings = _better_messages_get_settings($skin);
$title = drupal_render($form['name'][$skin]);
$row[] = '<strong>' . $title . '</strong>';
$form['default_skin'][$skin]['#title'] = t('Set !title as default', array(
'!title' => $title,
));
$form['default_skin'][$skin]['#title_display'] = 'invisible';
$row[] = drupal_render($form['default_skin'][$skin]);
if ($settings[$skin]['admin']['storage'] == 'custom') {
$row[] = t('Custom');
$row[] = l(t('edit'), 'admin/config/user-interface/better-messages/edit/' . $skin);
$row[] = l(t('clone'), 'admin/config/user-interface/better-messages/clone/' . $skin);
$row[] = l(t('delete'), 'admin/config/user-interface/better-messages/delete/' . $skin);
}
else {
if ($settings[$skin]['admin']['storage'] == 'overridden') {
$row[] = t('Overridden');
$row[] = l(t('edit'), 'admin/config/user-interface/better-messages/edit' . $skin);
$row[] = l(t('clone'), 'admin/config/user-interface/better-messages/clone/' . $skin);
$row[] = l(t('revert'), 'admin/config/user-interface/better-messages/revert/' . $skin);
}
else {
$row[] = t('Default');
$row[] = l(t('override'), 'admin/config/user-interface/better-messages/edit/' . $skin);
$row[] = l(t('clone'), 'admin/config/user-interface/better-messages/clone/' . $skin);
$row[] = '';
}
}
$rows[] = $row;
}
}
if (empty($rows)) {
$rows[] = array(
array(
'colspan' => 4,
'data' => t('There are currently no Better Messages skins. <a href="!url">Add a new one</a>.', array(
'!url' => url('admin/config/user-interface/better-messages/add'),
)),
),
);
}
$header = array(
array(
'data' => t('Skin name'),
),
array(
'data' => t('Default'),
),
array(
'data' => t('Settings'),
),
array(
'data' => t('Operations'),
'colspan' => 3,
),
);
$output = theme('table', array(
'header' => $header,
'rows' => $rows,
));
$output .= drupal_render_children($form);
return $output;
}
function better_messages_admin_overview_form_submit($form, &$form_state) {
variable_set('better_messages_default', $form_state['values']['default_skin']);
}
function better_messages_admin_skin_form($form, &$form_state, $op, $skin = null) {
if ($skin) {
$settings = _better_messages_get_settings($skin);
}
$form = array();
$form['name'] = array(
'#title' => t('Title'),
'#type' => 'textfield',
'#default_value' => $skin && $op != 'clone' ? $settings[$skin]['admin']['title'] : '',
'#description' => t('The human-readable name of this skin. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'),
'#required' => TRUE,
'#size' => 30,
);
$form['machine_name'] = array(
'#type' => 'machine_name',
'#default_value' => $skin && $op != 'clone' ? $skin : '',
'#maxlength' => 128,
'#disabled' => '',
'#machine_name' => array(
'exists' => '_better_messages_get_settings',
),
'#description' => t('A unique machine-readable name for this skin. It must only contain lowercase letters, numbers, and underscores'),
);
$form['css_path'] = array(
'#title' => t('CSS stylesheet path'),
'#type' => 'textfield',
'#default_value' => $skin ? $settings[$skin]['admin']['css'] : '',
'#description' => t("Path of your CSS stylesheet relative to Drupal's root directory.<br />Example: <abbr>sites/all/themes/zen/better_messages/skin.css</abbr>"),
'#required' => TRUE,
'#size' => 70,
);
$form['settings'] = array(
'#type' => 'vertical_tabs',
'#weight' => 1,
'#title' => t('Messages settings'),
'#attached' => array(
'js' => array(
drupal_get_path('module', 'better_messages') . '/better_messages.admin.js',
),
'css' => array(
drupal_get_path('module', 'better_messages') . '/better_messages.admin.css',
),
),
);
$form['settings']['position'] = array(
'#type' => 'fieldset',
'#title' => t('Messages positions and basic properties'),
'#weight' => 1,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['settings']['position']['pos_xy'] = array(
'#type' => 'item',
'#title' => t('Position of Better Messages'),
);
$form['settings']['position']['pos_xy']['pos_x'] = array(
'#type' => 'select',
'#title' => t('X-axis') . ':',
'#default_value' => $skin ? $settings[$skin]['placement']['pos_x'] : '',
'#options' => array(
'c' => t('Center'),
'r' => t('Right'),
'l' => t('Left'),
),
);
$form['settings']['position']['pos_xy']['pos_y'] = array(
'#type' => 'select',
'#title' => t('Y-axis') . ':',
'#default_value' => $skin ? $settings[$skin]['placement']['pos_y'] : '',
'#options' => array(
'c' => t('Center'),
't' => t('Top'),
'b' => t('Bottom'),
),
'#suffix' => '<div class="better-messages-clear"></div>',
);
$form['settings']['position']['space_x'] = array(
'#type' => 'textfield',
'#title' => t('X-axis spacing'),
'#description' => t('Inactive when position is set to "center".<br />In pixels. Example: 10'),
'#default_value' => $skin ? $settings[$skin]['placement']['space_x'] : '',
'#size' => 15,
'#maxlength' => 3,
'#required' => TRUE,
);
$form['settings']['position']['space_y'] = array(
'#type' => 'textfield',
'#title' => t('Y-axis spacing'),
'#description' => t('Inactive when position is set to "center".<br />In pixels. Example: 10'),
'#default_value' => $skin ? $settings[$skin]['placement']['space_y'] : '',
'#size' => 15,
'#maxlength' => 3,
'#required' => TRUE,
);
$form['settings']['position']['width'] = array(
'#type' => 'textfield',
'#title' => t('Width of Better Messages'),
'#description' => t('Width in pixels. Example: 400px<br />Or percentage. Example: 100%'),
'#default_value' => $skin ? $settings[$skin]['placement']['width'] : '',
'#size' => 15,
'#maxlength' => 6,
'#required' => TRUE,
);
$form['settings']['position']['fixed'] = array(
'#type' => 'checkbox',
'#default_value' => $skin ? $settings[$skin]['placement']['fixed'] : '',
'#title' => t('Keep Better Messages position fixed while scrolling.'),
);
$form['settings']['animation'] = array(
'#type' => 'fieldset',
'#title' => t('Messages animation settings'),
'#weight' => 2,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['settings']['animation']['popin'] = array(
'#type' => 'fieldset',
'#title' => t('Pop-in (show) settings'),
'#weight' => 0,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['settings']['animation']['popin']['popin_effect'] = array(
'#type' => 'select',
'#title' => t('Pop-in (show) message box effect'),
'#default_value' => $skin ? $settings[$skin]['animation']['popin']['effect'] : '',
'#options' => array(
'fadeIn' => t('Fade in'),
'slideDown' => t('Slide down'),
),
);
$form['settings']['animation']['popin']['popin_easing'] = array(
'#type' => 'textfield',
'#title' => t('Easing effect when poping in (showing) the message box'),
'#description' => t('Refer to <a href="@link">jQuery UI easing effects</a> for cool easing effects.', array(
'@link' => 'http://jqueryui.com/demos/effect/easing.html',
)),
'#default_value' => $skin ? $settings[$skin]['animation']['popin']['easing'] : '',
'#size' => 15,
'#maxlength' => 20,
);
$form['settings']['animation']['popin']['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").<br />Or the number of milliseconds to run the animation (e.g. 1000).'),
'#default_value' => $skin ? $settings[$skin]['animation']['popin']['duration'] : '',
'#size' => 15,
'#maxlength' => 20,
);
$form['settings']['animation']['popin']['open_delay'] = array(
'#type' => 'textfield',
'#title' => t('Number of seconds to delay Better Messages after the page has loaded'),
'#description' => t('0 for none. You can set it as 0.25 for quarter second.'),
'#default_value' => $skin ? $settings[$skin]['animation']['popin']['opendelay'] : '',
'#size' => 15,
'#maxlength' => 20,
);
$form['settings']['animation']['popout'] = array(
'#type' => 'fieldset',
'#title' => t('Pop-out (close) settings'),
'#weight' => 1,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['settings']['animation']['popout']['popout_effect'] = array(
'#type' => 'select',
'#title' => t('Pop-out (close) message box effect'),
'#default_value' => $skin ? $settings[$skin]['animation']['popout']['effect'] : '',
'#options' => array(
'fadeIn' => t('Fade out'),
'slideUp' => t('Slide Up'),
),
);
$form['settings']['animation']['popout']['popout_easing'] = array(
'#type' => 'textfield',
'#title' => t('Easing effect when poping out (closing) the message box'),
'#description' => t('Refer to <a href="@link">jQuery UI easing effects</a> for cool easing effects.', array(
'@link' => 'http://jqueryui.com/demos/effect/easing.html',
)),
'#default_value' => $skin ? $settings[$skin]['animation']['popout']['easing'] : '',
'#size' => 15,
'#maxlength' => 20,
);
$form['settings']['animation']['popout']['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").<br />Or the number of milliseconds to run the animation (e.g. 1000).'),
'#default_value' => $skin ? $settings[$skin]['animation']['popout']['duration'] : '',
'#size' => 20,
'#maxlength' => 20,
);
$form['settings']['animation']['autoclose'] = array(
'#type' => 'fieldset',
'#title' => t('Auto-close settings'),
'#weight' => 2,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['settings']['animation']['autoclose']['autoclose_seconds'] = array(
'#type' => 'textfield',
'#title' => t('Number of seconds to auto-close Better Messages after the page has loaded'),
'#description' => t('0 for never. You can set it as 0.25 for quarter second.'),
'#default_value' => $skin ? $settings[$skin]['animation']['popout']['autoclose']['seconds'] : '',
'#size' => 20,
'#maxlength' => 20,
);
$form['settings']['animation']['autoclose']['disable_autoclose_error'] = array(
'#type' => 'checkbox',
'#title' => t('Disable auto-close if Better Messages includes an error message'),
'#default_value' => $skin ? $settings[$skin]['animation']['popout']['autoclose']['disable_autoclose_error'] : '',
);
$form['settings']['animation']['autoclose']['disable_autoclose_hover'] = array(
'#type' => 'checkbox',
'#title' => t('Stop auto-close timer on hover'),
'#default_value' => $skin ? $settings[$skin]['animation']['popout']['autoclose']['disable_autoclose_hover'] : '',
);
$form['settings']['animation']['autoclose']['show_countdown'] = array(
'#type' => 'checkbox',
'#title' => t('Show countdown timer'),
'#default_value' => $skin ? $settings[$skin]['animation']['popout']['autoclose']['show_countdown'] : '',
);
$form['settings']['jquery_ui'] = array(
'#type' => 'fieldset',
'#title' => t('jQuery UI enhancements'),
'#weight' => 3,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['settings']['jquery_ui']['draggable'] = array(
'#type' => 'checkbox',
'#title' => t('Make Better Messages draggable'),
'#default_value' => $skin ? $settings[$skin]['jquery_ui']['draggable'] : '',
);
$visibility_options = array(
0 => t('All pages except those listed'),
1 => t('Only the listed pages'),
);
$visibility_description = t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array(
'%blog' => 'blog',
'%blog-wildcard' => 'blog/*',
'%front' => '<front>',
));
$php_access = user_access('use PHP for settings');
if (module_exists('php') && $php_access) {
$visibility_options += array(
2 => t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'),
);
$visibility_description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.', array(
'%php' => '<?php ?>',
));
}
$form['settings']['visibility_fieldset'] = array(
'#type' => 'fieldset',
'#weight' => 4,
'#title' => t('Better Messages visibility'),
'#collapsible' => FALSE,
);
$form['settings']['visibility_fieldset']['visibility'] = array(
'#type' => 'radios',
'#title' => t('Show Better Messages on specific pages'),
'#options' => $visibility_options,
'#default_value' => $skin ? $settings[$skin]['admin']['visibility']['visibility'] : '',
);
$form['settings']['visibility_fieldset']['pages'] = array(
'#type' => 'textarea',
'#default_value' => $skin ? $settings[$skin]['admin']['visibility']['pages'] : '',
'#description' => $visibility_description,
);
$form['actions'] = array(
'#tree' => FALSE,
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
$form['#theme'] = 'system_settings_form';
return $form;
}
function better_messages_admin_skin_form_validate($form, &$form_state) {
$numeric_fields = array(
'space_x',
'space_y',
'open_delay',
'autoclose_seconds',
);
foreach ($numeric_fields as $field_name) {
if (!is_numeric($form_state['values'][$field_name])) {
form_set_error($field_name, t('Value must be numerical.'));
}
}
$percentage_width = str_replace('%', '', $form_state['values']['width']);
$pixels_width = str_replace('px', '', $form_state['values']['width']);
if (!(is_numeric($percentage_width) xor is_numeric($pixels_width))) {
form_set_error('width', t('Width is invalid. Make sure you use only px or % suffix.'));
}
$popup_allowed_str = array(
'slow',
'normal',
'fast',
);
if (in_array($form_state['values']['popin_duration'], $popup_allowed_str) xor !is_numeric($form_state['values']['popin_duration'])) {
form_set_error('popin_duration', t('Duration of (show) effect is invalid.'));
}
if (in_array($form_state['values']['popout_duration'], $popup_allowed_str) xor !is_numeric($form_state['values']['popout_duration'])) {
form_set_error('popout_duration', t('Duration of (close) effect is invalid.'));
}
}
function better_messages_admin_skin_form_submit($form, &$form_state) {
if ($form_state['build_info']['args'][0] == 'add' || $form_state['build_info']['args'][0] == 'clone') {
}
if ($form_state['build_info']['args'][0] == 'edit') {
}
$settings = array(
'placement' => array(
'pos_x' => $form_state['values']['pos_x'],
'pos_y' => $form_state['values']['pos_y'],
'space_x' => trim($form_state['values']['space_x']),
'space_y' => trim($form_state['values']['space_y']),
'width' => trim($form_state['values']['width']),
'fixed' => $form_state['values']['fixed'],
),
'animation' => array(
'popin' => array(
'effect' => $form_state['values']['popin_effect'],
'easing' => trim($form_state['values']['popin_easing']),
'duration' => trim($form_state['values']['popin_duration']),
'opendelay' => trim($form_state['values']['open_delay']),
),
'popout' => array(
'effect' => $form_state['values']['popout_effect'],
'easing' => trim($form_state['values']['popout_easing']),
'duration' => trim($form_state['values']['popout_duration']),
'autoclose' => array(
'seconds' => trim($form_state['values']['autoclose_seconds']),
'disable_autoclose_error' => $form_state['values']['disable_autoclose_error'],
'disable_autoclose_hover' => $form_state['values']['disable_autoclose_hover'],
'show_countdown' => $form_state['values']['show_countdown'],
),
),
),
'jquery_ui' => array(
'draggable' => $form_state['values']['draggable'],
),
'admin' => array(
'visibility' => array(
'visibility' => $form_state['values']['visibility'],
'pages' => trim($form_state['values']['pages']),
),
'title' => $form_state['values']['name'],
'css' => $form_state['values']['css_path'],
'storage' => 'custom',
),
);
$skin = array(
'name' => $form_state['values']['machine_name'],
'data' => serialize($settings),
);
drupal_write_record('better_messages', $skin);
drupal_set_message(t('The configuration options for the skin %skin have been saved.', array(
'%skin' => $form_state['values']['name'],
)));
$form_state['redirect'] = array(
'admin/config/user-interface/better-messages',
);
}
function better_messages_admin_skin_delete_form($form, $form_state, $skin) {
$skin_settings = _better_messages_get_settings($skin);
$form_state['skin'] = $skin_settings;
return confirm_form($form, t('Are you sure you want to delete Better Messages skin %skin?', array(
'%skin' => $skin_settings[$skin]['admin']['title'],
)), 'admin/config/user-interface/better-messages', null, t('Delete'), t('Cancel'));
}
function better_messages_admin_skin_delete_form_submit($form, &$form_state) {
$skin = $form_state['skin'];
db_delete('better_messages')
->condition('name', key($skin))
->execute();
drupal_set_message(t('Skin %skin was deleted.', array(
'%skin' => $skin[key($skin)]['admin']['title'],
)));
$form_state['redirect'] = 'admin/config/user-interface/better-messages';
}