From cce5e7710295021b41d9aaecc503a60fb99256be Mon Sep 17 00:00:00 2001 From: deva Date: Sat, 4 Oct 2008 10:38:03 +0000 Subject: Initial revision --- forum/utils/calendar.php | 112 +++++++++++++++++++ forum/utils/clientinfo.php | 24 +++++ forum/utils/convert.php | 18 ++++ forum/utils/edit.php | 89 ++++++++++++++++ forum/utils/editor.php | 154 +++++++++++++++++++++++++++ forum/utils/editor_form.php | 127 ++++++++++++++++++++++ forum/utils/error.php | 6 ++ forum/utils/events.php | 141 ++++++++++++++++++++++++ forum/utils/filehandler.php | 33 ++++++ forum/utils/files.php | 134 +++++++++++++++++++++++ forum/utils/forums.php | 133 +++++++++++++++++++++++ forum/utils/log.php | 10 ++ forum/utils/login.php | 105 ++++++++++++++++++ forum/utils/mimetypes.php | 50 +++++++++ forum/utils/notify.php | 70 ++++++++++++ forum/utils/parser.php | 126 ++++++++++++++++++++++ forum/utils/ping.php | 126 ++++++++++++++++++++++ forum/utils/posts.php | 254 ++++++++++++++++++++++++++++++++++++++++++++ forum/utils/profile.php | 39 +++++++ forum/utils/roadmap.php | 70 ++++++++++++ forum/utils/smileys.php | 38 +++++++ forum/utils/threads.php | 162 ++++++++++++++++++++++++++++ forum/utils/users.php | 136 ++++++++++++++++++++++++ forum/utils/view.php | 28 +++++ 24 files changed, 2185 insertions(+) create mode 100644 forum/utils/calendar.php create mode 100644 forum/utils/clientinfo.php create mode 100644 forum/utils/convert.php create mode 100644 forum/utils/edit.php create mode 100644 forum/utils/editor.php create mode 100644 forum/utils/editor_form.php create mode 100644 forum/utils/error.php create mode 100644 forum/utils/events.php create mode 100644 forum/utils/filehandler.php create mode 100644 forum/utils/files.php create mode 100644 forum/utils/forums.php create mode 100644 forum/utils/log.php create mode 100644 forum/utils/login.php create mode 100644 forum/utils/mimetypes.php create mode 100644 forum/utils/notify.php create mode 100644 forum/utils/parser.php create mode 100644 forum/utils/ping.php create mode 100644 forum/utils/posts.php create mode 100644 forum/utils/profile.php create mode 100644 forum/utils/roadmap.php create mode 100644 forum/utils/smileys.php create mode 100644 forum/utils/threads.php create mode 100644 forum/utils/users.php create mode 100644 forum/utils/view.php (limited to 'forum') diff --git a/forum/utils/calendar.php b/forum/utils/calendar.php new file mode 100644 index 0000000..1592195 --- /dev/null +++ b/forum/utils/calendar.php @@ -0,0 +1,112 @@ +uid); + $events->add($event); + $events->write(); + notify("calendar", "New calendar entry:\n" . $title . "\n" . date("r", $time) . "\n" . + $description . "\n" . + "http://www.executionroom.com/forum/?mode=calendar&date=" . $time); +} + +if($action=="edit") { + /* + $event = $events->getEvent($eid); + $event->duration += 2000; + $events->write(); + */ +} + +?> +

+[<] +   +[<<] +   + +   +[>>] +   +[>]
+[Today]
+

