tags:

views:

47

answers:

1

I'm trying to do some integration between Drupal and a webmail client and I want to call a Drupal function from a PHP file that is part of the webmail client. In this case, the function I want to call is provided by a contrib module, but I'm assuming that won't matter.

So, if I have a non-Drupal page called mail_login.php and want to call Drupal's foo_bar() method, how can I do that?

+3  A: 

Depending on the complexity of whatever you wanna call you may have to bootstrap drupal:

        require_once '/full/path/to/drupal/includes/bootstrap.inc';
        drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

        $return = menu_execute_active_handler();

        if (is_int($return)) {
          switch ($return) {
            case MENU_NOT_FOUND:
              drupal_not_found();
              break;
            case MENU_ACCESS_DENIED:
              drupal_access_denied();
              break;
            case MENU_SITE_OFFLINE:
              drupal_site_offline();
              break;
          }
        }

After that you can code as if you are in the Drupal Enviroment, because, well, you are!

Hannes
Hmm, the require_once is crashing the page for some reason, but thanks!
Stewart
it will probably take you some time to work around all the includes / require / path Problems... have been there :)
Hannes