summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2006-04-11 20:05:04 +0200
committerneoraider <devnull@localhost>2006-04-11 20:05:04 +0200
commit2fe04a4707412ff2f4f8df5f5524bb1b2dcbb3d7 (patch)
tree6947238ea3e304acec01f24dff358d67e86cc1e2
parente267e31bd045ff4a6bfa1489b0ad0eb5fcc7b31d (diff)
downloadneon-2fe04a4707412ff2f4f8df5f5524bb1b2dcbb3d7.tar
neon-2fe04a4707412ff2f4f8df5f5524bb1b2dcbb3d7.zip
XML-Parser und Modulverwaltung implementiert.
-rw-r--r--code/handlers.inc.php5
-rw-r--r--code/modules.inc.php71
-rw-r--r--code/xmlparser.inc.php76
3 files changed, 152 insertions, 0 deletions
diff --git a/code/handlers.inc.php b/code/handlers.inc.php
index 5410de0..a167ba8 100644
--- a/code/handlers.inc.php
+++ b/code/handlers.inc.php
@@ -1,4 +1,6 @@
<?PHP
+ require_once('code/modules.inc.php');
+
$dir = opendir('handlers');
while($file = readdir($dir))
@@ -6,4 +8,7 @@
include('handlers/' . $file);
closedir($dir);
+
+ foreach($GLOBALS['modules']->handlers as $file)
+ include($file);
?>
diff --git a/code/modules.inc.php b/code/modules.inc.php
index a1bf361..1e84d45 100644
--- a/code/modules.inc.php
+++ b/code/modules.inc.php
@@ -1,5 +1,76 @@
<?PHP
+ require_once('code/xmlparser.inc.php');
+
+ function require_mod($file) {
+ if(isset($GLOBALS['modules']->code[$file]))
+ require_once($GLOBALS['modules']->code[$file]);
+ elseif(isset($GLOBALS['modules']->handlers[$file]))
+ require_once($GLOBALS['modules']->handlers[$file]);
+ else
+ require_once($file);
+ }
+
class Modules {
+ var $modules;
+ var $code;
+ var $handlers;
+ function Modules() {
+ $this->modules = array();
+ $this->code = array();
+ $this->handlers = array();
+
+ $dir = opendir('modules');
+
+ while($moddir = readdir($dir)) {
+ if($moddir[0] != '.' && is_dir('modules/' . $moddir)) {
+ $data = $GLOBALS['xmlparser']->ParseFile('modules/' . $moddir . '/module.xml');
+
+ if(!$data) continue;
+
+ $info = $GLOBALS['xmlparser']->FindTag($data, 'info');
+ if(!is_array($info)) continue;
+
+ $name = $GLOBALS['xmlparser']->FindTag($info, 'name');
+ if(!is_array($name)) continue;
+ if(count($name['children']) != 1) continue;
+ if(!is_string($name['children'][0])) continue;
+
+ $name = $name['children'][0];
+
+ $this->module[$name] = array('name' => $name, 'code' => array(),
+ 'handlers' => array());
+
+ $files = $GLOBALS['xmlparser']->FindTag($data, 'files');
+ if(!is_array($files)) continue;
+
+ foreach($files['children'] as $file) {
+ if(!is_array($file)) continue;
+ if(count($file['children']) != 1) continue;
+ if(!is_string($file['children'][0])) continue;
+
+ switch($file['tag']) {
+ case 'code':
+ $filename = 'code/' . $file['children'][0] . '.inc.php';
+ $realname = 'modules/' . $moddir . '/code/' . $file['children'][0] . '.inc.php';
+
+ $this->code[$filename] = $realname;
+ $this->modules[$name]['code'][$filename] = $realname;
+ break;
+ case 'handler':
+ $filename = 'handlers/' . $file['children'][0] . '.inc.php';
+ $realname = 'modules/' . $moddir . '/handlers/' . $file['children'][0] . '.inc.php';
+
+ $this->handlers[$filename] = $realname;
+ $this->modules[$name]['handlers'][$filename] = $realname;
+ }
+ }
+ }
+ }
+
+ closedir($dir);
+ }
}
+
+ $GLOBALS['modules'] = new Modules;
?>
diff --git a/code/xmlparser.inc.php b/code/xmlparser.inc.php
new file mode 100644
index 0000000..2d53a1f
--- /dev/null
+++ b/code/xmlparser.inc.php
@@ -0,0 +1,76 @@
+<?PHP
+ class XMLParser {
+ var $parser;
+ var $tags;
+ var $depth;
+
+ function XMLParser() {
+ $this->parser = xml_parser_create();
+
+ xml_set_object($this->parser, $this);
+ xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
+
+ xml_set_element_handler($this->parser, 'openTagHandler', 'closeTagHandler');
+ xml_set_character_data_handler($this->parser, 'cdataHandler');
+ }
+
+ function ParseFile($filename) {
+ $this->tags = array();
+ $this->depth = 0;
+
+ $file = fopen($filename, 'r');
+
+ while ($xml = fread($file, 4096)) {
+ if(!xml_parse($this->parser, $xml, feof($file))) {
+ $this->tags = null;
+ break;
+ }
+ }
+
+ fclose($file);
+
+ return $this->tags[0];
+ }
+
+ function ParseXML($xml) {
+ $this->tags = array();
+ $this->depth = 0;
+
+ if(!xml_parse($this->parser, $xml, true))
+ $this->tags = null;
+
+ return $this->tags[0];
+ }
+
+ function FindTag($data, $tag, $start = 0) {
+ for($i = $start; $i < count($data['children']); $i++) {
+ if(!is_array($data['children'][$i])) continue;
+ if($data['children'][$i]['tag'] == $tag) return $data['children'][$i];
+ }
+ }
+
+ function openTagHandler($parser, $name, $attribs) {
+ $this->tags[$this->depth] = array('tag' => $name,
+ 'attribs' => $attribs,
+ 'children' => array());
+
+ $this->depth++;
+ }
+
+ function closeTagHandler($parser, $name) {
+ $this->depth--;
+
+ if($this->depth > 0)
+ array_push($this->tags[$this->depth-1]['children'], $this->tags[$this->depth]);
+ }
+
+ function cdataHandler($parser, $data) {
+ $data = trim($data);
+
+ if($data != '')
+ array_push($this->tags[$this->depth-1]['children'], $data);
+ }
+ }
+
+ $GLOBALS['xmlparser'] = new XMLParser;
+?>