From: <jhe...@us...> - 2002-08-05 08:21:09
|
Update of /cvsroot/upcase-project/UpCase/lib In directory usw-pr-cvs1:/tmp/cvs-serv30610 Modified Files: uc_config.php Log Message: Use parser from uc_xmlparser.php Index: uc_config.php =================================================================== RCS file: /cvsroot/upcase-project/UpCase/lib/uc_config.php,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** uc_config.php 16 Jul 2002 15:31:56 -0000 1.1.1.1 --- uc_config.php 5 Aug 2002 08:21:07 -0000 1.2 *************** *** 1,115 **** <?php - include_once("config/uc_config.inc"); ! class UcConfig ! { ! var $db_name; ! var $db_host; ! var $db_user; ! var $db_passwd; ! var $tbl_users; ! var $tbl_sessions; ! var $tbl_groups; ! var $tbl_memberships; ! var $tbl_prefix; ! ! function UcConfig() ! { ! $parser = new UcConfigParser(); ! $ar = $parser->parse($mainconfig); ! $this->db_name = $ar[name]; ! $this->db_host = $ar[host]; ! $this->db_user = $ar[user]; ! $this->tbl_sessions = $ar[prefix] . $ar[table][sessions]; ! $this->tbl_users = $ar[prefix] . $ar[table][users]; ! $this->tbl_groups = $ar[prefix] . $ar[table][groups]; ! $this->tbl_memberships = $ar[prefix] . $ar[table][memberships]; ! $this->tbl_prefix = $ar[prefix]; ! } ! } ! class UcConfigParser { ! var $parser; ! var $config_data; ! var $xml_data; ! var $db_data; ! var $in_comment; ! ! function UcConfigParser() ! { ! $this->parser = xml_parser_create(); ! xml_set_object($this->parser, &$this); ! xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1); ! xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); ! xml_set_default_handler($this->parser, "default_handler"); ! xml_set_element_handler($this->parser, "tag_open", "tag_close"); ! } ! function parse($config_file) ! { ! $this->in_comment = FALSE; ! $this->config_data = implode("", file($config_file)); ! xml_parse($this->parser, $this->config_data, TRUE); ! print_r($this->db_data); ! } ! function tag_open($parser, $tag, $attribs) ! { ! if ($tag == "table") ! { ! $this->table_name = $attribs[data]; ! } ! } ! ! function tag_close($parser, $tag) ! { ! if ($tag == "database" || $tag == "upcase") ! { ! return; ! } ! if ($tag == "table") ! { ! $this->db_data[table][$this->table_name] = $this->xml_data; ! return; ! } ! $this->db_data[$tag] = $this->xml_data; ! } ! function default_handler($parser, $data) { ! if (trim($data) == "" || trim($data) == "<?xml version=\"1.0\"?>") ! { ! return; ! } ! // Handle comments ! if (strpos($data, "<!--") && !$this->in_comment) ! { ! if (strpos($data, "-->") !== FALSE) ! { ! return; ! } - $this->in_comment = TRUE; - return; - } ! if (strpos($data, "-->") && $this->in_comment) ! { ! $this->in_comment = FALSE; ! return; ! } ! if (!$this->in_comment) { ! $this->xml_data = trim($data); ! } } ! ! } // UcConfigParser ?> --- 1,102 ---- <?php ! include_once("lib/uc_dbdata.php"); ! include_once("lib/uc_xmlparser.php"); ! class UcConfig extends DbData { + /** + * The root url for the whole site + * + * @var string + * @access public + */ + var $wwwRoot; ! /** ! * The root for the physiqual files on disk ! * ! * @var string ! * @access public ! */ ! var $filesRoot; ! /** ! * The root url to access installed modules ! * ! * @var string ! * @access public ! */ ! var $wwwModules; ! /** ! * The directory where the modules are stored on disk ! * ! * @var string ! * @access public ! */ ! var $modulesRoot; ! /** ! * The default language for the site ! * ! * @var string ! * @access public ! */ ! var $defaultLang; ! /** ! * The supported languages in the site ! * ! * @var array ! * @access public ! */ ! var $languages; ! /** ! * Constructor for UcConfig object. ! * ! * This create a UcConfig object filled with all the value read ! * from the xml config file. ! * ! * @param string $configFile The xml config file ! */ ! function UcConfig($configFile) { ! DbData::DbData($configFile); ! $parser = new UcXmlParser(); ! $tree = $parser->parse($configFile); ! ! $ar = $tree->getElements("paths"); ! $pathNode = $ar[0]; ! ! $ar = $pathNode->getElements("rooturl"); ! $this->wwwRoot = $ar[0]->textElements[0]; ! $ar = $pathNode->getElements("modsurl"); ! $this->wwwModules = $ar[0]->textElements[0]; ! $ar = $pathNode->getElements("docroot"); ! $this->filesRoot = $ar[0]->textElements[0]; ! ! $ar = $pathNode->getElements("modules"); ! $this->modulesRoot = $ar[0]->textElements[0]; ! ! $ar = $tree->getElements("languages"); ! $langNode = $ar[0]; ! ! $ar = $langNode->getElements("defaultlang"); ! $this->defaultLang = $ar[0]->textElements[0]; ! ! $langs = $langNode->getElements("lang"); ! $this->languages = array(); ! foreach ($langs as $l) { ! $this->languages[$l->attributes["id"]] = $l->textElements[0]; ! } } ! } ?> |