diff options
Diffstat (limited to 'forum/utils')
-rw-r--r-- | forum/utils/forums.php | 49 | ||||
-rw-r--r-- | forum/utils/view.php | 18 |
2 files changed, 29 insertions, 38 deletions
diff --git a/forum/utils/forums.php b/forum/utils/forums.php index 9305623..85e977b 100644 --- a/forum/utils/forums.php +++ b/forum/utils/forums.php @@ -6,8 +6,6 @@ include_once($UTIL_DIR . "/threads.php"); class Forum { public $fid; - public $readlist; - public $writelist; public $name; private $newStuff; @@ -25,11 +23,9 @@ class Forum { echo "</div>"; } - public function Forum($fid, $readlist, $writelist, $name) + public function Forum($fid, $name) { $this->fid = $fid; - $this->readlist = $readlist; - $this->writelist = $writelist; $this->name = $name; } } @@ -40,13 +36,16 @@ class Forums { public $forums = array(); public function add($forum) { + global $FORUMS_DIR; + if(!file_exists($FORUMS_DIR . "/". $forum->fid)) { + mkdir($FORUMS_DIR . "/". $forum->fid); + } $key = $forum->fid; $this->forums[$key] = $forum; } public function write() { - /* $fp = fopen($this->file, "w"); $block = TRUE; @@ -54,39 +53,15 @@ class Forums { fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); - fwrite($fp, "<members>\n"); - foreach($this->members as $member) { - fwrite($fp, " <member id=\"" . - htmlspecialchars($member->id, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " name=\"" . - htmlspecialchars($member->name, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " description=\"" . - htmlspecialchars($member->description, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " image=\"" . - htmlspecialchars($member->image, ENT_QUOTES, "UTF-8") . "\">\n"); - - - fwrite($fp, " </member>\n"); + fwrite($fp, "<forums>\n"); + foreach($this->forums as $forum) { + fwrite($fp, " <forum fid=\"" . $forum->fid . "\"\n"); + fwrite($fp, " name=\"" . htmlspecialchars($forum->name, ENT_QUOTES, "UTF-8") . "\"/>\n"); } - fwrite($fp, "</members>\n"); + fwrite($fp, "</forums>\n"); fclose($fp); - */ - } - - /* - public function deleteForumUser($id) - { - if($this->members[$id]) { - unset($this->members[$id]); - // $this->write(); - } else { - echo "<p>ERROR: User! <em>".$id."</em> does not exist!</p>\n"; - return false; - } - return true; } - */ public function getForum($fid) { @@ -112,8 +87,6 @@ class Forums { foreach($forums as $f) { $forum = new Forum($f->getAttribute('fid'), - $f->getAttribute('readlist'), - $f->getAttribute('writelist'), $f->getAttribute('name')); $this->add($forum); @@ -126,7 +99,7 @@ class Forums { public function Forums($file) { $this->file = $file; - $this->read(); + if(file_exists($file)) $this->read(); } } diff --git a/forum/utils/view.php b/forum/utils/view.php index 0adb1a0..01e8b6a 100644 --- a/forum/utils/view.php +++ b/forum/utils/view.php @@ -23,6 +23,24 @@ echo "</div>\n"; echo "<h1>Forums</h1>"; include_once("forums.php"); $forums = new Forums($FORUMS_DIR . "/forums.xml"); + + if($action == "addforum") { + $newfid = 0; + while($forums->getForum($newfid)) $newfid++; + + $forums->add(new Forum($newfid, $title)); + $forums->write(); + } + $forums->show(); + + if($current_user->uid == 0) { +?> +<form method="post" action="?mode=forum&action=addforum"> +Add new forum: <input name="title" value=""><button type="submit">Add</button> +</form> +<?php + } + } ?>
\ No newline at end of file |