phpBB

Code Changes

File: phpbb/template/context.php

  Unmodified   Added   Modified   Removed
Line 142Line 142
	*/
protected function set_num_rows(&$loop_data)
{

	*/
protected function set_num_rows(&$loop_data)
{

		$s_num_rows = sizeof($loop_data);

		$s_num_rows = count($loop_data);

		foreach ($loop_data as &$mod_block)
{
foreach ($mod_block as $sub_block_name => &$sub_block)

		foreach ($loop_data as &$mod_block)
{
foreach ($mod_block as $sub_block_name => &$sub_block)

Line 190Line 190
	public function assign_block_vars($blockname, array $vararray)
{
$this->num_rows_is_set = false;

	public function assign_block_vars($blockname, array $vararray)
{
$this->num_rows_is_set = false;

		if (strpos($blockname, '.') !== false)
{
// Nested block.


// For nested block, $blockcount > 0, for top-level block, $blockcount == 0


			$blocks = explode('.', $blockname);

			$blocks = explode('.', $blockname);

			$blockcount = sizeof($blocks) - 1;

		$blockcount = count($blocks) - 1;





			$str = &$this->tpldata;

		$block = &$this->tpldata;

			for ($i = 0; $i < $blockcount; $i++)
{

			for ($i = 0; $i < $blockcount; $i++)
{

				$str = &$str[$blocks[$i]];
$str = &$str[sizeof($str) - 1];




			$pos = strpos($blocks[$i], '[');
$name = ($pos !== false) ? substr($blocks[$i], 0, $pos) : $blocks[$i];
$block = &$block[$name];
$index = (!$pos || strpos($blocks[$i], '[]') === $pos) ? (count($block) - 1) : (min((int) substr($blocks[$i], $pos + 1, -1), count($block) - 1));
$block = &$block[$index];

			}


			}


			$s_row_count = isset($str[$blocks[$blockcount]]) ? sizeof($str[$blocks[$blockcount]]) : 0;





		// $block = &$block[$blocks[$i]]; // Do not traverse the last block as it might be empty
$name = $blocks[$i];

// Assign S_ROW_COUNT and S_ROW_NUM
$s_row_count = isset($block[$name]) ? count($block[$name]) : 0;

			$vararray['S_ROW_COUNT'] = $vararray['S_ROW_NUM'] = $s_row_count;

// Assign S_FIRST_ROW

			$vararray['S_ROW_COUNT'] = $vararray['S_ROW_NUM'] = $s_row_count;

// Assign S_FIRST_ROW

Line 213Line 219
			}

// Assign S_BLOCK_NAME

			}

// Assign S_BLOCK_NAME

			$vararray['S_BLOCK_NAME'] = $blocks[$blockcount];

		$vararray['S_BLOCK_NAME'] = $name;


// Now the tricky part, we always assign S_LAST_ROW and remove the entry before
// This is much more clever than going through the complete template data on display (phew)
$vararray['S_LAST_ROW'] = true;
if ($s_row_count > 0)
{


// Now the tricky part, we always assign S_LAST_ROW and remove the entry before
// This is much more clever than going through the complete template data on display (phew)
$vararray['S_LAST_ROW'] = true;
if ($s_row_count > 0)
{

				unset($str[$blocks[$blockcount]][($s_row_count - 1)]['S_LAST_ROW']);

			unset($block[$name][($s_row_count - 1)]['S_LAST_ROW']);

			}

// Now we add the block that we're actually assigning to.
// We're adding a new iteration to this block with the given
// variable assignments.

			}

// Now we add the block that we're actually assigning to.
// We're adding a new iteration to this block with the given
// variable assignments.

			$str[$blocks[$blockcount]][] = $vararray;
}
else
{
// Top-level block.
$s_row_count = (isset($this->tpldata[$blockname])) ? sizeof($this->tpldata[$blockname]) : 0;
$vararray['S_ROW_COUNT'] = $vararray['S_ROW_NUM'] = $s_row_count;

// Assign S_FIRST_ROW
if (!$s_row_count)
{
$vararray['S_FIRST_ROW'] = true;
}

// Assign S_BLOCK_NAME
$vararray['S_BLOCK_NAME'] = $blockname;

// We always assign S_LAST_ROW and remove the entry before
$vararray['S_LAST_ROW'] = true;
if ($s_row_count > 0)
{
unset($this->tpldata[$blockname][($s_row_count - 1)]['S_LAST_ROW']);
}

// Add a new iteration to this block with the variable assignments we were given.
$this->tpldata[$blockname][] = $vararray;
}

		$block[$name][] = $vararray;




























return true;
}


return true;
}

Line 285Line 265
	{
// For nested block, $blockcount > 0, for top-level block, $blockcount == 0
$blocks = explode('.', $blockname);

	{
// For nested block, $blockcount > 0, for top-level block, $blockcount == 0
$blocks = explode('.', $blockname);

		$blockcount = sizeof($blocks) - 1;

		$blockcount = count($blocks) - 1;


$block = $this->tpldata;
for ($i = 0; $i <= $blockcount; $i++)


$block = $this->tpldata;
for ($i = 0; $i <= $blockcount; $i++)

Line 296Line 276

if (strpos($blocks[$i], '[]') === $pos)
{


if (strpos($blocks[$i], '[]') === $pos)
{

					$index = sizeof($block[$name]) - 1;

					$index = count($block[$name]) - 1;

				}
else
{

				}
else
{

					$index = min((int) substr($blocks[$i], $pos + 1, -1), sizeof($block[$name]) - 1);

					$index = min((int) substr($blocks[$i], $pos + 1, -1), count($block[$name]) - 1);

				}
}
else
{
$name = $blocks[$i];

				}
}
else
{
$name = $blocks[$i];

				$index = sizeof($block[$name]) - 1;

				$index = count($block[$name]) - 1;

			}
$block = $block[$name];
$block = $block[$index];

			}
$block = $block[$name];
$block = $block[$index];

Line 355Line 335
	{
// For nested block, $blockcount > 0, for top-level block, $blockcount == 0
$blocks = explode('.', $blockname);

	{
// For nested block, $blockcount > 0, for top-level block, $blockcount == 0
$blocks = explode('.', $blockname);

		$blockcount = sizeof($blocks) - 1;

		$blockcount = count($blocks) - 1;


$block = $this->tpldata;
for ($i = 0; $i < $blockcount; $i++)
{


$block = $this->tpldata;
for ($i = 0; $i < $blockcount; $i++)
{

			if (($pos = strpos($blocks[$i], '[')) !== false)
{
$name = substr($blocks[$i], 0, $pos);

			$pos = strpos($blocks[$i], '[');
$name = ($pos !== false) ? substr($blocks[$i], 0, $pos) : $blocks[$i];






				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;
}

 
			if (!isset($block[$name]))
{
return false;
}

			if (!isset($block[$name]))
{
return false;
}

			$block = $block[$name];
if (!isset($block[$index]))




$index = (!$pos || strpos($blocks[$i], '[]') === $pos) ? (count($block[$name]) - 1) : (min((int) substr($blocks[$i], $pos + 1, -1), count($block[$name]) - 1));

if (!isset($block[$name][$index]))

			{
return false;
}

			{
return false;
}

			$block = $block[$index];

			$block = $block[$name][$index];

		}

if (!isset($block[$blocks[$i]]))

		}

if (!isset($block[$blocks[$i]]))

Line 397Line 364
		$block = $block[$blocks[$i]]; // Traverse the last block

// Change key to zero (change first position) if false and to last position if true

		$block = $block[$blocks[$i]]; // Traverse the last block

// Change key to zero (change first position) if false and to last position if true

		if ($key === false || $key === true)

		if (is_bool($key))

		{

		{

			return ($key === false) ? 0 : sizeof($block) - 1;

			return (!$key) ? 0 : count($block) - 1;

		}

// Get correct position if array given

		}

// Get correct position if array given

Line 416Line 383
			}
}


			}
}


		return (is_int($key) && ((0 <= $key) && ($key < sizeof($block)))) ? $key : false;

		return (is_int($key) && ((0 <= $key) && ($key < count($block)))) ? $key : false;

	}

