Fix: Protected member variable must not be prefixed with an underscore
This commit is contained in:
parent
e9994c683a
commit
6c8db0aa2d
@ -31,9 +31,9 @@ require_once(DOL_DOCUMENT_ROOT."/core/lib/images.lib.php");
|
|||||||
*/
|
*/
|
||||||
class FileUpload
|
class FileUpload
|
||||||
{
|
{
|
||||||
protected $_options;
|
protected $options;
|
||||||
protected $_fk_element;
|
protected $fk_element;
|
||||||
protected $_element;
|
protected $element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -47,8 +47,8 @@ class FileUpload
|
|||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
global $object;
|
global $object;
|
||||||
|
|
||||||
$this->_fk_element=$fk_element;
|
$this->fk_element=$fk_element;
|
||||||
$this->_element=$element;
|
$this->element=$element;
|
||||||
|
|
||||||
$pathname=$filename=$element;
|
$pathname=$filename=$element;
|
||||||
if (preg_match('/^([^_]+)_([^_]+)/i',$element,$regs))
|
if (preg_match('/^([^_]+)_([^_]+)/i',$element,$regs))
|
||||||
@ -76,7 +76,7 @@ class FileUpload
|
|||||||
$object->fetch($fk_element);
|
$object->fetch($fk_element);
|
||||||
$object->fetch_thirdparty();
|
$object->fetch_thirdparty();
|
||||||
|
|
||||||
$this->_options = array(
|
$this->options = array(
|
||||||
'script_url' => $_SERVER['PHP_SELF'],
|
'script_url' => $_SERVER['PHP_SELF'],
|
||||||
'upload_dir' => $conf->$element->dir_output . '/' . $object->ref . '/',
|
'upload_dir' => $conf->$element->dir_output . '/' . $object->ref . '/',
|
||||||
'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object->ref.'/',
|
'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object->ref.'/',
|
||||||
@ -120,7 +120,7 @@ class FileUpload
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
if ($options) {
|
if ($options) {
|
||||||
$this->_options = array_replace_recursive($this->_options, $options);
|
$this->options = array_replace_recursive($this->options, $options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,9 +144,9 @@ class FileUpload
|
|||||||
* @param unknown_type $file
|
* @param unknown_type $file
|
||||||
*/
|
*/
|
||||||
protected function set_file_delete_url($file) {
|
protected function set_file_delete_url($file) {
|
||||||
$file->delete_url = $this->_options['script_url']
|
$file->delete_url = $this->options['script_url']
|
||||||
.'?file='.rawurlencode($file->name).'&fk_element='.$this->_fk_element.'&element='.$this->_element;
|
.'?file='.rawurlencode($file->name).'&fk_element='.$this->fk_element.'&element='.$this->element;
|
||||||
$file->delete_type = $this->_options['delete_type'];
|
$file->delete_type = $this->options['delete_type'];
|
||||||
if ($file->delete_type !== 'DELETE') {
|
if ($file->delete_type !== 'DELETE') {
|
||||||
$file->delete_url .= '&_method=DELETE';
|
$file->delete_url .= '&_method=DELETE';
|
||||||
}
|
}
|
||||||
@ -160,15 +160,15 @@ class FileUpload
|
|||||||
*/
|
*/
|
||||||
protected function get_file_object($file_name)
|
protected function get_file_object($file_name)
|
||||||
{
|
{
|
||||||
$file_path = $this->_options['upload_dir'].$file_name;
|
$file_path = $this->options['upload_dir'].$file_name;
|
||||||
if (is_file($file_path) && $file_name[0] !== '.')
|
if (is_file($file_path) && $file_name[0] !== '.')
|
||||||
{
|
{
|
||||||
$file = new stdClass();
|
$file = new stdClass();
|
||||||
$file->name = $file_name;
|
$file->name = $file_name;
|
||||||
$file->mime = dol_mimetype($file_name,'',2);
|
$file->mime = dol_mimetype($file_name,'',2);
|
||||||
$file->size = filesize($file_path);
|
$file->size = filesize($file_path);
|
||||||
$file->url = $this->_options['upload_url'].rawurlencode($file->name);
|
$file->url = $this->options['upload_url'].rawurlencode($file->name);
|
||||||
foreach($this->_options['image_versions'] as $version => $options) {
|
foreach($this->options['image_versions'] as $version => $options) {
|
||||||
if (is_file($options['upload_dir'].$file_name)) {
|
if (is_file($options['upload_dir'].$file_name)) {
|
||||||
$tmp=explode('.',$file->name);
|
$tmp=explode('.',$file->name);
|
||||||
$file->{$version.'_url'} = $options['upload_url'].rawurlencode($tmp[0].'_mini.'.$tmp[1]);
|
$file->{$version.'_url'} = $options['upload_url'].rawurlencode($tmp[0].'_mini.'.$tmp[1]);
|
||||||
@ -187,7 +187,7 @@ class FileUpload
|
|||||||
*/
|
*/
|
||||||
protected function get_file_objects()
|
protected function get_file_objects()
|
||||||
{
|
{
|
||||||
return array_values(array_filter(array_map(array($this, 'get_file_object'), scandir($this->_options['upload_dir']))));
|
return array_values(array_filter(array_map(array($this, 'get_file_object'), scandir($this->options['upload_dir']))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -201,7 +201,7 @@ class FileUpload
|
|||||||
{
|
{
|
||||||
global $maxwidthmini, $maxheightmini;
|
global $maxwidthmini, $maxheightmini;
|
||||||
|
|
||||||
$file_path = $this->_options['upload_dir'].$file_name;
|
$file_path = $this->options['upload_dir'].$file_name;
|
||||||
$new_file_path = $options['upload_dir'].$file_name;
|
$new_file_path = $options['upload_dir'].$file_name;
|
||||||
|
|
||||||
if (dol_mkdir($options['upload_dir']) >= 0)
|
if (dol_mkdir($options['upload_dir']) >= 0)
|
||||||
@ -242,7 +242,7 @@ class FileUpload
|
|||||||
$file->error = 'missingFileName';
|
$file->error = 'missingFileName';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!preg_match($this->_options['accept_file_types'], $file->name)) {
|
if (!preg_match($this->options['accept_file_types'], $file->name)) {
|
||||||
$file->error = 'acceptFileTypes';
|
$file->error = 'acceptFileTypes';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -251,33 +251,33 @@ class FileUpload
|
|||||||
} else {
|
} else {
|
||||||
$file_size = $_SERVER['CONTENT_LENGTH'];
|
$file_size = $_SERVER['CONTENT_LENGTH'];
|
||||||
}
|
}
|
||||||
if ($this->_options['max_file_size'] && (
|
if ($this->options['max_file_size'] && (
|
||||||
$file_size > $this->_options['max_file_size'] ||
|
$file_size > $this->options['max_file_size'] ||
|
||||||
$file->size > $this->_options['max_file_size'])
|
$file->size > $this->options['max_file_size'])
|
||||||
) {
|
) {
|
||||||
$file->error = 'maxFileSize';
|
$file->error = 'maxFileSize';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($this->_options['min_file_size'] &&
|
if ($this->options['min_file_size'] &&
|
||||||
$file_size < $this->_options['min_file_size']) {
|
$file_size < $this->options['min_file_size']) {
|
||||||
$file->error = 'minFileSize';
|
$file->error = 'minFileSize';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (is_int($this->_options['max_number_of_files']) && (
|
if (is_int($this->options['max_number_of_files']) && (
|
||||||
count($this->get_file_objects()) >= $this->_options['max_number_of_files'])
|
count($this->get_file_objects()) >= $this->options['max_number_of_files'])
|
||||||
) {
|
) {
|
||||||
$file->error = 'maxNumberOfFiles';
|
$file->error = 'maxNumberOfFiles';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
list($img_width, $img_height) = @getimagesize($uploaded_file);
|
list($img_width, $img_height) = @getimagesize($uploaded_file);
|
||||||
if (is_int($img_width)) {
|
if (is_int($img_width)) {
|
||||||
if ($this->_options['max_width'] && $img_width > $this->_options['max_width'] ||
|
if ($this->options['max_width'] && $img_width > $this->options['max_width'] ||
|
||||||
$this->_options['max_height'] && $img_height > $this->_options['max_height']) {
|
$this->options['max_height'] && $img_height > $this->options['max_height']) {
|
||||||
$file->error = 'maxResolution';
|
$file->error = 'maxResolution';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($this->_options['min_width'] && $img_width < $this->_options['min_width'] ||
|
if ($this->options['min_width'] && $img_width < $this->options['min_width'] ||
|
||||||
$this->_options['min_height'] && $img_height < $this->_options['min_height']) {
|
$this->options['min_height'] && $img_height < $this->options['min_height']) {
|
||||||
$file->error = 'minResolution';
|
$file->error = 'minResolution';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -327,8 +327,8 @@ class FileUpload
|
|||||||
preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {
|
preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {
|
||||||
$file_name .= '.'.$matches[1];
|
$file_name .= '.'.$matches[1];
|
||||||
}
|
}
|
||||||
if ($this->_options['discard_aborted_uploads']) {
|
if ($this->options['discard_aborted_uploads']) {
|
||||||
while(is_file($this->_options['upload_dir'].$file_name)) {
|
while(is_file($this->options['upload_dir'].$file_name)) {
|
||||||
$file_name = $this->upcount_name($file_name);
|
$file_name = $this->upcount_name($file_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -397,10 +397,10 @@ class FileUpload
|
|||||||
$file->mime = dol_mimetype($file->name,'',2);
|
$file->mime = dol_mimetype($file->name,'',2);
|
||||||
$file->size = intval($size);
|
$file->size = intval($size);
|
||||||
$file->type = $type;
|
$file->type = $type;
|
||||||
if ($this->validate($uploaded_file, $file, $error, $index) && dol_mkdir($this->_options['upload_dir']) >= 0) {
|
if ($this->validate($uploaded_file, $file, $error, $index) && dol_mkdir($this->options['upload_dir']) >= 0) {
|
||||||
$this->handle_form_data($file, $index);
|
$this->handle_form_data($file, $index);
|
||||||
$file_path = $this->_options['upload_dir'].$file->name;
|
$file_path = $this->options['upload_dir'].$file->name;
|
||||||
$append_file = !$this->_options['discard_aborted_uploads'] && is_file($file_path) && $file->size > filesize($file_path);
|
$append_file = !$this->options['discard_aborted_uploads'] && is_file($file_path) && $file->size > filesize($file_path);
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
if ($uploaded_file && is_uploaded_file($uploaded_file)) {
|
if ($uploaded_file && is_uploaded_file($uploaded_file)) {
|
||||||
// multipart/formdata uploads (POST method uploads)
|
// multipart/formdata uploads (POST method uploads)
|
||||||
@ -423,8 +423,8 @@ class FileUpload
|
|||||||
}
|
}
|
||||||
$file_size = filesize($file_path);
|
$file_size = filesize($file_path);
|
||||||
if ($file_size === $file->size) {
|
if ($file_size === $file->size) {
|
||||||
$file->url = $this->_options['upload_url'].rawurlencode($file->name);
|
$file->url = $this->options['upload_url'].rawurlencode($file->name);
|
||||||
foreach($this->_options['image_versions'] as $version => $options)
|
foreach($this->options['image_versions'] as $version => $options)
|
||||||
{
|
{
|
||||||
if ($this->create_scaled_image($file->name, $options))
|
if ($this->create_scaled_image($file->name, $options))
|
||||||
{
|
{
|
||||||
@ -432,7 +432,7 @@ class FileUpload
|
|||||||
$file->{$version.'_url'} = $options['upload_url'].rawurlencode($tmp[0].'_mini.'.$tmp[1]);
|
$file->{$version.'_url'} = $options['upload_url'].rawurlencode($tmp[0].'_mini.'.$tmp[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ($this->_options['discard_aborted_uploads']) {
|
} else if ($this->options['discard_aborted_uploads']) {
|
||||||
unlink($file_path);
|
unlink($file_path);
|
||||||
$file->error = 'abort';
|
$file->error = 'abort';
|
||||||
}
|
}
|
||||||
@ -470,8 +470,8 @@ class FileUpload
|
|||||||
if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
|
if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
|
||||||
return $this->delete();
|
return $this->delete();
|
||||||
}
|
}
|
||||||
$upload = isset($_FILES[$this->_options['param_name']]) ?
|
$upload = isset($_FILES[$this->options['param_name']]) ?
|
||||||
$_FILES[$this->_options['param_name']] : null;
|
$_FILES[$this->options['param_name']] : null;
|
||||||
$info = array();
|
$info = array();
|
||||||
if ($upload && is_array($upload['tmp_name'])) {
|
if ($upload && is_array($upload['tmp_name'])) {
|
||||||
// param_name is an array identifier like "files[]",
|
// param_name is an array identifier like "files[]",
|
||||||
@ -529,10 +529,10 @@ class FileUpload
|
|||||||
{
|
{
|
||||||
$file_name = isset($_REQUEST['file']) ?
|
$file_name = isset($_REQUEST['file']) ?
|
||||||
basename(stripslashes($_REQUEST['file'])) : null;
|
basename(stripslashes($_REQUEST['file'])) : null;
|
||||||
$file_path = $this->_options['upload_dir'].$file_name;
|
$file_path = $this->options['upload_dir'].$file_name;
|
||||||
$success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path);
|
$success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path);
|
||||||
if ($success) {
|
if ($success) {
|
||||||
foreach($this->_options['image_versions'] as $version => $options) {
|
foreach($this->options['image_versions'] as $version => $options) {
|
||||||
$file = $options['upload_dir'].$file_name;
|
$file = $options['upload_dir'].$file_name;
|
||||||
if (is_file($file)) {
|
if (is_file($file)) {
|
||||||
unlink($file);
|
unlink($file);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user