MyBB Community Forums

Full Version: sb.php >> alterations
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey everyone,
I am looking to make an alteration to minimize the amount of latest threads displayed in the sidebar over at :
http://www.wiiroom.net

Here is the relevant current PHP:

<?php
$lang->load("portal");

$unviewable = get_unviewable_forums();
if($unviewable)
{
	$unviewwhere = " AND fid NOT IN ($unviewable)";
}
// If user is known, welcome them
if($mybb->settings['portal_showwelcome'] != "no")
{
	if($mybb->user['uid'] != 0)
	{
		if($mybb->user['receivepms'] != "no" && $mybb->usergroup['canusepms'] != "no" && $mybb->settings['portal_showpms'] != "no")
		{
			$query = $db->query("SELECT COUNT(*) AS pms_total, SUM(IF(dateline>'".$mybb->user['lastvisit']."' AND folder='1','1','0')) AS pms_new, SUM(IF(status='0' AND folder='1','1','0')) AS pms_unread FROM ".TABLE_PREFIX."privatemessages WHERE uid='".$mybb->user['uid']."'");
			$messages = $db->fetch_array($query);
			if(!$messages['pms_new'])
			{
				$messages['pms_new'] = 0;
			}
			// the SUM() thing returns "" instead of 0
			if($messages['pms_unread'] == "")
			{
				$messages['pms_unread'] = 0;
			}
			$lang->pms_received_new = sprintf($lang->pms_received_new, $mybb->user['username'], $messages['pms_new']);
			eval("\$pms = \"".$templates->get("portal_pms")."\";");
		}
		// get number of new posts, threads, announcements
		$query = $db->simple_select(TABLE_PREFIX."posts", "COUNT(pid) AS newposts", "dateline>'".$mybb->user['lastvisit']."' $unviewwhere");
		$newposts = $db->fetch_field($query, "newposts");
		if($newposts)
		{ // if there aren't any new posts, there is no point in wasting two more queries
			$query = $db->simple_select(TABLE_PREFIX."threads", "COUNT(tid) AS newthreads", "dateline>'".$mybb->user['lastvisit']."' $unviewwhere");
			$newthreads = $db->fetch_field($query, "newthreads");
			$query = $db->simple_select(TABLE_PREFIX."threads", "COUNT(tid) AS newann", "dateline>'".$mybb->user['lastvisit']."' AND fid IN (".$mybb->settings['portal_announcementsfid'].") $unviewwhere");
			$newann = $db->fetch_field($query, "newann");
			if(!$newthreads)
			{
				$newthreads = 0;
			}
			if(!$newann)
			{
				$newann = 0;
			}
		}
		else
		{
			$newposts = 0;
			$newthreads = 0;
			$newann = 0;
		}

		// Make the text
		if($newann == 1)
		{
			$lang->new_announcements = $lang->new_announcement;
		}
		else
		{
			$lang->new_announcements = sprintf($lang->new_announcements, $newann);
		}
		if($newthreads == 1)
		{
			$lang->new_threads = $lang->new_thread;
		}
		else
		{
			$lang->new_threads = sprintf($lang->new_threads, $newthreads);
		}
		if($newposts == 1)
		{
			$lang->new_posts = $lang->new_post;
		}
		else
		{
			$lang->new_posts = sprintf($lang->new_posts, $newposts);
		}
		eval("\$welcometext = \"".$templates->get("portal_welcome_membertext")."\";");

	}
	else
	{
		$lang->guest_welcome_registration = sprintf($lang->guest_welcome_registration, $mybb->settings['bburl'] . '/member.php?action=register');
		$mybb->user['username'] = $lang->guest;
		eval("\$welcometext = \"".$templates->get("portal_welcome_guesttext")."\";");
	}
	$lang->welcome = sprintf($lang->welcome, $mybb->user['username']);
	eval("\$welcome = \"".$templates->get("portal_welcome")."\";");
	if($mybb->user['uid'] == 0)
	{
		$mybb->user['username'] = "";
	}
}

// Get Forum Statistics
if($mybb->settings['portal_showstats'] != "no")
{
	$stats = $cache->read("stats");
	$threadsnum = $stats['numthreads'];
	$postsnum = $stats['numposts'];
	$membersnum = $stats['numusers'];
	if(!$stats['lastusername'])
	{
		$newestmember = "<b>" . $lang->no_one . "</b>";
	}
	else
	{
		$newestmember = "<a href=\"".$mybb->settings[bburl]."/member.php?action=profile&uid=$stats[lastuid]\">$stats[lastusername]</a>";
	}
	eval("\$stats = \"".$templates->get("portal_stats")."\";");
}
// Search box
if($mybb->settings['portal_showsearch'] != "no")
{
	eval("\$search = \"".$templates->get("portal_search")."\";");
}


