| 11 |
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); |
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); |
| 12 |
|
|
| 13 |
/** |
/** |
| 14 |
|
* Basic XML parsing of installation files |
| 15 |
|
***/ |
| 16 |
|
|
| 17 |
|
class mosBasicXML { |
| 18 |
|
var $opentags = array(); |
| 19 |
|
var $opencount; |
| 20 |
|
var $accept = array(); |
| 21 |
|
var $mosinstall = false; |
| 22 |
|
var $type; |
| 23 |
|
var $terminalError = false; |
| 24 |
|
var $errors = array(); |
| 25 |
|
|
| 26 |
|
function mosBasicXML ($file) { |
| 27 |
|
//echo $file.'<br />'; |
| 28 |
|
$this->setTree(); |
| 29 |
|
$parser = xml_parser_create(); |
| 30 |
|
$startfunc = array ($this, 'start_element'); |
| 31 |
|
$endfunc = array ($this, 'end_element'); |
| 32 |
|
$charfunc = array ($this, 'character_data'); |
| 33 |
|
xml_set_element_handler ($parser, $startfunc, $endfunc); |
| 34 |
|
xml_set_character_data_handler ($parser, $charfunc); |
| 35 |
|
$fp = fopen($file, 'rb'); |
| 36 |
|
while ($data = fread($fp, 4096) AND !$this->terminalError) { |
| 37 |
|
$data = str_replace('&', ' ampersand ', $data); |
| 38 |
|
$ret = xml_parse($parser, $data, feof($fp)) or die (sprintf('XML ERROR: %s at line %d', |
| 39 |
|
xml_error_string(xml_get_error_code($parser)), |
| 40 |
|
xml_get_current_line_number($parser))); |
| 41 |
|
} |
| 42 |
|
if (count($this->opentags) != 0) { |
| 43 |
|
$tags = implode (', ', $this->opentags); |
| 44 |
|
trigger_error ("XML error - unclosed tag(s) ($tags) at end of file"); |
| 45 |
|
} |
| 46 |
|
xml_parser_free($parser); |
| 47 |
|
if (count($this->errors)) var_dump ($this->errors); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
function setTree () { |
| 51 |
|
$this->accept['MOSINSTALL'] = array ('NAME', 'CREATIONDATE', 'AUTHOR', 'COPYRIGHT', |
| 52 |
|
'LICENSE', 'AUTHOREMAIL', 'AUTHORURL', 'VERSION', 'DESCRIPTION', 'FILES', 'GROUP', |
| 53 |
|
'PARAMS', 'INSTALL', 'UNINSTALL', 'INSTALLFILE', 'UNINSTALLFILE', 'ADMINISTRATION', |
| 54 |
|
'IMAGES', 'CSS'); |
| 55 |
|
$this->accept['PARAMS'] = array ('PARAM'); |
| 56 |
|
$this->accept['PARAM'] = array ('OPTION'); |
| 57 |
|
$this->accept['FILES'] = array ('FILENAME'); |
| 58 |
|
$this->accept['INSTALL'] = array ('QUERIES'); |
| 59 |
|
$this->accept['UNINSTALL'] = array ('QUERIES'); |
| 60 |
|
$this->accept['QUERIES'] = array ('QUERY'); |
| 61 |
|
$this->accept['ADMINISTRATION'] = array ('FILES', 'IMAGES', 'MENU'); |
| 62 |
|
$this->accept['IMAGES'] = array ('FILENAME'); |
| 63 |
|
$this->accept['MENU'] = array ('SUBMENU'); |
| 64 |
|
$this->accept['SUBMENU'] = array('MENU'); |
| 65 |
|
$this->accept['CSS'] = array('FILENAME'); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
function start_element ($parser, $element_name, $element_attrs) { |
| 69 |
|
if ($this->terminalError) return; |
| 70 |
|
$method = 'element_'.$element_name; |
| 71 |
|
$specific = array ($this, $method); |
| 72 |
|
if (is_callable($specific)) $this->$method($element_attrs); |
| 73 |
|
if ($this->mosinstall) { |
| 74 |
|
$container = $this->opentags[0]; |
| 75 |
|
if (!isset($this->accept[$container]) OR !is_array($this->accept[$container])) trigger_error ("XML error $container is not a valid containing element"); |
| 76 |
|
if (!in_array($element_name, $this->accept[$container])) trigger_error ("XML error $element_name not permitted within $container"); |
| 77 |
|
} |
| 78 |
|
if ($this->mosinstall OR $element_name == 'MOSINSTALL') { |
| 79 |
|
$this->opencount = array_unshift ($this->opentags, $element_name); |
| 80 |
|
$setdata = array ($this, 'set_data'); |
| 81 |
|
if (is_callable($setdata)) $this->set_data($element_attrs); |
| 82 |
|
$this->mosinstall = true; |
| 83 |
|
} |
| 84 |
|
else trigger_error ("XML expected MOSINSTALL but found $element_name"); |
| 85 |
|
// echo '<br />Start of '.$element_name; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
function end_element ($parser, $element_name) { |
| 89 |
|
if ($this->terminalError) return; |
| 90 |
|
$check = array_shift ($this->opentags); |
| 91 |
|
if ($check != $element_name) { |
| 92 |
|
$this->opencount = array_unshift ($this->opentags, $check); |
| 93 |
|
trigger_error("XML last open tag was $check, but found end of $element_name"); |
| 94 |
|
} |
| 95 |
|
else $this->opencount--; |
| 96 |
|
// echo '<br />End of '.$element_name; |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
function character_data ($parser, $data) { |
| 100 |
|
// Should be overridden by inheriting class |
| 101 |
|
$this->errors[] = 'XML handler error - no method provided to deal with character data'; |
| 102 |
|
$this->terminalError = true; |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
function element_mosinstall ($attrs) { |
| 106 |
|
if (isset($attrs['TYPE'])) $this->type = $attrs['TYPE']; |
| 107 |
|
else trigger_error ("XML error - mosinstall does not have type attribute"); |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
function getType () { |
| 111 |
|
return $this->type; |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
/** |
| 117 |
|
* Extend basic parser to extract the description for a type of install file |
| 118 |
|
**/ |
| 119 |
|
|
| 120 |
|
class mosXMLDescription extends mosBasicXML { |
| 121 |
|
var $values = array(); |
| 122 |
|
|
| 123 |
|
function character_data ($parser, $data) { |
| 124 |
|
if ($this->terminalError) return; |
| 125 |
|
$data = trim($data); |
| 126 |
|
if ($data) { |
| 127 |
|
if (isset($this->opentags[1]) AND $this->opentags[1] == 'MOSINSTALL') $this->values[$this->opentags[0]] = $data; |
| 128 |
|
} |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
function getDescription ($type) { |
| 132 |
|
if ($type == $this->type AND isset($this->values['DESCRIPTION'])) return $this->values['DESCRIPTION']; |
| 133 |
|
else return ''; |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
function getName ($type) { |
| 137 |
|
if ($type == $this->type AND isset($this->values['NAME'])) return $this->values['NAME']; |
| 138 |
|
else return ''; |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
function getGroup ($type) { |
| 142 |
|
if ($type == $this->type AND isset($this->values['GROUP'])) return $this->values['GROUP']; |
| 143 |
|
else return ''; |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
function getCreationDate ($type) { |
| 147 |
|
if ($type == $this->type AND isset($this->values['CREATIONDATE'])) return $this->values['CREATIONDATE']; |
| 148 |
|
else return ''; |
| 149 |
|
} |
| 150 |
|
|
| 151 |
|
function getAuthor ($type) { |
| 152 |
|
if ($type == $this->type AND isset($this->values['AUTHOR'])) return $this->values['AUTHOR']; |
| 153 |
|
else return ''; |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
function getCopyright ($type) { |
| 157 |
|
if ($type == $this->type AND isset($this->values['COPYRIGHT'])) return $this->values['COPYRIGHT']; |
| 158 |
|
else return ''; |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
function getAuthorEmail ($type) { |
| 162 |
|
if ($type == $this->type AND isset($this->values['AUTHOREMAIL'])) return $this->values['AUTHOREMAIL']; |
| 163 |
|
else return ''; |
| 164 |
|
} |
| 165 |
|
|
| 166 |
|
function getAuthorUrl ($type) { |
| 167 |
|
if ($type == $this->type AND isset($this->values['AUTHORURL'])) return $this->values['AUTHORURL']; |
| 168 |
|
else return ''; |
| 169 |
|
} |
| 170 |
|
|
| 171 |
|
function getVersion ($type) { |
| 172 |
|
if ($type == $this->type AND isset($this->values['VERSION'])) return $this->values['VERSION']; |
| 173 |
|
else return ''; |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
} |
| 177 |
|
|
| 178 |
|
/** |
| 179 |
* @param string THe template position |
* @param string THe template position |
| 180 |
*/ |
*/ |
| 181 |
function mosCountAdminModules( $position='left' ) { |
function mosCountAdminModules( $position='left' ) { |