MyBB Community Forums

Full Version: Website Integration
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7
chdir("forums"); // path to MyBB
require "./global.php";

if($mybb->user['uid'])
{
  // logged in
}
else
{
  // logged out
}

I use that code, but I get some wierd error.
http://gamesrule.mihopa.com/test.php
You must call these functions or include MyBB BEFORE any content is sent to the browser.

For example, your:

chdir("forums"); // path to MyBB
require "./global.php";

Would need to go up above the output of any data. You can then use the conditional down further.
Thanks. Smile
I am using this code.
<?php

if($mybb->user['uid'])
{
  // logged in
	Thanks
}
else
{
  // logged out
<form action="forums/member.php" method="post">
Username: <input type="text" name="username" size="25" maxlength="30" /><br />
Password: <input type="password" name="password" size="25" />
<input type="hidden" name="action" value="do_login">
<input type="hidden" name="url" value="index.php" />
<input type="submit" class="submit" name="submit" value="Login" /> <br>
<br>
You may login with your forum username and password when you registered.<br>
<br>
If you haven't Registered, Please do so by clicking
<a href="forums/member.php?action=register">here</a>.<br>
<br>
Please note we do not openly distribute your details.</form>
}
?>

See the outcome. Sad
http://gamesrule.mihopa.com/test.php
Nvm, works.
How do I tell if the user has a new PM and then insert onload="java script:newPM()" into the body tag? This is what mybb does ans I want to have this feature in my web site. Also, how do I display how many users are online, and I do I also display their usernames like how mybb does.
Quote:16 users active in the past 15 minutes (1 members, 0 of whom are invisible, and 0 guests).
usernames here with link to their profile page
Just a note, I am including the global.php with this code:
chdir("forum"); // path to MyBB
require "./global.php";

Thanks for the help. Smile
MyBB sets $loadpmpopup if a user has a new PM.

If you wish to show it, you could do something like the following:

	if($loadpmpopup)
	{
		$onload = "onload=\"javascript:newPM();\"";
	}

Then in your body tag, add $onload.

(You also have to replace the javascript: in the above code with a version without a space)

For the Who's Online, I'd also recommend, as I mentioned before, taking a look at the code in portal.php beginning line 159 - and just lift out what you need.
Hmmm..
In who's online, it gives "Unknown Location" and links to pages out of my forum. (Home page, etc.)
How do I make unknown location into "GameZRule Index" if the file name (on the root, not forum) is index.php?
I'm using this code, and nothing is showing up on my page. Sad
<?php if($mybb->settings['portal_showwol'] != "no")
{
	$timesearch = time() - $mybb->settings['wolcutoff'];
	$comma = "";
	$guestcount = 0;
	$membercount = 0;
	$query = $db->query("SELECT s.sid, s.ip, s.uid, s.time, s.location, u.username, u.invisible, u.usergroup, u.displaygroup FROM ".TABLE_PREFIX."sessions s LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid) WHERE s.time>'$timesearch' ORDER BY u.username ASC, s.time DESC");
	while($user = $db->fetch_array($query))
	{
		if($user['uid'] == "0")
		{
			$guestcount++;
		}
		else
		{
			if($doneusers[$user['uid']] < $user['time'] || !$doneusers[$user['uid']])
			{
				$doneusers[$user['uid']] = $user['time'];
				$membercount++;
				if($user['invisible'] != "yes" || $mybb->usergroup['canviewwolinvis'] == "yes")
				{
					if($user['invisible'] == "yes")
					{
						$invisiblemark = "*";
					}
					else
					{
						$invisiblemark = "";
					}
					$user['username'] = formatname($user['username'], $user['usergroup'], $user['displaygroup']);
					eval("\$onlinemembers .= \"".$templates->get("portal_whosonline_memberbit", 1, 0)."\";");
					$comma = ", ";
				}
			}
		}
	}
	$onlinecount = $membercount + $guestcount + $anoncount;

	// Most users online
	$mostonline = $cache->read("mostonline");
	if($onlinecount > $mostonline['numusers'])
	{
		$time = time();
		$mostonline['numusers'] = $onlinecount;
		$mostonline['time'] = $time;
		$cache->update("mostonline", $mostonline);
	}
	$recordcount = $mostonline['numusers'];
	$recorddate = mydate($mybb->settings['dateformat'], $mostonline['time']);
	$recordtime = mydate($mybb->settings['timeformat'], $mostonline['time']);

	$lang->online_users = sprintf($lang->online_users, $onlinecount);
	$lang->online_counts = sprintf($lang->online_counts, $membercount, $guestcount);
	eval("\$whosonline = \"".$templates->get("portal_whosonline")."\";");
}

