- dont add variables already in cookie (reduces html output up to 30%)

- can pass all url variables as array to function
This commit is contained in:
Sebastian Mendel
2005-11-24 16:16:00 +00:00
parent 886e0f0dac
commit b9888e570d
2 changed files with 123 additions and 37 deletions

View File

@@ -32,6 +32,9 @@ $Source$
- replaced table layout - replaced table layout
- added some more infos - added some more infos
* themes/original/css/theme_left.cs..php: fixed font size * themes/original/css/theme_left.cs..php: fixed font size
* libraries/url_generating.lib.php:
- dont add variables already in cookie (reduces html output up to 30%)
- can pass all url variables as array to function
2005-11-23 Sebastian Mendel <cybot_tm@users.sourceforge.net> 2005-11-23 Sebastian Mendel <cybot_tm@users.sourceforge.net>
* *REVERTED* libraries/display_select_lang.lib.php: correct lang definition * *REVERTED* libraries/display_select_lang.lib.php: correct lang definition

View File

@@ -11,6 +11,7 @@
/** /**
* Generates text with hidden inputs. * Generates text with hidden inputs.
* *
* @see PMA_generate_common_url()
* @param string optional database name * @param string optional database name
* @param string optional table name * @param string optional table name
* @param int indenting level * @param int indenting level
@@ -28,38 +29,91 @@
* *
* @author nijel * @author nijel
*/ */
function PMA_generate_common_hidden_inputs ($db = '', $table = '', $indent = 0, $skip = array()) function PMA_generate_common_hidden_inputs( $db = '', $table = '', $indent = 0, $skip = array() )
{ {
global $lang, $convcharset, $collation_connection, $server; if ( is_array( $db ) ) {
global $cfg, $allow_recoding; $params =& $db;
$_indent = empty( $table ) ? $indent : $table;
if (!is_array($skip)) { $_skip = empty( $indent ) ? $skip : $indent;
$skip = array($skip); $indent =& $_indent;
$skip =& $_skip;
} else {
$params = array();
if ( ! empty( $db ) ) {
$params['db'] = $db;
}
if ( ! empty( $table ) ) {
$params['table'] = $table;
}
} }
$spaces = ''; if ( ! empty( $GLOBALS['server'] )
for ($i = 0; $i < $indent; $i++) { && $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault'] ) {
$spaces .= ' '; $params['server'] = $GLOBALS['server'];
}
if ( empty( $_COOKIE['pma_lang'] )
&& ! empty( $GLOBALS['lang'] ) ) {
$params['lang'] = $GLOBALS['lang'];
}
if ( empty( $_COOKIE['pma_charset'] )
&& ! empty( $GLOBALS['convcharset'] ) ) {
$params['convcharset'] = $GLOBALS['convcharset'];
}
if ( empty( $_COOKIE['pma_collation_connection'] )
&& ! empty( $GLOBALS['collation_connection'] ) ) {
$params['collation_connection'] = $GLOBALS['collation_connection'];
} }
$result = $spaces . '<input type="hidden" name="lang" value="' . $lang . '" />' . "\n" if ( ! is_array($skip) ) {
. $spaces . '<input type="hidden" name="server" value="' . $server . '" />' . "\n"; if ( isset( $params[$skip] ) ) unset( $params[$skip] );
if (!in_array('convcharset', $skip) && isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding) } else {
$result .= $spaces . '<input type="hidden" name="convcharset" value="' . $convcharset . '" />' . "\n"; foreach( $skip as $skipping ) {
if (!in_array('collation_connection', $skip) && isset($collation_connection)) if ( isset( $params[$skipping] ) ) unset( $params[$skipping] );
$result .= $spaces . '<input type="hidden" name="collation_connection" value="' . $collation_connection . '" />' . "\n"; }
if (!in_array('db', $skip) && !empty($db)) }
$result .= $spaces . '<input type="hidden" name="db" value="'.htmlspecialchars($db).'" />' . "\n";
if (!in_array('table', $skip) && !empty($table)) $spaces = str_repeat( ' ', $indent );
$result .= $spaces . '<input type="hidden" name="table" value="'.htmlspecialchars($table).'" />' . "\n";
return $result; $return = '';
foreach( $params as $key => $val ) {
$return .= $spaces . '<input type="hidden" name="' . htmlentities( $key ) . '" value="' . htmlentities( $val ) . '" />' . "\n";
}
return $return;
} }
/** /**
* Generates text with URL parameters. * Generates text with URL parameters.
* *
* @param string optional database name * <code>
* @param string optional table name * // note the ?
* echo 'script.php?' . PMA_generate_common_url( 'mysql', 'rights' );
* // produces with cookies enabled:
* // script.php?db=mysql&amp;table=rights
* // with cookies disabled:
* // script.php?server=1&amp;lang=en-utf-8&amp;db=mysql&amp;table=rights
*
* $params['myparam'] = 'myvalue';
* $params['db'] = 'mysql';
* $params['table'] = 'rights';
* // note the missing ?
* echo 'script.php' . PMA_generate_common_url( $params );
* // produces with cookies enabled:
* // script.php?myparam=myvalue&amp;db=mysql&amp;table=rights
* // with cookies disabled:
* // script.php?server=1&amp;lang=en-utf-8&amp;myparam=myvalue&amp;db=mysql&amp;table=rights
*
* // note the missing ?
* echo 'script.php' . PMA_generate_common_url();
* // produces with cookies enabled:
* // script.php
* // with cookies disabled:
* // script.php?server=1&amp;lang=en-utf-8
* </code>
*
* @param mixed assoc. array with url params or optional string with database name
* if first param is an array there is also an ? prefixed to the url
* @param string optional table name only if first param is array
* @param string character to use instead of '&amp;' for deviding * @param string character to use instead of '&amp;' for deviding
* multiple URL parameters from each other * multiple URL parameters from each other
* *
@@ -76,22 +130,51 @@ function PMA_generate_common_hidden_inputs ($db = '', $table = '', $indent = 0,
* *
* @author nijel * @author nijel
*/ */
function PMA_generate_common_url ($db = '', $table = '', $amp = '&amp;') function PMA_generate_common_url ($db = '', $table = '', $delim = '&amp;')
{ {
global $lang, $convcharset, $collation_connection, $server; if ( is_array( $db ) ) {
global $cfg, $allow_recoding; $params =& $db;
$delim = empty( $table ) ? $delim : $table;
$questionmark = '?';
} else {
$params = array();
if ( ! empty( $db ) ) {
$params['db'] = $db;
}
if ( ! empty( $table ) ) {
$params['table'] = $table;
}
$questionmark = '';
}
$result = 'lang=' . $lang if ( $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault']
. $amp . 'server=' . $server; && ! empty( $GLOBALS['server'] ) ) {
if (isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding) $params['server'] = $GLOBALS['server'];
$result .= $amp . 'convcharset=' . urlencode($convcharset); }
if (isset($collation_connection))
$result .= $amp . 'collation_connection=' . urlencode($collation_connection); if ( empty( $_COOKIE['pma_lang'] )
if (!empty($db)) && ! empty( $GLOBALS['lang'] ) ) {
$result .= $amp . 'db='.urlencode($db); $params['lang'] = $GLOBALS['lang'];
if (!empty($table)) }
$result .= $amp . 'table='.urlencode($table); if ( empty( $_COOKIE['pma_charset'] )
return $result; && ! empty( $GLOBALS['convcharset'] ) ) {
$params['convcharset'] = $GLOBALS['convcharset'];
}
if ( empty( $_COOKIE['pma_collation_connection'] )
&& ! empty( $GLOBALS['collation_connection'] ) ) {
$params['collation_connection'] = $GLOBALS['collation_connection'];
}
$param_strings = array();
foreach( $params as $key => $val ) {
$param_strings[] = urlencode( $key ) . '=' . urlencode( $val );
}
if ( empty( $param_strings ) ) {
return '';
}
return htmlentities( $questionmark . implode( $delim, $param_strings ) );
} }
?> ?>