From 769a819ddfb1917b473e2b36f86f7c5b99b14600 Mon Sep 17 00:00:00 2001 From: pdontthink Date: Sun, 31 Dec 2006 04:18:52 +0000 Subject: [PATCH] Refactor hyperlink template code git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@12029 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/html.php | 38 ++++++++++++++++++++++++++++++ functions/page_header.php | 14 +---------- functions/strings.php | 8 ++----- plugins/listcommands/functions.php | 9 +------ 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/functions/html.php b/functions/html.php index 004565ba..99e1e35f 100644 --- a/functions/html.php +++ b/functions/html.php @@ -14,6 +14,41 @@ * @since 1.3.0 */ + +/** + * 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) + * + * @return string The desired hyperlink tag. + * + * @since 1.5.2 + * + */ +function create_hyperlink($uri, $text, $target='', $onclick='', $class='', $id='') { + + global $oTemplate; + + $oTemplate->assign('uri', $uri); + $oTemplate->assign('text', $text); + $oTemplate->assign('target', $target); + $oTemplate->assign('onclick', $onclick); + $oTemplate->assign('class', $class); + $oTemplate->assign('id', $id); + + return $oTemplate->fetch('hyperlink.tpl'); + +} + + /** * Generates html tags * @@ -90,6 +125,7 @@ function html_tag( $tag, // Tag to output return( $ret ); } + /** * handy function to set url vars * @@ -157,3 +193,5 @@ function set_url_var($url, $var, $val=0, $link=true) { } return $url; } + + diff --git a/functions/page_header.php b/functions/page_header.php index f3ec7792..27fa23a0 100644 --- a/functions/page_header.php +++ b/functions/page_header.php @@ -159,19 +159,7 @@ function makeInternalLink($path, $text, $target='') { // //do_hook('internal_link', $text); - $oTemplate->assign('uri', $base_uri . $path); - $oTemplate->assign('text', $text); - $oTemplate->assign('target', $target); - - // blank the onclick because the template object might - // already contain an onclick value due to having been - // used to show a compose link (when comp_in_new is turned on) - // - $oTemplate->assign('onclick', ''); - $oTemplate->assign('class', ''); - $oTemplate->assign('id', ''); - - return $oTemplate->fetch('hyperlink.tpl'); + return create_hyperlink($base_uri . $path, $text, $target); } /** diff --git a/functions/strings.php b/functions/strings.php index 757ebdb2..2e610b38 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -812,12 +812,8 @@ function makeComposeLink($url, $text = null, $target='') { if($javascript_on) { sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); $compuri = SM_BASE_URI.$url; - $oTemplate->assign('uri', 'javascript:void(0)'); - $oTemplate->assign('text', $text); - $oTemplate->assign('onclick', "comp_in_new('$compuri','$compose_width','$compose_height')"); - $oTemplate->assign('class', ''); - $oTemplate->assign('id', ''); - return $oTemplate->fetch('hyperlink.tpl'); + + return create_hyperlink('javascript:void(0)', $text, '', "comp_in_new('$compuri','$compose_width','$compose_height')"); } // otherwise, just open new window using regular HTML diff --git a/plugins/listcommands/functions.php b/plugins/listcommands/functions.php index b906c8cc..d617cee0 100644 --- a/plugins/listcommands/functions.php +++ b/plugins/listcommands/functions.php @@ -63,14 +63,7 @@ function plugin_listcommands_menu_do() { $links[] = makeComposeLink($url, $fieldsdescr['reply']); } } else if ($proto == 'href') { - $oTemplate->assign('uri', $act); - $oTemplate->assign('target', '_blank'); - $oTemplate->assign('text', $fieldsdescr[$cmd]); - $oTemplate->assign('class', ''); - $oTemplate->assign('id', ''); - $oTemplate->assign('onclick', ''); - $output = $oTemplate->fetch('hyperlink.tpl'); - $links[] = $output; + $links[] = create_hyperlink($act, $fieldsdescr[$cmd], '_blank'); } } -- 2.25.1