+\n"; + echo "
\n"; + $t = $date + $day * 24 * 60 * 60; + echo " " . date("l j/n", $t) . "\n"; +?> + [+] +\n"; + + $t = strtotime(date("F j Y", $date + $day * 24 * 60 * 60)); + echo "
4) echo " style=\"background: #311;\""; + echo ">\n"; + + $events->show($t, $t + 24 * 60 * 60); + + echo "
\n"; + echo "
\n"; + + } +} else { +?> + + +\n"; + $t = $date + $day * 24 * 60 * 60; + echo " " . date("l j/n", $t) . "\n"; + echo " \n"; +} +?> + + + 4) echo " style=\"background: #311;\""; + echo ">\n"; +?> + Add +show($t, $t + 24 * 60 * 60); + echo " \n"; +} +?> + +
+ + +
+Title:
+Desription:
+Date: ">
+From-Time:
+To-Time:
+
+ +
+ diff --git a/forum/utils/clientinfo.php b/forum/utils/clientinfo.php new file mode 100644 index 0000000..cbb7a4d --- /dev/null +++ b/forum/utils/clientinfo.php @@ -0,0 +1,24 @@ +"; +$client_is_mobile_device = + stripos($_SERVER['HTTP_USER_AGENT'], "MIDP") != FALSE + || stripos($_SERVER['HTTP_USER_AGENT'], "Nokia") != FALSE + || stripos($_SERVER['HTTP_USER_AGENT'], "Sony") != FALSE + || stripos($_SERVER['HTTP_USER_AGENT'], "Ericson") != FALSE + || $_GET['forcemobile']; + +//$client_is_mobile_device = !$client_is_mobile_device; +/* +echo "client_is_mobile_device = "; +if($client_is_mobile_device) echo "yes"; + else echo "no"; +*/ +?> \ No newline at end of file diff --git a/forum/utils/convert.php b/forum/utils/convert.php new file mode 100644 index 0000000..2ba0afe --- /dev/null +++ b/forum/utils/convert.php @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/forum/utils/edit.php b/forum/utils/edit.php new file mode 100644 index 0000000..0af361c --- /dev/null +++ b/forum/utils/edit.php @@ -0,0 +1,89 @@ +uid, time(), $message); + $posts->add($post); + $posts->thread->name = $title; + $posts->thread->tid = $tid; + $posts->thread->lastpost = time(); + $posts->write(); + notify("forum", "New thread: http://www.executionroom.com/forum/?fid=". $fid . "&tid=" . $tid); + } else { + error("No forum id supplied!"); + } + break; + +case "reply": + if($fid && $tid && $pid) { + include_once("posts.php"); + $posts = new Posts($FORUMS_DIR . "/" . $fid . "/" . $tid . ".xml"); + $reply = $posts->getPost($pid); + if($reply) { + $post = new Post($posts->nextkey(), $title, $current_uid, time(), $message); + $reply->add($post); + $posts->thread->lastpost = time(); + $posts->write(); + notify("forum", "New reply: http://www.executionroom.com/forum/?fid=". $fid . "&tid=" . $tid); + } else { + error("Message " . $pid . " not found!"); + } + } else { + error("No message supplied!"); + } + break; + + case "edit": + if($fid && $tid && $pid) { + include_once("posts.php"); + $posts = new Posts($FORUMS_DIR . "/" . $fid . "/" . $tid . ".xml"); + $edit = $posts->getPost($pid); + if($edit) { + if($posts->thread->tid == $edit->pid) $posts->thread->name = $title; + $edit->title = $title; + $edit->message = $message . "\nEdited at: " . date("r", time()); + $posts->thread->lastpost = time(); + $posts->write(); + notify("forum", "Message has been edited: http://www.executionroom.com/forum/?fid=". $fid . "&tid=" . $tid); + } else { + error("Message " . $pid . " not found!"); + } + } else { + error("No message supplied!"); + } + break; + + case "quote": + if($fid && $tid && $pid) { + include_once("posts.php"); + $posts = new Posts($FORUMS_DIR . "/" . $fid . "/" . $tid . ".xml"); + $quote = $posts->getPost($pid); + if($quote) { + $post = new Post($posts->nextkey(), $title, $current_uid, time(), $message); + $quote->add($post); + $posts->thread->lastpost = time(); + $posts->write(); + notify("forum", "New reply (quote): http://www.executionroom.com/forum/?fid=". $fid . "&tid=" . $tid); + } else { + error("Message " . $pid . " not found!"); + } + } else { + error("No message supplied!"); + } + break; + +} +echo "

Return to thread.

\n"; + +?> \ No newline at end of file diff --git a/forum/utils/editor.php b/forum/utils/editor.php new file mode 100644 index 0000000..681b98d --- /dev/null +++ b/forum/utils/editor.php @@ -0,0 +1,154 @@ + +getPost($pid); + if($post || $pid == -1) { + + switch($task) { + case "new": + $title = "Title"; + $message = "Message"; + break; + + case "reply": + $title = "Re: " . $post->title; + $message = ""; + break; + + case "edit": + $title = $post->title; + $message = $post->message; + break; + + case "quote": + $title = "Re: " . $post->title; + $user = $users->getUser($post->user); + $message = "[quote title=" . $user->name . " wrote on " .date("r", $post->date) ."]" . $post->message . "[/quote]"; + break; + + default: + error("No mode supplied!"); + break; + } +?> +
+;-) +;-) +;-) +;-) +B +I +U +[L  ] +[ C ] +[  R] +URL +E-Mail +Image +"Q" +c++ + + + + + + */ ?> +

+ Title: + +

+

+\"\""; +} +?> +

+

+ +

+

+ To make a link, simply type the URL, and the system will + automagically transform it into an anchor (remember the + http:// part).
+ Example: http://www.executionroom.com
+

+

+ To insert an image, simply type the URL to that image, it will + automagically be transformed into an image, with a link to the + original image (again, remember the http:// part).
+ Example: http://www.executionroom.com/gfx/logos/die_logo_bloody.png +

+

+ +

+
+show(); + } else { + error("Message " . $pid . " not found!"); + } +} else { + error("No message supplied!"); +} + +?> diff --git a/forum/utils/editor_form.php b/forum/utils/editor_form.php new file mode 100644 index 0000000..6903ec9 --- /dev/null +++ b/forum/utils/editor_form.php @@ -0,0 +1,127 @@ + +
+ + + + + + + + + + + + +
Post Form
Logged in user:bent
Forum:Andet band relateret
Title:
Poll:[CREATE POLL]
Post Icon: + + + + +
No Icon
+
Smiley Shortcuts: +
[list all smilies] +
Embarassed Razz Mad Laughing Cool Confused Shocked Surprised Sad Smile Very Happy Crying or Very Sad Evil or Very Mad Twisted Evil Rolling Eyes Wink Exclamation Question Idea Arrow Neutral Grin Dead Frown Nod Proud Smug Thumbs Up Thumbs Down Uh Oh Bored 
Formatting Tools: + + +
+ + + + + + + + + + + + + + + + + +
+
   + + + + + +
Body:

Forum Options
+HTML code is OFF
+ +FUDcode is ON
+Images are ON
+Smilies are ON
Editing Time Limit: Unlimited

File Attachments: + + +Allowed File Extensions: (unrestricted)
Maximum File Size: 10240Kb
Maximum Files per Message: 1 + +

+ + +

Options: + + + + + +
Post Notification
 Notify me when someone replies to this message.
Include Signature
 Include my profile signature.
