MyBB Community Forums

Full Version: Calling MyBB engine from external script?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi!

I'm working now on Drupal bridge to MyBB. One of desirable features for this app is single sign-on (SSO). I made login from MyBB plugin to Drupal site and its works with such code:

  include('./includes/bootstrap.inc');
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  user_authenticate(array('name' => $mybb->input['username'], 'pass' => $mybb->input['password']));

because Drupal allows to use it from other scripts. Just needed include bootstrap.inc and execute drupal_bootstrap(), then you may use Drupal functions - login, logout, save nodes, users etc.

But on other side I get in troubles Sad

I tried to initialize MyBB from Drupal module:

  global $db, $lang, $mybb, $mybbgroups, $time, $cache, $plugins, $session, $groupscache, $displaygroupfields, $templates;
  global $debug, $templatecache, $templatelist, $maintimer, $globaltime, $parsetime;
  include("global.php");
  include(MYBB_ROOT."inc/functions_post.php");
  include(MYBB_ROOT."inc/functions_forumlist.php");
  include(MYBB_ROOT."inc/class_parser.php");

No errors, init seems successfull, but I not found way how to login user to MyBB site from Drupal module. Dances around member.php not get me success. MyBB hooks also seems unuseful for this case. Fallback way is to imitate MyBB cookies and set them from Drupal directly, but I hope maybe another way exists?

Well... my questions are:
What is right way to include MyBB to external scripts and execute MyBB functions?
Is there method for external login/logut user to MyBB site?
Is ther methods for other operations like create/modify/delete threads/replies and so on?

Thank for any useful suggestions.
You shouldn't need to global all that stuff and just include global.php.

Try that. Unless you are executing functions from specific mybb includes there is no need to seperately include them. Login does not require more but the posting pages might.

Hope that helps.
Thank for directing me to right way. I digging code again and understand logic of MyBB (I hope). Sign-on works in both directions now Smile

For these who follows this topic later. Right piece of code for this task is:
      require_once("global.php");
      $mybb->input['username'] = $username;
      $mybb->input['password'] = $password;
      $mybb->input['action'] = 'do_login';
      include(MYBB_ROOT."member.php");
^ You might want to be careful with that. You're including global.php, then member.php will include it again. Easiest fix is to change "include" to "require_once".
(2008-10-24, 08:24 AM)ZiNgA BuRgA Wrote: [ -> ]^ You might want to be careful with that. You're including global.php, then member.php will include it again. Easiest fix is to change "include" to "require_once".

You right, I fixed that, thanks.
How to get mybb settings in joomla?
I tried to include global.php but that didn't work
(2008-10-24, 07:12 PM)bombo Wrote: [ -> ]How to get mybb settings in joomla?
I tried to include global.php but that didn't work
You'd probably need to manually map some things over. Including MyBB with Joombla doesn't mean that both scripts magically know how to interact with each other, unfortunately.
I wonder how hard it would be to create a bridge class. Does that even make sense?