private function getLastPosterName(GWF_ForumThread $thread) { $posts = GDO::table('GWF_ForumPost'); # posts table $date = $thread->getVar('thread_lastdate'); # last date # Check if a post was made at this date. if (false !== ($username = $posts->selectVar('user_name', "post_date='{$date}'", '', array('post_uid')))) { return $username; } # Check if an edit was made at this date. if (false !== ($username = $posts->selectVar('post_eusername', "post_edate='{$date}'"))) { return $username; } # Should not get here (race condition) but works as a fallback. return $thread->getVar('thread_lastposter'); }
public static function setWatching(GWF_ForumThread $thread, $cut) { $tid = $thread->getID(); # Insert current spectator // GDO::table(__CLASS__); $row = new self(array('fowa_sess' => GWF_Session::getSessID(), 'fowa_time' => time(), 'fowa_tid' => $tid)); if (false === $row->replace()) { return false; } # Delete old $cut = time() - $cut; if (false === $row->deleteWhere("fowa_time<{$cut}")) { return false; } # Set new amount if (false === $thread->saveVar('thread_watchers', $row->countRows("fowa_tid={$tid}"))) { return false; } return true; }
public function templateForum() { $by = urlencode(Common::getGetString('tby', 'thread_lastdate')); $dir = urlencode(Common::getGetString('tdir', 'DESC')); $bby = urlencode(Common::getGetString('bby', 'board_pos')); $bdir = urlencode(Common::getGetString('bdir', 'ASC')); $orderby = GDO::table('GWF_ForumThread')->getMultiOrderby($by, $dir); $bid = $this->board->getVar('board_bid'); $bt = $this->board->urlencodeSEO('board_title'); $tVars = array('boards' => $this->board->getBoardPage($this->bPage, $this->tpp), 'board' => $this->board, 'pagemenu_boards' => GWF_PageMenu::display($this->bPage, $this->nBPages, sprintf(GWF_WEB_ROOT . 'forum-b%s/bby/%s/%s/%s-p%%PAGE%%.html', $bid, $bby, $bdir, $bt)), 'threads' => $this->board->getThreads($this->tpp, $this->page, $orderby), 'pagemenu_threads' => GWF_PageMenu::display($this->page, $this->nPages, sprintf(GWF_WEB_ROOT . 'forum-b%s/tby/%s/%s/%s-p%%PAGE%%.html', $bid, $by, $dir, $bt)), 'new_thread_allowed' => $this->board->isNewThreadAllowed(), 'unread_threads' => GWF_ForumThread::getUnreadThreadCount(GWF_Session::getUser()), 'latest_threads' => GWF_ForumThread::getLatestThreads($this->module->getNumLatestThreads()), 'href_options' => GWF_WEB_ROOT . 'forum/options', 'href_unread' => $this->module->getMethodURL('Unread'), 'href_search' => GWF_WEB_ROOT . 'forum/search', 'board_sort_url' => GWF_WEB_ROOT . sprintf('forum-b%s/bby/%%BY%%/%%DIR%%/%s-p1.html', $bid, $bt), 'thread_sort_url' => GWF_WEB_ROOT . sprintf('forum-b%s/bby/%s/%s/bp-%d/tby/%%BY%%/%%DIR%%/%s-p1.html', $bid, $bby, $bdir, $this->bPage, $bt), 'href_polls' => GWF_WEB_ROOT . 'poll_overview'); return $this->module->templatePHP('forum.php', $tVars); }
private function sanitize() { $this->threads = GDO::table('GWF_ForumThread'); $this->conditions = sprintf('thread_postcount>0 AND (%s) AND thread_options&%d=0', GWF_ForumThread::getPermQuery(), GWF_ForumThread::IN_MODERATION | GWF_ForumThread::INVISIBLE); $this->nThreads = $this->threads->countRows($this->conditions); $this->tpp = $this->module->getThreadsPerPage(); $this->nPages = GWF_PageMenu::getPagecount($this->tpp, $this->nThreads); $this->page = Common::clamp(Common::getGet('page', $this->nPages), 1, $this->nPages); $this->by = $_GET['by'] = Common::getGet('by', 'thread_lastdate'); $this->dir = $_GET['dir'] = Common::getGet('dir', 'ASC'); $this->orderby = $this->threads->getMultiOrderby($this->by, $this->dir); }
private function onUnSubscribeExtThread($token) { if (false === $this->checkExternalToken($token)) { return $this->module->error('err_token'); } if (!GWF_ForumSubscription::hasSubscribedManually($this->user, $this->thread->getID())) { return $this->module->error('err_sub_by_global'); } if (false === GWF_ForumSubscription::unsubscribe($this->user->getID(), $this->thread->getID())) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return $this->module->message('msg_unsubscribed', array($this->thread->getLastPageHREF())); }
private function deleteThread($tid, $token) { if (false === ($thread = GWF_ForumThread::getThread($tid))) { return $this->module->error('err_thread'); } if ($token !== $thread->getToken()) { return $this->module->error('err_token'); } if (false === $thread->deleteThread()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return $this->module->message('msg_thread_deleted'); }
private static function displayMenuForum(Module_PoolTool $module) { $sel = Common::getGet('mo') === 'Forum'; $sel = $sel ? ' class="menu_sel"' : ''; $href = GWF_WEB_ROOT . 'forum'; $app = ''; if (false !== ($user = GWF_Session::getUser())) { require_once GWF_CORE_PATH . 'module/Forum/GWF_ForumThread.php'; $count = GWF_ForumThread::getUnreadThreadCount($user); if ($count > 0) { $app = " [{$count}]"; } } return sprintf('<a %shref="%s">%s</a>', $sel, $href, $module->lang('menu_forum') . $app); }
public function templateUnread() { $by = Common::getGet('by', 'thread_lastdate'); $dir = Common::getGet('dir', 'DESC'); $page = intval(Common::getGet('page', 1)); $t = GDO::table('GWF_ForumThread'); $ipp = $this->module->getThreadsPerPage(); $orderby = $t->getMultiOrderby($by, $dir); $conditions = GWF_ForumThread::getUnreadQuery(GWF_Session::getUser()); $nItems = $t->countRows($conditions); $nPages = GWF_PageMenu::getPagecount($ipp, $nItems); $page = Common::clamp($page, 1, $nPages); $threads = $t->selectObjects('*', $conditions, $orderby, $ipp, GWF_PageMenu::getFrom($page, $ipp)); $pmhref = $this->getMethodHref(sprintf('&by=%s&dir=%s&page=%%PAGE%%', urlencode($by), urlencode($dir))); $tVars = array('pagemenu' => GWF_PageMenu::display($page, $nPages, $pmhref), 'threads' => $threads, 'board' => $this->module->getCurrentBoard(), 'sort_url' => $this->getMethodHref(sprintf('&by=%%BY%%&dir=%%DIR%%&page=1'))); return $this->module->templatePHP('unread.php', $tVars); }
public function execute() { if (false === ($mod_votes = GWF_Module::loadModuleDB('Votes'))) { return GWF_HTML::err('ERR_MODULE_MISSING', array('Votes')); } $mod_votes->onInclude(); if (!($this->thread = GWF_ForumThread::getThread(Common::getGet('tid')))) { return $this->module->error('err_thread'); } $this->user = GWF_Session::getUser(); if (!$this->thread->mayAddPoll($this->user)) { return GWF_HTML::err('ERR_NO_PERMISSION'); } if (false !== Common::getPost('assign')) { return $this->onAssign() . $this->template(); } return $this->template(); }
public function execute() { $user = GWF_Session::getUser(); $cnt = GWF_ForumThread::getUnreadThreadCount($user); // Save stamp $data = $user->getUserData(); $data[GWF_ForumThread::STAMP_NAME] = GWF_Time::getDate(GWF_Date::LEN_SECOND); if (false === $user->saveUserData($data)) { return GWF_HTML::err('ERR_DATABASE', __FILE__, __LINE__); } // Clean thread table $threads = GDO::table('GWF_ForumThread'); $uid = $user->getVar('user_id'); if (false === $threads->update("thread_unread=REPLACE(thread_unread, ':{$uid}:', ':'), thread_force_unread=REPLACE(thread_force_unread, ':{$uid}:', ':')")) { return GWF_HTML::err('ERR_DATABASE', __FILE__, __LINE__); } // $cnt = $threads->affectedRows(); # As we mark all read it's easier to assume it works :D return $this->module->message('msg_mark_aread', array($cnt)); }
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())); } }
public function onCreateThread(Module_WeChall $module) { if (false !== ($thread = $this->getThread())) { return true; } $title = 'Comments on ' . $this->getSitename(); $options = GWF_ForumThread::GUEST_VIEW; $thread = GWF_ForumThread::fakeThread($module->cfgWeChallUser(), $title, $this->getBoardID(), 0, 0, $options); if (false === $thread->insert()) { return false; } if (false === $this->saveVar('site_threadid', $thread->getID())) { return false; } return $thread->onApprove(false, 0); }
public function newsToForum(GWF_News $news, $visible = true) { if (false === ($poster = $news->getUser())) { return GWF_HTML::error('News_Edit', 'News_Edit::newsToForum(): Nobody as Poster'); } // Get News root. if (false === ($news_root = $this->getNewsForumRoot())) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $root_id = $news_root->getID(); $lang_roots = array(); foreach ($news->getTranslations() as $t) { if (false === ($lang = GWF_Language::getByID($t['newst_langid']))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === ($lang_board = $this->getNewsForumLangCached($lang, $root_id))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $iso = $lang->getISO(); $tid = (int) $t['newst_threadid']; $lang_roots[$iso] = $lang_board; $bid = $lang_board->getID(); $thread = GWF_ForumThread::getByID($tid); $title = $t['newst_title']; $message = $t['newst_message']; $gid = 0; $options = GWF_ForumThread::GUEST_VIEW; $options |= $visible ? 0 : GWF_ForumThread::INVISIBLE; if (!$visible) { if ($thread !== false) { $thread->setVisible($visible); } } else { if ($thread === false) { if (false === ($thread = GWF_ForumThread::newThread($poster, $title, $message, $options, $bid, $gid))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } } else { if (false === ($post = $thread->getFirstPost())) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === $post->saveVar('post_message', $message)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } } $thread->setVisible($visible); } $tid = $thread === false ? 0 : $thread->getID(); $langid = $lang->getID(); $newsid = $news->getID(); // Save threadid if (false === GDO::table('GWF_NewsTranslation')->update("newst_threadid={$tid}", "newst_langid={$langid} AND newst_newsid={$newsid}")) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } } // Set Boards Visible $news_root->setVisible($visible); foreach ($lang_roots as $iso => $board) { $board->setVisible($visible); } return ''; }
/** * @return GWF_ForumThread */ public function getThread() { return GWF_ForumThread::getThread($this->getVar('post_tid')); }
private function getPageMenu() { $href = GWF_WEB_ROOT . sprintf('forum-t%s/%s-p%%PAGE%%.html', $this->thread->getID(), $this->thread->urlencodeSEO('thread_title')); return GWF_PageMenu::display($this->page, $this->nPages, $href); }
/** * Return a page of threads for this board. (Some thread rows from DB) * @param unknown_type $count * @param unknown_type $page * @return unknown_type */ public function getThreads($count, $page, $orderby) { return GWF_ForumThread::getThreadPage($this->getID(), $count, $page, $orderby); }
public function hrefThread($thread_id) { if (false === ($thread = GWF_ForumThread::getByID($thread_id))) { return '#'; } return $thread->getLastPageHREF(); }
public function validate_thread($arg) { if (false === GWF_ForumThread::getThread($arg)) { return $this->lang('err_thread'); } return false; }
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())); } }
private static function sendSubscriptionB(Module_Forum $module, GWF_ForumThread $thread, GWF_User $user, $postername, $msg_block, $msg_count, $boardText, $threadTitle, $sender) { $userid = $user->getID(); $username = $user->displayUsername(); if (false === ($receiver = $user->getValidMail())) { GWF_Log::logCron('[ERROR] User ' . $username . ' has no valid email.'); return false; } if (false === ($options = GWF_ForumOptions::getUserOptions($user))) { GWF_Log::logCron('[ERROR] User ' . $username . ' has no valid forum options.'); } $token = $options->getVar('fopt_token'); $href = Common::getAbsoluteURL($thread->getLastPageHREF(false), false); $showLink = GWF_HTML::anchor($href, $href); $href = Common::getAbsoluteURL($thread->getExternalUnSubscribeHREF($userid, $token, true), false); $unsubLink = GWF_HTML::anchor($href, $href); $href = Common::getAbsoluteURL($thread->getExternalUnSubscribeAllHREF($userid, $token, true), false); $unsubLinkAll = GWF_HTML::anchor($href, $href); $mail = new GWF_Mail(); $mail->setSender($sender); $mail->setReceiver($receiver); $mail->setSubject($module->langUser($user, 'submail_subj', array($threadTitle, $postername, $boardText))); $mail->setBody($module->langUser($user, 'submail_body', array($username, $msg_count, $boardText, $threadTitle, $msg_block, $showLink, $unsubLink, $unsubLinkAll))); if (false === $mail->sendToUser($user)) { GWF_Log::logCron('[ERROR] Can not send mail to ' . $username . '; EMail: ' . $receiver); } else { GWF_Log::logCron('[+] Successfully sent Email to ' . $username . '; EMail: ' . $receiver); } }
private function onMerge(GWF_ForumThread $first, GWF_ForumThread $last) { // Delete thread if (false === $last->delete()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } // Sum counters if (false === $first->saveVar('thread_postcount', $first->getPostCount() + $last->getPostCount())) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === $first->saveVar('thread_viewcount', $first->getVar('thread_viewcount') + $last->getVar('thread_viewcount'))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === $first->saveVar('thread_thanks', $first->getVar('thread_thanks') + $last->getVar('thread_thanks'))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === $first->saveVar('thread_votes_up', $first->getVar('thread_votes_up') + $last->getVar('thread_votes_up'))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === $first->saveVar('thread_votes_down', $first->getVar('thread_votes_down') + $last->getVar('thread_votes_down'))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } // -1 thread if (false === $first->getBoard()->adjustCounters(-1, 0)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } // change threadid's $t1id = $first->getID(); $t2id = $last->getID(); if (false === GDO::table('GWF_ForumPost')->update("post_tid={$t1id}", "post_tid={$t2id}")) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } // Done return $this->module->message('msg_merged'); }
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(); }