Hi all. I have made a script for sincronizing phpBB3 and Drupal. It's working fine: all the account creation, login and logout procedures are carried by phpBB3. When you login to phpBB3, you are logged in drupal too. When you create a user in phpBB3, another one is created in Drupal, with the same ID.

Now I need to change the URLs generated by Drupal for showing profiles and login/logout actions, redirecting them to phpBB3.

I need to change 5 URLs, mainly:

?q=user/XX to forums/memberlist.php?mode=viewprofile&u=XX
?q=user/register to forums/ucp.php?mode=register
?q=user to forums/ucp.php?mode=login
?q=user/password to forums/ucp.php?mode=sendpassword
?q=logout to forums/ucp.php?mode=logout

Where in the drupal code are generated those URLs? Thank you!

Comments

Xabi’s picture

Anyone?

Phillip Mc’s picture

Hi Xabi,

I'm not sure how this will impact the rest of your Drupal site, but, you could override the theme_username function so instead of pointing towards user it points to the phpbb profile. The line you're looking for is:

    if (user_access('access user profiles')) { 
      $output = l($name, 'user/'. $object->uid, array('title' => t('View user profile.'))); 
    } 

You can search the Drupal API for other theme functions, although, for the login logout stuff, I think it might be easier just to disable the Drupal LOGIN form and create your own custom login form and manually add a new LOGOUT link in your menu.

There are some examples of login forms here:

http://drupal.org/node/154233

Phil

Xabi’s picture

Thank you, but I would need to override the login/register URLs too, it's not only a matter of login boxes... there are links like "Login or register to post comments" that I need to override :-)

Xabi’s picture

I'm stuck here, I don't know where these URLs are generated... I have tweaked user.module to no avail. Help!

Xabi’s picture

Any clues out there? :-)

Xabi’s picture

Excuse me for bumping, but I really need somebody pointing me in the right direction. Any ideas on how to replace those URLs?

thomie’s picture

and see if it works. You should be able to override the menu items that are defined in user_menu() in user.module.

Make a custom module and put this in there:

/**
 * Implementation of hook_menu().
 */
function user_menu($may_cache) {
  if (!$may_cache) {
    $items[] = array('path' => 'user/register', 
      'title' => t('Forum registration'),
      'callback' => 'drupal_goto', 
      'callback arguments' => array('forums/ucp.php?mode=register'),
      'access' => !$user->uid, 
      'type' => MENU_LOCAL_TASK);
  }

  return $items;
}

Make sure you logout before testing, then go to user/register. If it works for user/register, see user_menu() in user.module for more of these menu items that you want to override. Note, you need to use if (!$may_cache), otherwise it won't work.

Xabi’s picture

