1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-17 22:11:26 +02:00

Merge branch 'master' into ticket/12629

This commit is contained in:
Marc Alexander
2018-10-26 10:16:04 +02:00
committed by GitHub
114 changed files with 1902 additions and 967 deletions

View File

@@ -99,6 +99,8 @@ class delete
$this->set_sql_constraints($mode);
$sql_id = $this->sql_id;
/**
* Perform additional actions before collecting data for attachment(s) deletion
*
@@ -117,11 +119,21 @@ class delete
);
extract($this->dispatcher->trigger_event('core.delete_attachments_collect_data_before', compact($vars)));
$this->sql_id = $sql_id;
unset($sql_id);
// Collect post and topic ids for later use if we need to touch remaining entries (if resync is enabled)
$this->collect_attachment_info($resync);
// Delete attachments from database
$this->delete_attachments_from_db();
$this->delete_attachments_from_db($mode, $ids, $resync);
$sql_id = $this->sql_id;
$post_ids = $this->post_ids;
$topic_ids = $this->topic_ids;
$message_ids = $this->message_ids;
$physical = $this->physical;
$num_deleted = $this->num_deleted;
/**
* Perform additional actions after attachment(s) deletion from the database
@@ -151,13 +163,21 @@ class delete
);
extract($this->dispatcher->trigger_event('core.delete_attachments_from_database_after', compact($vars)));
$this->sql_id = $sql_id;
$this->post_ids = $post_ids;
$this->topic_ids = $topic_ids;
$this->message_ids = $message_ids;
$this->physical = $physical;
$this->num_deleted = $num_deleted;
unset($sql_id, $post_ids, $topic_ids, $message_ids, $physical, $num_deleted);
if (!$this->num_deleted)
{
return 0;
}
// Delete attachments from storage
$this->remove_from_storage();
$this->remove_from_storage($mode, $ids, $resync);
// If we do not resync, we do not need to adjust any message, post, topic or user entries
if (!$resync)
@@ -283,8 +303,14 @@ class delete
/**
* Delete attachments from database table
*/
protected function delete_attachments_from_db()
protected function delete_attachments_from_db($mode, $ids, $resync)
{
$sql_id = $this->sql_id;
$post_ids = $this->post_ids;
$topic_ids = $this->topic_ids;
$message_ids = $this->message_ids;
$physical = $this->physical;
/**
* Perform additional actions before attachment(s) deletion
*
@@ -311,6 +337,13 @@ class delete
);
extract($this->dispatcher->trigger_event('core.delete_attachments_before', compact($vars)));
$this->sql_id = $sql_id;
$this->post_ids = $post_ids;
$this->topic_ids = $topic_ids;
$this->message_ids = $message_ids;
$this->physical = $physical;
unset($sql_id, $post_ids, $topic_ids, $message_ids, $physical);
// Delete attachments
$sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
WHERE ' . $this->db->sql_in_set($this->sql_id, $this->ids);
@@ -324,7 +357,7 @@ class delete
/**
* Delete attachments from storage
*/
protected function remove_from_storage()
protected function remove_from_storage($mode, $ids, $resync)
{
$space_removed = $files_removed = 0;
@@ -343,6 +376,13 @@ class delete
}
}
$sql_id = $this->sql_id;
$post_ids = $this->post_ids;
$topic_ids = $this->topic_ids;
$message_ids = $this->message_ids;
$physical = $this->physical;
$num_deleted = $this->num_deleted;
/**
* Perform additional actions after attachment(s) deletion from the filesystem
*
@@ -375,6 +415,14 @@ class delete
);
extract($this->dispatcher->trigger_event('core.delete_attachments_from_filesystem_after', compact($vars)));
$this->sql_id = $sql_id;
$this->post_ids = $post_ids;
$this->topic_ids = $topic_ids;
$this->message_ids = $message_ids;
$this->physical = $physical;
$this->num_deleted = $num_deleted;
unset($sql_id, $post_ids, $topic_ids, $message_ids, $physical, $num_deleted);
if ($space_removed || $files_removed)
{
$this->config->increment('upload_dir_size', $space_removed * (-1), false);

View File

@@ -254,8 +254,6 @@ class upload
{
fclose($fp);
}
$this->storage->track_file($destination_name);
}
else
{

View File

@@ -392,7 +392,7 @@ class oauth extends \phpbb\auth\provider\base
if ($credentials['key'] && $credentials['secret'])
{
$actual_name = str_replace('auth.provider.oauth.service.', '', $service_name);
$redirect_url = build_url(false) . '&login=external&oauth_service=' . $actual_name;
$redirect_url = generate_board_url() . '/ucp.' . $this->php_ext . '?mode=login&login=external&oauth_service=' . $actual_name;
$login_data['BLOCK_VARS'][$service_name] = array(
'REDIRECT_URL' => redirect($redirect_url, true),
'SERVICE_NAME' => $this->user->lang['AUTH_PROVIDER_OAUTH_SERVICE_' . strtoupper($actual_name)],

View File

@@ -25,7 +25,11 @@ class apcu extends \phpbb\cache\driver\memory
*/
function purge()
{
apcu_clear_cache();
/*
* Use an iterator to selectively delete our cache entries without disturbing
* any other cache users (e.g. other phpBB boards hosted on this server)
*/
apcu_delete(new \APCUIterator('#^' . $this->key_prefix . '#'));
parent::purge();
}

