aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorMateBartus <mate.bartus@gmail.com>2015-03-12 00:25:00 +0100
committerMateBartus <mate.bartus@gmail.com>2015-04-16 13:24:10 +0200
commit4bdef6fd21a5dcab455b0cd1ee2652de606929c3 (patch)
tree33eae92e90b43770b2c1e2e4508dbcf35d6bd7da /phpBB/includes
parentf86c5d905bb82967505ef3e07fa429b59c112871 (diff)
downloadforums-4bdef6fd21a5dcab455b0cd1ee2652de606929c3.tar
forums-4bdef6fd21a5dcab455b0cd1ee2652de606929c3.tar.gz
forums-4bdef6fd21a5dcab455b0cd1ee2652de606929c3.tar.bz2
forums-4bdef6fd21a5dcab455b0cd1ee2652de606929c3.tar.xz
forums-4bdef6fd21a5dcab455b0cd1ee2652de606929c3.zip
[ticket/13697] Moving filesystem related functions to filesystem service
* Moving filesystem service to \phpbb\filesystem namespace * Wraping Symfony's Filesystem component * Moving filesystem related functions from includes/functions.php into \phpbb\filesystem\filesystem Functions moved (and deprecated): - phpbb_chmod - phpbb_is_writable - phpbb_is_absolute - phpbb_own_realpath - phpbb_realpath * Adding interface for filesystem service PHPBB3-13697
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/acp/acp_attachments.php18
-rw-r--r--phpBB/includes/acp/acp_main.php4
-rw-r--r--phpBB/includes/bbcode.php6
-rw-r--r--phpBB/includes/compatibility_globals.php2
-rw-r--r--phpBB/includes/functions.php448
-rw-r--r--phpBB/includes/functions_acp.php4
-rw-r--r--phpBB/includes/functions_compatibility.php87
-rw-r--r--phpBB/includes/functions_compress.php69
-rw-r--r--phpBB/includes/functions_convert.php16
-rw-r--r--phpBB/includes/functions_install.php4
-rw-r--r--phpBB/includes/functions_messenger.php32
-rw-r--r--phpBB/includes/functions_posting.php15
-rw-r--r--phpBB/includes/functions_upload.php32
13 files changed, 254 insertions, 483 deletions
diff --git a/phpBB/includes/acp/acp_attachments.php b/phpBB/includes/acp/acp_attachments.php
index 78488b4048..7413152e7a 100644
--- a/phpBB/includes/acp/acp_attachments.php
+++ b/phpBB/includes/acp/acp_attachments.php
@@ -36,13 +36,16 @@ class acp_attachments
/** @var \phpbb\user */
protected $user;
+ /** @var \phpbb\filesystem\filesystem_interface */
+ protected $filesystem;
+
public $id;
public $u_action;
protected $new_config;
function main($id, $mode)
{
- global $db, $user, $auth, $template, $cache, $phpbb_container;
+ global $db, $user, $auth, $template, $cache, $phpbb_container, $phpbb_filesystem;
global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx, $phpbb_log, $request;
$this->id = $id;
@@ -51,6 +54,7 @@ class acp_attachments
$this->template = $template;
$this->user = $user;
$this->phpbb_container = $phpbb_container;
+ $this->filesystem = $phpbb_filesystem;
$user->add_lang(array('posting', 'viewtopic', 'acp/attachments'));
@@ -1501,7 +1505,15 @@ class acp_attachments
if (!file_exists($phpbb_root_path . $upload_dir))
{
@mkdir($phpbb_root_path . $upload_dir, 0777);
- phpbb_chmod($phpbb_root_path . $upload_dir, CHMOD_READ | CHMOD_WRITE);
+
+ try
+ {
+ $this->filesystem->phpbb_chmod($phpbb_root_path . $upload_dir, CHMOD_READ | CHMOD_WRITE);
+ }
+ catch (\phpbb\filesystem\exception\filesystem_exception $e)
+ {
+ // Do nothing
+ }
}
}
@@ -1517,7 +1529,7 @@ class acp_attachments
return;
}
- if (!phpbb_is_writable($phpbb_root_path . $upload_dir))
+ if (!$this->filesystem->is_writable($phpbb_root_path . $upload_dir))
{
$error[] = sprintf($user->lang['NO_WRITE_UPLOAD'], $upload_dir);
return;
diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php
index c49ccdf479..21c6edfccf 100644
--- a/phpBB/includes/acp/acp_main.php
+++ b/phpBB/includes/acp/acp_main.php
@@ -26,7 +26,7 @@ class acp_main
function main($id, $mode)
{
global $config, $db, $cache, $user, $auth, $template, $request, $phpbb_log;
- global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container, $phpbb_dispatcher;
+ global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container, $phpbb_dispatcher, $phpbb_filesystem;
// Show restore permissions notice
if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm'))
@@ -644,7 +644,7 @@ class acp_main
}
}
- if (!defined('PHPBB_DISABLE_CONFIG_CHECK') && file_exists($phpbb_root_path . 'config.' . $phpEx) && phpbb_is_writable($phpbb_root_path . 'config.' . $phpEx))
+ if (!defined('PHPBB_DISABLE_CONFIG_CHECK') && file_exists($phpbb_root_path . 'config.' . $phpEx) && $phpbb_filesystem->is_writable($phpbb_root_path . 'config.' . $phpEx))
{
// World-Writable? (000x)
$template->assign_var('S_WRITABLE_CONFIG', (bool) (@fileperms($phpbb_root_path . 'config.' . $phpEx) & 0x0002));
diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php
index ee911b5ec5..53675637a0 100644
--- a/phpBB/includes/bbcode.php
+++ b/phpBB/includes/bbcode.php
@@ -129,7 +129,7 @@ class bbcode
*/
function bbcode_cache_init()
{
- global $phpbb_root_path, $phpEx, $config, $user, $phpbb_dispatcher, $phpbb_extension_manager, $phpbb_path_helper, $phpbb_container;
+ global $phpbb_root_path, $phpEx, $config, $user, $phpbb_dispatcher, $phpbb_extension_manager, $phpbb_path_helper, $phpbb_container, $phpbb_filesystem;
if (empty($this->template_filename))
{
@@ -146,7 +146,9 @@ class bbcode
$phpbb_container,
$phpbb_container->getParameter('core.root_path') . 'cache/',
$phpbb_container->get('ext.manager'),
- new \phpbb\template\twig\loader()
+ new \phpbb\template\twig\loader(
+ $phpbb_filesystem
+ )
),
$phpbb_container->getParameter('core.root_path') . 'cache/',
$phpbb_container->get('template.twig.extensions.collection'),
diff --git a/phpBB/includes/compatibility_globals.php b/phpBB/includes/compatibility_globals.php
index b0919aefb3..5c18793655 100644
--- a/phpBB/includes/compatibility_globals.php
+++ b/phpBB/includes/compatibility_globals.php
@@ -48,7 +48,7 @@ $phpbb_log = $phpbb_container->get('log');
/* @var $symfony_request \phpbb\symfony_request */
$symfony_request = $phpbb_container->get('symfony_request');
-/* @var $phpbb_filesystem \phpbb\filesystem */
+/* @var $phpbb_filesystem \phpbb\filesystem\filesystem_interface */
$phpbb_filesystem = $phpbb_container->get('filesystem');
/* @var $phpbb_path_helper \phpbb\path_helper */
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 949d33c566..957b475616 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -311,448 +311,6 @@ function phpbb_version_compare($version1, $version2, $operator = null)
}
}
-/**
-* Global function for chmodding directories and files for internal use
-*
-* This function determines owner and group whom the file belongs to and user and group of PHP and then set safest possible file permissions.
-* The function determines owner and group from common.php file and sets the same to the provided file.
-* The function uses bit fields to build the permissions.
-* The function sets the appropiate execute bit on directories.
-*
-* Supported constants representing bit fields are:
-*
-* CHMOD_ALL - all permissions (7)
-* CHMOD_READ - read permission (4)
-* CHMOD_WRITE - write permission (2)
-* CHMOD_EXECUTE - execute permission (1)
-*
-* NOTE: The function uses POSIX extension and fileowner()/filegroup() functions. If any of them is disabled, this function tries to build proper permissions, by calling is_readable() and is_writable() functions.
-*
-* @param string $filename The file/directory to be chmodded
-* @param int $perms Permissions to set
-*
-* @return bool true on success, otherwise false
-*/
-function phpbb_chmod($filename, $perms = CHMOD_READ)
-{
- static $_chmod_info;
-
- // Return if the file no longer exists.
- if (!file_exists($filename))
- {
- return false;
- }
-
- // Determine some common vars
- if (empty($_chmod_info))
- {
- if (!function_exists('fileowner') || !function_exists('filegroup'))
- {
- // No need to further determine owner/group - it is unknown
- $_chmod_info['process'] = false;
- }
- else
- {
- global $phpbb_root_path, $phpEx;
-
- // Determine owner/group of common.php file and the filename we want to change here
- $common_php_owner = @fileowner($phpbb_root_path . 'common.' . $phpEx);
- $common_php_group = @filegroup($phpbb_root_path . 'common.' . $phpEx);
-
- // And the owner and the groups PHP is running under.
- $php_uid = (function_exists('posix_getuid')) ? @posix_getuid() : false;
- $php_gids = (function_exists('posix_getgroups')) ? @posix_getgroups() : false;
-
- // If we are unable to get owner/group, then do not try to set them by guessing
- if (!$php_uid || empty($php_gids) || !$common_php_owner || !$common_php_group)
- {
- $_chmod_info['process'] = false;
- }
- else
- {
- $_chmod_info = array(
- 'process' => true,
- 'common_owner' => $common_php_owner,
- 'common_group' => $common_php_group,
- 'php_uid' => $php_uid,
- 'php_gids' => $php_gids,
- );
- }
- }
- }
-
- if ($_chmod_info['process'])
- {
- $file_uid = @fileowner($filename);
- $file_gid = @filegroup($filename);
-
- // Change owner
- if (@chown($filename, $_chmod_info['common_owner']))
- {
- clearstatcache();
- $file_uid = @fileowner($filename);
- }
-
- // Change group
- if (@chgrp($filename, $_chmod_info['common_group']))
- {
- clearstatcache();
- $file_gid = @filegroup($filename);
- }
-
- // If the file_uid/gid now match the one from common.php we can process further, else we are not able to change something
- if ($file_uid != $_chmod_info['common_owner'] || $file_gid != $_chmod_info['common_group'])
- {
- $_chmod_info['process'] = false;
- }
- }
-
- // Still able to process?
- if ($_chmod_info['process'])
- {
- if ($file_uid == $_chmod_info['php_uid'])
- {
- $php = 'owner';
- }
- else if (in_array($file_gid, $_chmod_info['php_gids']))
- {
- $php = 'group';
- }
- else
- {
- // Since we are setting the everyone bit anyway, no need to do expensive operations
- $_chmod_info['process'] = false;
- }
- }
-
- // We are not able to determine or change something
- if (!$_chmod_info['process'])
- {
- $php = 'other';
- }
-
- // Owner always has read/write permission
- $owner = CHMOD_READ | CHMOD_WRITE;
- if (is_dir($filename))
- {
- $owner |= CHMOD_EXECUTE;
-
- // Only add execute bit to the permission if the dir needs to be readable
- if ($perms & CHMOD_READ)
- {
- $perms |= CHMOD_EXECUTE;
- }
- }
-
- switch ($php)
- {
- case 'owner':
- $result = @chmod($filename, ($owner << 6) + (0 << 3) + (0 << 0));
-
- clearstatcache();
-
- if (is_readable($filename) && phpbb_is_writable($filename))
- {
- break;
- }
-
- case 'group':
- $result = @chmod($filename, ($owner << 6) + ($perms << 3) + (0 << 0));
-
- clearstatcache();
-
- if ((!($perms & CHMOD_READ) || is_readable($filename)) && (!($perms & CHMOD_WRITE) || phpbb_is_writable($filename)))
- {
- break;
- }
-
- case 'other':
- $result = @chmod($filename, ($owner << 6) + ($perms << 3) + ($perms << 0));
-
- clearstatcache();
-
- if ((!($perms & CHMOD_READ) || is_readable($filename)) && (!($perms & CHMOD_WRITE) || phpbb_is_writable($filename)))
- {
- break;
- }
-
- default:
- return false;
- break;
- }
-
- return $result;
-}
-
-/**
-* Test if a file/directory is writable
-*
-* This function calls the native is_writable() when not running under
-* Windows and it is not disabled.
-*
-* @param string $file Path to perform write test on
-* @return bool True when the path is writable, otherwise false.
-*/
-function phpbb_is_writable($file)
-{
- if (strtolower(substr(PHP_OS, 0, 3)) === 'win' || !function_exists('is_writable'))
- {
- if (file_exists($file))
- {
- // Canonicalise path to absolute path
- $file = phpbb_realpath($file);
-
- if (is_dir($file))
- {
- // Test directory by creating a file inside the directory
- $result = @tempnam($file, 'i_w');
-
- if (is_string($result) && file_exists($result))
- {
- unlink($result);
-
- // Ensure the file is actually in the directory (returned realpathed)
- return (strpos($result, $file) === 0) ? true : false;
- }
- }
- else
- {
- $handle = @fopen($file, 'r+');
-
- if (is_resource($handle))
- {
- fclose($handle);
- return true;
- }
- }
- }
- else
- {
- // file does not exist test if we can write to the directory
- $dir = dirname($file);
-
- if (file_exists($dir) && is_dir($dir) && phpbb_is_writable($dir))
- {
- return true;
- }
- }
-
- return false;
- }
- else
- {
- return is_writable($file);
- }
-}
-
-/**
-* Checks if a path ($path) is absolute or relative
-*
-* @param string $path Path to check absoluteness of
-* @return boolean
-*/
-function phpbb_is_absolute($path)
-{
- return (isset($path[0]) && $path[0] == '/' || preg_match('#^[a-z]:[/\\\]#i', $path)) ? true : false;
-}
-
-/**
-* @author Chris Smith <chris@project-minerva.org>
-* @copyright 2006 Project Minerva Team
-* @param string $path The path which we should attempt to resolve.
-* @return mixed
-*/
-function phpbb_own_realpath($path)
-{
- global $request;
-
- // Now to perform funky shizzle
-
- // Switch to use UNIX slashes
- $path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
- $path_prefix = '';
-
- // Determine what sort of path we have
- if (phpbb_is_absolute($path))
- {
- $absolute = true;
-
- if ($path[0] == '/')
- {
- // Absolute path, *NIX style
- $path_prefix = '';
- }
- else
- {
- // Absolute path, Windows style
- // Remove the drive letter and colon
- $path_prefix = $path[0] . ':';
- $path = substr($path, 2);
- }
- }
- else
- {
- // Relative Path
- // Prepend the current working directory
- if (function_exists('getcwd'))
- {
- // This is the best method, hopefully it is enabled!
- $path = str_replace(DIRECTORY_SEPARATOR, '/', getcwd()) . '/' . $path;
- $absolute = true;
- if (preg_match('#^[a-z]:#i', $path))
- {
- $path_prefix = $path[0] . ':';
- $path = substr($path, 2);
- }
- else
- {
- $path_prefix = '';
- }
- }
- else if ($request->server('SCRIPT_FILENAME'))
- {
- // Warning: If chdir() has been used this will lie!
- // Warning: This has some problems sometime (CLI can create them easily)
- $filename = htmlspecialchars_decode($request->server('SCRIPT_FILENAME'));
- $path = str_replace(DIRECTORY_SEPARATOR, '/', dirname($filename)) . '/' . $path;
- $absolute = true;
- $path_prefix = '';
- }
- else
- {
- // We have no way of getting the absolute path, just run on using relative ones.
- $absolute = false;
- $path_prefix = '.';
- }
- }
-
- // Remove any repeated slashes
- $path = preg_replace('#/{2,}#', '/', $path);
-
- // Remove the slashes from the start and end of the path
- $path = trim($path, '/');
-
- // Break the string into little bits for us to nibble on
- $bits = explode('/', $path);
-
- // Remove any . in the path, renumber array for the loop below
- $bits = array_values(array_diff($bits, array('.')));
-
- // Lets get looping, run over and resolve any .. (up directory)
- for ($i = 0, $max = sizeof($bits); $i < $max; $i++)
- {
- // @todo Optimise
- if ($bits[$i] == '..' )
- {
- if (isset($bits[$i - 1]))
- {
- if ($bits[$i - 1] != '..')
- {
- // We found a .. and we are able to traverse upwards, lets do it!
- unset($bits[$i]);
- unset($bits[$i - 1]);
- $i -= 2;
- $max -= 2;
- $bits = array_values($bits);
- }
- }
- else if ($absolute) // ie. !isset($bits[$i - 1]) && $absolute
- {
- // We have an absolute path trying to descend above the root of the filesystem
- // ... Error!
- return false;
- }
- }
- }
-
- // Prepend the path prefix
- array_unshift($bits, $path_prefix);
-
- $resolved = '';
-
- $max = sizeof($bits) - 1;
-
- // Check if we are able to resolve symlinks, Windows (prior to Vista and Server 2008) cannot.
- $symlink_resolve = (function_exists('readlink')) ? true : false;
-
- foreach ($bits as $i => $bit)
- {
- if (@is_dir("$resolved/$bit") || ($i == $max && @is_file("$resolved/$bit")))
- {
- // Path Exists
- if ($symlink_resolve && is_link("$resolved/$bit") && ($link = readlink("$resolved/$bit")))
- {
- // Resolved a symlink.
- $resolved = $link . (($i == $max) ? '' : '/');
- continue;
- }
- }
- else
- {
- // Something doesn't exist here!
- // This is correct realpath() behaviour but sadly open_basedir and safe_mode make this problematic
- // return false;
- }
- $resolved .= $bit . (($i == $max) ? '' : '/');
- }
-
- // @todo If the file exists fine and open_basedir only has one path we should be able to prepend it
- // because we must be inside that basedir, the question is where...
- // @internal The slash in is_dir() gets around an open_basedir restriction
- if (!@file_exists($resolved) || (!@is_dir($resolved . '/') && !is_file($resolved)))
- {
- return false;
- }
-
- // Put the slashes back to the native operating systems slashes
- $resolved = str_replace('/', DIRECTORY_SEPARATOR, $resolved);
-
- // Check for DIRECTORY_SEPARATOR at the end (and remove it!)
- if (substr($resolved, -1) == DIRECTORY_SEPARATOR)
- {
- return substr($resolved, 0, -1);
- }
-
- return $resolved; // We got here, in the end!
-}
-
-if (!function_exists('realpath'))
-{
- /**
- * A wrapper for realpath
- * @ignore
- */
- function phpbb_realpath($path)
- {
- return phpbb_own_realpath($path);
- }
-}
-else
-{
- /**
- * A wrapper for realpath
- */
- function phpbb_realpath($path)
- {
- $realpath = realpath($path);
-
- // Strangely there are provider not disabling realpath but returning strange values. :o
- // We at least try to cope with them.
- if ($realpath === $path || $realpath === false)
- {
- return phpbb_own_realpath($path);
- }
-
- // Check for DIRECTORY_SEPARATOR at the end (and remove it!)
- if (substr($realpath, -1) == DIRECTORY_SEPARATOR)
- {
- $realpath = substr($realpath, 0, -1);
- }
-
- return $realpath;
- }
-}
-
// functions used for building option fields
/**
@@ -1029,7 +587,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
/**
* This event is used for performing actions directly before marking forums,
* topics or posts as read.
- *
+ *
* It is also possible to prevent the marking. For that, the $should_markread parameter
* should be set to FALSE.
*
@@ -3913,11 +3471,13 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
*/
function phpbb_filter_root_path($errfile)
{
+ global $phpbb_filesystem;
+
static $root_path;
if (empty($root_path))
{
- $root_path = phpbb_realpath(dirname(__FILE__) . '/../');
+ $root_path = $phpbb_filesystem->realpath(dirname(__FILE__) . '/../');
}
return str_replace(array($root_path, '\\'), array('[ROOT]', '/'), $errfile);
diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php
index a53a54368e..6d59b513af 100644
--- a/phpBB/includes/functions_acp.php
+++ b/phpBB/includes/functions_acp.php
@@ -405,7 +405,7 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)
*/
function validate_config_vars($config_vars, &$cfg_array, &$error)
{
- global $phpbb_root_path, $user, $phpbb_dispatcher;
+ global $phpbb_root_path, $user, $phpbb_dispatcher, $phpbb_filesystem;
$type = 0;
$min = 1;
@@ -586,7 +586,7 @@ function validate_config_vars($config_vars, &$cfg_array, &$error)
// Check if the path is writable
if ($config_definition['validate'] == 'wpath' || $config_definition['validate'] == 'rwpath' || $config_definition['validate'] === 'absolute_path_writable')
{
- if (file_exists($path) && !phpbb_is_writable($path))
+ if (file_exists($path) && !$phpbb_filesystem->is_writable($path))
{
$error[] = sprintf($user->lang['DIRECTORY_NOT_WRITABLE'], $cfg_array[$config_name]);
}
diff --git a/phpBB/includes/functions_compatibility.php b/phpBB/includes/functions_compatibility.php
index 4707238951..2d064e37cb 100644
--- a/phpBB/includes/functions_compatibility.php
+++ b/phpBB/includes/functions_compatibility.php
@@ -117,7 +117,7 @@ function phpbb_clean_path($path)
new phpbb\symfony_request(
$request
),
- new phpbb\filesystem(),
+ new phpbb\filesystem\filesystem(),
$request,
$phpbb_root_path,
$phpEx
@@ -397,3 +397,88 @@ function get_tables(&$db)
return $db_tools->sql_list_tables();
}
+
+/**
+ * Global function for chmodding directories and files for internal use
+ *
+ * This function determines owner and group whom the file belongs to and user and group of PHP and then set safest possible file permissions.
+ * The function determines owner and group from common.php file and sets the same to the provided file.
+ * The function uses bit fields to build the permissions.
+ * The function sets the appropiate execute bit on directories.
+ *
+ * Supported constants representing bit fields are:
+ *
+ * CHMOD_ALL - all permissions (7)
+ * CHMOD_READ - read permission (4)
+ * CHMOD_WRITE - write permission (2)
+ * CHMOD_EXECUTE - execute permission (1)
+ *
+ * NOTE: The function uses POSIX extension and fileowner()/filegroup() functions. If any of them is disabled, this function tries to build proper permissions, by calling is_readable() and is_writable() functions.
+ *
+ * @param string $filename The file/directory to be chmodded
+ * @param int $perms Permissions to set
+ *
+ * @return bool true on success, otherwise false
+ *
+ * @deprecated 3.2.0-dev use \phpbb\filesystem\filesystem::phpbb_chmod() instead
+ */
+function phpbb_chmod($filename, $perms = CHMOD_READ)
+{
+ global $phpbb_filesystem;
+
+ try
+ {
+ $phpbb_filesystem->phpbb_chmod($filename, $perms);
+ }
+ catch (\phpbb\filesystem\exception\filesystem_exception $e)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Test if a file/directory is writable
+ *
+ * This function calls the native is_writable() when not running under
+ * Windows and it is not disabled.
+ *
+ * @param string $file Path to perform write test on
+ * @return bool True when the path is writable, otherwise false.
+ *
+ * @deprecated 3.2.0-dev use \phpbb\filesystem\filesystem::is_writable() instead
+ */
+function phpbb_is_writable($file)
+{
+ global $phpbb_filesystem;
+
+ return $phpbb_filesystem->is_writable($file);
+}
+
+/**
+ * Checks if a path ($path) is absolute or relative
+ *
+ * @param string $path Path to check absoluteness of
+ * @return boolean
+ *
+ * @deprecated 3.2.0-dev use \phpbb\filesystem\filesystem::is_absolute_path() instead
+ */
+function phpbb_is_absolute($path)
+{
+ global $phpbb_filesystem;
+
+ return $phpbb_filesystem->is_absolute_path($path);
+}
+
+/**
+ * A wrapper for realpath
+ *
+ * @deprecated 3.2.0-dev use \phpbb\filesystem\filesystem::realpath() instead
+ */
+function phpbb_realpath($path)
+{
+ global $phpbb_filesystem;
+
+ return $phpbb_filesystem->realpath($path);
+}
diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php
index a7ee29dd91..e768a0f47b 100644
--- a/phpBB/includes/functions_compress.php
+++ b/phpBB/includes/functions_compress.php
@@ -184,7 +184,7 @@ class compress
}
/**
-* Zip creation class from phpMyAdmin 2.3.0 (c) Tobias Ratschiller, Olivier Müller, Loïc Chapeaux,
+* Zip creation class from phpMyAdmin 2.3.0 (c) Tobias Ratschiller, Olivier Müller, Loïc Chapeaux,
* Marc Delisle, http://www.phpmyadmin.net/
*
* Zip extraction function by Alexandre Tedeschi, alexandrebr at gmail dot com
@@ -204,11 +204,19 @@ class compress_zip extends compress
var $datasec_len = 0;
/**
+ * @var \phpbb\filesystem\filesystem_interface
+ */
+ protected $filesystem;
+
+ /**
* Constructor
*/
function compress_zip($mode, $file)
{
+ global $phpbb_filesystem;
+
$this->fp = @fopen($file, $mode . 'b');
+ $this->filesystem = ($phpbb_filesystem instanceof \phpbb\filesystem\filesystem_interface) ? $phpbb_filesystem : new \phpbb\filesystem\filesystem();
if (!$this->fp)
{
@@ -286,7 +294,15 @@ class compress_zip extends compress
{
trigger_error("Could not create directory $folder");
}
- phpbb_chmod($str, CHMOD_READ | CHMOD_WRITE);
+
+ try
+ {
+ $this->filesystem->phpbb_chmod($str, CHMOD_READ | CHMOD_WRITE);
+ }
+ catch (\phpbb\filesystem\exception\filesystem_exception $e)
+ {
+ // Do nothing
+ }
}
}
}
@@ -315,7 +331,15 @@ class compress_zip extends compress
{
trigger_error("Could not create directory $folder");
}
- phpbb_chmod($str, CHMOD_READ | CHMOD_WRITE);
+
+ try
+ {
+ $this->filesystem->phpbb_chmod($str, CHMOD_READ | CHMOD_WRITE);
+ }
+ catch (\phpbb\filesystem\exception\filesystem_exception $e)
+ {
+ // Do nothing
+ }
}
}
}
@@ -539,10 +563,17 @@ class compress_tar extends compress
var $wrote = false;
/**
+ * @var \phpbb\filesystem\filesystem_interface
+ */
+ protected $filesystem;
+
+ /**
* Constructor
*/
function compress_tar($mode, $file, $type = '')
{
+ global $phpbb_filesystem;
+
$type = (!$type) ? $file : $type;
$this->isgz = preg_match('#(\.tar\.gz|\.tgz)$#', $type);
$this->isbz = preg_match('#\.tar\.bz2$#', $type);
@@ -551,6 +582,8 @@ class compress_tar extends compress
$this->file = &$file;
$this->type = &$type;
$this->open();
+
+ $this->filesystem = ($phpbb_filesystem instanceof \phpbb\filesystem\filesystem_interface) ? $phpbb_filesystem : new \phpbb\filesystem\filesystem();
}
/**
@@ -601,7 +634,15 @@ class compress_tar extends compress
{
trigger_error("Could not create directory $folder");
}
- phpbb_chmod($str, CHMOD_READ | CHMOD_WRITE);
+
+ try
+ {
+ $this->filesystem->phpbb_chmod($str, CHMOD_READ | CHMOD_WRITE);
+ }
+ catch (\phpbb\filesystem\exception\filesystem_exception $e)
+ {
+ // Do nothing
+ }
}
}
}
@@ -628,7 +669,15 @@ class compress_tar extends compress
{
trigger_error("Could not create directory $folder");
}
- phpbb_chmod($str, CHMOD_READ | CHMOD_WRITE);
+
+ try
+ {
+ $this->filesystem->phpbb_chmod($str, CHMOD_READ | CHMOD_WRITE);
+ }
+ catch (\phpbb\filesystem\exception\filesystem_exception $e)
+ {
+ // Do nothing
+ }
}
}
@@ -637,7 +686,15 @@ class compress_tar extends compress
{
trigger_error("Couldn't create file $filename");
}
- phpbb_chmod($target_filename, CHMOD_READ);
+
+ try
+ {
+ $this->filesystem->phpbb_chmod($target_filename, CHMOD_READ);
+ }
+ catch (\phpbb\filesystem\exception\filesystem_exception $e)
+ {
+ // Do nothing
+ }
// Grab the file contents
fwrite($fp, ($filesize) ? $fzread($this->fp, ($filesize + 511) &~ 511) : '', $filesize);
diff --git a/phpBB/includes/functions_convert.php b/phpBB/includes/functions_convert.php
index ea7816077d..ad693f4019 100644
--- a/phpBB/includes/functions_convert.php
+++ b/phpBB/includes/functions_convert.php
@@ -2316,7 +2316,10 @@ function convert_bbcode($message, $convert_size = true, $extended_bbcodes = fals
function copy_file($src, $trg, $overwrite = false, $die_on_failure = true, $source_relative_path = true)
{
- global $convert, $phpbb_root_path, $config, $user, $db;
+ global $convert, $phpbb_root_path, $config, $user, $db, $phpbb_filesystem;
+
+ /** @var \phpbb\filesystem\filesystem_interface $filesystem */
+ $filesystem = $phpbb_filesystem;
if (substr($trg, -1) == '/')
{
@@ -2349,7 +2352,7 @@ function copy_file($src, $trg, $overwrite = false, $die_on_failure = true, $sour
}
}
- if (!phpbb_is_writable($path))
+ if (!$filesystem->is_writable($path))
{
@chmod($path, 0777);
}
@@ -2370,7 +2373,10 @@ function copy_file($src, $trg, $overwrite = false, $die_on_failure = true, $sour
function copy_dir($src, $trg, $copy_subdirs = true, $overwrite = false, $die_on_failure = true, $source_relative_path = true)
{
- global $convert, $phpbb_root_path, $config, $user, $db;
+ global $convert, $phpbb_root_path, $config, $user, $db, $phpbb_filesystem;
+
+ /** @var \phpbb\filesystem\filesystem_interface $filesystem */
+ $filesystem = $phpbb_filesystem;
$dirlist = $filelist = $bad_dirs = array();
$src = path($src, $source_relative_path);
@@ -2384,7 +2390,7 @@ function copy_dir($src, $trg, $copy_subdirs = true, $overwrite = false, $die_on_
@chmod($trg_path, 0777);
}
- if (!phpbb_is_writable($trg_path))
+ if (!$filesystem->is_writable($trg_path))
{
$bad_dirs[] = path($config['script_path']) . $trg;
}
@@ -2451,7 +2457,7 @@ function copy_dir($src, $trg, $copy_subdirs = true, $overwrite = false, $die_on_
@chmod($trg_path . $dir, 0777);
}
- if (!phpbb_is_writable($trg_path . $dir))
+ if (!$filesystem->is_writable($trg_path . $dir))
{
$bad_dirs[] = $trg . $dir;
$bad_dirs[] = $trg_path . $dir;
diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php
index 8dacd25230..d9d073e984 100644
--- a/phpBB/includes/functions_install.php
+++ b/phpBB/includes/functions_install.php
@@ -189,7 +189,7 @@ function dbms_select($default = '', $only_20x_options = false)
*/
function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix, $dbhost, $dbuser, $dbpasswd, $dbname, $dbport, $prefix_may_exist = false, $load_dbal = true, $unicode_check = true)
{
- global $phpbb_root_path, $phpEx, $config, $lang;
+ global $phpbb_root_path, $phpEx, $config, $lang, $phpbb_filesystem;
$dbms = $dbms_details['DRIVER'];
@@ -205,7 +205,7 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
}
// Make sure we don't have a daft user who thinks having the SQLite database in the forum directory is a good idea
- if (($dbms_details['DRIVER'] == 'phpbb\db\driver\sqlite' || $dbms_details['DRIVER'] == 'phpbb\db\driver\sqlite3') && stripos(phpbb_realpath($dbhost), phpbb_realpath('../')) === 0)
+ if (($dbms_details['DRIVER'] == 'phpbb\db\driver\sqlite' || $dbms_details['DRIVER'] == 'phpbb\db\driver\sqlite3') && stripos($phpbb_filesystem->realpath($dbhost), $phpbb_filesystem->realpath('../')) === 0)
{
$error[] = $lang['INST_ERR_DB_FORUM_PATH'];
return false;
diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php
index 3aa3f3d03f..b0861585ba 100644
--- a/phpBB/includes/functions_messenger.php
+++ b/phpBB/includes/functions_messenger.php
@@ -623,7 +623,7 @@ class messenger
*/
protected function setup_template()
{
- global $config, $phpbb_path_helper, $user, $phpbb_extension_manager, $phpbb_container;
+ global $config, $phpbb_path_helper, $user, $phpbb_extension_manager, $phpbb_container, $phpbb_filesystem;
if ($this->template instanceof \phpbb\template\template)
{
@@ -641,7 +641,9 @@ class messenger
$phpbb_container,
$phpbb_container->getParameter('core.root_path') . 'cache/',
$phpbb_container->get('ext.manager'),
- new \phpbb\template\twig\loader()
+ new \phpbb\template\twig\loader(
+ $phpbb_filesystem
+ )
),
$phpbb_container->getParameter('core.root_path') . 'cache/',
$phpbb_container->get('template.twig.extensions.collection'),
@@ -672,14 +674,20 @@ class queue
var $eol = "\n";
/**
+ * @var \phpbb\filesystem\filesystem_interface
+ */
+ protected $filesystem;
+
+ /**
* constructor
*/
function queue()
{
- global $phpEx, $phpbb_root_path;
+ global $phpEx, $phpbb_root_path, $phpbb_filesystem;
$this->data = array();
$this->cache_file = "{$phpbb_root_path}cache/queue.$phpEx";
+ $this->filesystem = $phpbb_filesystem;
}
/**
@@ -865,7 +873,14 @@ class queue
fwrite($fp, "<?php\nif (!defined('IN_PHPBB')) exit;\n\$this->queue_data = unserialize(" . var_export(serialize($this->queue_data), true) . ");\n\n?>");
fclose($fp);
- phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE);
+ try
+ {
+ $this->filesystem->phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE);
+ }
+ catch (\phpbb\filesystem\exception\filesystem_exception $e)
+ {
+ // Do nothing
+ }
}
}
@@ -907,7 +922,14 @@ class queue
fwrite($fp, "<?php\nif (!defined('IN_PHPBB')) exit;\n\$this->queue_data = unserialize(" . var_export(serialize($this->data), true) . ");\n\n?>");
fclose($fp);
- phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE);
+ try
+ {
+ $this->filesystem->phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE);
+ }
+ catch (\phpbb\filesystem\exception\filesystem_exception $e)
+ {
+ // Do nothing
+ }
}
$lock->release();
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index 9c6ddffe9f..4233395574 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -407,14 +407,14 @@ function posting_gen_topic_types($forum_id, $cur_topic_type = POST_NORMAL)
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;
+ global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $phpbb_filesystem;
$filedata = array(
'error' => array()
);
include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx);
- $upload = new fileupload();
+ $upload = new fileupload($phpbb_filesystem);
if ($config['check_attachment_content'] && isset($config['mime_triggers']))
{
@@ -668,7 +668,7 @@ function get_supported_image_types($type = false)
*/
function create_thumbnail($source, $destination, $mimetype)
{
- global $config;
+ global $config, $phpbb_filesystem;
$min_filesize = (int) $config['img_min_thumb_filesize'];
$img_filesize = (file_exists($source)) ? @filesize($source) : false;
@@ -820,7 +820,14 @@ function create_thumbnail($source, $destination, $mimetype)
return false;
}
- phpbb_chmod($destination, CHMOD_READ | CHMOD_WRITE);
+ try
+ {
+ $this->filesystem->phpbb_chmod($destination, CHMOD_READ | CHMOD_WRITE);
+ }
+ catch (\phpbb\filesystem\exception\filesystem_exception $e)
+ {
+ // Do nothing
+ }
return true;
}
diff --git a/phpBB/includes/functions_upload.php b/phpBB/includes/functions_upload.php
index f179b2fd70..21a6de7a41 100644
--- a/phpBB/includes/functions_upload.php
+++ b/phpBB/includes/functions_upload.php
@@ -47,6 +47,11 @@ class filespec
var $upload = '';
/**
+ * @var \phpbb\filesystem\filesystem_interface
+ */
+ protected $filesystem;
+
+ /**
* The plupload object
* @var \phpbb\plupload\plupload
*/
@@ -62,7 +67,7 @@ class filespec
* File Class
* @access private
*/
- function filespec($upload_ary, $upload_namespace, \phpbb\mimetype\guesser $mimetype_guesser = null, \phpbb\plupload\plupload $plupload = null)
+ function filespec($upload_ary, $upload_namespace, \phpbb\filesystem\filesystem_interface $phpbb_filesystem, \phpbb\mimetype\guesser $mimetype_guesser = null, \phpbb\plupload\plupload $plupload = null)
{
if (!isset($upload_ary))
{
@@ -97,6 +102,7 @@ class filespec
$this->upload = $upload_namespace;
$this->plupload = $plupload;
$this->mimetype_guesser = $mimetype_guesser;
+ $this->filesystem = $phpbb_filesystem;
}
/**
@@ -374,7 +380,14 @@ class filespec
return false;
}
- phpbb_chmod($this->destination_file, $chmod);
+ try
+ {
+ $this->filesystem->phpbb_chmod($this->destination_file, $chmod);
+ }
+ catch (\phpbb\filesystem\exception\filesystem_exception $e)
+ {
+ // Do nothing
+ }
}
// Try to get real filesize from destination folder
@@ -500,8 +513,14 @@ class fileupload
var $upload_timeout = 6;
/**
+ * @var \phpbb\filesystem\filesystem_interface
+ */
+ protected $filesystem;
+
+ /**
* Init file upload class.
*
+ * @param \phpbb\filesystem\filesystem_interface $filesystem
* @param string $error_prefix Used error messages will get prefixed by this string
* @param array $allowed_extensions Array of allowed extensions, for example array('jpg', 'jpeg', 'gif', 'png')
* @param int $max_filesize Maximum filesize
@@ -513,13 +532,14 @@ class fileupload
* contain any of its values. Defaults to false.
*
*/
- function fileupload($error_prefix = '', $allowed_extensions = false, $max_filesize = false, $min_width = false, $min_height = false, $max_width = false, $max_height = false, $disallowed_content = false)
+ function fileupload(\phpbb\filesystem\filesystem_interface $filesystem, $error_prefix = '', $allowed_extensions = false, $max_filesize = false, $min_width = false, $min_height = false, $max_width = false, $max_height = false, $disallowed_content = false)
{
$this->set_allowed_extensions($allowed_extensions);
$this->set_max_filesize($max_filesize);
$this->set_allowed_dimensions($min_width, $min_height, $max_width, $max_height);
$this->set_error_prefix($error_prefix);
$this->set_disallowed_content($disallowed_content);
+ $this->filesystem = $filesystem;
}
/**
@@ -613,7 +633,7 @@ class fileupload
}
}
- $file = new filespec($upload, $this, $mimetype_guesser, $plupload);
+ $file = new filespec($upload, $this, $this->filesystem, $mimetype_guesser, $plupload);
if ($file->init_error)
{
@@ -694,7 +714,7 @@ class fileupload
$upload['type'] = $filedata['type'];
}
- $file = new filespec($upload, $this, $mimetype_guesser);
+ $file = new filespec($upload, $this, $this->filesystem, $mimetype_guesser);
if ($file->init_error)
{
@@ -932,7 +952,7 @@ class fileupload
$upload_ary['tmp_name'] = $filename;
- $file = new filespec($upload_ary, $this, $mimetype_guesser);
+ $file = new filespec($upload_ary, $this, $this->filesystem, $mimetype_guesser);
$this->common_checks($file);
return $file;