<?php
/**
- * imap.php
- *
- * Copyright (c) 1999-2002 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
+ * html.php
*
* The idea is to inlcude here some functions to make easier
* the right to left implementation by "functionize" some
* html outputs.
*
- * $Id$
- */
-
- function html_tag( $tag,
- $align = '',
- $bgcolor = '',
- $xtra = '' ) {
-
- GLOBAL $languages, $language;
-
- $align = strtolower( $align );
- $dir = strtolower( $dir );
-
- 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;
- default:
- $alg = " ALIGN=\"$lft\"";
- }
-
- return( "<$tag DIR=\"$dir\"$bgc$alg $xtra>" );
- }
-
-/*
- * Zookeeper
- * Copyright (c) 2001 Partridge
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
- * $Id$
+ * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ * @version $Id$
+ * @package squirrelmail
+ * @since 1.3.0
*/
/**
- * ZkSvc_html
+ * Generates html tags
*
- * The ZkSvc_html class manages 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
*/
-class ZkSvc_html {
-
- /* Constants */
- var $name = 'html'; // Module name
- var $ver = '$Id$';
-
- /* Properties */
- var $buffer; // Buffered output
- var $htmlmod; // Module handler
- var $title; // Page title
- var $head_extras; // Extra header tags
- var $bgcolor; // Background color
- var $text; // Text color
- var $link; // Link color
- var $vlink; // Visited link color
- var $alink; // Active link color
- var $onload; // Onload event
- var $onunload; // OnUnload event
- var $dir; // Text direction
-
- var $tag_options; // Array of tag options array
-
- /** CONSTRUCTOR
- */
-
- function ZkSvc_html() {
-
- GLOBAL $languages, $language;
-
- $this->spool = FALSE;
- $this->buffer = '';
- $this->title = 'Default zkHTML Title';
- $this->head_extras = '';
- $this->bgcolor = '#FFFFFF';
- $this->text = '#000000';
- $this->link = '#3300CC';
- $this->vlink = '#993333';
- $this->alink = '#993333';
- $this->onload = '';
- $this->onunload = '';
-
- /* To know if a tag exists we check that it has got a place in the following array */
- $this->tag_options = array( 'table' => array( 'tag_name' => 'table',
- 'tag_closed' => TRUE ),
- 'tr' => array( 'tag_name' => 'tr',
- 'tag_closed' => TRUE ),
- 'th' => array( 'tag_name' => 'th',
- 'tag_closed' => TRUE ),
- 'td' => array( 'tag_name' => 'td',
- 'tag_closed' => TRUE ),
- 'li' => array( 'tag_name' => 'li',
- 'tag_closed' => TRUE ),
- 'ol' => array( 'tag_name' => 'ol',
- 'tag_closed' => TRUE ),
- 'form' => array( 'tag_name' => 'form',
- 'tag_closed' => TRUE ),
- 'input' => array( 'tag_name' => 'input',
- 'tag_closed' => FALSE ),
- 'br' => array( 'tag_name' => 'br',
- 'tag_closed' => FALSE ),
- 'textarea' => array( 'tag_name' => 'textarea',
- 'tag_closed' => TRUE ),
- 'p' => array( 'tag_name' => 'p',
- 'tag_closed' => TRUE ),
- 'a' => array( 'tag_name' => 'a',
- 'tag_closed' => TRUE ),
- 'center' => array( 'name' => 'center',
- 'tag_closed' => TRUE ),
- 'img' => array( 'name' => 'img',
- 'tag_closed' => FALSE ),
- 'font' => array( 'tag_closed' => TRUE ),
- 'blockquote' => array( 'tag_name' => 'blockquote',
- 'tag_closed' => TRUE )
- );
-
- if ( isset( $languages[$language]['DIR']) ) {
- $this->dir = strtolower( $languages[$language]['DIR'] );
- } else {
- $this->dir = 'ltr';
- }
-
+function html_tag( $tag, // Tag to output
+ $val = '', // Value between tags
+ $align = '', // Alignment
+ $bgcolor = '', // Back color
+ $xtra = '' ) { // Extra options
+
+ 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';
}
- /**
- * Return the name of this service.
- *
- * @return string the name of this service
- */
- function getServiceName() {
- return( $this->name );
+ if ( $dir == 'ltr' ) {
+ $rgt = 'right';
+ $lft = 'left';
+ } else {
+ $rgt = 'left';
+ $lft = 'right';
}
- /**
- * Replace the Zookeeper html module loaded for this service. (no modules yet)
- *
- */
- function loadModule(&$module) {
- $this->htmlmod = &$module;
+ if ( $bgcolor <> '' ) {
+ $bgc = " bgcolor=\"$bgcolor\"";
}
- /**
- * Outputs the buffer and re-initialize it.
- *
- */
- function flush( $string = '' ) {
- echo $this->buffer . $string;
- flush();
- $this->buffer = '';
+ switch ( $align ) {
+ case '':
+ $alg = '';
+ break;
+ case 'right':
+ $alg = " align=\"$rgt\"";
+ break;
+ case 'left':
+ $alg = " align=\"$lft\"";
+ break;
+ default:
+ $alg = " align=\"$align\"";
+ break;
}
- /**
- * Builds a header string
- *
- */
- function header( $string = '' ) {
-
- // It initializes the buffer.
- $this->buffer = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">' .
- "\n<HTML>\n";
-
- if( $this->head_extras <> '' || $this->title <> '' ) {
-
- $this->buffer .= "<HEAD>\n";
-
- if( $this->title <> '' )
- $this->buffer .= "<TITLE>$this->title</TITLE>\n";
-
- $this->buffer .= "$this->head_extras</HEAD>\n";
- }
- $xtra = '';
- if ( $this->onload <> '' ) {
- $xtra .= ' onload="' . $this->onload . '" ';
- }
- if ( $this->onunload <> '' ) {
- $xtra .= ' onunload="' . $this->onunload . '" ';
- }
- $this->buffer .= "<BODY TEXT=\"$this->text\" BGCOLOR=\"$this->bgcolor\" LINK=\"$this->link\" VLINK=\"$this->vlink\" ALINK=\"$this->alink\" $xtra>\n";
-
- /* See if we're asking for a closed strcuture */
- if( $string == '' ) {
- $this->flush();
- } else {
- $this->buffer .= $string . '</BODY></HTML>';
- }
+ $ret = "<$tag";
+ if ( $dir <> 'ltr' ) {
+ $ret .= " dir=\"$dir\"";
}
+ $ret .= $bgc . $alg;
- /**
- * Builds a footer string
- *
- */
- function footer() {
-
- $this->buffer .= "\n</body>\n</html>\n";
- $this->flush();
-
- }
-
- /**
- * Builds a tag string
- *
- */
- function tag( $tag, $string = '', $options = '' ) {
-
- $ret = '';
- if( $this->tag_options[$tag] <> NULL ) {
- if( $options == '' ) {
- $options = $this->tag_options[$tag];
- }
- switch( strtolower( $tag ) ) {
- case 'td':
- case 'th':
- if ( $this->dir == 'rtl' && isset( $options['align'] ) ) {
-
- }
- case 'table':
- if ( $this->dir <> '' ) {
- $options['DIR'] = $this->dir;
- }
- break;
- }
- $ret = zkTag_html( $tag, $string, $options, $this->tag_options[$tag]['tag_closed'] );
- }
- return( $ret );
-
+ if ( $xtra <> '' ) {
+ $ret .= " $xtra";
}
- /**
- * Builds a header string
- *
- */
- function h( $string, $level = '1' ) {
-
- $buffer = "<h$level>";
-
- /* See if we're asking for a closed strcuture */
- if( $string == '' ) {
- $this->$buffer .= $buffer;
- } else {
- $buffer .= $string . "</h$level>";
- }
- return( $buffer );
-
+ if ( $val <> '' ) {
+ $ret .= ">$val</$tag>\n";
+ } else {
+ $ret .= '>'. "\n";
}
+ return( $ret );
}
/**
- * Converts an array into a parameters tag list.
+ * handy function to set url vars
*
+ * especially useful when $url = $PHP_SELF
+ * @param string $url url that must be modified
+ * @param string $var 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 zkGetParms_html( $parms ) {
+function set_url_var($url, $var, $val=0, $link=true) {
+ $k = '';
+ $pat_a = array (
+ '/.+(\\&'.$var.')=(.*)\\&/AU', /* in the middle */
+ '/.+\\?('.$var.')=(.*\\&).+/AU', /* at front, more follow */
+ '/.+(\\?'.$var.')=(.*)$/AU', /* at front and only var */
+ '/.+(\\&'.$var.')=(.*)$/AU' /* at the end */
+ );
+ preg_replace('/&/','&',$url);
+
+ // FIXME: why switch is used instead of if () or one preg_match()
+ switch (true) {
+ case (preg_match($pat_a[0],$url,$regs)):
+ $k = $regs[1];
+ $v = $regs[2];
+ break;
+ case (preg_match($pat_a[1],$url,$regs)):
+ $k = $regs[1];
+ $v = $regs[2];
+ break;
+ case (preg_match($pat_a[2],$url,$regs)):
+ $k = $regs[1];
+ $v = $regs[2];
+ break;
+ case (preg_match($pat_a[3],$url,$regs)):
+ $k = $regs[1];
+ $v = $regs[2];
+ break;
+ default:
+ if ($val) {
+ if (strpos($url,'?')) {
+ $url .= "&$var=$val";
+ } else {
+ $url .= "?$var=$val";
+ }
+ }
+ break;
+ }
- $buffer = '';
- foreach( $parms as $key => $opt ) {
- if( substr( $key, 0, 3 ) <> 'tag' ) {
- $buffer .= " $key";
- if ($opt <> '' ) {
- $buffer .= "=\"$opt\"";
+ if ($k) {
+ if ($val) {
+ $rpl = "$k=$val";
+ if ($link) {
+ $rpl = preg_replace('/&/','&',$rpl);
}
+ } else {
+ $rpl = '';
+ }
+ if( substr($v,-1)=='&' ) {
+ $rpl .= '&';
}
+ $pat = "/$k=$v/";
+ $url = preg_replace($pat,$rpl,$url);
}
- return( $buffer );
+ return $url;
}
/**
- * Composes a tag string with all its parameters.
- *
+ * Temporary test function to process template vars with formatting.
+ * I use it for viewing the message_header (view_header.php) with
+ * a sort of template.
+ * @param mixed $var
+ * @param mixed $format_ar
+ * @since 1.3.0
+ * @todo if function is temporary, then why it is used.
+ * @deprecated
*/
-function zkTag_html( $tag, $string, $options, $closed ) {
-
- /*
- We must check direction tag in case we have table, td or th
- */
-
- $ret = "<$tag" .
- zkGetParms_html( $options ) .
- '>' .
- $string;
-
- if ( $closed ) {
- $ret .= "</$tag>";
+function echo_template_var($var, $format_ar = array() ) {
+ $frm_last = count($format_ar) -1;
+
+ if (isset($format_ar[0])) echo $format_ar[0];
+ $i = 1;
+
+ switch (true) {
+ case (is_string($var)):
+ echo $var;
+ break;
+ case (is_array($var)):
+ $frm_a = array_slice($format_ar,1,$frm_last-1);
+ foreach ($var as $a_el) {
+ if (is_array($a_el)) {
+ echo_template_var($a_el,$frm_a);
+ } else {
+ echo $a_el;
+ if (isset($format_ar[$i])) {
+ echo $format_ar[$i];
+ }
+ $i++;
+ }
+ }
+ break;
+ default:
+ break;
}
-
- return( $ret );
-}
-
-function optionize( $name, $opts, $default, $xtra = '' ) {
-
- $ret = "<select name=\"$name\" $xtra>\n";
-
- foreach( $opts as $key => $opt ) {
- if( $opt == $default ) {
- $chk = ' SELECTED';
- } else {
- $chk = '';
- }
- $ret .= "<option value=\"$opt\"$chk>$opt</option>\n";
+ if (isset($format_ar[$frm_last]) && $frm_last>$i ) {
+ echo $format_ar[$frm_last];
}
-
- $ret .= "</select>\n";
- return( $ret );
}
-
?>
\ No newline at end of file