diff options
Diffstat (limited to 'phpBB/phpbb')
| -rw-r--r-- | phpBB/phpbb/mimetype/guesser.php | 39 | ||||
| -rw-r--r-- | phpBB/phpbb/path_helper.php | 24 | 
2 files changed, 53 insertions, 10 deletions
| diff --git a/phpBB/phpbb/mimetype/guesser.php b/phpBB/phpbb/mimetype/guesser.php index 773a1f822a..8baa77089b 100644 --- a/phpBB/phpbb/mimetype/guesser.php +++ b/phpBB/phpbb/mimetype/guesser.php @@ -115,17 +115,42 @@ class guesser  			return false;  		} +		$mimetype = 'application/octet-stream'; +  		foreach ($this->guessers as $guesser)  		{ -			$mimetype = $guesser->guess($file, $file_name); +			$mimetype_guess = $guesser->guess($file, $file_name); -			// Try to guess something that is not the fallback application/octet-stream -			if ($mimetype !== null && $mimetype !== 'application/octet-stream') -			{ -				return $mimetype; -			} +			$mimetype = $this->choose_mime_type($mimetype, $mimetype_guess);  		}  		// Return any mimetype if we got a result or the fallback value -		return (!empty($mimetype)) ? $mimetype : 'application/octet-stream'; +		return $mimetype; +	} + +	/** +	 * Choose the best mime type based on the current mime type and the guess +	 * If a guesser returns nulls or application/octet-stream, we will keep +	 * the current guess. Guesses with a slash inside them will be favored over +	 * already existing ones. However, any guess that will pass the first check +	 * will always overwrite the default application/octet-stream. +	 * +	 * @param	string	$mime_type	The current mime type +	 * @param	string	$guess		The current mime type guess +	 * +	 * @return string The best mime type based on current mime type and guess +	 */ +	public function choose_mime_type($mime_type, $guess) +	{ +		if ($guess === null || $guess == 'application/octet-stream') +		{ +			return $mime_type; +		} + +		if ($mime_type == 'application/octet-stream' || strpos($guess, '/') !== false) +		{ +			$mime_type = $guess; +		} + +		return $mime_type;  	}  } diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php index 38dbbab51e..936564d8b6 100644 --- a/phpBB/phpbb/path_helper.php +++ b/phpBB/phpbb/path_helper.php @@ -316,7 +316,7 @@ class path_helper  	* Glue URL parameters together  	*  	* @param array $params URL parameters in the form of array(name => value) -	* @return string Returns the glued string, e.g. name1=value1&name2=value2 +	* @return string Returns the glued string, e.g. name1=value1&name2&name3=value3  	*/  	public function glue_url_params($params)  	{ @@ -324,7 +324,15 @@ class path_helper  		foreach ($params as $key => $value)  		{ -			$_params[] = $key . '=' . $value; +			// some parameters do not have value +			if ($value !== null) +			{ +				$_params[] = $key . '=' . $value; +			} +			else +			{ +				$_params[] = $key; +			}  		}  		return implode('&', $_params);  	} @@ -353,7 +361,17 @@ class path_helper  				{  					continue;  				} -				list($key, $value) = explode('=', $argument, 2); + +				// some parameters don't have value +				if (strpos($argument, '=') !== false) +				{ +					list($key, $value) = explode('=', $argument, 2); +				} +				else +				{ +					$key = $argument; +					$value = null; +				}  				if ($key === '')  				{ | 
