summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2006-09-19 00:53:00 +0200
committerneoraider <devnull@localhost>2006-09-19 00:53:00 +0200
commite5a1418503a1b0f7d20a0c5c51d44f10a881411a (patch)
treefc2e19d958382a93e778faecfd6db300d4e6cfea /core
parent2390cba867a49e96156e9cf57cbf591182f98bd7 (diff)
downloadneon-e5a1418503a1b0f7d20a0c5c51d44f10a881411a.tar
neon-e5a1418503a1b0f7d20a0c5c51d44f10a881411a.zip
Interne Modulverwaltung neu geschrieben;
Basis modularisiert; das gesamte System an die neue Modulverwaltung angepasst.
Diffstat (limited to 'core')
-rw-r--r--core/config.inc.php11
-rw-r--r--core/db.inc.php10
-rw-r--r--core/modules.inc.php164
-rw-r--r--core/xmlparser.inc.php95
4 files changed, 280 insertions, 0 deletions
diff --git a/core/config.inc.php b/core/config.inc.php
new file mode 100644
index 0000000..5318341
--- /dev/null
+++ b/core/config.inc.php
@@ -0,0 +1,11 @@
+<?PHP
+ require_once('config/config.inc.php');
+
+ require_once('core/db.inc.php');
+
+
+ $res = $GLOBALS['db']->Execute('SELECT name, value FROM config WHERE module = 0');
+
+ while($row = $res->FetchRow())
+ $GLOBALS['config'][$row[0]] = $row[1];
+?>
diff --git a/core/db.inc.php b/core/db.inc.php
new file mode 100644
index 0000000..706f63d
--- /dev/null
+++ b/core/db.inc.php
@@ -0,0 +1,10 @@
+<?PHP
+ require_once('config/config.inc.php');
+
+ require_once('adodb/adodb.inc.php');
+
+
+ $GLOBALS['db'] = &ADONewConnection($GLOBALS['config']['driver']);
+ $GLOBALS['db']->PConnect($GLOBALS['config']['server'], $GLOBALS['config']['user'],
+ $GLOBALS['config']['password'], $GLOBALS['config']['db']);
+?>
diff --git a/core/modules.inc.php b/core/modules.inc.php
new file mode 100644
index 0000000..c1ebc80
--- /dev/null
+++ b/core/modules.inc.php
@@ -0,0 +1,164 @@
+<?PHP
+ require_once('core/xmlparser.inc.php');
+ require_once('core/db.inc.php');
+
+ function Uses() {
+ foreach(func_get_args() as $file) {
+ if(isset($GLOBALS['modules']->code[$file]))
+ require_once($GLOBALS['modules']->code[$file]['path'] . 'code/' . $file . '.inc.php');
+ else
+ die('Fatal: a required code file was not found.');
+ }
+ }
+
+ class Modules {
+ var $modules = array();
+ var $pages = array();
+ var $code = array();
+ var $templates = array();
+
+ function Modules() {
+ $module = $this->Load('base.xml');
+ if(!$module) die('Fatal: could not load Neon base.');
+
+ $module['path'] = '';
+
+ $this->modules['base'] = $module;
+
+
+ $dir = opendir('modules');
+
+ while($moddir = readdir($dir)) {
+ if($moddir[0] == '.' || !is_dir('modules/' . $moddir) || !is_file('modules/' . $moddir . '/module.xml'))
+ continue;
+
+ $module = $this->Load('modules/' . $moddir . '/module.xml');
+
+ if(!$module) continue;
+
+ $module['path'] = 'modules/' . $moddir . '/';
+ $this->modules[$module['name']] = $module;
+ }
+
+ closedir($dir);
+
+ $res = $GLOBALS['db']->Execute('SELECT name, enabled FROM modules');
+
+ $row[0] = 'base';
+ $row[1] = 1;
+
+ do {
+ if(!array_key_exists($row[0], $this->modules)) {
+ $GLOBALS['db']->Execute('DELETE FROM modules WHERE name = ?', $row[0]);
+ continue;
+ }
+
+ if(!$row[1]) continue;
+
+ $this->modules[$row[0]]['enabled'] = true;
+
+ foreach($this->modules[$row[0]]['pages'] as $page)
+ $this->pages[$page] = &$this->modules[$row[0]];
+ foreach($this->modules[$row[0]]['code'] as $code)
+ $this->code[$code] = &$this->modules[$row[0]];
+ foreach($this->modules[$row[0]]['templates'] as $template)
+ $this->templates[$template] = &$this->modules[$row[0]];
+ } while($row = $res->FetchRow());
+ }
+
+ function Load($file) {
+ if(!is_file($file)) return null;
+
+ $data = $GLOBALS['xmlparser']->ParseFile($file);
+ if(!$data) return null;
+
+ $info = $GLOBALS['xmlparser']->FindTag($data, 'info');
+ if(!$info) return null;
+
+ $name = $GLOBALS['xmlparser']->FindTag($info, 'name');
+ if(!$name) return null;
+ if(count($name['children']) != 1) return null;
+ if(!is_string($name['children'][0])) return null;
+ $name = $name['children'][0];
+
+ $version = $GLOBALS['xmlparser']->FindTag($info, 'version');
+ if(!$version) return null;
+ if(count($version['children']) != 1) return null;
+ if(!is_string($version['children'][0])) return null;
+ $version = $version['children'][0];
+
+ $desc = $GLOBALS['xmlparser']->FindTag($info, 'desc');
+ if($desc && (count($desc['children']) == 1) && is_string($desc['children'][0])) $desc = $desc['children'][0];
+ else $desc = '';
+
+
+ $module = array('name' => $name, 'version' => $version, 'desc' => $desc, 'code' => array(),
+ 'pages' => array(), 'templates' => array(), 'config' => false, 'enabled' => false);
+
+ if($GLOBALS['xmlparser']->FindTag($info, 'config')) $module['config'] = true;
+
+ $files = $GLOBALS['xmlparser']->FindTag($data, 'files');
+ if(!$files) return $module;
+
+ 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 'page':
+ $type = $file['attribs']['type'];
+ if(!$type) $type = 'c';
+
+ array_push($module['pages'], $file['children'][0] . '.' . $type);
+ break;
+ case 'code':
+ array_push($module['code'], $file['children'][0]);
+ break;
+ case 'template':
+ array_push($module['templates'], $file['children'][0]);
+ }
+ }
+
+ return $module;
+ }
+
+ function Exists($name) {
+ return array_key_exists($name, $this->modules);
+ }
+
+ function Enabled($name) {
+ return $this->Exists($name) && $this->modules[$name]['enabled'];
+ }
+
+ function HasConfig($name) {
+ if(!$this->Exists($name)) return false;
+
+ return $this->modules[$name]['config'];
+ }
+
+ function Enable($name, $enable = true) {
+ if(!$this->Exists($name)) return false;
+
+ if($this->Enabled($name) == $enable) return true;
+
+ $res = $GLOBALS['db']->Execute('SELECT id FROM modules WHERE name = ?', $name);
+
+ if($res->RecordCount()) {
+ $GLOBALS['db']->Execute('UPDATE modules SET enabled = ? WHERE name = ?', array(intval($enable), $name));
+
+ return ($GLOBALS['db']->Affected_Rows() > 0);
+ }
+
+ $GLOBALS['db']->Execute('INSERT INTO modules (name, enabled) VALUES (?, ?)', array($name, intval($enable)));
+
+ return ($GLOBALS['db']->Affected_Rows() > 0);
+ }
+
+ function Disable($name) {
+ return $this->Enable($name, false);
+ }
+ }
+
+ $GLOBALS['modules'] = new Modules;
+?>
diff --git a/core/xmlparser.inc.php b/core/xmlparser.inc.php
new file mode 100644
index 0000000..0666c5a
--- /dev/null
+++ b/core/xmlparser.inc.php
@@ -0,0 +1,95 @@
+<?PHP
+ class XMLParser {
+ var $tags;
+ var $depth;
+
+ function ParseFile($filename) {
+ $this->tags = array();
+ $this->depth = 0;
+
+ $parser = xml_parser_create();
+
+ xml_set_object($parser, $this);
+ xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
+
+ xml_set_element_handler($parser, 'openTagHandler', 'closeTagHandler');
+ xml_set_character_data_handler($parser, 'cdataHandler');
+
+ $file = fopen($filename, 'r');
+
+ while ($xml = fread($file, 4096)) {
+ if(!xml_parse($parser, $xml, feof($file))) {
+ $this->tags = null;
+ break;
+ }
+ }
+
+ fclose($file);
+
+ xml_parser_free($parser);
+
+ return $this->tags[0];
+ }
+
+ function ParseXML($xml) {
+ $this->tags = array();
+ $this->depth = 0;
+
+ $parser = xml_parser_create();
+
+ xml_set_object($parser, $this);
+ xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
+
+ xml_set_element_handler($parser, 'openTagHandler', 'closeTagHandler');
+ xml_set_character_data_handler($parser, 'cdataHandler');
+
+ if(!xml_parse($parser, $xml, true))
+ $this->tags = null;
+
+ xml_parser_free($parser);
+
+ 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) {
+ $children = &$this->tags[$this->depth-1]['children'];
+
+ $children[count($children)-1] = trim($children[count($children)-1]);
+
+ $this->tags[$this->depth] = array('tag' => $name,
+ 'attribs' => $attribs,
+ 'children' => array());
+
+ $this->depth++;
+ }
+
+ function closeTagHandler($parser, $name) {
+ $children = &$this->tags[$this->depth-1]['children'];
+
+ $children[count($children)-1] = trim($children[count($children)-1]);
+
+ $this->depth--;
+
+ if($this->depth > 0)
+ array_push($this->tags[$this->depth-1]['children'], $this->tags[$this->depth]);
+ }
+
+ function cdataHandler($parser, $data) {
+ $children = &$this->tags[$this->depth-1]['children'];
+
+ if(is_string($children[count($children)-1]))
+ $children[count($children)-1] .= $data;
+ elseif(trim($data) != '')
+ array_push($children, $data);
+ }
+ }
+
+ $GLOBALS['xmlparser'] = new XMLParser;
+?>