aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/template
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/template')
-rw-r--r--phpBB/phpbb/template/asset.php1
-rw-r--r--phpBB/phpbb/template/context.php78
-rw-r--r--phpBB/phpbb/template/twig/definition.php2
-rw-r--r--phpBB/phpbb/template/twig/environment.php9
-rw-r--r--phpBB/phpbb/template/twig/extension.php1
5 files changed, 65 insertions, 26 deletions
diff --git a/phpBB/phpbb/template/asset.php b/phpBB/phpbb/template/asset.php
index 5a01ee3a93..67dbd7b357 100644
--- a/phpBB/phpbb/template/asset.php
+++ b/phpBB/phpbb/template/asset.php
@@ -24,6 +24,7 @@ class asset
* Constructor
*
* @param string $url URL
+ * @param \phpbb\path_helper $path_helper Path helper object
*/
public function __construct($url, \phpbb\path_helper $path_helper)
{
diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php
index 0a32879943..4ee48205c8 100644
--- a/phpBB/phpbb/template/context.php
+++ b/phpBB/phpbb/template/context.php
@@ -34,6 +34,11 @@ class context
*/
private $rootref;
+ /**
+ * @var bool
+ */
+ private $num_rows_is_set;
+
public function __construct()
{
$this->clear();
@@ -46,6 +51,7 @@ class context
{
$this->tpldata = array('.' => array(0 => array()));
$this->rootref = &$this->tpldata['.'][0];
+ $this->num_rows_is_set = false;
}
/**
@@ -95,10 +101,59 @@ class context
// returning a reference directly is not
// something php is capable of doing
$ref = &$this->tpldata;
+
+ if (!$this->num_rows_is_set)
+ {
+ /*
+ * We do not set S_NUM_ROWS while adding a row, to reduce the complexity
+ * If we would set it on adding, each subsequent adding would cause
+ * n modifications, resulting in a O(n!) complexity, rather then O(n)
+ */
+ foreach ($ref as $loop_name => &$loop_data)
+ {
+ if ($loop_name === '.')
+ {
+ continue;
+ }
+
+ $this->set_num_rows($loop_data);
+ }
+ $this->num_rows_is_set = true;
+ }
+
return $ref;
}
/**
+ * Set S_NUM_ROWS for each row in this template block
+ *
+ * @param array $loop_data
+ */
+ protected function set_num_rows(&$loop_data)
+ {
+ $s_num_rows = sizeof($loop_data);
+ foreach ($loop_data as &$mod_block)
+ {
+ foreach ($mod_block as $sub_block_name => &$sub_block)
+ {
+ // If the key name is lowercase and the data is an array,
+ // it could be a template loop. So we set the S_NUM_ROWS there
+ // aswell.
+ if ($sub_block_name === strtolower($sub_block_name) && is_array($sub_block))
+ {
+ $this->set_num_rows($sub_block);
+ }
+ }
+
+ // Check whether we are inside a block before setting the variable
+ if (isset($mod_block['S_BLOCK_NAME']))
+ {
+ $mod_block['S_NUM_ROWS'] = $s_num_rows;
+ }
+ }
+ }
+
+ /**
* Returns a reference to template root scope.
*
* This function is public so that template renderer may invoke it.
@@ -123,6 +178,7 @@ class context
*/
public function assign_block_vars($blockname, array $vararray)
{
+ $this->num_rows_is_set = false;
if (strpos($blockname, '.') !== false)
{
// Nested block.
@@ -160,13 +216,6 @@ class context
// We're adding a new iteration to this block with the given
// variable assignments.
$str[$blocks[$blockcount]][] = $vararray;
- $s_num_rows = sizeof($str[$blocks[$blockcount]]);
-
- // Set S_NUM_ROWS
- foreach ($str[$blocks[$blockcount]] as &$mod_block)
- {
- $mod_block['S_NUM_ROWS'] = $s_num_rows;
- }
}
else
{
@@ -192,13 +241,6 @@ class context
// Add a new iteration to this block with the variable assignments we were given.
$this->tpldata[$blockname][] = $vararray;
- $s_num_rows = sizeof($this->tpldata[$blockname]);
-
- // Set S_NUM_ROWS
- foreach ($this->tpldata[$blockname] as &$mod_block)
- {
- $mod_block['S_NUM_ROWS'] = $s_num_rows;
- }
}
return true;
@@ -250,6 +292,7 @@ class context
*/
public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert')
{
+ $this->num_rows_is_set = false;
if (strpos($blockname, '.') !== false)
{
// Nested block.
@@ -349,12 +392,6 @@ class context
$block[$key] = $vararray;
$block[$key]['S_ROW_COUNT'] = $block[$key]['S_ROW_NUM'] = $key;
- // Set S_NUM_ROWS
- foreach ($this->tpldata[$blockname] as &$mod_block)
- {
- $mod_block['S_NUM_ROWS'] = sizeof($this->tpldata[$blockname]);
- }
-
return true;
}
@@ -382,6 +419,7 @@ class context
*/
public function destroy_block_vars($blockname)
{
+ $this->num_rows_is_set = false;
if (strpos($blockname, '.') !== false)
{
// Nested block.
diff --git a/phpBB/phpbb/template/twig/definition.php b/phpBB/phpbb/template/twig/definition.php
index 39653f6d26..cb3c953692 100644
--- a/phpBB/phpbb/template/twig/definition.php
+++ b/phpBB/phpbb/template/twig/definition.php
@@ -25,6 +25,8 @@ class definition
* Get a DEFINE'd variable
*
* @param string $name
+ * @param array $arguments
+ *
* @return mixed Null if not found
*/
public function __call($name, $arguments)
diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php
index 8d25153e14..476ffd935e 100644
--- a/phpBB/phpbb/template/twig/environment.php
+++ b/phpBB/phpbb/template/twig/environment.php
@@ -36,11 +36,10 @@ class environment extends \Twig_Environment
/**
* Constructor
*
- * @param \phpbb\config\config $phpbb_config
- * @param \phpbb\path_helper
- * @param \phpbb\extension\manager
- * @param string $phpbb_root_path
- * @param \Twig_LoaderInterface $loader
+ * @param \phpbb\config\config $phpbb_config The phpBB configuration
+ * @param \phpbb\path_helper $path_helper phpBB path helper
+ * @param \phpbb\extension\manager $extension_manager phpBB extension manager
+ * @param \Twig_LoaderInterface $loader Twig loader interface
* @param array $options Array of options to pass to Twig
*/
public function __construct($phpbb_config, \phpbb\path_helper $path_helper, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array())
diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php
index 8f523684dd..3a983491b9 100644
--- a/phpBB/phpbb/template/twig/extension.php
+++ b/phpBB/phpbb/template/twig/extension.php
@@ -162,7 +162,6 @@ class extension extends \Twig_Extension
* (e.g. in the ACP, L_TITLE)
* If not, we return the result of $user->lang()
*
- * @param string $lang name
* @return string
*/
function lang()