function outline_designer_settings_submit in Outline Designer 5
Implementation of hook_settings_submit
File
- ./
outline_designer.module, line 172
Code
function outline_designer_settings_submit($form_id, $form_values) {
$dir = file_create_path(file_directory_path() . '/outline_designer');
$is_writable = file_check_directory($dir, 1);
if ($is_writable) {
$result = db_query("SELECT type,name FROM {node_type}");
while ($value = db_fetch_array($result)) {
$source = file_check_upload("outline_designer_" . $value['type'] . "_icon");
// Security measure to prevent exploit of file.php.png
if ($source->filename != '') {
$source->filename = upload_munge_filename($source->filename);
if ($file = file_save_upload($source, $dir)) {
$image_ary = image_get_info($file->filepath);
if ($image_ary) {
//icons must be 16x16, png or gif format
if ($image_ary['mime_type'] != 'image/png' && $image_ary['mime_type'] != 'image/gif') {
file_delete($file->filepath);
drupal_set_message('Uploaded file must be PNG or GIF format.', 'error');
}
else {
if ($image_ary['height'] != 16 || $image_ary['width'] != 16) {
file_delete($file->filepath);
drupal_set_message('Uploaded image must be 16x16 pixels.', 'error');
}
else {
drupal_set_message(t('New ' . $value['name'] . ' icon saved.'));
variable_set("outline_designer_" . $value['type'] . "_icon", $file->filepath);
}
}
}
else {
file_delete($file->filepath);
drupal_set_message('Uploaded file does not appear to be a valid image file. Please try again.', 'error');
}
}
}
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 = $form_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) + strlen($base_path);
$icon = substr($icon, $pos);
}
}
//clean up the string incase those other two didn't do the trick
$icon = substr($icon, strpos($icon, drupal_get_path('module', 'outline_designer')));
$icon = 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);
}
}
}
//over-riding the normal submit function so these need to be set manually
variable_set("outline_designer_default_type", $form_values['outline_designer_default_type']);
variable_set("outline_designer_content_types", $form_values['outline_designer_content_types']);
}