private function onAdd() { $form = $this->formAdd(); if (false !== ($error = $form->validate($this->module))) { return $error . $this->templateAdd(); } $file = $form->getVar('file'); $tmp = $file['tmp_name']; $postid = $this->post->getID(); $userid = GWF_Session::getUserID(); $options = 0; $options |= isset($_POST['guest_view']) ? GWF_ForumAttachment::GUEST_VISIBLE : 0; $options |= isset($_POST['guest_down']) ? GWF_ForumAttachment::GUEST_DOWNLOAD : 0; # Put in db $attach = new GWF_ForumAttachment(array('fatt_aid' => 0, 'fatt_uid' => $userid, 'fatt_pid' => $postid, 'fatt_mime' => GWF_Upload::getMimeType($tmp), 'fatt_size' => filesize($tmp), 'fatt_downloads' => 0, 'fatt_filename' => $file['name'], 'fatt_options' => $options, 'fatt_date' => GWF_Time::getDate(GWF_Date::LEN_SECOND))); if (false === $attach->insert()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $aid = $attach->getID(); # Copy file $path = $attach->dbimgPath(); if (false === GWF_Upload::moveTo($file, $path)) { @unlink($tmp); return GWF_HTML::err('ERR_WRITE_FILE', $path); } @unlink($tmp); $this->post->increase('post_attachments', 1); return $this->module->message('msg_attach_added', array($this->post->getShowHREF())); }
public function onRequestInit() { GWF_ForumBoard::init(); # Init by Post if (0 !== ($this->post_id = (int) Common::getGet('pid', 0))) { if (false === ($this->post = GWF_ForumPost::getPost($this->post_id))) { $this->post_id = 0; } elseif (false !== ($this->thread = $this->post->getThread())) { $this->thread_id = $this->thread->getID(); if (false !== ($this->board = $this->thread->getBoard())) { $this->board_id = $this->board->getID(); } } } elseif (0 !== ($this->thread_id = (int) Common::getGet('tid', 0))) { if (false === ($this->thread = GWF_ForumThread::getThread($this->thread_id))) { $this->thread_id = 0; } elseif (false !== ($this->board = $this->thread->getBoard())) { $this->board_id = $this->board->getID(); } } else { $this->board_id = Common::getGetString('bid', '1'); if (false === ($this->board = GWF_ForumBoard::getBoard($this->board_id))) { $this->board_id = '1'; if (false === ($this->board = GWF_ForumBoard::getRoot())) { $this->board_id = '0'; } } } if ($this->thread_id !== 0 && 0 < ($cut = $this->cfgWatchTimeout())) { GWF_ForumVisitors::setWatching($this->thread, $cut); } }
private function onEdit() { $form = $this->formEdit(); if (false !== ($error = $form->validate($this->module))) { return $error; } $prepend = ''; # Re-Upload if (false !== ($file = $form->getVar('file')) & $file['size'] !== 0) { if (false !== ($error = $this->unReUpload($file, $this->attach))) { return $error; } $prepend = $this->module->message('msg_reupload'); } # Save option $this->attach->saveOption(GWF_ForumAttachment::GUEST_VISIBLE, isset($_POST['guest_view'])); $this->attach->saveOption(GWF_ForumAttachment::GUEST_DOWNLOAD, isset($_POST['guest_down'])); return $prepend . $this->module->message('msg_attach_edited', array($this->post->getShowHREF())); }
private function deletePost($pid, $token) { if (false === ($post = GWF_ForumPost::getPost($pid))) { return $this->module->error('err_post'); } if ($token !== $post->getToken()) { return $this->module->error('err_token'); } if (false === $post->deletePost()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return $this->module->message('msg_post_deleted'); }
public function onPreview() { $form = $this->getForm(); $errors = $form->validate($this->module); // $user = GWF_Session::getUser(); $user = $this->post->getUser(true); $title = $form->getVar('title'); $message = $form->getVar('message'); $options = 0; $options |= Common::getPost('bbcode') === false ? 0 : GWF_ForumPost::DISABLE_BB; $options |= Common::getPost('smileys') === false ? 0 : GWF_ForumPost::DISABLE_SMILE; $tVars = array('thread' => GWF_ForumThread::fakeThread($user, $title), 'posts' => array(GWF_ForumPost::fakePost($user, $title, $message, $options, 0, 0, GWF_Time::getDate(GWF_Date::LEN_SECOND), true)), 'pagemenu' => '', 'actions' => false, 'title' => false, 'reply' => true, 'nav' => false, 'term' => '', 'page' => 0, 'href_edit' => ''); $preview = $this->module->templatePHP('show_thread.php', $tVars); return $errors . $preview . $this->templateEdit(); }
private function onVote(GWF_ForumPost $post, $up = 1) { if (!$this->module->cfgVotesEnabled()) { return $this->module->error('err_votes_off'); } $userid = GWF_Session::getUserID(); if ($userid === $post->getUserID()) { return $this->module->error('err_vote_self'); } if ($up === 1) { $post->onVoteUp($userid); } else { $post->onVoteDown($userid); } return '1:' . $post->getVar('post_votes_up') . ':' . $post->getVar('post_votes_down'); // return $this->module->message('msg_voted'); }
public function onQuickSearch($term) { $posts = GDO::table('GWF_ForumPost'); $fields = $posts->getSearchableFields(GWF_User::getStaticOrGuest()); $_GET['term'] = $term = trim($term); // $term = Common::getRequest('term', ''); if (false === ($conditions = GWF_QuickSearch::getQuickSearchConditions($posts, $fields, $term))) { $conditions = '0'; } $permQuery = GWF_ForumPost::getPermQuery(); $conditions .= ' AND (' . $permQuery . ')'; $by = Common::getGet('by', 'post_date'); $dir = Common::getGet('dir', 'DESC'); $orderby = $posts->getMultiOrderby($by, $dir); $ipp = $this->module->getThreadsPerPage(); $nItems = $posts->countRows($conditions); $nPages = GWF_PageMenu::getPagecount($ipp, $nItems); $page = Common::clamp(Common::getGet('page', 1), 1, $nPages); $href = $this->getMethodHref(sprintf('&term=%s&by=%s&dir=%s&page=%%PAGE%%', urlencode($term), urlencode($by), urlencode($dir))); $this->pagemenu = GWF_PageMenu::display($page, $nPages, $href); $result = GWF_QuickSearch::search($posts, $fields, $term, $orderby, $ipp, GWF_PageMenu::getFrom($page, $ipp), $permQuery); $this->sortURL = $this->getMethodHref(sprintf('&term=%s&by=%%BY%%&dir=%%DIR%%&page=1', urlencode($term))); return $this->templateSearch($result, $term); }
private function onAddThread() { $form = $this->getForm(); if (false !== ($error = $form->validate($this->module))) { return $error . $this->templateAddThread(); } $user = GWF_Session::getUser(); $is_mod = $user === false && $this->module->isGuestPostModerated(); $title = $form->getVar('title'); $message = $form->getVar('message'); $bid = $this->board->getID(); $gid = $this->board->getGroupID(); $options = 0; $options |= $is_mod === false ? 0 : GWF_ForumThread::IN_MODERATION; $options |= $this->board->isGuestView() ? GWF_ForumThread::GUEST_VIEW : 0; // $options |= Common::getPost('guest_view') === false ? 0 : GWF_ForumThread::GUEST_VIEW; $date = GWF_Time::getDate(GWF_Time::LEN_SECOND); $thread = GWF_ForumThread::fakeThread($user, $title, $bid, $gid, 1, $options, $date); if (false === $thread->insert()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $tid = $thread->getID(); $gid = $thread->getGroupID(); $options = 0; $options |= Common::getPost('bbcode') === false ? 0 : GWF_ForumPost::DISABLE_BB; $options |= Common::getPost('smileys') === false ? 0 : GWF_ForumPost::DISABLE_SMILE; $options |= $is_mod === false ? 0 : GWF_ForumPost::IN_MODERATION; $options |= $this->board->isGuestView() ? GWF_ForumPost::GUEST_VIEW : 0; $post = GWF_ForumPost::fakePost($user, $title, $message, $options, $tid, $gid, $date); if (false === $post->insert()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (!$is_mod) { $thread->onApprove(); // $this->module->cachePostcoun(); return $this->module->message('msg_posted', array($thread->getLastPageHREF())); } else { GWF_ForumSubscription::sendModerateThread($this->module, $thread, $message); return $this->module->message('msg_posted_mod', array($this->board->getShowBoardHREF())); } }
public static function pushPost(GWF_ForumPost $post) { $history = new self(array('fph_pid' => $post->getID(), 'fph_euid' => $post->getUserID(), 'fph_gid' => $post->getGroupID(), 'fph_date' => $post->getDate(), 'fph_message' => $post->getVar('post_message'), 'fph_options' => $post->getOptions())); return $history->insert(); }
public static function newThread(GWF_User $user, $title = '', $message = '', $options = 0, $bid = 0, $gid = 0) { // No params if ($title === '' && $message === '') { return false; } // insert thread $postcount = $message === '' ? 0 : 1; $thread = self::fakeThread($user, $title, $bid, $gid, $postcount, $options); if (false === $thread->insert()) { return false; } // Insert message if there is one. if ($message !== '') { $threadid = $thread->getID(); $post = GWF_ForumPost::fakePost($user, $title, $message, $options, $threadid, $gid); if (false === $post->insert()) { return false; } } $thread->onApprove(false, $postcount); Module_Forum::getInstance()->cachePostcount(); return $thread; }
public static function sendModeratePost(Module_Forum $module, GWF_ForumPost $post) { $thread = $post->getThread(); $boardtxt = self::getBoardTreeText($thread->getBoard()); $threadtxt = $thread->display('thread_title'); $usertxt = GWF_User::getStaticOrGuest()->display('user_name'); $title = $post->displayTitle(); $message = $post->displayMessage(array(), true); $pid = $post->getID(); $token = $post->getToken(); $addtxt = Common::getAbsoluteURL('index.php?mo=Forum&me=Moderate&yes_post=' . $pid . '&token=' . $token); $remtxt = Common::getAbsoluteURL('index.php?mo=Forum&me=Moderate&no_post=' . $pid . '&token=' . $token); return self::sendModMail($module, $boardtxt, $threadtxt, $usertxt, $title, $message, $addtxt, $remtxt); }
/** * Get the forum post associated with this attachment. * @return GWF_ForumPost */ public function getPost() { return GWF_ForumPost::getPost($this->getVar('fatt_pid')); }
private function onReply() { $form = $this->getForm(); if (false !== ($error = $form->validate($this->module))) { return $error . $this->templateReply(); } # Gather vars $user = GWF_Session::getUser(); $is_mod = $user === false && $this->module->isGuestPostModerated(); $title = $form->getVar('title'); $message = $form->getVar('message'); $options = 0; $options |= Common::getPost('bbcode') === false ? 0 : GWF_ForumPost::DISABLE_BB; $options |= Common::getPost('smileys') === false ? 0 : GWF_ForumPost::DISABLE_SMILE; $options |= $is_mod ? GWF_ForumPost::IN_MODERATION : 0; // $options |= Common::getPost('guest_view') === false ? 0 : $this->thread->isGuestView(); $options |= $this->thread->isGuestView() ? GWF_ForumPost::GUEST_VIEW : 0; $threadid = $this->thread->getID(); $groupid = $this->thread->getGroupID(); # Post it $post = GWF_ForumPost::fakePost($user, $title, $message, $options, $threadid, $groupid); if (false === $post->insert()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (!$is_mod) { if (false === $post->onApprove($this->module)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } // $this->thread->increase('thread_postcount', 1); # Increase cache :/ $this->module->cachePostcount(); return $this->module->message('msg_posted', array($post->getThread()->getLastPageHREF())); } else { GWF_ForumSubscription::sendModeratePost($this->module, $post); return $this->module->message('msg_posted_mod', array($this->thread->getLastPageHREF())); } }