xmlfile = $file; $this->mosParameter = $mosParameter; $this->name = $name; $this->errors = new mosErrorSet(); $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); if ($fp = fopen($this->xmlfile, 'rb')) { while ($data = fread($fp, 4096) AND $this->errors->getMaxLevel() < _MOS_ERROR_FATAL) { $data = str_replace('&', ' ampersand ', $data); $ret = xml_parse($parser, $data, feof($fp)) or $this->errors->addErrorDetails(sprintf(T_('XML ERROR in %s: %s at line %d'), $this->xmlfile, xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)), _MOS_ERROR_FATAL); } } else $this->errors->addErrorDetails(sprintf(T_('Unable to open XML file %s'),$this->xmlfile), _MOS_ERROR_FATAL); if (count($this->opentags) != 0) { $tags = implode (', ', $this->opentags); $this->errors->addErrorDetails(sprintf(T_('XML error in %s - unclosed tag(s) (%s) at end of file'),$this->xmlfile, $tags), _MOS_ERROR_SEVERE); } xml_parser_free($parser); } 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', 'GROUP'); $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->errors->getMaxLevel() >= _MOS_ERROR_FATAL) return; if ($this->mosinstall) { $container = $this->opentags[0]; if (!isset($this->accept[$container]) OR !is_array($this->accept[$container])) $this->errors->addErrorDetails(sprintf(T_('XML error in %s: %s is not a valid containing element'), $this->xmlfile, $container), _MOS_ERROR_WARN); elseif (!in_array($element_name, $this->accept[$container])) $this->errors->addErrorDetails(sprintf(T_('XML error in %s: %s not permitted within %s'), $this->xmlfile, $element_name, $container), _MOS_ERROR_WARN); } 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 $this->errors->addErrorDetails(sprintf(T_('XML error in %s: expected MOSINSTALL but found %s'), $this->xmlfile, $element_name), _MOS_ERROR_SEVERE); } function end_element ($parser, $element_name) { if ($this->errors->getMaxLevel() >= _MOS_ERROR_FATAL) return; if ($this->opentags[0] != $element_name) { $this->errors->addErrorDetails(sprintf(T_('XML error in %s: last open tag was %s, but found end of %s'), $this->xmlfile, $check, $element_name), _MOS_ERROR_SEVERE); return; } if (isset($this->opentags[1]) AND $this->opentags[1] == 'MOSINSTALL') $this->values[$this->opentags[0]] = $this->chardata; $method = 'end_element_'.$element_name; $specific = array (&$this, $method); if (is_callable($specific)) $this->$method(); array_shift ($this->opentags); $this->opencount--; $this->chardata = ''; } function character_data ($parser, $data) { if ($this->errors->getMaxLevel() >= _MOS_ERROR_FATAL) return; $this->chardata .= trim($data); } function element_mosinstall ($attrs) { if (isset($attrs['TYPE'])) $this->type = $attrs['TYPE']; else $this->errors->addErrorDetails(sprintf(T_('XML error in %s: mosinstall does not have type attribute'), $this->xmlfile), _MOS_ERROR_FATAL); } function getType () { return $this->type; } function &getErrors () { $errors =& $this->errors->getErrors(); return $errors; } } /** * Extend basic parser to extract the description for a type of install file **/ class mosXMLDescription extends mosBasicXML { var $values = array(); 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 $paramattrs = array(); var $paramcount = 0; var $html = array(); function element_params ($attrs) { $this->html[] = '
| $pname | |||
| '.$label.' | '; $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 ('$type | "; $this->html[] = "$controlstring | "; $this->html[] = "$tooltip | "; $this->html[] = '
";
if ($withLineNums) {
$txt .= "";
$txt .= str_replace( ' ', ' ', sprintf( "%4d:", $ln ) );
$txt .= "";
}
$txt .= "$line
";
$ln++;
}
return $txt;
}
function mosIsChmodable($file)
{
$perms = fileperms($file);
if ($perms !== FALSE)
if (@chmod($file, $perms ^ 0001)) {
@chmod($file, $perms);
return TRUE;
} // if
return FALSE;
} // mosIsChmodable
/**
* @param string An existing base path
* @param string A path to create from the base path
* @param int Directory permissions
* @return boolean True if successful
*/
function mosMakePath($base, $path='', $mode = NULL)
{
global $mosConfig_dirperms;
// convert windows paths
$path = str_replace( '\\', '/', $path );
$path = str_replace( '//', '/', $path );
// check if dir exists
if (file_exists( $base . $path )) return true;
// set mode
$origmask = NULL;
if (isset($mode)) {
$origmask = @umask(0);
} else {
if ($mosConfig_dirperms=='') {
// rely on umask
$mode = 0777;
} else {
$origmask = @umask(0);
$mode = octdec($mosConfig_dirperms);
} // if
} // if
$parts = explode( '/', $path );
$n = count( $parts );
$ret = true;
if ($n < 1) {
$ret = @mkdir($base, $mode);
} else {
$path = $base;
for ($i = 0; $i < $n; $i++) {
$path .= $parts[$i] . '/';
if (!file_exists( $path )) {
if (!@mkdir( $path, $mode )) {
$ret = false;
break;
}
}
}
}
if (isset($origmask)) @umask($origmask);
return $ret;
}
function &checkAdminSession (&$database) {
// restore some session variables
$my = new mosUser( $database );
$my->id = mosGetParam( $_SESSION, 'session_user_id', '' );
$my->username = mosGetParam( $_SESSION, 'session_username', '' );
$my->usertype = mosGetParam( $_SESSION, 'session_usertype', '' );
$my->gid = mosGetParam( $_SESSION, 'session_gid', '' );
$session_id = mosGetParam( $_SESSION, 'session_id', '' );
$logintime = mosGetParam( $_SESSION, 'session_logintime', '' );
// check against db record of session
if ($session_id == md5( $my->id.$my->username.$my->usertype.$logintime )) {
$database->setQuery( "SELECT * FROM #__session"
. "\nWHERE session_id='$session_id'"
. " AND username = '" . $database->getEscaped( $my->username ) . "'"
. " AND userid = " . intval( $my->id )
);
if (!$result = $database->query()) {
echo $database->stderr();
}
if ($database->getNumRows( $result ) <> 1) $my = null;
}
else $my = null;
if ($my) {
// update session timestamp
$current_time = time();
$database->setQuery("UPDATE #__session SET time='$current_time' WHERE session_id='$session_id'");
$database->query();
// timeout old sessions
$past = time()-1800;
$database->setQuery( "DELETE FROM #__session WHERE time < '$past'" );
$database->query();
}
return $my;
}
?>