Plugin index
<?php
if (class_exists('\Textpattern\Tag\Registry')) {
Txp::get('\Textpattern\Tag\Registry')
->register('rvm_inherit')
->register('rvm_block')
->register('rvm_child')
->register('rvm_parent');
}
function rvm_inherit($atts, $thing = null)
{
static $stack = array();
extract(lAtts(array(
'page' => false,
'form' => false
), $atts));
$out = '';
rvm_block(false);
if ($thing !== null)
{
parse($thing);
}
else
{
trigger_error('rvm_inherit should be used as a container tag');
}
rvm_block(true);
if ($page === false and $form === false)
{
$page = 'default';
}
if ($page !== false)
{
if (in_array($page, $stack, true))
{
trigger_error('circular page reference: ' . array_pop($stack) . ' calls ' . $page);
}
else
{
$stack[] = $page;
if (is_callable('fetch_page'))
{
$page = fetch_page($page);
}
else
{
$page = safe_field('user_html','txp_page',"name='".doSlash($page)."'");
}
$out = ($page === false ? '' : parse($page));
}
}
else
{
$out = parse_form($form);
}
rvm_block(false);
return $out;
}
function rvm_block($atts, $thing = null)
{
static $parse = true;
static $chain = array();
static $children = array();
static $parents = array();
static $queue = array();
if (is_bool($atts))
{
$parse = $atts;
return;
}
extract(lAtts(array(
'name' => false,
'child' => false,
'parent' => false
), $atts));
$out = '';
if ($child or $parent)
{
if ($thing !== null)
{
trigger_error('ignoring container contents because child or parent attribute is specified');
}
if ($name === false)
{
if (!empty($queue))
{
$name = end($queue);
}
elseif ($parent)
{
trigger_error('use of parent attribute in a standalone block tag is not allowed');
}
}
}
if ($name === false)
{
$name = '';
}
if ($child !== false)
{
if (assert_int($child) and $child > 0)
{
if (!isset($children[$name]))
{
$children[$name] = count($chain[$name]);
}
$children[$name] -= $child;
if (isset($chain[$name]) and $children[$name] >= 0)
{
$thing = $chain[$name][$children[$name]];
$out = ($thing === null ? '' : parse($thing));
}
}
}
elseif ($parent !== false)
{
if (assert_int($parent) and $parent > 0)
{
if (!isset($parents[$name]))
{
$parents[$name] = 0;
}
$parents[$name] += $parent;
if (isset($chain[$name]) and $parents[$name] < count($chain[$name]))
{
$thing = $chain[$name][$parents[$name]];
$out = ($thing === null ? '' : parse($thing));
}
else
{
trigger_error('missing parent');
}
}
}
else
{
$chain[$name][] = $thing;
if ($parse)
{
if (in_array($name, $queue))
{
trigger_error('do not nest blocks with the same name, unless it is a parent/child construct.');
}
else
{
$queue[] = $name;
$thing = $chain[$name][0];
$out = ($thing === null ? '' : parse($thing));
array_pop($queue);
}
array_pop($chain[$name]); # needed in case a template contains the same block more then once.
}
}
return $out;
}
function rvm_child($atts, $thing = null)
{
$atts['child'] = 1;
return rvm_block($atts);
}
function rvm_parent($atts, $thing = null)
{
$atts['parent'] = 1;
return rvm_block($atts);
}
?>