--- C:\Documents and Settings\Aldo\Local Settings\Temp\TCV5bbf.tmp\field_file.1.13.inc Sat Jul 01 00:11:29 2006 +++ D:\drupal cvs\contributions\modules\flexinode\field_file.inc Sat Jul 01 00:05:53 2006 @@ -46,15 +46,65 @@ } } +function flexinode_field_file_validate($field, $node) { + $fieldname = 'flexinode_'. $field->field_id; + if($file = file_check_upload($fieldname)) { + $pathinfo = pathinfo($file->filename); + if ($field->options[1]!=NULL && (!in_array($pathinfo['extension'], explode(',', $field->options[1]) ))) { + form_set_error($fieldname, t('The file has the wrong extension and/or type.')); + } + else if ($field->options[2]!=NULL && @filesize($file->filepath) > ($field->options[2] * 1000)) { + form_set_error($fieldname, t('The uploaded image is too large; the maximum file size is %num kB.', array('%num' => $field->options[4]))); + } + } + elseif(!empty($node->$fieldname)) { + form_set_error($fieldname, t('The file upload was not successful.')); + } +} + + function flexinode_field_file_execute($field, $node) { $fieldname = 'flexinode_'. $field->field_id; - if ($file = file_save_upload($fieldname, variable_get('file_directory_path', NULL))) { + $savepath = flexinode_save_path((isset($field->options[3])) ? $field->options[3]:NULL); + if ($file = file_save_upload($fieldname, $savepath )) { return $file; } elseif (empty($node->$fieldname)) { return unserialize($node->{$fieldname .'_old'}); } } + +function flexinode_field_file_config($field, $edit) { + $form = array(); + + $form['fileoptions'] = array( + '#type' => 'fieldset', + '#title' => t('Options'), + '#description' => t('Limitations for files to upload.'), + ); + $form['fileoptions'][] = array('options][1' => array( + '#type' => 'textfield', + '#title' => t('Allowed extensions'), + '#default_value' => $field->options[1], + '#description' => t('Comma separated list of allowed file extensions. Leave blank for no restriction (except extensions that would impair security).'), + )); + $form['fileoptions'][] = array('options][2' => array( + '#type' => 'textfield', + '#title' => t('Maximum file size'), + '#default_value' => $field->options[2], + '#description' => t('Maximum picture file size, in kB. Leave blank for unlimited'), + )); + + $form[] = array('options][3' => array( + '#type' => 'textfield', + '#title' => 'Save path format', + '#default_value' => $field->options[3], + '#description' => t('Enter save path format, this will be appended to file_directory_path, mark it up with %username, %day, %dayname, %month, %monthname, %year. Blank if not required. Example: nodefiles/%year/%month/%username. Directories will be created if not present, and original filenames are preserved.'), + )); + + return $form; +} + function flexinode_field_file_format($field, $node, $brief = 0) { $fieldname = 'flexinode_'. $field->field_id;