post_id = (int)safe_post("p"); $this->message = trim(safe_post("m")); } else if (isset($_GET["p"])) { $this->post_id = (int)safe_get("p"); $this->quote = (((int)safe_get("q")) === 1 ? true : false); set_this_link("post", array("p" => $this->post_id)); } else { throw new bad_parameters(); } $this->post = get_single_post($this->post_id); $this->thread = $this->post->thread(); } public function title() { return loc("reply_title"); } public function output($u, $problem) { $content = ""; if ($this->message !== "") $content = $this->message; else if ($this->quote) $content = $this->post->quote(); $tp = temporary_post::create_reply( $this->post->id(), $u->profile()->name(), $content); output_new_post($tp, $problem); } public function output_url() { return "post.html?p=" . $this->post_id . ($this->quote ? "&q=1" : ""); } public function on_submit($u) { if ($this->message === "") throw new empty_message(); return get_single_post(add_reply( $this->thread, $this->post, $u, $this->message)); } } class new_thread_poster extends poster { private $forum_id = 0; private $title = ""; private $message = ""; private $forum = null; public function __construct() { if (isset($_POST["f"])) { $this->forum_id = (int)safe_post("f"); $this->title = trim(safe_post("t")); $this->message = trim(safe_post("m")); } else if (isset($_GET["f"])) { $this->forum_id = (int)safe_get("f"); set_this_link("post", array("f" => $this->forum_id)); } else { throw new bad_parameters(); } $this->forum = get_forum($this->forum_id); } public function title() { return loc("new_thread_title"); } public function output($u, $problem) { $tp = temporary_post::create_new_thread( $this->forum->id(), $this->title, $u->profile()->name(), $this->message); output_new_thread($tp, $problem); } public function output_url() { return "post.html?f=" . $this->forum_id; } public function on_submit($u) { if ($this->title === "") throw new empty_title(); if ($this->message === "") throw new empty_message(); return get_single_post(add_thread( $this->forum, $u, $this->title, $this->message)); } } class edit_poster extends poster { private $post_id = 0; private $post = null; private $message = ""; public function __construct() { if (isset($_POST["e"])) { $this->post_id = (int)safe_post("e"); $this->message = trim(safe_post("m")); } else if (isset($_GET["e"])) { $this->post_id = (int)safe_get("e"); set_this_link("post", array("e" => $this->post_id)); } else { throw new bad_parameters(); } $this->post = get_single_post($this->post_id); if (!$this->post->editable()) throw new bad_parameters(); } public function title() { return loc("edit_title"); } public function output($u, $problem) { output_edit($this->post, $problem); } public function output_url() { return "post.html?e=" . $this->post_id; } public function on_submit($u) { if ($this->message === "") throw new empty_message(); $cm = $this->post->mod_comment(); if (logged_user()->can_moderate()) $cm = safe_post("c", $cm); $this->post->set_content($this->message, $cm); return $this->post; } } function make_poster() { if (isset($_POST["p"]) || isset($_GET["p"])) return new reply_poster(); else if (isset($_POST["f"]) || isset($_GET["f"])) return new new_thread_poster(); else if (isset($_POST["e"]) || isset($_GET["e"])) return new edit_poster(); else throw new bad_parameters(); } function do_post($p, $u) { $post = $p->on_submit($u); $url = ""; if ($post->queued()) { if ($post->first_post()) $url = make_forum_link_impl($post->forum_id()); else $url = make_thread_link_impl($post->thread_id()); } else { $url = make_post_link_impl($post->thread_id(), $post->id()); } header("Location: $url"); exit; } $error = ""; $problem = ""; $title = ""; $p = null; $user = null; try { $author = trim(safe_post("a")); $user = logged_user(); if ($user->is_anonymous()) $user = user::anonymous($author); if (opt()->readonly()) throw new readonly(); $p = make_poster(); $title = $p->title(); if (isset($_POST["submit"])) { do_post($p, $user); exit; } } catch(empty_message $e) { $problem = loc("new_post_empty_message"); } catch(empty_title $e) { $problem = loc("new_post_empty_title"); } catch(readonly $e) { $error = "posting disabled"; } catch(bad_parameters $e) { $error = "bad parameters"; } catch(forum_not_found $e) { $error = "forum not found"; } catch(thread_not_found $e) { $error = "thread not found"; } catch(post_not_found $e) { $error = "post not found"; } catch(db_exception $e) { $error = $e->html(); } output_head("forum", $title); ?>