MyBB Community Forums

Full Version: Last poll on portal page?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there,

I think it might be interesting to have the last poll (or poll results if answered) as a part of the portal, as the search or the who's online block.
HELLO,

Open portal.php

Find

eval("\$portal = \"".$templates->get("portal")."\";");
Above it add
$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&amp;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 = '&nbsp;';
			if($poll['public'] == "yes")
			{
				$publicnote = $lang->public_note;
			}
			eval("\$pollbox = \"".$templates->get("showthread_poll")."\";");
		}

Now in the portal template
Find
{$latestthreads}
Below it add
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}">
<tr><td>{$pollbox}</td></tr>
</table>
<br />
I can't use the above script (it not show the last poll on index page). Can you use it, Mr. CrazyCat?
Well this is made for portal.
You can use the same code, however in index.php. The search terms will be different however, for example in index.php find

eval("\$index = \"".$templates->get("index")."\";");
And place the php code mentioned above above it.

In index template which can be found in Admin CP > Templates > Modify / Delete >EXPAND > Index page templates

You have to add the HTML code i have mentioned above in the proper place you find that will suit your vision of the template. You might need to do some changes to fit it in some place in the index page.

Regards
Thank you very much Smile
Now, it's good work!
Hi, This works great but it looks out of align with the other boxes on the portal how can i make it look all the same.

http://www.tussaudtimes.co.uk/portal.php