2012-06-11 13:18:00 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package phpBB
|
|
|
|
* @copyright (c) 2011 phpBB Group
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
if (!defined('IN_PHPBB'))
|
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper class for ini_get function.
|
|
|
|
*
|
|
|
|
* Provides easier handling of the different interpretations of ini values.
|
|
|
|
*
|
|
|
|
* @package phpBB
|
|
|
|
*/
|
|
|
|
class phpbb_php_ini
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Simple wrapper for ini_get()
|
|
|
|
* See http://php.net/manual/en/function.ini-get.php
|
|
|
|
*
|
|
|
|
* @param string $varname The configuration option name.
|
|
|
|
* @return bool|string False if configuration option does not exist,
|
|
|
|
* the configuration option value (string) otherwise.
|
|
|
|
*/
|
|
|
|
public function get($varname)
|
|
|
|
{
|
2012-06-11 13:40:14 +02:00
|
|
|
return ini_get($varname);
|
2012-06-11 13:18:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-11 13:45:39 +02:00
|
|
|
* Gets the configuration option value as a trimmed string.
|
2012-06-11 13:18:00 +02:00
|
|
|
*
|
|
|
|
* @param string $varname The configuration option name.
|
|
|
|
* @return bool|string False if configuration option does not exist,
|
|
|
|
* the configuration option value (string) otherwise.
|
|
|
|
*/
|
|
|
|
public function get_string($varname)
|
|
|
|
{
|
|
|
|
$value = $this->get($varname);
|
|
|
|
|
|
|
|
if ($value === false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return trim($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets configuration option value as a boolean.
|
|
|
|
* Interprets the string value 'off' as false.
|
|
|
|
*
|
|
|
|
* @param string $varname The configuration option name.
|
|
|
|
* @return bool False if configuration option does not exist.
|
|
|
|
* False if configuration option is disabled.
|
|
|
|
* True otherwise.
|
|
|
|
*/
|
|
|
|
public function get_bool($varname)
|
|
|
|
{
|
|
|
|
$value = strtolower($this->get_string($varname));
|
|
|
|
|
|
|
|
if (empty($value) || $value == 'off')
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets configuration option value as an integer.
|
|
|
|
*
|
|
|
|
* @param string $varname The configuration option name.
|
|
|
|
* @return bool|int False if configuration option does not exist,
|
2012-06-11 13:53:17 +02:00
|
|
|
* false if configuration option value is not numeric,
|
2012-06-11 13:18:00 +02:00
|
|
|
* the configuration option value (integer) otherwise.
|
|
|
|
*/
|
|
|
|
public function get_int($varname)
|
|
|
|
{
|
|
|
|
$value = $this->get_string($varname);
|
|
|
|
|
|
|
|
if (!is_numeric($value))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int) $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets configuration option value as a float.
|
|
|
|
*
|
|
|
|
* @param string $varname The configuration option name.
|
|
|
|
* @return bool|float False if configuration option does not exist,
|
2012-06-11 13:53:17 +02:00
|
|
|
* false if configuration option value is not numeric,
|
2012-06-11 13:18:00 +02:00
|
|
|
* the configuration option value (float) otherwise.
|
|
|
|
*/
|
|
|
|
public function get_float($varname)
|
|
|
|
{
|
|
|
|
$value = $this->get_string($varname);
|
|
|
|
|
|
|
|
if (!is_numeric($value))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (float) $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets configuration option value in bytes.
|
|
|
|
* Converts strings like '128M' to bytes (integer or float).
|
|
|
|
*
|
|
|
|
* @param string $varname The configuration option name.
|
|
|
|
* @return bool|int|float False if configuration option does not exist,
|
2012-06-11 13:53:17 +02:00
|
|
|
* false if configuration option value is not well-formed,
|
2012-06-11 13:18:00 +02:00
|
|
|
* the configuration option value otherwise.
|
|
|
|
*/
|
|
|
|
public function get_bytes($varname)
|
|
|
|
{
|
|
|
|
$value = strtolower($this->get_string($varname));
|
|
|
|
|
|
|
|
if ($value === false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_numeric($value))
|
|
|
|
{
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
else if (strlen($value) < 2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$value_numeric = (int) $value;
|
|
|
|
|
|
|
|
switch ($value[strlen($value) - 1])
|
|
|
|
{
|
|
|
|
case 'g':
|
|
|
|
$value_numeric *= 1024;
|
|
|
|
case 'm':
|
|
|
|
$value_numeric *= 1024;
|
|
|
|
case 'k':
|
|
|
|
$value_numeric *= 1024;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// It's not already in bytes (and thus numeric)
|
|
|
|
// and does not carry a unit.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value_numeric;
|
|
|
|
}
|
|
|
|
}
|