summaryrefslogtreecommitdiffstats
path: root/code/pages.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'code/pages.inc.php')
-rw-r--r--code/pages.inc.php128
1 files changed, 101 insertions, 27 deletions
diff --git a/code/pages.inc.php b/code/pages.inc.php
index 09cd525..d57bb17 100644
--- a/code/pages.inc.php
+++ b/code/pages.inc.php
@@ -4,58 +4,132 @@
require_once('code/handlers.inc.php');
class Pages {
- function Get($name, $type, $extra = null) {
- if(!$this->Exists($name, $type))
- return array('title' => $name,
- 'content' => ErrorMessage('PageNotFound', array('page' => $name)));
+ function Get($page, $type = null, $extra = null) {
+ if(!$this->Exists($page, $type))
+ return array('title' => $page,
+ 'content' => ErrorMessage('PageNotFound', array('page' => $page)));
- $res = $GLOBALS['db']->Execute('SELECT id, handler, data FROM pages WHERE name = ? AND type = ?', array($name, $type));
+ if($type) $res = $GLOBALS['db']->Execute('SELECT id, name, type, handler, data FROM pages WHERE name = ? AND type = ?', array($page, $type));
+ else $res = $GLOBALS['db']->Execute('SELECT id, name, type, handler, data FROM pages WHERE id = ?', $page);
- if(!$this->HasAccess($name, $type))
- return array('title' => $name,
- 'content' => ErrorMessage('Forbidden', array('page' => $name)));
+ if(!$this->HasAccess($page, $type))
+ return array('title' => $res->fields[1],
+ 'content' => ErrorMessage('Forbidden', array('page' => $res->fields[1])));
- parse_str($res->fields[2], $data);
+ parse_str($res->fields[4], $data);
$data = array_map('Unquote', $data);
if($extra) $data = array_merge($data, $extra);
$data['_id'] = $res->fields[0];
- $data['_page'] = $name;
+ $data['_page'] = $res->fields[1];
+ $data['_type'] = $res->fields[2];
- return $GLOBALS['handlers'][$res->fields[1]]->Get($data);
+ return $GLOBALS['handlers'][$res->fields[3]]->Get($data);
}
- function Edit($name, $type) {
- if(!$this->Exists($name, $type))
- return array('title' => $name,
- 'content' => ErrorMessage('PageNotFound', array('page' => $name)));
+ function GetEditor($page, $type = null) {
+ if(!$this->Exists($page, $type))
+ return array('title' => $page,
+ 'content' => ErrorMessage('PageNotFound', array('page' => $page)));
- $res = $GLOBALS['db']->Execute('SELECT id, handler, data FROM pages WHERE name = ? AND type = ?', array($name, $type));
+ if($type) $res = $GLOBALS['db']->Execute('SELECT id, name, type, handler, data FROM pages WHERE name = ? AND type = ?', array($page, $type));
+ else $res = $GLOBALS['db']->Execute('SELECT id, name, type, handler, data FROM pages WHERE id = ?', $page);
if(!$GLOBALS['user']->IsAdmin())
- return array('title' => $name,
- 'content' => ErrorMessage('Forbidden', array('page' => $name)));
+ return array('title' => $res->fields[1],
+ 'content' => ErrorMessage('Forbidden', array('page' => $res->fields[1])));
- parse_str($res->fields[2], $data = null);
+ parse_str($res->fields[4], $data = null);
$data = array_map('Unquote', $data);
$data['_id'] = $res->fields[0];
- $data['_page'] = $name;
- $data['_type'] = $type;
+ $data['_page'] = $res->fields[1];
+ $data['_type'] = $res->fields[2];
- return $this->Get($res->fields[1], 'e', array('_data' => $data));
+ return $this->Get($res->fields[3], 'e', array('_data' => $data));
}
- function Exists($name, $type) {
- $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE name = ? AND type = ?', array($name, $type));
+ function GetName($id) {
+ $res = $GLOBALS['db']->Execute('SELECT name FROM pages WHERE id = ?', $id);
+
+ return $res->fields[0];
+ }
+
+ function GetType($id) {
+ $res = $GLOBALS['db']->Execute('SELECT type FROM pages WHERE id = ?', $id);
+
+ 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);
return ($res->RecordCount() > 0);
}
- function HasAccess($name, $type) {
- $gid = $GLOBALS['user']->GetGid();
- $res = $GLOBALS['db']->Execute('SELECT access FROM pages WHERE name = ? AND type = ?', array($name, $type));
+ function HasAccess($page, $type = null) {
+ $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);
return ($GLOBALS['user']->IsAdmin() || (ord($res->fields[0][$gid/8]) & (1 << ($gid%8))) != 0);
}
+
+ function Add($name, $handler, $type) {
+ if($this->Exists($name, $type)) return 0;
+
+ $GLOBALS['db']->Execute('INSERT INTO pages (name, handler, access, data, type) VALUES (?, ?, 0, "", ?)',
+ array($name, $handler, $type));
+
+ return $GLOBALS['db']->Insert_ID();
+ }
+
+ function Edit($page, $data, $type = null) {
+ $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));
+ }
+
+ function Rename($page, $new_name, $type = null) {
+ if($type) {
+ if($this->Exists($new_name, $type)) return;
+
+ $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));
+ }
+ }
+
+ function Copy($page, $new_name, $type = null) {
+ if($type) {
+ if($this->Exists($new_name, $type)) return;
+
+ $res = $GLOBALS['db']->Execute('SELECT * FROM pages WHERE name = ? AND type = ?', array($page, $type));
+ }
+ else {
+ if($this->Exists($new_name, $this->GetType($type))) return;
+
+ $res = $GLOBALS['db']->Execute('SELECT handler, data, type FROM pages WHERE id = ?', $page);
+ }
+
+ $GLOBALS['db']->Execute('INSERT INTO pages (name, handler, access, data, type) VALUES (?, ?, 0, ?, ?)',
+ array($new_name, $res->fields[0], $res->fields[1], $res->fields[2]));
+
+ return $GLOBALS['db']->Insert_ID();
+ }
+
+ 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);
+ }
}
$GLOBALS['pages'] = new Pages;