Disable smilies in this message
+
+ + 
+ + + + + + + + + +
diff --git a/forum/utils/error.php b/forum/utils/error.php new file mode 100644 index 0000000..78128d2 --- /dev/null +++ b/forum/utils/error.php @@ -0,0 +1,6 @@ +Error: " . $msg . "\n"; + // exit($msg); +} +?> \ No newline at end of file diff --git a/forum/utils/events.php b/forum/utils/events.php new file mode 100644 index 0000000..737c03c --- /dev/null +++ b/forum/utils/events.php @@ -0,0 +1,141 @@ +getUser($this->user); + + echo "
\n"; + echo "
". $this->title . "\n"; + // echo " Edit\n"; + echo "
\n"; + echo "
" . date("G:i", $this->starttime) . " - " . + date("G:i", $this->starttime + $this->duration) . "
\n"; + if(!$client_is_mobile_device) { + echo "
". $this->description . "
\n"; + } else { + echo "
". $this->description . "
\n"; + } + echo "
By: ".$user->name . "
\n"; + // echo " Edit"; + echo "
\n"; + } + + public function Event($eid, $title, $starttime, $duration, $description, $user) + { + $this->eid = $eid; + $this->title = $title; + $this->starttime = $starttime; + $this->duration = $duration; + $this->description = $description; + $this->user = $user; + } +} + +class Events { + + private $file; + public $events = array(); + + public function add($event) { + $key = $event->eid; + $this->events[$key] = $event; + } + + public function write() + { + $fp = fopen($this->file, "w"); + + $block = TRUE; + flock($fp, LOCK_EX, $block); // do an exclusive lock + + fwrite($fp, "\n"); + + fwrite($fp, "\n"); + foreach($this->events as $event) { + fwrite($fp, " eid, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " title=\"" . + htmlspecialchars($event->title, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " starttime=\"" . + htmlspecialchars($event->starttime, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " duration=\"" . + htmlspecialchars($event->duration, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " description=\"" . + htmlspecialchars($event->description, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " user=\"" . + htmlspecialchars($event->user, ENT_QUOTES, "UTF-8") . "\">\n"); + fwrite($fp, " \n"); + } + fwrite($fp, "\n"); + + fclose($fp); + } + + /* + public function deleteForumUser($id) + { + if($this->members[$id]) { + unset($this->members[$id]); + // $this->write(); + } else { + echo "

ERROR: User! ".$id." does not exist!

\n"; + return false; + } + return true; + } + */ + + public function show($starttime, $endtime) + { + foreach($this->events as $event) { + if($event->starttime > $starttime && $event->starttime < $endtime) + $event->show(); + } + } + + public function getEvent($eid) + { + $event = $this->events[$eid]; + return $event; + } + + private function read() + { + $dom = new DomDocument; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->file); + $events = $dom->getElementsByTagName('event'); + + foreach ($events as $e) { + $event = new Event($e->getAttribute('eid'), + $e->getAttribute('title'), + $e->getAttribute('starttime'), + $e->getAttribute('duration'), + $e->getAttribute('description'), + $e->getAttribute('user')); + + $this->add($event); + } + + } + + public function Events($file) + { + $this->file = $file; + $this->read(); + } + +} +?> diff --git a/forum/utils/filehandler.php b/forum/utils/filehandler.php new file mode 100644 index 0000000..231ddd6 --- /dev/null +++ b/forum/utils/filehandler.php @@ -0,0 +1,33 @@ +newFile($_FILES['userfile']['tmp_name'], $name); + } +} + +if($task == "delete" && $fid) { + $files->deleteFile($fid); +} + +$files->show(); + + +?> +
+

+ File: +

+

+ Use alternative filename (leave empty to use original filename): + +

+

+ +

