Beispiel #1
0
        } else {
            unset($pageinfo['goto']);
            $pageinfo['p'] = $threadinfo['lastpostid'];
            exec_header_redirect(fetch_seo_url('thread|js', $threadinfo, $pageinfo, null, null, true) . "#post{$threadinfo['lastpostid']}");
        }
        break;
        // *********************************************************************************
}
// end switch($vbulletin->GPC['goto'])
// *********************************************************************************
// workaround for header redirect issue from forms with enctype in IE
// (use a scrollIntoView javascript call in the <body> onload event)
$onload = '';
// *********************************************************************************
// set $perpage
$perpage = sanitize_maxposts($vbulletin->GPC['perpage']);
// *********************************************************************************
// set post order
if ($vbulletin->userinfo['postorder'] == 0) {
    $postorder = '';
} else {
    $postorder = 'DESC';
}
// *********************************************************************************
// get thread info
$thread = verify_id('thread', $threadid, 1, 1);
$threadinfo =& $thread;
($hook = vBulletinHook::fetch_hook('showthread_getinfo')) ? eval($hook) : false;
// *********************************************************************************
// check for visible / deleted thread
if (!$thread['visible'] and !can_moderate($thread['forumid'], 'canmoderateposts') or $thread['isdeleted'] and !can_moderate($thread['forumid'])) {
Beispiel #2
0
	exec_header_redirect('printthread.php?' . $vbulletin->session->vars['sessionurl_js'] . "t=$threadinfo[pollid]");
}

// check if there is a forum password and if so, ensure the user has it set
verify_forum_password($foruminfo['forumid'], $foruminfo['password']);

