📄 formdisplay.class.php
字号:
case 'array': $type = 'list'; $value = (array) $value; $value_default = (array) $value_default; break; case 'NULL': trigger_error("Field $system_path has no type", E_USER_WARNING); return; } // TrustedProxies requires changes before displaying if ($system_path == 'TrustedProxies') { foreach ($value as $ip => &$v) { if (!preg_match('/^-\d+$/', $ip)) { $v = $ip . ': ' . $v; } } } // send default value to form's JS $js_line = '\'' . $translated_path . '\': '; switch ($type) { case 'text': $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; display_input($translated_path, $name, $description, $type, $value, $value_is_default, $opts); } /** * Displays errors */ public function displayErrors() { $this->_validate(); if (count($this->errors) == 0) { return; } foreach ($this->errors as $system_path => $error_list) { if (isset($this->system_paths[$system_path])) { $path = $this->system_paths[$system_path]; $name = PMA_lang_name($path); } else { $name = $GLOBALS["strSetupForm_$system_path"]; } display_errors($name, $error_list); } } /** * Reverts erroneous fields to their default values */ public function fixErrors() { $this->_validate(); if (count($this->errors) == 0) { return; } $cf = ConfigFile::getInstance(); foreach (array_keys($this->errors) as $work_path) { if (!isset($this->system_paths[$work_path])) { continue; } $canonical_path = $this->system_paths[$work_path]; $cf->set($work_path, $cf->getDefault($canonical_path)); } } /** * Validates select field and casts $value to correct type * * @param string $value * @param array $allowed * @return bool */ private function _validateSelect(&$value, array $allowed) { foreach ($allowed as $v) { if ($value == $v) { settype($value, gettype($v)); return true; } } return false; } /** * Validates and saves form data to session * * @param array|string $forms array of form names * @param bool $allow_partial_save allows for partial form saving on failed validation * @return boolean true on success (no errors and all saved) */ public function save($forms, $allow_partial_save = true) { $result = true; $cf = ConfigFile::getInstance(); $forms = (array) $forms; $values = array(); $to_save = array(); $this->errors = array(); foreach ($forms as $form) { /* @var $form Form */ if (isset($this->forms[$form])) { $form = $this->forms[$form]; } else { continue; } // get current server id $change_index = $form->index === 0 ? $cf->getServerCount() + 1 : false; // grab POST values foreach ($form->fields as $field => $system_path) { $work_path = array_search($system_path, $this->system_paths); $key = $this->translated_paths[$work_path]; // ensure the value is set if (!isset($_POST[$key])) { // checkboxes aren't set by browsers if they're off if ($form->getOptionType($field) == 'boolean') { $_POST[$key] = false; } else { $this->errors[$form->name][] = PMA_lang( 'error_missing_field_data', '<i>' . PMA_lang_name($system_path) . '</i>'); $result = false; continue; } } // cast variables to correct type $type = $form->getOptionType($field); switch ($type) { case 'double': settype($_POST[$key], 'float'); break; case 'boolean': case 'integer': if ($_POST[$key] !== '') { settype($_POST[$key], $type); } break; case 'select': if (!$this->_validateSelect($_POST[$key], $form->getOptionValueList($system_path))) { $this->errors[$work_path][] = $GLOBALS["strstrSetuperror_incorrect_value"]; $result = false; continue; } break; case 'string': $_POST[$key] = trim($_POST[$key]); break; case 'array': // eliminate empty values and ensure we have an array $post_values = explode("\n", $_POST[$key]); $_POST[$key] = array(); foreach ($post_values as $v) { $v = trim($v); if ($v !== '') { $_POST[$key][] = $v; } } break; } // now we have value with proper type $values[$system_path] = $_POST[$key]; if ($change_index !== false) { $work_path = str_replace("Servers/$form->index/", "Servers/$change_index/", $work_path); } $to_save[$work_path] = $system_path; } } // save forms if ($allow_partial_save || empty($this->errors)) { foreach ($to_save as $work_path => $path) { // TrustedProxies requires changes before saving if ($path == 'TrustedProxies') { $proxies = array(); $i = 0; foreach ($values[$path] as $value) { $matches = array(); if (preg_match("/^(.+):(?:[ ]?)(\\w+)$/", $value, $matches)) { // correct 'IP: HTTP header' pair $ip = trim($matches[1]); $proxies[$ip] = trim($matches[2]); } else { // save also incorrect values $proxies["-$i"] = $value; $i++; } } $values[$path] = $proxies; } $cf->set($work_path, $values[$path], $path); } } // don't look for non-critical errors $this->_validate(); return $result; } /** * Tells whether form validation failed * * @return boolean */ public function hasErrors() { return count($this->errors) > 0; } /** * Returns link to documentation * * @param string $path * @return string */ public function getDocLink($path) { $test = substr($path, 0, 6); if ($test == 'Import' || $test == 'Export') { return ''; } return '../Documentation.html#cfg_' . self::_getOptName($path); } /** * Returns link to wiki * * @param string $path * @return string */ public function getWikiLink($path) { $opt_name = self::_getOptName($path); if (substr($opt_name, 0, 7) == 'Servers') { $opt_name = substr($opt_name, 8); if (strpos($opt_name, 'AllowDeny') === 0) { $opt_name = str_replace('_', '_.28', $opt_name) . '.29'; } } $test = substr($path, 0, 6); if ($test == 'Import') { $opt_name = substr($opt_name, 7); if ($opt_name == 'format') { $opt_name = 'format_2'; } } if ($test == 'Export') { $opt_name = substr($opt_name, 7); } return 'http://wiki.cihar.com/pma/Config#' . $opt_name; } /** * Changes path so it can be used in URLs * * @param string $path * @return string */ private static function _getOptName($path) { return str_replace(array('Servers/1/', '/'), array('Servers/', '_'), $path); }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -