예제 #1
0
 /**
  * Test for ConfigFile::getConfigArray
  *
  * @return void
  * @test
  */
 public function testGetConfigArray()
 {
     $this->object->setPersistKeys(array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE));
     $this->object->set('Array/test', array('x', 'y'));
     $default_value = $this->object->getDefault(self::SIMPLE_KEY_WITH_DEFAULT_VALUE);
     $this->assertEquals(array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $default_value, 'Array/test' => array('x', 'y')), $this->object->getConfigArray());
 }
 /**
  * Creates config file
  *
  * @param ConfigFile $cf Config file instance
  *
  * @return string
  */
 public static function getConfigFile(ConfigFile $cf)
 {
     $crlf = isset($_SESSION['eol']) && $_SESSION['eol'] == 'win' ? "\r\n" : "\n";
     $c = $cf->getConfig();
     // header
     $ret = '<?php' . $crlf . '/*' . $crlf . ' * Generated configuration file' . $crlf . ' * Generated by: phpMyAdmin ' . $GLOBALS['PMA_Config']->get('PMA_VERSION') . ' setup script' . $crlf . ' * Date: ' . date(DATE_RFC1123) . $crlf . ' */' . $crlf . $crlf;
     // servers
     if ($cf->getServerCount() > 0) {
         $ret .= "/* Servers configuration */{$crlf}\$i = 0;" . $crlf . $crlf;
         foreach ($c['Servers'] as $id => $server) {
             $ret .= '/* Server: ' . strtr($cf->getServerName($id) . " [{$id}] ", '*/', '-') . "*/" . $crlf . '$i++;' . $crlf;
             foreach ($server as $k => $v) {
                 $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
                 $ret .= "\$cfg['Servers'][\$i]['{$k}'] = " . (is_array($v) && self::_isZeroBasedArray($v) ? self::_exportZeroBasedArray($v, $crlf) : var_export($v, true)) . ';' . $crlf;
             }
             $ret .= $crlf;
         }
         $ret .= '/* End of servers configuration */' . $crlf . $crlf;
     }
     unset($c['Servers']);
     // other settings
     $persistKeys = $cf->getPersistKeysMap();
     foreach ($c as $k => $v) {
         $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
         $ret .= self::_getVarExport($k, $v, $crlf);
         if (isset($persistKeys[$k])) {
             unset($persistKeys[$k]);
         }
     }
     // keep 1d array keys which are present in $persist_keys (config.values.php)
     foreach (array_keys($persistKeys) as $k) {
         if ($GLOBALS['PMA_String']->strpos($k, '/') === false) {
             $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
             $ret .= self::_getVarExport($k, $cf->getDefault($k), $crlf);
         }
     }
     $ret .= '?' . '>';
     return $ret;
 }
예제 #3
0
 /**
  * Prepares data for input field display and outputs HTML code
  *
  * @param Form      $form                 Form object
  * @param string    $field                field name as it appears in $form
  * @param string    $system_path          field path, eg. Servers/1/verbose
  * @param string    $work_path            work path, eg. Servers/4/verbose
  * @param string    $translated_path      work path changed so that it can be
  *                                        used as XHTML id
  * @param bool      $show_restore_default whether show "restore default" button
  *                                        besides the input field
  * @param bool|null $userprefs_allow      whether user preferences are enabled
  *                                        for this field (null - no support,
  *                                        true/false - enabled/disabled)
  * @param array     &$js_default          array which stores JavaScript code
  *                                        to be displayed
  *
  * @return string HTML for input field
  */
 private function _displayFieldInput(Form $form, $field, $system_path, $work_path, $translated_path, $show_restore_default, $userprefs_allow, array &$js_default)
 {
     $name = PMA_langName($system_path);
     $description = PMA_langName($system_path, 'desc', '');
     $value = $this->_configFile->get($work_path);
     $value_default = $this->_configFile->getDefault($system_path);
     $value_is_default = false;
     if ($value === null || $value === $value_default) {
         $value = $value_default;
         $value_is_default = true;
     }
     $opts = array('doc' => $this->getDocLink($system_path), 'show_restore_default' => $show_restore_default, 'userprefs_allow' => $userprefs_allow, 'userprefs_comment' => PMA_langName($system_path, 'cmt', ''));
     if (isset($form->default[$system_path])) {
         $opts['setvalue'] = $form->default[$system_path];
     }
     if (isset($this->_errors[$work_path])) {
         $opts['errors'] = $this->_errors[$work_path];
     }
     $type = '';
     switch ($form->getOptionType($field)) {
         case 'string':
             $type = 'text';
             break;
         case 'short_string':
             $type = 'short_text';
             break;
         case 'double':
         case 'integer':
             $type = 'number_text';
             break;
         case 'boolean':
             $type = 'checkbox';
             break;
         case 'select':
             $type = 'select';
             $opts['values'] = $form->getOptionValueList($form->fields[$field]);
             break;
         case 'array':
             $type = 'list';
             $value = (array) $value;
             $value_default = (array) $value_default;
             break;
         case 'group':
             // :group:end is changed to :group:end:{unique id} in Form class
             $htmlOutput = '';
             if (mb_substr($field, 7, 4) != 'end:') {
                 $htmlOutput .= PMA_displayGroupHeader(mb_substr($field, 7));
             } else {
                 PMA_displayGroupFooter();
             }
             return $htmlOutput;
         case 'NULL':
             trigger_error("Field {$system_path} has no type", E_USER_WARNING);
             return null;
     }
     // detect password fields
     if ($type === 'text' && mb_substr($translated_path, -9) === '-password') {
         $type = 'password';
     }
     // TrustedProxies requires changes before displaying
     if ($system_path == 'TrustedProxies') {
         foreach ($value as $ip => &$v) {
             if (!preg_match('/^-\\d+$/', $ip)) {
                 $v = $ip . ': ' . $v;
             }
         }
     }
     $this->_setComments($system_path, $opts);
     // send default value to form's JS
     $js_line = '\'' . $translated_path . '\': ';
     switch ($type) {
         case 'text':
         case 'short_text':
         case 'number_text':
         case 'password':
             $js_line .= '\'' . PMA_escapeJsString($value_default) . '\'';
             break;
         case 'checkbox':
             $js_line .= $value_default ? 'true' : 'false';
             break;
         case 'select':
             $value_default_js = is_bool($value_default) ? (int) $value_default : $value_default;
             $js_line .= '[\'' . PMA_escapeJsString($value_default_js) . '\']';
             break;
         case 'list':
             $js_line .= '\'' . PMA_escapeJsString(implode("\n", $value_default)) . '\'';
             break;
     }
     $js_default[] = $js_line;
     return PMA_displayInput($translated_path, $name, $type, $value, $description, $value_is_default, $opts);
 }