psr12 fixes for new PHP_CodeSniffer (#4795)
[openemr.git] / portal / patient / fwk / libs / savant / Savant3 / resources / Savant3_Plugin_ahref.php
blobb85f4b4289e0bc7d0da2bd900c108e5d16c25938
1 <?php
3 /**
5 * Generates an <a href="">...</a> tag.
7 * @package Savant3
9 * @author Paul M. Jones <pmjones@ciaweb.net>
11 * @license http://www.gnu.org/copyleft/lesser.html LGPL
13 * @version $Id: Savant3_Plugin_ahref.php,v 1.4 2005/08/09 12:56:14 pmjones Exp $
17 /**
19 * Generates an <a href="">...</a> tag.
21 * @package Savant3
23 * @author Paul M. Jones <pmjones@ciaweb.net>
27 class Savant3_Plugin_ahref extends Savant3_Plugin
29 /**
31 * Generate an HTML <a href="">...</a> tag.
33 * @access public
35 * @param string|array $href
36 * A string URL for the resulting tag. May
37 * also be an array with any combination of the keys 'scheme',
38 * 'host', 'path', 'query', and 'fragment' (c.f. PHP's native
39 * parse_url() function).
41 * @param string $text
42 * The displayed text of the link.
44 * @param string|array $attr
45 * Any extra attributes for the <a> tag.
47 * @return string The <a href="">...</a> tag.
50 public function ahref($href, $text, $attr = null)
52 $html = '<a href="';
54 if (is_array($href)) {
55 // add the HREF from an array
56 $tmp = '';
58 if (isset($href ['scheme'])) {
59 $tmp .= $href ['scheme'] . ':';
60 if (strtolower($href ['scheme']) != 'mailto') {
61 $tmp .= '//';
65 if (isset($href ['host'])) {
66 $tmp .= $href ['host'];
69 if (isset($href ['path'])) {
70 $tmp .= $href ['path'];
73 if (isset($href ['query'])) {
74 $tmp .= '?' . $href ['query'];
77 if (isset($href ['fragment'])) {
78 $tmp .= '#' . $href ['fragment'];
81 $html .= htmlspecialchars($tmp);
82 } else {
83 // add the HREF from a scalar
84 $html .= htmlspecialchars($href);
87 $html .= '"';
89 // add attributes
90 if (is_array($attr)) {
91 // from array
92 foreach ($attr as $key => $val) {
93 $key = htmlspecialchars($key);
94 $val = htmlspecialchars($val);
95 $html .= " $key=\"$val\"";
97 } elseif (! is_null($attr)) {
98 // from scalar
99 $html .= htmlspecialchars(" $attr");
102 // set the link text, close the tag, and return
103 $html .= '>' . $text . '</a>';
104 return $html;