// Latest forum discussions
if($mybb->settings['portal_showdiscussions'] != "no" && $mybb->settings['portal_showdiscussionsnum'])
{
	$altbg = "trow1";
	$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))
	{

		if($thread['lastpost'] != "" && $thread['lastposter'] != "")
		{
			$lastpostdate = mydate($mybb->settings['dateformat'], $thread['lastpost']);
			$lastposttime = mydate($mybb->settings['timeformat'], $thread['lastpost']);
			eval("\$lastpost = \"".$templates->get("portal_latestthreads_thread_lastpost")."\";");
		}
		else
		{
			$lastpost = "";
		}
		$thread['subject'] = stripslashes($thread['subject']);
		if(strlen($thread['subject']) > 25)
		{
			$thread['subject'] = substr($thread['subject'], 0, 25) . "...";
		}
		$thread['subject'] = htmlspecialchars_uni($thread['subject']);
		eval("\$threadlist .= \"".$templates->get("portal_latestthreads_thread")."\";");
		if($altbg == "trow1")
		{
			$altbg = "trow2";
		}
		else
		{
			$altbg = "trow1";
		}
	}
	if($threadlist)
	{ // show the table only if there are threads
		eval("\$latestthreads = \"".$templates->get("portal_latestthreads")."\";");
	}
}

// Get latest news announcements
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."forums WHERE fid='".$mybb->settings['portal_announcementsfid']."'");
$forum = $db->fetch_array($query);

$pids = "";
$comma="";
$query = $db->query("SELECT p.pid, p.message, p.tid FROM ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid AND t.dateline=p.dateline) WHERE t.fid='".$mybb->settings['portal_announcementsfid']."' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' ORDER BY t.dateline DESC LIMIT 0, ".$mybb->settings['portal_numannouncements']);
while($getid = $db->fetch_array($query))
{
	$pids .= ",'$getid[pid]'";
	$posts[$getid['tid']] = $getid;
}
$pids = "pid IN(0$pids)";
// Now lets fetch all of the attachments for these posts
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."attachments WHERE $pids");
while($attachment = $db->fetch_array($query))
{
	$attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
}

