aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r--phpBB/phpbb/console/command/update/check.php2
-rw-r--r--phpBB/phpbb/db/migration/data/v320/add_help_phpbb.php7
-rw-r--r--phpBB/phpbb/di/extension/core.php2
-rw-r--r--phpBB/phpbb/extension/manager.php61
-rw-r--r--phpBB/phpbb/extension/metadata_manager.php133
-rw-r--r--phpBB/phpbb/module/module_manager.php2
-rw-r--r--phpBB/phpbb/request/request.php6
-rw-r--r--phpBB/phpbb/template/context.php42
-rw-r--r--phpBB/phpbb/template/template.php3
-rw-r--r--phpBB/phpbb/template/twig/environment.php36
-rw-r--r--phpBB/phpbb/textformatter/s9e/factory.php16
11 files changed, 150 insertions, 160 deletions
diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php
index 1f1cfa25d2..ed8ad79eea 100644
--- a/phpBB/phpbb/console/command/update/check.php
+++ b/phpBB/phpbb/console/command/update/check.php
@@ -134,7 +134,7 @@ class check extends \phpbb\console\command\command
try
{
$ext_manager = $this->phpbb_container->get('ext.manager');
- $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null);
+ $md_manager = $ext_manager->create_extension_metadata_manager($ext_name);
$updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability);
$metadata = $md_manager->get_metadata('all');
diff --git a/phpBB/phpbb/db/migration/data/v320/add_help_phpbb.php b/phpBB/phpbb/db/migration/data/v320/add_help_phpbb.php
index afa67fbc58..8fadb4bde4 100644
--- a/phpBB/phpbb/db/migration/data/v320/add_help_phpbb.php
+++ b/phpBB/phpbb/db/migration/data/v320/add_help_phpbb.php
@@ -32,10 +32,9 @@ class add_help_phpbb extends \phpbb\db\migration\migration
return array(
array('config.add', array('help_send_statistics', true)),
array('config.add', array('help_send_statistics_time', 0)),
- array('module.remove', array(
- 'acp',
- false,
- 'ACP_SEND_STATISTICS',
+ array('if', array(
+ array('module.exists', array('acp', false, 'ACP_SEND_STATISTICS')),
+ array('module.remove', array('acp', false, 'ACP_SEND_STATISTICS')),
)),
array('module.add', array(
'acp',
diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php
index 29c0b0e44e..67150f0103 100644
--- a/phpBB/phpbb/di/extension/core.php
+++ b/phpBB/phpbb/di/extension/core.php
@@ -24,7 +24,7 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension;
*/
class core extends Extension
{
- const TWIG_OPTIONS_POSITION = 6;
+ const TWIG_OPTIONS_POSITION = 7;
/**
* Config path
diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php
index e3e6fe4077..00aa2c6826 100644
--- a/phpBB/phpbb/extension/manager.php
+++ b/phpBB/phpbb/extension/manager.php
@@ -152,7 +152,12 @@ class manager
*/
public function create_extension_metadata_manager($name)
{
- return new \phpbb\extension\metadata_manager($name, $this->config, $this, $this->phpbb_root_path);
+ if (!isset($this->extensions[$name]['metadata']))
+ {
+ $metadata = new \phpbb\extension\metadata_manager($name, $this->get_extension_path($name, true));
+ $this->extensions[$name]['metadata'] = $metadata;
+ }
+ return $this->extensions[$name]['metadata'];
}
/**
@@ -168,7 +173,7 @@ class manager
public function enable_step($name)
{
// ignore extensions that are already enabled
- if (isset($this->extensions[$name]) && $this->extensions[$name]['ext_active'])
+ if ($this->is_enabled($name))
{
return false;
}
@@ -258,7 +263,7 @@ class manager
public function disable_step($name)
{
// ignore extensions that are already disabled
- if (!isset($this->extensions[$name]) || !$this->extensions[$name]['ext_active'])
+ if ($this->is_disabled($name))
{
return false;
}
@@ -336,8 +341,8 @@ class manager
*/
public function purge_step($name)
{
- // ignore extensions that do not exist
- if (!isset($this->extensions[$name]))
+ // ignore extensions that are not configured
+ if (!$this->is_configured($name))
{
return false;
}
@@ -431,25 +436,11 @@ class manager
if ($file_info->isFile() && $file_info->getFilename() == 'composer.json')
{
$ext_name = $iterator->getInnerIterator()->getSubPath();
- $composer_file = $iterator->getPath() . '/composer.json';
-
- // Ignore the extension if there is no composer.json.
- if (!is_readable($composer_file) || !($ext_info = file_get_contents($composer_file)))
- {
- continue;
- }
-
- $ext_info = json_decode($ext_info, true);
$ext_name = str_replace(DIRECTORY_SEPARATOR, '/', $ext_name);
-
- // Ignore the extension if directory depth is not correct or if the directory structure
- // does not match the name value specified in composer.json.
- if (substr_count($ext_name, '/') !== 1 || !isset($ext_info['name']) || $ext_name != $ext_info['name'])
+ if ($this->is_available($ext_name))
{
- continue;
+ $available[$ext_name] = $this->get_extension_path($ext_name, true);
}
-
- $available[$ext_name] = $this->phpbb_root_path . 'ext/' . $ext_name . '/';
}
}
ksort($available);
@@ -472,8 +463,12 @@ class manager
$configured = array();
foreach ($this->extensions as $name => $data)
{
- $data['ext_path'] = ($phpbb_relative ? $this->phpbb_root_path : '') . $data['ext_path'];
- $configured[$name] = $data;
+ if ($this->is_configured($name))
+ {
+ unset($data['metadata']);
+ $data['ext_path'] = ($phpbb_relative ? $this->phpbb_root_path : '') . $data['ext_path'];
+ $configured[$name] = $data;
+ }
}
return $configured;
}
@@ -490,7 +485,7 @@ class manager
$enabled = array();
foreach ($this->extensions as $name => $data)
{
- if ($data['ext_active'])
+ if ($this->is_enabled($name))
{
$enabled[$name] = ($phpbb_relative ? $this->phpbb_root_path : '') . $data['ext_path'];
}
@@ -511,7 +506,7 @@ class manager
$disabled = array();
foreach ($this->extensions as $name => $data)
{
- if (!$data['ext_active'])
+ if ($this->is_disabled($name))
{
$disabled[$name] = ($phpbb_relative ? $this->phpbb_root_path : '') . $data['ext_path'];
}
@@ -527,7 +522,15 @@ class manager
*/
public function is_available($name)
{
- return file_exists($this->get_extension_path($name, true));
+ $md_manager = $this->create_extension_metadata_manager($name);
+ try
+ {
+ return $md_manager->get_metadata('all') && $md_manager->validate_enable();
+ }
+ catch (\phpbb\extension\exception $e)
+ {
+ return false;
+ }
}
/**
@@ -538,7 +541,7 @@ class manager
*/
public function is_enabled($name)
{
- return isset($this->extensions[$name]) && $this->extensions[$name]['ext_active'];
+ return isset($this->extensions[$name]['ext_active']) && $this->extensions[$name]['ext_active'];
}
/**
@@ -549,7 +552,7 @@ class manager
*/
public function is_disabled($name)
{
- return isset($this->extensions[$name]) && !$this->extensions[$name]['ext_active'];
+ return isset($this->extensions[$name]['ext_active']) && !$this->extensions[$name]['ext_active'];
}
/**
@@ -563,7 +566,7 @@ class manager
*/
public function is_configured($name)
{
- return isset($this->extensions[$name]);
+ return isset($this->extensions[$name]['ext_active']);
}
/**
diff --git a/phpBB/phpbb/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php
index 6fc6dc9891..60b8db8310 100644
--- a/phpBB/phpbb/extension/metadata_manager.php
+++ b/phpBB/phpbb/extension/metadata_manager.php
@@ -19,24 +19,6 @@ namespace phpbb\extension;
class metadata_manager
{
/**
- * phpBB Config instance
- * @var \phpbb\config\config
- */
- protected $config;
-
- /**
- * phpBB Extension Manager
- * @var \phpbb\extension\manager
- */
- protected $extension_manager;
-
- /**
- * phpBB root path
- * @var string
- */
- protected $phpbb_root_path;
-
- /**
* Name (including vendor) of the extension
* @var string
*/
@@ -58,19 +40,13 @@ class metadata_manager
* Creates the metadata manager
*
* @param string $ext_name Name (including vendor) of the extension
- * @param \phpbb\config\config $config phpBB Config instance
- * @param \phpbb\extension\manager $extension_manager An instance of the phpBB extension manager
- * @param string $phpbb_root_path Path to the phpbb includes directory.
+ * @param string $ext_path Path to the extension directory including root path
*/
- public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, $phpbb_root_path)
+ public function __construct($ext_name, $ext_path)
{
- $this->config = $config;
- $this->extension_manager = $extension_manager;
- $this->phpbb_root_path = $phpbb_root_path;
-
$this->ext_name = $ext_name;
$this->metadata = array();
- $this->metadata_file = '';
+ $this->metadata_file = $ext_path . 'composer.json';
}
/**
@@ -81,13 +57,11 @@ class metadata_manager
*/
public function get_metadata($element = 'all')
{
- $this->set_metadata_file();
-
- // Fetch the metadata
- $this->fetch_metadata();
-
- // Clean the metadata
- $this->clean_metadata_array();
+ // Fetch and clean the metadata if not done yet
+ if ($this->metadata === array())
+ {
+ $this->fetch_metadata_from_file();
+ }
switch ($element)
{
@@ -110,52 +84,29 @@ class metadata_manager
}
/**
- * Sets the filepath of the metadata file
+ * Gets the metadata file contents and cleans loaded file
*
* @throws \phpbb\extension\exception
*/
- private function set_metadata_file()
+ private function fetch_metadata_from_file()
{
- $ext_filepath = $this->extension_manager->get_extension_path($this->ext_name);
- $metadata_filepath = $this->phpbb_root_path . $ext_filepath . 'composer.json';
-
- $this->metadata_file = $metadata_filepath;
-
if (!file_exists($this->metadata_file))
{
throw new \phpbb\extension\exception('FILE_NOT_FOUND', array($this->metadata_file));
}
- }
- /**
- * Gets the contents of the composer.json file
- *
- * @return bool True if success, throws an exception on failure
- * @throws \phpbb\extension\exception
- */
- private function fetch_metadata()
- {
- if (!file_exists($this->metadata_file))
+ if (!($file_contents = file_get_contents($this->metadata_file)))
{
- throw new \phpbb\extension\exception('FILE_NOT_FOUND', array($this->metadata_file));
+ throw new \phpbb\extension\exception('FILE_CONTENT_ERR', array($this->metadata_file));
}
- else
- {
- if (!($file_contents = file_get_contents($this->metadata_file)))
- {
- throw new \phpbb\extension\exception('FILE_CONTENT_ERR', array($this->metadata_file));
- }
-
- if (($metadata = json_decode($file_contents, true)) === null)
- {
- throw new \phpbb\extension\exception('FILE_JSON_DECODE_ERR', array($this->metadata_file));
- }
- array_walk_recursive($metadata, array($this, 'sanitize_json'));
- $this->metadata = $metadata;
-
- return true;
+ if (($metadata = json_decode($file_contents, true)) === null)
+ {
+ throw new \phpbb\extension\exception('FILE_JSON_DECODE_ERR', array($this->metadata_file));
}
+
+ array_walk_recursive($metadata, array($this, 'sanitize_json'));
+ $this->metadata = $metadata;
}
/**
@@ -170,16 +121,6 @@ class metadata_manager
}
/**
- * This array handles the cleaning of the array
- *
- * @return array Contains the cleaned metadata array
- */
- private function clean_metadata_array()
- {
- return $this->metadata;
- }
-
- /**
* Validate fields
*
* @param string $name ("all" for display and enable validation
@@ -202,7 +143,7 @@ class metadata_manager
{
case 'all':
$this->validate_enable();
- // no break
+ // no break
case 'display':
foreach ($fields as $field => $data)
@@ -316,40 +257,4 @@ class metadata_manager
return true;
}
-
- /**
- * Outputs the metadata into the template
- *
- * @param \phpbb\template\template $template phpBB Template instance
- */
- public function output_template_data(\phpbb\template\template $template)
- {
- $template->assign_vars(array(
- 'META_NAME' => $this->metadata['name'],
- 'META_TYPE' => $this->metadata['type'],
- 'META_DESCRIPTION' => (isset($this->metadata['description'])) ? $this->metadata['description'] : '',
- 'META_HOMEPAGE' => (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '',
- 'META_VERSION' => (isset($this->metadata['version'])) ? $this->metadata['version'] : '',
- 'META_TIME' => (isset($this->metadata['time'])) ? $this->metadata['time'] : '',
- 'META_LICENSE' => $this->metadata['license'],
-
- 'META_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? $this->metadata['require']['php'] : '',
- 'META_REQUIRE_PHP_FAIL' => (isset($this->metadata['require']['php'])) ? false : true,
-
- 'META_REQUIRE_PHPBB' => (isset($this->metadata['extra']['soft-require']['phpbb/phpbb'])) ? $this->metadata['extra']['soft-require']['phpbb/phpbb'] : '',
- 'META_REQUIRE_PHPBB_FAIL' => (isset($this->metadata['extra']['soft-require']['phpbb/phpbb'])) ? false : true,
-
- 'META_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? $this->metadata['extra']['display-name'] : '',
- ));
-
- foreach ($this->metadata['authors'] as $author)
- {
- $template->assign_block_vars('meta_authors', array(
- 'AUTHOR_NAME' => $author['name'],
- 'AUTHOR_EMAIL' => (isset($author['email'])) ? $author['email'] : '',
- 'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '',
- 'AUTHOR_ROLE' => (isset($author['role'])) ? $author['role'] : '',
- ));
- }
- }
}
diff --git a/phpBB/phpbb/module/module_manager.php b/phpBB/phpbb/module/module_manager.php
index 7ae16cdb61..67bac5b33e 100644
--- a/phpBB/phpbb/module/module_manager.php
+++ b/phpBB/phpbb/module/module_manager.php
@@ -208,7 +208,7 @@ class module_manager
WHERE m1.module_class = '" . $this->db->sql_escape($module_class) . "'
AND m2.module_class = '" . $this->db->sql_escape($module_class) . "'
AND m1.module_id = $module_id
- ORDER BY m2.left_id DESC";
+ ORDER BY m2.left_id";
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
diff --git a/phpBB/phpbb/request/request.php b/phpBB/phpbb/request/request.php
index 92d4213180..00be8fd381 100644
--- a/phpBB/phpbb/request/request.php
+++ b/phpBB/phpbb/request/request.php
@@ -169,12 +169,6 @@ class request implements \phpbb\request\request_interface
$GLOBALS[$this->super_globals[$super_global]][$var_name] = $value;
}
}
-
- if (!$this->super_globals_disabled())
- {
- unset($GLOBALS[$this->super_globals[$super_global]][$var_name]);
- $GLOBALS[$this->super_globals[$super_global]][$var_name] = $value;
- }
}
/**
diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php
index 5d04a09865..5e4f71a2a9 100644
--- a/phpBB/phpbb/template/context.php
+++ b/phpBB/phpbb/template/context.php
@@ -363,10 +363,11 @@ class context
* If key is false the position is set to 0
* If key is true the position is set to the last entry
*
- * @param string $mode Mode to execute (valid modes are 'insert' and 'change')
+ * @param string $mode Mode to execute (valid modes are 'insert', 'change' and 'delete')
*
* If insert, the vararray is inserted at the given position (position counting from zero).
* If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new \value).
+ * If delete, the vararray is ignored, and the block at the given position (counting from zero) is removed.
*
* Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array)
* and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars)
@@ -502,6 +503,45 @@ class context
return true;
}
+ // Delete Block
+ if ($mode == 'delete')
+ {
+ // If we are exceeding last iteration, do not delete anything
+ if ($key > sizeof($block) || $key < 0)
+ {
+ return false;
+ }
+
+ // If we are positioned at the end, we remove the last element
+ if ($key == sizeof($block))
+ {
+ $key--;
+ }
+
+ // We are deleting the last element in the block, so remove the block
+ if (sizeof($block) === 1)
+ {
+ $block = null; // unset($block); does not work on references
+ return true;
+ }
+
+ // Re-position template blocks
+ for ($i = $key; $i < sizeof($block)-1; $i++)
+ {
+ $block[$i] = $block[$i+1];
+ $block[$i]['S_ROW_COUNT'] = $block[$i]['S_ROW_NUM'] = $i;
+ }
+
+ // Remove the last element
+ unset($block[$i]);
+
+ // Set first and last elements again, in case they were removed
+ $block[0]['S_FIRST_ROW'] = true;
+ $block[sizeof($block)-1]['S_LAST_ROW'] = true;
+
+ return true;
+ }
+
return false;
}
diff --git a/phpBB/phpbb/template/template.php b/phpBB/phpbb/template/template.php
index 9e3d658ca8..d1ec442e9a 100644
--- a/phpBB/phpbb/template/template.php
+++ b/phpBB/phpbb/template/template.php
@@ -160,10 +160,11 @@ interface template
* If key is false the position is set to 0
* If key is true the position is set to the last entry
*
- * @param string $mode Mode to execute (valid modes are 'insert' and 'change')
+ * @param string $mode Mode to execute (valid modes are 'insert', 'change' and 'delete')
*
* If insert, the vararray is inserted at the given position (position counting from zero).
* If change, the current block gets merged with the vararray (resulting in new \key/value pairs be added and existing keys be replaced by the new \value).
+ * If delete, the vararray is ignored, and the block at the given position (counting from zero) is removed.
*
* Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array)
* and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars)
diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php
index 179412a2e3..ac4b16e457 100644
--- a/phpBB/phpbb/template/twig/environment.php
+++ b/phpBB/phpbb/template/twig/environment.php
@@ -32,6 +32,9 @@ class environment extends \Twig_Environment
/** @var \phpbb\extension\manager */
protected $extension_manager;
+ /** @var \phpbb\event\dispatcher_interface */
+ protected $phpbb_dispatcher;
+
/** @var string */
protected $phpbb_root_path;
@@ -53,15 +56,17 @@ class environment extends \Twig_Environment
* @param string $cache_path The path to the cache directory
* @param \phpbb\extension\manager $extension_manager phpBB extension manager
* @param \Twig_LoaderInterface $loader Twig loader interface
+ * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object
* @param array $options Array of options to pass to Twig
*/
- public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array())
+ public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, \phpbb\event\dispatcher_interface $phpbb_dispatcher = null, $options = array())
{
$this->phpbb_config = $phpbb_config;
$this->filesystem = $filesystem;
$this->phpbb_path_helper = $path_helper;
$this->extension_manager = $extension_manager;
+ $this->phpbb_dispatcher = $phpbb_dispatcher;
$this->phpbb_root_path = $this->phpbb_path_helper->get_phpbb_root_path();
$this->web_root_path = $this->phpbb_path_helper->get_web_root_path();
@@ -202,8 +207,37 @@ class environment extends \Twig_Environment
$context['definition']->set('STYLESHEETS', '__STYLESHEETS_' . $placeholder_salt . '__');
}
+ /**
+ * Allow changing the template output stream before rendering
+ *
+ * @event core.twig_environment_render_template_before
+ * @var array context Array with template variables
+ * @var string name The template name
+ * @since 3.2.1-RC1
+ */
+ if ($this->phpbb_dispatcher)
+ {
+ $vars = array('context', 'name');
+ extract($this->phpbb_dispatcher->trigger_event('core.twig_environment_render_template_before', compact($vars)));
+ }
+
$output = parent::render($name, $context);
+ /**
+ * Allow changing the template output stream after rendering
+ *
+ * @event core.twig_environment_render_template_after
+ * @var array context Array with template variables
+ * @var string name The template name
+ * @var string output Rendered template output stream
+ * @since 3.2.1-RC1
+ */
+ if ($this->phpbb_dispatcher)
+ {
+ $vars = array('context', 'name', 'output');
+ extract($this->phpbb_dispatcher->trigger_event('core.twig_environment_render_template_after', compact($vars)));
+ }
+
return $this->inject_assets($output, $placeholder_salt);
}
diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php
index 5cbf2712f7..7719ce5afa 100644
--- a/phpBB/phpbb/textformatter/s9e/factory.php
+++ b/phpBB/phpbb/textformatter/s9e/factory.php
@@ -311,7 +311,7 @@ class factory implements \phpbb\textformatter\cache_interface
{
$configurator->Emoticons->set(
$row['code'],
- '<img class="smilies" src="{$T_SMILIES_PATH}/' . htmlspecialchars($row['smiley_url']) . '" width="' . $row['smiley_width'] . '" height="' . $row['smiley_height'] . '" alt="{.}" title="' . htmlspecialchars($row['emotion']) . '"/>'
+ '<img class="smilies" src="{$T_SMILIES_PATH}/' . $this->escape_html_attribute($row['smiley_url']) . '" width="' . $row['smiley_width'] . '" height="' . $row['smiley_height'] . '" alt="{.}" title="' . $this->escape_html_attribute($row['emotion']) . '"/>'
);
}
@@ -442,6 +442,20 @@ class factory implements \phpbb\textformatter\cache_interface
}
/**
+ * Escape a literal to be used in an HTML attribute in an XSL template
+ *
+ * Escapes "HTML special chars" for obvious reasons and curly braces to avoid them
+ * being interpreted as an attribute value template
+ *
+ * @param string $value Original string
+ * @return string Escaped string
+ */
+ protected function escape_html_attribute($value)
+ {
+ return htmlspecialchars(strtr($value, ['{' => '{{', '}' => '}}']), ENT_COMPAT | ENT_XML1, 'UTF-8');
+ }
+
+ /**
* Return the default BBCodes configuration
*
* @return array 2D array. Each element has a 'usage' key, a 'template' key, and an optional 'options' key