My drupal installation seems broken after activating that module. I created .module and .info files and I got a blank page after activating it. Now the whole drupal installation is blank :-(

Edit: Deleting the module all works again.

thomie’s picture

The function name should be mymodule_menu, not user_menu (how can I edit that comment?).

So you need:
*a directory called mymodule inside sites/all/modules
*a file called mymodule.module in there, with the code that I posted and subsitituing user_menu by mymodule_menu.
*a file called mymodule.info in there like you did.
*to activate the module.

Does that work?

Xabi’s picture

hey! it worked! Thanks! :-D But the resulting URL is rendered in this way: ?q=forums/ucp.php%3Fmode%3Dregister

thomie’s picture

Try this:

'callback arguments' => array('forums/ucp.php', 'mode=register'),
Xabi’s picture

nope... it shows forums/ucp.php&mode=register instead of forums/ucp.php?mode=register

thomie’s picture

which version of Drupal are you using? I tested with 5.1, with the following code in mymodule.module:

function mymodule_menu($may_cache) {
  if (!$may_cache) {
    $items[] = array('path' => 'user/register',
      'title' => t('Forum registration'),
      'callback' => 'drupal_goto',
      'callback arguments' => array('forums/ucp.php', 'mode=register'),
      'access' => !$user->uid,
      'type' => MENU_LOCAL_TASK);
  }
  return $items;
}

And when I go to www.example.com/user/register, I'm redirected to www.example.com/forums/ucp.php?mode=register (and get a page not found).

The following might also work, but it's not so nice. Replace that 'callback arguments' line again, this time by:

'callback arguments' => array('http://www.example.com/forums/ucp.php?mode=register'),

Replacing example.com with your hostname.

Xabi’s picture

Your second example works for me, thank you very much! Anyway, this function works only for unregistered users, isn't it? I need it working for registered and logged in users too...

One last thing: how could I add more items/redirections to this function? Which is the right format? Excuse me, I know only a bit of PHP.

thomie’s picture

Double post.

thomie’s picture

you should replace 'access' => !$user->uid, by 'access' => TRUE, . But I think logged in users are already registered aren't they, so they shouldn't be allowed to access user/register again.

For more redirections, take a good look at the function user_menu() in user.module. Basically you just add more of these $items[] = array(.. , .. , .. ) parts after the one you already have in your custom module, using 'callback' => 'drupal_goto', etc. I think you'll be able to figure it out. Maybe only ?q=user/XX will be bit more difficult, if you need help, let me know.

Xabi’s picture

Hi again. Some problems. This is the code I'm using:

<?php
function user_phpbb_menu($may_cache) {
  if (!$may_cache) {
    $items[] = array('path' => 'user/register',
      'title' => t('Registrarse'),
      'callback' => 'drupal_goto',
      'callback arguments' => array('http://www.mydomain.com/forums/ucp.php?mode=register'),
      'access' => TRUE,
      'type' => MENU_LOCAL_TASK);

    $items[] = array('path' => 'user/login',
      'title' => t('Identificarse'),
      'callback' => 'drupal_goto',
      'callback arguments' => array('http://www.mydomain.com/forums/ucp.php'),
      'access' => TRUE,
      'type' => MENU_DEFAULT_LOCAL_TASK);

    $items[] = array('path' => 'user/password',
      'title' => t('Recuperar password'),
      'callback' => 'drupal_goto',
      'callback arguments' => array('http://www.mydomain.com/forums/ucp.php?mode=sendpassword'),
      'access' => TRUE,
      'type' => MENU_LOCAL_TASK);

    $items[] = array('path' => 'user',
      'title' => t('Identificarse'),
      'callback' => 'drupal_goto',
      'callback arguments' => array('http://www.mydomain.com/forums/ucp.php'),
      'access' => TRUE,
      'type' => MENU_CALLBACK);
}
return $items;
}
?>

Only the user/register redirection works. The another three give errors like this: warning: call_user_func_array() [function.call-user-func-array]: First argumented is expected to be a valid callback, 'http://www.mydomain.com/foros/ucp.php' was given in /XXX/includes/form.inc on line 218.

And last one: I can't find what to do with the user/XX (user ID) redirection... User IDs are the same in drupal and phpBB, so I just need to do a redirection from, for example, user/23 to /forums/memberlist.php?mode=viewprofile&u=23. It "seems" easy...

Thank you for your help!

Xabi’s picture

Excuse me, I did not put "drupal_goto'" in all callbacks! Now it seems to work! I would only need to redirect the URLS like user/45 and user/45/edit. Have you any clues?

Xabi’s picture

Hey, user/X/edit URLs are redirected with this one!

$items[] = array('path' => 'user/'. arg(1) .'/edit',
      'title' => t('Editar cuenta'),
      'callback' => 'drupal_goto',
      'callback arguments' => array('phpBB3/ucp.php', 'i=164'),
      'access' => $admin_access || $user->uid == arg(1),
      'type' => MENU_LOCAL_TASK);

Now I'm trying the last one: user/XX. I'm near, but I can't get it to work yet. This is my code:

$items[] = array('path' => 'user/'. arg(1),
      'title' => t('Perfil de usuario'),
      'type' => MENU_CALLBACK,
      'callback' => 'drupal_goto',
      'callback arguments' => array('memberlist.php', 'mode=viewprofile', 'u=', arg(1)), 'access' => $view_access);

Any clues? THANK you!

Xabi’s picture

Ok... done for user/X. The whole code has some issues, anyway. I'll post them here in a while.

$items[] = array('path' => 'user/'. arg(1),
      'title' => t('Perfil de usuario'),
      'type' => MENU_CALLBACK,
      'callback' => 'drupal_goto',
      'callback arguments' => array('phpBB3/memberlist.php', 'mode=viewprofile&u=' . arg(1)));
Xabi’s picture

My module stopped working after installing Drupal 5.2 :-( Any idea of what's happening? Thank you.