コード例 #1
0
ファイル: Viewthread.php プロジェクト: knapnet/PHP-Fusion
 /**
  * Thread Class constructor - This builds all essential data on load.
  */
 public function __construct()
 {
     global $locale, $userdata, $settings, $forum_settings;
     // exit no.1
     if (!isset($_GET['thread_id']) && !isnum($_GET['thread_id'])) {
         redirect(INFUSIONS . 'forum/index.php');
     }
     $thread_data = \PHPFusion\Forums\Functions::get_thread($_GET['thread_id']);
     // fetch query and define iMOD
     if (!empty($thread_data)) {
         $thread_stat = self::get_thread_stats($_GET['thread_id']);
         // get post_count, lastpost_id, first_post_id.
         if ($thread_data['forum_type'] == 1) {
             redirect(INFUSIONS . 'forum/index.php');
         }
         if ($thread_stat['post_count'] < 1) {
             redirect(INFUSIONS . 'forum/index.php');
         }
         // Set meta
         add_to_meta($locale['forum_0000']);
         if ($thread_data['forum_description'] !== '') {
             add_to_meta('description', $thread_data['forum_description']);
         }
         if ($thread_data['forum_meta'] !== '') {
             add_to_meta('keywords', $thread_data['forum_meta']);
         }
         add_to_title($thread_data['thread_subject']);
         // Set Forum Breadcrumbs
         $this->forum_index = dbquery_tree(DB_FORUMS, 'forum_id', 'forum_cat');
         add_breadcrumb(array('link' => INFUSIONS . 'forum/index.php', 'title' => $locale['forum_0000']));
         forum_breadcrumbs($this->forum_index, $thread_data['forum_id']);
         add_breadcrumb(array('link' => INFUSIONS . 'forum/viewthread.php?forum_id=' . $thread_data['forum_id'] . '&amp;thread_id=' . $thread_data['thread_id'], 'title' => $thread_data['thread_subject']));
         $this->setThreadPermission($thread_data);
         // Sanitizes $_GETs
         $_GET['forum_id'] = $thread_data['forum_id'];
         /**
          * Generate User Tracked Buttons
          */
         $this->thread_info['buttons']['notify'] = array();
         if ($this->getThreadPermission("can_access")) {
             // only member can track the thread
             if ($thread_data['user_tracked']) {
                 $this->thread_info['buttons']['notify'] = array('link' => INFUSIONS . "forum/postify.php?post=off&amp;forum_id=" . $thread_data['forum_id'] . "&amp;thread_id=" . $thread_data['thread_id'], 'title' => $locale['forum_0174']);
             } else {
                 $this->thread_info['buttons']['notify'] = array('link' => INFUSIONS . "forum/postify.php?post=on&amp;forum_id=" . $thread_data['forum_id'] . "&amp;thread_id=" . $thread_data['thread_id'], 'title' => $locale['forum_0175']);
             }
         }
         /**
          * Generate Quick Reply Form
          */
         $qr_form = "";
         if ($this->getThreadPermission("can_reply") == TRUE && $thread_data['forum_quick_edit'] == TRUE) {
             $qr_form = "<!--sub_forum_thread-->\n";
             $form_url = INFUSIONS . "forum/viewthread.php?thread_id=" . $thread_data['thread_id'];
             $qr_form .= openform('quick_reply_form', 'post', $form_url, array('class' => 'm-b-20 m-t-20'));
             $qr_form .= "<h4 class='m-t-20 pull-left'>" . $locale['forum_0168'] . "</h4>\n";
             $qr_form .= form_textarea('post_message', $locale['forum_0601'], '', array('bbcode' => true, 'required' => true, 'autosize' => true, 'preview' => true, 'form_name' => 'quick_reply_form'));
             $qr_form .= "<div class='m-t-10 pull-right'>\n";
             $qr_form .= form_button('post_quick_reply', $locale['forum_0172'], $locale['forum_0172'], array('class' => 'btn-primary btn-sm m-r-10'));
             $qr_form .= "</div>\n";
             $qr_form .= "<div class='overflow-hide'>\n";
             $qr_form .= form_checkbox('post_smileys', $locale['forum_0169'], '', array('class' => 'm-b-0'));
             if (array_key_exists("user_sig", $userdata) && $userdata['user_sig']) {
                 $qr_form .= form_checkbox('post_showsig', $locale['forum_0170'], '1', array('class' => 'm-b-0'));
             }
             if ($forum_settings['thread_notify']) {
                 $qr_form .= form_checkbox('notify_me', $locale['forum_0171'], $thread_data['user_tracked'], array('class' => 'm-b-0'));
             }
             $qr_form .= "</div>\n";
             $qr_form .= closeform();
         }
         /**
          * Generate Poll Form
          */
         $poll = array();
         $poll_form = "";
         if ($this->getThreadPermission("can_access") && $thread_data['thread_poll'] == TRUE) {
             $poll_result = dbquery("SELECT\n\t\t\t\tpoll_opts.*, poll.forum_poll_title, poll.forum_poll_votes\n\t\t\t\tFROM " . DB_FORUM_POLL_OPTIONS . " poll_opts\n\t\t\t\tINNER JOIN " . DB_FORUM_POLLS . " poll using (thread_id)\n\t\t\t\tWHERE poll.thread_id='" . intval($thread_data['thread_id']) . "'\n\t\t\t\t");
             if (dbrows($poll_result) > 0) {
                 $i = 0;
                 // Construct poll data - model
                 while ($pdata = dbarray($poll_result)) {
                     if ($i == 0) {
                         $poll['forum_poll_title'] = $pdata['forum_poll_title'];
                         $poll['forum_poll_votes'] = $pdata['forum_poll_votes'];
                         $poll['forum_poll_max_options'] = dbrows($poll_result);
                     }
                     $poll['forum_poll_options'][$pdata['forum_poll_option_id']] = $pdata;
                     $i++;
                 }
                 // SQL cast poll vote
                 if (isset($_POST['poll_option']) && isnum($_POST['poll_option']) && $_POST['poll_option'] <= $poll['forum_poll_max_options']) {
                     if ($this->getThreadPermission("can_vote_poll") == TRUE) {
                         $pollInput['poll_option_id'] = stripinput($_POST['poll_option']);
                         global $defender;
                         if ($defender->safe()) {
                             dbquery("UPDATE " . DB_FORUM_POLL_OPTIONS . " SET forum_poll_option_votes=forum_poll_option_votes+1 WHERE thread_id='" . intval($thread_data['thread_id']) . "' AND forum_poll_option_id='" . intval($pollInput['poll_option_id']) . "'");
                             dbquery("UPDATE " . DB_FORUM_POLLS . " SET forum_poll_votes=forum_poll_votes+1 WHERE thread_id='" . intval($thread_data['thread_id']) . "'");
                             dbquery("INSERT INTO " . DB_FORUM_POLL_VOTERS . " (thread_id, forum_vote_user_id, forum_vote_user_ip, forum_vote_user_ip_type) VALUES ('" . $thread_data['thread_id'] . "', '" . $userdata['user_id'] . "', '" . USER_IP . "', '" . USER_IP_TYPE . "')");
                             addNotice('success', $locale['forum_0614']);
                             redirect(INFUSIONS . "forum/viewthread.php?forum_id=" . $thread_data['forum_id'] . "&thread_id=" . $thread_data['thread_id']);
                         } else {
                             addNotice("danger", "You are not eligible to cast a vote in the poll.");
                         }
                     }
                 }
                 $poll_form_start = "";
                 $poll_form_end = "";
                 if ($this->getThreadPermission("can_vote_poll")) {
                     $poll_form_start = openform("poll_vote_form", "post", INFUSIONS . "forum/viewthread.php?thread_id=" . $thread_data['thread_id']);
                     $poll_form_end = form_button('vote', $locale['forum_2010'], 'vote', array('class' => 'btn btn-sm btn-primary m-l-20 '));
                     $poll_form_end .= closeform();
                 }
                 // need to fix security.
                 if ($this->getThreadPermission("can_edit_poll")) {
                     $poll_form .= "<div class='pull-right btn-group'>\n";
                     $poll_form .= "<a class='btn btn-sm btn-default' href='" . INFUSIONS . "forum/viewthread.php?action=editpoll&forum_id=" . $thread_data['forum_id'] . "&thread_id=" . $thread_data['thread_id'] . "'>" . $locale['forum_0603'] . "</a>\n";
                     $poll_form .= "<a class='btn btn-sm btn-default' href='" . INFUSIONS . "forum/viewthread.php?action=deletepoll&forum_id=" . $thread_data['forum_id'] . "&thread_id=" . $thread_data['thread_id'] . "' onclick='confirm('" . $locale['forum_0616'] . "');'>" . $locale['delete'] . "</a>\n";
                     $poll_form .= "</div>\n";
                 }
                 $poll_form .= $poll_form_start;
                 $poll_form .= "<h3 class='strong m-b-10'><i class='fa fa-fw fa-pie-chart fa-lg'></i>" . $locale['forum_0377'] . " : " . $poll['forum_poll_title'] . "</h3>\n";
                 $poll_form .= "<ul class='p-l-20 p-t-0'>\n";
                 if (!empty($poll['forum_poll_options'])) {
                     $i = 1;
                     $vote_options = $poll['forum_poll_options'];
                     foreach ($vote_options as $poll_option) {
                         if ($this->getThreadPermission("can_vote_poll") == TRUE) {
                             $poll_form .= "<li><label for='opt-" . $i . "'><input id='opt-" . $i . "' type='radio' name='poll_option' value='" . $i . "' class='m-r-20'> <span class='m-l-10'>" . $poll_option['forum_poll_option_text'] . "</span>\n</label></li>\n";
                         } else {
                             $option_votes = $poll['forum_poll_votes'] ? number_format(100 / $poll['forum_poll_votes'] * $poll_option['forum_poll_option_votes']) : 0;
                             $poll_form .= progress_bar($option_votes, $poll_option['forum_poll_option_text'], '', '10px');
                         }
                         $i++;
                     }
                 }
                 $poll_form .= "</ul>\n";
                 $poll_form .= $poll_form_end;
             }
         }
         /**
          * Generate Attachment
          */
         $attachments = array();
         if ($this->getThreadPermission("can_download_attach") == TRUE) {
             $a_result = dbquery("SELECT * FROM " . DB_FORUM_ATTACHMENTS . " WHERE thread_id='" . intval($thread_data['thread_id']) . "' ORDER BY post_id ASC");
             if (dbrows($a_result) > 0) {
                 while ($a_data = dbarray($a_result)) {
                     if (file_exists(INFUSIONS . "forum/attachments/" . $a_data['attach_name'])) {
                         //$this->thread_info['attachments'][$a_data['post_id']][] = $a_data;
                         $attachments[$a_data['post_id']][] = $a_data;
                     }
                 }
             }
         }
         /**
          * Generate Mod Form
          */
         if (iMOD) {
             // need to wrap with issets?
             $mod = new Moderator();
             $mod->setForumId($thread_data['forum_id']);
             $mod->setThreadId($thread_data['thread_id']);
             $mod->set_modActions();
             /**
              * Thread moderation form template
              */
             $this->thread_info['mod_options'] = array('renew' => $locale['forum_0207'], 'delete' => $locale['forum_0201'], $thread_data['thread_locked'] ? "unlock" : "lock" => $thread_data['thread_locked'] ? $locale['forum_0203'] : $locale['forum_0202'], $thread_data['thread_sticky'] ? "nonsticky" : "sticky" => $thread_data['thread_sticky'] ? $locale['forum_0205'] : $locale['forum_0204'], 'move' => $locale['forum_0206']);
             $addition = isset($_GET['rowstart']) ? "&amp;rowstart=" . intval($_GET['rowstart']) : "";
             $this->thread_info['form_action'] = INFUSIONS . "forum/viewthread.php?thread_id=" . intval($thread_data['thread_id']) . $addition;
             $this->thread_info['open_post_form'] = openform('moderator_menu', 'post', $this->thread_info['form_action']);
             $this->thread_info['close_post_form'] = closeform();
             /*
             * <a id='check' class='btn button btn-sm btn-default text-dark' href='#' onclick=\"javascript:setChecked('mod_form','delete_post[]',1);return false;\">".$locale['forum_0080']."</a>\n
             						<a id='uncheck' class='btn button btn-sm btn-default text-dark' href='#' onclick=\"javascript:setChecked('mod_form','delete_post[]',0);return false;\">".$locale['forum_0081']."</a>\n
             */
             $this->thread_info['mod_form'] = "\n\t\t\t\t<div class='list-group-item'>\n\n\t\t\t\t\t<div class='btn-group m-r-10'>\n\n\t\t\t\t\t\t" . form_button("check_all", $locale['forum_0080'], $locale['forum_0080'], array('class' => 'btn-default btn-sm', "type" => "button")) . "\n\t\t\t\t\t\t" . form_button("check_none", $locale['forum_0081'], $locale['forum_0080'], array('class' => 'btn-default btn-sm', "type" => "button")) . "\n\t\t\t\t\t</div>\n\n\t\t\t\t\t" . form_button('move_posts', $locale['forum_0176'], $locale['forum_0176'], array('class' => 'btn-default btn-sm m-r-10')) . "\n\t\t\t\t\t" . form_button('delete_posts', $locale['forum_0177'], $locale['forum_0177'], array('class' => 'btn-default btn-sm')) . "\n\t\t\t\t\t<div class='pull-right'>\n\t\t\t\t\t\t" . form_button('go', $locale['forum_0208'], $locale['forum_0208'], array('class' => 'btn-default pull-right btn-sm m-t-0 m-l-10')) . "\n\t\t\t\t\t\t" . form_select('step', '', '', array('options' => $this->thread_info['mod_options'], 'placeholder' => $locale['forum_0200'], 'width' => '250px', 'allowclear' => 1, 'class' => 'm-b-0 m-t-5', 'inline' => 1)) . "\n\t\t\t\t\t</div>\n\n\t\t\t\t</div>\n";
             add_to_jquery("\n\t\t\t\t\$('#check_all').bind('click', function() {\n\t\t\t\t    var thread_posts = \$('#moderator_menu input:checkbox').prop('checked', true);\n\t\t\t\t});\n\t\t\t\t\$('#check_none').bind('click', function() {\n\t\t\t\t    var thread_posts = \$('#moderator_menu input:checkbox').prop('checked', false); });\n\t\t\t\t");
         }
         $this->thread_info += array("thread" => $thread_data, "thread_id" => $thread_data['thread_id'], "forum_id" => $thread_data['forum_id'], "forum_cat" => isset($_GET['forum_cat']) && verify_forum($_GET['forum_cat']) ? $_GET['forum_cat'] : 0, "forum_branch" => isset($_GET['forum_branch']) && verify_forum($_GET['forum_branch']) ? $_GET['forum_branch'] : 0, "forum_link" => array("link" => INFUSIONS . "forum/index.php?viewforum&amp;forum_id=" . $thread_data['forum_id'] . "&amp;forum_cat=" . $thread_data['forum_cat'] . "&amp;forum_branch=" . $thread_data['forum_branch'], "title" => $thread_data['forum_name']), "post_id" => isset($_GET['post_id']) && verify_post($_GET['post_id']) ? $_GET['post_id'] : 0, "pid" => isset($_GET['pid']) && isnum($_GET['pid']) ? $_GET['pid'] : 0, "section" => isset($_GET['section']) ? $_GET['section'] : '', "forum_moderators" => Functions::parse_forumMods($thread_data['forum_mods']), "max_post_items" => $thread_stat['post_count'], "post_firstpost" => $thread_stat['first_post_id'], "post_lastpost" => $thread_stat['last_post_id'], "posts_per_page" => $forum_settings['posts_per_page'], "threads_per_page" => $forum_settings['threads_per_page'], "lastvisited" => isset($userdata['user_lastvisit']) && isnum($userdata['user_lastvisit']) ? $userdata['user_lastvisit'] : time(), "allowed_post_filters" => array('oldest', 'latest', 'high'), "attachtypes" => explode(",", $forum_settings['forum_attachtypes']), "quick_reply_form" => $qr_form, "poll_form" => $poll_form, "post-filters" => "", 'mod_options' => array(), 'form_action' => '', 'open_post_form' => '', 'close_post_form' => '', 'mod_form' => '');
         /**
          * Generate All Thread Buttons
          */
         $this->thread_info['buttons'] += array("print" => array("link" => BASEDIR . "print.php?type=F&amp;item_id=" . $thread_data['thread_id'] . "&amp;rowstart=" . $_GET['rowstart'], "title" => $locale['forum_0178']), "newthread" => $this->getThreadPermission("can_post") == TRUE ? array("link" => INFUSIONS . "forum/newthread.php?forum_id=" . $thread_data['forum_id'], "title" => $locale['forum_0264']) : array(), "reply" => $this->getThreadPermission("can_reply") == TRUE ? array("link" => INFUSIONS . "forum/viewthread.php?action=reply&amp;forum_id=" . $thread_data['forum_id'] . "&amp;thread_id=" . $thread_data['thread_id'], "title" => $locale['forum_0360']) : array(), "poll" => $this->getThreadPermission("can_create_poll") == TRUE ? array("link" => INFUSIONS . "forum/viewthread.php?action=newpoll&amp;forum_id=" . $thread_data['forum_id'] . "&amp;thread_id=" . $thread_data['thread_id'], "title" => $locale['forum_0366']) : array());
         /**
          * Generate Post Filters
          */
         $this->thread_info['post-filters'][0] = array('value' => INFUSIONS . 'forum/viewthread.php?thread_id=' . $thread_data['thread_id'] . '&amp;section=oldest', 'locale' => $locale['forum_0180']);
         $this->thread_info['post-filters'][1] = array('value' => INFUSIONS . 'forum/viewthread.php?thread_id=' . $thread_data['thread_id'] . '&amp;section=latest', 'locale' => $locale['forum_0181']);
         if ($this->getThreadPermission("can_rate") == TRUE) {
             $this->thread_info['allowed-post-filters'][2] = 'high';
             $this->thread_info['post-filters'][2] = array('value' => INFUSIONS . 'forum/viewthread.php?thread_id=' . $this->thread_info['thread_id'] . '&amp;section=high', 'locale' => $locale['forum_0182']);
         }
         $this->handle_quick_reply();
         $this->get_thread_post();
         //self::set_ThreadJs();
         // execute in the end.
         //self::set_ForumPostDB();
     } else {
         redirect(FORUM . 'index.php');
     }
 }
