mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-30 21:29:23 +02:00
BUGFIX: replacing calls to deprecated Upload functions - using validator instead (related to r100057) (from r100496)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@105581 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
1e5944c690
commit
ecb6c8cb3f
@ -53,6 +53,15 @@ class Upload extends Controller {
|
|||||||
$this->validator = new Upload_Validator();
|
$this->validator = new Upload_Validator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current validator
|
||||||
|
*
|
||||||
|
* @return object $validator
|
||||||
|
*/
|
||||||
|
public function getValidator() {
|
||||||
|
return $this->validator;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a different instance than {@link Upload_Validator}
|
* Set a different instance than {@link Upload_Validator}
|
||||||
* for this upload session.
|
* for this upload session.
|
||||||
|
@ -19,6 +19,7 @@ class FileField extends FormField {
|
|||||||
* or a specific extension, with extension-name
|
* or a specific extension, with extension-name
|
||||||
* as array-key and the size-restriction in bytes as array-value.
|
* as array-key and the size-restriction in bytes as array-value.
|
||||||
*
|
*
|
||||||
|
* @deprecated 2.5
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $allowedMaxFileSize = array();
|
public $allowedMaxFileSize = array();
|
||||||
@ -31,6 +32,9 @@ class FileField extends FormField {
|
|||||||
* <code>
|
* <code>
|
||||||
* array("jpg","GIF")
|
* array("jpg","GIF")
|
||||||
* </code>
|
* </code>
|
||||||
|
*
|
||||||
|
* @deprecated 2.5
|
||||||
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $allowedExtensions = array();
|
public $allowedExtensions = array();
|
||||||
|
|
||||||
@ -93,7 +97,7 @@ class FileField extends FormField {
|
|||||||
array(
|
array(
|
||||||
"type" => "hidden",
|
"type" => "hidden",
|
||||||
"name" => "MAX_FILE_SIZE",
|
"name" => "MAX_FILE_SIZE",
|
||||||
"value" => $this->getAllowedMaxFileSize(),
|
"value" => $this->getValidator()->getAllowedMaxFileSize(),
|
||||||
"tabindex" => $this->getTabIndex()
|
"tabindex" => $this->getTabIndex()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -111,8 +115,6 @@ class FileField extends FormField {
|
|||||||
$file = new File();
|
$file = new File();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->upload->setAllowedExtensions($this->allowedExtensions);
|
|
||||||
$this->upload->setAllowedMaxFileSize($this->allowedMaxFileSize);
|
|
||||||
$this->upload->loadIntoFile($_FILES[$this->name], $file, $this->folderName);
|
$this->upload->loadIntoFile($_FILES[$this->name], $file, $this->folderName);
|
||||||
if($this->upload->isError()) return false;
|
if($this->upload->isError()) return false;
|
||||||
|
|
||||||
@ -130,21 +132,36 @@ class FileField extends FormField {
|
|||||||
return $_FILES[$this->Name()];
|
return $_FILES[$this->Name()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get custom validator for this field
|
||||||
|
*
|
||||||
|
* @param object $validator
|
||||||
|
*/
|
||||||
|
public function getValidator() {
|
||||||
|
return $this->upload->getValidator();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set custom validator for this field
|
||||||
|
*
|
||||||
|
* @param object $validator
|
||||||
|
*/
|
||||||
|
public function setValidator($validator) {
|
||||||
|
$this->upload->setValidator($validator);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get maximum file size for all or specified file extension.
|
* Get maximum file size for all or specified file extension.
|
||||||
* Falls back to the default filesize restriction ('*')
|
* Falls back to the default filesize restriction ('*')
|
||||||
* if the extension was not found.
|
* if the extension was not found.
|
||||||
*
|
*
|
||||||
|
* @deprecated 2.5
|
||||||
* @param string $ext
|
* @param string $ext
|
||||||
* @return int Filesize in bytes (0 means no filesize set)
|
* @return int Filesize in bytes (0 means no filesize set)
|
||||||
*/
|
*/
|
||||||
public function getAllowedMaxFileSize($ext = null) {
|
public function getAllowedMaxFileSize($ext = null) {
|
||||||
$ext = strtolower($ext);
|
user_error('Upload::getAllowedMaxFileSize() is deprecated. Please use Upload_Validator::getAllowedMaxFileSize() instead', E_USER_NOTICE);
|
||||||
if(isset($ext) && isset($this->allowedMaxFileSize[$ext])) {
|
$this->getValidator()->getAllowedMaxFileSize($ext);
|
||||||
return $this->allowedMaxFileSize[$ext];
|
|
||||||
} else {
|
|
||||||
return (isset($this->allowedMaxFileSize['*'])) ? $this->allowedMaxFileSize['*'] : 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,35 +174,30 @@ class FileField extends FormField {
|
|||||||
* array('*' => 200, 'jpg' => 1000)
|
* array('*' => 200, 'jpg' => 1000)
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
|
* @deprecated 2.5
|
||||||
* @param unknown_type $rules
|
* @param unknown_type $rules
|
||||||
*/
|
*/
|
||||||
public function setAllowedMaxFileSize($rules) {
|
public function setAllowedMaxFileSize($rules) {
|
||||||
if(is_array($rules)) {
|
user_error('Upload::setAllowedMaxFileSize() is deprecated. Please use Upload_Validator::setAllowedMaxFileSize() instead', E_USER_NOTICE);
|
||||||
// make sure all extensions are lowercase
|
$this->getValidator()->setAllowedMaxFileSize($rules);
|
||||||
$rules = array_change_key_case($rules, CASE_LOWER);
|
|
||||||
$this->allowedMaxFileSize = $rules;
|
|
||||||
} else {
|
|
||||||
$this->allowedMaxFileSize['*'] = (int)$rules;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @deprecated 2.5
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getAllowedExtensions() {
|
public function getAllowedExtensions() {
|
||||||
return $this->allowedExtensions;
|
user_error('Upload::getAllowedExtensions() is deprecated. Please use Upload_Validator::getAllowedExtensions() instead', E_USER_NOTICE);
|
||||||
|
return $this->getValidator()->getAllowedExtensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @deprecated 2.5
|
||||||
* @param array $rules
|
* @param array $rules
|
||||||
*/
|
*/
|
||||||
public function setAllowedExtensions($rules) {
|
public function setAllowedExtensions($rules) {
|
||||||
if(!is_array($rules)) return false;
|
user_error('Upload::setAllowedExtensions() is deprecated. Please use Upload_Validator::setAllowedExtensions() instead', E_USER_NOTICE);
|
||||||
|
$this->getValidator()->setAllowedExtensions($rules);
|
||||||
// make sure all rules are lowercase
|
|
||||||
foreach($rules as &$rule) $rule = strtolower($rule);
|
|
||||||
|
|
||||||
$this->allowedExtensions = $rules;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -206,8 +218,6 @@ class FileField extends FormField {
|
|||||||
if(!isset($_FILES[$this->name])) return true;
|
if(!isset($_FILES[$this->name])) return true;
|
||||||
|
|
||||||
$tmpFile = $_FILES[$this->name];
|
$tmpFile = $_FILES[$this->name];
|
||||||
$this->upload->setAllowedExtensions($this->allowedExtensions);
|
|
||||||
$this->upload->setAllowedMaxFileSize($this->allowedMaxFileSize);
|
|
||||||
|
|
||||||
$valid = $this->upload->validate($tmpFile);
|
$valid = $this->upload->validate($tmpFile);
|
||||||
if(!$valid) {
|
if(!$valid) {
|
||||||
|
@ -167,9 +167,6 @@ class FileIFrameField extends FileField {
|
|||||||
if($data['FileSource'] == 'new') {
|
if($data['FileSource'] == 'new') {
|
||||||
$fileObject = Object::create($desiredClass);
|
$fileObject = Object::create($desiredClass);
|
||||||
|
|
||||||
$this->upload->setAllowedExtensions($this->allowedExtensions);
|
|
||||||
$this->upload->setAllowedMaxFileSize($this->allowedMaxFileSize);
|
|
||||||
|
|
||||||
$this->upload->loadIntoFile($_FILES['Upload'], $fileObject, $this->folderName);
|
$this->upload->loadIntoFile($_FILES['Upload'], $fileObject, $this->folderName);
|
||||||
|
|
||||||
if($this->upload->isError()) {
|
if($this->upload->isError()) {
|
||||||
|
@ -20,9 +20,17 @@
|
|||||||
* @subpackage fields-files
|
* @subpackage fields-files
|
||||||
*/
|
*/
|
||||||
class SimpleImageField extends FileField {
|
class SimpleImageField extends FileField {
|
||||||
|
/**
|
||||||
|
* @deprecated 2.5
|
||||||
|
*/
|
||||||
public $allowedExtensions = array('jpg','gif','png');
|
public $allowedExtensions = array('jpg','gif','png');
|
||||||
|
|
||||||
|
function __constructor($name, $title = null, $value = null, $form = null, $rightTitle = null, $folderName = null) {
|
||||||
|
parent::__constructor($name, $title, $value, $form, $rightTitle, $folderName);
|
||||||
|
|
||||||
|
$this->getValidator()->setAllowedExtensions(array('jpg','gif','png'));
|
||||||
|
}
|
||||||
|
|
||||||
function Field() {
|
function Field() {
|
||||||
if($this->form) $record = $this->form->getRecord();
|
if($this->form) $record = $this->form->getRecord();
|
||||||
$fieldName = $this->name;
|
$fieldName = $this->name;
|
||||||
@ -55,7 +63,7 @@ class SimpleImageField extends FileField {
|
|||||||
array(
|
array(
|
||||||
"type" => "hidden",
|
"type" => "hidden",
|
||||||
"name" => "MAX_FILE_SIZE",
|
"name" => "MAX_FILE_SIZE",
|
||||||
"value" => $this->getAllowedMaxFileSize(),
|
"value" => $this->getValidator()->getAllowedMaxFileSize(),
|
||||||
"tabindex" => $this->getTabIndex()
|
"tabindex" => $this->getTabIndex()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user