MyBB Community Forums

Full Version: Accessing MyBB data from outside forum
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Disclaimer: I searched around quite a bit before posting this question. I found this thread which recommends using a mod (which I don't want to do for a few good reasons) and this one which is a more complex problem than mine and kind of over my head. /Disclaimer

I've just migrated my dating forum from SMF to MyBB and so far am very happy. However, there are two things I used to do with SMF which I know can be done in MyBB too but haven't figured out how to do yet.

1. Identifying a MyBB user role (e.g. admins) outside the forum.

I have some scripts that use my forum's user database to disallow anyone who isn't logged in as an admin. In SMF this was accomplished with this little piece of code:

<?php require_once('/path/forum/SSI.php');
if (!$context['user']['is_admin']) {
    header( 'Location: http://www.datesphere.com' ) ;
}
?>

What is the MyBB equivalent? I can't find anything about this in either this forum or the MyBB documentation.

2. Displaying posts outside the forum.

Like I said, I found a thread suggesting you do this with a mod, but since this is basically the same kind of problem as my first question (accessing MyBB data from outside the forum) I assume the answer is related, and that it can be achieved by including a MyBB core file (globals.php?) and a little php. All I want to do is display the last 10 forum posts on my main page (i.e. datesphere.com. My forum is located at datesphere.com/forum/). Again, in SMF there were some basic functions defined in SSI.php to do this. How do I do it in MyBB?

Thank you very much for any help you can provide. It's very appreciated.

Chris
For question 1
<?php
require("/forumdirectory/global.php");
if ($mybb->user['usergroup']==4)
{
/*whatever you want it to do */
}
else
{
error_no_permission();
}
?>

For question 2
<?php
require("forumdirectory/global.php");
$query=$db->query("SELECT * FROM ".TABLE_PREFIX."posts ORDER BY dateline DESC LIMIT 0,9");
/*Do what you want with the data*/
?>
I think you can get the rest from there.
THANK YOU! Trying this now.
By the way, how did you know admins are usergroup 4? Did you just have that memorized, or did you go into phpmyadmin or something and look it up? I'm trying to find a list of variables, properties, methods, etc. for MyBB but coming up short - documentation seems to be limited.

I guess you just have to remember this stuff from experience?

Thanks again.
Default admins are group 4. However if you want to check if the user is admin then you can check if $mybb->user['cancp'] is true.
This worked like a charm, by the way. Thanks!

The only issue I'm having now is getting MySQL to correctly return the most recent user who posted in each thread. I posted about it in StackOverflow if anyone's interested.

http://stackoverflow.com/questions/55601...e-in-mysql

Thanks,

Chris
Quote:By the way, how did you know admins are usergroup 4? Did you just have that memorized, or did you go into phpmyadmin or something and look it up? I'm trying to find a list of variables, properties, methods, etc. for MyBB but coming up short - documentation seems to be limited.

I guess you just have to remember this stuff from experience?

I got really big into template edits and adding new things without plugins so that's how I learned. If you want to use data the easiest method is to use $mybb->tablename['fieldname'] ignore the table prefix. The users table is shortened to user, otherwise that works.
Example: $uid=$mybb->user['uid']; You could then use the variable and do things with it.

(2011-04-05, 11:39 PM)- G33K - Wrote: [ -> ]Default admins are group 4. However if you want to check if the user is admin then you can check if $mybb->user['cancp'] is true.

The only thing is if supermods are able to view the Admin CP, they would be able to view that page.
(2011-04-06, 01:17 AM)dragonexpert Wrote: [ -> ]
(2011-04-05, 11:39 PM)- G33K - Wrote: [ -> ]Default admins are group 4. However if you want to check if the user is admin then you can check if $mybb->user['cancp'] is true.

The only thing is if supermods are able to view the Admin CP, they would be able to view that page.

Yes and isn't that the point? Administrators == users with admin access??