コード例 #2
0
ファイル: forum.php プロジェクト: php-fusion/PHP-Fusion
 /**
  * Executes forum
  */
 public function set_ForumInfo()
 {
     $forum_settings = $this->get_forum_settings();
     $userdata = fusion_get_userdata();
     $locale = fusion_get_locale("", FORUM_LOCALE);
     $_GET['forum_id'] = isset($_GET['forum_id']) && verify_forum($_GET['forum_id']) ? intval($_GET['forum_id']) : 0;
     // security boot due to insufficient access level
     if (isset($_GET['viewforum']) && empty($_GET['forum_id'])) {
         redirect(INFUSIONS . 'forum/index.php');
     }
     if (stristr($_SERVER['PHP_SELF'], 'forum_id')) {
         if ($_GET['section'] == 'latest') {
             redirect(INFUSIONS . 'forum/index.php?section=latest');
         }
         if ($_GET['section'] == 'mypost') {
             redirect(INFUSIONS . 'forum/index.php?section=mypost');
         }
         if ($_GET['section'] == 'tracked') {
             redirect(INFUSIONS . 'forum/index.php?section=tracked');
         }
     }
     // Xss sanitization
     $this->forum_info = array('forum_id' => isset($_GET['forum_id']) ? $_GET['forum_id'] : 0, 'parent_id' => isset($_GET['parent_id']) && verify_forum($_GET['parent_id']) ? $_GET['parent_id'] : 0, 'forum_branch' => isset($_GET['forum_branch']) && verify_forum($_GET['forum_branch']) ? $_GET['forum_branch'] : 0, 'new_thread_link' => '', 'lastvisited' => isset($userdata['user_lastvisit']) && isnum($userdata['user_lastvisit']) ? $userdata['user_lastvisit'] : time(), 'posts_per_page' => $forum_settings['posts_per_page'], 'threads_per_page' => $forum_settings['threads_per_page'], 'forum_index' => dbquery_tree(DB_FORUMS, 'forum_id', 'forum_cat'), 'threads' => array(), 'section' => isset($_GET['section']) ? $_GET['section'] : 'thread');
     // Set Max Rows -- XSS
     $this->forum_info['forum_max_rows'] = dbcount("('forum_id')", DB_FORUMS, (multilang_table("FO") ? "forum_language='" . LANGUAGE . "' AND" : '') . "\n\t\tforum_cat='" . $this->forum_info['parent_id'] . "' AND " . groupaccess('forum_access') . "");
     // Sanitize Globals
     $_GET['rowstart'] = isset($_GET['rowstart']) && $_GET['rowstart'] <= $this->forum_info['forum_max_rows'] ? $_GET['rowstart'] : 0;
     $this->ext = isset($this->forum_info['parent_id']) && isnum($this->forum_info['parent_id']) ? "&amp;parent_id=" . $this->forum_info['parent_id'] : '';
     add_to_title($locale['global_200'] . $locale['forum_0000']);
     add_breadcrumb(array('link' => INFUSIONS . 'forum/index.php', 'title' => $locale['forum_0000']));
     $this->forum_breadcrumbs($this->forum_info['forum_index']);
     // Set Meta data
     if ($this->forum_info['forum_id'] > 0) {
         $meta_sql = "SELECT forum_meta, forum_description FROM " . DB_FORUMS . "\n            WHERE forum_id='" . intval($this->forum_info['forum_id']) . "'";
         $meta_result = dbquery($meta_sql);
         if (dbrows($meta_result) > 0) {
             $meta_data = dbarray($meta_result);
             if (!empty($meta_data['forum_description'])) {
                 set_meta('description', $meta_data['forum_description']);
             }
             if (!empty($meta_data['forum_meta'])) {
                 set_meta('keywords', $meta_data['forum_meta']);
             }
         }
     }
     // Additional Sections in Index View
     if (isset($_GET['section'])) {
         switch ($_GET['section']) {
             case 'participated':
                 include FORUM_SECTIONS . "participated.php";
                 add_to_title($locale['global_201'] . $locale['global_024']);
                 add_breadcrumb(array('link' => FORUM . "index.php?section=participated", 'title' => $locale['global_024']));
                 set_meta("description", $locale['global_024']);
                 break;
             case 'latest':
                 include FORUM_SECTIONS . "latest.php";
                 add_to_title($locale['global_201'] . $locale['global_021']);
                 add_breadcrumb(array('link' => FORUM . "index.php?section=latest", 'title' => $locale['global_021']));
                 set_meta("description", $locale['global_021']);
                 break;
             case 'tracked':
                 include FORUM_SECTIONS . "tracked.php";
                 add_to_title($locale['global_201'] . $locale['global_056']);
                 add_breadcrumb(array('link' => FORUM . "index.php?section=tracked", 'title' => $locale['global_056']));
                 set_meta("description", $locale['global_056']);
                 break;
             case "unanswered":
                 include FORUM_SECTIONS . "unanswered.php";
                 add_to_title($locale['global_201'] . $locale['global_027']);
                 add_breadcrumb(array('link' => INFUSIONS . "forum/index.php?section=unanswered", 'title' => $locale['global_027']));
                 set_meta("description", $locale['global_027']);
                 break;
             case "unsolved":
                 include FORUM_SECTIONS . "unsolved.php";
                 add_to_title($locale['global_201'] . $locale['global_028']);
                 add_breadcrumb(array('link' => INFUSIONS . "forum/index.php?section=unsolved", 'title' => $locale['global_028']));
                 set_meta("description", $locale['global_028']);
                 break;
             default:
                 redirect(FORUM);
         }
     } else {
         // Viewforum view
         if (!empty($this->forum_info['forum_id']) && isset($this->forum_info['parent_id']) && isset($_GET['viewforum'])) {
             // @todo: turn this into ajax filtration to cut down SEO design pattern
             $this->forum_info['filter'] = $this->filter()->get_FilterInfo();
             // Forum SQL
             $forum_sql = "\n                SELECT f.*,\n                f2.forum_name 'forum_cat_name',\n\t\t\t\tt.thread_id, t.thread_lastpost, t.thread_lastpostid, t.thread_subject,\n\t\t\t\tp.post_message,\n\t\t\t\tu.user_id, u.user_name, u.user_status, u.user_avatar,\n\t\t\t\tmin(p2.post_datestamp) 'first_post_datestamp'\n\t\t\t\tFROM " . DB_FORUMS . " f\n\t\t\t\t# subforums\n\t\t\t\tLEFT JOIN " . DB_FORUMS . " f2 ON f.forum_cat = f2.forum_id\n\t\t\t\t# thread info\n\t\t\t\tLEFT JOIN " . DB_FORUM_THREADS . " t ON t.forum_id = f.forum_id AND " . groupaccess('f.forum_access') . "\n\t\t\t\t# just last post\n\t\t\t\tLEFT JOIN " . DB_FORUM_POSTS . " p on p.thread_id = t.thread_id and p.post_id = t.thread_lastpostid\n\t\t\t\t# post info\n\t\t\t\tLEFT JOIN " . DB_FORUM_POSTS . " p2 ON p2.thread_id = t.thread_id\n\t\t\t\t# just last post user\n\t\t\t\tLEFT JOIN " . DB_USERS . " u ON f.forum_lastuser=u.user_id\n\t\t\t\t" . (multilang_table("FO") ? "WHERE f.forum_language='" . LANGUAGE . "' AND" : "WHERE") . " " . groupaccess('f.forum_access') . "\n\t\t\t\tAND f.forum_id='" . intval($this->forum_info['forum_id']) . "' OR f.forum_cat='" . intval($this->forum_info['forum_id']) . "'\n\t\t\t\tOR f.forum_branch='" . intval($this->forum_info['forum_branch']) . "'\n\t\t\t\tGROUP BY f.forum_id ORDER BY forum_cat ASC\n                ";
             $result = dbquery($forum_sql);
             $refs = array();
             // define what a row is
             $row_array = array('forum_new_status' => '', 'last_post' => '', 'forum_icon' => '', 'forum_icon_lg' => '', 'forum_moderators' => '', 'forum_link' => array('link' => '', 'title' => ''), 'forum_description' => '', 'forum_postcount_word' => '', 'forum_threadcount_word' => '');
             if (dbrows($result) > 0) {
                 while ($row = dbarray($result) and checkgroup($row['forum_access'])) {
                     // Calculate Forum New Status
                     $newStatus = "";
                     $forum_match = "\\|" . $row['forum_lastpost'] . "\\|" . $row['forum_id'];
                     $last_visited = isset($userdata['user_lastvisit']) && isnum($userdata['user_lastvisit']) ? $userdata['user_lastvisit'] : time();
                     if ($row['forum_lastpost'] > $last_visited) {
                         if (iMEMBER && ($row['forum_lastuser'] !== $userdata['user_id'] || !preg_match("({$forum_match}\\.|{$forum_match}\$)", $userdata['user_threads']))) {
                             $newStatus = "<span class='forum-new-icon'><i title='" . $locale['forum_0260'] . "' class='" . self::get_forumIcons('new') . "'></i></span>";
                         }
                     }
                     // Calculate lastpost information
                     $lastPostInfo = array();
                     if (!empty($row['forum_lastpostid'])) {
                         $last_post = array('avatar' => '', 'avatar_src' => $row['user_avatar'] && file_exists(IMAGES . 'avatars/' . $row['user_avatar']) && !is_dir(IMAGES . 'avatars/' . $row['user_avatar']) ? IMAGES . 'avatars/' . $row['user_avatar'] : '', 'message' => fusion_first_words(parseubb(parsesmileys($row['post_message'])), 10), 'profile_link' => profile_link($row['forum_lastuser'], $row['user_name'], $row['user_status']), 'time' => timer($row['forum_lastpost']), 'date' => showdate("forumdate", $row['forum_lastpost']), 'thread_link' => INFUSIONS . "forum/viewthread.php?forum_id=" . $row['forum_id'] . "&amp;thread_id=" . $row['thread_id'], 'post_link' => INFUSIONS . "forum/viewthread.php?forum_id=" . $row['forum_id'] . "&amp;thread_id=" . $row['thread_id'] . "&amp;pid=" . $row['thread_lastpostid'] . "#post_" . $row['thread_lastpostid']);
                         if ($forum_settings['forum_last_post_avatar']) {
                             $last_post['avatar'] = display_avatar($row, '30px', '', '', 'img-rounded');
                         }
                         $lastPostInfo = $last_post;
                     }
                     /**
                      * Default system icons - why do i need this? Why not let themers decide?
                      */
                     switch ($row['forum_type']) {
                         case '1':
                             $forum_icon = "<i class='" . self::get_forumIcons('forum') . " fa-fw m-r-10'></i>";
                             $forum_icon_lg = "<i class='" . self::get_forumIcons('forum') . " fa-3x fa-fw m-r-10'></i>";
                             break;
                         case '2':
                             $forum_icon = "<i class='" . self::get_forumIcons('thread') . " fa-fw m-r-10'></i>";
                             $forum_icon_lg = "<i class='" . self::get_forumIcons('thread') . " fa-3x fa-fw m-r-10'></i>";
                             break;
                         case '3':
                             $forum_icon = "<i class='" . self::get_forumIcons('link') . " fa-fw m-r-10'></i>";
                             $forum_icon_lg = "<i class='" . self::get_forumIcons('link') . " fa-3x fa-fw m-r-10'></i>";
                             break;
                         case '4':
                             $forum_icon = "<i class='" . self::get_forumIcons('question') . " fa-fw m-r-10'></i>";
                             $forum_icon_lg = "<i class='" . self::get_forumIcons('question') . " fa-3x fa-fw m-r-10'></i>";
                             break;
                         default:
                             $forum_icon = "";
                             $forum_icon_lg = "";
                     }
                     $mods = new Moderator();
                     $_row = array_merge($row_array, $row, array("forum_type" => $row['forum_type'], "forum_moderators" => $mods::parse_forum_mods($row['forum_mods']), "forum_new_status" => $newStatus, "forum_link" => array("link" => FORUM . "index.php?viewforum&amp;forum_id=" . $row['forum_id'] . "&amp;parent_id=" . $row['forum_cat'], "title" => $row['forum_name']), "forum_description" => nl2br(parseubb($row['forum_description'])), "forum_postcount_word" => format_word($row['forum_postcount'], $locale['fmt_post']), "forum_threadcount_word" => format_word($row['forum_threadcount'], $locale['fmt_thread']), "last_post" => $lastPostInfo, "forum_icon" => $forum_icon, "forum_icon_lg" => $forum_icon_lg, "forum_image" => $row['forum_image'] && file_exists(FORUM . "images/" . $row['forum_image']) ? $row['forum_image'] : ""));
                     $this->forum_info['forum_moderators'] = $_row['forum_moderators'];
                     // child hierarchy data.
                     $thisref =& $refs[$_row['forum_id']];
                     $thisref = $_row;
                     if ($_row['forum_cat'] == $this->forum_info['parent_id']) {
                         $this->forum_info['item'][$_row['forum_id']] =& $thisref;
                         // will push main item out.
                     } else {
                         $refs[$_row['forum_cat']]['child'][$_row['forum_id']] =& $thisref;
                     }
                     /**
                      * The current forum
                      */
                     if ($row['forum_id'] == $this->forum_info['forum_id']) {
                         require_once INCLUDES . "mimetypes_include.php";
                         $this->forum_info['forum_type'] = $row['forum_type'];
                         $mods::define_forum_mods($row);
                         // do the full string of checks for forums access
                         $this->setForumPermission($row);
                         // Generate New thread link
                         if ($this->getForumPermission("can_post") && $row['forum_type'] > 1) {
                             $this->forum_info['new_thread_link'] = FORUM . "newthread.php?forum_id=" . $row['forum_id'];
                         }
                         // Not a category
                         if ($row['forum_type'] !== '1') {
                             $filter_sql = $this->filter()->get_filterSQL();
                             $thread_info = $this->thread(FALSE)->get_forum_thread($this->forum_info['forum_id'], array('condition' => $filter_sql['condition'], 'order' => $filter_sql['order']));
                             $this->forum_info = array_merge_recursive($this->forum_info, $thread_info);
                         }
                     }
                 }
             } else {
                 redirect(INFUSIONS . 'forum/index.php');
             }
         } else {
             $this->forum_info['forums'] = self::get_forum();
             //Index view
         }
     }
 }
