From 6edb574e192d8b3fe9dc882dabc258489d6d08c9 Mon Sep 17 00:00:00 2001 From: pdontthink Date: Thu, 4 Jan 2007 07:23:03 +0000 Subject: [PATCH] Add attribute array to hyperlink/image/span templates for future extensibility git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@12062 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/html.php | 53 +++++++++++++++++++++++++-------- templates/default/hyperlink.tpl | 35 ++++++++++++++++------ templates/default/image.tpl | 24 ++++++++++++++- templates/default/span.tpl | 21 ++++++++++--- 4 files changed, 106 insertions(+), 27 deletions(-) diff --git a/functions/html.php b/functions/html.php index cfd0652a..85679f10 100644 --- a/functions/html.php +++ b/functions/html.php @@ -18,16 +18,23 @@ /** * Generates a hyperlink * - * @param string $uri The target link location - * @param string $text The link text - * @param string $target The location where the link should - * be opened (OPTIONAL; default not used) - * @param string $onclick The onClick JavaScript handler (OPTIONAL; - * default not used) - * @param string $class The CSS class name (OPTIONAL; default - * not used) - * @param string $id The ID name (OPTIONAL; default not used) - * @param string $name The anchor name (OPTIONAL; default not used) + * @param string $uri The target link location + * @param string $text The link text + * @param string $target The location where the link should + * be opened (OPTIONAL; default not used) + * @param string $onclick The onClick JavaScript handler (OPTIONAL; + * default not used) + * @param string $class The CSS class name (OPTIONAL; default + * not used) + * @param string $id The ID name (OPTIONAL; default not used) + * @param string $name The anchor name (OPTIONAL; default not used) + * @param array $aAttribs Any extra attributes: this must be an + * associative array, where keys will be + * added as the attribute name, and values + * (which are optional - should be null if + * none should be used) will be placed in + * double quotes (pending template implementation) + * as the attribute value (OPTIONAL; default empty). * * @return string The desired hyperlink tag. * @@ -35,7 +42,7 @@ * */ function create_hyperlink($uri, $text, $target='', $onclick='', - $class='', $id='', $name='') { + $class='', $id='', $name='', $aAttribs=array()) { global $oTemplate; @@ -47,6 +54,8 @@ function create_hyperlink($uri, $text, $target='', $onclick='', $oTemplate->assign('id', $id); $oTemplate->assign('name', $name); + $oTemplate->assign('aAttribs', $aAttribs); + return $oTemplate->fetch('hyperlink.tpl'); } @@ -83,6 +92,13 @@ function create_hyperlink($uri, $text, $target='', $onclick='', * if for some reason the image tag * cannot or should not be produced * (OPTIONAL; default not used) + * @param array $aAttribs Any extra attributes: this must be an + * associative array, where keys will be + * added as the attribute name, and values + * (which are optional - should be null if + * none should be used) will be placed in + * double quotes (pending template implementation) + * as the attribute value (OPTIONAL; default empty). * * @return string The desired hyperlink tag. * @@ -92,7 +108,7 @@ function create_hyperlink($uri, $text, $target='', $onclick='', function create_image($src, $alt='', $width='', $height='', $border='', $class='', $id='', $onclick='', $title='', $align='', $hspace='', $vspace='', - $text_alternative='') { + $text_alternative='', $aAttribs=array()) { global $oTemplate; @@ -110,6 +126,8 @@ function create_image($src, $alt='', $width='', $height='', $oTemplate->assign('vspace', $vspace); $oTemplate->assign('text_alternative', $text_alternative); + $oTemplate->assign('aAttribs', $aAttribs); + return $oTemplate->fetch('image.tpl'); } @@ -122,13 +140,20 @@ function create_image($src, $alt='', $width='', $height='', * @param string $class The CSS class name (OPTIONAL; default * not used) * @param string $id The ID name (OPTIONAL; default not used) + * @param array $aAttribs Any extra attributes: this must be an + * associative array, where keys will be + * added as the attribute name, and values + * (which are optional - should be null if + * none should be used) will be placed in + * double quotes (pending template implementation) + * as the attribute value (OPTIONAL; default empty). * * @return string The desired span tag. * * @since 1.5.2 * */ -function create_span($value, $class='', $id='') { +function create_span($value, $class='', $id='', $aAttribs=array()) { global $oTemplate; @@ -136,6 +161,8 @@ function create_span($value, $class='', $id='') { $oTemplate->assign('class', $class); $oTemplate->assign('id', $id); + $oTemplate->assign('aAttribs', $aAttribs); + return $oTemplate->fetch('span.tpl'); } diff --git a/templates/default/hyperlink.tpl b/templates/default/hyperlink.tpl index 7b31e5b4..f9c9a6ff 100644 --- a/templates/default/hyperlink.tpl +++ b/templates/default/hyperlink.tpl @@ -6,14 +6,19 @@ * Template for constructing a hyperlink. * * The following variables are available in this template: - * + $uri - the target link location - * + $text - link text - * + $target - the location where the link should be opened - * (optional; may not be present) - * + $onclick - onClick JavaScript handler (optional; may not be present) - * + $class - CSS class name (optional; may not be present) - * + $id - ID name (optional; may not be present) - * + $name - Anchor name (optional; may not be present) + * + $uri - the target link location + * + $text - link text + * + $target - the location where the link should be opened + * (optional; may not be present) + * + $onclick - onClick JavaScript handler (optional; may not be present) + * + $class - CSS class name (optional; may not be present) + * + $id - ID name (optional; may not be present) + * + $name - Anchor name (optional; may not be present) + * + $aAttribs - Any extra attributes: an associative array, where + * keys are attribute names, and values (which are + * optional and might be null) should be placed + * in double quotes as attribute values (optional; + * may not be present) * * @copyright © 1999-2006 The SquirrelMail Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License @@ -28,4 +33,16 @@ extract($t); -?>> +echo ' $value) { + echo ' ' . $key . (is_null($value) ? '' : '="' . $value . '"'); +} +echo '>' . $text . ''; + + diff --git a/templates/default/image.tpl b/templates/default/image.tpl index 61ad8cf8..5f3c0b26 100644 --- a/templates/default/image.tpl +++ b/templates/default/image.tpl @@ -30,6 +30,11 @@ * image tag, if for some reason the * image tag cannot or should not be * produced (optional; may not be present) + * + $aAttribs - Any extra attributes: an associative array, where + * keys are attribute names, and values (which are + * optional and might be null) should be placed + * in double quotes as attribute values (optional; + * may not be present) * * @copyright © 1999-2006 The SquirrelMail Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License @@ -44,4 +49,21 @@ extract($t); -?> /> +echo '' . $alt . ' $value) { + echo ' ' . $key . (is_null($value) ? '' : '="' . $value . '"'); +} +echo ' />'; + + diff --git a/templates/default/span.tpl b/templates/default/span.tpl index 2bbda59b..10bf7f7a 100644 --- a/templates/default/span.tpl +++ b/templates/default/span.tpl @@ -6,9 +6,14 @@ * Template for constructing a span tag. * * The following variables are available in this template: - * + $value - The contents that belong inside the span - * + $class - CSS class name (optional; may not be present) - * + $id - ID name (optional; may not be present) + * + $value - The contents that belong inside the span + * + $class - CSS class name (optional; may not be present) + * + $id - ID name (optional; may not be present) + * + $aAttribs - Any extra attributes: an associative array, where + * keys are attribute names, and values (which are + * optional and might be null) should be placed + * in double quotes as attribute values (optional; + * may not be present) * * @copyright © 1999-2006 The SquirrelMail Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License @@ -23,4 +28,12 @@ extract($t); -?>> +echo ' $value) { + echo ' ' . $key . (is_null($value) ? '' : '="' . $value . '"'); +} +echo '>' . $value . ''; + + -- 2.25.1