BBCode::FillTemplate( $template,  $insert_array,  $default_array = array() )

Description

Source

File: bp-forums/admin/parser.php

function FillTemplate($template, $insert_array, $default_array = Array()) {
$pieces = preg_split('/(\{\$[a-zA-Z0-9_.:\/-]+\})/', $template,
-1, PREG_SPLIT_DELIM_CAPTURE);
if (count($pieces) <= 1)
return $template;
$result = Array();
$is_an_insert = false;
foreach ($pieces as $piece) {
if (!$is_an_insert) {
$result[] = $piece;
}
else if (!preg_match('/\{\$([a-zA-Z0-9_:-]+)((?:\\.[a-zA-Z0-9_:-]+)*)(?:\/([a-zA-Z0-9_:-]+))?\}/', $piece, $matches)) {
$result[] = $piece;
}
else {
if (isset($insert_array[$matches[1]]))
$value = @$insert_array[$matches[1]];
else $value = @$default_array[$matches[1]];
if (strlen(@$matches[2])) {
foreach (explode(".", substr($matches[2], 1)) as $index) { 
if (is_array($value))
$value = @$value[$index];
else if (is_object($value)) {
$value = (array)$value;
$value = @$value[$index];
}
else $value = "";
}
}
switch (gettype($value)) {
case 'boolean': $value = $value ? "true" : "false"; break;
case 'integer': $value = (string)$value; break;
case 'double': $value = (string)$value; break;
case 'string': break;
default: $value = ""; break;
}
if (strlen(@$matches[3]))
$flags = array_flip(str_split($matches[3]));
else $flags = Array();
if (!isset($flags['v'])) {
if (isset($flags['w']))
$value = preg_replace("/[\\x00-\\x09\\x0B-\x0C\x0E-\\x20]+/", " ", $value);
if (isset($flags['t'])) $value = trim($value);
if (isset($flags['b'])) $value = basename($value);
if (isset($flags['e'])) $value = $this->HTMLEncode($value);
else if (isset($flags['k'])) $value = $this->Wikify($value);
else if (isset($flags['h'])) $value = htmlspecialchars($value);
else if (isset($flags['u'])) $value = urlencode($value);
if (isset($flags['n'])) $value = $this->nl2br($value);
}
$result[] = $value;
}
$is_an_insert = !$is_an_insert;
}
return implode("", $result);
}

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.