コード例 #3
0
ファイル: Forum.php プロジェクト: knapnet/PHP-Fusion
 public function set_ForumInfo()
 {
     global $forum_settings, $userdata, $locale;
     if (stristr($_SERVER['PHP_SELF'], 'forum_id')) {
         if ($_GET['section'] == 'latest') {
             redirect(INFUSIONS . 'forum/index.php?section=latest');
         }
         if ($_GET['section'] == 'mypost') {
             redirect(INFUSIONS . 'forum/index.php?section=mypost');
         }
         if ($_GET['section'] == 'tracked') {
             redirect(INFUSIONS . 'forum/index.php?section=tracked');
         }
     }
     // security boot due to insufficient access level
     if (isset($_GET['viewforum']) && !verify_forum($_GET['forum_id'])) {
         redirect(INFUSIONS . 'forum/index.php');
     }
     // Xss sanitization
     $this->forum_info = array('forum_id' => isset($_GET['forum_id']) ? $_GET['forum_id'] : 0, 'parent_id' => isset($_GET['parent_id']) && verify_forum($_GET['parent_id']) ? $_GET['parent_id'] : 0, 'forum_branch' => isset($_GET['forum_branch']) && verify_forum($_GET['forum_branch']) ? $_GET['forum_branch'] : 0, 'new_thread_link' => '', 'lastvisited' => isset($userdata['user_lastvisit']) && isnum($userdata['user_lastvisit']) ? $userdata['user_lastvisit'] : time(), 'posts_per_page' => $forum_settings['posts_per_page'], 'threads_per_page' => $forum_settings['threads_per_page'], 'forum_index' => dbquery_tree(DB_FORUMS, 'forum_id', 'forum_cat'), 'threads' => array(), 'section' => isset($_GET['section']) ? $_GET['section'] : 'thread');
     // Set Max Rows -- XSS
     $this->forum_info['forum_max_rows'] = dbcount("('forum_id')", DB_FORUMS, (multilang_table("FO") ? "forum_language='" . LANGUAGE . "' AND" : '') . "\n\t\tforum_cat='" . $this->forum_info['parent_id'] . "' AND " . groupaccess('forum_access') . "");
     // Sanitize Globals
     $_GET['forum_id'] = $this->forum_info['forum_id'];
     $_GET['rowstart'] = isset($_GET['rowstart']) && $_GET['rowstart'] <= $this->forum_info['forum_max_rows'] ? $_GET['rowstart'] : 0;
     $this->ext = isset($this->forum_info['parent_id']) && isnum($this->forum_info['parent_id']) ? "&amp;parent_id=" . $this->forum_info['parent_id'] : '';
     add_to_title($locale['global_200'] . $locale['forum_0000']);
     add_breadcrumb(array('link' => INFUSIONS . 'forum/index.php', 'title' => $locale['forum_0000']));
     forum_breadcrumbs($this->forum_info['forum_index']);
     // Set Meta data
     if ($this->forum_info['forum_id'] > 0) {
         $meta_result = dbquery("SELECT forum_meta, forum_description FROM " . DB_FORUMS . " WHERE forum_id='" . intval($this->forum_info['forum_id']) . "'");
         if (dbrows($meta_result) > 0) {
             $meta_data = dbarray($meta_result);
             if ($meta_data['forum_description'] !== '') {
                 set_meta('description', $meta_data['forum_description']);
             }
             if ($meta_data['forum_meta'] !== '') {
                 set_meta('keywords', $meta_data['forum_meta']);
             }
         }
     }
     // Additional Sections in Index View
     if (isset($_GET['section'])) {
         switch ($_GET['section']) {
             case 'participated':
                 include INFUSIONS . "forum/sections/participated.php";
                 add_to_title($locale['global_201'] . $locale['global_024']);
                 add_breadcrumb(array('link' => INFUSIONS . "forum/index.php?section=participated", 'title' => $locale['global_024']));
                 set_meta("description", $locale['global_024']);
                 break;
             case 'latest':
                 include INFUSIONS . "forum/sections/latest.php";
                 add_to_title($locale['global_201'] . $locale['global_021']);
                 add_breadcrumb(array('link' => INFUSIONS . "forum/index.php?section=latest", 'title' => $locale['global_021']));
                 set_meta("description", $locale['global_021']);
                 break;
             case 'tracked':
                 include INFUSIONS . "forum/sections/tracked.php";
                 add_to_title($locale['global_201'] . $locale['global_056']);
                 add_breadcrumb(array('link' => INFUSIONS . "forum/index.php?section=tracked", 'title' => $locale['global_056']));
                 set_meta("description", $locale['global_056']);
                 break;
             case "unanswered":
                 include INFUSIONS . "forum/sections/unanswered.php";
                 add_to_title($locale['global_201'] . $locale['global_027']);
                 add_breadcrumb(array('link' => INFUSIONS . "forum/index.php?section=unanswered", 'title' => $locale['global_027']));
                 set_meta("description", $locale['global_027']);
                 break;
             case "unsolved":
                 include INFUSIONS . "forum/sections/unsolved.php";
                 add_to_title($locale['global_201'] . $locale['global_028']);
                 add_breadcrumb(array('link' => INFUSIONS . "forum/index.php?section=unsolved", 'title' => $locale['global_028']));
                 set_meta("description", $locale['global_028']);
                 break;
             default:
                 redirect(FUSION_SELF);
         }
     } else {
         // Switch between view forum or forum index -- required: $_GET['viewforum']
         if ($this->forum_info['forum_id'] && isset($this->forum_info['parent_id']) && isset($_GET['viewforum'])) {
             /**
              * View Forum Additional Views - add Filter Initialization
              */
             $time = isset($_GET['time']) ? $_GET['time'] : '';
             $type = isset($_GET['type']) ? $_GET['type'] : '';
             $sort = isset($_GET['sort']) ? $_GET['sort'] : '';
             $order = isset($_GET['order']) ? $_GET['order'] : '';
             $timeCol = '';
             $typeCol = '';
             if ($time) {
                 $time_array = array('today' => strtotime('today'), '2days' => strtotime('-2 day'), '1week' => strtotime('-1 week'), '2week' => strtotime('-2 week'), '1month' => strtotime('-2 month'), '2month' => strtotime('-2 month'), '3month' => strtotime('-2 month'), '6month' => strtotime('-6 month'), '1year' => strtotime('-1 year'));
                 $time_stop = '';
                 foreach ($time_array as $key => $value) {
                     if ($time == $key) {
                         $time_stop = prev($time_array);
                         break;
                     }
                 }
                 if ($time !== 'today') {
                     $timeCol = "AND ((post_datestamp >= '" . $time_array[$time] . "' OR t.thread_lastpost >= '" . $time_array[$time] . "') AND (post_datestamp <= '" . $time_stop . "' OR t.thread_lastpost <= '" . $time_stop . "')) ";
                 } else {
                     $timeCol = "AND (post_datestamp >= '" . $time_array[$time] . "' OR t.thread_lastpost >= '" . $time_array[$time] . "') ";
                 }
             }
             if ($type) {
                 $type_array = array('all' => '', 'discussions' => "AND (a1.attach_name IS NULL or a1.attach_name='') AND (a2.attach_name IS NULL or a2.attach_name='') AND (forum_poll_title IS NULL or forum_poll_title='')", 'attachments' => "AND a1.attach_name !='' OR a2.attach_name !='' AND (forum_poll_title IS NULL or forum_poll_title='')", 'poll' => "AND (a1.attach_name IS NULL or a1.attach_name='') AND (a2.attach_name IS NULL or a2.attach_name='') AND forum_poll_title !=''", 'solved' => "AND t.thread_answered = '1'", 'unsolved' => "AND t.thread_answered = '0'");
                 $typeCol = $type_array[$type];
             }
             $sortCol = "ORDER BY t.thread_lastpost ";
             $orderCol = 'ASC';
             if ($sort) {
                 $sort_array = array('author' => 't.thread_author', 'time' => 't.thread_lastpost', 'subject' => 't.thread_subject', 'reply' => 't.thread_postcount', 'view' => 't.thread_views');
                 $sortCol = "ORDER BY " . $sort_array[$sort] . " ";
             }
             if ($order) {
                 $order_array = array('ascending' => 'ASC', 'descending' => 'DESC');
                 $orderCol = $order_array[$order];
             }
             $sql_condition = $timeCol . $typeCol;
             $sql_order = $sortCol . $orderCol;
             // Filter Links
             $timeExt = isset($_GET['time']) ? "&amp;time=" . $_GET['time'] : '';
             $typeExt = isset($_GET['type']) ? "&amp;type=" . $_GET['type'] : '';
             $sortExt = isset($_GET['sort']) ? "&amp;sort=" . $_GET['sort'] : '';
             $orderExt = isset($_GET['order']) ? "&amp;order=" . $_GET['order'] : '';
             $baseLink = INFUSIONS . 'forum/index.php?viewforum&amp;forum_id=' . $_GET['forum_id'] . '' . (isset($_GET['parent_id']) ? '&amp;parent_id=' . $_GET['parent_id'] . '' : '');
             $timeLink = $baseLink . $typeExt . $sortExt . $orderExt;
             $this->forum_info['filter']['time'] = array($locale['forum_3006'] => INFUSIONS . 'forum/index.php?viewforum&amp;forum_id=' . $_GET['forum_id'] . '' . (isset($_GET['parent_id']) ? '&amp;parent_id=' . $_GET['parent_id'] . '' : ''), $locale['forum_3007'] => $timeLink . '&amp;time=today', $locale['forum_3008'] => $timeLink . '&amp;time=2days', $locale['forum_3009'] => $timeLink . '&amp;time=1week', $locale['forum_3010'] => $timeLink . '&amp;time=2week', $locale['forum_3011'] => $timeLink . '&amp;time=1month', $locale['forum_3012'] => $timeLink . '&amp;time=2month', $locale['forum_3013'] => $timeLink . '&amp;time=3month', $locale['forum_3014'] => $timeLink . '&amp;time=6month', $locale['forum_3015'] => $timeLink . '&amp;time=1year');
             $typeLink = $baseLink . $timeExt . $sortExt . $orderExt;
             $this->forum_info['filter']['type'] = array($locale['forum_3000'] => $typeLink . '&amp;type=all', $locale['forum_3001'] => $typeLink . '&amp;type=discussions', $locale['forum_3002'] => $typeLink . '&amp;type=attachments', $locale['forum_3003'] => $typeLink . '&amp;type=poll', $locale['forum_3004'] => $typeLink . '&amp;type=solved', $locale['forum_3005'] => $typeLink . '&amp;type=unsolved');
             $sortLink = $baseLink . $timeExt . $typeExt . $orderExt;
             $this->forum_info['filter']['sort'] = array($locale['forum_3016'] => $sortLink . '&amp;sort=author', $locale['forum_3017'] => $sortLink . '&amp;sort=time', $locale['forum_3018'] => $sortLink . '&amp;sort=subject', $locale['forum_3019'] => $sortLink . '&amp;sort=reply', $locale['forum_3020'] => $sortLink . '&amp;sort=view');
             $orderLink = $baseLink . $timeExt . $typeExt . $sortExt;
             $this->forum_info['filter']['order'] = array($locale['forum_3021'] => $orderLink . '&amp;order=descending', $locale['forum_3022'] => $orderLink . '&amp;order=ascending');
             // Forum SQL
             $result = dbquery("SELECT f.*, f2.forum_name AS forum_cat_name,\n\t\t\t\tt.thread_id, t.thread_lastpost, t.thread_lastpostid, t.thread_subject,\n\t\t\t\tcount(t.thread_id) as forum_threadcount, p.post_message,\n\t\t\t\tu.user_id, u.user_name, u.user_status, u.user_avatar\n\t\t\t\tFROM " . DB_FORUMS . " f\n\t\t\t\tLEFT JOIN " . DB_FORUMS . " f2 ON f.forum_cat = f2.forum_id\n\t\t\t\tLEFT JOIN " . DB_FORUM_THREADS . " t ON t.forum_id = f.forum_id\n\t\t\t\tLEFT JOIN " . DB_FORUM_POSTS . " p on p.thread_id = t.thread_id and p.post_id = t.thread_lastpostid\n\t\t\t\tLEFT JOIN " . DB_USERS . " u ON f.forum_lastuser=u.user_id  ## -- redo this part -- ##\n\t\t\t\t" . (multilang_table("FO") ? "WHERE f.forum_language='" . LANGUAGE . "' AND" : "WHERE") . " " . groupaccess('f.forum_access') . "\n\t\t\t\tAND f.forum_id='" . intval($this->forum_info['forum_id']) . "' OR f.forum_cat='" . intval($this->forum_info['forum_id']) . "' OR f.forum_branch='" . intval($this->forum_info['forum_branch']) . "'\n\t\t\t\tgroup by f.forum_id ORDER BY forum_cat ASC\n\t\t\t\t");
             $refs = array();
             if (dbrows($result) > 0) {
                 while ($row = dbarray($result) and checkgroup($row['forum_access'])) {
                     // Calculate Forum New Status
                     $newStatus = "";
                     $forum_match = "\\|" . $row['forum_lastpost'] . "\\|" . $row['forum_id'];
                     $last_visited = isset($userdata['user_lastvisit']) && isnum($userdata['user_lastvisit']) ? $userdata['user_lastvisit'] : time();
                     if ($row['forum_lastpost'] > $last_visited) {
                         if (iMEMBER && ($row['forum_lastuser'] !== $userdata['user_id'] || !preg_match("({$forum_match}\\.|{$forum_match}\$)", $userdata['user_threads']))) {
                             $newStatus = "<span class='forum-new-icon'><i title='" . $locale['forum_0260'] . "' class='" . Functions::get_forumIcons('new') . "'></i></span>";
                         }
                     }
                     // Calculate lastpost information
                     $lastPostInfo = array();
                     if ($row['forum_lastpostid']) {
                         $last_post = array('avatar' => '', 'avatar_src' => $row['user_avatar'] && file_exists(IMAGES . 'avatars/' . $row['user_avatar']) && !is_dir(IMAGES . 'avatars/' . $row['user_avatar']) ? IMAGES . 'avatars/' . $row['user_avatar'] : '', 'message' => fusion_first_words(parseubb(parsesmileys($row['post_message'])), 10), 'profile_link' => profile_link($row['forum_lastuser'], $row['user_name'], $row['user_status']), 'time' => timer($row['forum_lastpost']), 'date' => showdate("forumdate", $row['forum_lastpost']), 'thread_link' => INFUSIONS . "forum/viewthread.php?forum_id=" . $row['forum_id'] . "&amp;thread_id=" . $row['thread_id'], 'post_link' => INFUSIONS . "forum/viewthread.php?forum_id=" . $row['forum_id'] . "&amp;thread_id=" . $row['thread_id'] . "&amp;pid=" . $row['thread_lastpostid'] . "#post_" . $row['thread_lastpostid']);
                         if ($forum_settings['forum_last_post_avatar']) {
                             $last_post['avatar'] = display_avatar($row, '30px', '', '', 'img-rounded');
                         }
                         $lastPostInfo = $last_post;
                     }
                     /**
                      * Default system icons - why do i need this? Why not let themers decide?
                      */
                     switch ($row['forum_type']) {
                         case '1':
                             $forum_icon = "<i class='" . Functions::get_forumIcons('forum') . " fa-fw m-r-10'></i>";
                             $forum_icon_lg = "<i class='" . Functions::get_forumIcons('forum') . " fa-3x fa-fw m-r-10'></i>";
                             break;
                         case '2':
                             $forum_icon = "<i class='" . Functions::get_forumIcons('thread') . " fa-fw m-r-10'></i>";
                             $forum_icon_lg = "<i class='" . Functions::get_forumIcons('thread') . " fa-3x fa-fw m-r-10'></i>";
                             break;
                         case '3':
                             $forum_icon = "<i class='" . Functions::get_forumIcons('link') . " fa-fw m-r-10'></i>";
                             $forum_icon_lg = "<i class='" . Functions::get_forumIcons('link') . " fa-3x fa-fw m-r-10'></i>";
                             break;
                         case '4':
                             $forum_icon = "<i class='" . Functions::get_forumIcons('question') . " fa-fw m-r-10'></i>";
                             $forum_icon_lg = "<i class='" . Functions::get_forumIcons('question') . " fa-3x fa-fw m-r-10'></i>";
                             break;
                         default:
                             $forum_icon = "";
                             $forum_icon_lg = "";
                     }
                     $row += array("forum_moderators" => Functions::parse_forumMods($row['forum_mods']), "forum_new_status" => $newStatus, "forum_link" => array("link" => INFUSIONS . "forum/index.php?viewforum&amp;forum_id=" . $row['forum_id'] . "&amp;parent_id=" . $row['forum_cat'], "title" => $row['forum_name']), "forum_description" => nl2br(parseubb($row['forum_description'])), "forum_postcount_word" => format_word($row['forum_postcount'], $locale['fmt_post']), "forum_threadcount_word" => format_word($row['forum_threadcount'], $locale['fmt_thread']), "last_post" => $lastPostInfo, "forum_icon" => $forum_icon, "forum_icon_lg" => $forum_icon_lg, "forum_image" => $row['forum_image'] && file_exists(FORUM . "images/" . $row['forum_image']) ? $row['forum_image'] : "");
                     $this->forum_info['forum_moderators'] = $row['forum_moderators'];
                     // child hierarchy data.
                     $thisref =& $refs[$row['forum_id']];
                     $thisref = $row;
                     if ($row['forum_cat'] == $this->forum_info['parent_id']) {
                         $this->forum_info['item'][$row['forum_id']] =& $thisref;
                         // will push main item out.
                     } else {
                         $refs[$row['forum_cat']]['child'][$row['forum_id']] =& $thisref;
                     }
                     /**
                      * The current forum
                      */
                     if ($row['forum_id'] == $this->forum_info['forum_id']) {
                         require_once INCLUDES . "mimetypes_include.php";
                         define_forum_mods($row);
                         // do the full string of checks for forums access
                         $this->setForumPermission($row);
                         // Generate Links
                         if ($this->getForumPermission("can_post")) {
                             $this->forum_info['new_thread_link'] = INFUSIONS . "forum/newthread.php?forum_id=" . $row['forum_id'];
                         }
                         /**
                          * Get threads with filter conditions
                          */
                         //xss
                         $count = dbarray(dbquery("SELECT\n\t\t\t\t\t\t\t\tcount(t.thread_id) 'thread_max_rows',\n\t\t\t\t\t\t\t\tcount(a1.attach_id) 'attach_image',\n\t\t\t\t\t\t\t\tcount(a2.attach_id) 'attach_files'\n\n\t\t\t\t\t\t\t\tFROM " . DB_FORUM_THREADS . " t\n\t\t\t\t\t\t\t\tLEFT JOIN " . DB_FORUMS . " tf ON tf.forum_id = t.forum_id\n\t\t\t\t\t\t\t\tINNER JOIN " . DB_USERS . " tu1 ON t.thread_author = tu1.user_id\n\t\t\t\t\t\t\t\tLEFT JOIN " . DB_USERS . " tu2 ON t.thread_lastuser = tu2.user_id #issue 323\n\t\t\t\t\t\t\t\tLEFT JOIN " . DB_FORUM_POSTS . " p1 ON p1.thread_id = t.thread_id and p1.post_id = t.thread_lastpostid\n\t\t\t\t\t\t\t\tLEFT JOIN " . DB_FORUM_POLLS . " p ON p.thread_id = t.thread_id\n\t\t\t\t\t\t\t\tLEFT JOIN " . DB_FORUM_VOTES . " v ON v.thread_id = t.thread_id AND p1.post_id = v.post_id\n\t\t\t\t\t\t\t\tLEFT JOIN " . DB_FORUM_ATTACHMENTS . " a1 on a1.thread_id = t.thread_id AND a1.attach_mime IN ('" . implode(",", img_mimeTypes()) . "')\n\t\t\t\t\t\t\t\tLEFT JOIN " . DB_FORUM_ATTACHMENTS . " a2 on a2.thread_id = t.thread_id AND a2.attach_mime NOT IN ('" . implode(",", img_mimeTypes()) . "')\n\t\t\t\t\t\t\t\tWHERE t.forum_id='" . $this->forum_info['forum_id'] . "' AND t.thread_hidden='0' AND " . groupaccess('tf.forum_access') . " {$sql_condition}\n\t\t\t\t\t\t\t\t##GROUP BY t.thread_id {$sql_order}\n\t\t\t\t\t\t"));
                         $this->forum_info['thread_max_rows'] = $count['thread_max_rows'];
                         if ($this->forum_info['thread_max_rows'] > 0) {
                             $this->forum_info['threads']['pagenav'] = "";
                             $this->forum_info['threads']['pagenav2'] = "";
                             // anti-XSS filtered rowstart
                             $_GET['thread_rowstart'] = isset($_GET['thread_rowstart']) && isnum($_GET['thread_rowstart']) && $_GET['thread_rowstart'] <= $this->forum_info['thread_max_rows'] ? $_GET['thread_rowstart'] : 0;
                             $t_result = dbquery("\n                                SELECT t.*, tu1.user_name AS author_name, tu1.user_status AS author_status, tu1.user_avatar as author_avatar,\n\t\t\t\t\t\t\t\ttu2.user_name AS last_user_name, tu2.user_status AS last_user_status, tu2.user_avatar AS last_user_avatar,\n\t\t\t\t\t\t\t\tp1.post_datestamp, p1.post_message,\n\t\t\t\t\t\t\t\tp.forum_poll_title,\n\t\t\t\t\t\t\t\tcount(v.post_id) AS vote_count,\n\t\t\t\t\t\t\t\ta1.attach_name, a1.attach_id,\n\t\t\t\t\t\t\t\ta2.attach_name, a2.attach_id,\n\t\t\t\t\t\t\t\tcount(a1.attach_mime) 'attach_image',\n\t\t\t\t\t\t\t\tcount(a2.attach_mime) 'attach_files'\n\t\t\t\t\t\t\t\tFROM " . DB_FORUM_THREADS . " t\n\t\t\t\t\t\t\t\tLEFT JOIN " . DB_FORUMS . " tf ON tf.forum_id = t.forum_id\n\t\t\t\t\t\t\t\tINNER JOIN " . DB_USERS . " tu1 ON t.thread_author = tu1.user_id\n\t\t\t\t\t\t\t\tLEFT JOIN " . DB_USERS . " tu2 ON t.thread_lastuser = tu2.user_id #issue 323\n\t\t\t\t\t\t\t\tLEFT JOIN " . DB_FORUM_POSTS . " p1 ON p1.thread_id = t.thread_id and p1.post_id = t.thread_lastpostid\n\t\t\t\t\t\t\t\tLEFT JOIN " . DB_FORUM_POLLS . " p ON p.thread_id = t.thread_id\n\t\t\t\t\t\t\t\tLEFT JOIN " . DB_FORUM_VOTES . " v ON v.thread_id = t.thread_id AND p1.post_id = v.post_id\n\t\t\t\t\t\t\t\tLEFT JOIN " . DB_FORUM_ATTACHMENTS . " a1 on a1.thread_id = t.thread_id AND a1.attach_mime IN ('" . implode(",", img_mimeTypes()) . "')\n\t\t\t\t\t\t\t\tLEFT JOIN " . DB_FORUM_ATTACHMENTS . " a2 on a2.thread_id = t.thread_id AND a2.attach_mime NOT IN ('" . implode(",", img_mimeTypes()) . "')\n\t\t\t\t\t\t\t\tWHERE t.forum_id='" . $this->forum_info['forum_id'] . "' AND t.thread_hidden='0' AND " . groupaccess('tf.forum_access') . " {$sql_condition}\n\t\t\t\t\t\t\t\tGROUP BY t.thread_id {$sql_order} LIMIT " . intval($_GET['thread_rowstart']) . ", " . $this->forum_info['threads_per_page']);
                             $thread_rows = dbrows($t_result);
                             if ($thread_rows > 0) {
                                 while ($threads = dbarray($t_result)) {
                                     $icon = "";
                                     $match_regex = $threads['thread_id'] . "\\|" . $threads['thread_lastpost'] . "\\|" . $threads['forum_id'];
                                     if ($threads['thread_lastpost'] > $this->forum_info['lastvisited']) {
                                         if (iMEMBER && ($threads['thread_lastuser'] == $userdata['user_id'] || preg_match("(^\\.{$match_regex}\$|\\.{$match_regex}\\.|\\.{$match_regex}\$)", $userdata['user_threads']))) {
                                             $icon = "<i class='" . get_forumIcons('thread') . "' title='" . $locale['forum_0261'] . "'></i>";
                                         } else {
                                             $icon = "<i class='" . get_forumIcons('new') . "' title='" . $locale['forum_0260'] . "'></i>";
                                         }
                                     }
                                     $author = array('user_id' => $threads['thread_author'], 'user_name' => $threads['author_name'], 'user_status' => $threads['author_status'], 'user_avatar' => $threads['author_avatar']);
                                     $lastuser = array('user_id' => $threads['thread_lastuser'], 'user_name' => $threads['last_user_name'], 'user_status' => $threads['last_user_status'], 'user_avatar' => $threads['last_user_avatar']);
                                     $threads += array("thread_link" => array("link" => INFUSIONS . "forum/viewthread.php?thread_id=" . $threads['thread_id'], "title" => $threads['thread_subject']), "forum_type" => $row['forum_type'], "thread_pages" => makepagenav(0, $forum_settings['posts_per_page'], $threads['thread_postcount'], 3, FORUM . "viewthread.php?thread_id=" . $threads['thread_id'] . "&amp;"), "thread_icons" => array('lock' => $threads['thread_locked'] ? "<i class='" . get_forumIcons('lock') . "' title='" . $locale['forum_0263'] . "'></i>" : '', 'sticky' => $threads['thread_sticky'] ? "<i class='" . get_forumIcons('sticky') . "' title='" . $locale['forum_0103'] . "'></i>" : '', 'poll' => $threads['thread_poll'] ? "<i class='" . get_forumIcons('poll') . "' title='" . $locale['forum_0314'] . "'></i>" : '', 'hot' => $threads['thread_postcount'] >= 20 ? "<i class='" . get_forumIcons('hot') . "' title='" . $locale['forum_0311'] . "'></i>" : '', 'reads' => $threads['thread_views'] >= 20 ? "<i class='" . get_forumIcons('reads') . "' title='" . $locale['forum_0311'] . "'></i>" : '', 'image' => $threads['attach_image'] > 0 ? "<i class='" . get_forumIcons('image') . "' title='" . $locale['forum_0313'] . "'></i>" : '', 'file' => $threads['attach_files'] > 0 ? "<i class='" . get_forumIcons('file') . "' title='" . $locale['forum_0312'] . "'></i>" : '', 'icon' => $icon), "thread_starter" => $locale['forum_0006'] . timer($threads['post_datestamp']) . " " . $locale['by'] . " " . profile_link($author['user_id'], $author['user_name'], $author['user_status']) . "</span>", "thread_author" => $author, "thread_last" => array('avatar' => display_avatar($lastuser, '30px', '', '', ''), 'profile_link' => profile_link($lastuser['user_id'], $lastuser['user_name'], $lastuser['user_status']), 'time' => $threads['post_datestamp'], 'post_message' => parseubb(parsesmileys($threads['post_message'])), "formatted" => "<div class='pull-left'>" . display_avatar($lastuser, '30px', '', '', '') . "</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class='overflow-hide'>" . $locale['forum_0373'] . " <span class='forum_profile_link'>" . profile_link($lastuser['user_id'], $lastuser['user_name'], $lastuser['user_status']) . "</span><br/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . timer($threads['post_datestamp']) . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div>"));
                                     //if ($threads['thread_status']['reads']) $threads['thread_status']['icon'] = $threads['thread_status']['reads'];
                                     //if ($threads['thread_status']['hot']) $threads['thread_status']['icon'] = $threads['thread_status']['hot'];
                                     //if ($threads['thread_status']['sticky']) $threads['thread_status']['icon'] = $threads['thread_status']['sticky'];
                                     //if ($threads['thread_status']['lock']) $threads['thread_status']['icon'] = $threads['thread_status']['lock'];
                                     // Threads Customized Output
                                     /*
                                     										$attach_image = 0;
                                     										$attach_file = 0;
                                     										$a_result = dbquery("SELECT attach_id, attach_mime FROM ".DB_FORUM_ATTACHMENTS." WHERE thread_id ='".$threads['thread_id']."'");
                                     										if (dbrows($a_result) > 0) {
                                     											require_once INCLUDES."mimetypes_include.php";
                                     											while ($adata = dbarray($a_result)) {
                                     												if (in_array($adata['attach_mime'], img_mimeTypes())) {
                                     													$attach_image = $attach_image+1;
                                     												} else {
                                     													$attach_file = $attach_file+1;
                                     												}
                                     											}
                                     										}*/
                                     if ($threads['thread_sticky']) {
                                         $this->forum_info['threads']['sticky'][$threads['thread_id']] = $threads;
                                     } else {
                                         $this->forum_info['threads']['item'][$threads['thread_id']] = $threads;
                                     }
                                 }
                             }
                             if ($this->forum_info['thread_max_rows'] > $this->forum_info['threads_per_page']) {
                                 $this->forum_info['threads']['pagenav'] = makepagenav($_GET['thread_rowstart'], $this->forum_info['threads_per_page'], $this->forum_info['thread_max_rows'], 3, clean_request("", array("thread_rowstart"), FALSE) . "&amp;", "thread_rowstart");
                                 $this->forum_info['threads']['pagenav2'] = makepagenav($_GET['thread_rowstart'], $this->forum_info['threads_per_page'], $this->forum_info['thread_max_rows'], 3, clean_request("", array("thread_rowstart"), FALSE) . "&amp;", "thread_rowstart", TRUE);
                             }
                         }
                     }
                 }
             } else {
                 redirect(INFUSIONS . 'forum/index.php');
             }
         } else {
             $this->forum_info['forums'] = Functions::get_forum();
         }
     }
 }
