'; $this->xmlfile = $file; $this->mosParameter = $mosParameter; $this->name = $name; $this->setTree(); $parser = xml_parser_create(); $startfunc = array (&$this, 'start_element'); $endfunc = array (&$this, 'end_element'); $charfunc = array (&$this, 'character_data'); xml_set_element_handler ($parser, $startfunc, $endfunc); xml_set_character_data_handler ($parser, $charfunc); $fp = fopen($file, 'rb'); while ($data = fread($fp, 4096) AND !$this->terminalError) { $data = str_replace('&', ' ampersand ', $data); $ret = xml_parse($parser, $data, feof($fp)) or die (sprintf('XML ERROR: %s at line %d', xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser))); } if (count($this->opentags) != 0) { $tags = implode (', ', $this->opentags); trigger_error ("XML error - unclosed tag(s) ($tags) at end of file"); } xml_parser_free($parser); if (count($this->errors)) var_dump ($this->errors); } function setTree () { $this->accept['MOSINSTALL'] = array ('NAME', 'CREATIONDATE', 'AUTHOR', 'COPYRIGHT', 'LICENSE', 'AUTHOREMAIL', 'AUTHORURL', 'VERSION', 'DESCRIPTION', 'FILES', 'MEDIA', 'PARAMS', 'INSTALL', 'UNINSTALL', 'INSTALLFILE', 'UNINSTALLFILE', 'ADMINISTRATION', 'IMAGES', 'CSS'); $this->accept['PARAMS'] = array ('PARAM'); $this->accept['PARAM'] = array ('OPTION'); $this->accept['FILES'] = array ('FILENAME'); $this->accept['INSTALL'] = array ('QUERIES'); $this->accept['UNINSTALL'] = array ('QUERIES'); $this->accept['QUERIES'] = array ('QUERY'); $this->accept['ADMINISTRATION'] = array ('FILES', 'IMAGES', 'MENU', 'SUBMENU'); $this->accept['IMAGES'] = array ('FILENAME'); $this->accept['SUBMENU'] = array('MENU'); $this->accept['MEDIA'] = array('FILENAME'); $this->accept['CSS'] = array('FILENAME'); } function start_element ($parser, $element_name, $element_attrs) { if ($this->terminalError) return; if ($this->mosinstall) { $container = $this->opentags[0]; if (!isset($this->accept[$container]) OR !is_array($this->accept[$container])) trigger_error ("XML error $container is not a valid containing element"); if (!in_array($element_name, $this->accept[$container])) trigger_error ("XML error $element_name not permitted within $container"); } if ($this->mosinstall OR $element_name == 'MOSINSTALL') { $this->opencount = array_unshift ($this->opentags, $element_name); $this->mosinstall = true; $method = 'element_'.$element_name; $specific = array (&$this, $method); if (is_callable($specific)) $this->$method($element_attrs); } else trigger_error ("XML expected MOSINSTALL but found $element_name"); // echo '
Start of '.$element_name; } function end_element ($parser, $element_name) { if ($this->terminalError) return; if ($this->opentags[0] != $element_name) { trigger_error("XML last open tag was $check, but found end of $element_name"); return; } $method = 'end_element_'.$element_name; $specific = array (&$this, $method); if (is_callable($specific)) $this->$method(); array_shift ($this->opentags); $this->opencount--; // echo '
End of '.$element_name; } function character_data ($parser, $data) { // Should be overridden by inheriting class $this->errors[] = 'XML handler error - no method provided to deal with character data'; $this->terminalError = true; } function element_mosinstall ($attrs) { if (isset($attrs['TYPE'])) $this->type = $attrs['TYPE']; else trigger_error ("XML error - mosinstall does not have type attribute"); } function getType () { return $this->type; } } /** * Extend basic parser to extract the description for a type of install file **/ class mosXMLDescription extends mosBasicXML { var $values = array(); function character_data ($parser, $data) { if ($this->terminalError) return; $this->topLevelCharacterData($data); } function topLevelCharacterData ($data) { if ($data = trim($data)) { if (isset($this->opentags[1]) AND $this->opentags[1] == 'MOSINSTALL') $this->values[$this->opentags[0]] = $data; } } function getDescription ($type) { if ($type == $this->type AND isset($this->values['DESCRIPTION'])) return $this->values['DESCRIPTION']; else return ''; } function getName ($type) { if ($type == $this->type AND isset($this->values['NAME'])) return $this->values['NAME']; else return ''; } function getGroup ($type) { if ($type == $this->type AND isset($this->values['GROUP'])) return $this->values['GROUP']; else return ''; } function getCreationDate ($type) { if ($type == $this->type AND isset($this->values['CREATIONDATE'])) return $this->values['CREATIONDATE']; else return ''; } function getAuthor ($type) { if ($type == $this->type AND isset($this->values['AUTHOR'])) return $this->values['AUTHOR']; else return ''; } function getCopyright ($type) { if ($type == $this->type AND isset($this->values['COPYRIGHT'])) return $this->values['COPYRIGHT']; else return ''; } function getAuthorEmail ($type) { if ($type == $this->type AND isset($this->values['AUTHOREMAIL'])) return $this->values['AUTHOREMAIL']; else return ''; } function getAuthorUrl ($type) { if ($type == $this->type AND isset($this->values['AUTHORURL'])) return $this->values['AUTHORURL']; else return ''; } function getVersion ($type) { if ($type == $this->type AND isset($this->values['VERSION'])) return $this->values['VERSION']; else return ''; } } class mosXMLParams extends mosXMLDescription { var $options = array(); var $optvalue = ''; var $optdata = ''; var $paramattrs = array(); var $paramcount = 0; var $html = array(); function element_params ($attrs) { $this->html[] = ''; if (isset($attrs['NAME'])) { $pname = $attrs['NAME']; $this->html[] = ""; } } function element_param ($attrs) { $this->paramattrs = $attrs; } function element_option ($attrs) { if (isset($attrs['VALUE'])) $optvalue = $attrs['VALUE']; } function character_data ($parser, $data) { if ($this->terminalError) return; $this->topLevelCharacterData($data); if ($this->opentags[0] == 'OPTION') $this->optdata = $data; } function end_element_option () { $this->options[] = mosHTML::makeOption($this->optvalue, $this->optdata); $this->optdata = ''; $this->optvalue = ''; } function end_element_param () { $type = mosGetParam ($this->paramattrs, 'TYPE', ''); $name = mosGetParam ($this->paramattrs, 'NAME', ''); $label = mosGetParam ($this->paramattrs, 'LABEL', $name); $default = mosGetParam ($this->paramattrs, 'DEFAULT', ''); if ($description = mosGetParam ($this->paramattrs, 'DESCRIPTION', '')) $tooltip = mosToolTip($description, $name); else $tooltip = ''; if (is_object($this->mosParameter)) $value = $this->mosParameter->get($name, $default); else $value = $default; $this->html[] = ''; if ($label == '@spacer') $label = '
'; elseif ($label) $label .= ':'; $this->html[] = ''; $controlname = $this->name; switch ($type) { case 'text': $size = mosGetParam ($this->paramattrs, 'SIZE', 0); $controlstring = ''; break; case 'list': $controlstring = mosHTML::selectList($this->options, "$controlname[$name]", 'class="inputbox"', 'value', 'text', $value); break; case 'radio': $controlstring = mosHTML::radioList($this->options, "$controlname[$name]", $value); break; case 'imagelist': $directory = new mosDirectory (mamboCore::get('mosConfig_absolute_path').mosGetParam($this->paramattrs, 'DIRECTORY', '')); $files = $directory->listFiles ('\.png$|\.gif$|\.jpg$|\.bmp$|\.ico$'); $options = array(); foreach ($files as $file) $options[] = mosHTML::makeOption($file, $file); if (!isset($this->paramattrs['HIDE_NONE'])) array_unshift($options, mosHTML::makeOption('-1', '- Do not use an image -' )); if (!isset($this->paramattrs['HIDE_DEFAULT'])) array_unshift($options, mosHTML::makeOption('', '- Use Default image -')); $controlstring = mosHTML::selectList ($options, "$controlname[$name]", 'class="inputbox"', 'value', 'text', $value); break; case 'textarea': $rows = mosGetParam ($this->paramattrs, 'ROWS', 0); $cols = mosGetParam ($this->paramattrs, 'COLS', 0); $value = str_replace ('
'; break; case 'mos_section': $controlstring = _form_mos_section($name, $value, $controlname); break; case 'mos_category': $controlstring = _form_mos_category($name, $value, $controlname); break; case 'mos_menu': default: $controlstring = _HANDLER.'='.$type; } // $this->html[] = ""; $this->html[] = ""; $this->html[] = ""; $this->html[] = ''; $this->options = array(); $this->paramattrs = array(); $this->paramcount++; } function end_element_params () { $this->html[] = '
$pname
'.$label.'$type$controlstring$tooltip
'; if ($this->paramcount == 0) $this->html[] = ''._NO_PARAMS.''; $this->paramcount = 0; } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_mos_section( $name, $value, $control_name ) { $database = mamboDatabase::getInstance(); $query = "SELECT id AS value, title AS text" . "\n FROM #__sections" . "\n WHERE published='1' AND scope='content'" . "\n ORDER BY title" ; $database->setQuery( $query ); $options = $database->loadObjectList(); array_unshift($options, mosHTML::makeOption( '0', '- Select Content Section -' )); return mosHTML::selectList( $options, "$control_name[$name]", 'class="inputbox"', 'value', 'text', $value ); } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ function _form_mos_category( $name, $value, $control_name ) { $database = mamboDatabase::getInstance(); $query = "SELECT c.id AS value, CONCAT_WS( '/',s.title, c.title ) AS text" . "\n FROM #__categories AS c" . "\n LEFT JOIN #__sections AS s ON s.id=c.section" . "\n WHERE c.published='1' AND s.scope='content'" . "\n ORDER BY c.title" ; $database->setQuery( $query ); $options = $database->loadObjectList(); array_unshift($options, mosHTML::makeOption('0', '- Select Content Category -')); return mosHTML::selectList( $options, "$control_name[$name]", 'class="inputbox"', 'value', 'text', $value ); } /** * @param string The name of the form element * @param string The value of the element * @param object The xml element for the parameter * @param string The control name * @return string The html for the element */ // function _form_mos_menu( $name, $value, &$node, $control_name ) { // global $database; // // $menuTypes = $mainframe->menutypes(); // // foreach($menuTypes as $menutype ) { // $options[] = mosHTML::makeOption( $menutype, $menutype ); // } // array_unshift( $options, mosHTML::makeOption( '', '- Select Menu -' ) ); // // return mosHTML::selectList( $options, ''. $control_name .'['. $name .']', 'class="inputbox"', 'value', 'text', $value ); // } } /** * Parameters handler * @package Mambo */ class mosAdminParameters extends mosParameters { /** @var string Path to the xml setup file */ var $_path = null; /** @var string The type of setup file */ var $_type = null; /** @var object The xml params element */ var $_xmlElem = null; /** * Constructor * @param string The raw parms text * @param string Path to the xml setup file * @var string The type of setup file */ function mosAdminParameters( $text, $path='', $type='component' ) { $this->_params = $this->parse( $text ); $this->_raw = $text; $this->_path = $path; $this->_type = $type; } /** * @param string The name of the control, or the default text area if a setup file is not found * @return string HTML */ function render( $name='params' ) { $parser = new mosXMLParams ($this->_path, $this, $name); if (count($parser->html)) return implode("\n", $parser->html); else { $raw = $this->_raw; return "