View File

@@ -51,10 +51,11 @@ abstract class memory extends \phpbb\cache\driver\base
function load()
{
// grab the global cache
$this->vars = $this->_read('global');
$data = $this->_read('global');
if ($this->vars !== false)
if ($data !== false)
{
$this->vars = $data;
return true;
}

View File

@@ -471,13 +471,18 @@ class installer
$composer = Factory::create($io, null, false);
$core_packages = $this->get_core_packages($composer);
// The composer/installers package must be installed on his own and not provided by the existing autoloader
$core_replace = $core_packages;
unset($core_replace['composer/installers']);
$ext_json_data = [
'require' => array_merge(
['php' => $this->get_core_php_requirement($composer)],
$core_packages,
$this->get_extra_dependencies(),
$packages),
'replace' => $core_packages,
'replace' => $core_replace,
'repositories' => $this->get_composer_repositories(),
'config' => [
'vendor-dir'=> $this->packages_vendor_dir,

View File

@@ -55,21 +55,26 @@ class prune_all_forums extends \phpbb\cron\task\base
include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);
}
$sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq
FROM ' . FORUMS_TABLE . "
WHERE enable_prune = 1
AND prune_next < " . time();
$sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, enable_shadow_prune, prune_shadow_days, prune_shadow_freq, prune_shadow_next, forum_flags, prune_freq
FROM ' . FORUMS_TABLE;
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
if ($row['prune_days'])
if ($row['enable_prune'] && $row['prune_next'] < time())
{
auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']);
}
if ($row['prune_days'])
{
auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']);
}
if ($row['prune_viewed'])
if ($row['prune_viewed'])
{
auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);
}
}
if ($row['enable_shadow_prune'] && $row['prune_shadow_next'] < time() && $row['prune_shadow_days'])
{
auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']);
auto_prune($row['forum_id'], 'shadow', $row['forum_flags'], $row['prune_shadow_days'], $row['prune_shadow_freq']);
}
}
$this->db->sql_freeresult($result);

View File

