# will encode foo (using enc_html()) before displaying it, so that characters
# such as < will display properly.
function enc_jsdq($str) {
$str = enc_sql($str);
$str = str_replace("\n", "\\n", $str);
return str_replace("\r", "\\r", $str);
}
# encode for putting within double-quotes in SQL
function enc_sql($str) {
$str = str_replace("\\", "\\\\", $str);
$str = str_replace('"', "\\\"", $str);
return $str;
}
# Encode for output in html. does nothing with whitespace
#
# Example:
~foo.html~
function enc_html($str) {
$str = str_replace('&', '&', $str);
$str = str_replace('<', '<', $str);
$str = str_replace('>', '>', $str);
return $str;
}
# Encode for output in html. Convert newlines to
#
# Example:
~foo.html~
function enc_htmlbr($str) {
$str = enc_html($str);
$str = str_replace("\n", " \n", $str);
return $str;
}
# HTML attribute.
#
# Example:
function enc_attr($str) {
$str = str_replace('&', '&', $str);
$str = str_replace('"', '"', $str);
return $str;
}
# URI agument value.
#
# Example: http://example.com?foo=~foo.url_val~
function enc_url_val($str) {
return rawurlencode($str);
}
# FIXME
function enc_url_path($str) {
$str = rawurlencode($str);
$str = str_replace('%2F', '/', $str);
return $str;
}
# This is a hack to work around html's stupid syntax for checkboxes.
#
# Place the template marker just before a " somewhere.
#
# Example:
function enc_checked($str) {
if($str == 'Yes') {
return '" checked="checked';
} else {
return '';
}
}
# add a tab at the begining of each non-empty line
function enc_tab($str) {
$lines = explode("\n", $str);
$out = '';
foreach($lines as $line) {
if($line) {
$out .= "\t$line";
}
$out .= "\n";
}
# remove the extra newline added above
return substr($out, 0, -1);
}
function enc_upper($str) {
return strtoupper($str);
}
function enc_ddmmyyyyhhmm($seconds) {
return date('m/d/Y g:ia', (int)$seconds);
}
# display