// split thread over pages if necessary
$countposts = $db->query_first_slave("
	SELECT COUNT(*) AS total
	FROM " . TABLE_PREFIX . "post AS post
	WHERE threadid=$threadinfo[threadid] AND visible=1
");
$totalposts = $countposts['total'];

$vbulletin->GPC['perpage'] = sanitize_maxposts($vbulletin->GPC['perpage']);
$maxperpage = sanitize_maxposts(-1);

if ($vbulletin->GPC['pagenumber'] < 1)
{
	$vbulletin->GPC['pagenumber'] = 1;
}

$startat = ($vbulletin->GPC['pagenumber'] - 1) * $vbulletin->GPC['perpage'];

$pagenav = construct_page_nav(
	$vbulletin->GPC['pagenumber'],
	$vbulletin->GPC['perpage'],
	$totalposts,
	'printthread.php?' . $vbulletin->session->vars['sessionurl'] . "t=$threadinfo[threadid]",
	'&amp;pp=' . $vbulletin->GPC['perpage']
);
function process_thread_array($thread, $lastread = -1, $allowicons = -1, $fetchavatar = false)
{
    global $vbphrase, $foruminfo, $vbulletin;
    global $newthreads, $dotthreads, $perpage, $ignore, $show;
    static $pperpage, $perm_cache;
    if ($pperpage == 0) {
        // lets calculate posts per page
        // the following code should be left just in case we plan to use this function in showthread at some point
        if (THIS_SCRIPT != 'showthread') {
            $pperpage = sanitize_maxposts();
        } else {
            $pperpage = sanitize_maxposts($perpage);
        }
    }
    // init value for the inline moderation checkbox
    $thread['checkbox_value'] = 0;
    if (can_moderate($thread['forumid'], 'caneditthreads') or $thread['open'] and $thread['postuserid'] == $vbulletin->userinfo['userid'] and $forumperms = fetch_permissions($thread['forumid']) and $forumperms & $vbulletin->bf_ugp_forumpermissions['caneditpost'] and (!$vbulletin->options['editthreadtitlelimit'] or $thread['dateline'] + $vbulletin->options['editthreadtitlelimit'] * 60 > TIMENOW)) {
        $thread['title_editable'] = true;
        $show['ajax_js'] = true;
    }
    if ($thread['open'] != 10 and (can_moderate($thread['forumid'], 'canopenclose') or $thread['postuserid'] == $vbulletin->userinfo['userid'] and $forumperms = fetch_permissions($thread['forumid']) and $forumperms & $vbulletin->bf_ugp_forumpermissions['canopenclose'])) {
        $thread['openclose_editable'] = true;
        $show['ajax_js'] = true;
    }
    /*if ($thread['postuserid'] == $vbulletin->userinfo['userid'])
    	{
    		$forumperms = fetch_permissions($thread['forumid']);
    		if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canopenclose'])
    		{
    			$thread['openclose_editable'] .= "<div><strong>Own thread</strong></div>";
    		}
    	}*/
    if ($fetchavatar) {
        require_once DIR . '/includes/functions_user.php';
        $avatar = fetch_avatar_from_record($thread, true, 'userid', 'api_');
        $thread['avatarurl'] = $avatar[0];
        $avatarinfo = parse_subsstring_array($thread, 'api_');
        $avatarinfo['adminavatar'] = $avatarinfo['adminoptions'] & $vbulletin->bf_misc_adminoptions['adminavatar'];
        if (!isset($perm_cache["{$avatarinfo['userid']}"])) {
            $perm_cache["{$avatarinfo['userid']}"] = cache_permissions($avatarinfo, false);
        } else {
            $avatarinfo['permissions'] =& $perm_cache["{$avatarinfo['userid']}"];
        }
        if (empty($thread['avatarurl']) or $vbulletin->userinfo['userid'] > 0 and !$vbulletin->userinfo['showavatars'] or !$avatarinfo['avatarid'] and !($perm_cache["{$avatarinfo['userid']}"]['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canuseavatar']) and !$avatarinfo['adminavatar']) {
            $show['avatar'] = false;
        } else {
            $show['avatar'] = true;
        }
    }
    if ($allowicons == -1) {
        $allowicons = $vbulletin->forumcache["{$thread['forumid']}"]['options'] & $vbulletin->bf_misc_forumoptions['allowicons'];
    }
    if ($lastread == -1) {
        $lastread = $vbulletin->userinfo['lastvisit'];
    }
    $show['rexpires'] = $show['rmanage'] = $show['threadmoved'] = $show['paperclip'] = $show['unsubscribe'] = false;
    // thread forumtitle
    if (empty($thread['forumtitle'])) {
        $thread['forumtitle'] = $vbulletin->forumcache["{$thread['forumid']}"]['title'];
    }
    $thread['forumtitleclean'] = $vbulletin->forumcache["{$thread['forumid']}"]['title_clean'];
    // word wrap title
    if ($vbulletin->options['wordwrap'] != 0) {
        $thread['threadtitle'] = fetch_word_wrapped_string($thread['threadtitle']);
    }
    $thread['threadtitle'] = fetch_censored_text($thread['threadtitle']);
    if ($thread['prefixid']) {
        $thread['prefix_plain_html'] = htmlspecialchars_uni($vbphrase["prefix_{$thread['prefixid']}_title_plain"]);
        $thread['prefix_rich'] = $vbphrase["prefix_{$thread['prefixid']}_title_rich"];
    } else {
        $thread['prefix_plain_html'] = '';
        $thread['prefix_rich'] = '';
    }
    // format thread preview if there is one
    if ($ignore["{$thread['postuserid']}"]) {
        $thread['preview'] = '';
    } else {
        if (isset($thread['preview'])) {
            if ($vbulletin->options['threadpreview'] > 0) {
                $thread['preview'] = strip_quotes($thread['preview']);
                $thread['preview'] = htmlspecialchars_uni(fetch_censored_text(fetch_trimmed_title(strip_bbcode($thread['preview'], false, true, true, true), $vbulletin->options['threadpreview'])));
            } else {
                unset($thread['preview']);
            }
        }
    }
    // thread last reply date/time
    $thread['lastpostdate'] = vbdate($vbulletin->options['dateformat'], $thread['lastpost'], true);
    $thread['lastposttime'] = vbdate($vbulletin->options['timeformat'], $thread['lastpost']);
    // post reply date/time (for search results as posts mainly)
    if ($thread['postdateline']) {
        $thread['postdate'] = vbdate($vbulletin->options['dateformat'], $thread['postdateline'], true);
        $thread['posttime'] = vbdate($vbulletin->options['timeformat'], $thread['postdateline']);
    } else {
        $thread['postdate'] = '';
        $thread['posttime'] = '';
    }
    // get the thread starting date and time if applicable
    if ($thread['dateline']) {
        $thread['startdate'] = vbdate($vbulletin->options['dateformat'], $thread['dateline'], true);
        $thread['starttime'] = vbdate($vbulletin->options['timeformat'], $thread['dateline']);
    } else {
        $thread['startdate'] = '';
        $thread['starttime'] = '';
    }
    // non magical thread status
    if (2 == $thread['visible']) {
        $thread['status']['deleted'] = 'deleted';
    } else {
        if (!$thread['visible']) {
            $thread['status']['moderated'] = 'moderated';
        }
    }
    // thread not moved
    if ($thread['open'] != 10) {
        // allow ratings?
        if ($foruminfo['allowratings']) {
            // show votes?
            if ($thread['votenum'] and $thread['votenum'] >= $vbulletin->options['showvotes']) {
                $thread['voteavg'] = vb_number_format($thread['votetotal'] / $thread['votenum'], 2);
                $thread['rating'] = intval(round($thread['votetotal'] / $thread['votenum']));
            } else {
                $thread['rating'] = 0;
            }
        } else {
            $thread['rating'] = 0;
            $thread['votenum'] = 0;
        }
        // moderated thread?
        if (!$thread['visible']) {
            $thread['moderatedprefix'] = $vbphrase['moderated_thread_prefix'];
            $thread['checkbox_value'] += THREAD_FLAG_INVISIBLE;
        } else {
            $thread['moderatedprefix'] = '';
        }
        // deleted thread?
        if ($thread['visible'] == 2) {
            $thread['checkbox_value'] += THREAD_FLAG_DELETED;
            $thread['del_reason'] = fetch_censored_text($thread['del_reason']);
        }
        // sticky thread?
        if ($thread['sticky']) {
            $show['sticky'] = true;
            $thread['typeprefix'] = $vbphrase['sticky_thread_prefix'];
            $thread['checkbox_value'] += THREAD_FLAG_STICKY;
        } else {
            $show['sticky'] = false;
            $thread['typeprefix'] = '';
        }
        // thread contains poll?
        if ($thread['pollid'] != 0) {
            $thread['typeprefix'] .= $vbphrase['poll_thread_prefix'];
            $thread['checkbox_value'] += THREAD_FLAG_POLL;
        }
        // multipage nav
        $thread['totalposts'] = $thread['replycount'] + 1;
        $total =& $thread['totalposts'];
        if (($vbulletin->options['allowthreadedmode'] == 0 or $vbulletin->userinfo['threadedmode'] == 0 and empty($vbulletin->GPC[COOKIE_PREFIX . 'threadedmode']) or $vbulletin->GPC[COOKIE_PREFIX . 'threadedmode'] == 'linear') and $thread['totalposts'] > $pperpage and $vbulletin->options['linktopages']) {
            $thread['totalpages'] = ceil($thread['totalposts'] / $pperpage);
            #$address2 = "$thread[highlight]";
            $curpage = 0;
            $thread['pagenav'] = '';
            $show['pagenavmore'] = false;
            while ($curpage++ < $thread['totalpages']) {
                if ($vbulletin->options['maxmultipage'] and $curpage > $vbulletin->options['maxmultipage']) {
                    $lastpageinfo = array('page' => $thread['totalpages']);
                    if ($thread['highlight']) {
                        $lastpageinfo['highlight'] = urlencode(implode(' ', $thread['highlight']));
                    }
                    $thread['lastpagelink'] = fetch_seo_url('thread', $thread, $lastpageinfo, 'threadid', 'threadtitle');
                    $show['pagenavmore'] = true;
                    break;
                }
                $pageinfo = array('page' => $curpage);
                if ($thread['highlight']) {
                    $pageinfo['highlight'] = urlencode(implode(' ', $thread['highlight']));
                }
                $pagenumbers = fetch_start_end_total_array($curpage, $pperpage, $thread['totalposts']);
                $templater = vB_Template::create('threadbit_pagelink');
                $templater->register('curpage', $curpage);
                $templater->register('pageinfo', $pageinfo);
                $templater->register('thread', $thread);
                $thread['pagenav'] .= ' ' . $templater->render();
            }
        } else {
            $thread['pagenav'] = '';
        }
        // allow thread icons?
        if ($allowicons) {
            // get icon from icon cache
            if ($thread['threadiconid']) {
                $thread['threadiconpath'] = $vbulletin->iconcache["{$thread['threadiconid']}"]['iconpath'];
                $thread['threadicontitle'] = $vbulletin->iconcache["{$thread['threadiconid']}"]['title'];
            }
            // show poll icon
            if ($thread['pollid'] != 0) {
                $show['threadicon'] = true;
                $thread['threadiconpath'] = vB_Template_Runtime::fetchStyleVar('imgdir_misc') . "/poll_posticon.gif";
                $thread['threadicontitle'] = $vbphrase['poll'];
            } else {
                if ($thread['threadiconpath']) {
                    $show['threadicon'] = true;
                } else {
                    if (!empty($vbulletin->options['showdeficon'])) {
                        $show['threadicon'] = true;
                        $thread['threadiconpath'] = $vbulletin->options['showdeficon'];
                        $thread['threadicontitle'] = '';
                    } else {
                        $show['threadicon'] = false;
                        $thread['threadiconpath'] = '';
                        $thread['threadicontitle'] = '';
                    }
                }
            }
        } else {
            $show['threadicon'] = false;
            $thread['threadiconpath'] = '';
            $thread['threadicontitle'] = '';
        }
        // thread has attachment?
        if ($thread['attach'] > 0) {
            $show['paperclip'] = true;
            $thread['checkbox_value'] += THREAD_FLAG_ATTACH;
        }
        // folder icon generation
        $thread['status'] = array();
        // show dot folder?
        if ($vbulletin->userinfo['userid'] and $vbulletin->options['showdots'] and $dotthreads["{$thread['threadid']}"]) {
            $thread['status']['dot'] = 'dot';
            $thread['dot_count'] = $dotthreads["{$thread['threadid']}"]['count'];
            $thread['dot_lastpost'] = $dotthreads["{$thread['threadid']}"]['lastpost'];
        }
        // show hot folder?
        if ($vbulletin->options['usehotthreads'] and ($thread['replycount'] >= $vbulletin->options['hotnumberposts'] and $vbulletin->options['hotnumberposts'] > 0 or $thread['views'] >= $vbulletin->options['hotnumberviews'] and $vbulletin->options['hotnumberviews'] > 0)) {
            $thread['status']['hot'] = 'hot';
        }
        // show locked folder?
        if (!$thread['open']) {
            $thread['status']['lock'] = 'lock';
            $thread['checkbox_value'] += THREAD_FLAG_CLOSED;
        }
        // show new folder?
        if ($thread['lastpost'] > $lastread) {
            if ($vbulletin->options['threadmarking'] and $thread['threadread']) {
                $threadview = $thread['threadread'];
            } else {
                $threadview = intval(fetch_bbarray_cookie('thread_lastview', $thread['threadid']));
            }
            if ($thread['lastpost'] > $threadview) {
                $thread['status']['new'] = 'new';
                $show['gotonewpost'] = true;
            } else {
                $newthreads--;
                $show['gotonewpost'] = false;
            }
        } else {
            $show['gotonewpost'] = false;
        }
        // format numbers nicely
        $thread['replycount'] = vb_number_format($thread['replycount']);
        $thread['views'] = vb_number_format($thread['views']);
        $thread['realthreadid'] = $thread['threadid'];
    } else {
        // thread has been moved, lets delete if required!
        if (can_moderate($thread['forumid'])) {
            if ($thread['expires']) {
                if ($thread['expires'] <= TIMENOW) {
                    $threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_STANDARD, 'threadpost');
                    $threadman->set_existing($thread);
                    $threadman->delete(false, true, NULL, false);
                    unset($threadman);
                }
                $show['rexpires'] = true;
                $thread['expiredate'] = vbdate($vbulletin->options['dateformat'], $thread['expires']);
                $thread['expiretime'] = vbdate($vbulletin->options['timeformat'], $thread['expires']);
            }
            $show['rmanage'] = can_moderate($thread['forumid'], 'canmanagethreads');
        }
        $thread['realthreadid'] = $thread['threadid'];
        $thread['redirectthreadid'] = $thread['threadid'];
        $thread['threadid'] = $thread['pollid'];
        $thread['replycount'] = '-';
        $thread['views'] = '-';
        $show['threadicon'] = false;
        $thread['status'] = array();
        // VB_API relies on thread redirects to fully reflect the read status of the redirected thread
        if ($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid'] and defined('VB_API') and VB_API === true) {
            if ($lastpost = $vbulletin->db->query_first("\n\t\t\t\tSELECT thread.forumid, thread.lastpost, threadread.readtime AS threadread\n\t\t\t\tFROM " . TABLE_PREFIX . "thread AS thread\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "threadread AS threadread ON (threadread.threadid = thread.threadid AND threadread.userid = {$vbulletin->userinfo['userid']})\n\t\t\t\tWHERE thread.threadid = {$thread['pollid']}\n\t\t\t")) {
                $forumread = $vbulletin->forumcache["{$lastpost['forumid']}"]['forumread'];
                $lastread = max($forumread, TIMENOW - $vbulletin->options['markinglimit'] * 86400);
                if ($lastpost['lastpost'] > $lastread) {
                    if ($lastpost['threadread']) {
                        $threadview = $lastpost['threadread'];
                    }
                    if ($lastpost['lastpost'] > $threadview) {
                        $thread['status']['new'] = 'new';
                    }
                }
            } else {
                $thread['status']['new'] = $thread['lastpost'] > $lastread ? 'new' : false;
            }
        } else {
            $thread['status']['new'] = $thread['lastpost'] > $lastread ? 'new' : false;
        }
        $thread['status']['moved'] = 'moved';
        $thread['pagenav'] = '';
        $thread['movedprefix'] = $vbphrase['moved_thread_prefix'];
        $thread['rating'] = 0;
        $thread['votenum'] = 0;
        $show['gotonewpost'] = false;
        $thread['showpagenav'] = false;
        $show['sticky'] = false;
        $show['threadmoved'] = true;
    }
    $show['subscribed'] = iif($thread['issubscribed'], true, false);
    $show['pagenav'] = iif($thread['pagenav'] != '', true, false);
    $show['guestuser'] = iif(!$thread['postuserid'], true, false);
    $show['threadrating'] = iif($thread['rating'] > 0, true, false);
    $show['threadcount'] = iif($thread['dot_count'], true, false);
    $show['taglist'] = ($vbulletin->options['threadtagging'] and !empty($thread['taglist']));
    ($hook = vBulletinHook::fetch_hook('threadbit_process')) ? eval($hook) : false;
    $thread['statusstring'] = implode(' ', $thread['status']);
    return $thread;
}
function process_thread_array($thread, $lastread = -1, $allowicons = -1)
{
    global $vbphrase, $stylevar, $foruminfo, $vbulletin;
    global $newthreads, $dotthreads, $perpage, $ignore, $show;
    static $pperpage;
    if ($pperpage == 0) {
        // lets calculate posts per page
        // the following code should be left just in case we plan to use this function in showthread at some point
        if (THIS_SCRIPT != 'showthread') {
            $pperpage = sanitize_maxposts();
        } else {
            $pperpage = sanitize_maxposts($perpage);
        }
    }
    // init value for the inline moderation checkbox
    $thread['checkbox_value'] = 0;
    if (can_moderate($thread['forumid'], 'caneditthreads') or $thread['open'] and $thread['postuserid'] == $vbulletin->userinfo['userid'] and $forumperms = fetch_permissions($thread['forumid']) and $forumperms & $vbulletin->bf_ugp_forumpermissions['caneditpost'] and $thread['dateline'] + $vbulletin->options['editthreadtitlelimit'] * 60 > TIMENOW) {
        $thread['title_editable'] = '<a rel="vB::AJAX"></a>';
        $show['ajax_js'] = true;
    } else {
        $thread['title_editable'] = '';
    }
    if ($thread['open'] != 10 and (can_moderate($thread['forumid'], 'canopenclose') or $thread['postuserid'] == $vbulletin->userinfo['userid'] and $forumperms = fetch_permissions($thread['forumid']) and $forumperms & $vbulletin->bf_ugp_forumpermissions['canopenclose'])) {
        $thread['openclose_editable'] = '<a rel="vB::AJAX"></a>';
        $show['ajax_js'] = true;
    } else {
        $thread['openclose_editable'] = '';
    }
    /*if ($thread['postuserid'] == $vbulletin->userinfo['userid'])
    	{
    		$forumperms = fetch_permissions($thread['forumid']);
    		if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canopenclose'])
    		{
    			$thread['openclose_editable'] .= "<div><strong>Own thread</strong></div>";
    		}
    	}*/
    if ($allowicons == -1) {
        $allowicons = $vbulletin->forumcache["{$thread['forumid']}"]['options'] & $vbulletin->bf_misc_forumoptions['allowicons'];
    }
    if ($lastread == -1) {
        $lastread = $vbulletin->userinfo['lastvisit'];
    }
    $show['rexpires'] = $show['rmanage'] = $show['threadmoved'] = $show['paperclip'] = $show['unsubscribe'] = false;
    // thread forumtitle
    if (empty($thread['forumtitle'])) {
        $thread['forumtitle'] = $vbulletin->forumcache["{$thread['forumid']}"]['title'];
    }
    // word wrap title
    if ($vbulletin->options['wordwrap'] != 0) {
        $thread['threadtitle'] = fetch_word_wrapped_string($thread['threadtitle']);
    }
    $thread['threadtitle'] = fetch_censored_text($thread['threadtitle']);
    if ($thread['prefixid']) {
        $thread['prefix_plain_html'] = htmlspecialchars_uni($vbphrase["prefix_{$thread['prefixid']}_title_plain"]);
        $thread['prefix_rich'] = $vbphrase["prefix_{$thread['prefixid']}_title_rich"];
    } else {
        $thread['prefix_plain_html'] = '';
        $thread['prefix_rich'] = '';
    }
    // format thread preview if there is one
    if ($ignore["{$thread['postuserid']}"]) {
        $thread['preview'] = '';
    } else {
        if (isset($thread['preview']) and $vbulletin->options['threadpreview'] > 0) {
            $thread['preview'] = strip_quotes($thread['preview']);
            $thread['preview'] = htmlspecialchars_uni(fetch_censored_text(fetch_trimmed_title(strip_bbcode($thread['preview'], false, true), $vbulletin->options['threadpreview'])));
        }
    }
    // thread last reply date/time
    $thread['lastpostdate'] = vbdate($vbulletin->options['dateformat'], $thread['lastpost'], true);
    $thread['lastposttime'] = vbdate($vbulletin->options['timeformat'], $thread['lastpost']);
    // post reply date/time (for search results as posts mainly)
    if ($thread['postdateline']) {
        $thread['postdate'] = vbdate($vbulletin->options['dateformat'], $thread['postdateline'], true);
        $thread['posttime'] = vbdate($vbulletin->options['timeformat'], $thread['postdateline']);
    } else {
        $thread['postdate'] = '';
        $thread['posttime'] = '';
    }
    // thread not moved
    if ($thread['open'] != 10) {
        // allow ratings?
        if ($foruminfo['allowratings']) {
            // show votes?
            if ($thread['votenum'] and $thread['votenum'] >= $vbulletin->options['showvotes']) {
                $thread['voteavg'] = vb_number_format($thread['votetotal'] / $thread['votenum'], 2);
                $thread['rating'] = intval(round($thread['votetotal'] / $thread['votenum']));
            } else {
                $thread['rating'] = 0;
            }
        } else {
            $thread['rating'] = 0;
            $thread['votenum'] = 0;
        }
        // moderated thread?
        if (!$thread['visible']) {
            $thread['moderatedprefix'] = $vbphrase['moderated_thread_prefix'];
            $thread['checkbox_value'] += THREAD_FLAG_INVISIBLE;
        } else {
            $thread['moderatedprefix'] = '';
        }
        // deleted thread?
        if ($thread['visible'] == 2) {
            $thread['checkbox_value'] += THREAD_FLAG_DELETED;
            $thread['del_reason'] = fetch_censored_text($thread['del_reason']);
        }
        // sticky thread?
        if ($thread['sticky']) {
            $show['sticky'] = true;
            $thread['typeprefix'] = $vbphrase['sticky_thread_prefix'];
            $thread['checkbox_value'] += THREAD_FLAG_STICKY;
        } else {
            $show['sticky'] = false;
            $thread['typeprefix'] = '';
        }
        // thread contains poll?
        if ($thread['pollid'] != 0) {
            $thread['typeprefix'] .= $vbphrase['poll_thread_prefix'];
            $thread['checkbox_value'] += THREAD_FLAG_POLL;
        }
        // multipage nav
        $thread['totalposts'] = $thread['replycount'] + 1;
        $total =& $thread['totalposts'];
        if (($vbulletin->options['allowthreadedmode'] == 0 or $vbulletin->userinfo['threadedmode'] == 0 and empty($vbulletin->GPC[COOKIE_PREFIX . 'threadedmode']) or $vbulletin->GPC[COOKIE_PREFIX . 'threadedmode'] == 'linear') and $thread['totalposts'] > $pperpage and $vbulletin->options['linktopages']) {
            $thread['totalpages'] = ceil($thread['totalposts'] / $pperpage);
            $address = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "t={$thread['threadid']}";
            $address2 = "{$thread['highlight']}";
            $curpage = 0;
            $thread['pagenav'] = '';
            $show['pagenavmore'] = false;
            while ($curpage++ < $thread['totalpages']) {
                if ($vbulletin->options['maxmultipage'] and $curpage > $vbulletin->options['maxmultipage']) {
                    $show['pagenavmore'] = true;
                    break;
                }
                $pagenumbers = fetch_start_end_total_array($curpage, $pperpage, $thread['totalposts']);
                eval('$thread[pagenav] .= " ' . fetch_template('threadbit_pagelink') . '";');
            }
        } else {
            $thread['pagenav'] = '';
        }
        // allow thread icons?
        if ($allowicons) {
            // get icon from icon cache
            if ($thread['threadiconid']) {
                $thread['threadiconpath'] = $vbulletin->iconcache["{$thread['threadiconid']}"]['iconpath'];
                $thread['threadicontitle'] = $vbulletin->iconcache["{$thread['threadiconid']}"]['title'];
            }
            // show poll icon
            if ($thread['pollid'] != 0) {
                $show['threadicon'] = true;
                $thread['threadiconpath'] = "{$stylevar['imgdir_misc']}/poll_posticon.gif";
                $thread['threadicontitle'] = $vbphrase['poll'];
            } else {
                if ($thread['threadiconpath']) {
                    $show['threadicon'] = true;
                } else {
                    if (!empty($vbulletin->options['showdeficon'])) {
                        $show['threadicon'] = true;
                        $thread['threadiconpath'] = $vbulletin->options['showdeficon'];
                        $thread['threadicontitle'] = '';
                    } else {
                        $show['threadicon'] = false;
                        $thread['threadiconpath'] = '';
                        $thread['threadicontitle'] = '';
                    }
                }
            }
        } else {
            $show['threadicon'] = false;
            $thread['threadiconpath'] = '';
            $thread['threadicontitle'] = '';
        }
        // thread has attachment?
        if ($thread['attach'] > 0) {
            $show['paperclip'] = true;
            $thread['checkbox_value'] += THREAD_FLAG_ATTACH;
        }
        // folder icon generation
        $thread['statusicon'] = '';
        // show dot folder?
        if ($vbulletin->userinfo['userid'] and $vbulletin->options['showdots'] and $dotthreads["{$thread['threadid']}"]) {
            $thread['statusicon'] .= '_dot';
            $thread['dot_count'] = $dotthreads["{$thread['threadid']}"]['count'];
            $thread['dot_lastpost'] = $dotthreads["{$thread['threadid']}"]['lastpost'];
        }
        // show hot folder?
        if ($vbulletin->options['usehotthreads'] and ($thread['replycount'] >= $vbulletin->options['hotnumberposts'] and $vbulletin->options['hotnumberposts'] > 0 or $thread['views'] >= $vbulletin->options['hotnumberviews'] and $vbulletin->options['hotnumberviews'] > 0)) {
            $thread['statusicon'] .= '_hot';
        }
        // show locked folder?
        if (!$thread['open']) {
            $thread['statusicon'] .= '_lock';
            $thread['checkbox_value'] += THREAD_FLAG_CLOSED;
        }
        // show new folder?
        if ($thread['lastpost'] > $lastread) {
            if ($vbulletin->options['threadmarking'] and $thread['threadread']) {
                $threadview = $thread['threadread'];
            } else {
                $threadview = intval(fetch_bbarray_cookie('thread_lastview', $thread['threadid']));
            }
            if ($thread['lastpost'] > $threadview) {
                $thread['statusicon'] .= '_new';
                $show['gotonewpost'] = true;
            } else {
                $newthreads--;
                $show['gotonewpost'] = false;
            }
        } else {
            $show['gotonewpost'] = false;
        }
        // format numbers nicely
        $thread['replycount'] = vb_number_format($thread['replycount']);
        $thread['views'] = vb_number_format($thread['views']);
        $thread['realthreadid'] = $thread['threadid'];
    } else {
        // thread has been moved, lets delete if required!
        if (can_moderate($thread['forumid'])) {
            if ($thread['expires']) {
                if ($thread['expires'] <= TIMENOW) {
                    $threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_STANDARD, 'threadpost');
                    $threadman->set_existing($thread);
                    $threadman->delete(false, true, NULL, false);
                    unset($threadman);
                }
                $show['rexpires'] = true;
                $thread['expiredate'] = vbdate($vbulletin->options['dateformat'], $thread['expires']);
                $thread['expiretime'] = vbdate($vbulletin->options['timeformat'], $thread['expires']);
            }
            $show['rmanage'] = can_moderate($thread['forumid'], 'canmanagethreads');
        }
        $thread['realthreadid'] = $thread['threadid'];
        $thread['redirectthreadid'] = $thread['threadid'];
        $thread['threadid'] = $thread['pollid'];
        $thread['replycount'] = '-';
        $thread['views'] = '-';
        $show['threadicon'] = false;
        $thread['statusicon'] = '_moved' . iif($thread['lastpost'] > $lastread, '_new');
        $thread['pagenav'] = '';
        $thread['movedprefix'] = $vbphrase['moved_thread_prefix'];
        $thread['rating'] = 0;
        $thread['votenum'] = 0;
        $thread['pagenav'] = '';
        $show['gotonewpost'] = false;
        $thread['showpagenav'] = false;
        $show['sticky'] = false;
        $show['threadmoved'] = true;
    }
    $show['subscribed'] = iif($thread['issubscribed'], true, false);
    $show['pagenav'] = iif($thread['pagenav'] != '', true, false);
    $show['guestuser'] = iif(!$thread['postuserid'], true, false);
    $show['threadrating'] = iif($thread['rating'] > 0, true, false);
    $show['threadcount'] = iif($thread['dot_count'], true, false);
    $show['taglist'] = ($vbulletin->options['threadtagging'] and !empty($thread['taglist']));
    ($hook = vBulletinHook::fetch_hook('threadbit_process')) ? eval($hook) : false;
    return $thread;
}
function process_thread_array($thread, $lastread = -1, $allowicons = -1)
{
	global $vbphrase, $foruminfo, $vbulletin;
	global $newthreads, $dotthreads, $perpage, $ignore, $show;
	static $pperpage;

	if ($pperpage == 0)
	{ // lets calculate posts per page
		// the following code should be left just in case we plan to use this function in showthread at some point

		if (THIS_SCRIPT != 'showthread')
		{
			$pperpage = sanitize_maxposts();
		}
		else
		{
			$pperpage = sanitize_maxposts($perpage);
		}
	}

	// init value for the inline moderation checkbox
	$thread['checkbox_value'] = 0;

	if (
		can_moderate($thread['forumid'], 'caneditthreads')
		OR
		(
			$thread['open']
			AND
			$thread['postuserid'] == $vbulletin->userinfo['userid']
			AND
			($forumperms = fetch_permissions($thread['forumid'])) AND ($forumperms & $vbulletin->bf_ugp_forumpermissions['caneditpost'])
			AND
			($thread['dateline'] + $vbulletin->options['editthreadtitlelimit'] * 60) > TIMENOW
		)
	)
	{
		$thread['title_editable'] = true;
		$show['ajax_js'] = true;
	}

	if (
		$thread['open'] != 10
		AND
		(
			can_moderate($thread['forumid'], 'canopenclose')
			OR
			(
				$thread['postuserid'] == $vbulletin->userinfo['userid']
				AND
				($forumperms = fetch_permissions($thread['forumid'])) AND ($forumperms & $vbulletin->bf_ugp_forumpermissions['canopenclose'])
			)
		)
	)
	{
		$thread['openclose_editable'] = true;
		$show['ajax_js'] = true;
	}

	/*if ($thread['postuserid'] == $vbulletin->userinfo['userid'])
	{
		$forumperms = fetch_permissions($thread['forumid']);
		if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canopenclose'])
		{
			$thread['openclose_editable'] .= "<div><strong>Own thread</strong></div>";
		}
	}*/

	if ($allowicons == -1)
	{
		$allowicons = $vbulletin->forumcache["$thread[forumid]"]['options'] & $vbulletin->bf_misc_forumoptions['allowicons'];
	}

	if ($lastread == -1)
	{
		$lastread = $vbulletin->userinfo['lastvisit'];
	}

	$show['rexpires'] = $show['rmanage'] = $show['threadmoved'] = $show['paperclip'] = $show['unsubscribe'] = false;

	// thread forumtitle
	if (empty($thread['forumtitle']))
	{
		$thread['forumtitle'] = $vbulletin->forumcache["$thread[forumid]"]['title'];
	}
	$thread['forumtitleclean'] = $vbulletin->forumcache["$thread[forumid]"]['title_clean'];

	// word wrap title
	if ($vbulletin->options['wordwrap'] != 0)
	{
		$thread['threadtitle'] = fetch_word_wrapped_string($thread['threadtitle']);
	}

	$thread['threadtitle'] = fetch_censored_text($thread['threadtitle']);

	if ($thread['prefixid'])
	{
		$thread['prefix_plain_html'] = htmlspecialchars_uni($vbphrase["prefix_$thread[prefixid]_title_plain"]);
		$thread['prefix_rich'] = $vbphrase["prefix_$thread[prefixid]_title_rich"];
	}
	else
	{
		$thread['prefix_plain_html'] = '';
		$thread['prefix_rich'] = '';
	}

	// format thread preview if there is one
	if ($ignore["$thread[postuserid]"])
	{
		$thread['preview'] = '';
	}
	else if (isset($thread['preview']))
	{
		if($vbulletin->options['threadpreview'] > 0)
		{
			$thread['preview'] = strip_quotes($thread['preview']);
			$thread['preview'] = htmlspecialchars_uni(fetch_censored_text(
				fetch_trimmed_title(strip_bbcode($thread['preview'], false, true, true, true),
					$vbulletin->options['threadpreview'])
			));
		}
		//if the preview text is disabled, then make sure that we don't leave this function
		//with it set.
		else
		{
			unset($thread['preview']);
		}
	}

	// thread last reply date/time
	$thread['lastpostdate'] = vbdate($vbulletin->options['dateformat'], $thread['lastpost'], true);
	$thread['lastposttime'] = vbdate($vbulletin->options['timeformat'], $thread['lastpost']);

	// post reply date/time (for search results as posts mainly)
	if ($thread['postdateline'])
	{
		$thread['postdate'] = vbdate($vbulletin->options['dateformat'], $thread['postdateline'], true);
		$thread['posttime'] = vbdate($vbulletin->options['timeformat'], $thread['postdateline']);
	}
	else
	{
		$thread['postdate'] = '';
		$thread['posttime'] = '';
	}

	// get the thread starting date and time if applicable
	if ($thread['dateline'])
	{
		$thread['startdate'] = vbdate($vbulletin->options['dateformat'], $thread['dateline'], true);
		$thread['starttime'] = vbdate($vbulletin->options['timeformat'], $thread['dateline']);
	}
	else
	{
		$thread['startdate'] = '';
		$thread['starttime'] = '';
	}

	// non magical thread status
	if (2 == $thread['visible'])
	{
		$thread['status']['deleted'] = 'deleted';
	}
	else if (!$thread['visible'])
	{
		$thread['status']['moderated'] = 'moderated';
	}

	// thread not moved
	if ($thread['open'] != 10)
	{
		// allow ratings?
		if ($foruminfo['allowratings'])
		{
			// show votes?
			if ($thread['votenum'] AND $thread['votenum'] >= $vbulletin->options['showvotes'])
			{
				$thread['voteavg'] = vb_number_format($thread['votetotal'] / $thread['votenum'], 2);
				$thread['rating'] = intval(round($thread['votetotal'] / $thread['votenum']));
			}
			// do not show votes
			else
			{
				$thread['rating'] = 0;
			}
		}
		// do not allow ratings
		else
		{
			 $thread['rating'] = 0;
			 $thread['votenum'] = 0;
		}

		// moderated thread?
		if (!$thread['visible'])
		{
			$thread['moderatedprefix'] = $vbphrase['moderated_thread_prefix'];
			$thread['checkbox_value'] += THREAD_FLAG_INVISIBLE;
		}
		else
		{
			$thread['moderatedprefix'] = '';
		}

		// deleted thread?
		if ($thread['visible'] == 2)
		{
			$thread['checkbox_value'] += THREAD_FLAG_DELETED;
			$thread['del_reason'] = fetch_censored_text($thread['del_reason']);
		}

		// sticky thread?
		if ($thread['sticky'])
		{
			$show['sticky'] = true;
			$thread['typeprefix'] = $vbphrase['sticky_thread_prefix'];
			$thread['checkbox_value'] += THREAD_FLAG_STICKY;
		}
		else
		{
			$show['sticky'] = false;
			$thread['typeprefix'] = '';
		}

		// thread contains poll?
		if ($thread['pollid'] != 0)
		{
			$thread['typeprefix'] .= $vbphrase['poll_thread_prefix'];
			$thread['checkbox_value'] += THREAD_FLAG_POLL;
		}

		// multipage nav
		$thread['totalposts'] = $thread['replycount'] + 1;
		$total =& $thread['totalposts'];
		if (
			($vbulletin->options['allowthreadedmode'] == 0 OR
				($vbulletin->userinfo['threadedmode'] == 0 AND
					empty($vbulletin->GPC[COOKIE_PREFIX . 'threadedmode'])) OR
				$vbulletin->GPC[COOKIE_PREFIX . 'threadedmode'] == 'linear') AND
			$thread['totalposts'] > $pperpage AND $vbulletin->options['linktopages']
		)
		{
			$thread['totalpages'] = ceil($thread['totalposts'] / $pperpage);
			#$address2 = "$thread[highlight]";

			$curpage = 0;

			$thread['pagenav'] = '';
			$show['pagenavmore'] = false;

			while ($curpage++ < $thread['totalpages'])
			{
				if ($vbulletin->options['maxmultipage'] AND $curpage > $vbulletin->options['maxmultipage'])
				{
					$lastpageinfo = array(
						'page' => $thread['totalpages']
					);
					$thread['lastpagelink'] = fetch_seo_url('thread', $thread, $lastpageinfo, 'threadid', 'threadtitle');
					$show['pagenavmore'] = true;
					break;
				}

				$pageinfo = array(
					'page' => $curpage
				);
				if ($thread['highlight'])
				{
					$pageinfo['highlight'] = urlencode(implode(' ', $thread['highlight']));
				}

				$pagenumbers = fetch_start_end_total_array($curpage, $pperpage, $thread['totalposts']);
				$templater = vB_Template::create('threadbit_pagelink');
					$templater->register('curpage', $curpage);
					$templater->register('pageinfo', $pageinfo);
					$templater->register('thread', $thread);
				$thread['pagenav'] .= ' ' . $templater->render();
			}
		}
		// do not show pagenav
		else
		{
			$thread['pagenav'] = '';
		}

		// allow thread icons?
		if ($allowicons)
		{
			// get icon from icon cache
			if ($thread['threadiconid'])
			{
				$thread['threadiconpath'] = $vbulletin->iconcache["$thread[threadiconid]"]['iconpath'];
				$thread['threadicontitle'] = $vbulletin->iconcache["$thread[threadiconid]"]['title'];
			}

			// show poll icon
			if ($thread['pollid'] != 0)
			{
				$show['threadicon'] = true;
				$thread['threadiconpath'] = vB_Template_Runtime::fetchStyleVar('imgdir_misc') . "/poll_posticon.gif";
				$thread['threadicontitle'] = $vbphrase['poll'];
			}
			// show specified icon
			// this looks obsolete -- there isn't anything that appears to set threadiconpath
			// anywhere outside of this file.
			else if ($thread['threadiconpath'])
			{
				$show['threadicon'] = true;
			}
			// show default icon
			else if (!empty($vbulletin->options['showdeficon']))
			{
				$show['threadicon'] = true;
				$thread['threadiconpath'] = $vbulletin->options['showdeficon'];
				$thread['threadicontitle'] = '';
			}
			// do not show icon
			else
			{
				$show['threadicon'] = false;
				$thread['threadiconpath'] = '';
				$thread['threadicontitle'] = '';
			}
		}
		// do not allow icons
		else
		{
			$show['threadicon'] = false;
			$thread['threadiconpath'] = '';
			$thread['threadicontitle'] = '';
		}

		// thread has attachment?
		if ($thread['attach'] > 0)
		{
			$show['paperclip'] = true;
			$thread['checkbox_value'] += THREAD_FLAG_ATTACH;
		}

		// folder icon generation
		$thread['status'] = array();

		// show dot folder?
		if ($vbulletin->userinfo['userid'] AND $vbulletin->options['showdots'] AND $dotthreads["$thread[threadid]"])
		{
			$thread['status']['dot'] = 'dot';
			$thread['dot_count'] = $dotthreads["$thread[threadid]"]['count'];
			$thread['dot_lastpost'] = $dotthreads["$thread[threadid]"]['lastpost'];
		}
		// show hot folder?
		if ($vbulletin->options['usehotthreads'] AND (($thread['replycount'] >= $vbulletin->options['hotnumberposts'] AND $vbulletin->options['hotnumberposts'] > 0) OR ($thread['views'] >= $vbulletin->options['hotnumberviews'] AND $vbulletin->options['hotnumberviews'] > 0)))
		{
			$thread['status']['hot'] = 'hot';
		}
		// show locked folder?
		if (!$thread['open'])
		{
			$thread['status']['lock'] = 'lock';
			$thread['checkbox_value'] += THREAD_FLAG_CLOSED;
		}

		// show new folder?
		if ($thread['lastpost'] > $lastread)
		{
			if ($vbulletin->options['threadmarking'] AND $thread['threadread'])
			{
				$threadview = $thread['threadread'];
			}
			else
			{
				$threadview = intval(fetch_bbarray_cookie('thread_lastview', $thread['threadid']));
			}

			if ($thread['lastpost'] > $threadview)
			{
				$thread['status']['new'] = 'new';
				$show['gotonewpost'] = true;
			}
			else
			{
				$newthreads--;
				$show['gotonewpost'] = false;
			}
		}
		else
		{
			$show['gotonewpost'] = false;
		}

		// format numbers nicely
		$thread['replycount'] = vb_number_format($thread['replycount']);
		$thread['views'] = vb_number_format($thread['views']);
		$thread['realthreadid'] = $thread['threadid'];
	}
	// thread moved?
	else
	{
		// thread has been moved, lets delete if required!
		if (can_moderate($thread['forumid']))
		{
			if ($thread['expires'])
			{
				if ($thread['expires'] <= TIMENOW)
				{
					$threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_STANDARD, 'threadpost');
					$threadman->set_existing($thread);
					$threadman->delete(false, true, NULL, false);
					unset($threadman);
				}

				$show['rexpires'] = true;
				$thread['expiredate'] = vbdate($vbulletin->options['dateformat'], $thread['expires']);
				$thread['expiretime'] = vbdate($vbulletin->options['timeformat'], $thread['expires']);
			}
			$show['rmanage']  = can_moderate($thread['forumid'], 'canmanagethreads');
		}
		$thread['realthreadid'] = $thread['threadid'];
		$thread['redirectthreadid'] = $thread['threadid'];
		$thread['threadid'] = $thread['pollid'];
		$thread['replycount'] = '-';
		$thread['views'] = '-';
		$show['threadicon'] = false;
		$thread['status'] = array('moved' => 'moved', 'new' => ($thread['lastpost'] > $lastread) ? 'new' : false);
		$thread['pagenav'] = '';
		$thread['movedprefix'] = $vbphrase['moved_thread_prefix'];
		$thread['rating'] = 0;
		$thread['votenum'] = 0;
		$show['gotonewpost'] = false;
		$thread['showpagenav'] = false;
		$show['sticky'] = false;
		$show['threadmoved'] = true;
	}

	$show['subscribed'] = iif ($thread['issubscribed'], true, false);
	$show['pagenav'] = iif ($thread['pagenav'] != '', true, false);
	$show['guestuser'] = iif (!$thread['postuserid'], true, false);
	$show['threadrating'] = iif ($thread['rating'] > 0, true, false);
	$show['threadcount'] = iif ($thread['dot_count'], true, false);
	$show['taglist'] = ($vbulletin->options['threadtagging'] AND !empty($thread['taglist']));

	($hook = vBulletinHook::fetch_hook('threadbit_process')) ? eval($hook) : false;

	$thread['statusstring'] = implode(' ', $thread['status']);

	return $thread;
}