2008-08-09, 06:00 AM
How do I modify the Latest Poll code on Portal, $pollbox, to only get polls from a certain forum?
Here is the code for the latest poll box taken from portal.php.
Here is the code for the latest poll box taken from portal.php.
$lang->vote = "Vote!";
$lang->show_results = "Show results";
$options = array(
"order_by" => "dateline",
"order_dir" => "DESC"
);
$query = $db->simple_select(TABLE_PREFIX."polls", "*", "",$options);
$poll = $db->fetch_array($query);
$poll['timeout'] = $poll['timeout']*60*60*24;
$expiretime = $poll['dateline'] + $poll['timeout'];
$now = time();
// If the poll or the thread is closed or if the poll is expired, show the results.
if($poll['closed'] == "yes" || $thread['closed'] == "yes" || ($expiretime < $now && $poll['timeout'] > 0))
{
$showresults = 1;
}
// If the user is not a guest, check if he already voted.
if($mybb->user['uid'] != 0)
{
$query = $db->simple_select(TABLE_PREFIX."pollvotes", "*", "uid='".$mybb->user['uid']."' AND pid='".$poll['pid']."'");
while($votecheck = $db->fetch_array($query))
{
$alreadyvoted = 1;
$votedfor[$votecheck['voteoption']] = 1;
}
}
else
{
if($_COOKIE['pollvotes'][$poll['pid']])
{
$alreadyvoted = 1;
}
}
$optionsarray = explode("||~|~||", $poll['options']);
$votesarray = explode("||~|~||", $poll['votes']);
$poll['question'] = htmlspecialchars_uni($poll['question']);
$polloptions = '';
$totalvotes = 0;
for($i = 1; $i <= $poll['numoptions']; $i++)
{
$poll['totvotes'] = $poll['totvotes'] + $votesarray[$i-1];
}
// Loop through the poll options.
for($i = 1; $i <= $poll['numoptions']; ++$i)
{
// Set up the parser options.
$parser_options = array(
"allow_html" => $forum['allowhtml'],
"allow_mycode" => $forum['allowmycode'],
"allow_smilies" => $forum['allowsmilies'],
"allow_imgcode" => $forum['allowimgcode']
);
$option = $parser->parse_message($optionsarray[$i-1], $parser_options);
$votes = $votesarray[$i-1];
$totalvotes += $votes;
$number = $i;
// Mark the option the user voted for.
if($votedfor[$number])
{
$optionbg = "trow2";
$votestar = "*";
}
else
{
$optionbg = "trow1";
$votestar = "";
}
// If the user already voted or if the results need to be shown, do so; else show voting screen.
if($alreadyvoted || $showresults)
{
if(intval($votes) == "0")
{
$percent = "0";
}
else
{
$percent = number_format($votes / $poll['totvotes'] * 100, 2);
}
$imagewidth = round(($percent/3))+5;
eval("\$polloptions .= \"".$templates->get("showthread_poll_resultbit")."\";");
}
else
{
if($poll['multiple'] == "yes")
{
eval("\$polloptions .= \"".$templates->get("showthread_poll_option_multiple")."\";");
}
else
{
eval("\$polloptions .= \"".$templates->get("showthread_poll_option")."\";");
}
}
}
// If there are any votes at all, all votes together will be 100%;
//if there are no votes, all votes together will be 0%.
if($poll['totvotes'])
{
$totpercent = "100%";
}
else
{
$totpercent = "0%";
}
// Check if user is allowed to edit posts; if so, show "edit poll" link.
if(is_moderator($fid, 'caneditposts') != 'yes')
{
$edit_poll = '';
}
else
{
$edit_poll = " <a href=\"polls.php?action=editpoll&pid={$poll['pid']}\">Edit poll</a>";
}
// Decide what poll status to show depending on the status of the poll and whether or not the user voted already.
if($alreadyvoted || $showresults)
{
if($alreadyvoted)
{
$pollstatus = $lang->already_voted;
}
else
{
$pollstatus = $lang->poll_closed;
}
$lang->total_votes = sprintf($lang->total_votes, $totalvotes);
eval("\$pollbox = \"".$templates->get("showthread_poll_results")."\";");
$plugins->run_hooks("showthread_poll_results");
}
else
{
$publicnote = ' ';
if($poll['public'] == "yes")
{
$publicnote = $lang->public_note;
}
eval("\$pollbox = \"".$templates->get("showthread_poll")."\";");
}