1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

Merge pull request #6687 from marc1706/ticket/12479

[ticket/12479] Remove deprecated functions
This commit is contained in:
Marc Alexander
2024-07-24 22:45:53 +02:00
committed by GitHub
25 changed files with 410 additions and 1341 deletions

View File

@@ -13,91 +13,116 @@
namespace phpbb;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use phpbb\exception\runtime_exception;
class file_downloader
{
const OK = 200;
const NOT_FOUND = 404;
const REQUEST_TIMEOUT = 408;
/** @var string Error string */
protected $error_string = '';
protected string $error_string = '';
/** @var int Error number */
protected $error_number = 0;
protected int $error_number = 0;
/**
* Create new guzzle client
*
* @param string $host
* @param int $port
* @param int $timeout
*
* @return Client
*/
protected function create_client(string $host, int $port = 443, int $timeout = 6): Client
{
// Only set URL scheme if not specified in URL
$url_parts = parse_url($host);
if (!isset($url_parts['scheme']))
{
$host = (($port === 443) ? 'https://' : 'http://') . $host;
}
// Initialize Guzzle client
return new Client([
'base_uri' => $host,
'timeout' => $timeout,
]);
}
/**
* Retrieve contents from remotely stored file
*
* @param string $host File host
* @param string $directory Directory file is in
* @param string $filename Filename of file to retrieve
* @param int $port Port to connect to; default: 80
* @param int $timeout Connection timeout in seconds; default: 6
* @param string $host File host
* @param string $directory Directory file is in
* @param string $filename Filename of file to retrieve
* @param int $port Port to connect to; default: 80
* @param int $timeout Connection timeout in seconds; default: 6
*
* @return false|string File data as string if file can be read and there is no
* timeout, false if there were errors or the connection timed out
* timeout, false if there were errors or the connection timed out
*
* @throws \phpbb\exception\runtime_exception If data can't be retrieved and no error
* message is returned
* @throws runtime_exception If data can't be retrieved and no error
* message is returned
*/
public function get($host, $directory, $filename, $port = 80, $timeout = 6)
public function get(string $host, string $directory, string $filename, int $port = 443, int $timeout = 6): bool|string
{
// Initialize Guzzle client
$client = $this->create_client($host, $port, $timeout);
// Set default values for error variables
$this->error_number = 0;
$this->error_string = '';
if (function_exists('fsockopen') &&
$socket = @fsockopen(($port == 443 ? 'ssl://' : '') . $host, $port, $this->error_number, $this->error_string, $timeout)
)
try
{
@fputs($socket, "GET $directory/$filename HTTP/1.0\r\n");
@fputs($socket, "HOST: $host\r\n");
@fputs($socket, "Connection: close\r\n\r\n");
$response = $client->request('GET', "$directory/$filename");
$timer_stop = time() + $timeout;
stream_set_timeout($socket, $timeout);
$file_info = '';
$get_info = false;
while (!@feof($socket))
// Check if the response status code is 200 (OK)
if ($response->getStatusCode() == self::OK)
{
if ($get_info)
{
$file_info .= @fread($socket, 1024);
}
else
{
$line = @fgets($socket, 1024);
if ($line == "\r\n")
{
$get_info = true;
}
else if (stripos($line, '404 not found') !== false)
{
throw new \phpbb\exception\runtime_exception('FILE_NOT_FOUND', array($filename));
}
}
$stream_meta_data = stream_get_meta_data($socket);
if ($stream_meta_data['timed_out'] || time() >= $timer_stop)
{
throw new \phpbb\exception\runtime_exception('FSOCK_TIMEOUT');
}
}
@fclose($socket);
}
else
{
if ($this->error_string)
{
$this->error_string = utf8_convert_message($this->error_string);
return false;
return $response->getBody()->getContents();
}
else
{
throw new \phpbb\exception\runtime_exception('FSOCK_DISABLED');
$this->error_number = $response->getStatusCode();
throw new runtime_exception('FILE_NOT_FOUND', [$filename]);
}
}
catch (RequestException $exception)
{
if ($exception->hasResponse())
{
$this->error_number = $exception->getResponse()->getStatusCode();
return $file_info;
if ($this->error_number == self::NOT_FOUND)
{
throw new runtime_exception('FILE_NOT_FOUND', [$filename]);
}
}
else
{
$this->error_number = self::REQUEST_TIMEOUT;
throw new runtime_exception('FSOCK_TIMEOUT');
}
$this->error_string = utf8_convert_message($exception->getMessage());
return false;
}
catch (runtime_exception $exception)
{
// Rethrow runtime_exceptions, only handle unknown cases below
throw $exception;
}
catch (\Throwable $exception)
{
$this->error_string = utf8_convert_message($exception->getMessage());
throw new runtime_exception('FSOCK_DISABLED');
}
}
/**
@@ -105,7 +130,7 @@ class file_downloader
*
* @return string Error string
*/
public function get_error_string()
public function get_error_string(): string
{
return $this->error_string;
}
@@ -115,7 +140,7 @@ class file_downloader
*
* @return int Error number
*/
public function get_error_number()
public function get_error_number(): int
{
return $this->error_number;
}

View File

@@ -398,7 +398,7 @@ class filespec
* @param bool $overwrite If set to true, an already existing file will be overwritten
* @param bool $skip_image_check If set to true, the check for the file to be a valid image is skipped
* @param string|bool $chmod Permission mask for chmodding the file after a successful move.
* The mode entered here reflects the mode defined by {@link phpbb_chmod()}
* The mode entered here reflects the mode defined by {@link \phpbb\filesystem\filesystem::phpbb_chmod()}
*
* @return bool True if file was moved, false if not
* @access public

View File

@@ -1,21 +0,0 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb;
/**
* @deprecated 3.2.0-dev (To be removed 4.0.0) use \phpbb\filesystem\filesystem instead
*/
class filesystem extends \phpbb\filesystem\filesystem
{
}

View File

@@ -1,175 +0,0 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\php;
/**
* Wrapper class for ini_get function.
*
* Provides easier handling of the different interpretations of ini values.
* @deprecated 3.2.10 (To be removed 4.0.0)
*/
class 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)
{
return ini_get($varname);
}
/**
* Gets the configuration option value as a trimmed string.
*
* @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 = $this->get_string($varname);
if (empty($value) || strtolower($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,
* false if configuration option value is not numeric,
* 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,
* false if configuration option value is not numeric,
* 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,
* false if configuration option value is not well-formed,
* the configuration option value otherwise.
*/
public function get_bytes($varname)
{
$value = $this->get_string($varname);
if ($value === false)
{
return false;
}
if (is_numeric($value))
{
// Already in bytes.
return phpbb_to_numeric($value);
}
else if (is_string($value))
{
if (strlen($value) < 2)
{
// Single character.
return false;
}
else if (strlen($value) < 3 && $value[0] === '-')
{
// Two characters but the first one is a minus.
return false;
}
}
$value_lower = strtolower($value);
$value_numeric = phpbb_to_numeric($value);
switch ($value_lower[strlen($value_lower) - 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;
}
}

View File

@@ -344,8 +344,9 @@ class plupload
}
$tmp_file = $this->temporary_filepath($upload['tmp_name']);
$filesystem = new \phpbb\filesystem\filesystem();
if (!phpbb_is_writable($this->temporary_directory) || !move_uploaded_file($upload['tmp_name'], $tmp_file))
if (!$filesystem->is_writable($this->temporary_directory) || !move_uploaded_file($upload['tmp_name'], $tmp_file))
{
$this->emit_error(103, 'PLUPLOAD_ERR_MOVE_UPLOADED');
}

