public static function expandUserString($string, $escape = null, $updates = array())
{
/* Content */
$vars = array();
$vars['http_host'] = PMA_getenv('HTTP_HOST');
$vars['server_name'] = $GLOBALS['cfg']['Server']['host'];
$vars['server_verbose'] = $GLOBALS['cfg']['Server']['verbose'];
if (empty($GLOBALS['cfg']['Server']['verbose'])) {
$vars['server_verbose_or_name'] = $GLOBALS['cfg']['Server']['host'];
} else {
$vars['server_verbose_or_name'] = $GLOBALS['cfg']['Server']['verbose'];
}
$vars['database'] = $GLOBALS['db'];
$vars['table'] = $GLOBALS['table'];
$vars['phpmyadmin_version'] = 'phpMyAdmin ' . PMA_VERSION;
/* Update forced variables */
foreach ($updates as $key => $val) {
$vars[$key] = $val;
}
/* Replacement mapping */
/*
* The __VAR__ ones are for backward compatibility, because user
* might still have it in cookies.
*/
$replace = array('@HTTP_HOST@' => $vars['http_host'], '@SERVER@' => $vars['server_name'], '__SERVER__' => $vars['server_name'], '@VERBOSE@' => $vars['server_verbose'], '@VSERVER@' => $vars['server_verbose_or_name'], '@DATABASE@' => $vars['database'], '__DB__' => $vars['database'], '@TABLE@' => $vars['table'], '__TABLE__' => $vars['table'], '@PHPMYADMIN@' => $vars['phpmyadmin_version']);
/* Optional escaping */
if (!is_null($escape)) {
if (is_array($escape)) {
$escape_class = new $escape[1]();
$escape_method = $escape[0];
}
foreach ($replace as $key => $val) {
if (is_array($escape)) {
$replace[$key] = $escape_class->{$escape_method}($val);
} else {
$replace[$key] = $escape == 'backquote' ? self::$escape($val) : $escape($val);
}
}
}
/* Backward compatibility in 3.5.x */
if (mb_strpos($string, '@FIELDS@') !== false) {
$string = strtr($string, array('@FIELDS@' => '@COLUMNS@'));
}
/* Fetch columns list if required */
if (mb_strpos($string, '@COLUMNS@') !== false) {
$columns_list = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $GLOBALS['table']);
// sometimes the table no longer exists at this point
if (!is_null($columns_list)) {
$column_names = array();
foreach ($columns_list as $column) {
if (!is_null($escape)) {
$column_names[] = self::$escape($column['Field']);
} else {
$column_names[] = $column['Field'];
}
}
$replace['@COLUMNS@'] = implode(',', $column_names);
} else {
$replace['@COLUMNS@'] = '*';
}
}
/* Do the replacement */
return strtr(strftime($string), $replace);
}