summaryrefslogtreecommitdiffstats
path: root/code
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2006-04-13 02:45:02 +0200
committerneoraider <devnull@localhost>2006-04-13 02:45:02 +0200
commit415243607829013d91b23b40608507fcd76b307b (patch)
tree8199fbaacf2d17fbc4c2efe68a2fb46c386086b3 /code
parent0ef2bb0245fedaf18508feabfa980955ba4a238e (diff)
downloadneon-415243607829013d91b23b40608507fcd76b307b.tar
neon-415243607829013d91b23b40608507fcd76b307b.zip
Seiten-Verwaltung vollkommen ?berarbeitet.
Diffstat (limited to 'code')
-rw-r--r--code/modules.inc.php18
-rw-r--r--code/pages.inc.php254
-rw-r--r--code/util.inc.php2
-rw-r--r--code/xmlparser.inc.php51
4 files changed, 225 insertions, 100 deletions
diff --git a/code/modules.inc.php b/code/modules.inc.php
index 4c17807..02aa9f2 100644
--- a/code/modules.inc.php
+++ b/code/modules.inc.php
@@ -12,6 +12,7 @@
class Modules {
var $modules;
+ var $pages;
var $code;
var $templates;
@@ -29,10 +30,10 @@
if(!$data) continue;
$info = $GLOBALS['xmlparser']->FindTag($data, 'info');
- if(!is_array($info)) continue;
+ if(!$info) continue;
$name = $GLOBALS['xmlparser']->FindTag($info, 'name');
- if(!is_array($name)) continue;
+ if(!$name) continue;
if(count($name['children']) != 1) continue;
if(!is_string($name['children'][0])) continue;
@@ -42,7 +43,7 @@
'templates' => array());
$files = $GLOBALS['xmlparser']->FindTag($data, 'files');
- if(!is_array($files)) continue;
+ if(!$files) continue;
foreach($files['children'] as $file) {
if(!is_array($file)) continue;
@@ -50,6 +51,17 @@
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($file['children'][0], array(':' => '/'))
+ . '.' . $type . '.xml';
+
+ $this->pages[$pagename] = $realname;
+ $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';
diff --git a/code/pages.inc.php b/code/pages.inc.php
index 7bdd907..c121d2f 100644
--- a/code/pages.inc.php
+++ b/code/pages.inc.php
@@ -2,142 +2,236 @@
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');
class Pages {
- function Get($page, $type = null, $extra = null) {
+ var $pages = array();
+
+ function Pages($dirs = array('pages')) {
+ $dir = opendir(join('/', $dirs));
+
+ while($file = readdir($dir)) {
+ if($file[0] == '.') continue;
+
+ if(is_dir(join('/', $dirs) . '/' . $file))
+ $this->Pages(array_merge($dirs, array($file)));
+ elseif(is_file(join('/', $dirs) . '/' . $file)) {
+ switch(substr($file, -6)) {
+ case '.c.xml':
+ case '.e.xml':
+ case '.n.xml':
+ if(count($dirs) > 1)
+ $this->pages[join(array_merge(array_slice($dirs, 1), array(substr($file, 0, -4))), ':')] = array();
+ else
+ $this->pages[substr($file, 0, -4)] = array();
+ }
+ }
+ }
+
+ closedir($dir);
+ }
+
+ function Get($page, $type, $extra = null) {
if(!$this->Exists($page, $type))
return array('title' => $page,
'content' => ErrorMessage('PageNotFound', array('page' => $page)));
- if($type) $res = $GLOBALS['db']->Execute('SELECT id, name, type, template, data FROM pages WHERE name = ? AND type = ?', array($page, $type));
- else $res = $GLOBALS['db']->Execute('SELECT id, name, type, template, data FROM pages WHERE id = ?', $page);
-
if(!$this->HasAccess($page, $type))
- return array('title' => $res->fields[1],
- 'content' => ErrorMessage('Forbidden', array('page' => $res->fields[1])));
+ return array('title' => $page,
+ 'content' => ErrorMessage('Forbidden', array('page' => $page)));
- $data = null;
- parse_str($res->fields[4], $data);
- $data = array_map('Unquote', $data);
+ $pagedata = $this->GetPageData($page, $type);
+
+ $data = $pagedata['data'];
if($extra) $data = array_merge($data, $extra);
- $data['_id'] = $res->fields[0];
- $data['_page'] = $res->fields[1];
- $data['_type'] = $res->fields[2];
+ $data['_page'] = $page;
+ $data['_type'] = $type;
- return $GLOBALS['templates'][$res->fields[3]]->Get($data);
+ return $GLOBALS['templates'][$pagedata['template']]->Get($data);
}
- function GetEditor($page, $type = null) {
+ function GetEditor($page, $type) {
if(!$this->Exists($page, $type))
return array('title' => $page,
'content' => ErrorMessage('PageNotFound', array('page' => $page)));
- if($type) $res = $GLOBALS['db']->Execute('SELECT id, name, type, template, data FROM pages WHERE name = ? AND type = ?', array($page, $type));
- else $res = $GLOBALS['db']->Execute('SELECT id, name, type, template, data FROM pages WHERE id = ?', $page);
-
if(!$GLOBALS['user']->IsAdmin())
- return array('title' => $res->fields[1],
- 'content' => ErrorMessage('Forbidden', array('page' => $res->fields[1])));
+ return array('title' => $page,
+ 'content' => ErrorMessage('Forbidden', array('page' => $page)));
- parse_str($res->fields[4], $data = null);
- $data = array_map('Unquote', $data);
- $data['_id'] = $res->fields[0];
- $data['_page'] = $res->fields[1];
- $data['_type'] = $res->fields[2];
+ $pagedata = $this->GetPageData($page, $type);
- return $this->Get($res->fields[3], 'e', array('_data' => $data));
- }
-
- function GetName($id) {
- $res = $GLOBALS['db']->Execute('SELECT name FROM pages WHERE id = ?', $id);
+ $data = $pagedata['data'];
+ $data['_page'] = $page;
+ $data['_type'] = $type;
- return $res->fields[0];
+ return $this->Get($pagedata['template'], 'e', array('_data' => $data));
}
- function GetType($id) {
- $res = $GLOBALS['db']->Execute('SELECT type FROM pages WHERE id = ?', $id);
+ function Exists($page, $type) {
+ if(array_key_exists($page . '.' . $type, $this->pages))
+ return true;
- return $res->fields[0];
- }
-
- function Exists($page, $type = null) {
- if($type) $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE name = ? AND type = ?', array($page, $type));
- else $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE id = ?', $page);
+ if(array_key_exists($page . '.' . $type, $GLOBALS['modules']->pages))
+ return true;
+
+ $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE name = ? AND type = ?', array($page, $type));
return ($res->RecordCount() > 0);
}
- function HasAccess($page, $type = null) {
+ function HasAccess($page, $type) {
+ if($GLOBALS['user']->IsAdmin()) return $this->Exists($page, $type);
+
$gid = $GLOBALS['user']->gid;
- if($type) $res = $GLOBALS['db']->Execute('SELECT access FROM pages WHERE name = ? AND type = ?', array($page, $type));
- else $res = $GLOBALS['db']->Execute('SELECT access FROM pages WHERE id = ?', $page);
- if(!$res->RecordCount()) return false;
- return ($GLOBALS['user']->IsAdmin() || (ord($res->fields[0][$gid/8]) & (1 << ($gid%8))) != 0);
+ $pagedata = $this->GetPageData($page, $type);
+
+ if(!$pagedata)
+ return false;
+
+ return ((hexdec(substr($pagedata['access'], ($gid/8)*2, 2)) & (1 << ($gid%8))) != 0);
}
- function Add($name, $template, $type) {
- if($this->Exists($name, $type)) return 0;
+ function GetPageData($page, $type) {
+ if(!$this->Exists($page, $type)) return null;
+
+ if(!count($this->pages[$page . '.' . $type])) {
+ $res = $GLOBALS['db']->Execute('SELECT template, HEX(access), data FROM pages WHERE name = ? AND type = ?', array($page, $type));
+
+ if($res->RecordCount()) {
+ parse_str($res->fields[2], $data);
+ $data = array_map('Unquote', $data);
+
+ $this->pages[$page . '.' . $type] = array('name' => $page, 'type' => $type, 'template' => $res->fields[0],
+ 'access' => $res->fields[1], 'data' => $data);
+ }
+ else {
+ $filename = $GLOBALS['modules']->pages[$page . '.' . $type];
+ if(!$filename) $filename = 'pages/' . strtr($page, array(':' => '/')) . '.' . $type . '.xml';
+
+ $xmldata = $GLOBALS['xmlparser']->ParseFile($filename);
+ if(!$xmldata) return null;
+
+ $info = $GLOBALS['xmlparser']->FindTag($xmldata, 'info');
+ if(!$info) return null;
+
+ $template = $GLOBALS['xmlparser']->FindTag($info, 'template');
+ if(!$template) return null;
+ if(count($template['children']) != 1) return;
+ if(!is_string($template['children'][0])) return;
+ $template = $template['children'][0];
+
+ $access = $GLOBALS['xmlparser']->FindTag($info, 'access');
+ if(!$access) return null;
+ if(count($access['children']) != 1) return;
+ if(!is_string($access['children'][0])) return;
+ $access = $access['children'][0];
+
+ $rawdata = $GLOBALS['xmlparser']->FindTag($xmldata, 'data');
+
+ $data = array();
+
+ foreach($rawdata['children'] as $field) {
+ if(!is_array($field)) continue;
+ if(count($field['children']) != 1) continue;
+
+ $data[$field['tag']] = $field['children'][0];
+ }
+
+ $this->pages[$page . '.' . $type] = array('name' => $page, 'type' => $type, 'template' => $template,
+ 'access' => $access, 'data' => $data);
+ }
+ }
- $GLOBALS['db']->Execute('INSERT INTO pages (name, template, access, data, type) VALUES (?, ?, 0, "", ?)',
- array($name, $templates, $type));
+ return $this->pages[$page . '.' . $type];
+ }
+
+ function Add($name, $type, $template) {
+ if($this->Exists($name, $type)) return false;
+
+ $GLOBALS['db']->Execute('INSERT INTO pages (name, template, access, data, type) VALUES (?, ?, "", "", ?)',
+ array($name, $template, $type));
- return $GLOBALS['db']->Insert_ID();
+ return ($GLOBALS['db']->Affected_Rows() > 0);
}
- function Edit($page, $data, $type = null) {
+ function Edit($page, $type, $data) {
$string = '';
foreach($data as $key => $val)
$string .= urlencode($key) . '=' . urlencode($val) . '&';
- if($type) $GLOBALS['db']->Execute('UPDATE pages SET data = ? WHERE name = ? AND type = ?',
- array(substr($string, 0, -1), $page, $type));
- else $GLOBALS['db']->Execute('UPDATE pages SET data = ? WHERE id = ?',
- array(substr($string, 0, -1), $page));
+ $GLOBALS['db']->Execute('UPDATE pages SET data = ? WHERE name = ? AND type = ?',
+ array(substr($string, 0, -1), $page, $type));
+
+ if($GLOBALS['db']->Affected_Rows()) return true;
+
+ $pagedata = $this->GetPageData($page, $type);
+
+ $string = '';
+
+ foreach($pagedata['data'] as $key => $val)
+ $string .= urlencode($key) . '=' . urlencode($val) . '&';
+
+ $access = '';
+
+ for($i = 0; $i < strlen($pagedata['access']); $i+=2)
+ $access .= chr(hexdec(substr($pagedata['access'], $i, 2)));
+
+
+ $GLOBALS['db']->Execute('INSERT INTO pages (name, template, access, data, type) VALUES (?, ?, ?, ?, ?)',
+ array($page, $pagedata['template'], $access, $string, $type));
return ($GLOBALS['db']->Affected_Rows() > 0);
}
- function Rename($page, $new_name, $type = null) {
- if($type) {
- if($this->Exists($new_name, $type)) return;
+ function Rename($page, $type, $new_name) {
+ if($this->Exists($new_name, $type)) return false;
- $GLOBALS['db']->Execute('UPDATE pages SET name = ? WHERE name = ? AND type = ?', array($new_name, $page, $type));
- }
- else {
- if($this->Exists($new_name, $this->GetType($type))) return;
-
- $GLOBALS['db']->Execute('UPDATE pages SET name = ? WHERE id = ?', array($new_name, $page));
- }
+ $GLOBALS['db']->Execute('UPDATE pages SET name = ? WHERE name = ? AND type = ?', array($new_name, $page, $type));
return ($GLOBALS['db']->Affected_Rows() > 0);
}
- function Copy($page, $new_name, $type = null) {
- if($type) {
- if($this->Exists($new_name, $type)) return 0;
-
- $res = $GLOBALS['db']->Execute('SELECT * FROM pages WHERE name = ? AND type = ?', array($page, $type));
- }
- else {
- if($this->Exists($new_name, $this->GetType($type))) return 0;
-
- $res = $GLOBALS['db']->Execute('SELECT template, data, type FROM pages WHERE id = ?', $page);
- }
+ function Copy($page, $type, $new_name) {
+ if($this->Exists($new_name, $type)) return false;
+ if(!$this->Exists($page, $type)) return false;
- $GLOBALS['db']->Execute('INSERT INTO pages (name, template, access, data, type) VALUES (?, ?, 0, ?, ?)',
- array($new_name, $res->fields[0], $res->fields[1], $res->fields[2]));
+ $pagedata = $this->GetPageData($page, $type);
- return $GLOBALS['db']->Insert_ID();
+ $string = '';
+
+ foreach($pagedata['data'] as $key => $val)
+ $string .= urlencode($key) . '=' . urlencode($val) . '&';
+
+ $GLOBALS['db']->Execute('INSERT INTO pages (name, template, access, data, type) VALUES (?, ?, "", ?, ?)',
+ array($new_name, $pagedata['template'], $string, $type));
+
+ return ($GLOBALS['db']->Affected_Rows() > 0);
}
- function Delete($page, $type = null) {
- if($type) $GLOBALS['db']->Execute('DELETE FROM pages WHERE name = ? AND type = ?', array($page, $type));
- else $GLOBALS['db']->Execute('DELETE FROM pages WHERE id = ?', $page);
+ function Delete($page, $type) {
+ $GLOBALS['db']->Execute('DELETE FROM pages WHERE name = ? AND type = ?', array($page, $type));
return ($GLOBALS['db']->Affected_Rows() > 0);
}
+
+ function GetList() {
+ $res = $GLOBALS['db']->Execute('SELECT name, type FROM pages');
+
+ $pages = array();
+
+ while($row = $res->FetchRow())
+ $pages[$row[0] . '.' . $row[1]] = null;
+
+ $pages = array_keys(array_merge($pages, $this->pages, $GLOBALS['modules']->pages));
+
+ sort($pages);
+
+ return $pages;
+ }
}
$GLOBALS['pages'] = new Pages;
diff --git a/code/util.inc.php b/code/util.inc.php
index 4b498e7..3ee2489 100644
--- a/code/util.inc.php
+++ b/code/util.inc.php
@@ -1,6 +1,6 @@
<?PHP
function Subst($string, $subst = array()) {
- $tr['$$'] = '$';
+ $tr = array('$$' => '$');
foreach($subst as $key => $value)
$tr['$' . $key] = $value;
diff --git a/code/xmlparser.inc.php b/code/xmlparser.inc.php
index 2d53a1f..0666c5a 100644
--- a/code/xmlparser.inc.php
+++ b/code/xmlparser.inc.php
@@ -1,27 +1,24 @@
<?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;
+ $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($this->parser, $xml, feof($file))) {
+ if(!xml_parse($parser, $xml, feof($file))) {
$this->tags = null;
break;
}
@@ -29,6 +26,8 @@
fclose($file);
+ xml_parser_free($parser);
+
return $this->tags[0];
}
@@ -36,9 +35,19 @@
$this->tags = array();
$this->depth = 0;
- if(!xml_parse($this->parser, $xml, true))
+ $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];
}
@@ -50,6 +59,10 @@
}
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());
@@ -58,6 +71,10 @@
}
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)
@@ -65,10 +82,12 @@
}
function cdataHandler($parser, $data) {
- $data = trim($data);
+ $children = &$this->tags[$this->depth-1]['children'];
- if($data != '')
- array_push($this->tags[$this->depth-1]['children'], $data);
+ if(is_string($children[count($children)-1]))
+ $children[count($children)-1] .= $data;
+ elseif(trim($data) != '')
+ array_push($children, $data);
}
}