diff options
author | neoraider <devnull@localhost> | 2006-09-19 00:53:00 +0200 |
---|---|---|
committer | neoraider <devnull@localhost> | 2006-09-19 00:53:00 +0200 |
commit | e5a1418503a1b0f7d20a0c5c51d44f10a881411a (patch) | |
tree | fc2e19d958382a93e778faecfd6db300d4e6cfea /code | |
parent | 2390cba867a49e96156e9cf57cbf591182f98bd7 (diff) | |
download | neon-e5a1418503a1b0f7d20a0c5c51d44f10a881411a.tar neon-e5a1418503a1b0f7d20a0c5c51d44f10a881411a.zip |
Interne Modulverwaltung neu geschrieben;
Basis modularisiert;
das gesamte System an die neue Modulverwaltung angepasst.
Diffstat (limited to 'code')
-rw-r--r-- | code/config.inc.php | 11 | ||||
-rw-r--r-- | code/db.inc.php | 10 | ||||
-rw-r--r-- | code/links.inc.php | 2 | ||||
-rw-r--r-- | code/message.inc.php | 3 | ||||
-rw-r--r-- | code/modules.inc.php | 148 | ||||
-rw-r--r-- | code/nav.inc.php | 2 | ||||
-rw-r--r-- | code/pages.inc.php | 12 | ||||
-rw-r--r-- | code/templates.inc.php | 14 | ||||
-rw-r--r-- | code/user.inc.php | 2 | ||||
-rw-r--r-- | code/xmlparser.inc.php | 95 |
10 files changed, 9 insertions, 290 deletions
diff --git a/code/config.inc.php b/code/config.inc.php deleted file mode 100644 index b94a74e..0000000 --- a/code/config.inc.php +++ /dev/null @@ -1,11 +0,0 @@ -<?PHP - require_once('config/config.inc.php'); - - require_once('code/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/code/db.inc.php b/code/db.inc.php deleted file mode 100644 index 706f63d..0000000 --- a/code/db.inc.php +++ /dev/null @@ -1,10 +0,0 @@ -<?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/code/links.inc.php b/code/links.inc.php index 4484a72..cb264cd 100644 --- a/code/links.inc.php +++ b/code/links.inc.php @@ -1,5 +1,5 @@ <?PHP - require_once('code/user.inc.php'); + Uses('user'); class Links { function GetNeonLink($page, $extra = '', $html = true) { diff --git a/code/message.inc.php b/code/message.inc.php index 092f4ec..8545a01 100644 --- a/code/message.inc.php +++ b/code/message.inc.php @@ -1,6 +1,5 @@ <?PHP - require_once('code/config.inc.php'); - require_once('code/util.inc.php'); + Uses('util'); $message['Error'] = 'Error'; $message['PageNotFound'] = 'The page \'$page\' does not exist.'; diff --git a/code/modules.inc.php b/code/modules.inc.php deleted file mode 100644 index 4a4a889..0000000 --- a/code/modules.inc.php +++ /dev/null @@ -1,148 +0,0 @@ -<?PHP - require_once('code/xmlparser.inc.php'); - require_once('code/db.inc.php'); - - function require_mod($file) { - if(isset($GLOBALS['modules']->code[$file])) - require_once($GLOBALS['modules']->code[$file]); - elseif(isset($GLOBALS['modules']->templates[$file])) - require_once($GLOBALS['modules']->templates[$file]); - else - require_once($file); - } - - class Modules { - var $modules = array(); - var $pages = array(); - var $code = array(); - var $templates = array(); - - function Modules() { - $dir = opendir('modules'); - - while($moddir = readdir($dir)) { - if($moddir[0] != '.' && is_dir('modules/' . $moddir) && is_file('modules/' . $moddir . '/module.xml')) { - $data = $GLOBALS['xmlparser']->ParseFile('modules/' . $moddir . '/module.xml'); - - if(!$data) continue; - - $info = $GLOBALS['xmlparser']->FindTag($data, 'info'); - if(!$info) continue; - - $name = $GLOBALS['xmlparser']->FindTag($info, 'name'); - if(!$name) continue; - if(count($name['children']) != 1) continue; - if(!is_string($name['children'][0])) continue; - $name = $name['children'][0]; - - $version = $GLOBALS['xmlparser']->FindTag($info, 'version'); - if(!$version) continue; - if(count($version['children']) != 1) continue; - if(!is_string($version['children'][0])) continue; - $version = $version['children'][0]; - - $desc = $GLOBALS['xmlparser']->FindTag($info, 'desc'); - if(!$desc) continue; - if(count($desc['children']) != 1) continue; - if(!is_string($desc['children'][0])) continue; - $desc = $desc['children'][0]; - - $this->modules[$name] = array('name' => $name, 'version' => $version, 'desc' => $desc, 'code' => array(), - 'templates' => array(), 'config' => false, 'enabled' => false); - - if($GLOBALS['xmlparser']->FindTag($info, 'config')) $this->modules[$name]['config'] = true; - - $files = $GLOBALS['xmlparser']->FindTag($data, 'files'); - if(!$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 'page': - $type = $file['attribs']['type']; - if(!$type) $type = 'c'; - - $pagename = $file['children'][0] . '.' . $type; - $realname = 'modules/' . $moddir . '/pages/' . strtr($type, array('c' => 'content', 'e' => 'editor', 'n' => 'nav')) - . '/' . $file['children'][0] . '.xml'; - - $this->modules[$name]['pages'][$pagename] = $realname; - break; - case 'code': - $filename = 'code/' . $file['children'][0] . '.inc.php'; - $realname = 'modules/' . $moddir . '/code/' . $file['children'][0] . '.inc.php'; - - $this->modules[$name]['code'][$filename] = $realname; - break; - case 'template': - $filename = 'templates/' . $file['children'][0] . '.inc.php'; - $realname = 'modules/' . $moddir . '/templates/' . $file['children'][0] . '.inc.php'; - - $this->modules[$name]['templates'][$filename] = $realname; - } - } - } - } - - closedir($dir); - - $res = $GLOBALS['db']->Execute('SELECT name, enabled FROM modules'); - - while($row = $res->FetchRow()) { - 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; - - $this->pages = array_merge($this->pages, $this->modules[$row[0]]['pages']); - $this->code = array_merge($this->code, $this->modules[$row[0]]['code']); - $this->templates = array_merge($this->templates, $this->modules[$row[0]]['templates']); - } - } - - 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/code/nav.inc.php b/code/nav.inc.php index bb7ce12..d5ede02 100644 --- a/code/nav.inc.php +++ b/code/nav.inc.php @@ -1,5 +1,5 @@ <?PHP - require_once('code/links.inc.php'); + Uses('links'); class Nav { var $entries = array(); diff --git a/code/pages.inc.php b/code/pages.inc.php index 6f0e383..290b4bd 100644 --- a/code/pages.inc.php +++ b/code/pages.inc.php @@ -1,9 +1,6 @@ <?PHP - require_once('code/db.inc.php'); - require_once('code/user.inc.php'); - require_once('code/templates.inc.php'); - require_once('code/xmlparser.inc.php'); - require_once('code/modules.inc.php'); + Uses('user', 'templates'); + class Pages { var $pages = array( @@ -117,9 +114,8 @@ 'access' => '', 'data' => $data); } else { - $filename = $GLOBALS['modules']->pages[$page . '.' . $type]; - if(!$filename) $filename = 'pages/' . strtr($type, array('c' => 'content', 'e' => 'editor', 'n' => 'nav')) - . '/' . $page . '.xml'; + $filename = $GLOBALS['modules']->pages[$page . '.' . $type]['path'] . 'pages/' + . strtr($type, array('c' => 'content', 'e' => 'editor', 'n' => 'nav')) . '/' . $page . '.xml'; $xmldata = $GLOBALS['xmlparser']->ParseFile($filename); if(!$xmldata) return null; diff --git a/code/templates.inc.php b/code/templates.inc.php index 7abfe79..9db1ff2 100644 --- a/code/templates.inc.php +++ b/code/templates.inc.php @@ -1,14 +1,4 @@ <?PHP - require_once('code/modules.inc.php'); - - $dir = opendir('templates'); - - while($file = readdir($dir)) - if($file[0] != '.' && substr($file, -8) == '.inc.php') - include('templates/' . $file); - - closedir($dir); - - foreach($GLOBALS['modules']->templates as $file) - include($file); + foreach($GLOBALS['modules']->templates as $file => $module) + require_once($module['path'] . 'templates/' . $file . '.inc.php'); ?> diff --git a/code/user.inc.php b/code/user.inc.php index 4912bcc..7c9b907 100644 --- a/code/user.inc.php +++ b/code/user.inc.php @@ -1,6 +1,4 @@ <?PHP - require_once('code/db.inc.php'); - class User { var $uid = 0, $gid = 0; var $login_key = '', $login_type = ''; diff --git a/code/xmlparser.inc.php b/code/xmlparser.inc.php deleted file mode 100644 index 0666c5a..0000000 --- a/code/xmlparser.inc.php +++ /dev/null @@ -1,95 +0,0 @@ -<?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; -?> |