mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-22 16:40:21 +01:00
[ticket/15068] Add template vars retrieval from the template object
PHPBB3-15068
This commit is contained in:
parent
3322117c38
commit
f23d9bf2e0
@ -104,6 +104,27 @@ abstract class base implements template
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function retrieve_vars(array $vararray)
|
||||
{
|
||||
$result = array();
|
||||
foreach ($vararray as $varname)
|
||||
{
|
||||
$result[$varname] = $this->retrieve_var($varname);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function retrieve_var($varname)
|
||||
{
|
||||
return $this->context->retrieve_var($varname);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -124,6 +145,14 @@ abstract class base implements template
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function retrieve_block_vars($blockname, array $vararray)
|
||||
{
|
||||
return $this->context->retrieve_block_vars($blockname, $vararray);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -86,6 +86,17 @@ class context
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retreive a single scalar value from a single key.
|
||||
*
|
||||
* @param string $varname Variable name
|
||||
* @return mixed Variable value, or null if not set
|
||||
*/
|
||||
public function retrieve_var($varname)
|
||||
{
|
||||
return isset($this->rootref[$varname]) ? $this->rootref[$varname] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to template data array.
|
||||
*
|
||||
@ -263,6 +274,52 @@ class context
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve key variable pairs from the specified block
|
||||
*
|
||||
* @param string $blockname Name of block to retrieve $vararray from
|
||||
* @param array $vararray An array of variable names
|
||||
* @return array of hashes with variable name as key and retrieved value or null as value
|
||||
*/
|
||||
public function retrieve_block_vars($blockname, array $vararray)
|
||||
{
|
||||
// For nested block, $blockcount > 0, for top-level block, $blockcount == 0
|
||||
$blocks = explode('.', $blockname);
|
||||
$blockcount = sizeof($blocks) - 1;
|
||||
|
||||
$block = $this->tpldata;
|
||||
for ($i = 0; $i <= $blockcount; $i++)
|
||||
{
|
||||
if (($pos = strpos($blocks[$i], '[')) !== false)
|
||||
{
|
||||
$name = substr($blocks[$i], 0, $pos);
|
||||
|
||||
if (strpos($blocks[$i], '[]') === $pos)
|
||||
{
|
||||
$index = sizeof($block[$name]) - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$index = min((int) substr($blocks[$i], $pos + 1, -1), sizeof($block[$name]) - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$name = $blocks[$i];
|
||||
$index = sizeof($block[$name]) - 1;
|
||||
}
|
||||
$block = $block[$name];
|
||||
$block = $block[$index];
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($vararray as $varname)
|
||||
{
|
||||
$result[$varname] = isset($block[$varname]) ? $block[$varname] : null;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change already assigned key variable pair (one-dimensional - single loop entry)
|
||||
*
|
||||
|
@ -127,6 +127,22 @@ interface template
|
||||
*/
|
||||
public function append_var($varname, $varval);
|
||||
|
||||
/**
|
||||
* Retrieve multiple template values
|
||||
*
|
||||
* @param array $vararray An array with variable names
|
||||
* @return array A hash of variable name => value pairs (value is null if not set)
|
||||
*/
|
||||
public function retrieve_vars(array $vararray);
|
||||
|
||||
/**
|
||||
* Retreive a single scalar value from a single key.
|
||||
*
|
||||
* @param string $varname Variable name
|
||||
* @return mixed Variable value, or null if not set
|
||||
*/
|
||||
public function retrieve_var($varname);
|
||||
|
||||
/**
|
||||
* Assign key variable pairs from an array to a specified block
|
||||
* @param string $blockname Name of block to assign $vararray to
|
||||
@ -143,6 +159,14 @@ interface template
|
||||
*/
|
||||
public function assign_block_vars_array($blockname, array $block_vars_array);
|
||||
|
||||
/**
|
||||
* Retrieve variable values from an specified block
|
||||
* @param string $blockname Name of block to retrieve $vararray from
|
||||
* @param array $vararray An array with variable names
|
||||
* @return array A hash of variable name => value pairs (value is null if not set)
|
||||
*/
|
||||
public function retrieve_block_vars($blockname, array $vararray);
|
||||
|
||||
/**
|
||||
* Change already assigned key variable pair (one-dimensional - single loop entry)
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user