Added html_print_anchor function for link tags

This commit is contained in:
Jose Gonzalez 2020-11-06 12:38:06 +01:00
parent b5dc75ce93
commit 22ae632850
1 changed files with 49 additions and 0 deletions

View File

@ -2159,6 +2159,55 @@ function html_print_div($options, $return=false)
}
/**
* Render an anchor html element.
*
* @param array $options Parameters
* - id: string
* - style: string
* - title: string
* - href: string.
* @param boolean $return Return or echo flag.
*
* @return string HTML code if return parameter is true.
*/
function html_print_anchor(
array $options,
bool $return=false
) {
$output = '<a ';
// Valid attributes (invalid attributes get skipped).
$attrs = [
'id',
'style',
'class',
'title',
];
$output .= (isset($options['href']) === true) ? 'href="'.io_safe_input_html($options['href']).'"' : ui_get_full_url();
foreach ($attrs as $attribute) {
if (isset($options[$attribute])) {
$output .= ' '.$attribute.'="'.io_safe_input_html($options[$attribute]).'"';
}
}
$output .= '>';
$output .= (isset($options['content']) === true) ? io_safe_input_html($options['content']) : '';
$output .= '</a>';
if ($return === true) {
return $output;
} else {
echo $output;
}
}
/**
* Render an input password element.
*