Пример #1
0
function xthreads_global()
{
    global $current_page, $mybb, $templatelist, $templates;
    if ($current_page == 'index.php' || $current_page == 'forumdisplay.php') {
        global $plugins;
        require_once MYBB_ROOT . 'inc/xthreads/xt_forumdhooks.php';
        $plugins->add_hook('forumdisplay_start', 'xthreads_forumdisplay');
        $plugins->add_hook('build_forumbits_forum', 'xthreads_tpl_forumbits');
        xthreads_global_forumbits_tpl();
    }
    switch ($current_page) {
        case 'misc.php':
            if ($mybb->input['action'] != 'rules') {
                break;
            }
        case 'forumdisplay.php':
        case 'newthread.php':
        case 'moderation.php':
            $fid = (int) $mybb->input['fid'];
            if ($fid) {
                break;
            }
        case 'polls.php':
            switch ($mybb->input['action']) {
                case 'editpoll':
                case 'do_editpoll':
                case 'showresults':
                case 'vote':
                case 'do_undovote':
                    // no cached poll getting function, dupe a query then...
                    global $db;
                    $tid = $db->fetch_field($db->simple_select('polls', 'tid', 'pid=' . (int) $mybb->input['pid']), 'tid');
            }
            // fall through
        // fall through
        case 'showthread.php':
        case 'newreply.php':
        case 'ratethread.php':
        case 'sendthread.php':
        case 'printthread.php':
            if (isset($tid) || ($tid = (int) $mybb->input['tid'])) {
                $thread = get_thread($tid);
                if ($thread['fid']) {
                    $fid = $thread['fid'];
                    $set_thread_urlvar = $thread['tid'];
                }
            }
            if ($fid || $current_page == 'polls.php') {
                break;
            }
        case 'editpost.php':
            if ($pid = (int) $mybb->input['pid']) {
                $post = get_post($pid);
                if ($post['fid']) {
                    $fid = $post['fid'];
                    $set_thread_urlvar = $post['tid'];
                }
            }
            break;
        case 'announcements.php':
            if ($aid = (int) $mybb->input['aid']) {
                // unfortunately MyBB doesn't have a cache for announcements
                // so we can have fun and double query!
                global $db;
                $fid = $db->fetch_field($db->simple_select('announcements', 'fid', 'aid=' . $aid), 'fid');
                // note, $fid can be 0, for invalid aid, or announcement applying to all forums
            }
            break;
        default:
            return;
    }
    $fid = (int) $fid;
    // paranoia
    if ($fid) {
        global $forum;
        $forum = get_forum($fid);
        if (function_exists('xthreads_evalcacheForums')) {
            $xtforum = xthreads_evalcacheForums($fid);
            if ($xtforum['tplprefix'] !== '') {
                // this forum has a custom tpl prefix, hook into templates system
                control_object($templates, '
					function cache($templates) {
						xthreads_tpl_cache($templates, $this);
					}
					
					function get($title, $eslashes=1, $htmlcomments=1) {
						xthreads_tpl_get($this, $title);
						return parent::get($title, $eslashes, $htmlcomments);
					}
				');
                $templates->non_existant_templates = array();
                $templates->xt_tpl_prefix = $xtforum['tplprefix'];
            }
            if ($xtforum['langprefix'] !== '') {
                global $lang;
                // this forum has a custom lang prefix, hook into lang system
                control_object($lang, '
					function load($section, $isdatahandler=false, $supress_error=false) {
						$this->__xt_load($section, $isdatahandler, $supress_error);
						foreach($this->__xt_lang_prefix as &$pref)
							if($pref !== \'\')
								$this->__xt_load($pref.$section, $isdatahandler, true);
					}
					function __xt_load($section, $isdatahandler=false, $supress_error=false) {
						return parent::load($section, $isdatahandler, $supress_error);
					}
				');
                $lang->__xt_lang_prefix = $xtforum['langprefix'];
                // load global lang messages that we couldn't before
                foreach ($lang->__xt_lang_prefix as &$pref) {
                    if ($pref !== '' && preg_match('~^[a-zA-Z0-9_]+$~', $pref)) {
                        $lang->__xt_load($pref . 'global', false, true);
                        $lang->__xt_load($pref . 'messages', false, true);
                    }
                }
            }
            if ($xtforum['settingoverrides'] !== '') {
                foreach ($xtforum['settingoverrides'] as $k => &$v) {
                    $mybb->settings[$k] = $v;
                }
            }
        }
        //if($forum['xthreads_firstpostattop']) {
        switch ($current_page) {
            case 'showthread.php':
                require_once MYBB_ROOT . 'inc/xthreads/xt_sthreadhooks.php';
                xthreads_showthread_firstpost();
                break;
            case 'newthread.php':
            case 'editpost.php':
                if ($mybb->input['previewpost']) {
                    $do_preload = true;
                    if ($current_page == 'editpost.php') {
                        global $thread;
                        // check if first post
                        $post = get_post((int) $mybb->input['pid']);
                        if (!empty($post)) {
                            $thread = get_thread($post['tid']);
                        }
                        $do_preload = !empty($thread) && $thread['firstpost'] == $post['pid'];
                    }
                    if ($do_preload) {
                        require_once MYBB_ROOT . 'inc/xthreads/xt_sthreadhooks.php';
                        xthreads_firstpost_tpl_preload();
                    }
                    break;
                }
        }
        //}
        // settings overrides
        if ($forum['xthreads_postsperpage']) {
            $mybb->settings['postsperpage'] = $forum['xthreads_postsperpage'];
        }
        // cache some more templates if necessary
        switch ($current_page) {
            case 'forumdisplay.php':
                if ($forum['xthreads_grouping']) {
                    $templatelist .= ',forumdisplay_group_sep,forumdisplay_thread_null';
                }
                if ($forum['xthreads_inlinesearch']) {
                    $templatelist .= ',forumdisplay_searchforum_inline';
                }
                if (function_exists('quickthread_run')) {
                    // Quick Thread plugin
                    $templatelist .= ',post_threadfields_inputrow';
                }
                break;
            case 'editpost.php':
                $templatelist .= ',editpost_first';
            case 'newthread.php':
                $templatelist .= ',post_threadfields_inputrow';
            case 'showthread.php':
                $templatelist .= ',showthread_threadfields,showthread_threadfield_row';
                break;
        }
        // hide breadcrumb business
        if ($current_page != 'printthread.php') {
            xthreads_breadcrumb_hack($fid);
        } else {
            // printthread needs some whacky attention
            $GLOBALS['plugins']->add_hook('printthread_start', 'xthreads_breadcrumb_hack_printthread', 10, MYBB_ROOT . 'inc/xthreads/xt_mischooks.php');
        }
        xthreads_set_threadforum_urlvars('forum', $forum['fid']);
    }
    if (isset($set_thread_urlvar)) {
        xthreads_set_threadforum_urlvars('thread', $set_thread_urlvar);
        // since it's convenient...
    }
}
Пример #2
0
function xthreads_tpl_forumbits(&$forum)
{
    static $done = false;
    global $templates;
    if (!$done) {
        $done = true;
        function xthreads_tpl_forumbits_tplget(&$obj, &$forum, $title, $eslashes, $htmlcomments)
        {
            if ($forum['xthreads_hideforum']) {
                // alternate the bgcolor if applicable (so we get no net change)
                if ($title == 'forumbit_depth1_cat' || $title == 'forumbit_depth2_cat' || $title == 'forumbit_depth2_forum') {
                    $GLOBALS['bgcolor'] = alt_trow();
                }
                return 'return "";';
            }
            global $forum_tpl_prefixes;
            if (!empty($forum_tpl_prefixes[$forum['fid']])) {
                foreach ($forum_tpl_prefixes[$forum['fid']] as &$p) {
                    if (isset($obj->cache[$p . $title]) && !isset($obj->non_existant_templates[$p . $title])) {
                        $title = $p . $title;
                        break;
                    }
                }
            }
            return 'return "' . $obj->xthreads_tpl_forumbits_get($title, $eslashes, $htmlcomments) . '";';
        }
        control_object($templates, '
			function get($title, $eslashes=1, $htmlcomments=1) {
				if(substr($title, 0, 9) != \'forumbit_\')
					return parent::get($title, $eslashes, $htmlcomments);
				return \'".eval(xthreads_tpl_forumbits_tplget($templates, $forum, \\\'\'.strtr($title, array(\'\\\\\' => \'\\\\\\\\\', \'\\\'\' => \'\\\\\\\'\')).\'\\\', \'.$eslashes.\', \'.$htmlcomments.\'))."\';
			}
			function xthreads_tpl_forumbits_get($title, $eslashes, $htmlcomments){
				return parent::get($title, $eslashes, $htmlcomments);
			}
		');
    }
    xthreads_set_threadforum_urlvars('forum', $forum['fid']);
}
Пример #3
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) . '";');
        }
    }
}