[ticket/10763] Make functions for remote avatars static

fileupload::image_types() and filespec::get_extension() are called
statically while submitting the form for the remote avatar. Make them
static as described in the ticket in order to prevent a PHP notice.
Also change the tests to use the static functions.

PHPBB3-10763
This commit is contained in:
Marc Alexander 2012-12-17 12:59:44 +01:00
parent 9420647c43
commit 54d96dfac7
3 changed files with 11 additions and 36 deletions

View file

@ -70,7 +70,7 @@ class filespec
$this->mimetype = 'application/octetstream'; $this->mimetype = 'application/octetstream';
} }
$this->extension = strtolower($this->get_extension($this->realname)); $this->extension = strtolower(filespec::get_extension($this->realname));
// Try to get real filesize from temporary folder (not always working) ;) // Try to get real filesize from temporary folder (not always working) ;)
$this->filesize = (@filesize($this->filename)) ? @filesize($this->filename) : $this->filesize; $this->filesize = (@filesize($this->filename)) ? @filesize($this->filename) : $this->filesize;
@ -187,8 +187,11 @@ class filespec
/** /**
* Get file extension * Get file extension
*
* @param string Filename that needs to be checked
* @return string Extension of the supplied filename
*/ */
function get_extension($filename) static public function get_extension($filename)
{ {
if (strpos($filename, '.') === false) if (strpos($filename, '.') === false)
{ {
@ -369,7 +372,7 @@ class filespec
} }
// Check image type // Check image type
$types = $this->upload->image_types(); $types = fileupload::image_types();
if (!isset($types[$this->image_info[2]]) || !in_array($this->extension, $types[$this->image_info[2]])) if (!isset($types[$this->image_info[2]]) || !in_array($this->extension, $types[$this->image_info[2]]))
{ {
@ -1019,9 +1022,11 @@ class fileupload
} }
/** /**
* Return image type/extension mapping * Get image type/extension mapping
*
* @return array Array containing the image types and their extensions
*/ */
function image_types() static public function image_types()
{ {
return array( return array(
IMAGETYPE_GIF => array('gif'), IMAGETYPE_GIF => array('gif'),

View file

@ -20,33 +20,4 @@ class phpbb_mock_fileupload
{ {
return true; return true;
} }
/**
* Copied verbatim from phpBB/includes/functions_upload.php's fileupload
* class to ensure the correct behaviour of filespec::move_file.
*
* Maps file extensions to the constant in second index of the array
* returned by getimagesize()
*/
public function image_types()
{
return array(
IMAGETYPE_GIF => array('gif'),
IMAGETYPE_JPEG => array('jpg', 'jpeg'),
IMAGETYPE_PNG => array('png'),
IMAGETYPE_SWF => array('swf'),
IMAGETYPE_PSD => array('psd'),
IMAGETYPE_BMP => array('bmp'),
IMAGETYPE_TIFF_II => array('tif', 'tiff'),
IMAGETYPE_TIFF_MM => array('tif', 'tiff'),
IMAGETYPE_JPC => array('jpg', 'jpeg'),
IMAGETYPE_JP2 => array('jpg', 'jpeg'),
IMAGETYPE_JPX => array('jpg', 'jpeg'),
IMAGETYPE_JB2 => array('jpg', 'jpeg'),
IMAGETYPE_SWC => array('swc'),
IMAGETYPE_IFF => array('iff'),
IMAGETYPE_WBMP => array('wbmp'),
IMAGETYPE_XBM => array('xbm'),
);
}
} }

View file

@ -205,8 +205,7 @@ class phpbb_filespec_test extends phpbb_test_case
*/ */
public function test_get_extension($filename, $expected) public function test_get_extension($filename, $expected)
{ {
$filespec = $this->get_filespec(); $this->assertEquals($expected, filespec::get_extension($filename));
$this->assertEquals($expected, $filespec->get_extension($filename));
} }
public function is_image_variables() public function is_image_variables()