MyBB Community Forums

Full Version: Portal Recent Threads - If thread contains a poll, show whether user has voted
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Would be easy if you share the file that worked for you before starting making edits. I can't really see anything wrong.
Ok, here is the working code I was using when I first made this thread Smile

<?php 

define('IN_MYBB', 1); require "./global.php";

add_breadcrumb("Polls", "nlpolls.php"); 

// get forums user cannot view
$unviewable = get_unviewable_forums(true);
if($unviewable)
{
        $unviewwhere = " AND fid NOT IN ($unviewable)";
}

        $altbg = alt_trow();
        $threadlist = '';
$query = $db->query("
                SELECT t.*, u.username, u.displaygroup, u.avatar, u.usergroup, u.avatardimensions, f.name AS forumname, lp.avatar as lpavatar, t.username AS threadusername
                FROM ".TABLE_PREFIX."threads t
                LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
                LEFT JOIN ".TABLE_PREFIX."users lp ON (lp.uid=t.lastposteruid)
                LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=t.fid)    
                WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.poll > 0 
                ORDER BY t.lastpost DESC
                LIMIT 0, 10"
        );
        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($thread['lpavatar'])
        {
        $thread['lpavatar'] = htmlspecialchars_uni($thread['lpavatar']);
        }
        else
        {
        $thread['lpavatar'] = $mybb->settings['bburl']."/images/default_avatar.gif"; $thread['avatardimensions'] = "45|45";
        }
        if($thread['avatar'])
        {
        $thread['avatar'] = htmlspecialchars_uni($thread['avatar']);
        }
        else
        {
        $thread['avatar'] = $mybb->settings['bburl']."/images/default_avatar.gif"; $thread['avatardimensions'] = "45|45";
        }
        
                if(my_strlen($thread['subject']) > 100)
                {
                        $thread['subject'] = my_substr($thread['subject'], 0, 100) . "...";
                }
                $thread['subject'] = htmlspecialchars_uni($thread['subject']);
                $thread['threadlink'] = get_thread_link($thread['tid']);
                $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
                $thread['username'] = $thread['threadusername'];
                $threadstarter = build_profile_link($thread['username'], $thread['uid']);
                $thread['profilelink'] = $thread['threadusername'];    
                eval("\$threadlist .= \"".$templates->get("portal_latestpolls_poll")."\";");
                $altbg = alt_trow();
                
                
        }
        if($threadlist)
        {
                // Show the table only if there are threads
                eval("\$nlpolls = \"".$templates->get("portal_latestpolls")."\";");
        } 
        
    
    
eval("\$html = \"".$templates->get("nintendolounge_polls")."\";"); 

output_page($html);

?>
Try this:
<?php 

define('IN_MYBB', 1); require "./global.php";

add_breadcrumb("Polls", "nlpolls.php"); 

// get forums user cannot view
$unviewable = get_unviewable_forums(true);
if($unviewable)
{
        $unviewwhere = " AND fid NOT IN ($unviewable)";
}

        $altbg = alt_trow();
        $threadlist = '';
$query = $db->query("
                SELECT t.*, u.username, u.displaygroup, u.avatar, u.usergroup, u.avatardimensions, f.name AS forumname, lp.avatar as lpavatar, t.username AS threadusername
                FROM ".TABLE_PREFIX."threads t
                LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
                LEFT JOIN ".TABLE_PREFIX."users lp ON (lp.uid=t.lastposteruid)
                LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=t.fid)    
                WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.poll > 0 
                ORDER BY t.lastpost DESC
                LIMIT 0, 10"
        );
/*******/
$pids = $polls = $votes = array();
while($pid = $db->fetch_field($query, 'poll'))
{
    $pids[] = (int)$pid;
}

$query_p = $db->simple_select('polls', 'pid, numvotes', "pid IN ('".implode("','", $pids)."')");
while($poll = $db->fetch_array($query_p))
{
    $polls[(int)$poll['pid']] = (int)$poll['numvotes'];
}

$query_p = $db->simple_select('pollvotes', 'pid', "pid IN ('".implode("','", $pids)."') AND uid='{$mybb->user['uid']}'");
while($vote = $db->fetch_field($query_p, 'pid'))
{
    $votes[(int)$vote['pid']] = 1;
}
/*******/
        while($thread = $db->fetch_array($query))
        {    
		/*******/
		$votes = 'This poll has '.my_number_format($polls[(int)$poll['pid']]).' votes.';
		$mark = '';
		if(isset($votes[(int)$thread['poll']]))
		{
			$mark = '<span title="You already voted for this poll.">*</span>';
		}
		/*******/

                $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($thread['lpavatar'])
        {
        $thread['lpavatar'] = htmlspecialchars_uni($thread['lpavatar']);
        }
        else
        {
        $thread['lpavatar'] = $mybb->settings['bburl']."/images/default_avatar.gif"; $thread['avatardimensions'] = "45|45";
        }
        if($thread['avatar'])
        {
        $thread['avatar'] = htmlspecialchars_uni($thread['avatar']);
        }
        else
        {
        $thread['avatar'] = $mybb->settings['bburl']."/images/default_avatar.gif"; $thread['avatardimensions'] = "45|45";
        }
        
                if(my_strlen($thread['subject']) > 100)
                {
                        $thread['subject'] = my_substr($thread['subject'], 0, 100) . "...";
                }
                $thread['subject'] = htmlspecialchars_uni($thread['subject']);
                $thread['threadlink'] = get_thread_link($thread['tid']);
                $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
                $thread['username'] = $thread['threadusername'];
                $threadstarter = build_profile_link($thread['username'], $thread['uid']);
                $thread['profilelink'] = $thread['threadusername'];    
                eval("\$threadlist .= \"".$templates->get("portal_latestpolls_poll")."\";");
                $altbg = alt_trow();
                
                
        }
        if($threadlist)
        {
                // Show the table only if there are threads
                eval("\$nlpolls = \"".$templates->get("portal_latestpolls")."\";");
        } 
        
    
    
eval("\$html = \"".$templates->get("nintendolounge_polls")."\";"); 

output_page($html);

?>
Nope, no threads appear with that code.
May you provide us with temporary FTP access to your forum files? If so please do so here where only staff and yourself can view your threads. Please do add a link back to this thread in the OP as well.
Done Smile
EDIT: Shouldn't have bumped this thread.
how to choose one particular forum only?
Depends on the code you are using.
Pages: 1 2 3