$forumpermissions = forum_permissions($mybb->settings['portal_announcementsfid']);
$query = $db->query("SELECT t.*, i.name as iconname, i.path as iconpath, t.username AS threadusername, u.username, u.avatar FROM ".TABLE_PREFIX."threads t LEFT JOIN ".TABLE_PREFIX."icons i ON (i.iid = t.icon) LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid) WHERE fid='".$mybb->settings['portal_announcementsfid']."' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' ORDER BY t.dateline DESC LIMIT 0, ".$mybb->settings['portal_numannouncements']);
while($announcement = $db->fetch_array($query))
{
	$announcement['message'] = $posts[$announcement['tid']]['message'];
	$announcement['pid'] = $posts[$announcement['tid']]['pid'];
	$announcement['author'] = $announcement['uid'];
	if(!$announcement['username'])
	{
		$announcement['username'] = $announcement['threadusername'];
	}
	$announcement['subject'] = htmlspecialchars_uni(stripslashes($announcement['subject']));
	if($announcement['iconpath'])
	{
		$icon = "<img src=\"$announcement[iconpath]\" alt=\"$announcement[iconname]\">";
	}
	else
	{
		$icon = "&nbsp;";
	}
	if($announcement['avatar'] != "")
	{
		$avatar = "<td class=\"trow\" class=\"trow1\" width=1 align=\"center\" valign=\"top\"><img src=\"$announcement[avatar]\"></td>";
	}
	else
	{
		$avatar = "";
	}
	$anndate = mydate($mybb->settings['dateformat'], $announcement['dateline']);
	$anntime = mydate($mybb->settings['timeformat'], $announcement['dateline']);

	if($announcement['replies'])
	{
		eval("\$numcomments = \"".$templates->get("portal_announcement_numcomments")."\";");
	}
	else
	{
		eval("\$numcomments = \"".$templates->get("portal_announcement_numcomments_no")."\";");
		$lastcomment = "";
	}
	if(is_array($attachcache[$announcement['pid']]))
	{ // This post has 1 or more attachments
		$validationcount = 0;
		$id = $announcement['pid'];
		foreach($attachcache[$id] as $aid => $attachment)
		{
			if($attachment['visible'])
			{ // There is an attachment thats visible!
				$attachment['name'] = htmlspecialchars_uni($attachment['name']);
				$attachment['filesize'] = getfriendlysize($attachment['filesize']);
				$ext = getextention($attachment['filename']);
				if($ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg")
				{
					$isimage = true;
				}
				else
				{
					$isimage = false;
				}
				$attachment['icon'] = getattachicon($ext);
				// Support for [attachment=id] code
				if(stripos($announcement['message'], "[attachment=".$attachment['aid']."]") !== false)
				{
					if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != "")
					{ // We have a thumbnail to show (and its not the "SMALL" enough image
						eval("\$attbit = \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
					}
					elseif($attachment['thumbnail'] == "SMALL" && $forumpermissions['candlattachments'] == "yes")
					{
						// Image is small enough to show - no thumbnail
						eval("\$attbit = \"".$templates->get("postbit_attachments_images_image")."\";");
					}
					else
					{
						// Show standard link to attachment
						eval("\$attbit = \"".$templates->get("postbit_attachments_attachment")."\";");
					}
					$announcement['message'] = preg_replace("#\[attachment=".$attachment['aid']."]#si", $attbit, $announcement['message']);
				}
				else
				{
					if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != "")
					{ // We have a thumbnail to show
						eval("\$post['thumblist'] .= \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
						if($tcount == 5)
						{
							$thumblist .= "<br />";
							$tcount = 0;
						}
						$tcount++;
					}
					elseif($attachment['thumbnail'] == "SMALL" && $forumpermissions['candlattachments'] == "yes")
					{
						// Image is small enough to show - no thumbnail
						eval("\$post['imagelist'] .= \"".$templates->get("postbit_attachments_images_image")."\";");
					}
					else
					{
						eval("\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment")."\";");
					}
				}
			}
			else
			{
				$validationcount++;
			}
		}
		if($post['thumblist'])
		{
			eval("\$post['attachedthumbs'] = \"".$templates->get("postbit_attachments_thumbnails")."\";");
		}
		if($post['imagelist'])
		{
			eval("\$post['attachedimages'] = \"".$templates->get("postbit_attachments_images")."\";");
		}
		if($post['attachmentlist'] || $post['thumblist'] || $post['imagelist'])
		{
			eval("\$post['attachments'] = \"".$templates->get("postbit_attachments")."\";");
		}
	}

	$plugins->run_hooks("portal_announcement");

	$message = postify($announcement['message'], $forum['allowhtml'], $forum['allowmycode'], $forum['allowsmilies'], $forum['allowimgcode']);
	eval("\$announcements .= \"".$templates->get("portal_announcement")."\";");
	unset($post);
}
eval("\$portal = \"".$templates->get("portal")."\";");
as i want to write a good windows application in vb, i thought i could start the mission of trying to make a small program that will generate the code so you can have parts intergrated into your site.
Pages: 1 2 3 4 5 6 7