diff --git a/indefero/src/IDF/Form/Upload.php b/indefero/src/IDF/Form/Upload.php index 52046a7..ab0ac98 100644 --- a/indefero/src/IDF/Form/Upload.php +++ b/indefero/src/IDF/Form/Upload.php @@ -53,6 +53,15 @@ class IDF_Form_Upload extends Pluf_Form 'size' => 67, ), )); + $this->fields['ext_file_name'] = new Pluf_Form_Field_Varchar( + array('required' => false, + 'label' => __('External File Name'), + 'initial' => '', + 'widget_attrs' => array( + 'maxlength' => 200, + 'size' => 67, + ), + )); $this->fields['changelog'] = new Pluf_Form_Field_Varchar( array('required' => false, 'label' => __('Description'), @@ -133,9 +142,15 @@ class IDF_Form_Upload extends Pluf_Form throw new Pluf_Form_Invalid(__('You provided an invalid label.')); } } - if (empty($this->cleaned_data["file"]) && empty($this->cleaned_data["ext_file"])) { + if (empty($this->cleaned_data["file"]) && empty($this->cleaned_data["ext_file"]) && empty($this->cleaned_data["ext_file_name"])) { throw new Pluf_Form_Invalid(__("Must upload a file or specify an external file")); } + + foreach(explode(".", $this->cleaned_data["ext_file_name"]) as $section) { + if (!ctype_alpha($section)) { + throw new Pluf_Form_Invalid(__("External file name must not contain characters other than a-zA-Z and .")); + } + } return $this->cleaned_data; } @@ -188,7 +203,7 @@ class IDF_Form_Upload extends Pluf_Form $upload->file = $this->cleaned_data['file']; $upload->filesize = filesize(Pluf::f('upload_path').'/'.$this->project->shortname.'/files/'.$this->cleaned_data['file']); } else { - $upload->file = end(explode("/", $this->cleaned_data["ext_file"])); + $upload->file = $this->cleaned_data["ext_file_name"]; $upload->ext_file = $this->cleaned_data['ext_file']; } diff --git a/indefero/src/IDF/Upload.php b/indefero/src/IDF/Upload.php index fa49d9a..caf5290 100644 --- a/indefero/src/IDF/Upload.php +++ b/indefero/src/IDF/Upload.php @@ -63,6 +63,13 @@ class IDF_Upload extends Pluf_Model 'size' => 250, 'verbose' => __('External File URL'), ), + 'ext_file_name' => + array( + 'type' => 'Pluf_DB_Field_Varchar', + 'blank' => false, + 'size' => 250, + 'verbose' => __('External File Name'), + ), 'changelog' => array( 'type' => 'Pluf_DB_Field_Text', diff --git a/indefero/src/IDF/templates/idf/downloads/create.html b/indefero/src/IDF/templates/idf/downloads/create.html index b42e577..3844ccb 100644 --- a/indefero/src/IDF/templates/idf/downloads/create.html +++ b/indefero/src/IDF/templates/idf/downloads/create.html @@ -25,6 +25,13 @@ + {$form.f.ext_file_name.labelTag}: + {if $form.f.ext_file_name.errors}{$form.f.ext_file_name.fieldErrors}{/if} + {$form.f.ext_file_name|unsafe} + + + + {$form.f.changelog.labelTag}: {if $form.f.changelog.errors}{$form.f.changelog.fieldErrors}{/if} {$form.f.changelog|unsafe}