@@ -267,7 +267,7 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
unset($row['line2'], $row['line3']);
}
}
return (count($row)) ? $row : false;
return ($row !== null) ? $row : false;
}
/**

View File

@@ -17,7 +17,7 @@ class auth_provider_oauth extends \phpbb\db\migration\migration
{
public function effectively_installed()
{
return $this->db_tools->sql_table_exists($this->table_prefix . 'auth_provider_oauth');
return $this->db_tools->sql_table_exists($this->table_prefix . 'oauth_tokens');
}
static public function depends_on()

View File

@@ -85,13 +85,11 @@ class remove_outdated_media extends \phpbb\db\migration\migration
WHERE ' . $this->db->sql_in_set('group_id', $group_ids);
}
$result = $this->db->sql_query($sql);
$this->db->sql_freeresult($result);
$this->db->sql_query($sql);
// delete the now empty, outdated media extension groups
$sql = 'DELETE FROM ' . EXTENSION_GROUPS_TABLE . '
WHERE ' . $this->db->sql_in_set('group_id', $group_ids);
$result = $this->db->sql_query($sql);
$this->db->sql_freeresult($result);
$this->db->sql_query($sql);
}
}

View File

@@ -0,0 +1,37 @@
<?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\db\migration\data\v32x;
class forum_topics_per_page_type extends \phpbb\db\migration\migration
{
static public function depends_on()
{
return array(
'\phpbb\db\migration\data\v32x\v323',
);
}
public function update_schema()
{
return array(
'change_columns' => array(
$this->table_prefix . 'forums' => array(
'forum_topics_per_page' => array('USINT', 0),
),
),
);
}
}

View File

@@ -0,0 +1,37 @@
<?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\db\migration\data\v32x;
class v323 extends \phpbb\db\migration\migration
{
public function effectively_installed()
{
return phpbb_version_compare($this->config['version'], '3.2.3', '>=');
}
static public function depends_on()
{
return array(
'\phpbb\db\migration\data\v32x\v323rc2',
);
}
public function update_data()
{
return array(
array('config.update', array('version', '3.2.3')),
);
}
}

View File

@@ -0,0 +1,33 @@
<?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\db\migration\data\v330;
class extensions_composer_2 extends \phpbb\db\migration\migration
{
public function update_data()
{
$repositories = json_decode($this->config['exts_composer_repositories'], true);
$repositories[] = 'https://satis.phpbb.com';
$repositories = array_unique($repositories);
return array(
array('config.update', array('exts_composer_repositories', json_encode($repositories, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES))),
);
}
static public function depends_on()
{
return array('\phpbb\db\migration\data\v330\extensions_composer');
}
}

View File

@@ -74,13 +74,11 @@ class remove_attachment_flash extends \phpbb\db\migration\migration
WHERE ' . $this->db->sql_in_set('group_id', $group_ids);
}
$result = $this->db->sql_query($sql);
$this->db->sql_freeresult($result);
$this->db->sql_query($sql);
// delete the now empty, outdated media extension groups
$sql = 'DELETE FROM ' . EXTENSION_GROUPS_TABLE . '
WHERE ' . $this->db->sql_in_set('group_id', $group_ids);
$result = $this->db->sql_query($sql);
$this->db->sql_freeresult($result);
$this->db->sql_query($sql);
}
}

View File

@@ -13,7 +13,7 @@
namespace phpbb\db\migration\data\v330;
class storage_adapter_local_depth extends \phpbb\db\migration\migration
class storage_adapter_local_subfolders extends \phpbb\db\migration\migration
{
static public function depends_on()
{
@@ -29,15 +29,15 @@ class storage_adapter_local_depth extends \phpbb\db\migration\migration
return array(
array('if', array(
($this->config['storage\\attachment\\provider'] == \phpbb\storage\provider\local::class),
array('config.add', array('storage\\attachment\\config\\depth', '0')),
array('config.add', array('storage\\attachment\\config\\subfolders', '0')),
)),
array('if', array(
($this->config['storage\\avatar\\provider'] == \phpbb\storage\provider\local::class),
array('config.add', array('storage\\avatar\\config\\depth', '0')),
array('config.add', array('storage\\avatar\\config\\subfolders', '0')),
)),
array('if', array(
($this->config['storage\\backup\\provider'] == \phpbb\storage\provider\local::class),
array('config.add', array('storage\\backup\\config\\depth', '0')),
array('config.add', array('storage\\backup\\config\\subfolders', '0')),
)),
);
}

View File

@@ -86,7 +86,14 @@ class storage_track extends \phpbb\db\migration\container_aware_migration
$ext = substr(strrchr($filename, '.'), 1);
$filename = (int) $filename;
$storage->track_file($this->config['avatar_salt'] . '_' . ($avatar_group ? 'g' : '') . $filename . '.' . $ext);
try
{
$storage->track_file($this->config['avatar_salt'] . '_' . ($avatar_group ? 'g' : '') . $filename . '.' . $ext);
}
catch (\phpbb\storage\exception\exception $e)
{
// If file don't exist, don't track it
}
}
$this->db->sql_freeresult($result);
}
@@ -103,11 +110,25 @@ class storage_track extends \phpbb\db\migration\container_aware_migration
while ($row = $this->db->sql_fetchrow($result))
{
$storage->track_file($row['physical_filename']);
try
{
$storage->track_file($row['physical_filename']);
}
catch (\phpbb\storage\exception\exception $e)
{
// If file don't exist, don't track it
}
if ($row['thumbnail'] == 1)
{
$storage->track_file('thumb_' . $row['physical_filename']);
try
{
$storage->track_file('thumb_' . $row['physical_filename']);
}
catch (\phpbb\storage\exception\exception $e)
{
// If file don't exist, don't track it
}
}
}
$this->db->sql_freeresult($result);
@@ -125,8 +146,16 @@ class storage_track extends \phpbb\db\migration\container_aware_migration
while ($row = $this->db->sql_fetchrow($result))
{
$storage->track_file($row['filename']);
try
{
$storage->track_file($row['filename']);
}
catch (\phpbb\storage\exception\exception $e)
{
// If file don't exist, don't track it
}
}
$this->db->sql_freeresult($result);
}
}

View File

@@ -341,7 +341,7 @@ class module implements \phpbb\db\migration\tool\tool_interface
}
// Clear the Modules Cache
$this->cache->destroy("_modules_$class");
$this->module_manager->remove_cache_file($class);
}
/**
@@ -425,7 +425,7 @@ class module implements \phpbb\db\migration\tool\tool_interface
$this->module_manager->delete_module($module_id, $class);
}
$this->cache->destroy("_modules_$class");
$this->module_manager->remove_cache_file($class);
}
}

View File

@@ -486,7 +486,7 @@ class container_builder
$cached_container_dump = $dumper->dump(array(
'class' => 'phpbb_cache_container',
'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder',
'base_class' => 'Symfony\\Component\\DependencyInjection\\Container',
));
$cache->write($cached_container_dump, $this->container->getResources());

View File

@@ -31,12 +31,14 @@ class container_configuration implements ConfigurationInterface
$rootNode
->children()
->booleanNode('require_dev_dependencies')->defaultValue(false)->end()
->booleanNode('allow_install_dir')->defaultValue(false)->end()
->arrayNode('debug')
->addDefaultsIfNotSet()
->children()
->booleanNode('exceptions')->defaultValue(false)->end()
->booleanNode('load_time')->defaultValue(false)->end()
->booleanNode('sql_explain')->defaultValue(false)->end()
->booleanNode('memory')->defaultValue(false)->end()
->booleanNode('show_errors')->defaultValue(false)->end()
->end()
->end()
@@ -55,6 +57,12 @@ class container_configuration implements ConfigurationInterface
->booleanNode('composer_verbose')->defaultValue(false)->end()
->end()
->end()
->arrayNode('session')
->addDefaultsIfNotSet()
->children()
->booleanNode('log_errors')->defaultValue(false)->end()
->end()
->end()
->end()
;
return $treeBuilder;

View File

@@ -72,6 +72,8 @@ class core extends Extension
}
}
$container->setParameter('allow_install_dir', $config['allow_install_dir']);
// Set the Twig options if defined in the environment
$definition = $container->getDefinition('template.twig.environment');
$twig_environment_options = $definition->getArgument(static::TWIG_OPTIONS_POSITION);
@@ -110,6 +112,12 @@ class core extends Extension
{
$container->setParameter('debug.' . $name, $value);
}
// Set the log options
foreach ($config['session'] as $name => $value)
{
$container->setParameter('session.' . $name, $value);
}
}
/**

View File

@@ -439,16 +439,9 @@ class md_exporter
$event_list = array();
$file_content = file_get_contents($this->path . $file);
$events = explode('<!-- EVENT ', $file_content);
// Remove the code before the first event
array_shift($events);
foreach ($events as $event)
{
$event = explode(' -->', $event, 2);
$event_list[] = array_shift($event);
}
preg_match_all('/(?:{%|<!--) EVENT (.*) (?:%}|-->)/U', $file_content, $event_list);
return $event_list;
return $event_list[1];
}
/**

View File

@@ -456,8 +456,6 @@ class filespec_storage
{
fclose($fp);
}
$storage->track_file($this->destination_file);
}
catch (\phpbb\storage\exception\exception $e)
{

View File

@@ -68,7 +68,7 @@ class filesystem implements filesystem_interface
$error = trim($e->getMessage());
$file = substr($error, strrpos($error, ' '));
throw new filesystem_exception('CANNOT_CHANGE_FILE_GROUP', $file, array(), $e);
throw new filesystem_exception('FILESYSTEM_CANNOT_CHANGE_FILE_GROUP', $file, array(), $e);
}
}
@@ -125,14 +125,14 @@ class filesystem implements filesystem_interface
{
if (true !== @chmod($file, $dir_perm))
{
throw new filesystem_exception('CANNOT_CHANGE_FILE_PERMISSIONS', $file, array());
throw new filesystem_exception('FILESYSTEM_CANNOT_CHANGE_FILE_PERMISSIONS', $file, array());
}
}
else if (is_file($file))
{
if (true !== @chmod($file, $file_perm))
{
throw new filesystem_exception('CANNOT_CHANGE_FILE_PERMISSIONS', $file, array());
throw new filesystem_exception('FILESYSTEM_CANNOT_CHANGE_FILE_PERMISSIONS', $file, array());
}
}
}
@@ -154,7 +154,7 @@ class filesystem implements filesystem_interface
$error = trim($e->getMessage());
$file = substr($error, strrpos($error, ' '));
throw new filesystem_exception('CANNOT_CHANGE_FILE_GROUP', $file, array(), $e);
throw new filesystem_exception('FILESYSTEM_CANNOT_CHANGE_FILE_GROUP', $file, array(), $e);
}
}
@@ -177,7 +177,7 @@ class filesystem implements filesystem_interface
}
catch (IOException $e)
{
throw new filesystem_exception('CANNOT_COPY_FILES', '', array(), $e);
throw new filesystem_exception('FILESYSTEM_CANNOT_COPY_FILES', '', array(), $e);
}
}
@@ -192,7 +192,7 @@ class filesystem implements filesystem_interface
}
catch (IOException $e)
{
throw new filesystem_exception('CANNOT_DUMP_FILE', $filename, array(), $e);
throw new filesystem_exception('FILESYSTEM_CANNOT_DUMP_FILE', $filename, array(), $e);
}
}
@@ -304,7 +304,7 @@ class filesystem implements filesystem_interface
$msg = $e->getMessage();
$filename = substr($msg, strpos($msg, '"'), strrpos($msg, '"'));
throw new filesystem_exception('CANNOT_MIRROR_DIRECTORY', $filename, array(), $e);
throw new filesystem_exception('FILESYSTEM_CANNOT_MIRROR_DIRECTORY', $filename, array(), $e);
}
}
@@ -322,7 +322,7 @@ class filesystem implements filesystem_interface
$msg = $e->getMessage();
$filename = substr($msg, strpos($msg, '"'), strrpos($msg, '"'));
throw new filesystem_exception('CANNOT_CREATE_DIRECTORY', $filename, array(), $e);
throw new filesystem_exception('FILESYSTEM_CANNOT_CREATE_DIRECTORY', $filename, array(), $e);
}
}
@@ -487,7 +487,7 @@ class filesystem implements filesystem_interface
$error = trim($e->getMessage());
$file = substr($error, strrpos($error, ' '));
throw new filesystem_exception('CANNOT_DELETE_FILES', $file, array(), $e);
throw new filesystem_exception('FILESYSTEM_CANNOT_DELETE_FILES', $file, array(), $e);
}
}
@@ -505,7 +505,7 @@ class filesystem implements filesystem_interface
$msg = $e->getMessage();
$filename = substr($msg, strpos($msg, '"'), strrpos($msg, '"'));
throw new filesystem_exception('CANNOT_RENAME_FILE', $filename, array(), $e);
throw new filesystem_exception('FILESYSTEM_CANNOT_RENAME_FILE', $filename, array(), $e);
}
}
@@ -520,7 +520,7 @@ class filesystem implements filesystem_interface
}
catch (IOException $e)
{
throw new filesystem_exception('CANNOT_CREATE_SYMLINK', $origin_dir, array(), $e);
throw new filesystem_exception('FILESYSTEM_CANNOT_CREATE_SYMLINK', $origin_dir, array(), $e);
}
}
@@ -540,7 +540,7 @@ class filesystem implements filesystem_interface
$error = trim($e->getMessage());
$file = substr($error, strrpos($error, ' '));
throw new filesystem_exception('CANNOT_TOUCH_FILES', $file, array(), $e);
throw new filesystem_exception('FILESYSTEM_CANNOT_TOUCH_FILES', $file, array(), $e);
}
}

View File

@@ -122,8 +122,11 @@ class check_update extends task_base
// Check for a valid update directory
if (!$this->filesystem->exists($update_files) || !$this->filesystem->is_readable($update_files))
{
$this->iohandler->add_warning_message('UPDATE_FILES_NOT_FOUND');
$this->set_test_passed(false);
if ($this->iohandler->get_input('update_type', 'all') === 'all')
{
$this->iohandler->add_warning_message('UPDATE_FILES_NOT_FOUND');
$this->set_test_passed(false);
}
// If there are no update files, we can't check the version etc
// However, we can let the users run migrations if they really want to...

View File

@@ -87,7 +87,7 @@ abstract class messenger_base extends \phpbb\notification\method\base
$banned_users = phpbb_get_banned_user_ids($user_ids);
// Load all the users we need
$this->user_loader->load_users($user_ids);
$this->user_loader->load_users(array_diff($user_ids, $banned_users), array(USER_IGNORE));
// Load the messenger
if (!class_exists('messenger'))
@@ -107,7 +107,7 @@ abstract class messenger_base extends \phpbb\notification\method\base
$user = $this->user_loader->get_user($notification->user_id);
if ($user['user_type'] == USER_IGNORE || ($user['user_type'] == USER_INACTIVE && $user['user_inactive_reason'] == INACTIVE_MANUAL) || in_array($notification->user_id, $banned_users))
if ($user['user_type'] == USER_INACTIVE && $user['user_inactive_reason'] == INACTIVE_MANUAL)
{
continue;
}

View File

@@ -150,8 +150,6 @@ class request implements \phpbb\request\request_interface
return;
}
$this->type_cast_helper->add_magic_quotes($value);
// setting to null means unsetting
if ($value === null)
{

View File

@@ -18,69 +18,6 @@ namespace phpbb\request;
*/
class type_cast_helper implements \phpbb\request\type_cast_helper_interface
{
/**
* @var string Whether slashes need to be stripped from input
*/
protected $strip;
/**
* Initialises the type cast helper class.
* All it does is find out whether magic quotes are turned on.
*/
public function __construct()
{
if (version_compare(PHP_VERSION, '5.4.0-dev', '>='))
{
$this->strip = false;
}
else
{
$this->strip = (@get_magic_quotes_gpc()) ? true : false;
}
}
/**
* Recursively applies addslashes to a variable.
*
* @param mixed &$var Variable passed by reference to which slashes will be added.
*/
public function addslashes_recursively(&$var)
{
if (is_string($var))
{
$var = addslashes($var);
}
else if (is_array($var))
{
$var_copy = $var;
$var = array();
foreach ($var_copy as $key => $value)
{
if (is_string($key))
{
$key = addslashes($key);
}
$var[$key] = $value;
$this->addslashes_recursively($var[$key]);
}
}
}
/**
* Recursively applies addslashes to a variable if magic quotes are turned on.
*
* @param mixed &$var Variable passed by reference to which slashes will be added.
*/
public function add_magic_quotes(&$var)
{
if ($this->strip)
{
$this->addslashes_recursively($var);
}
}
/**
* Set variable $result to a particular type.
*
@@ -129,8 +66,6 @@ class type_cast_helper implements \phpbb\request\type_cast_helper_interface
$result = preg_replace('/[\x80-\xFF]/', '?', $result);
}
}
$result = ($this->strip) ? stripslashes($result) : $result;
}
}

View File

@@ -18,20 +18,6 @@ namespace phpbb\request;
*/
interface type_cast_helper_interface
{
/**
* Recursively applies addslashes to a variable.
*
* @param mixed &$var Variable passed by reference to which slashes will be added.
*/
public function addslashes_recursively(&$var);
/**
* Recursively applies addslashes to a variable if magic quotes are turned on.
*
* @param mixed &$var Variable passed by reference to which slashes will be added.
*/
public function add_magic_quotes(&$var);
/**
* Set variable $result to a particular type.
*

View File

@@ -292,7 +292,6 @@ class fulltext_sphinx
AND p.post_id >= $start AND p.post_id <= $end'),
array('sql_query_post', ''),
array('sql_query_post_index', 'UPDATE ' . SPHINX_TABLE . ' SET max_doc_id = $maxid WHERE counter_id = 1'),
array('sql_query_info', 'SELECT * FROM ' . POSTS_TABLE . ' WHERE post_id = $id'),
array('sql_attr_uint', 'forum_id'),
array('sql_attr_uint', 'topic_id'),
array('sql_attr_uint', 'poster_id'),
@@ -333,7 +332,6 @@ class fulltext_sphinx
array('morphology', 'none'),
array('stopwords', ''),
array('min_word_len', '2'),
array('charset_type', 'utf-8'),
array('charset_table', 'U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z, A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6, U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101, U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109, U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F, U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, U+0116->U+0117, U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D, U+011D, U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, U+0134->U+0135, U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, U+013C, U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, U+0143->U+0144, U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, U+014B, U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, U+0152->U+0153, U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159, U+0159, U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, U+0160->U+0161, U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, U+0167, U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, U+016E->U+016F, U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175, U+0175, U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, U+017B->U+017C, U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, U+0430..U+044F, U+4E00..U+9FFF'),
array('min_prefix_len', '0'),
array('min_infix_len', '0'),
@@ -346,14 +344,12 @@ class fulltext_sphinx
array('mem_limit', $this->config['fulltext_sphinx_indexer_mem_limit'] . 'M'),
),
'searchd' => array(
array('compat_sphinxql_magics' , '0'),
array('listen' , ($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost') . ':' . ($this->config['fulltext_sphinx_port'] ? $this->config['fulltext_sphinx_port'] : '9312')),
array('log', $this->config['fulltext_sphinx_data_path'] . 'log/searchd.log'),
array('query_log', $this->config['fulltext_sphinx_data_path'] . 'log/sphinx-query.log'),
array('read_timeout', '5'),
array('max_children', '30'),
array('pid_file', $this->config['fulltext_sphinx_data_path'] . 'searchd.pid'),
array('max_matches', (string) SPHINX_MAX_MATCHES),
array('binlog_path', $this->config['fulltext_sphinx_data_path']),
),
);
@@ -648,7 +644,7 @@ class fulltext_sphinx
$this->sphinx->SetFilter('deleted', array(0));
$this->sphinx->SetLimits($start, (int) $per_page, SPHINX_MAX_MATCHES);
$this->sphinx->SetLimits((int) $start, (int) $per_page, SPHINX_MAX_MATCHES);
$result = $this->sphinx->Query($search_query_prefix . $this->sphinx->EscapeString(str_replace('&quot;', '"', $this->search_query)), $this->indexes);
// Could be connection to localhost:9312 failed (errno=111,

View File

@@ -481,7 +481,7 @@ class session
else
{
// Added logging temporarily to help debug bugs...
if (defined('DEBUG') && $this->data['user_id'] != ANONYMOUS)
if ($phpbb_container->getParameter('session.log_errors') && $this->data['user_id'] != ANONYMOUS)
{
if ($referer_valid)
{

View File

@@ -28,8 +28,7 @@ interface adapter_interface
* @param string path The file to be written to.
* @param string content The data to write into the file.
*
* @throws \phpbb\storage\exception\exception When the file already exists
* When the file cannot be written
* @throws \phpbb\storage\exception\exception When the file cannot be written
*/
public function put_contents($path, $content);
@@ -38,8 +37,7 @@ interface adapter_interface
*
* @param string $path The file to read
*
* @throws \phpbb\storage\exception\exception When the file doesn't exist
* When cannot read file contents
* @throws \phpbb\storage\exception\exception When cannot read file contents
*
* @return string Returns file contents
*
@@ -70,8 +68,7 @@ interface adapter_interface
* @param string $path_orig The original file/direcotry
* @param string $path_dest The target file/directory
*
* @throws \phpbb\storage\exception\exception When target exists
* When file/directory cannot be renamed
* @throws \phpbb\storage\exception\exception When file/directory cannot be renamed
*/
public function rename($path_orig, $path_dest);
@@ -81,8 +78,7 @@ interface adapter_interface
* @param string $path_orig The original filename
* @param string $path_dest The target filename
*
* @throws \phpbb\storage\exception\exception When target exists
* When the file cannot be copied
* @throws \phpbb\storage\exception\exception When the file cannot be copied
*/
public function copy($path_orig, $path_dest);

View File

@@ -73,10 +73,17 @@ class local implements adapter_interface, stream_interface
* This is for those who have problems storing a large number of files in
* a single directory.
* More info: https://tracker.phpbb.com/browse/PHPBB3-15371
*
*/
/*
* @var bool subfolders
*/
protected $subfolders;
/*
* @var int dir_depth
*/
protected $dir_depth;
protected $dir_depth = 2;
/**
* Constructor
@@ -101,7 +108,7 @@ class local implements adapter_interface, stream_interface
$this->path = $options['path'];
$this->root_path = $this->phpbb_root_path . $options['path'];
$this->dir_depth = (int) $options['depth'];
$this->subfolders = (bool) $options['subfolders'];
}
/**
@@ -111,11 +118,6 @@ class local implements adapter_interface, stream_interface
{
$this->ensure_directory_exists($path);
if ($this->exists($path))
{
throw new exception('STORAGE_FILE_EXISTS', $path);
}
try
{
$this->filesystem->dump_file($this->root_path . $this->get_path($path) . $this->get_filename($path), $content);
@@ -131,11 +133,6 @@ class local implements adapter_interface, stream_interface
*/
public function get_contents($path)
{
if (!$this->exists($path))
{
throw new exception('STORAGE_FILE_NO_EXIST', $path);
}
$content = @file_get_contents($this->root_path . $this->get_path($path) . $this->get_filename($path));
if ($content === false)
@@ -249,17 +246,20 @@ class local implements adapter_interface, stream_interface
*/
protected function remove_empty_dirs($path)
{
$dirpath = dirname($this->root_path . $path);
$filepath = dirname($this->root_path . $this->get_path($path) . $this->get_filename($path));
$path = filesystem_helper::make_path_relative($filepath, $dirpath);
do
if ($this->subfolders)
{
$parts = explode('/', $path);
$parts = array_slice($parts, 0, -1);
$path = implode('/', $parts);
$dirpath = dirname($this->root_path . $path);
$filepath = dirname($this->root_path . $this->get_path($path) . $this->get_filename($path));
$path = filesystem_helper::make_path_relative($filepath, $dirpath);
do
{
$parts = explode('/', $path);
$parts = array_slice($parts, 0, -1);
$path = implode('/', $parts);
}
while ($path && @rmdir($dirpath . '/' . $path));
}
while ($path && @rmdir($dirpath . '/' . $path));
}
/**
@@ -271,21 +271,22 @@ class local implements adapter_interface, stream_interface
protected function get_path($path)
{
$dirname = dirname($path);
$dirname = ($dirname != '.') ? $dirname . DIRECTORY_SEPARATOR : '';
$hash = md5(basename($path));
$parts = str_split($hash, 2);
$parts = array_slice($parts, 0, $this->dir_depth);
// Create path
$path = $dirname . DIRECTORY_SEPARATOR;
if (!empty($parts))
if ($this->subfolders)
{
$path .= implode(DIRECTORY_SEPARATOR, $parts) . DIRECTORY_SEPARATOR;
$hash = md5(basename($path));
$parts = str_split($hash, 2);
$parts = array_slice($parts, 0, $this->dir_depth);
if (!empty($parts))
{
$dirname .= implode(DIRECTORY_SEPARATOR, $parts) . DIRECTORY_SEPARATOR;
}
}
return $path;
return $dirname;
}
/**
@@ -320,11 +321,6 @@ class local implements adapter_interface, stream_interface
{
$this->ensure_directory_exists($path);
if ($this->exists($path))
{
throw new exception('STORAGE_FILE_EXISTS', $path);
}
$stream = @fopen($this->root_path . $this->get_path($path) . $this->get_filename($path), 'w+b');
if (!$stream)
@@ -337,6 +333,8 @@ class local implements adapter_interface, stream_interface
fclose($stream);
throw new exception('STORAGE_CANNOT_COPY_RESOURCE');
}
fclose($stream);
}
/**
@@ -350,7 +348,7 @@ class local implements adapter_interface, stream_interface
*/
public function file_size($path)
{
$size = filesize($this->root_path . $this->get_path($path) . $this->get_filename($path));
$size = @filesize($this->root_path . $this->get_path($path) . $this->get_filename($path));
if ($size === null)
{
@@ -422,7 +420,7 @@ class local implements adapter_interface, stream_interface
*/
public function get_link($path)
{
return generate_board_url() . $this->path . $path;
return generate_board_url() . '/' . $this->path . $path;
}
/**

View File

@@ -37,8 +37,14 @@ class local implements provider_interface
public function get_options()
{
return [
'path' => array('type' => 'text'),
'depth' => array('type' => 'text'),
'path' => ['type' => 'text'],
'subfolders' => [
'type' => 'radio',
'options' => [
'ENABLE' => '1',
'DISABLE' => '0',
],
],
];
}

View File

@@ -15,6 +15,7 @@ namespace phpbb\storage;
use phpbb\cache\driver\driver_interface as cache;
use phpbb\db\driver\driver_interface as db;
use phpbb\storage\exception\exception;
/**
* @internal Experimental
@@ -106,6 +107,11 @@ class storage
*/
public function put_contents($path, $content)
{
if ($this->exists($path))
{
throw new exception('STORAGE_FILE_EXISTS', $path);
}
$this->get_adapter()->put_contents($path, $content);
$this->track_file($path);
}
@@ -123,19 +129,25 @@ class storage
*/
public function get_contents($path)
{
if (!$this->exists($path))
{
throw new exception('STORAGE_FILE_NO_EXIST', $path);
}
return $this->get_adapter()->get_contents($path);
}
/**
* Checks the existence of files or directories
*
* @param string $path file/directory to check
* @param string $path file/directory to check
* @param bool $full_check check in the filesystem too
*
* @return bool Returns true if the file/directory exist, false otherwise.
* @return bool Returns true if the file/directory exist, false otherwise
*/
public function exists($path)
public function exists($path, $full_check = false)
{
return $this->get_adapter()->exists($path);
return ($this->is_tracked($path) && (!$full_check || $this->get_adapter()->exists($path)));
}
/**
@@ -143,10 +155,16 @@ class storage
*
* @param string $path file/directory to remove
*
* @throws \phpbb\storage\exception\exception When removal fails.
* @throws \phpbb\storage\exception\exception When removal fails
* When the file doesn't exist
*/
public function delete($path)
{
if (!$this->exists($path))
{
throw new exception('STORAGE_FILE_NO_EXIST', $path);
}
$this->get_adapter()->delete($path);
$this->untrack_file($path);
}
@@ -157,11 +175,22 @@ class storage
* @param string $path_orig The original file/direcotry
* @param string $path_dest The target file/directory
*
* @throws \phpbb\storage\exception\exception When target exists
* @throws \phpbb\storage\exception\exception When the file doesn't exist
* When target exists
* When file/directory cannot be renamed
*/
public function rename($path_orig, $path_dest)
{
if (!$this->exists($path_orig))
{
throw new exception('STORAGE_FILE_NO_EXIST', $path_orig);
}
if ($this->exists($path_dest))
{
throw new exception('STORAGE_FILE_EXISTS', $path_dest);
}
$this->get_adapter()->rename($path_orig, $path_dest);
$this->track_rename($path_orig, $path_dest);
}
@@ -172,11 +201,22 @@ class storage
* @param string $path_orig The original filename
* @param string $path_dest The target filename
*
* @throws \phpbb\storage\exception\exception When target exists
* @throws \phpbb\storage\exception\exception When the file doesn't exist
* When target exists
* When the file cannot be copied
*/
public function copy($path_orig, $path_dest)
{
if (!$this->exists($path_orig))
{
throw new exception('STORAGE_FILE_NO_EXIST', $path_orig);
}
if ($this->exists($path_dest))
{
throw new exception('STORAGE_FILE_EXISTS', $path_dest);
}
$this->get_adapter()->copy($path_orig, $path_dest);
$this->track_file($path_dest);
}
@@ -186,12 +226,18 @@ class storage
*
* @param string $path File to read
*
* @throws \phpbb\storage\exception\exception When unable to open file
* @throws \phpbb\storage\exception\exception When the file doesn't exist
* When unable to open file
*
* @return resource Returns a file pointer
*/
public function read_stream($path)
{
if (!$this->exists($path))
{
throw new exception('STORAGE_FILE_NO_EXIST', $path);
}
$stream = null;
$adapter = $this->get_adapter();
@@ -212,20 +258,31 @@ class storage
/**
* Writes a new file using a stream
* The file needs to be tracked after using this method
*
* @param string $path The target file
* @param resource $resource The resource
*
* @throws \phpbb\storage\exception\exception When target file cannot be created
* @throws \phpbb\storage\exception\exception When the file exist
* When target file cannot be created
*/
public function write_stream($path, $resource)
{
if ($this->exists($path))
{
throw new exception('STORAGE_FILE_EXISTS', $path);
}
if (!is_resource($resource))
{
throw new exception('STORAGE_INVALID_RESOURCE');
}
$adapter = $this->get_adapter();
if ($adapter instanceof stream_interface)
{
$adapter->write_stream($path, $resource);
$this->track_file($path);
}
else
{
@@ -242,6 +299,11 @@ class storage
*/
public function track_file($path, $update = false)
{
if (!$this->get_adapter()->exists($path))
{
throw new exception('STORAGE_FILE_NO_EXIST', $path);
}
$sql_ary = array(
'file_path' => $path,
'storage' => $this->get_name(),
@@ -256,7 +318,10 @@ class storage
if (!$row)
{
$file = $this->file_info($path);
// Don't call the file_info method, because it check's if the file is tracked
// and is not (for now). This method check if the file exists using the adapter
// at the beginning.
$file = new file_info($this->get_adapter(), $path);
$sql_ary['filesize'] = $file->size;
$sql = 'INSERT INTO ' . $this->storage_table . $this->db->sql_build_array('INSERT', $sql_ary);
@@ -295,6 +360,29 @@ class storage
$this->cache->destroy('_storage_' . $this->get_name() . '_numfiles');
}
/**
* Check if a file is tracked
*
* @param string $path The file
*
* @return bool True if file is tracked
*/
public function is_tracked($path)
{
$sql_ary = array(
'file_path' => $path,
'storage' => $this->get_name(),
);
$sql = 'SELECT file_id FROM ' . $this->storage_table . '
WHERE ' . $this->db->sql_build_array('SELECT', $sql_ary);
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
return ($row) ? true : false;
}
/**
* Rename tracked file
*
@@ -316,11 +404,17 @@ class storage
* @param string $path The file
*
* @throws \phpbb\storage\exception\not_implemented When the adapter doesnt implement the method
* When the file doesn't exist
*
* @return \phpbb\storage\file_info Returns file_info object
*/
public function file_info($path)
{
if (!$this->exists($path))
{
throw new exception('STORAGE_FILE_NO_EXIST', $path);
}
return new file_info($this->get_adapter(), $path);
}

View File

@@ -110,7 +110,7 @@ class user extends \phpbb\session
function setup($lang_set = false, $style_id = false)
{
global $db, $request, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache;
global $phpbb_dispatcher;
global $phpbb_dispatcher, $phpbb_container;
$this->language->set_default_language($config['default_lang']);
@@ -189,6 +189,9 @@ class user extends \phpbb\session
/**
* Event to load language files and modify user data on every page
*
* Note: To load language file with this event, see description
* of lang_set_ext variable.
*
* @event core.user_setup
* @var array user_data Array with user's data row
* @var string user_lang_name Basename of the user's langauge
@@ -325,7 +328,7 @@ class user extends \phpbb\session
// Disable board if the install/ directory is still present
// For the brave development army we do not care about this, else we need to comment out this every time we develop locally
if (!defined('DEBUG') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install'))
if (!$phpbb_container->getParameter('allow_install_dir') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install'))
{
// Adjust the message slightly according to the permissions
if ($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))

View File

@@ -64,8 +64,9 @@ class user_loader
* Load user helper
*
* @param array $user_ids
* @param array $ignore_types user types to ignore
*/
public function load_users(array $user_ids)
public function load_users(array $user_ids, array $ignore_types = array())
{
$user_ids[] = ANONYMOUS;
@@ -79,7 +80,8 @@ class user_loader
{
$sql = 'SELECT *
FROM ' . $this->users_table . '
WHERE ' . $this->db->sql_in_set('user_id', $user_ids);
WHERE ' . $this->db->sql_in_set('user_id', $user_ids) . '
AND ' . $this->db->sql_in_set('user_type', $ignore_types, true, true);
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))