コード例 #4
0
ファイル: threads.php プロジェクト: php-fusion/PHP-Fusion
 /**
  * Thread Class constructor - This builds all essential data on load.
  */
 public function set_threadInfo()
 {
     if (!isset($_GET['thread_id']) && !isnum($_GET['thread_id'])) {
         redirect(INFUSIONS . 'forum/index.php');
     }
     $forum_settings = $this->get_forum_settings();
     $locale = fusion_get_locale("", FORUM_LOCALE);
     $userdata = fusion_get_userdata();
     // Download acceptable types for Forum
     $this->thread_data = self::get_thread($_GET['thread_id']);
     // fetch query and define iMOD
     if (!empty($this->thread_data)) {
         $thread_stat = self::get_thread_stats($_GET['thread_id']);
         // get post_count, lastpost_id, first_post_id.
         if ($this->thread_data['forum_type'] == 1) {
             if (fusion_get_settings("site_seo")) {
                 redirect(fusion_get_settings("siteurl") . "infusions/forum/index.php");
             }
             redirect(INFUSIONS . 'forum/index.php');
         }
         if ($thread_stat['post_count'] < 1) {
             if (fusion_get_settings("site_seo")) {
                 redirect(fusion_get_settings("siteurl") . "infusions/forum/index.php");
             }
             redirect(INFUSIONS . 'forum/index.php');
         }
         // Set meta
         add_to_title($this->thread_data['thread_subject']);
         add_to_meta($locale['forum_0000']);
         if ($this->thread_data['forum_description'] !== '') {
             add_to_meta('description', $this->thread_data['forum_description']);
         }
         if ($this->thread_data['forum_meta'] !== '') {
             add_to_meta('keywords', $this->thread_data['forum_meta']);
         }
         // Set Forum Breadcrumbs
         $forum_index = dbquery_tree(DB_FORUMS, 'forum_id', 'forum_cat');
         add_breadcrumb(array('link' => INFUSIONS . 'forum/index.php', 'title' => $locale['forum_0000']));
         $this->forum_breadcrumbs($forum_index, $this->thread_data['forum_id']);
         add_breadcrumb(array('link' => INFUSIONS . 'forum/viewthread.php?forum_id=' . $this->thread_data['forum_id'] . '&amp;thread_id=' . $this->thread_data['thread_id'], 'title' => $this->thread_data['thread_subject']));
         $this->setThreadPermission();
         // Sanitizes $_GETs
         $_GET['forum_id'] = intval($this->thread_data['forum_id']);
         /**
          * Generate User Tracked Buttons
          */
         $this->thread_info['buttons']['notify'] = array();
         if ($this->getThreadPermission("can_access")) {
             // only member can track the thread
             if ($this->thread_data['user_tracked']) {
                 $this->thread_info['buttons']['notify'] = array('link' => INFUSIONS . "forum/postify.php?post=off&amp;forum_id=" . $this->thread_data['forum_id'] . "&amp;thread_id=" . $this->thread_data['thread_id'], 'title' => $locale['forum_0174']);
             } else {
                 $this->thread_info['buttons']['notify'] = array('link' => INFUSIONS . "forum/postify.php?post=on&amp;forum_id=" . $this->thread_data['forum_id'] . "&amp;thread_id=" . $this->thread_data['thread_id'], 'title' => $locale['forum_0175']);
             }
         }
         $this->thread_info['thread'] = $this->thread_data;
         /**
          * Generate Quick Reply Form
          */
         $qr_form = "";
         if ($this->getThreadPermission("can_reply") == TRUE && $this->thread_data['forum_quick_edit'] == TRUE) {
             $qr_form = QuickReply::display_quickReply($this->thread_data);
         }
         /**
          * Generate Poll Form
          */
         $poll = new Poll($this->thread_info);
         $poll_form = $poll->generate_poll($this->thread_data);
         /**
          * Generate Attachment
          */
         $attach = new Attachment($this->thread_info);
         $attachments = $attach::get_attachments($this->thread_data);
         /**
          * Generate Mod Form
          */
         if (iMOD) {
             $this->moderator()->setForumId($this->thread_data['forum_id']);
             $this->moderator()->setThreadId($this->thread_data['thread_id']);
             $this->moderator()->set_modActions();
             /**
              * Thread moderation form template
              */
             $addition = isset($_GET['rowstart']) ? "&amp;rowstart=" . intval($_GET['rowstart']) : "";
             $this->thread_info['form_action'] = INFUSIONS . "forum/viewthread.php?thread_id=" . intval($this->thread_data['thread_id']) . $addition;
             $this->thread_info['open_post_form'] = openform('moderator_menu', 'post', $this->thread_info['form_action']);
             $this->thread_info['mod_options'] = array('renew' => $locale['forum_0207'], 'delete' => $locale['forum_0201'], $this->thread_data['thread_locked'] ? "unlock" : "lock" => $this->thread_data['thread_locked'] ? $locale['forum_0203'] : $locale['forum_0202'], $this->thread_data['thread_sticky'] ? "nonsticky" : "sticky" => $this->thread_data['thread_sticky'] ? $locale['forum_0205'] : $locale['forum_0204'], 'move' => $locale['forum_0206']);
             $this->thread_info['close_post_form'] = closeform();
             $this->thread_info['mod_form'] = "\n\t\t\t\t<div class='list-group-item'>\n\n\t\t\t\t\t<div class='btn-group m-r-10'>\n\n\t\t\t\t\t\t" . form_button("check_all", $locale['forum_0080'], $locale['forum_0080'], array('class' => 'btn-default btn-sm', "type" => "button")) . "\n\t\t\t\t\t\t" . form_button("check_none", $locale['forum_0081'], $locale['forum_0080'], array('class' => 'btn-default btn-sm', "type" => "button")) . "\n\t\t\t\t\t</div>\n\n\t\t\t\t\t" . form_button('move_posts', $locale['forum_0176'], $locale['forum_0176'], array('class' => 'btn-default btn-sm m-r-10')) . "\n\t\t\t\t\t" . form_button('delete_posts', $locale['forum_0177'], $locale['forum_0177'], array('class' => 'btn-default btn-sm')) . "\n\t\t\t\t\t<div class='pull-right'>\n\t\t\t\t\t\t" . form_button('go', $locale['forum_0208'], $locale['forum_0208'], array('class' => 'btn-default pull-right btn-sm m-t-0 m-l-10')) . "\n\t\t\t\t\t\t" . form_select('step', '', '', array('options' => $this->thread_info['mod_options'], 'placeholder' => $locale['forum_0200'], 'width' => '250px', 'allowclear' => TRUE, 'class' => 'm-b-0 m-t-5', 'inline' => TRUE)) . "\n\t\t\t\t\t</div>\n\n\t\t\t\t</div>\n";
             add_to_jquery("\n\t\t\t\t\$('#check_all').bind('click', function() {\n\t\t\t\t    var thread_posts = \$('#moderator_menu input:checkbox').prop('checked', true);\n\t\t\t\t});\n\t\t\t\t\$('#check_none').bind('click', function() {\n\t\t\t\t    var thread_posts = \$('#moderator_menu input:checkbox').prop('checked', false); });\n\t\t\t\t");
         }
         $this->thread_info += array("thread" => $this->thread_data, "thread_id" => $this->thread_data['thread_id'], "forum_id" => $this->thread_data['forum_id'], 'thread_tags' => $this->thread_data['thread_tags'], 'thread_tags_display' => '', "forum_cat" => isset($_GET['forum_cat']) && verify_forum($_GET['forum_cat']) ? $_GET['forum_cat'] : 0, "forum_branch" => isset($_GET['forum_branch']) && verify_forum($_GET['forum_branch']) ? $_GET['forum_branch'] : 0, "forum_link" => array("link" => INFUSIONS . "forum/index.php?viewforum&amp;forum_id=" . $this->thread_data['forum_id'] . "&amp;forum_cat=" . $this->thread_data['forum_cat'] . "&amp;forum_branch=" . $this->thread_data['forum_branch'], "title" => $this->thread_data['forum_name']), "thread_attachments" => $attachments, "post_id" => isset($_GET['post_id']) && verify_post($_GET['post_id']) ? $_GET['post_id'] : 0, "pid" => isset($_GET['pid']) && isnum($_GET['pid']) ? $_GET['pid'] : 0, "section" => isset($_GET['section']) ? $_GET['section'] : '', "forum_moderators" => $this->moderator()->parse_forum_mods($this->thread_data['forum_mods']), "max_post_items" => $thread_stat['post_count'], "post_firstpost" => $thread_stat['first_post_id'], "post_lastpost" => $thread_stat['last_post_id'], "posts_per_page" => $forum_settings['posts_per_page'], "threads_per_page" => $forum_settings['threads_per_page'], "lastvisited" => isset($userdata['user_lastvisit']) && isnum($userdata['user_lastvisit']) ? $userdata['user_lastvisit'] : time(), "allowed_post_filters" => array('oldest', 'latest', 'high'), "attachtypes" => explode(",", $forum_settings['forum_attachtypes']), "quick_reply_form" => $qr_form, "poll_form" => $poll_form, "post-filters" => "", 'mod_options' => array(), 'form_action' => '', 'open_post_form' => '', 'close_post_form' => '', 'mod_form' => '');
         //print_p($this->thread_info);
         if (!empty($this->thread_info['thread_tags'])) {
             $this->thread_info['thread_tags_display'] = $this->tag(FALSE)->display_thread_tags($this->thread_info['thread_tags']);
         }
         /**
          * Generate All Thread Buttons
          */
         $this->thread_info['buttons'] += array("print" => array("link" => BASEDIR . "print.php?type=F&amp;item_id=" . $this->thread_data['thread_id'] . "&amp;rowstart=" . $_GET['rowstart'], "title" => $locale['forum_0178']), "newthread" => $this->getThreadPermission("can_post") == TRUE ? array("link" => INFUSIONS . "forum/newthread.php?forum_id=" . $this->thread_data['forum_id'], "title" => $locale['forum_0264']) : array(), "reply" => $this->getThreadPermission("can_reply") == TRUE ? array("link" => INFUSIONS . "forum/viewthread.php?action=reply&amp;forum_id=" . $this->thread_data['forum_id'] . "&amp;thread_id=" . $this->thread_data['thread_id'], "title" => $locale['forum_0360']) : array(), "poll" => $this->getThreadPermission("can_create_poll") == TRUE ? array("link" => INFUSIONS . "forum/viewthread.php?action=newpoll&amp;forum_id=" . $this->thread_data['forum_id'] . "&amp;thread_id=" . $this->thread_data['thread_id'], "title" => $locale['forum_0366']) : array());
         /**
          * Generate Post Filters
          */
         $this->thread_info['post-filters'][0] = array('value' => INFUSIONS . 'forum/viewthread.php?thread_id=' . $this->thread_data['thread_id'] . '&amp;section=oldest', 'locale' => $locale['forum_0180']);
         $this->thread_info['post-filters'][1] = array('value' => INFUSIONS . 'forum/viewthread.php?thread_id=' . $this->thread_data['thread_id'] . '&amp;section=latest', 'locale' => $locale['forum_0181']);
         if ($this->getThreadPermission("can_rate") == TRUE) {
             $this->thread_info['allowed-post-filters'][2] = 'high';
             $this->thread_info['post-filters'][2] = array('value' => INFUSIONS . 'forum/viewthread.php?thread_id=' . $this->thread_info['thread_id'] . '&amp;section=high', 'locale' => $locale['forum_0182']);
         }
         $this->handle_quick_reply();
         $this->get_thread_post();
         //self::set_ThreadJs();
         // execute in the end.
     } else {
         redirect(FORUM . 'index.php');
     }
 }