+
diff --git a/forum/utils/files.php b/forum/utils/files.php new file mode 100644 index 0000000..d714ba2 --- /dev/null +++ b/forum/utils/files.php @@ -0,0 +1,134 @@ +fid; + } + + public function show() + { + global $PERMSTORE; + echo "
\n"; + echo " fid . "\">Delete\n"; + echo "
Filename: link() . "\">" . $this->name . "(" . $this->mimetype. ")
\n"; + echo "
Size: " . ceil(filesize($PERMSTORE . "/" . $this->fid) / 1024) . "kb
\n"; + echo "
\n"; + } + + public function File($fid, $name, $mimetype) + { + $this->fid = $fid; + $this->name = $name; + $this->mimetype = $mimetype; + } +} + +class Files { + + private $file; + public $files = array(); + + public function add($file) { + $key = $file->fid; + $this->files[$key] = $file; + } + + public function write() + { + $fp = fopen($this->file, "w"); + + $block = TRUE; + flock($fp, LOCK_EX, $block); // do an exclusive lock + + fwrite($fp, "\n"); + + fwrite($fp, "\n"); + foreach($this->files as $file) { + fwrite($fp, " fid, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " name=\"" . + htmlspecialchars($file->name, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " mimetype=\"" . + htmlspecialchars($file->mimetype, ENT_QUOTES, "UTF-8") . "\">\n"); + fwrite($fp, " \n"); + } + fwrite($fp, "\n"); + + fclose($fp); + } + + public function show() + { + foreach($this->files as $file) { + $file->show(); + } + } + + public function getFile($fid) + { + $file = $this->files[$fid]; + return $file; + } + + public function newFile($tempfile, $name) + { + global $PERMSTORE; + $fid = time(); + + // move tempfile to permstore and put it in db. + move_uploaded_file($tempfile, $PERMSTORE . "/" . $fid); + + $f = new File($fid, $name, getMimeType($name)->name); + $this->add($f); + + // We cannot wait to write the db, otherwise we'll get inconsistency! + $this->write(); + + // Return new file id. + return $fid; + } + + public function deleteFile($fid) + { + global $PERMSTORE; + unlink($PERMSTORE . "/" . $fid); + unset($this->files[$fid]); + + // We cannot wait to write the db, otherwise we'll get inconsitency! + $this->write(); + } + + private function read() + { + $dom = new DomDocument; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->file); + $files = $dom->getElementsByTagName('file'); + + foreach ($files as $f) { + $file = new File($f->getAttribute('fid'), + $f->getAttribute('name'), + $f->getAttribute('mimetype')); + + $this->add($file); + } + + } + + public function Files($file) + { + $this->file = $file; + $this->read(); + } + +} +?> \ No newline at end of file diff --git a/forum/utils/forums.php b/forum/utils/forums.php new file mode 100644 index 0000000..9305623 --- /dev/null +++ b/forum/utils/forums.php @@ -0,0 +1,133 @@ +newStuff = $newStuff; + } + + public function show() + { + echo "
"; + if($this->newStuff) echo "
"; + else echo "
"; + echo "fid . "\">" . $this->name . ""; + echo "
"; + } + + public function Forum($fid, $readlist, $writelist, $name) + { + $this->fid = $fid; + $this->readlist = $readlist; + $this->writelist = $writelist; + $this->name = $name; + } +} + +class Forums { + + private $file; + public $forums = array(); + + public function add($forum) { + $key = $forum->fid; + $this->forums[$key] = $forum; + } + + public function write() + { + /* + $fp = fopen($this->file, "w"); + + $block = TRUE; + flock($fp, LOCK_EX, $block); // do an exclusive lock + + fwrite($fp, "\n"); + + fwrite($fp, "\n"); + foreach($this->members as $member) { + fwrite($fp, " 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, " \n"); + } + fwrite($fp, "\n"); + + fclose($fp); + */ + } + + /* + public function deleteForumUser($id) + { + if($this->members[$id]) { + unset($this->members[$id]); + // $this->write(); + } else { + echo "

ERROR: User! ".$id." does not exist!

\n"; + return false; + } + return true; + } + */ + + public function getForum($fid) + { + $forum = $this->forums[$fid]; + return $forum; + } + + public function show() + { + foreach($this->forums as $forum) { + $forum->show(); + } + } + + private function read() + { + global $FORUMS_DIR; + + $dom = new DomDocument; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->file); + $forums = $dom->getElementsByTagName('forum'); + + foreach($forums as $f) { + $forum = new Forum($f->getAttribute('fid'), + $f->getAttribute('readlist'), + $f->getAttribute('writelist'), + $f->getAttribute('name')); + + $this->add($forum); + + $threads = new Threads($FORUMS_DIR . "/" . $f->getAttribute('fid')); + $forum->setNewStuff($threads->newStuff()); + } + } + + public function Forums($file) + { + $this->file = $file; + $this->read(); + } + +} +?> \ No newline at end of file diff --git a/forum/utils/log.php b/forum/utils/log.php new file mode 100644 index 0000000..e04c3bf --- /dev/null +++ b/forum/utils/log.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/forum/utils/login.php b/forum/utils/login.php new file mode 100644 index 0000000..50d0da2 --- /dev/null +++ b/forum/utils/login.php @@ -0,0 +1,105 @@ +getUserID($current_username); + $u = $users->getUser($current_uid); + + if($u && $u->checkPassword($current_password) ) { + $current_user = $u; + setcookie("current_uid", $current_uid, time()+$ADMIN_TIMEOUT); + setcookie("current_password", $current_password, time()+$ADMIN_TIMEOUT); + + _log($u->username, "logged in"); + + if($current_user->notified > 0) { + $current_user->notified = 0; + $users->write(); + } + + } else { + // Remove cookies + setcookie("current_uid", "", time()-1); + setcookie("current_password", "", time()-1); + } + + } else if($action == "logout") { + + /** + * Logout + */ + $u = $users->getUser($HTTP_COOKIE_VARS["current_uid"]); + + // Remove cookies + setcookie("current_uid", "", time()-1); + setcookie("current_password", "", time()-1); + + $current_uid = ""; + $current_password = ""; + $current_user = false; + + _log($u->username, "logged out"); + + } else { + + /** + * Usage + */ + + if($HTTP_COOKIE_VARS["current_uid"] == "") return; + + $u = $users->getUser($HTTP_COOKIE_VARS["current_uid"]); + if($u->checkPassword($HTTP_COOKIE_VARS["current_password"]) ) { + setcookie("current_uid", $HTTP_COOKIE_VARS["current_uid"], time()+$ADMIN_TIMEOUT); + setcookie("current_password", $HTTP_COOKIE_VARS["current_password"], time()+$ADMIN_TIMEOUT); + + $current_user = $u; + + if($current_user->notified > 0) { + $current_user->notified = 0; + $users->write(); + } + + _log($u->username, "seen"); + + } else { + // Remove cookies + setcookie("current_uid", "", time()-1); + setcookie("current_password", "", time()-1); + + $current_uid = ""; + $current_password = ""; + $current_user = false; + + } + } + +} + +?> diff --git a/forum/utils/mimetypes.php b/forum/utils/mimetypes.php new file mode 100644 index 0000000..f9ecfea --- /dev/null +++ b/forum/utils/mimetypes.php @@ -0,0 +1,50 @@ +name = $name; + $this->exts = $exts; + $this->show = $show; + } +}; + + +$DEFAULT_MIME_TYPE = new MimeType("application/octet-stream", array(), false); + +// Know mimetypes +$MIME_TYPES = array(new MimeType("image/jpeg",array("jpg","jpeg","jpe"),true), + new MimeType("image/gif",array("gif"),true), + new MimeType("image/png",array("png"),true), + new MimeType("audio/mpeg",array("mp3","mpga","mpega","mp2","m4a"),false), + new MimeType("application/ogg",array("ogg"),false), + new MimeType("application/pdf",array("pdf"),false), + new MimeType("application/msword",array("doc"),false), + new MimeType("text/plain", array("asc","txt","text","diff","pot"), true) + ); + + +// Get file extension. +function extension($file) { + $fileExp = explode('.', $file); // make array off the periods + $filetype = $fileExp[count($fileExp) -1]; // file extension will be last index in array, -1 for 0-based indexes + return strtolower($filetype); +} + +function getMimeType($file) +{ + global $DEFAULT_MIME_TYPE; + global $MIME_TYPES; + + $ext = extension($file); + foreach($MIME_TYPES as $m) { + foreach($m->exts as $e) if($e == $ext) return $m; + } + return $DEFAULT_MIME_TYPE; +} + +?> \ No newline at end of file diff --git a/forum/utils/notify.php b/forum/utils/notify.php new file mode 100644 index 0000000..f52d167 --- /dev/null +++ b/forum/utils/notify.php @@ -0,0 +1,70 @@ +"; +$replyto = $sender; +$footer = " + +Stay Brutal! +// DIE +http://www.executionroom.com +info@executionroom.com +"; + +function send($email, $subject, $message) +{ + global $subject_prefix; + global $sender; + global $replyto; + global $footer; + + $message .= $footer; + // $message .= ""; + $headers = "From: " . $sender . "\r\n"; + $headers .= "Reply-To: " . $replyto . "\r\n"; + $headers .= "Content-Type: text/plain; charset=iso-8859-1\r\n"; + $headers .= "X-Mailer: PHP/" . phpversion(); + $subject = "[".$subject_prefix."] " . utf8_decode($subject); + + $ret = mail($email, $subject, utf8_decode($message), $headers); + if(!$ret) echo error("The mail to " . $email . "could not be sent."); +} + +function notify($module = "", $event = "") +{ + global $users; + global $current_user; + $users_changed = false; + + foreach($users->users as $user) { + if($user->uid == 0) continue; // Don't notify the admin + if($user->enabled == false) continue; // Do not mail disabled accounts. + + if($module == "calendar" || // Always mail calendar updates. + ( + $module == "forum" && + $user != $current_user && // Don't notify current user. + $user->notified < (time() - (60 * 60 * 24 * 7)) // Don't notify if already notified. + ) + ) { + send($user->email, $module . " changed", + "There has been a change in the " . $module . " module by " . + $current_user->name . ":\n" . $event); + + _log($user->username, "notified (" . $module . ")"); + + if($module != "calendar") { + $user->notified = time(); + $users_changed = true; + } + } + } + if($users_changed == true) $users->write(); +} +?> diff --git a/forum/utils/parser.php b/forum/utils/parser.php new file mode 100644 index 0000000..3c33a9b --- /dev/null +++ b/forum/utils/parser.php @@ -0,0 +1,126 @@ +", $output); + $output = $smile; + } + + // Replace URLs with tags + $urls = ""; + while(($start = strpos($output, "http://"))) { + $pre = substr($output, 0, $start); + $url = substr($output, $start); + $end1 = strpos($url, " "); + $end2 = strpos($url, "\n"); + if($end1 == 0) { + if($end2 == 0) $end = strlen($url); + else $end = $end2; + } else { + if($end2 == 0) $end = $end1; + else if($end1 < $end2) $end = $end1; + else $end = $end2; + } + $url = substr($url, 0, $end); + $post = substr($output, $start + $end); + if(strstr($url, ".jpg") || strstr($url, ".gif") || strstr($url, ".png")) { + $urls .= $pre . "\"""; + } else { + $urls .= $pre . "" . $url . ""; + } + $output = $post; + } + $urls .= $output; + $output = $urls; + + // Replace [quote title=...]...[/quote] + $urls = ""; + while(($start = strpos($output, "[quote"))) { + $pre = substr($output, 0, $start); + $url = substr($output, $start); + $end = strpos($url, "[/quote]") + strlen("[/quote]"); + $url = substr($url, 0, $end - strlen("[/quote]")); + $post = substr($output, $start + $end + strlen("[/quote]") ); + + $header = substr($url, 0, strpos($url, "]") + 1); + $body = substr($url, strpos($url, "]") + 1); + + $header = str_replace(array("title"), "", $header); + $header = str_replace(array("="), "
", $header); + $header = str_replace(array("[quote"), "
", $header); + $header = str_replace(array("]"), "
", $header); + + $urls .= $pre . $header . $body . "
"; + $output = $post; + } + $urls .= $output; + $output = $urls; + + // + // Hack to make quotes two levels deep. + // + // Replace [quote title=...]...[/quote] + $urls = ""; + while(($start = strpos($output, "[quote"))) { + $pre = substr($output, 0, $start); + $url = substr($output, $start); + $end = strpos($url, "[/quote]") + strlen("[/quote]"); + $url = substr($url, 0, $end - strlen("[/quote]")); + $post = substr($output, $start + $end + strlen("[/quote]") ); + + $header = substr($url, 0, strpos($url, "]") + 1); + $body = substr($url, strpos($url, "]") + 1); + + $header = str_replace(array("title"), "", $header); + $header = str_replace(array("="), "
", $header); + $header = str_replace(array("[quote"), "
", $header); + $header = str_replace(array("]"), "
", $header); + + $urls .= $pre . $header . $body . "
"; + $output = $post; + } + $urls .= $output; + $output = $urls; + + // + $b = array("[b]", "[B]"); + $b = str_replace($b, "", $output); + $output = $b; + + $b = array("[/b]", "[/B]"); + $b = str_replace($b, "", $output); + $output = $b; + + // + $i = array("[i]", "[I]"); + $i = str_replace($i, "", $output); + $output = $i; + + $i = array("[/i]", "[/i]"); + $i = str_replace($i, "", $output); + $output = $i; + + // Replace newlines with
tags + $nls = array("\n"); + $nls = str_replace($nls, "
\n", $output); + $output = $nls; + + return $output; +} + +?> diff --git a/forum/utils/ping.php b/forum/utils/ping.php new file mode 100644 index 0000000..8977df5 --- /dev/null +++ b/forum/utils/ping.php @@ -0,0 +1,126 @@ +> 16) + ($sum & 0xffff); + $sum += ($sum >> 16); + + return pack('n*', ~$sum); +} + +function getLastIcmpError() +{ + global $g_icmp_error; + return $g_icmp_error; +} + +?> \ No newline at end of file diff --git a/forum/utils/posts.php b/forum/utils/posts.php new file mode 100644 index 0000000..c301852 --- /dev/null +++ b/forum/utils/posts.php @@ -0,0 +1,254 @@ +pid . "\"\n"); + fwrite($fp, $indent . " user=\"" . $this->user . "\"\n"); + fwrite($fp, $indent . " title=\"" . convert_xml($this->title) . "\"\n"); + fwrite($fp, $indent . " date=\"" . $this->date . "\">\n"); + fwrite($fp, $indent . " " . convert_xml($this->message) . "\n"); + + foreach($this->replies as $reply) { + $reply->write($fp, $indent . " "); + } + + fwrite($fp, $indent . "\n"); + } + + public function add($post) { + $key = $post->pid; + $this->replies[$key] = $post; + } + + public function getPost($pid) + { + $result = false; + + foreach($this->replies as $post) { + if($post->pid == $pid) return $post; + $result = $post->getPost($pid); + if($result) return $result; + } + + return $result; + } + + public function show($indent = "", $recurse = true) + { + global $users, $fid, $tid, $current_user, $client_is_mobile_device; + $user = $users->getUser($this->user); + + echo $indent . "
\n"; + if($client_is_mobile_device) { + $avatar = "mobileavatar.gif"; + } else { + if($user->avatar) $avatar = $user->avatar; + else $avatar = "default.gif"; + } + echo $indent . " \"avatar\"\n"; + if(!$client_is_mobile_device) { + echo $indent . "
ID: " . $this->pid . "
\n"; + echo $indent . "
Title: " . convert_xml($this->title) . "
\n"; + } + echo $indent . "
"; + if(!$client_is_mobile_device) echo "UserID: "; + echo $user->name . "
\n"; + echo $indent . "
"; + if(!$client_is_mobile_device) echo "Date: "; + echo date("j. M Y - G:i", $this->date) . "
\n"; + echo $indent . "
\n"; + echo parse($this->message, $indent . " ") . "\n"; + echo $indent . "
\n"; + echo $indent . "
\n"; + + if($current_user->uid == $this->user) { + echo $indent . + " "; + echo "\"edit\"\n"; + } + + echo $indent . + " "; + echo "\"quote\"\n"; + + echo $indent . + " "; + echo "\"reply\"\n"; + + echo $indent . "
\n"; + echo $indent . "
\n"; + + if($recurse) { + foreach($this->replies as $reply) { + $reply->show($indent . " "); + } + } + + echo $indent . "
\n"; + echo $indent . "
\n"; + } + + public function Post($pid, $title, $user, $date, $message = "") + { + $this->pid = $pid; + $this->title = $title; + $this->user = $user; + $this->date = $date; + $this->message = $message; + } +} + +class Posts { + private $file; + private $posts = array(); + public $thread; + private $posts_linear = array(); + private $maxkey = 0; + + public function nextkey() { + $this->maxkey++; + return $this->maxkey; + } + + public function add($post) { + $key = $post->pid; + $this->posts[$key] = $post; + } + + public function write() + { + $fp = fopen($this->file, "w"); + + $block = TRUE; + flock($fp, LOCK_EX, $block); // do an exclusive lock + + fwrite($fp, "\n"); + + if($this->thread->lastseen) { + foreach($this->thread->lastseen as $key => $value) { + if($lastseenstr != "") $lastseenstr .= ","; + $lastseenstr .= $key . "=" . $value; + } + } + + fwrite($fp, "thread->tid . "\"\n"); + fwrite($fp, " name=\"" . convert_xml($this->thread->name) . "\"\n"); + fwrite($fp, " lastpost=\"" . $this->thread->lastpost . "\"\n"); + fwrite($fp, " lastseen=\"" . $lastseenstr . "\">\n"); + + foreach($this->posts as $post) { + $post->write($fp, " "); + } + + fwrite($fp, "\n"); + + fclose($fp); + } + + public function getPost($pid) + { + $result = false; + + foreach($this->posts as $post) { + if($post->pid == $pid) return $post; + $result = $post->getPost($pid); + if($result) return $result; + } + + return $result; + } + + public function show() + { + global $current_user; + echo "

" . $this->thread->name . "

"; + + /* // Recursive + foreach($this->posts as $post) { + $post->show(); + } + */ + + // Linear + foreach($this->posts_linear as $post) { + $post->show("", false); + } + + $this->thread->lastseen[$current_user->uid] = time(); + + $this->write(); + + echo "

Back to the top

"; + } + + private function recurser($parentpost, $element) + { + if($element->tagName != "post") return; + + $post = new Post($element->getAttribute('pid'), + $element->getAttribute('title'), + $element->getAttribute('user'), + $element->getAttribute('date')); + + $this->posts_linear[$post->date . "-" . $post->pid] = $post; + + if($post->pid > $this->maxkey) $this->maxkey = $post->pid; + + if($parentpost) $parentpost->add($post); + else $this->add($post); + + foreach($element->childNodes as $child) { + if($child->tagName == "post") + $this->recurser($post, $child); + if($child->tagName == "message") + $post->message = $child->textContent; + } + } + + private function read() + { + $dom = new DomDocument; + $dom->resolveExternals = FALSE; + $dom->substituteEntities = FALSE; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->file); + + $thread = $dom->documentElement; + $this->thread = new Thread($thread->getAttribute('tid'), + $thread->getAttribute('name'), + $thread->getAttribute('lastpost'), + $thread->getAttribute('lastseen')); + foreach($thread->childNodes as $child) { + $this->recurser(false, $child); + } + + // The linear list should be sorted. + sort($this->posts_linear); + } + + public function Posts($file) + { + $this->file = $file; + if(file_exists($this->file)) $this->read(); + } + +} +?> diff --git a/forum/utils/profile.php b/forum/utils/profile.php new file mode 100644 index 0000000..ee47cb0 --- /dev/null +++ b/forum/utils/profile.php @@ -0,0 +1,39 @@ +username = $username; + $current_user->name = $name; + $current_user->email = $email; + $current_user->avatar = $avatar; + if($password != "") { + if($password == $password_confirm) { + $current_user->password = sha1(md5($password)); + } else { + error("Passwords do not match - thus not changed!"); + } + } + $users->write(); +} +?> + +
+username; ?>">
*/ ?> +Name:
+New password:
+Confirm password:
+E-Mail:
+Avatar:
+
+ +
diff --git a/forum/utils/roadmap.php b/forum/utils/roadmap.php new file mode 100644 index 0000000..f3e85ca --- /dev/null +++ b/forum/utils/roadmap.php @@ -0,0 +1,70 @@ +file, "w"); + + $block = TRUE; + flock($fp, LOCK_EX, $block); // do an exclusive lock + + fwrite($fp, "\n"); + + fwrite($fp, " . "\"\n"); + fwrite($fp, " abc=\"" . . "\">\n"); + + // for each group + for($gid = 0; $gid < length($groups); $gid++) { + fwrite($fp, " \n"); + + for($iid = 0; $iid < length($groups[$gid]); $iid++) { + fwrite($fp, " \n"); + } + + fwrite($fp, " \n"); + } + + fwrite($fp, "\n"); + + fclose($fp); + } + + public function show() + { + } + + private function read() + { + $dom = new DomDocument; + $dom->resolveExternals = FALSE; + $dom->substituteEntities = FALSE; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->file); + + + $roadmap = $dom->documentElement; + foreach($roadmap->childNodes as $group) { + echo $group->getAttribute('id'); + echo $group->getAttribute('name'); + foreach($group->childNodes as $item) { + echo $item->getAttribute('id'); + echo $item->getAttribute('name'); + } + } + } + + public function Roadmap($file) + { + $this->file = $file; + if(file_exists($this->file)) $this->read(); + } + +} +?> \ No newline at end of file diff --git a/forum/utils/smileys.php b/forum/utils/smileys.php new file mode 100644 index 0000000..e0a2d1a --- /dev/null +++ b/forum/utils/smileys.php @@ -0,0 +1,38 @@ +", "->"), "arrow.gif"), + array(array(":smug:"), "smug.gif"), + array(array(":idea:"), "idea.gif"), + array(array(":-K", ":-k", ":k", ":K"), "think.gif"), + array(array(":-O", ":O"), "surprised.gif"), + array(array(":S", ":-S"), "confused.gif"), + array(array(":drinker:"), "drinker.gif"), + array(array(":drinkers:"), "party.gif") + ); + + +?> diff --git a/forum/utils/threads.php b/forum/utils/threads.php new file mode 100644 index 0000000..e3f0996 --- /dev/null +++ b/forum/utils/threads.php @@ -0,0 +1,162 @@ + + * + * . + * . + * . + * + */ + +class Thread { + public $tid; + public $name; + public $lastseen = array(); + public $lastpost; + + public function show() + { + global $fid, $current_user; + echo "
"; + if($this->lastseen[$current_user->uid] < $this->lastpost) echo "
"; + else echo "
"; + echo "" . $this->name . ""; + echo "
"; + } + + private function loadLastSeen($lastseen) + { + if($lastseen == "") return; + $list = explode(",", $lastseen); + foreach($list as $l) { + $pair = explode("=", $l); + if($pair[0] != "" && $pair[1] != "") { + $this->lastseen[$pair[0]] = $pair[1]; + } + } + } + + public function Thread($tid, $name, $lastpost, $lastseen) + { + $this->tid = $tid; + $this->name = $name; + $this->lastpost = $lastpost; + $this->loadLastSeen($lastseen); + } +} + +class Threads { + + private $dir; + public $threads = array(); + + public function add($thread) { + // $key = $thread->name; + // $key = sprintf("%d-%d", $thread->lastpost, $thread->tid); + // $key = sprintf("%d", $thread->lastpost); + $key = $thread->lastpost . "-" . $thread->tid;//name; + // echo "[" . $key . "]"; + $this->threads[$key] = $thread; + } + + public function write() + { + /* + $fp = fopen($this->file, "w"); + + $block = TRUE; + flock($fp, LOCK_EX, $block); // do an exclusive lock + + fwrite($fp, "\n"); + + fwrite($fp, "\n"); + foreach($this->members as $member) { + fwrite($fp, " 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, " \n"); + } + fwrite($fp, "\n"); + + fclose($fp); + */ + } + + /* + public function deleteForumUser($id) + { + if($this->members[$id]) { + unset($this->members[$id]); + // $this->write(); + } else { + echo "

ERROR: User! ".$id." does not exist!

\n"; + return false; + } + return true; + } + */ + + public function getThread($tid) + { + $thread = $this->threads[$tid]; + return $thread; + } + + public function show() + { + foreach($this->threads as $thread) { + $thread->show(); + } + } + + public function newStuff() + { + global $current_user; + + foreach($this->threads as $thread) { + if($thread->lastseen[$current_user->uid] < $thread->lastpost) return true; + } + + return false; + } + + private function read() + { + $dh = opendir($this->dir); + while($file = readdir($dh)) { + if($file == "." || $file == "..") continue; + $dom = new DomDocument; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->dir . "/" . $file); + $threads = $dom->getElementsByTagName('thread'); + + foreach($threads as $f) { + $thread = new Thread($f->getAttribute('tid'), + $f->getAttribute('name'), + $f->getAttribute('lastpost'), + $f->getAttribute('lastseen')); + + $this->add($thread); + } + } + } + + public function Threads($dir) + { + $this->dir = $dir; + $this->read(); + krsort($this->threads); + } + +} +?> \ No newline at end of file diff --git a/forum/utils/users.php b/forum/utils/users.php new file mode 100644 index 0000000..99aaffc --- /dev/null +++ b/forum/utils/users.php @@ -0,0 +1,136 @@ +password == sha1(md5($password)); + } + + public function write($fp) + { + fwrite($fp, " enabled . "\"\n"); + fwrite($fp, " uid=\"" . $this->uid . "\"\n"); + fwrite($fp, " gid=\"" . $this->gid . "\"\n"); + fwrite($fp, " notified=\"" . $this->notified . "\"\n"); + fwrite($fp, " username=\"" . htmlspecialchars($this->username, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " password=\"" . $this->password . "\"\n"); + fwrite($fp, " name=\"" . htmlspecialchars($this->name, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " avatar=\"" . htmlspecialchars($this->avatar, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " email=\"" . htmlspecialchars($this->email, ENT_QUOTES, "UTF-8") . "\">\n"); + fwrite($fp, " \n"); + } + + public function User($enabled, $uid, $gid, $username, $password, $name, $email, $avatar, $notified) + { + $this->enabled = $enabled; + $this->gid = $gid; + $this->uid = $uid; + $this->username = $username; + $this->password = $password; + $this->email = $email; + $this->name = $name; + $this->avatar = $avatar; + if($notified == "") $notified = 0; + $this->notified = $notified; + } +} + +class Users { + + private $file; + public $users = array(); + + public function add($user) { + $key = $user->uid; + $this->users[$key] = $user; + } + + public function write() + { + $fp = fopen($this->file, "w"); + + $block = TRUE; + flock($fp, LOCK_EX, $block); // do an exclusive lock + + fwrite($fp, "\n"); + + fwrite($fp, "\n"); + foreach($this->users as $user) { + $user->write($fp); + } + fwrite($fp, "\n"); + + fclose($fp); + } + + /* + public function deleteForumUser($id) + { + if($this->members[$id]) { + unset($this->members[$id]); + // $this->write(); + } else { + echo "

ERROR: User! ".$id." does not exist!

\n"; + return false; + } + return true; + } + */ + + public function getUserID($username) + { + foreach($this->users as $user) { + if($user->username == $username) return $user->uid; + } + return false; + } + + public function getUser($uid) + { + $user = $this->users[$uid]; + return $user; + } + + private function read() + { + $dom = new DomDocument; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->file); + $users = $dom->getElementsByTagName('user'); + + foreach ($users as $u) { + $user = new User($u->getAttribute('enabled'), + $u->getAttribute('uid'), + $u->getAttribute('gid'), + $u->getAttribute('username'), + $u->getAttribute('password'), + $u->getAttribute('name'), + $u->getAttribute('email'), + $u->getAttribute('avatar'), + $u->getAttribute('notified')); + + $this->add($user); + } + + } + + public function Users($file) + { + $this->file = $file; + $this->read(); + } + +} +?> \ No newline at end of file diff --git a/forum/utils/view.php b/forum/utils/view.php new file mode 100644 index 0000000..0adb1a0 --- /dev/null +++ b/forum/utils/view.php @@ -0,0 +1,28 @@ +"; +if($fid) echo "forums"; +if($tid) echo ":: threads"; +if($pid) echo ":: posts"; +echo "\n"; + + + if($fid && $tid) { + // echo "

Posts

"; + include_once("posts.php"); + $posts = new Posts($FORUMS_DIR . "/" . $fid . "/" . $tid . ".xml"); + $posts->show(); + } else if($fid) { + echo "

Threads

"; + echo "New thread"; + + include_once("threads.php"); + $threads = new Threads($FORUMS_DIR . "/" . $fid); + $threads->show(); + } else { + echo "

Forums

"; + include_once("forums.php"); + $forums = new Forums($FORUMS_DIR . "/forums.xml"); + $forums->show(); + } +?> \ No newline at end of file -- cgit v1.2.3