mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/16836] Use absolute paths in local adapter
PHPBB3-16836
This commit is contained in:
parent
f836605ab8
commit
fdb7c8a671
3 changed files with 60 additions and 18 deletions
|
@ -53,11 +53,22 @@ class local implements adapter_interface, stream_interface
|
|||
protected $phpbb_root_path;
|
||||
|
||||
/**
|
||||
* Absolute path to the storage folder
|
||||
* Always finish with DIRECTORY_SEPARATOR
|
||||
* Example:
|
||||
* - /var/www/phpBB/images/avatar/upload/
|
||||
* - C:\phpBB\images\avatars\upload\
|
||||
*
|
||||
* @var string path
|
||||
*/
|
||||
protected $root_path;
|
||||
|
||||
/**
|
||||
* Relative path from $phpbb_root_path to the storage folder
|
||||
* Always finish with slash (/) character
|
||||
* Example:
|
||||
* - images/avatars/upload/
|
||||
*
|
||||
* @var string path
|
||||
*/
|
||||
protected $path;
|
||||
|
@ -106,13 +117,14 @@ class local implements adapter_interface, stream_interface
|
|||
*/
|
||||
public function configure(array $options): void
|
||||
{
|
||||
if (substr($options['path'], -1, 1) !== DIRECTORY_SEPARATOR)
|
||||
$this->path = $options['path'];
|
||||
|
||||
if (substr($this->path, -1, 1) !== '/')
|
||||
{
|
||||
$options['path'] = $options['path'] . DIRECTORY_SEPARATOR;
|
||||
$this->path = $this->path . '/';
|
||||
}
|
||||
|
||||
$this->path = $options['path'];
|
||||
$this->root_path = $this->phpbb_root_path . $options['path'];
|
||||
$this->root_path = filesystem_helper::realpath($this->phpbb_root_path . $options['path']) . DIRECTORY_SEPARATOR;
|
||||
$this->subfolders = (bool) $options['subfolders'];
|
||||
}
|
||||
|
||||
|
@ -216,7 +228,7 @@ class local implements adapter_interface, stream_interface
|
|||
*
|
||||
* @throws exception On any directory creation failure
|
||||
*/
|
||||
protected function create_dir($path)
|
||||
protected function create_dir(string $path): void
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -232,12 +244,13 @@ class local implements adapter_interface, stream_interface
|
|||
* Ensures that the directory of a file exists.
|
||||
*
|
||||
* @param string $path The file path
|
||||
*
|
||||
* @throws exception On any directory creation failure
|
||||
*/
|
||||
protected function ensure_directory_exists($path)
|
||||
protected function ensure_directory_exists(string $path): void
|
||||
{
|
||||
$absolute_root_path = filesystem_helper::realpath($this->root_path) . DIRECTORY_SEPARATOR;
|
||||
$path = dirname($absolute_root_path . $this->get_path($path) . $this->get_filename($path));
|
||||
$path = filesystem_helper::make_path_relative($path, $absolute_root_path);
|
||||
$path = dirname($this->root_path . $this->get_path($path) . $this->get_filename($path));
|
||||
$path = filesystem_helper::make_path_relative($path, $this->root_path);
|
||||
|
||||
if (!$this->exists($path))
|
||||
{
|
||||
|
@ -250,7 +263,7 @@ class local implements adapter_interface, stream_interface
|
|||
*
|
||||
* @param string $path The file path
|
||||
*/
|
||||
protected function remove_empty_dirs($path)
|
||||
protected function remove_empty_dirs(string $path): void
|
||||
{
|
||||
if ($this->subfolders)
|
||||
{
|
||||
|
@ -275,7 +288,7 @@ class local implements adapter_interface, stream_interface
|
|||
* @param string $path The file path
|
||||
* @return string
|
||||
*/
|
||||
protected function get_path($path)
|
||||
protected function get_path(string $path): string
|
||||
{
|
||||
$dirname = dirname($path);
|
||||
$dirname = ($dirname != '.') ? $dirname . DIRECTORY_SEPARATOR : '';
|
||||
|
@ -302,7 +315,7 @@ class local implements adapter_interface, stream_interface
|
|||
* @param string $path The file path
|
||||
* @return string
|
||||
*/
|
||||
protected function get_filename($path)
|
||||
protected function get_filename(string $path): string
|
||||
{
|
||||
return basename($path);
|
||||
}
|
||||
|
@ -356,7 +369,7 @@ class local implements adapter_interface, stream_interface
|
|||
* @throws exception When cannot get size
|
||||
*
|
||||
*/
|
||||
public function file_size($path)
|
||||
public function file_size(string $path): array
|
||||
{
|
||||
$size = @filesize($this->root_path . $this->get_path($path) . $this->get_filename($path));
|
||||
|
||||
|
@ -375,7 +388,7 @@ class local implements adapter_interface, stream_interface
|
|||
*
|
||||
* @return array Properties
|
||||
*/
|
||||
public function file_mimetype($path)
|
||||
public function file_mimetype(string $path): array
|
||||
{
|
||||
return ['mimetype' => $this->mimetype_guesser->guess($this->root_path . $this->get_path($path) . $this->get_filename($path))];
|
||||
}
|
||||
|
@ -387,7 +400,7 @@ class local implements adapter_interface, stream_interface
|
|||
*
|
||||
* @return array Properties
|
||||
*/
|
||||
protected function image_dimensions($path)
|
||||
protected function image_dimensions(string $path): array
|
||||
{
|
||||
$size = $this->imagesize->getImageSize($this->root_path . $this->get_path($path) . $this->get_filename($path));
|
||||
|
||||
|
@ -408,7 +421,7 @@ class local implements adapter_interface, stream_interface
|
|||
*
|
||||
* @return array Properties
|
||||
*/
|
||||
public function file_image_width($path)
|
||||
public function file_image_width(string $path): array
|
||||
{
|
||||
return $this->image_dimensions($path);
|
||||
}
|
||||
|
@ -420,7 +433,7 @@ class local implements adapter_interface, stream_interface
|
|||
*
|
||||
* @return array Properties
|
||||
*/
|
||||
public function file_image_height($path): array
|
||||
public function file_image_height(string $path): array
|
||||
{
|
||||
return $this->image_dimensions($path);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ interface stream_interface
|
|||
* @param string $path File to read
|
||||
*
|
||||
* @return resource Returns a file pointer
|
||||
* @throws exception\exception When unable to open file
|
||||
* @throws exception When unable to open file
|
||||
*/
|
||||
public function read_stream(string $path);
|
||||
|
||||
|
|
29
tests/functional/acp_storage_test.php
Normal file
29
tests/functional/acp_storage_test.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group functional
|
||||
*/
|
||||
class phpbb_functional_acp_storage_test extends phpbb_functional_test_case
|
||||
{
|
||||
public function test_acp_storage_free_space()
|
||||
{
|
||||
$this->add_lang(['acp/common', 'acp/storage']);
|
||||
$this->login();
|
||||
$this->admin_login();
|
||||
|
||||
$crawler = self::request('GET', 'adm/index.php?i=acp_storage&mode=settings&sid=' . $this->sid);
|
||||
$this->assertContainsLang('STORAGE_TITLE', $this->get_content());
|
||||
$this->assertNotContainsLang('STORAGE_UNKNOWN', $crawler->filter('div#main div.main table.table1')->text());
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue