Exemplo n.º 1
0
 function ShowThreads($id)
 {
     global $LimitJump_top, $LimitJump_bot, $awcUser;
     global $wgOut, $wgUser, $WhoWhere, $awc_tables, $numthreadcols, $tplt;
     $perm = new awcs_forum_perm_checks();
     $thread_tools = new awcs_forum_thread_list_tools();
     $word_headers = array('replies' => get_awcsforum_word('word_replies'), 'views' => get_awcsforum_word('views'), 'last_action' => get_awcsforum_word('last_action'), 'started_by' => get_awcsforum_word('thread_title_started_by'));
     $word = array('replies' => get_awcsforum_word('word_replies'), 'views' => get_awcsforum_word('views'), 'last_action' => get_awcsforum_word('last_action'), 'started_by' => get_awcsforum_word('forum_started_by'));
     $f_id = (int) $id;
     $sql = $this->rDB->selectSQLText(array('awc_f_forums', 'awc_f_cats'), array('f_name, f_desc, f_top_tmplt, f_parentid, f_id, f_threads,
              f_wiki_read_perm, f_wiki_write_perm, f_passworded, cat_name'), "f_id={$f_id}", __METHOD__, array('OFFSET' => '0', 'LIMIT' => '1'), array('awc_f_cats' => array('LEFT JOIN', 'cat_id=f_parentid')));
     $res = $this->rDB->query($sql);
     $r = $this->rDB->fetchRow($res);
     $this->rDB->freeResult($res);
     $forum_info = array();
     $forum_info['f_name'] = $r['f_name'];
     $forum_info['f_desc'] = $r['f_desc'];
     $forum_info['f_top_tmplt'] = $r['f_top_tmplt'];
     $forum_info['cid'] = $r['f_parentid'];
     $forum_info['cat_name'] = $r['cat_name'];
     $forum_info['fid'] = $r['f_id'];
     $forum_info['f_threads'] = $r['f_threads'];
     $forum_info['f_wiki_write_perm'] = $r['f_wiki_write_perm'];
     $forum_info['f_wiki_read_perm'] = $r['f_wiki_read_perm'];
     $forum_info['f_passworded'] = $r['f_passworded'];
     $WhoWhere['type'] = 'forum';
     $WhoWhere['where'] = 'cid' . $r['f_parentid'] . '|fid' . $r['f_id'] . '||awc-split||' . $forum_info['f_name'];
     $WhoWhere['perm'] = $forum_info['f_wiki_read_perm'];
     unset($r, $res);
     // check for Forums Subscriptions
     if ($awcUser->isLoggedIn and $this->cf_forumsubscrip == '1') {
         $m_forum_subsrib = array();
         $m_forum_subsrib = $awcUser->m_forum_subsrib;
         if (!empty($m_forum_subsrib)) {
             if (!array_key_exists($id, $m_forum_subsrib)) {
                 $word_subscribe = get_awcsforum_word('word_subscribe');
                 $options_menu = null;
             } else {
                 $word_subscribe = get_awcsforum_word('word_unsubscrib');
                 $options_menu = get_awcsforum_word('word_youraresubscribed');
                 if ($awcUser->m_forum_subsrib[$id] == '') {
                     $dbw = wfGetDB(DB_MASTER);
                     $awcUser->m_forum_subsrib[$id] = 'seen';
                     awcsforum_funcs::get_table_names(array('awc_f_mems', 'awc_f_watchforums'));
                     $sql = "UPDATE {$awc_tables['awc_f_watchforums']} f \r\r\n                                        JOIN {$awc_tables['awc_f_mems']} m\r\r\n                                        ON f.wtchf_mem_id=m.m_id \r\r\n                                        SET f.wtchf_sent=0, m.m_forum_subsrib='" . serialize($awcUser->m_forum_subsrib) . "' \r\r\n                                    WHERE f.wtchf_forum_id = {$id} AND f.wtchf_mem_id = {$awcUser->mId}";
                     $dbw->query($sql);
                 }
             }
         } else {
             $word_subscribe = get_awcsforum_word('word_subscribe');
             $options_menu = null;
         }
     }
     $ann_threads = '<form name="mod_form" enctype="multipart/form-data" action="' . awc_url . 'mod/" method="post">
                     <input name="todo" type="hidden" value="mod_thread">';
     # query for Announcement threads...
     $totalAnnocments = 0;
     $sql = "SELECT t.t_id,t.t_ann,t.t_pin,t.t_status,t.t_poll,t.t_name,t.t_starter,t.t_starterid,t.t_topics,t.t_hits,t.t_lastdate, t.t_lastuser, t.t_lastuserid, t.t_forumid \r\r\n\t\t\t\tFROM {$awc_tables['awc_f_anns']} a\r\r\n                INNER JOIN {$awc_tables['awc_f_threads']} t ON a.ann_id=t.t_id \r\r\n\t\t\t\tORDER BY t.t_lastdate DESC, t.t_name DESC ";
     $res = $this->rDB->query($sql);
     $a = null;
     $sa = null;
     $to_skin = array();
     while ($r = $this->rDB->fetchObject($res)) {
         $a++;
         if ($a == 1) {
             // create announcements header
             $to_skin['col_5_isSearch_forum_name'] = '';
             $to_skin['tr_id'] = 'id="annc"';
             $to_skin['first_col_name'] = get_awcsforum_word('announcement');
             $ann_threads .= $tplt->phase($word_headers, $to_skin, 'thread_list_header');
             unset($to_skin);
         }
         /*
          check if threads being looped are part of the current forum
          if so, count them for the "math" in the thread-display-limit
         */
         if ($r->forum_id == $id) {
             $totalAnnocments++;
         }
         $to_skin = $thread_tools->loop_thread_list($r);
         $ann_threads .= $tplt->phase($word, $to_skin, 'thread_list_rows');
         // unset($to_skin);
     }
     $this->rDB->freeResult($res);
     unset($r, $res);
     if ($a >= 1) {
         $ann_threads .= "</table><br />";
     }
     $can_read = $perm->can_read($forum_info['f_wiki_read_perm']);
     if (!$can_read) {
         global $wgOut;
         $wgOut->addHTML($ann_threads);
         return awcs_forum_error('no_forum_read_perm');
     }
     if (!isset($awcUser->pw)) {
         $awcUser->pw[0] = 0;
     }
     if ($perm->is_password($forum_info['f_passworded']) and !in_array($id, $awcUser->pw)) {
         // show Announcement's then password field
         Set_AWC_Forum_SubTitle($forum_info['f_name'], $forum_info['f_desc'], '');
         Set_AWC_Forum_BreadCrumbs('<a href="' . awc_url . 'sc/id' . $forum_info['cid'] . '">' . $forum_info['cat_name'] . '</a>');
         Set_AWC_Forum_BreadCrumbs(strtr($forum_info['f_name'], "_", " "), true);
         global $wgOut;
         $password_field = '<br /><hr />' . get_awcsforum_word('forum_passworded') . '<hr />';
         $password_field .= '</form><form action="' . awc_url . 'fpw" method="post"  enctype="multipart/form-data">
             <input name="fid" type="hidden" value="' . $id . '">
             <input name="pw" type="password" size="20">
             <input type="submit" value="' . get_awcsforum_word('submit') . '">
             </form><br /><br />';
         $wgOut->addHTML($ann_threads . $password_field);
         return;
     }
     $post_button = '';
     if ($awcUser->canPost and $perm->can_post($forum_info['f_wiki_write_perm'])) {
         $word1['start_new_thread'] = str_replace(' ', '&nbsp;', get_awcsforum_word('start_new_thread'));
         $info['url'] = awc_url . 'post/todo_new_t/id' . $id;
         $post_button = $tplt->phase($word1, $info, 'forum:start_new_thread');
     }
     $tplt->kill('forum:start_new_thread');
     // add templet after anncoments... todo
     if (strlen($forum_info['f_top_tmplt']) > 1) {
         $ann_threads .= add_tmpl_to_skin($forum_info['f_top_tmplt']);
     }
     $TotalPosts = intval($forum_info['f_threads'] - $totalAnnocments);
     $total['TotalPosts'] = $TotalPosts;
     $limit = GetLimit($total, 'cat');
     if ($awcUser->isLoggedIn and $this->cf_forumsubscrip == '1') {
         $info['url'] = awc_url . 'post/fsub/id' . $id;
         $word1['subscrib'] = $word_subscribe;
         $sb = $tplt->phase($word1, $info, 'forum:subscrib_to_forum');
     } else {
         $sb = null;
     }
     unset($word1);
     $tplt->kill('forum:subscrib_to_forum');
     // add tplt, start new thread button, subscrib, page jumps
     $info['jump'] = $LimitJump_top;
     $info['new_thread_button'] = $post_button;
     $info['subscrib_button'] = $sb;
     $html = $tplt->phase('', $info, 'thread_list_header_menu', true);
     unset($info);
     $info['col_5_isSearch_forum_name'] = '';
     $info['tr_id'] = null;
     $info['first_col_name'] = UserPerm >= 2 ? '<INPUT type="checkbox" name="checkbox_toggle" onChange="return checkall_toggle(\'mod_form\',\'tID[]\', this.checked)">  ' : null;
     $info['first_col_name'] .= get_awcsforum_word('thread_title');
     $html .= $tplt->phase($word_headers, $info, 'thread_list_header', true);
     unset($info, $word_headers);
     $limit = str_replace('LIMIT ', '', $limit);
     $limitSPLIT = explode(',', $limit);
     $offset = isset($limitSPLIT[0]) ? $limitSPLIT[0] : 0;
     $limit = isset($limitSPLIT[1]) ? $limitSPLIT[1] : 15;
     $t_forumid = (int) $id;
     $sql = $this->rDB->selectSQLText(array('awc_f_threads'), array('t_id,t_ann,t_pin,t_status,t_poll,t_name,t_starter,t_starterid,t_topics,t_hits,t_lastdate,t_lastuser,t_lastuserid'), "t_forumid={$t_forumid} AND t_ann=0", __METHOD__, array('OFFSET' => $offset, 'LIMIT' => $limit, 'ORDER BY' => 't_pin DESC, t_lastdate DESC,t_name'));
     $res = $this->rDB->query($sql);
     $isThreads = false;
     $thread_tools->thread_count = 0;
     while ($r = $this->rDB->fetchObject($res)) {
         $isThreads = true;
         $to_tplt = $thread_tools->loop_thread_list($r);
         $html .= $tplt->phase($word, $to_tplt, 'thread_list_rows');
     }
     $this->rDB->freeResult($res);
     unset($r, $res);
     $tplt->kill('thread_list_rows');
     if (!$isThreads) {
         //  keep this here...
         $tplt->add_tplts(array("'empty_forum'"), true);
         $info['new_thread_button'] = $post_button;
         $info['subscrib_button'] = $sb;
         $word['empty_forum'] = get_awcsforum_word('word_emptyforum');
         $html = $tplt->phase($word, $info, 'empty_forum', true);
     }
     $html .= "</table>";
     $e = array();
     $e['fID'] = $id;
     $e['cID'] = $forum_info['cid'];
     Set_AWC_Forum_SubTitle($forum_info['f_name'], $forum_info['f_desc'], $e);
     unset($e);
     Set_AWC_Forum_BreadCrumbs('<a href="' . awc_url . 'sc/id' . $forum_info['cid'] . '">' . $forum_info['cat_name'] . '</a>');
     $BreadCrumb = Set_AWC_Forum_BreadCrumbs(strtr($forum_info['f_name'], "_", " "), true);
     #
     #
     $info['page_jumps'] = $LimitJump_bot ? $LimitJump_bot : null;
     if (UserPerm >= 2) {
         $words['ann'] = get_awcsforum_word('thread_makeAnnouncement');
         $words['unann'] = get_awcsforum_word('thread_UnMakeAnnouncement');
         $mod['ann'] = UserPerm >= 10 ? $tplt->phase($words, '', 'thread_listing_mod_drop_ann') : null;
         $tplt->kill('thread_listing_mod_drop_ann');
         $words['pinn'] = get_awcsforum_word('pinned_word');
         $words['unpinn'] = get_awcsforum_word('pinnedUn_word');
         $words['lock'] = get_awcsforum_word('lockThread_word');
         $words['unlock'] = get_awcsforum_word('lockThreadUn_word');
         $words['move'] = get_awcsforum_word('mod_movethread');
         $words['delete'] = get_awcsforum_word('delete');
         $words['mod_options'] = get_awcsforum_word('mod_post');
         $info['page_jumps'] = ' ' . $tplt->phase($words, $mod, 'thread_listing_mod_drop', true) . $info['page_jumps'];
         unset($words, $mod);
     }
     $info['BreadCrumb'] = $BreadCrumb;
     $html .= $tplt->phase($word, $info, 'bottom_page_jumps', true);
     return $ann_threads . $html . '</form>';
 }