Jump to content


Help...


1 reply to this topic

#1 5354

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 10 November 2007 - 06:24 AM

Hi guys, I need help to get the code from a MyBB plugin and make it work separately unlike the plugin. I am trying to build my site around the forum and not using forum as the main side.

My main motive is like in this thread, pulling news from the site and displaying it on the homepage.
I want to do the similar thing as well for poll, but I found it in a plugin rather than a tutorial like that, I hope someone can retrieve the plugin code and make it like the one for pulling news.

Plugin Code:
<?php
/*

 * Latest Poll In SideBox for MyBB 1.2.9
 * By: LeX-
 * Website: http://www.thingiej.be
 * Version: 1.0

*/

// ADD HOOK FOR INDEX
$plugins->add_hook('index_end', 'lpis');


function lpis_info()
{
	return array(
		'name'			=> 'Latest Poll In Sidebox On Index',
		'description'	=> 'Shows The Latest Poll In A SideBox On Your Index Page.',
		'website'		=> 'http://www.thingiej.be/',
		'author'		=> 'LeX-',
		'authorsite'	=> 'http://www.thingiej.be/',
		'version'		=> '1.0',
	);
}

function lpis_activate()
{
	global $db, $mybb, $cache;
	$plugincache = $cache->read("plugins");
	if(!$plugincache['active']['sideboxes'])
	{
		cperror("Errrrr, Seems Like The Sidebox Plugin By Zaher Aint Activated ...","Error While Activating");
	}
}

function lpis_deactivate()
{
}

function lpis()
{
	global $db, $mybb, $latestpoll ,$theme, $templates, $lang, $sb_lp;

	if($mybb->user['uid'] != 0)
	{
		require_once MYBB_ROOT."inc/class_parser.php";
		$parser = new postParser;

		$lang->load("showthread");
		$query = $db->query("SELECT * FROM `".TABLE_PREFIX."polls` WHERE closed!='yes' ORDER BY `dateline` DESC LIMIT 1");
		$poll = $db->fetch_array($query);
		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];
		}
		for($i = 1; $i <= $poll['numoptions']; ++$i)
		{
			$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;

			if($votedfor[$number])
			{
				$optionbg = "trow2";
				$votestar = "*";
			}
			else
			{
				$optionbg = "trow1";
				$votestar = "";
			}

			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($poll['totvotes'])
		{
			$totpercent = "100%";
		}
		else
		{	
			$totpercent = "0%";
		}

		if($alreadyvoted || $showresults)
		{
			if($alreadyvoted)
			{
				$pollstatus = $lang->already_voted;
			}
			else
			{
			$pollstatus = $lang->poll_closed;
			}
			$lang->total_votes = sprintf($lang->total_votes, $totalvotes);
			eval("\$latestpoll = \"".$templates->get("showthread_poll_results")."\";");
		}
		else
		{
			eval("\$latestpoll = \"".$templates->get("showthread_poll")."\";");
		}
	
		if(!$latestpoll)
		{
			$latestpoll = "No Poll";
		}

		$sb_lp = "<table border=\"0\" cellspacing=\"1\" cellpadding=\"4\" class=\"tborder\">
	<tr>
	<td class=\"thead\"><strong>Latest Poll</strong></td>
	</tr>
	<tr>
	<td class=\"trow1\">{$latestpoll}</td>
	</tr>
	</table>
	<br />";
	}
}

?>


#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 10 November 2007 - 01:53 PM

Are you asking for somebody to do all the work for you? If so, then this isn't quite the right forum for this.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users