X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;ds=sidebyside;f=functions%2Fhtml.php;h=2df57f2e7aa0e9550a2e1639a06e7070ae1e5d48;hb=9ac8d987e165f4e0a1c815edacaac44529dd2784;hp=72351c0cb2893545ebc1681c93b430345163e748;hpb=8008456a180e245d1c81c1773547d59573b5c1bf;p=squirrelmail.git diff --git a/functions/html.php b/functions/html.php index 72351c0c..2df57f2e 100644 --- a/functions/html.php +++ b/functions/html.php @@ -3,77 +3,372 @@ /** * html.php * - * Copyright (c) 1999-2002 The SquirrelMail Project Team - * Licensed under the GNU GPL. For full terms see the file COPYING. - * * The idea is to inlcude here some functions to make easier * the right to left implementation by "functionize" some * html outputs. * - * $Id$ + * @copyright © 1999-2007 The SquirrelMail Project Team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + * @version $Id$ + * @package squirrelmail + * @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) + * @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. + * + * @since 1.5.2 + * */ +function create_hyperlink($uri, $text, $target='', $onclick='', + $class='', $id='', $name='', $aAttribs=array()) { + + 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); + $oTemplate->assign('name', $name); + + $oTemplate->assign('aAttribs', $aAttribs); + + return $oTemplate->fetch('hyperlink.tpl'); + +} + + +/** + * Generates an image tag + * + * @param string $src The image source path + * @param string $alt Alternate link text (OPTIONAL; default + * not used) + * @param string $width The width the image should be shown in + * (OPTIONAL; default not used) + * @param string $height The height the image should be shown in + * (OPTIONAL; default not used) + * @param string $border The image's border attribute value + * (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 $onclick The onClick JavaScript handler (OPTIONAL; + * default not used) + * @param string $title The image's title attribute value + * (OPTIONAL; default not used) + * @param string $align The image's alignment attribute value + * (OPTIONAL; default not used) + * @param string $hspace The image's hspace attribute value + * (OPTIONAL; default not used) + * @param string $vspace The image's vspace attribute value + * (OPTIONAL; default not used) + * @param string $text_alternative A text replacement for the entire + * image tag, to be used at the + * discretion of the template set, + * 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. + * + * @since 1.5.2 + * + */ +function create_image($src, $alt='', $width='', $height='', + $border='', $class='', $id='', $onclick='', + $title='', $align='', $hspace='', $vspace='', + $text_alternative='', $aAttribs=array()) { + + global $oTemplate; + + $oTemplate->assign('src', $src); + $oTemplate->assign('alt', $alt); + $oTemplate->assign('width', $width); + $oTemplate->assign('height', $height); + $oTemplate->assign('border', $border); + $oTemplate->assign('class', $class); + $oTemplate->assign('id', $id); + $oTemplate->assign('onclick', $onclick); + $oTemplate->assign('title', $title); + $oTemplate->assign('align', $align); + $oTemplate->assign('hspace', $hspace); + $oTemplate->assign('vspace', $vspace); + $oTemplate->assign('text_alternative', $text_alternative); + + $oTemplate->assign('aAttribs', $aAttribs); + + return $oTemplate->fetch('image.tpl'); + +} + + +/** + * Generates a label tag + * + * @param string $value The contents that belong inside the label + * @param string $for The ID to which the label applies (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 label tag. + * + * @since 1.5.2 + * + */ +function create_label($value, $for='', $aAttribs=array()) { + + global $oTemplate; + + $oTemplate->assign('text', $value); + $oTemplate->assign('for', $for); + + $oTemplate->assign('aAttribs', $aAttribs); + + return $oTemplate->fetch('label.tpl'); + +} + + +/** + * Generates a span tag + * + * @param string $value The contents that belong inside the span + * @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='', $aAttribs=array()) { + + global $oTemplate; + + $oTemplate->assign('value', $value); + $oTemplate->assign('class', $class); + $oTemplate->assign('id', $id); + + $oTemplate->assign('aAttribs', $aAttribs); + + return $oTemplate->fetch('span.tpl'); + +} - function html_tag( $tag, // Tag to output - $val = '', // Value between tags (if empty only start tag is output) + +/** + * Generates an opening body tag + * + * @param string $onload Body onload JavaScript handler code + * (OPTIONAL; default not used) + * @param string $class The CSS class 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 body tag. + * + * @since 1.5.2 + * + */ +function create_body($onload='', $class='', $aAttribs=array()) { + + global $oTemplate; + + $oTemplate->assign('onload', $onload); + $oTemplate->assign('class', $class); + + $oTemplate->assign('aAttribs', $aAttribs); + + return $oTemplate->fetch('body.tpl'); + +} + + +/** + * Generates html tags +//FIXME: This should not be used anywhere in the core, or we should convert this to use templates. We sould not be assuming HTML output. + * + * @param string $tag Tag to output + * @param string $val Value between tags + * @param string $align Alignment (left, center, etc) + * @param string $bgcolor Back color in hexadecimal + * @param string $xtra Extra options + * @return string HTML ready for output + * @since 1.3.0 + */ +function html_tag( $tag, // Tag to output + $val = '', // Value between tags $align = '', // Alignment $bgcolor = '', // Back color $xtra = '' ) { // Extra options - - GLOBAL $languages, $language; - - $align = strtolower( $align ); - $dir = strtolower( $dir ); - $tag = strtoupper( $tag ); - - if ( isset( $languages[$language]['DIR']) ) { - $dir = $languages[$language]['DIR']; - } else { - $dir = 'ltr'; - } - - if ( $dir == 'ltr' ) { - $rgt = 'right'; - $lft = 'left'; - } else { - $rgt = 'left'; - $lft = 'right'; - } - - if ( $bgcolor <> '' ) { - $bgc = " BGCOLOR=\"$bgcolor\""; - } - - switch ( $align ) { - case '': - $alg = ''; - break; - case 'right': - $alg = " ALIGN=\"$rgt\""; - break; - case 'left': - $alg = " ALIGN=\"$lft\""; - default: - $alg = " ALIGN=\"$align\""; - } - - $ret = "<$tag"; - - if ( $dir <> 'ltr' ) { - $ret .= " DIR=\"$dir\""; - } - - $ret .= "$bgc$alg"; - - if ( $xtra <> '' ) { - $ret .= " $xtra"; - } - $ret .= '>'; - - if ( $val <> '' ) { - $ret .= "$val"; - } - - return( $ret ); + + GLOBAL $languages, $squirrelmail_language; + + $align = strtolower( $align ); + $bgc = ''; + $tag = strtolower( $tag ); + + if ( isset( $languages[$squirrelmail_language]['DIR']) ) { + $dir = $languages[$squirrelmail_language]['DIR']; + } else { + $dir = 'ltr'; + } + + if ( $dir == 'ltr' ) { + $rgt = 'right'; + $lft = 'left'; + } else { + $rgt = 'left'; + $lft = 'right'; + } + + if ( $bgcolor <> '' ) { + $bgc = " bgcolor=\"$bgcolor\""; + } + + switch ( $align ) { + case '': + $alg = ''; + break; + case 'right': + $alg = " align=\"$rgt\""; + break; + case 'left': + $alg = " align=\"$lft\""; + break; + default: + $alg = " align=\"$align\""; + break; + } + + $ret = "<$tag"; + + if ( $dir <> 'ltr' ) { + $ret .= " dir=\"$dir\""; + } + $ret .= $bgc . $alg; + + if ( $xtra <> '' ) { + $ret .= " $xtra"; + } + + if ( $val <> '' ) { + $ret .= ">$val\n"; + } else { + $ret .= '>'. "\n"; + } + + return( $ret ); +} + + +/** + * This function is used to add, modify or delete GET variables in a URL. + * It is especially useful when $url = $PHP_SELF + * + * Set $val to NULL to remove $var from $url. + * To ensure compatibility with older versions, use $val='0' to set $var to 0. + * + * @param string $url url that must be modified + * @param string $var GET variable name + * @param string $val variable value + * @param boolean $link controls sanitizing of ampersand in urls (since 1.3.2) + * + * @return string $url modified url + * + * @since 1.3.0 + * + */ +function set_url_var($url, $var, $val=null, $link=true) { + $url = str_replace('&','&',$url); + + if (strpos($url, '?') === false) { + $url .= '?'; + } + + list($uri, $params) = explode('?', $url, 2); + + $newpar = array(); + $params = explode('&', $params); + + foreach ($params as $p) { + if (trim($p)) { + $p = explode('=', $p); + $newpar[$p[0]] = (isset($p[1]) ? $p[1] : ''); + } + } + + if (is_null($val)) { + unset($newpar[$var]); + } else { + $newpar[$var] = $val; + } + + if (!count($newpar)) { + return $uri; + } + + $url = $uri . '?'; + foreach ($newpar as $name => $value) { + $url .= "$name=$value&"; + } + + $url = substr($url, 0, -1); + if ($link) { + $url = str_replace('&','&',$url); } + + return $url; +} -?> \ No newline at end of file