5 * Generates an <a href="">...</a> tag.
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 $
19 * Generates an <a href="">...</a> tag.
23 * @author Paul M. Jones <pmjones@ciaweb.net>
27 class Savant3_Plugin_ahref
extends Savant3_Plugin
31 * Generate an HTML <a href="">...</a> tag.
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).
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)
54 if (is_array($href)) {
55 // add the HREF from an array
58 if (isset($href ['scheme'])) {
59 $tmp .= $href ['scheme'] . ':';
60 if (strtolower($href ['scheme']) != 'mailto') {
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);
83 // add the HREF from a scalar
84 $html .= htmlspecialchars($href);
90 if (is_array($attr)) {
92 foreach ($attr as $key => $val) {
93 $key = htmlspecialchars($key);
94 $val = htmlspecialchars($val);
95 $html .= " $key=\"$val\"";
97 } elseif (! is_null($attr)) {
99 $html .= htmlspecialchars(" $attr");
102 // set the link text, close the tag, and return
103 $html .= '>' . $text . '</a>';