/**

	}

/**

Line 453Line 420

// For nested block, $blockcount > 0, for top-level block, $blockcount == 0
$blocks = explode('.', $blockname);


// For nested block, $blockcount > 0, for top-level block, $blockcount == 0
$blocks = explode('.', $blockname);

		$blockcount = sizeof($blocks) - 1;

		$blockcount = count($blocks) - 1;


$block = &$this->tpldata;
for ($i = 0; $i < $blockcount; $i++)


$block = &$this->tpldata;
for ($i = 0; $i < $blockcount; $i++)

Line 464Line 431

if (strpos($blocks[$i], '[]') === $pos)
{


if (strpos($blocks[$i], '[]') === $pos)
{

					$index = sizeof($block[$name]) - 1;

					$index = count($block[$name]) - 1;

				}
else
{

				}
else
{

					$index = min((int) substr($blocks[$i], $pos + 1, -1), sizeof($block[$name]) - 1);

					$index = min((int) substr($blocks[$i], $pos + 1, -1), count($block[$name]) - 1);

				}
}
else
{
$name = $blocks[$i];

				}
}
else
{
$name = $blocks[$i];

				$index = sizeof($block[$name]) - 1;

				$index = count($block[$name]) - 1;

			}
$block = &$block[$name];
$block = &$block[$index];

			}
$block = &$block[$name];
$block = &$block[$index];

Line 496Line 463
		// Change key to zero (change first position) if false and to last position if true
if ($key === false || $key === true)
{

		// Change key to zero (change first position) if false and to last position if true
if ($key === false || $key === true)
{

			$key = ($key === false) ? 0 : sizeof($block);

			$key = ($key === false) ? 0 : count($block);

		}

// Get correct position if array given

		}

// Get correct position if array given

Line 526Line 493
		if ($mode == 'insert')
{
// Make sure we are not exceeding the last iteration

		if ($mode == 'insert')
{
// Make sure we are not exceeding the last iteration

			if ($key >= sizeof($block))

			if ($key >= count($block))

			{

			{

				$key = sizeof($block);

				$key = count($block);

				unset($block[($key - 1)]['S_LAST_ROW']);
$vararray['S_LAST_ROW'] = true;
}

				unset($block[($key - 1)]['S_LAST_ROW']);
$vararray['S_LAST_ROW'] = true;
}

Line 543Line 510
			$vararray['S_BLOCK_NAME'] = $name;

// Re-position template blocks

			$vararray['S_BLOCK_NAME'] = $name;

// Re-position template blocks

			for ($i = sizeof($block); $i > $key; $i--)

			for ($i = count($block); $i > $key; $i--)

			{
$block[$i] = $block[$i-1];


			{
$block[$i] = $block[$i-1];


Line 561Line 528
		if ($mode == 'change')
{
// If key is out of bounds, do not change anything

		if ($mode == 'change')
{
// If key is out of bounds, do not change anything

			if ($key > sizeof($block) || $key < 0)

			if ($key > count($block) || $key < 0)

			{
return false;
}


			{
return false;
}


			if ($key == sizeof($block))

			if ($key == count($block))

			{
$key--;
}

			{
$key--;
}

Line 580Line 547
		if ($mode == 'delete')
{
// If we are exceeding last iteration, do not delete anything

		if ($mode == 'delete')
{
// If we are exceeding last iteration, do not delete anything

			if ($key > sizeof($block) || $key < 0)

			if ($key > count($block) || $key < 0)

			{
return false;
}

// If we are positioned at the end, we remove the last element

			{
return false;
}

// If we are positioned at the end, we remove the last element

			if ($key == sizeof($block))

			if ($key == count($block))

			{
$key--;
}

// We are deleting the last element in the block, so remove the block

			{
$key--;
}

// We are deleting the last element in the block, so remove the block

			if (sizeof($block) === 1)

			if (count($block) === 1)

			{
$block = null; // unset($block); does not work on references
return true;
}

// Re-position template blocks

			{
$block = null; // unset($block); does not work on references
return true;
}

// Re-position template blocks

			for ($i = $key; $i < sizeof($block)-1; $i++)

			for ($i = $key; $i < count($block)-1; $i++)

			{
$block[$i] = $block[$i+1];
$block[$i]['S_ROW_COUNT'] = $block[$i]['S_ROW_NUM'] = $i;

			{
$block[$i] = $block[$i+1];
$block[$i]['S_ROW_COUNT'] = $block[$i]['S_ROW_NUM'] = $i;

Line 610Line 577

// Set first and last elements again, in case they were removed
$block[0]['S_FIRST_ROW'] = true;


// 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;

			$block[count($block)-1]['S_LAST_ROW'] = true;


return true;
}


return true;
}

Line 631Line 598
		{
// Nested block.
$blocks = explode('.', $blockname);

		{
// Nested block.
$blocks = explode('.', $blockname);

			$blockcount = sizeof($blocks) - 1;

			$blockcount = count($blocks) - 1;


$str = &$this->tpldata;
for ($i = 0; $i < $blockcount; $i++)
{
$str = &$str[$blocks[$i]];


$str = &$this->tpldata;
for ($i = 0; $i < $blockcount; $i++)
{
$str = &$str[$blocks[$i]];

				$str = &$str[sizeof($str) - 1];

				$str = &$str[count($str) - 1];

			}

unset($str[$blocks[$blockcount]]);

			}

unset($str[$blocks[$blockcount]]);