From: philippe_mingo Date: Thu, 30 May 2002 14:27:32 +0000 (+0000) Subject: Html output. Proposal 2 X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=94ac35c67eff63dedaa4a7013f13d3d7a5f04e86 Html output. Proposal 2 git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2907 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/html.php b/functions/html.php index aeae3d81..75429eb2 100644 --- a/functions/html.php +++ b/functions/html.php @@ -15,40 +15,321 @@ function html_tag( $tag, $align = '', + $bgcolor = '', $xtra = '' ) { - GLOBAL $languages, $language; + 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\""; + } - $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'; - } - - switch ( $align ) { - case '': - $alg = ''; - break; - case 'right': - $alg = " ALIGN=\"$rgt\""; - break; - default: - $alg = " ALIGN=\"$lft\""; - } - - return( "<$tag DIR=\"$dir\"$alg $xtra>" ); + 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$ + */ + +/** + * ZkSvc_html + * + * The ZkSvc_html class manages html output. + */ +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'; + } + + } + + /** + * Return the name of this service. + * + * @return string the name of this service + */ + function getServiceName() { + return( $this->name ); + } + + /** + * Replace the Zookeeper html module loaded for this service. (no modules yet) + * + */ + function loadModule(&$module) { + $this->htmlmod = &$module; + } + + /** + * Outputs the buffer and re-initialize it. + * + */ + function flush( $string = '' ) { + echo $this->buffer . $string; + flush(); + $this->buffer = ''; + } + + /** + * Builds a header string + * + */ + function header( $string = '' ) { + + // It initializes the buffer. + $this->buffer = '' . + "\n\n"; + + if( $this->head_extras <> '' || $this->title <> '' ) { + + $this->buffer .= "\n"; + + if( $this->title <> '' ) + $this->buffer .= "$this->title\n"; + + $this->buffer .= "$this->head_extras\n"; + } + $xtra = ''; + if ( $this->onload <> '' ) { + $xtra .= ' onload="' . $this->onload . '" '; + } + if ( $this->onunload <> '' ) { + $xtra .= ' onunload="' . $this->onunload . '" '; + } + $this->buffer .= "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 . ''; + } + + } + + /** + * Builds a footer string + * + */ + function footer() { + + $this->buffer .= "\n\n\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 ); + + } + + /** + * Builds a header string + * + */ + function h( $string, $level = '1' ) { + + $buffer = ""; + + /* See if we're asking for a closed strcuture */ + if( $string == '' ) { + $this->$buffer .= $buffer; + } else { + $buffer .= $string . ""; + } + return( $buffer ); + + } + +} + +/** + * Converts an array into a parameters tag list. + * + */ +function zkGetParms_html( $parms ) { + + $buffer = ''; + foreach( $parms as $key => $opt ) { + if( substr( $key, 0, 3 ) <> 'tag' ) { + $buffer .= " $key"; + if ($opt <> '' ) { + $buffer .= "=\"$opt\""; + } + } + } + return( $buffer ); +} + +/** + * Composes a tag string with all its parameters. + * + */ +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 .= ""; + } + + return( $ret ); +} + +function optionize( $name, $opts, $default, $xtra = '' ) { + + $ret = "\n"; + return( $ret ); +} -?> +?> \ No newline at end of file diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 13f185a3..c7d24e2e 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -14,7 +14,6 @@ require_once('../functions/strings.php'); require_once('../functions/imap_utf7_decode_local.php'); -require_once('../functions/html.php'); /* Default value for page_selector_max. */ define('PG_SEL_MAX', 10); @@ -33,7 +32,7 @@ function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $server_sort_order, /* sort value when using server-sorting */ $row_count, $allow_server_sort; /* enable/disable server-side sorting */ - $color_string = $color[4]; + $color_string = $color[4]; if ($GLOBALS['alt_index_colors']) { if (!isset($row_count)) { @@ -497,126 +496,140 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) { - global $folder_prefix, $sent_folder, - $imapServerAddress, $data_dir, $username, $use_mailbox_cache, - $index_order, $real_endMessage, $real_startMessage, $checkall, - $indent_array, $thread_sort_messages, $allow_server_sort, $server_sort_order; - - /* If cache isn't already set, do it now. */ - if (!session_is_registered('msgs')) { - session_register('msgs'); - } - if (!session_is_registered('msort')) { - session_register('msort'); - } - - if ($start_msg + ($show_num - 1) < $num_msgs){ - $end_msg = $start_msg + ($show_num - 1); - } else { - $end_msg = $num_msgs; - } - - if ($end_msg < $start_msg) { - $start_msg = $start_msg - $show_num; - if ($start_msg < 1) { - $start_msg = 1; + + global $folder_prefix, $sent_folder, + $imapServerAddress, $data_dir, $username, $use_mailbox_cache, + $index_order, $real_endMessage, $real_startMessage, $checkall, + $indent_array, $thread_sort_messages, $allow_server_sort, + $server_sort_order, $html; + + /* If cache isn't already set, do it now. */ + if (!session_is_registered('msgs')) { + session_register('msgs'); } - } - - $urlMailbox = urlencode($mailbox); - - do_hook('mailbox_index_before'); - - $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs); - $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg, - $num_msgs, $show_num, $sort); - - if (!isset($msg)) { - $msg = ''; - } - - /* get indent level for subject display */ - if ($thread_sort_messages == 1 ) { - $indent_array = get_parent_level($imapConnection); - } - $fstring = "move_messages.php?msg=$msg&mailbox=$urlMailbox" - . "&startMessage=$start_msg"; - mail_message_listing_beginning($imapConnection, $fstring, - $mailbox, $sort, $msg_cnt_str, - $paginator_str, $start_msg); - - $groupNum = $start_msg % ($show_num - 1); - $real_startMessage = $start_msg; - if ($sort == 6) { - if ($end_msg - $start_msg < $show_num - 1) { - $end_msg = $end_msg - $start_msg + 1; - $start_msg = 1; - } else if ($start_msg > $show_num) { - $end_msg = $show_num; - $start_msg = 1; + if (!session_is_registered('msort')) { + session_register('msort'); } - } - $endVar = $end_msg + 1; - - /* - * Loop through and display the info for each message. - * ($t is used for the checkbox number) - */ - $t = 0; - if ($num_msgs == 0) { - /* if there's no messages in this folder */ - echo "\n" - . "

". _("THIS FOLDER IS EMPTY") - . "
 
\n" - . ""; - } elseif ($start_msg == $end_msg) { - /* if there's only one message in the box, handle it differently. */ - if ($sort != 6){ - $i = $start_msg; + + if ($start_msg + ($show_num - 1) < $num_msgs){ + $end_msg = $start_msg + ($show_num - 1); } else { - $i = 1; + $end_msg = $num_msgs; } - reset($msort); - $k = 0; - do { - $key = key($msort); - next($msort); - $k++; - } while (isset ($key) && ($k < $i)); - printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, - $real_startMessage, 0, 0); - } else { - $i = $start_msg; - reset($msort); - $k = 0; - do { - $key = key($msort); - next($msort); - $k++; - } while (isset ($key) && ($k < $i)); - do { - printMessageInfo($imapConnection, $t, $i, $key, $mailbox, - $sort, $real_startMessage, 0, 0); - $key = key($msort); - $t++; - $i++; - next($msort); - } while ($i && $i < $endVar); - } - - echo '' - . html_tag( 'table', '', - "bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 cellspacing=1" ) - . "" - . "" - . html_tag( 'td', 'right' ) . "$msg_cnt_str
$paginator_str
" - . ""; - /* End of message-list table */ - - do_hook('mailbox_index_after'); - echo "\n"; + + if ($end_msg < $start_msg) { + $start_msg = $start_msg - $show_num; + if ($start_msg < 1) { + $start_msg = 1; + } + } + + $urlMailbox = urlencode($mailbox); + + do_hook('mailbox_index_before'); + + $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs); + $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg, + $num_msgs, $show_num, $sort); + + if (!isset($msg)) { + $msg = ''; + } + + /* get indent level for subject display */ + if ($thread_sort_messages == 1 ) { + $indent_array = get_parent_level($imapConnection); + } + $fstring = "move_messages.php?msg=$msg&mailbox=$urlMailbox" + . "&startMessage=$start_msg"; + mail_message_listing_beginning($imapConnection, $fstring, + $mailbox, $sort, $msg_cnt_str, + $paginator_str, $start_msg); + + $groupNum = $start_msg % ($show_num - 1); + $real_startMessage = $start_msg; + if ($sort == 6) { + if ($end_msg - $start_msg < $show_num - 1) { + $end_msg = $end_msg - $start_msg + 1; + $start_msg = 1; + } else if ($start_msg > $show_num) { + $end_msg = $show_num; + $start_msg = 1; + } + } + $endVar = $end_msg + 1; + + /* + * Loop through and display the info for each message. + * ($t is used for the checkbox number) + */ + $t = 0; + if ($num_msgs == 0) { + /* if there's no messages in this folder */ + echo "\n" + . "

". _("THIS FOLDER IS EMPTY") + . "
 
\n" + . ""; + } elseif ($start_msg == $end_msg) { + /* if there's only one message in the box, handle it differently. */ + if ($sort != 6){ + $i = $start_msg; + } else { + $i = 1; + } + reset($msort); + $k = 0; + do { + $key = key($msort); + next($msort); + $k++; + } while (isset ($key) && ($k < $i)); + printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, + $real_startMessage, 0, 0); + } else { + $i = $start_msg; + reset($msort); + $k = 0; + do { + $key = key($msort); + next($msort); + $k++; + } while (isset ($key) && ($k < $i)); + do { + printMessageInfo($imapConnection, $t, $i, $key, $mailbox, + $sort, $real_startMessage, 0, 0); + $key = key($msort); + $t++; + $i++; + next($msort); + } while ($i && $i < $endVar); + } + + echo '' . + $html->tag( 'table', + $html->tag( 'tr', + $html->tag( 'td', + $html->tag( 'table', + $html->tag( 'tr', + $html->tag( 'td', $paginator_str ) . + $html->tag( 'td', $msg_cnt_str, array( 'align' => 'right' ) ) + ) + , array( 'bgcolor'=> $color[4], + 'width' => '100%', + 'cellpadding' => 1, + 'cellspacing' => 1 ) ) + ) + , array( 'bgcolor' => $color[4] ) ) + , array( 'bgcolor' => $color[9], + 'width' => '100%', + 'cellpadding' => 1, + 'cellspacing' => 1 ) ); + + /* End of message-list table */ + + do_hook('mailbox_index_after'); + echo "\n"; } /* diff --git a/src/right_main.php b/src/right_main.php index d8581494..a4db4efe 100644 --- a/src/right_main.php +++ b/src/right_main.php @@ -198,4 +198,4 @@ sqimap_logout ($imapConnection); echo ''; -?> +?> \ No newline at end of file diff --git a/src/validate.php b/src/validate.php index f19a8604..7292164f 100644 --- a/src/validate.php +++ b/src/validate.php @@ -73,15 +73,22 @@ $theme=array(); require_once('../config/config.php'); require_once('../src/load_prefs.php'); require_once('../functions/page_header.php'); -require_once('../functions/prefs.php'); +require_once('../functions/html.php'); /* Set up the language (i18n.php was included by auth.php). */ global $username, $data_dir; set_up_language(getPref($data_dir, $username, 'language')); $timeZone = getPref($data_dir, $username, 'timezone'); -if ( $timeZone != SMPREF_NONE && ($timeZone != "") - && !ini_get("safe_mode")) { - putenv("TZ=".$timeZone); +if ( $timeZone != SMPREF_NONE && ($timeZone <> '') + && !ini_get( 'safe_mode' )) { + putenv( 'TZ=' . $timeZone ); } + +/* + Initialize the html object +*/ +GLOBAL $html; +$html = new ZkSvc_html(); + ?>