if($mybb->settings['portal_showdiscussions'] != "no" && $mybb->settings['portal_showdiscussionsnum'])
{
	$altbg = "trow1";
	$threadlist = '';
	$query = $db->query("
		SELECT t.*, u.username
		FROM ".TABLE_PREFIX."threads t
		LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
		WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
		ORDER BY t.lastpost DESC 
		LIMIT 0, ".$mybb->settings['portal_showdiscussionsnum']
	);
	while($thread = $db->fetch_array($query))
	{
		$lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
		$lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
		// Don't link to guest's profiles (they have no profile).
		if($thread['lastposteruid'] == 0)
		{
			$lastposterlink = $thread['lastposter'];
		}
		else
		{
			$lastposterlink = build_profile_link($thread['lastposter'], $thread['lastposteruid']);
		}
		if(my_strlen($thread['subject']) > 25)
		{
			$thread['subject'] = my_substr($thread['subject'], 0, 25) . "...";
		}
		$thread['subject'] = htmlspecialchars_uni($thread['subject']);
		eval("\$threadlist .= \"".$templates->get("portal_latestthreads_thread")."\";");
		$altbg = alt_trow();
	}
	if($threadlist)
	{ // show the table only if there are threads
		eval("\$latestthreads = \"".$templates->get("portal_latestthreads")."\";");
	}
}
?>
Alex.
Well, I could tell you how to hand edit it to get the desired effect, but it's easier to change the setting. Go to Admin panel->Board settings->Change->Portal settings->Number of latest discussions to show. Change that number to whatever you want. Lol. Remember that most settings are actually in templates or in the Board settings widget, not in the PHP itself.
Hello there..
Please take note that there is a newer version of the plugin you are using.. Look here.

Regarding the amount, it is not specified the way coolv.I will make sure by next version to make it Side Boxes! own settings, i donno how i missed thisToungue

regards
Oh. So that is a plugin... I am confused. I thought that this had something to do with portal.php. In that case, go to the following php code, which is at the bottom:

if($mybb->settings['portal_showdiscussions'] != "no" && $mybb->settings['portal_showdiscussionsnum'])
{
    $altbg = "trow1";
    $threadlist = '';
    $query = $db->query("
        SELECT t.*, u.username
        FROM ".TABLE_PREFIX."threads t
        LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
        WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
        ORDER BY t.lastpost DESC 
        LIMIT 0, ".$mybb->settings['portal_showdiscussionsnum']
    );
    while($thread = $db->fetch_array($query))
    {
        $lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
        $lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
        // Don't link to guest's profiles (they have no profile).
        if($thread['lastposteruid'] == 0)
        {
            $lastposterlink = $thread['lastposter'];
        }
        else
        {
            $lastposterlink = build_profile_link($thread['lastposter'], $thread['lastposteruid']);
        }
        if(my_strlen($thread['subject']) > 25)
        {
            $thread['subject'] = my_substr($thread['subject'], 0, 25) . "...";
        }
        $thread['subject'] = htmlspecialchars_uni($thread['subject']);
        eval("\$threadlist .= \"".$templates->get("portal_latestthreads_thread")."\";");
        $altbg = alt_trow();
    }
    if($threadlist)
    { // show the table only if there are threads
        eval("\$latestthreads = \"".$templates->get("portal_latestthreads")."\";");
    }
}

and then edit the query at the top, namely the part that currently says:

LIMIT 0, ".$mybb->settings['portal_showdiscussionsnum']

change it in such a way, that for example if you wanted for there to be 2 threads, it would become:

LIMIT 0, 2"

I hope that you understand what I mean...

Alternatively, you can make your own setting group for that...

EDIT: Btw, judging from the screenshot posted at your website, you have the word "sponsors" spelled incorrectly. You wrote "sponsers". Wink

EDIT 2: By the way, the shoutbox on your portal page is not aligned with the other box on the right-hand side.

EDIT 3: Right after I made edit 2, there was some king of SQL error shwoing up as the text of my post... when I refreshed again, the entire page was an error... and then the error disappeared, along with my message, so I had to type it again (that is I had to type edit 2 again)...
Quote:I hope that you understand what I mean...

Alternatively, you can make your own setting group for that...
I know how to do it... just didn't remember to include it in the plugin.

Quote:EDIT: Btw, judging from the screenshot posted at your website, you have the word "sponsors" spelled incorrectly. You wrote "sponsers".
The screen shot is from someone's website.. the 1st to use side boxes.


Quote:: By the way, the shoutbox on your portal page is not aligned with the other box on the right-hand side
It is centered.


Quote:EDIT 3: Right after I made edit 2, there was some king of SQL error shwoing up as the text of my post... when I refreshed again, the entire page was an error... and then the error disappeared, along with my message, so I had to type it again (that is I had to type edit 2 again)...


   ORDER BY t.lastpost DESC 
        LIMIT 0, 2"
    );

If its end is like this there shoudl be no error
thanks everyone, so sorry im a tad confused, what should I do to get this working?
Alex
open ./inc/plugins/sideboxes.php

find

$query = $db->query("
			SELECT t.*, u.username
			FROM ".TABLE_PREFIX."threads t
			LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
			WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
			ORDER BY t.lastpost DESC 
			LIMIT 0, ".$mybb->settings['portal_showdiscussionsnum']
		);

replace with

$query = $db->query("
			SELECT t.*, u.username
			FROM ".TABLE_PREFIX."threads t
			LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
			WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
			ORDER BY t.lastpost DESC 
			LIMIT 0, X"
		);

Change X to the number you want.

it should work.
thanks zaher!!
by the way I think i will have the best MyBB skin ever soon ill show you all later.
Alex.
No problem.. waiting and wishing you luckWink welcome to mybb.
Grrr. Way to steal my suggestion!

BTW, I meant that there was an error in mybboard.net, not in the modification. Also, I was referring to wiiroom with my post.