From 3ee16453993960c5e043aa0eda708aa9b5027d8f Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sat, 30 Jan 2010 20:49:53 -0700 Subject: [PATCH] Make Horde_Config_Form autoloadable --- framework/Core/lib/Horde/Config.php | 146 ------------------------------ framework/Core/lib/Horde/Config/Form.php | 151 +++++++++++++++++++++++++++++++ framework/Core/package.xml | 8 +- horde/admin/setup/config.php | 3 +- 4 files changed, 158 insertions(+), 150 deletions(-) create mode 100644 framework/Core/lib/Horde/Config/Form.php diff --git a/framework/Core/lib/Horde/Config.php b/framework/Core/lib/Horde/Config.php index f09d608e9..f24d44460 100644 --- a/framework/Core/lib/Horde/Config.php +++ b/framework/Core/lib/Horde/Config.php @@ -1567,149 +1567,3 @@ class Horde_Config } } - -/** - * A Horde_Form:: form that implements a user interface for the config - * system. - * - * @author Chuck Hagenbuch - * @package Core - */ -class ConfigForm extends Horde_Form -{ - /** - * Don't use form tokens for the configuration form - while - * generating configuration info, things like the Token system - * might not work correctly. This saves some headaches. - * - * @var boolean - */ - protected $_useFormToken = false; - - /** - * Contains the Horde_Config object that this form represents. - * - * @var Horde_Config - */ - protected $_xmlConfig; - - /** - * Contains the Horde_Variables object of this form. - * - * @var Horde_Variables - */ - protected $_vars; - - /** - * Constructor. - * - * @param Horde_Variables &$vars The variables object of this form. - * @param string $app The name of the application that this - * configuration form is for. - */ - public function __construct(&$vars, $app) - { - parent::__construct($vars); - - $this->_xmlConfig = new Horde_Config($app); - $this->_vars = &$vars; - $config = $this->_xmlConfig->readXMLConfig(); - $this->addHidden('', 'app', 'text', true); - $this->_buildVariables($config); - } - - /** - * Builds the form based on the specified level of the configuration tree. - * - * @param array $config The portion of the configuration tree for that - * the form fields should be created. - * @param string $prefix A string representing the current position - * inside the configuration tree. - */ - protected function _buildVariables($config, $prefix = '') - { - if (!is_array($config)) { - return; - } - - foreach ($config as $name => $configitem) { - $prefixedname = empty($prefix) ? $name : $prefix . '|' . $name; - $varname = str_replace('|', '__', $prefixedname); - if ($configitem == 'placeholder') { - continue; - } elseif (isset($configitem['tab'])) { - $this->setSection($configitem['tab'], $configitem['desc']); - } elseif (isset($configitem['switch'])) { - $selected = $this->_vars->getExists($varname, $wasset); - $var_params = array(); - $select_option = true; - if (is_bool($configitem['default'])) { - $configitem['default'] = $configitem['default'] ? 'true' : 'false'; - } - foreach ($configitem['switch'] as $option => $case) { - $var_params[$option] = $case['desc']; - if ($option == $configitem['default']) { - $select_option = false; - if (!$wasset) { - $selected = $option; - } - } - } - - $name = '$conf[' . implode('][', explode('|', $prefixedname)) . ']'; - $desc = $configitem['desc']; - - $v = &$this->addVariable($name, $varname, 'enum', true, false, $desc, array($var_params, $select_option)); - if (array_key_exists('default', $configitem)) { - $v->setDefault($configitem['default']); - } - if (!empty($configitem['is_default'])) { - $v->_new = true; - } - $v_action = Horde_Form_Action::factory('reload'); - $v->setAction($v_action); - if (isset($selected) && isset($configitem['switch'][$selected])) { - $this->_buildVariables($configitem['switch'][$selected]['fields'], $prefix); - } - } elseif (isset($configitem['_type'])) { - $required = (isset($configitem['required'])) ? $configitem['required'] : true; - $type = $configitem['_type']; - - // FIXME: multienum fields can well be required, meaning that - // you need to select at least one entry. Changing this before - // Horde 4.0 would break a lot of configuration files though. - if ($type == 'multienum' || $type == 'header' || - $type == 'description') { - $required = false; - } - - $var_params = ($type == 'multienum' || $type == 'enum') - ? array($configitem['values']) - : array(); - - if ($type == 'header' || $type == 'description') { - $name = $configitem['desc']; - $desc = null; - } else { - $name = '$conf[' . implode('][', explode('|', $prefixedname)) . ']'; - $desc = $configitem['desc']; - if ($type == 'php') { - $type = 'text'; - $desc .= "\nEnter a valid PHP expression."; - } - } - - $v = &$this->addVariable($name, $varname, $type, $required, false, $desc, $var_params); - if (isset($configitem['default'])) { - $v->setDefault($configitem['default']); - } - if (!empty($configitem['is_default'])) { - $v->_new = true; - } - } else { - $this->_buildVariables($configitem, $prefixedname); - } - } - } - -} diff --git a/framework/Core/lib/Horde/Config/Form.php b/framework/Core/lib/Horde/Config/Form.php new file mode 100644 index 000000000..b3194280f --- /dev/null +++ b/framework/Core/lib/Horde/Config/Form.php @@ -0,0 +1,151 @@ + + * @package Core + */ +class Horde_Config_Form extends Horde_Form +{ + /** + * Don't use form tokens for the configuration form - while + * generating configuration info, things like the Token system + * might not work correctly. This saves some headaches. + * + * @var boolean + */ + protected $_useFormToken = false; + + /** + * Contains the Horde_Config object that this form represents. + * + * @var Horde_Config + */ + protected $_xmlConfig; + + /** + * Contains the Horde_Variables object of this form. + * + * @var Horde_Variables + */ + protected $_vars; + + /** + * Constructor. + * + * @param Horde_Variables &$vars The variables object of this form. + * @param string $app The name of the application that this + * configuration form is for. + */ + public function __construct(&$vars, $app) + { + parent::__construct($vars); + + $this->_xmlConfig = new Horde_Config($app); + $this->_vars = &$vars; + $config = $this->_xmlConfig->readXMLConfig(); + $this->addHidden('', 'app', 'text', true); + $this->_buildVariables($config); + } + + /** + * Builds the form based on the specified level of the configuration tree. + * + * @param array $config The portion of the configuration tree for that + * the form fields should be created. + * @param string $prefix A string representing the current position + * inside the configuration tree. + */ + protected function _buildVariables($config, $prefix = '') + { + if (!is_array($config)) { + return; + } + + foreach ($config as $name => $configitem) { + $prefixedname = empty($prefix) ? $name : $prefix . '|' . $name; + $varname = str_replace('|', '__', $prefixedname); + if ($configitem == 'placeholder') { + continue; + } elseif (isset($configitem['tab'])) { + $this->setSection($configitem['tab'], $configitem['desc']); + } elseif (isset($configitem['switch'])) { + $selected = $this->_vars->getExists($varname, $wasset); + $var_params = array(); + $select_option = true; + if (is_bool($configitem['default'])) { + $configitem['default'] = $configitem['default'] ? 'true' : 'false'; + } + foreach ($configitem['switch'] as $option => $case) { + $var_params[$option] = $case['desc']; + if ($option == $configitem['default']) { + $select_option = false; + if (!$wasset) { + $selected = $option; + } + } + } + + $name = '$conf[' . implode('][', explode('|', $prefixedname)) . ']'; + $desc = $configitem['desc']; + + $v = &$this->addVariable($name, $varname, 'enum', true, false, $desc, array($var_params, $select_option)); + if (array_key_exists('default', $configitem)) { + $v->setDefault($configitem['default']); + } + if (!empty($configitem['is_default'])) { + $v->_new = true; + } + $v_action = Horde_Form_Action::factory('reload'); + $v->setAction($v_action); + if (isset($selected) && isset($configitem['switch'][$selected])) { + $this->_buildVariables($configitem['switch'][$selected]['fields'], $prefix); + } + } elseif (isset($configitem['_type'])) { + $required = (isset($configitem['required'])) ? $configitem['required'] : true; + $type = $configitem['_type']; + + // FIXME: multienum fields can well be required, meaning that + // you need to select at least one entry. Changing this before + // Horde 4.0 would break a lot of configuration files though. + if ($type == 'multienum' || $type == 'header' || + $type == 'description') { + $required = false; + } + + $var_params = ($type == 'multienum' || $type == 'enum') + ? array($configitem['values']) + : array(); + + if ($type == 'header' || $type == 'description') { + $name = $configitem['desc']; + $desc = null; + } else { + $name = '$conf[' . implode('][', explode('|', $prefixedname)) . ']'; + $desc = $configitem['desc']; + if ($type == 'php') { + $type = 'text'; + $desc .= "\nEnter a valid PHP expression."; + } + } + + $v = &$this->addVariable($name, $varname, $type, $required, false, $desc, $var_params); + if (isset($configitem['default'])) { + $v->setDefault($configitem['default']); + } + if (!empty($configitem['is_default'])) { + $v->_new = true; + } + } else { + $this->_buildVariables($configitem, $prefixedname); + } + } + } + +} diff --git a/framework/Core/package.xml b/framework/Core/package.xml index d3b7c7ffe..6b2d8f793 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -49,12 +49,15 @@ Application Framework. + + + - - + + @@ -145,6 +148,7 @@ Application Framework. + diff --git a/horde/admin/setup/config.php b/horde/admin/setup/config.php index f344f8193..44b17cb1a 100644 --- a/horde/admin/setup/config.php +++ b/horde/admin/setup/config.php @@ -29,8 +29,7 @@ if (empty($app) || !in_array($app, $registry->listAllApps())) { $vars = Horde_Variables::getDefaultVariables(); -require_once 'Horde/Config.php'; -$form = new ConfigForm($vars, $app); +$form = new Horde_Config_Form($vars, $app); $form->setButtons(sprintf(_("Generate %s Configuration"), $appname)); if (file_exists($registry->get('fileroot', $app) . '/config/conf.bak.php')) { $form->appendButtons(_("Revert Configuration")); -- 2.11.0