# PLUGIN PREVIEW BY TEXTPATTERN.INFO
// TXP 4.6 tag registration
if (class_exists('\Textpattern\Tag\Registry')) {
Txp::get('\Textpattern\Tag\Registry')
->register('adi_if_content')
->register('adi_if_content_insert')
->register('adi_if_content_ignore')
;
}
/*
global $prefs;
if (!isset($prefs['adi_if_content_ignore']))
set_pref('adi_if_content_ignore', $prefs['adi_if_content_ignore'] = 'site_name,site_slogan,site_url,text', 'adi_if_cnt', PREF_ADVANCED);
*/
function adi_if_content_insert($atts, $thing='') {
return parse($thing);
}
function adi_if_content_ignore($atts, $thing='') {
return parse($thing);
}
function adi_if_content($atts, $thing='') {
global $variable, $txp_parsed, $txp_else;
extract(lAtts(array(
'name' => NULL,
'test' => '',
'insert' => '',
'ignore' => get_pref('adi_if_content_ignore')
), $atts));
if ($name !== null) { /* variable mode */
return parse($thing, isset($variable[$name]) && trim($variable[$name]) !== '');
}
$test = $test ? do_list_unique($test) : array();
$insert = $insert ? do_list_unique($insert) : array();
$insert[] = 'adi_if_content_insert';
$ignore = $ignore ? do_list_unique($ignore) : array();
$ignore[] = 'adi_if_content_ignore';
$tag = $txp_parsed[$hash = sha1($thing)];
if (empty($tag)) return $thing;
$nr = $txp_else[$hash][0] - 2;
$n = 1;
for ($isempty = TRUE, $tags = array(), $out = $tag[0], $i = 0; $n <= $nr; $n++) {
$t = $tag[$n];
if (in_array($t[1], $insert)) {
$out .= "<txp:$i />";
$tags[$i++] = $t;
} else {
$out .= ($nextag = processTags($t[1], $t[2], $t[3]));
$isempty &= trim($nextag) === '' || ($test ? !in_array($t[1], $test) : in_array($t[1], $ignore));
}
$out .= $tag[++$n];
}
if (!$isempty) {
$replacements = array();
foreach ($tags as $i => $t) {
$replacements["<txp:$i />"] = processTags($t[1], $t[2], $t[3]);
}
$out = strtr($out, $replacements);
}
return $isempty ? parse($thing, false) : $out;
}