Example #1
0
function SubstituteValueWorker($a_matches, $s_repl, $b_html = true)
{
    global $aSubstituteErrors, $aSubstituteValues, $SPECIAL_VALUES;
    $s_name = $a_matches[1];
    $s_value = "";
    if (isset($aSubstituteValues[$s_name]) && !empty($aSubstituteValues[$s_name])) {
        if (is_array($aSubstituteValues[$s_name])) {
            //
            // note that the separator can include HTML special chars
            //
            $s_value = implode($SPECIAL_VALUES['template_list_sep'], $b_html ? ArrayHTMLSpecialChars($aSubstituteValues[$s_name]) : $aSubstituteValues[$s_name]);
        } else {
            $s_value = $b_html ? htmlspecialchars((string) $aSubstituteValues[$s_name]) : (string) $aSubstituteValues[$s_name];
        }
        if ($b_html) {
            //
            // Replace newlines with HTML line breaks.
            //
            $s_value = nl2br($s_value);
        }
    } elseif (isset($SPECIAL_VALUES[$s_name])) {
        $s_value = $b_html ? htmlspecialchars((string) $SPECIAL_VALUES[$s_name]) : (string) $SPECIAL_VALUES[$s_name];
    } elseif (isset($s_repl)) {
        //
        // If a replacement value has been specified use it, and
        // don't call htmlspecialchars.  This allows the use
        // of HTML tags in a replacement string.
        //
        $s_value = $s_repl;
    } else {
        $aSubstituteErrors[] = GetMessage(MSG_FLD_NOTFOUND, array("FIELD" => $s_name));
    }
    return $s_value;
}
function ArrayHTMLSpecialChars($a_list)
{
    $a_new = array();
    foreach ($a_list as $m_key => $m_value) {
        if (is_array($m_value)) {
            $a_new[$m_key] = ArrayHTMLSpecialChars($m_value);
        } else {
            $a_new[$m_key] = htmlspecialchars($m_value);
        }
    }
    return $a_new;
}
Example #3
0
function SubstituteValueWorker($a_matches, $s_repl, $b_html = true)
{
    global $aSubstituteErrors, $aSubstituteValues, $SPECIAL_VALUES;
    $b_insert_br = true;
    // option to put "<br />" tags before newlines in HTML templates
    $s_name = $a_matches[0];
    assert(strlen($s_name) > 1 && $s_name[0] == '$');
    $s_name = substr($s_name, 1);
    if (($i_len = strlen($s_name)) > 0 && $s_name[0] == '{') {
        assert($s_name[$i_len - 1] == '}');
        $s_name = substr($s_name, 1, -1);
        //
        // grab any processing options
        //
        $a_args = explode(":", $s_name);
        $s_name = $a_args[0];
        if (($n_args = count($a_args)) > 1) {
            for ($ii = 1; $ii < $n_args; $ii++) {
                switch ($a_args[$ii]) {
                    case "nobr":
                        $b_insert_br = false;
                        break;
                }
            }
        }
    }
    $s_value = "";
    if (IsFieldSet($s_name, $aSubstituteValues) && !TestFieldEmpty($s_name, $aSubstituteValues, $s_mesg)) {
        if (is_array($aSubstituteValues[$s_name])) {
            //
            // note that the separator can include HTML special chars
            //
            $s_value = implode($SPECIAL_VALUES['template_list_sep'], $b_html ? ArrayHTMLSpecialChars($aSubstituteValues[$s_name]) : $aSubstituteValues[$s_name]);
        } else {
            $s_value = GetFieldValue($s_name, $aSubstituteValues);
            if ($b_html) {
                $s_value = htmlspecialchars($s_value);
            }
        }
        if ($b_html && $b_insert_br) {
            //
            // Insert HTML line breaks before newlines.
            //
            $s_value = nl2br($s_value);
        }
    } elseif (isset($SPECIAL_VALUES[$s_name])) {
        $s_value = $b_html ? htmlspecialchars((string) $SPECIAL_VALUES[$s_name]) : (string) $SPECIAL_VALUES[$s_name];
    } elseif (isset($s_repl)) {
        //
        // If a replacement value has been specified use it, and
        // don't call htmlspecialchars.  This allows the use
        // of HTML tags in a replacement string.
        //
        $s_value = $s_repl;
    } else {
        $aSubstituteErrors[] = GetMessage(MSG_FLD_NOTFOUND, array("FIELD" => $s_name));
    }
    return $s_value;
}