PMA\libraries\Util::expandUserString PHP Method

expandUserString() public static method

Formats user string, expanding @VARIABLES@, accepting strftime format string.
public static expandUserString ( string $string, array | string $escape = null, array $updates = [] ) : string
$string string Text where to do expansion.
$escape array | string Function to call for escaping variable values. Can also be an array of: - the escape method name - the class that contains the method - location of the class (for inclusion)
$updates array Array with overrides for default parameters (obtained from GLOBALS).
return string
    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);
    }

Usage Example

コード例 #1
0
ファイル: Header.php プロジェクト: iShareLife/phpmyadmin
 /**
  * If the page is missing the title, this function
  * will set it to something reasonable
  *
  * @return string
  */
 private function _getPageTitle()
 {
     if (empty($this->_title)) {
         if ($GLOBALS['server'] > 0) {
             if (!empty($GLOBALS['table'])) {
                 $temp_title = $GLOBALS['cfg']['TitleTable'];
             } else {
                 if (!empty($GLOBALS['db'])) {
                     $temp_title = $GLOBALS['cfg']['TitleDatabase'];
                 } elseif (!empty($GLOBALS['cfg']['Server']['host'])) {
                     $temp_title = $GLOBALS['cfg']['TitleServer'];
                 } else {
                     $temp_title = $GLOBALS['cfg']['TitleDefault'];
                 }
             }
             $this->_title = htmlspecialchars(Util::expandUserString($temp_title));
         } else {
             $this->_title = 'phpMyAdmin';
         }
     }
     return $this->_title;
 }
All Usage Examples Of PMA\libraries\Util::expandUserString
Util