コード例 #1
0
ファイル: xt_sthreadhooks.php プロジェクト: sunnybutani/webc
function xthreads_showthread_firstpost()
{
    global $mybb, $templatelist;
    // don't do this if using threaded mode
    if (isset($mybb->input['mode'])) {
        $threaded = $mybb->input['mode'] == 'threaded';
    } elseif (!empty($mybb->user['threadmode'])) {
        $threaded = $mybb->user['threadmode'] == 'threaded';
    } else {
        $threaded = $mybb->settings['threadusenetstyle'] == 1;
    }
    if ($threaded) {
        return;
    }
    global $db;
    xthreads_firstpost_tpl_preload();
    $templatelist .= ',showthread_noreplies';
    function xthreads_tpl_firstpost_moveout()
    {
        global $posts;
        static $done = false;
        if ($done) {
            return;
        }
        $done = true;
        $GLOBALS['first_post'] = $posts;
        $posts = '';
        // uh... what's this next line here for again?
        //$GLOBALS['plugins']->remove_hook('showthread_start', 'xthreads_showthread_firstpost_hack');
    }
    function xthreads_tpl_firstpost_noreplies()
    {
        global $posts;
        // execute this in case there's only one post in the thread
        xthreads_tpl_firstpost_moveout();
        if (!$posts) {
            eval('$posts = "' . $GLOBALS['templates']->get('showthread_noreplies') . '";');
        }
    }
    function xthreads_tpl_postbitrestore()
    {
        global $templates, $xthreads_postbit_templates, $page;
        foreach ($xthreads_postbit_templates as &$t) {
            $pbname = substr($t, 7);
            if (!$pbname) {
                $pbname = '';
            }
            if (isset($templates->cache['postbit_first' . $pbname]) && !isset($templates->non_existant_templates['postbit_first' . $pbname])) {
                $templates->cache[$t] = $templates->cache['backup_postbit' . $pbname . '_backup__'];
            }
        }
        // whilst we're here, add the necessary plugin hook
        $GLOBALS['plugins']->add_hook('postbit', 'xthreads_tpl_firstpost_moveout');
        $GLOBALS['plugins']->add_hook('showthread_linear', 'xthreads_tpl_firstpost_noreplies');
        // don't forget to fix the postcounter too!
        if ($page > 1) {
            global $mybb;
            if (!$mybb->settings['postsperpage']) {
                $mybb->settings['postsperpage'] = 20;
            }
            $GLOBALS['postcounter'] = $mybb->settings['postsperpage'] * ($page - 1);
        }
    }
    function xthreads_showthread_firstpost_hack()
    {
        if (xthreads_tpl_postbithack()) {
            // *sigh* no other way to do this other than to hack the templates object again... >_>
            control_object($GLOBALS['templates'], '
				function get($title, $eslashes=1, $htmlcomments=1) {
					static $done=false;
					if(!$done && ($title == \'postbit\' || $title == \'postbit_classic\')) {
						$done = true;
						$r = parent::get($title, $eslashes, $htmlcomments);
						xthreads_tpl_postbitrestore();
						//return str_replace(\'{$post_extra_style}\', \'border-top-width: 0;\', $r);
						return \'".($post_extra_style="border-top-width: 0;"?"":"")."\'.$r;
					} else
						return parent::get($title, $eslashes, $htmlcomments);
				}
			');
        }
    }
    //$GLOBALS['plugins']->add_hook('showthread_start', 'xthreads_showthread_firstpost_hack');
    // and now actually do the hack to display the first post on each page
    if ($GLOBALS['forum']['xthreads_firstpostattop']) {
        // would be great if we had a reliable way to determine if we're on the first page here
        $db->xthreads_firstpost_hack = false;
        // this is a dirty hack we probably shouldn't be relying on (but eh, it works)
        // basically '-0' evaluates to true, effectively skipping the check in build_postbit()
        // but when incremented, becomes 1
        $GLOBALS['postcounter'] = '-0';
        $extra_code = '
			function fetch_array($query, $resulttype=1) { // 1 == MYSQL_ASSOC == MYSQLI_ASSOC == PGSQL_ASSOC
				if($this->xthreads_firstpost_hack) {
					$this->xthreads_firstpost_hack = false;
					return array(\'pid\' => $GLOBALS[\'thread\'][\'firstpost\']);
				}
				return parent::fetch_array($query, $resulttype);
			}
		';
        $firstpost_hack_code = 'if($options[\'limit_start\']) $this->xthreads_firstpost_hack = true;';
    } else {
        $extra_code = '';
        $firstpost_hack_code = 'if(!$options[\'limit_start\'])';
    }
    control_object($db, '
		function simple_select($table, $fields=\'*\', $conditions=\'\', $options=array()) {
			static $done=false;
			if(!$done && $table == \'posts p\' && $fields == \'p.pid\' && $options[\'order_by\'] == \'p.dateline\') {
				$done = true;
				' . $firstpost_hack_code . '
					xthreads_showthread_firstpost_hack();
			}
			return parent::simple_select($table, $fields, $conditions, $options);
		}
		' . $extra_code . '
	');
}
コード例 #2
0
ファイル: xthreads.php プロジェクト: sammykumar/TheVRForums
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...
    }
}