s:
* .type_unset Unset PHP variables
* .type_null NULL values from databases
* .type_resource PHP resources (file handles etc.)
* .type_syntax parentheses, commas etc.
* .type_bool boolean values
* .type_scalar numbers and strings
* .type_controlcode nonprintable characters in strings
* .type_unkown other type (probably the effect of a bug)
*/
if(!isset($what)) {
return 'Unset';
} elseif(is_null($what)) {
return 'NULL';
} elseif(is_resource($what)) {
return
''
. htmlentities(get_resource_type($what), ENT_QUOTES)
. '';
} elseif(is_array($what) || is_object($what)) {
$a = array();
foreach($what as $id=>$v) {
$a[] =
RuleTableHtmlDump($id)
. ' => '
. RuleTableHtmlDump($v);
}
return implode(',
', $a);
} elseif(is_bool($what)) {
return
''
. ($what ? 'True' : 'False')
. '';
} elseif(is_scalar($what)) {
global $Charset, $KeepToken;
$ktchar = $KeepToken[0]; # add $KeepToken character to list for old pmwiki versions - cgg
$ktrepl = '\\x' . bin2hex($ktchar);
return
''
. str_replace(
array(
"\x00", "\x01", "\x02", "\x03",
"\x04", "\x05", "\x06", "\x07",
"\x08", "\x09", "\x0a", "\x0b",
"\x0c", "\x0d", "\x0e", "\x0f",
"\x10", "\x11", "\x12", "\x13",
"\x14", "\x15", "\x16", "\x17",
"\x18", "\x19", "\x1a", "\x1b",
"\x1c", "\x1d", "\x1e", "\x1f",
$ktchar),
array(
'\\x00',
'\\x01',
'\\x02',
'\\x03',
'\\x04',
'\\x05',
'\\x06',
'\\x07',
'\\x08',
'\\t',
'\\n',
'\\x0b',
'\\x0c',
'\\r',
'\\x0e',
'\\x0f',
'\\x10',
'\\x11',
'\\x12',
'\\x13',
'\\x14',
'\\x15',
'\\x16',
'\\x17',
'\\x18',
'\\x19',
'\\x1a',
'\\x1b',
'\\x1c',
'\\x1d',
'\\x1e',
'\\x1f',
''.$ktrepl.''),
htmlentities($what, ENT_QUOTES, $Charset)) # add char set for new php versions - cgg
. '';
} else {
return 'Unknown datatype';
}
}
function RuleTableColsCB($columns, $rule) {
#SDV ($columns, array());
#SDV ($rule, array());
return array_merge($columns, $rule);
}
function RuleTableEPatCB($m) {
return '^' . preg_quote($m[1],'/') . '(.*)' . preg_quote($m[2],'/') . '$';
}
function RuleTableHandler($pagename) {
global $ScriptUrl;
global $MarkupTable;
BuildMarkupRules();
$out = array();
# Collect available columns
$RuleTableColumns =
array_keys(
array_reduce(
$MarkupTable, 'RuleTableColsCB', array()
)
);
# Further restrict to those listed in ?columns=...
if(isset($_REQUEST['columns'])) {
$RuleTableColumns =
array_intersect(
explode(',', $_REQUEST['columns']),
$RuleTableColumns);
}
$out[] = '';
$out[] = '';
$out[] = '
Markup rules, in order of application (duplicate patterns and patterns using the deprecated /e flag are highlighted):
'; $out[] = 'id | '; foreach($RuleTableColumns as $m) { $out[] = "$m | "; } $out[] = '
---|---|
' . htmlentities($id, ENT_QUOTES) . ' | '; foreach($RuleTableColumns as $n) { $cellattr = ''; #cgg $prefix = ''; #cgg # $comment = ''; #cgg $comments = array(); #cgg $val = @$m[@$n]; if ($n == 'rep') { if (is_callable($val)) { if (is_a($val, 'Closure')) { $val = ''; $prefix = 'Closure Object'; } elseif (preg_match('/^((.*?)lambda_\\d+)$/', (string)$val, $matches)) { # Retrieve replacement code from callback function cache -cgg $lambda = preg_replace_callback('/([\x00-\x2f\x7f-\xff])/',$trfunc,$matches[1]); if (isset($lambdas[$lambda])) { $val = $lambdas[$lambda]; $val2 = preg_replace("/$markupEPat/s", '$1', $val, 1); if ($val2 !== $val) { $val = $val2; $color = ($matches[2] != "\x00") ? '#f00' : 'blue'; $prefix = 'Markup_e: '; } } else { $val = $lambda; } } } } elseif ($n == 'pat') { # Highlight pattern if /e flag present -cgg if (preg_match('!^/(?>.*/)(?=[a-z]*$).*?e!is', strval($val))) { $cellattr = ' class="patbad"'; } if (@$patterns[$val] && $val != '' && $val != 'Unset') { $comments[] = '";
$divclass = (preg_match('/^(?:seq|dep|cmd)$/', $n) ? '' : ' class="wide"');
$out[] = " " . $prefix . RuleTableHtmlDump($val) . ' ';
# if ($comment !== '') {
# $out[] = " " . $comment;
# }
if ($comments) {
$out = array_merge($out, $comments);
}
$out[] = ' | ';
}
$out[] = '