View File

@@ -184,7 +184,7 @@ class request implements request_interface
* @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE)
* Specifies which super global should be used
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* @return mixed The value of $_REQUEST[$var_name] run through {@link type_cast_helper_interface::set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
public function variable($var_name, $default, $multibyte = false, $super_global = request_interface::REQUEST)
@@ -208,7 +208,7 @@ class request implements request_interface
* @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE)
* Specifies which super global should be used
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* @return mixed The value of $_REQUEST[$var_name] run through {@link type_cast_helper_interface::set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
public function untrimmed_variable($var_name, $default, $multibyte = false, $super_global = request_interface::REQUEST)
@@ -401,7 +401,7 @@ class request implements request_interface
* Specifies which super global should be used
* @param bool $trim Indicates whether trim() should be applied to string values.
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* @return mixed The value of $_REQUEST[$var_name] run through {@link type_cast_helper_interface::set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
protected function _variable($var_name, $default, $multibyte = false, $super_global = request_interface::REQUEST, $trim = true)

View File

@@ -59,7 +59,7 @@ interface request_interface
* @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE)
* Specifies which super global shall be changed
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* @return mixed The value of $_REQUEST[$var_name] run through {@link type_cast_helper_interface::set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
public function variable($var_name, $default, $multibyte = false, $super_global = request_interface::REQUEST);
@@ -81,7 +81,7 @@ interface request_interface
* @param int $super_global (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE)
* Specifies which super global shall be changed
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* @return mixed The value of $_REQUEST[$var_name] run through {@link type_cast_helper_interface::set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
public function raw_variable($var_name, $default, $super_global = request_interface::REQUEST);