aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2014-08-07 12:06:33 +0200
committerNils Adermann <naderman@naderman.de>2014-08-07 12:06:33 +0200
commitb203b4afa18e7e4774bec525620ec2a390ac374f (patch)
treeffaab499179ddddbf4f6debe766f0ccf764c596f /phpBB/includes
parenta8cb525f77059afe23629935150f8ef96e07d4f9 (diff)
parentff56f0dcfe6355a9bd24c1e33dee15c60d01526b (diff)
downloadforums-b203b4afa18e7e4774bec525620ec2a390ac374f.tar
forums-b203b4afa18e7e4774bec525620ec2a390ac374f.tar.gz
forums-b203b4afa18e7e4774bec525620ec2a390ac374f.tar.bz2
forums-b203b4afa18e7e4774bec525620ec2a390ac374f.tar.xz
forums-b203b4afa18e7e4774bec525620ec2a390ac374f.zip
Merge remote-tracking branch 'github-marc1706/ticket/11148' into develop-ascraeus
* github-marc1706/ticket/11148: [ticket/11148] Remove unneeded variable mimetype and use type octet-stream [ticket/11148] Change expected output with disallowed content in test [ticket/11148] Always use the output of the mimetype guesser in get_mimetype [ticket/11148] Get rid of extra line in mimetype guesser setter doc block [ticket/11148] Add missing parts to docblock of get_mimetype() method [ticket/11148] Default to application/octet-stream if no mimetype given [ticket/11148] Use mimetype guesser for uploaded avatars [ticket/11148] Pass mimetype guesser to upload_attachment() function [ticket/11148] Add mimetype guesser to filespec and fileupload class
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/functions_posting.php5
-rw-r--r--phpBB/includes/functions_upload.php60
-rw-r--r--phpBB/includes/message_parser.php20
3 files changed, 47 insertions, 38 deletions
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index b3f164a84d..f7e33725ec 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -398,11 +398,12 @@ function posting_gen_topic_types($forum_id, $cur_topic_type = POST_NORMAL)
* @param string $local_storage The path to the local file
* @param bool $is_message Whether it is a PM or not
* @param \filespec $local_filedata A filespec object created for the local file
+* @param \phpbb\mimetype\guesser $mimetype_guesser The mimetype guesser object if used
* @param \phpbb\plupload\plupload $plupload The plupload object if one is being used
*
* @return object filespec
*/
-function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = false, \phpbb\plupload\plupload $plupload = null)
+function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = false, \phpbb\mimetype\guesser $mimetype_guesser = null, \phpbb\plupload\plupload $plupload = null)
{
global $auth, $user, $config, $db, $cache;
global $phpbb_root_path, $phpEx, $phpbb_dispatcher;
@@ -434,7 +435,7 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage
$extensions = $cache->obtain_attach_extensions((($is_message) ? false : (int) $forum_id));
$upload->set_allowed_extensions(array_keys($extensions['_allowed_']));
- $file = ($local) ? $upload->local_upload($local_storage, $local_filedata) : $upload->form_upload($form_name, $plupload);
+ $file = ($local) ? $upload->local_upload($local_storage, $local_filedata, $mimetype_guesser) : $upload->form_upload($form_name, $mimetype_guesser, $plupload);
if ($file->init_error)
{
diff --git a/phpBB/includes/functions_upload.php b/phpBB/includes/functions_upload.php
index 0847c3a550..e658e607ec 100644
--- a/phpBB/includes/functions_upload.php
+++ b/phpBB/includes/functions_upload.php
@@ -53,10 +53,16 @@ class filespec
protected $plupload;
/**
+ * phpBB Mimetype guesser
+ * @var \phpbb\mimetype\guesser
+ */
+ protected $mimetype_guesser;
+
+ /**
* File Class
* @access private
*/
- function filespec($upload_ary, $upload_namespace, \phpbb\plupload\plupload $plupload = null)
+ function filespec($upload_ary, $upload_namespace, \phpbb\mimetype\guesser $mimetype_guesser = null, \phpbb\plupload\plupload $plupload = null)
{
if (!isset($upload_ary))
{
@@ -76,7 +82,7 @@ class filespec
if (!$this->mimetype)
{
- $this->mimetype = 'application/octetstream';
+ $this->mimetype = 'application/octet-stream';
}
$this->extension = strtolower(self::get_extension($this->realname));
@@ -90,6 +96,7 @@ class filespec
$this->local = (isset($upload_ary['local_mode'])) ? true : false;
$this->upload = $upload_namespace;
$this->plupload = $plupload;
+ $this->mimetype_guesser = $mimetype_guesser;
}
/**
@@ -215,25 +222,19 @@ class filespec
}
/**
- * Get mimetype. Utilize mime_content_type if the function exist.
- * Not used at the moment...
+ * Get mimetype
+ *
+ * @param string $filename Filename that needs to be checked
+ * @return string Mimetype of supplied filename
*/
function get_mimetype($filename)
{
- $mimetype = '';
-
- if (function_exists('mime_content_type'))
- {
- $mimetype = mime_content_type($filename);
- }
-
- // Some browsers choke on a mimetype of application/octet-stream
- if (!$mimetype || $mimetype == 'application/octet-stream')
+ if ($this->mimetype_guesser !== null)
{
- $mimetype = 'application/octetstream';
+ $this->mimetype = $this->mimetype_guesser->guess($filename);
}
- return $mimetype;
+ return $this->mimetype;
}
/**
@@ -372,6 +373,9 @@ class filespec
// Try to get real filesize from destination folder
$this->filesize = (@filesize($this->destination_file)) ? @filesize($this->destination_file) : $this->filesize;
+ // Get mimetype of supplied file
+ $this->mimetype = $this->get_mimetype($this->destination_file);
+
if ($this->is_image() && !$skip_image_check)
{
$this->width = $this->height = 0;
@@ -583,7 +587,7 @@ class fileupload
* @return object $file Object "filespec" is returned, all further operations can be done with this object
* @access public
*/
- function form_upload($form_name, \phpbb\plupload\plupload $plupload = null)
+ function form_upload($form_name, \phpbb\mimetype\guesser $mimetype_guesser = null, \phpbb\plupload\plupload $plupload = null)
{
global $user, $request;
@@ -599,7 +603,7 @@ class fileupload
}
}
- $file = new filespec($upload, $this, $plupload);
+ $file = new filespec($upload, $this, $mimetype_guesser, $plupload);
if ($file->init_error)
{
@@ -659,7 +663,7 @@ class fileupload
/**
* Move file from another location to phpBB
*/
- function local_upload($source_file, $filedata = false)
+ function local_upload($source_file, $filedata = false, \phpbb\mimetype\guesser $mimetype_guesser = null)
{
global $user, $request;
@@ -672,20 +676,6 @@ class fileupload
{
$upload['name'] = utf8_basename($source_file);
$upload['size'] = 0;
- $mimetype = '';
-
- if (function_exists('mime_content_type'))
- {
- $mimetype = mime_content_type($source_file);
- }
-
- // Some browsers choke on a mimetype of application/octet-stream
- if (!$mimetype || $mimetype == 'application/octet-stream')
- {
- $mimetype = 'application/octetstream';
- }
-
- $upload['type'] = $mimetype;
}
else
{
@@ -694,7 +684,7 @@ class fileupload
$upload['type'] = $filedata['type'];
}
- $file = new filespec($upload, $this);
+ $file = new filespec($upload, $this, $mimetype_guesser);
if ($file->init_error)
{
@@ -752,7 +742,7 @@ class fileupload
* @return object $file Object "filespec" is returned, all further operations can be done with this object
* @access public
*/
- function remote_upload($upload_url)
+ function remote_upload($upload_url, \phpbb\mimetype\guesser $mimetype_guesser = null)
{
global $user, $phpbb_root_path;
@@ -931,7 +921,7 @@ class fileupload
$upload_ary['tmp_name'] = $filename;
- $file = new filespec($upload_ary, $this);
+ $file = new filespec($upload_ary, $this, $mimetype_guesser);
$this->common_checks($file);
return $file;
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index da27d8900d..92ace7b585 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -1083,6 +1083,12 @@ class parse_message extends bbcode_firstpass
protected $plupload;
/**
+ * The mimetype guesser object used for attachment mimetypes
+ * @var \phpbb\mimetype\guesser
+ */
+ protected $mimetype_guesser;
+
+ /**
* Init - give message here or manually
*/
function parse_message($message = '')
@@ -1560,7 +1566,7 @@ class parse_message extends bbcode_firstpass
{
if ($num_attachments < $cfg['max_attachments'] || $auth->acl_gets('m_', 'a_', $forum_id))
{
- $filedata = upload_attachment($form_name, $forum_id, false, '', $is_message, false, $this->plupload);
+ $filedata = upload_attachment($form_name, $forum_id, false, '', $is_message, false, $this->mimetype_guesser, $this->plupload);
$error = array_merge($error, $filedata['error']);
if (!sizeof($error))
@@ -1792,4 +1798,16 @@ class parse_message extends bbcode_firstpass
{
$this->plupload = $plupload;
}
+
+ /**
+ * Setter function for passing the mimetype_guesser object
+ *
+ * @param \phpbb\mimetype\guesser $mimetype_guesser The mimetype_guesser object
+ *
+ * @return null
+ */
+ public function set_mimetype_guesser(\phpbb\mimetype\guesser $mimetype_guesser)
+ {
+ $this->mimetype_guesser = $mimetype_guesser;
+ }
}