Exemplo n.º 1
0
function xthreads_forumdisplay_thread()
{
    global $thread, $threadfields, $threadfield_cache, $foruminfo;
    // make threadfields array
    $threadfields = array();
    foreach ($threadfield_cache as $k => &$v) {
        xthreads_get_xta_cache($v, $GLOBALS['tids']);
        $threadfields[$k] =& $thread['xthreads_' . $k];
        xthreads_sanitize_disp($threadfields[$k], $v, !xthreads_empty($thread['username']) ? $thread['username'] : $thread['threadusername']);
    }
    // evaluate group separator
    if ($foruminfo['xthreads_grouping']) {
        static $threadcount = 0;
        static $nulldone = false;
        global $templates;
        if ($thread['sticky'] == 0 && !$nulldone) {
            $nulldone = true;
            $nulls = (count($GLOBALS['threadcache']) - $threadcount) % $foruminfo['xthreads_grouping'];
            if ($nulls) {
                $excess = $nulls;
                $nulls = $foruminfo['xthreads_grouping'] - $nulls;
                $GLOBALS['nullthreads'] = '';
                while ($nulls--) {
                    $bgcolor = alt_trow();
                    // TODO: this may be problematic
                    eval('$GLOBALS[\'nullthreads\'] .= "' . $templates->get('forumdisplay_thread_null') . '";');
                }
            }
        }
        // reset counter on sticky/normal sep
        if ($thread['sticky'] == 0 && $GLOBALS['shownormalsep']) {
            $nulls = $threadcount % $foruminfo['xthreads_grouping'];
            if ($nulls) {
                $excess = $nulls;
                $nulls = $foruminfo['xthreads_grouping'] - $nulls;
                while ($nulls--) {
                    $bgcolor = alt_trow();
                    eval('$GLOBALS[\'threads\'] .= "' . $templates->get('forumdisplay_thread_null') . '";');
                }
            }
            $threadcount = 0;
        }
        if ($threadcount && $threadcount % $foruminfo['xthreads_grouping'] == 0) {
            eval('$GLOBALS[\'threads\'] .= "' . $templates->get('forumdisplay_group_sep') . '";');
        }
        ++$threadcount;
    }
}
Exemplo n.º 2
0
function xthreads_get_threadfields($tid, &$threadfields, $noextra = true, $thread = array())
{
    $tid = (int) $tid;
    if (!$tid) {
        return;
    }
    if (empty($thread)) {
        $thread = get_thread($tid);
    }
    if ($thread['fid'] == $GLOBALS['fid']) {
        // use global cache if we're referring to current forum
        $threadfield_cache =& $GLOBALS['threadfield_cache'];
    }
    if (!isset($threadfield_cache)) {
        $threadfield_cache = xthreads_gettfcache((int) $thread['fid']);
    }
    if (!empty($threadfield_cache)) {
        global $db;
        $threadfields = $db->fetch_array($db->simple_select('threadfields_data', '`' . implode('`,`', array_keys($threadfield_cache)) . '`', 'tid=' . $tid));
        if (!isset($threadfields)) {
            $threadfields = array();
        }
        foreach ($threadfield_cache as $k => &$v) {
            xthreads_get_xta_cache($v, $tid);
            xthreads_sanitize_disp($threadfields[$k], $v, $thread['username'], $noextra);
        }
    }
}
Exemplo n.º 3
0
function xthreads_inputdisp()
{
    global $thread, $post, $fid, $mybb, $plugins;
    // work around for editpost bug in MyBB prior to 1.4.12 (http://dev.mybboard.net/issues/374)
    // this function should only ever be run once
    static $called = false;
    if ($called) {
        return;
    }
    $called = true;
    $editpost = $GLOBALS['current_page'] == 'editpost.php';
    if ($editpost) {
        // because the placement of the editpost_start hook really sucks...
        if (!$post) {
            $post = get_post((int) $mybb->input['pid']);
            // hopefully MyBB will also use get_post in their code too...
        }
        if (!$thread) {
            if (!empty($post)) {
                $thread = get_thread($post['tid']);
            }
            if (empty($thread)) {
                return;
            }
        }
        if (!$fid) {
            $fid = $thread['fid'];
        }
        // check if first post
        if ($post['pid'] != $thread['firstpost']) {
            return;
        }
    }
    if ($mybb->request_method == 'post') {
        $recvfields = array();
        foreach ($mybb->input as $k => &$v) {
            if (substr($k, 0, 9) == 'xthreads_') {
                $recvfields[substr($k, 9)] =& $v;
            }
        }
        _xthreads_input_generate($recvfields, $fid, $thread['tid']);
    } elseif ($editpost || $mybb->input['action'] == 'editdraft' && $thread['tid']) {
        $blank = array();
        _xthreads_input_generate($blank, $fid, $thread['tid']);
    } else {
        // newthread.php
        $blank = array();
        _xthreads_input_generate($blank, $fid);
        // is this really a good idea? it may be possible to delete the current attachments connected to this post!
        // Update: hmm, perhaps unlikely, since this will only run if a POST request isn't made
        $plugins->add_hook('newthread_end', 'xthreads_attach_clear_posthash');
    }
    // editpost_first template hack
    if ($editpost && !xthreads_empty($GLOBALS['templates']->cache['editpost_first'])) {
        $plugins->add_hook('editpost_end', 'xthreads_editpost_first_tplhack');
    }
    if ($mybb->input['previewpost'] || $editpost) {
        global $threadfields, $forum;
        // $forum may not exist for editpost
        if (empty($forum)) {
            if (!empty($GLOBALS['thread'])) {
                // should be set
                $fid = $GLOBALS['thread']['fid'];
            } else {
                // last ditch resort, grab everything from the post
                $pid = (int) $mybb->input['pid'];
                $post = get_post($pid);
                $fid = $post['fid'];
            }
            $forum = get_forum($fid);
        }
        $threadfields = array();
        $threadfield_cache = xthreads_gettfcache($fid);
        // don't use global cache as that will probably have been cleared of uneditable fields
        $errors = xthreads_input_validate($threadfields, $threadfield_cache, $editpost ? $thread['tid'] : false);
        // don't validate here if on editpost, as MyBB will do it later (does a full posthandler validate call)
        // unfortunately, this method has the side effect of running our validation function twice :( [but not a big issue I guess]
        if ($editpost || empty($errors)) {
            // grab threadfields
            global $db;
            if (!empty($threadfield_cache)) {
                if ($thread['tid']) {
                    $curthreaddata = array();
                    foreach ($threadfield_cache as $k => &$v) {
                        if (!isset($threadfields[$k])) {
                            if (empty($curthreaddata)) {
                                $curthreaddata = $db->fetch_array($db->simple_select('threadfields_data', '`' . implode('`,`', array_keys($threadfield_cache)) . '`', 'tid=' . $thread['tid']));
                                if (empty($curthreaddata)) {
                                    break;
                                }
                                // there isn't anything set for this thread
                            }
                            $threadfields[$k] =& $curthreaddata[$k];
                        }
                    }
                    $tidstr = $thread['tid'];
                    $posthashstr = '';
                    $usernamestr = $thread['username'];
                } else {
                    $tidstr = '';
                    $posthashstr = $mybb->input['posthash'];
                    $usernamestr = $mybb->user['username'];
                }
                foreach ($threadfield_cache as $k => &$v) {
                    xthreads_get_xta_cache($v, $tidstr, $posthashstr);
                    xthreads_sanitize_disp($threadfields[$k], $v, $usernamestr);
                }
            }
            // do first post hack if applicable
            //if($forum['xthreads_firstpostattop']) {
            //require_once MYBB_ROOT.'inc/xthreads/xt_sthreadhooks.php';
            // above file should already be included
            if (function_exists('xthreads_tpl_postbithack')) {
                xthreads_tpl_postbithack();
            }
            //}
        } else {
            // block preview if there's errors
            // <removed previously commented out code which blocked preview by unsetting the previewpost input>
            // we'll block by forcing an error, so we can get a hook in somewhere...
            if (!$mybb->input['ajax']) {
                // will not happen, but be pedantic
                $GLOBALS['xthreads_backup_subject'] = $mybb->input['subject'];
                $GLOBALS['xthreads_preview_errors'] =& $errors;
                $mybb->input['subject'] = '';
                control_object($GLOBALS['templates'], '
					function get($title, $eslashes=1, $htmlcomments=1) {
						static $done = false;
						if(!$done && $title == "error_inline") {
							$done = true;
							return str_replace(\'{$errorlist}\', xthreads_blockpreview_hook(), parent::get($title, $eslashes, $htmlcomments));
						}
						return parent::get($title, $eslashes, $htmlcomments);
					}
				');
                function xthreads_blockpreview_hook()
                {
                    global $posthandler;
                    $posthandler->data['subject'] = $GLOBALS['mybb']->input['subject'] = $GLOBALS['xthreads_backup_subject'];
                    // remove the error
                    foreach ($posthandler->errors as $k => &$v) {
                        if ($v['error_code'] == 'missing_subject' || $v['error_code'] == 'firstpost_no_subject') {
                            unset($posthandler->errors[$k]);
                        }
                    }
                    // and recheck
                    $posthandler->verify_subject();
                    xthreads_posthandler_add_errors($posthandler, $GLOBALS['xthreads_preview_errors']);
                    $GLOBALS['lang']->load('xthreads');
                    $errorlist = '';
                    foreach ($posthandler->get_friendly_errors() as $error) {
                        $errorlist .= '<li>' . $error . '</li>';
                    }
                    return $errorlist;
                }
            }
        }
        // message length hack for newthread
        if (!$editpost && $forum['xthreads_allow_blankmsg'] && my_strlen($mybb->input['message']) == 0) {
            $mybb->input['message'] = str_repeat('-', max((int) $mybb->settings['minmessagelength'], 1));
            function xthreads_newthread_prev_blankmsg_hack()
            {
                static $done = false;
                if ($done) {
                    return;
                }
                $done = true;
                $GLOBALS['message'] = '';
                $GLOBALS['mybb']->input['message'] = '';
            }
            function xthreads_newthread_prev_blankmsg_hack_postbit(&$p)
            {
                $p['message'] = '';
                xthreads_newthread_prev_blankmsg_hack();
            }
            $plugins->add_hook('newthread_end', 'xthreads_newthread_prev_blankmsg_hack');
            $plugins->add_hook('postbit_prev', 'xthreads_newthread_prev_blankmsg_hack_postbit');
        }
    }
}
Exemplo n.º 4
0
function xthreads_portal_announcement()
{
    static $doneinit = false;
    global $threadfield_cache, $announcement, $threadfields, $forum_tpl_prefixes;
    if (!$doneinit) {
        $doneinit = true;
        // cache templates
        $cachelist = '';
        $forum_tpl_prefixes = xthreads_get_tplprefixes(true, $GLOBALS['forum']);
        foreach ($forum_tpl_prefixes as $pref) {
            $pref = $GLOBALS['db']->escape_string($pref);
            $cachelist .= ($cachelist ? ',' : '') . $pref . 'portal_announcement,' . $pref . 'portal_announcement_numcomments,' . $pref . 'portal_announcement_numcomments_no';
        }
        if ($cachelist !== '') {
            $GLOBALS['templates']->cache($cachelist);
        }
    }
    // following two lines not needed as we have $anndate and $anntime
    //$announcement['threaddate'] = my_date($mybb->settings['dateformat'], $announcement['dateline']);
    //$announcement['threadtime'] = my_date($mybb->settings['timeformat'], $announcement['dateline']);
    xthreads_set_threadforum_urlvars('thread', $announcement['tid']);
    xthreads_set_threadforum_urlvars('forum', $announcement['fid']);
    if (!empty($threadfield_cache)) {
        // make threadfields array
        $threadfields = array();
        // clear previous threadfields
        foreach ($threadfield_cache as $k => &$v) {
            if ($v['forums'] && strpos(',' . $v['forums'] . ',', ',' . $announcement['fid'] . ',') === false) {
                continue;
            }
            $tids = '0' . $GLOBALS['tids'];
            xthreads_get_xta_cache($v, $tids);
            $threadfields[$k] =& $announcement['xthreads_' . $k];
            xthreads_sanitize_disp($threadfields[$k], $v, $announcement['username'] !== '' ? $announcement['username'] : $announcement['threadusername']);
        }
    }
    // template hack
    $tplprefix =& $forum_tpl_prefixes[$announcement['fid']];
    xthreads_portalsearch_cache_hack($tplprefix, 'portal_announcement');
    if (!xthreads_empty($tplprefix)) {
        $tplname = $tplprefix . 'portal_announcement_numcomments' . ($announcement['replies'] ? '' : '_no');
        if (!xthreads_empty($GLOBALS['templates']->cache[$tplname])) {
            global $lang, $mybb;
            // re-evaluate comments template
            eval('$GLOBALS[\'numcomments\'] = "' . $GLOBALS['templates']->get($tplname) . '";');
        }
    }
}