function _outline_designer_settings_submit in Outline Designer 7
Same name and namespace in other branches
- 6 outline_designer.module \_outline_designer_settings_submit()
Implementation of hook_settings_submit().
File
- ./
outline_designer.module, line 436 - Massive usability improvement for quickly structuring / creating content.
Code
function _outline_designer_settings_submit($form, &$form_state) {
$checkboxes = array();
$items_unchecked = array();
// store the context menu settings
$form_values = array_filter($form_state['values']);
$menu_items = array_keys($form["context_menu"]["checkboxes"]);
// collect all the ticked checkboxes
foreach ($form_values as $key => $val) {
if (strpos($key, "outline_designer_context_menu_") !== FALSE) {
$checkboxes[] = $key;
}
}
// extrapolate which items have unchecked by comparing the list of
// ticked checkboxes with the list of all the context menu checkboxes
foreach ($menu_items as $item) {
if (substr($item, 0, 1) != "#") {
$item_checkboxes = $form["context_menu"]["checkboxes"][$item];
foreach ($item_checkboxes as $cb_name => $cb_properties) {
if ($cb_properties['#type'] == 'checkbox' && !in_array($cb_name, $checkboxes)) {
$items_unchecked[$cb_properties['#return_value']['rid']][$cb_properties['#return_value']['item_name']]['unchecked'] = TRUE;
}
}
}
}
variable_set('outline_designer_context_menu_exclusion_matrix', array_filter($items_unchecked));
// store the checkbox value
variable_set('outline_designer_collapse_toggle', $form_state['values']["outline_designer_collapse_toggle"]);
// store theme selected
variable_set('outline_designer_theme', $form_state['values']["outline_designer_theme"]);
// take into account outline child pages
if (function_exists('outline_child_pages_menu')) {
variable_set('outline_child_pages_type', $form_state['values']["outline_child_pages_type"]);
}
// the rest is for files
$dir = file_create_path(file_directory_path() . '/outline_designer');
$is_writable = file_prepare_directory($dir, 1);
if ($is_writable) {
$validators = array(
'file_validate_is_image' => array(),
'_outline_designer_validate_image_resolution' => array(
'16x16',
),
'file_validate_size' => array(
30 * 1024,
),
);
$result = db_query("SELECT type, name FROM {node_type}");
while ($value = db_fetch_array($result)) {
if ($file = file_save_upload("outline_designer_" . $value['type'] . "_icon", $validators, $dir)) {
drupal_set_message(t('New @title icon saved.', array(
'@title' => $value['name'],
)));
variable_set("outline_designer_" . $value['type'] . "_icon", $file->filepath);
}
else {
// this is the case when there is no image uploaded to associate the textfield icon to the icon page to use, this will allow for references to icons already used
$icon = check_plain($form_state['values']["outline_designer_" . $value['type'] . "_icon_link"]);
$base_path = base_path();
// pull off the site name if it was included
if ($base_path != '/' && $base_path != '') {
if (strpos(' ' . $icon, $base_path) != 0) {
$pos = strpos($icon, $base_path) + drupal_strlen($base_path);
$icon = drupal_substr($icon, $pos);
}
}
// clean up the string incase those other two didn't do the trick
$icon = drupal_substr($icon, strpos($icon, drupal_get_path('module', 'outline_designer')));
$icon = drupal_substr($icon, strpos($icon, file_directory_path()));
// potentially this isn't a valid icon path on our server...need to still check this
variable_set("outline_designer_" . $value['type'] . "_icon", $icon);
}
}
}
drupal_set_message(t('Settings saved'));
}