From e3ff258e16b82c4d86083509c6514b011036aac5 Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Mon, 12 Dec 2005 12:48:00 +0000 Subject: [PATCH] moved stuff from grab_globals into common.inc.php (preprare removal of grab_globals) check/init global required variables like: $lang, $server, $db, $table, $convcharset, $goto introduced $goto-whitelist PEAR coding standard --- libraries/common.lib.php | 837 ++++++++++++++++++++------------- libraries/grab_globals.lib.php | 250 ++++------ 2 files changed, 611 insertions(+), 476 deletions(-) diff --git a/libraries/common.lib.php b/libraries/common.lib.php index dd3a0693a..145a791fb 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -17,9 +17,17 @@ * * ... so the required order is: * - * #0031 definition of functions LABEL_definition_of_functions - * #2300 parsing of the config file label_parsing_config_file - * #2331 loading language file label_loading_language_file + * LABEL_definition_of_functions + * - definition of functions + * LABEL_variables_init + * - init some variables always needed + * LABEL_parsing_config_file + * - parsing of the config file + * LABEL_loading_language_file + * - loading language file + * LABEL_theme_setup + * - setting up themes + * * - load of mysql extension (if necessary) label_loading_mysql * - loading of an authentication library label_ * - db connection @@ -30,7 +38,7 @@ /******************************************************************************/ -/* definition of functions label_definition_of_functions */ +/* definition of functions LABEL_definition_of_functions */ /** * Removes insecure parts in a path; used before include() or * require() when a part of the path comes from an insecure source @@ -43,8 +51,8 @@ * @access public * @author Marc Delisle (lem9@users.sourceforge.net) */ -function PMA_securePath($path) { - +function PMA_securePath($path) +{ // change .. to . $path = preg_replace('@\.\.*@','.',$path); @@ -71,7 +79,8 @@ function PMA_securePath($path) { * @uses explode() * @return array db list */ -function PMA_getDbList() { +function PMA_getDbList() +{ if ( empty( $GLOBALS['dblist'] ) ) { PMA_availableDatabases(); } @@ -83,15 +92,15 @@ function PMA_getDbList() { $db_tooltip = ''; if ( $GLOBALS['cfg']['ShowTooltip'] && $GLOBALS['cfgRelation']['commwork'] ) { - $_db_tooltip = PMA_getComments( $db ); - if ( is_array( $_db_tooltip ) ) { - $db_tooltip = implode( ' ', $_db_tooltip ); + $_db_tooltip = PMA_getComments($db); + if ( is_array($_db_tooltip) ) { + $db_tooltip = implode(' ', $_db_tooltip); } } if ( $GLOBALS['cfg']['LeftFrameDBTree'] && $GLOBALS['cfg']['LeftFrameDBSeparator'] - && strstr( $db, $GLOBALS['cfg']['LeftFrameDBSeparator'] ) ) + && strstr($db, $GLOBALS['cfg']['LeftFrameDBSeparator']) ) { $pos = strrpos($db, $GLOBALS['cfg']['LeftFrameDBSeparator']); $group = substr($db, 0, $pos); @@ -113,7 +122,7 @@ function PMA_getDbList() { 'disp_name_cut' => $disp_name_cut, 'disp_name' => $disp_name, 'comment' => $db_tooltip, - 'num_tables' => PMA_getTableCount( $db ), + 'num_tables' => PMA_getTableCount($db), ); } // end foreach ( $dblist as $db ) return $dbgroups; @@ -124,18 +133,19 @@ function PMA_getDbList() { * * @return string html code select */ -function PMA_getHtmlSelectDb( $selected = '' ) { +function PMA_getHtmlSelectDb($selected = '') +{ $dblist = PMA_getDbList(); // TODO: IE can not handle different text directions in select boxes // so, as mostly names will be in english, we set the whole selectbox to LTR // and EN $return = ''; } @@ -510,7 +527,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { * * @access public */ - function PMA_sqlAddslashes($a_string = '', $is_like = FALSE, $crlf = FALSE, $php_code = FALSE) + function PMA_sqlAddslashes($a_string = '', $is_like = false, $crlf = false, $php_code = false) { if ($is_like) { $a_string = str_replace('\\', '\\\\\\\\', $a_string); @@ -561,7 +578,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { * @return string the escaped string * @access public */ - function PMA_unescape_mysql_wildcards( $name ) + function PMA_unescape_mysql_wildcards($name) { $name = str_replace('\\_', '_', $name); $name = str_replace('\\%', '%', $name); @@ -639,7 +656,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { * * @access public */ - function PMA_showMySQLDocu($chapter, $link, $big_icon = FALSE) + function PMA_showMySQLDocu($chapter, $link, $big_icon = false) { global $cfg; @@ -665,7 +682,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { default: if (empty($link)) $link = 'index'; $mysql = '5.0'; - if (defined( 'PMA_MYSQL_INT_VERSION')) { + if ( defined('PMA_MYSQL_INT_VERSION')) { if (PMA_MYSQL_INT_VERSION < 50000) { $mysql = '4.1'; } elseif (PMA_MYSQL_INT_VERSION >= 50100) { @@ -678,7 +695,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { break; } - if ($big_icon) { + if ( $big_icon ) { return '' . $GLOBALS['strDocu'] . ''; } elseif ($GLOBALS['cfg']['ReplaceHelpImg']) { return '' . $GLOBALS['strDocu'] . ''; @@ -696,8 +713,8 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { */ function PMA_showHint($hint_message) { - //return '' . $hint_message . ''; - return 'Tip'; + //return '' . $hint_message . ''; + return 'Tip'; } /** @@ -714,12 +731,12 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { * @access public */ function PMA_mysqlDie($error_message = '', $the_query = '', - $is_modify_link = TRUE, $back_url = '', - $exit = TRUE) + $is_modify_link = true, $back_url = '', + $exit = true) { global $cfg, $table, $db, $sql_query; - require_once('./libraries/header.inc.php'); + require_once './libraries/header.inc.php'; if (!$error_message) { $error_message = PMA_DBI_getError(); @@ -815,27 +832,27 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { // get the duplicate entry // get table name - preg_match( '�ALTER\sTABLE\s\`([^\`]+)\`�iu', $the_query, $error_table = array() ); + preg_match('�ALTER\sTABLE\s\`([^\`]+)\`�iu', $the_query, $error_table = array()); $error_table = $error_table[1]; // get fields - preg_match( '�\(([^\)]+)\)�i', $the_query, $error_fields = array() ); - $error_fields = explode( ',', $error_fields[1] ); + preg_match('�\(([^\)]+)\)�i', $the_query, $error_fields = array()); + $error_fields = explode(',', $error_fields[1]); // duplicate value - preg_match( '�\'([^\']+)\'�i', $tmp_mysql_error, $duplicate_value = array() ); + preg_match('�\'([^\']+)\'�i', $tmp_mysql_error, $duplicate_value = array()); $duplicate_value = $duplicate_value[1]; $sql = ' SELECT * - FROM ' . PMA_backquote( $error_table ) . ' - WHERE CONCAT_WS( "-", ' . implode( ', ', $error_fields ) . ' ) - = "' . PMA_sqlAddslashes( $duplicate_value ) . '" - ORDER BY ' . implode( ', ', $error_fields ); + FROM ' . PMA_backquote($error_table) . ' + WHERE CONCAT_WS( "-", ' . implode(', ', $error_fields) . ' ) + = "' . PMA_sqlAddslashes($duplicate_value) . '" + ORDER BY ' . implode(', ', $error_fields); unset( $error_table, $error_fields, $duplicate_value ); echo '
' ."\n" - .' ' . "\n" + .' ' . "\n" .' ' . PMA_generate_common_hidden_inputs($db, $table) . "\n" .' ' . "\n" .'
' . "\n"; @@ -851,7 +868,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { } echo ' ' . "\n\n"; if ($exit) { - require_once('./libraries/footer.inc.php'); + require_once './libraries/footer.inc.php'; } } // end of the 'PMA_mysqlDie()' function @@ -866,8 +883,8 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { * * @access private */ - function PMA_convert_using($string, $mode='unquoted') { - + function PMA_convert_using($string, $mode='unquoted') + { if ($mode == 'quoted') { $possible_quote = "'"; } else { @@ -889,7 +906,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { * @param string $uri the header to send * @return boolean always true */ - function PMA_sendHeaderLocation( $uri ) + function PMA_sendHeaderLocation($uri) { if (PMA_IS_IIS && strlen($uri) > 600) { @@ -912,23 +929,23 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { } else { if ( SID ) { - if ( strpos( $uri, '?' ) === false ) { - header( 'Location: ' . $uri . '?' . SID ); + if ( strpos($uri, '?') === false ) { + header('Location: ' . $uri . '?' . SID); } else { // use seperators defined by php, but prefer ';' // as recommended by W3C - $php_arg_separator_input = ini_get( 'arg_separator.input' ); - if ( strpos( $php_arg_separator_input, ';' ) !== false ) { + $php_arg_separator_input = ini_get('arg_separator.input'); + if ( strpos($php_arg_separator_input, ';') !== false ) { $separator = ';'; - } elseif ( strlen( $php_arg_separator_input ) > 0 ) { + } elseif ( strlen($php_arg_separator_input) > 0 ) { $separator = $php_arg_separator_input{0}; } else { $separator = '&'; } - header( 'Location: ' . $uri . $separator . SID ); + header('Location: ' . $uri . $separator . SID); } } else { - header( 'Location: ' . $uri ); + header('Location: ' . $uri); } } } @@ -952,9 +969,9 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { // 1. A list of allowed databases has already been defined by the // authentification process -> gets the available databases list - if ( count( $dblist ) ) { + if ( count($dblist) ) { foreach ( $dblist as $key => $db ) { - if ( ! @PMA_DBI_select_db( $db ) ) { + if ( ! @PMA_DBI_select_db($db) ) { unset( $dblist[$key] ); } // end if } // end for @@ -962,19 +979,19 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { // 2. Allowed database list is empty -> gets the list of all databases // on the server elseif ( empty( $cfg['Server']['only_db'] ) ) { - $dblist = PMA_DBI_get_dblist(); // needed? or PMA_mysqlDie('', 'SHOW DATABASES;', FALSE, $error_url); + $dblist = PMA_DBI_get_dblist(); // needed? or PMA_mysqlDie('', 'SHOW DATABASES;', false, $error_url); } // end else - $num_dbs = count( $dblist ); + $num_dbs = count($dblist); // natural order for db list; but do not sort if user asked // for a specific order with the 'only_db' mechanism - if ( ! is_array( $GLOBALS['cfg']['Server']['only_db'] ) + if ( ! is_array($GLOBALS['cfg']['Server']['only_db']) && $GLOBALS['cfg']['NaturalOrder'] ) { - natsort( $dblist ); + natsort($dblist); } - return TRUE; + return true; } // end of the 'PMA_availableDatabases()' function /** @@ -994,16 +1011,17 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { * @param string $db name of db * return array (rekursive) grouped table list */ - function PMA_getTableList( $db ) { + function PMA_getTableList($db) + { $sep = $GLOBALS['cfg']['LeftFrameTableSeparator']; $tables = PMA_DBI_get_tables_full($db); - if ( count( $tables ) < 1 ) { + if ( count($tables) < 1 ) { return $tables; } if ( $GLOBALS['cfg']['NaturalOrder'] ) { - uksort( $tables, 'strnatcasecmp' ); + uksort($tables, 'strnatcasecmp'); } $default = array( @@ -1018,22 +1036,22 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { foreach ( $tables as $table_name => $table ) { // check for correct row count - if ( NULL === $table['Rows'] ) { - $table['Rows'] = PMA_countRecords( $db, $table['Name'], - $return = true, $force_exact = true ); + if ( null === $table['Rows'] ) { + $table['Rows'] = PMA_countRecords($db, $table['Name'], + $return = true, $force_exact = true); } // in $group we save the reference to the place in $table_groups // where to store the table info if ( $GLOBALS['cfg']['LeftFrameDBTree'] - && $sep && strstr( $table_name, $sep ) ) + && $sep && strstr($table_name, $sep) ) { - $parts = explode( $sep, $table_name ); + $parts = explode($sep, $table_name); $group =& $table_groups; $i = 0; $group_name_full = ''; - while ( $i < count( $parts ) - 1 + while ( $i < count($parts) - 1 && $i < $GLOBALS['cfg']['LeftFrameTableLevel'] ) { $group_name = $parts[$i] . $sep; $group_name_full .= $group_name; @@ -1074,7 +1092,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { $table['disp_name'] = $table['Name']; } - $group[$table_name] = array_merge( $default, $table ); + $group[$table_name] = array_merge($default, $table); } return $table_groups; @@ -1099,7 +1117,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { * * @access public */ - function PMA_backquote($a_name, $do_it = TRUE) + function PMA_backquote($a_name, $do_it = true) { // '0' is also empty for php :-( if ($do_it @@ -1107,7 +1125,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { if (is_array($a_name)) { $result = array(); - foreach ($a_name AS $key => $val) { + foreach ( $a_name AS $key => $val ) { $result[$key] = '`' . $val . '`'; } return $result; @@ -1132,7 +1150,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { * * @access public */ - function PMA_jsFormat($a_string = '', $add_backquotes = TRUE) + function PMA_jsFormat($a_string = '', $add_backquotes = true) { if (is_string($a_string)) { $a_string = htmlspecialchars($a_string); @@ -1164,7 +1182,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { $the_crlf = "\r\n"; } // Mac case - else if (PMA_USR_OS == 'Mac') { + elseif (PMA_USR_OS == 'Mac') { $the_crlf = "\r"; } // Others @@ -1191,11 +1209,11 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { * * @access public */ - function PMA_countRecords($db, $table, $ret = FALSE, $force_exact = FALSE) + function PMA_countRecords($db, $table, $ret = false, $force_exact = false) { global $err_url, $cfg; if (!$force_exact) { - $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';'); + $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, true) . '\';'); $showtable = PMA_DBI_fetch_assoc($result); $num = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); if ($num < $cfg['MaxExactCount']) { @@ -1213,7 +1231,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { return $num; } else { echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']); - return TRUE; + return true; } } // end of the 'PMA_countRecords()' function @@ -1225,7 +1243,8 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { * * @access public */ - function PMA_reloadNavigation() { + function PMA_reloadNavigation() + { global $cfg; // Reloads the navigation frame via JavaScript if required @@ -1264,31 +1283,31 @@ if (typeof(window.parent) != 'undefined' // Corrects the tooltip text via JS if required if (!empty($GLOBALS['table']) && $cfg['ShowTooltip']) { - $result = PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\''); + $result = PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\''); if ($result) { $tbl_status = PMA_DBI_fetch_assoc($result); $tooltip = (empty($tbl_status['Comment'])) ? '' : $tbl_status['Comment'] . ' '; - $tooltip .= '(' . PMA_formatNumber( $tbl_status['Rows'], 0 ) . ' ' . $GLOBALS['strRows'] . ')'; + $tooltip .= '(' . PMA_formatNumber($tbl_status['Rows'], 0) . ' ' . $GLOBALS['strRows'] . ')'; PMA_DBI_free_result($result); - $uni_tbl = PMA_jsFormat( $GLOBALS['db'] . '.' . $GLOBALS['table'], false ); + $uni_tbl = PMA_jsFormat($GLOBALS['db'] . '.' . $GLOBALS['table'], false); echo "\n"; ?> ', ''; } - if ( $cfg['ShowSQL'] == TRUE + if ( $cfg['ShowSQL'] == true && ( !empty($GLOBALS['sql_query']) || !empty($GLOBALS['display_query']) ) ) { $local_query = !empty($GLOBALS['display_query']) ? $GLOBALS['display_query'] : (($cfg['SQP']['fmtType'] == 'none' && isset($GLOBALS['unparsed_sql']) && $GLOBALS['unparsed_sql'] != '') ? $GLOBALS['unparsed_sql'] : $GLOBALS['sql_query']); // Basic url query part @@ -1337,7 +1356,7 @@ window.parent.updateTableTitle( '', '', '', '', ' $onclick ) ) . ']'; + $edit_link = ' [' . PMA_linkOrButton($edit_link, $GLOBALS['strEdit'], array( 'onclick' => $onclick )) . ']'; } else { $edit_link = ''; } @@ -1416,7 +1435,7 @@ window.parent.updateTableTitle( '', '', '', '', '', '', '', '', '= 1; $d--, $ex-=3 ) { if (isset($GLOBALS['byteUnits'][$d]) && $value >= $li * pow(10, $ex)) { - $value = round($value / ( pow(1024, $d) / $dh) ) /$dh; + $value = round($value / ( pow(1024, $d) / $dh)) /$dh; $unit = $GLOBALS['byteUnits'][$d]; break 1; } // end if @@ -1582,12 +1601,12 @@ window.parent.updateTableTitle( '', ' - * echo PMA_formatNumber( 123456789, 6 ); // 123,457 k - * echo PMA_formatNumber( -123456789, 4, 2 ); // -123.46 M - * echo PMA_formatNumber( -0.003, 6 ); // -3 m - * echo PMA_formatNumber( 0.003, 3, 3 ); // 0.003 - * echo PMA_formatNumber( 0.00003, 3, 2 ); // 0.03 m - * echo PMA_formatNumber( 0, 6 ); // 0 + * echo PMA_formatNumber(123456789, 6); // 123,457 k + * echo PMA_formatNumber(-123456789, 4, 2); // -123.46 M + * echo PMA_formatNumber(-0.003, 6); // -3 m + * echo PMA_formatNumber(0.003, 3, 3); // 0.003 + * echo PMA_formatNumber(0.00003, 3, 2); // 0.03 m + * echo PMA_formatNumber(0, 6); // 0 * * @param double $value the value to format * @param integer $length the max length @@ -1601,12 +1620,13 @@ window.parent.updateTableTitle( '', '', '', '= 1 ) { for ( $d = 8; $d >= 0; $d-- ) { if (isset($units[$d]) && $value >= $li * pow(1000, $d-1)) { - $value = round($value / ( pow(1000, $d) / $dh) ) /$dh; + $value = round($value / ( pow(1000, $d) / $dh)) /$dh; $unit = $units[$d]; break 1; } // end if @@ -1658,17 +1678,17 @@ window.parent.updateTableTitle( '', '= 1 ) elseif ( ! $only_down && (float) $value !== 0.0 ) - $value = number_format( $value, + $value = number_format($value, $comma, $GLOBALS['number_decimal_separator'], - $GLOBALS['number_thousands_separator'] ); + $GLOBALS['number_thousands_separator']); return $sign . $value . ' ' . $unit; } // end of the 'PMA_formatNumber' function @@ -1679,15 +1699,16 @@ window.parent.updateTableTitle( '', '', '', ' '', ); - $tab = array_merge( $defaults, $tab ); + $tab = array_merge($defaults, $tab); // determine aditional style-class if ( empty( $tab['class'] ) ) { @@ -1769,7 +1790,7 @@ window.parent.updateTableTitle( '', '', ' $value ) { - $tab['link'] .= '&' . urlencode( $param ) . '=' - . urlencode( $value ); + foreach ( $tab['args'] as $param => $value ) { + $tab['link'] .= '&' . urlencode($param) . '=' + . urlencode($value); } } } @@ -1792,24 +1813,23 @@ window.parent.updateTableTitle( '', '%2$s'; - $tab['text'] = sprintf( $image, htmlentities( $tab['icon'] ), $tab['text'] ); + $tab['text'] = sprintf($image, htmlentities($tab['icon']), $tab['text']); } // check to not display an empty link-text elseif ( empty( $tab['text'] ) ) { $tab['text'] = '?'; - trigger_error( __FILE__ . '(' . __LINE__ . '): ' - . 'empty linktext in function ' . __FUNCTION__ . '()', - E_USER_NOTICE ); + trigger_error('empty linktext in function ' . __FUNCTION__ . '()', + E_USER_NOTICE); } if ( ! empty( $tab['link'] ) ) { - $out = '' . $tab['text'] . ''; } else { - $out = '' + $out = '' . $tab['text'] . ''; } @@ -1825,13 +1845,14 @@ window.parent.updateTableTitle( '', '' . "\n" - .'