MyBB Community Forums

Full Version: MyBB Integration Class
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Two days ago, I have started to write an Integration class, which contains handy features to include forum functions in your own website.

I have already opened this thread (http://community.mybboard.net/thread-41804.html) some while ago, but since it is now in development, I thought it is best to open a thread in here, where I can ask some questions I come across.

Questions so far (taken from the previous thread):

Quote:Okay, so I have been working on the class the past days and I have just come across a problem I cannot solve alone it seems.
I want to get the login status of the user, but there are following problems:
- $mybb->cookies['sid'] changes constantly each time you refresh???
- $mybb->user['uid'] is 0 even though I'm logged in
- $mybb->cookies contain different cookies when showing them while viewing the actual board than when you remotely include global.php ( if you print_r $mybb->cookies in the Session Class init() )

Can somebody help me on the MyBB procedure on how to fetch the Login Status? It would save me quite time, otherwise I will need to look into it some other day. Also, I ddo prefer to stick to the MyBB code rather than to compose something on my own, which might not be compatible with following versions of MyBB.
Thanks in advance - If I'm done, I will definitely publish this Website Integration Class.
(2009-01-22, 07:33 PM)No0oB Wrote: [ -> ]$mybb->cookies['sid'] changes constantly each time you refresh???
Do you have cookies enabled on the client?

(2009-01-22, 07:33 PM)No0oB Wrote: [ -> ]$mybb->user['uid'] is 0 even though I'm logged in
Are you dumping the value before the session has been created?

(2009-01-22, 07:33 PM)No0oB Wrote: [ -> ]$mybb->cookies contain different cookies when showing them while viewing the actual board than when you remotely include global.php ( if you print_r $mybb->cookies in the Session Class init() )
Is everything on the same subdomain? Also make sure that the cookie path isn't interfering.

(2009-01-22, 07:33 PM)No0oB Wrote: [ -> ]Can somebody help me on the MyBB procedure on how to fetch the Login Status? It would save me quite time, otherwise I will need to look into it some other day. Also, I ddo prefer to stick to the MyBB code rather than to compose something on my own, which might not be compatible with following versions of MyBB.
Generally if($mybb->user['uid']) to check if the user is logged in, however make sure you're running that after the user has been loaded.
The user and everything else is loaded when you include the global.php file, so the cookie path and all other related settings should be the same like with mybb I'd say.

I have considered that there might be difficulties because I am running this on my localhost in two separate folders, but I thought that the cookie path will be the same like the one MyBB uses.

And no, I am not dumping anything or $mybb->user['uid'], my question would be if MyBB dumps anything Toungue

So the paths I am using are:
- localhost/forums/MyBB_1.4.4 for the forum
- localhost/MyBBIntegrator/ location of the class
- localhost/some_website location of the website which uses the class

Is it really necessary to have everything under one folder? Say for instance localhost/website, then website/forums would be the forums and the class would be in website/together with the actual site?
(2009-01-23, 06:20 AM)No0oB Wrote: [ -> ]The user and everything else is loaded when you include the global.php file, so the cookie path and all other related settings should be the same like with mybb I'd say.

I have considered that there might be difficulties because I am running this on my localhost in two separate folders, but I thought that the cookie path will be the same like the one MyBB uses.

And no, I am not dumping anything or $mybb->user['uid'], my question would be if MyBB dumps anything Toungue

So the paths I am using are:
- localhost/forums/MyBB_1.4.4 for the forum
- localhost/MyBBIntegrator/ location of the class
- localhost/some_website location of the website which uses the class

Is it really necessary to have everything under one folder? Say for instance localhost/website, then website/forums would be the forums and the class would be in website/together with the actual site?
No, the files do not have to be in the same directory (make sure when you include MyBB files, you may need to chmod to the MyBB directory before doing so). However, the cookie path (check AdminCP -> Configuration -> Settings -> General Configuration -> Cookie Path) must be set to allow the cookies to be visible on all the places you want.
In your instance, the cookie path should be set to / - that is, a single forward slash (by default, it probably would be /forums/MyBB_1.4.4/).

See if that helps.
I can't believe how I didn't come up with this issue.
Thank you for noticing the cookie path problem, it definitely was due to the cookie path.
Logged In Status works now.
Okay, so I have done a few things.

Current features of the class:
Quote: * - getForum: Returns forum data of $forum_id
* - getLatestActiveThreads: Get latest active threads, where posts have been posted
* - getPost: Returns post data of $post_id, also parse it instantly
* - getPrivateMessagesOfUser: Get messages of a user in a nicely structured array
* - getThread: Returns thread data of $thread_id
* - getUser: Returns user data of $user_id
* - getWhoIsOnline: Returns list of online users
* - isLoggedIn: Return status if the user is logged in
* - isModerator: Return status if the user is a mod
* - isSuperAdmin: Returns if user is super admin
* - login: Login Procedure with user and password
* - logout: Logout Procedure
* - markRead: Mark one or more forums read

I would like to have a bit of feedback on what else is very important to include in this class for first release.
Keep in mind: This class shall help you integrate useful functions you might want to use on your website, besides running the forum. It is not supposed to replace the MyBB forum!
i'm offering to test the class and see how it works from kohana and codeigniter
where can i download it ?
This might come in handy, drop me a PM if you need testers!
It's still in development, but I will release a v1.0 with a few functionalities.
Current list:
Quote: * - dbEscape: Escape Values for Database usage
* - getForum: Returns forum data of $forum_id
* - getLatestActiveThreads: Get latest active threads, where posts have been posted
* - getLatestPosts: Get latest posts of one or more forums
* - getLatestThreads: Get latest threads of one or more forums
* - getPost: Returns post data of $post_id, also parse it instantly
* - getPosts:
* - getPostsOfThread: Return posts from a specific thread
* - getPrivateMessagesOfUser: Get messages of a user in a nicely structured array
* - getThread: Returns thread data of $thread_id
* - getUser: Returns user data of $user_id
* - getWhoIsOnline: Returns list of online users
* - incViews: Increase the view count of a thread
* - isLoggedIn: Return status if the user is logged in
* - isModerator: Return status if the user is a mod
* - isSuperAdmin: Returns if user is super admin
* - login: Login Procedure with user and password
* - logout: Logout Procedure
* - markRead: Mark one or more forums read
* - parseString: Parses a string with MyBB's parser (MyCodes/BBCodes)
can u add a register function would be nice to be able to register a user when he creates a account on the site
Since you are taking the time to write it and share, please include a couple simple examples of exactly how to use it. Smile
For people who are still learning how to write code and use classes.

ie. getLatestThreads: Get latest threads of one or more forums

Thank you

(2009-01-31, 06:02 AM)quasiperfect Wrote: [ -> ]can u add a register function would be nice to be able to register a user when he creates a account on the site

Great idea!
Pages: 1 2