【php开源代码栏目提醒】:本文主要为网学会员提供common.lib.php,希望对需要common.lib.php网友有所帮助,学习一下!
<?php
/* $Id: common.lib.php,v 2.266.2.27 2006/06/30 13:11:04 lem9 Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Misc stuff and functions used by almost all the scripts.
* Among other things, it contains the advanced authentication work.
*/
/**
* Order of sections for common.lib.php:
*
* the include of libraries/defines_mysql.lib.php must be after the connection
* to db to get the MySql version
*
* the authentication libraries must be before the connection to db
*
* ... so the required order is:
*
* 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
* - authentication work
* - load of the libraries/defines_
mysql.lib.php library to get the MySQL
* release number
*/
/**
* For now, avoid warnings of E_STRICT mode
* (this must be done before function definitions)
*/
if (defined('E_STRICT')) {
$old_error_reporting = error_reporting(0);
if ($old_error_reporting & E_STRICT) {
error_reporting($old_error_reporting ^ E_STRICT);
} else {
error_reporting($old_error_reporting);
}
unset($old_error_reporting);
}
/**
* Avoid object cloning errors
*/
@ini_set('zend.ze1_compatibility_mode',false);
/******************************************************************************/
/* 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
* like a cookie or form.
*
* @param string The path to check
*
* @return string The secured path
*
* @access public
* @author Marc Delisle (lem9@users.sourceforge.net)
*/
function PMA_securePath($path)
{
// change .. to .
$path = preg_replace('@\.\.*@', '.', $path);
return $path;
} // end function
/**
* returns array with dbs grouped with extended infos
*
* @uses $GLOBALS['dblist'] from PMA_availableDatabases()
* @uses $GLOBALS['num_dbs'] from PMA_availableDatabases()
* @uses $GLOBALS['cfgRelation']['commwork']
* @uses $GLOBALS['cfg']['ShowTooltip']
* @uses $GLOBALS['cfg']['LeftFrameDBTree']
* @uses $GLOBALS['cfg']['LeftFrameDBSeparator']
* @uses $GLOBALS['cfg']['ShowTooltipAliasDB']
* @uses PMA_availableDatabases()
* @uses PMA_getTableCount()
* @uses PMA_getComments()
* @uses PMA_availableDatabases()
* @uses is_array()
* @uses implode()
* @uses strstr()
* @uses explode()
* @return array db list
*/
function PMA_getDbList()
{
if (empty($GLOBALS['dblist'])) {
PMA_availableDatabases();
}
$dblist = $GLOBALS['dblist'];
$dbgroups = array();
$parts = array();
foreach ($dblist as $key => $db) {
// garvin: Get comments from PMA comments table
$db_tooltip = '';
if ($GLOBALS['cfg']['ShowTooltip']
&& $GLOBALS['cfgRelation']['commwork']) {
$_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']))
{
$pos = strrpos($db, $GLOBALS['cfg']['LeftFrameDBSeparator']);
$group = substr($db, 0, $pos);
$disp_name_cut = substr($db, $pos);
} else {
$group = $db;
$disp_name_cut = $db;
}
$disp_name = $db;
if ($db_tooltip && $GLOBALS['cfg']['ShowTooltipAliasDB']) {
$disp_name = $db_tooltip;
$disp_name_cut = $db_tooltip;
$db_tooltip = $db;
}
$dbgroups[$group][$db] = array(
'name' => $db,
'disp_name_cut' => $disp_name_cut,
'disp_name' => $disp_name,
'comment' => $db_tooltip,
'num_tables' => PMA_getTableCount($db),
);
} // end foreach ($dblist as $db)
return $dbgroups;
}
/**
* returns html code for select form element with dbs
*
* @return string html code select
*/
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 = '<select name="db" id="lightm_db"
xml:lang="en" dir="ltr"'
.' onchange="if (this.value != \'\') window.parent.openDb(this.value);">' . "\n"
.'<option value="" dir="' . $GLOBALS['text_dir'] . '">('