The blogtitle and realname modules don't play well together. With both enabled, when I go to e.g. blog/3, I get

Fatal error: Call to undefined function blog_page_user() in /home/andrex/html/tealtoes.org/trunk/sites/all/modules/realname/realname.module on line 186

The offending function in realname.module is

/**
 * Intercept the user blog page.
 */
function realname_blog_page($account) {
  $output = blog_page_user($account);
  drupal_set_title($title = t("@name's blog", array('@name' => $account->realname)));
  return $output;
}

What seems to happen is that since blogtitle has changed the value of $callback['blog/%user_uid_optional']['page callback'] from 'blog_page_user' to 'blogtitle_blog_page_user' (in blogtitle.module, line 59), blog_page_user() is no longer loaded and available when realname_blog_page() is called.

In addition:

  • realname_blog_page() wants to set the page title to "User's blog", overriding the user's custom title, that blogtitle_blog_page_user() wants to set.
  • blogtitle's blogtitle_get_blog_title() wants to set the default blog title (the one used if the user hasn't specified a different one) using $account->name, rather than $account->realname as realname wants to do.

So how can these two play nicely together? I think that what we want is:

  • When setting the default blog title, blogtitle should use $account->realname if it's non-null, otherwise $account->name.
  • realname should call blogtitle_blog_page_user() to create the user blog page, if the blogtitle module is present. (Alternatively, it could just not intercept the user blog page at all, allowing blogtitle_blog_page_user() to stay in place as the menu callback. But if the user then disabled the blogtitle module, I don't think realname would get to do its work.)

These are pretty simple changes. I've coded them and they seem to work fine on my host.

I'm attaching a patch that makes this change for blogtitle. The default blog title is now computed inside of blogtitle_get_blog_title(), using either $account->realname or $account->name, if $default is empty. This makes it easier on the calling functions, which don't have to worry about realname vs. name.

I'm opening a similar bug report for realname, with a patch, and will post the link to that here.

Thanks,
Andrew.

Comments

Andrew Schulman’s picture

Andrew Schulman’s picture

StatusFileSize
new2.35 KB

I made a few minor corrections to the patch. Revised patch is attached here.

nancydru’s picture

Using theme_username is a better way to go.

Andrew Schulman’s picture

Status: Active » Needs review
StatusFileSize
new2.34 KB

Using theme_username is a better way to go.

Agreed. Here's a revised patch that uses theme('username') instead of $user->realname etc. Please test.

Thanks,
Andrew.

Andrew Schulman’s picture

StatusFileSize
new2.43 KB

On second look, theme_username isn't a better way to go. The problem is that in general, theme_username() returns not the themed username itself (e.g. "Carey" for user carey), but the name wrapped in an HTML link to the user's account page. The form of the link isn't known since it can be themed, so there's no reliable way of extracting just the themed username from it.

Instead I think we have to go back to just using $user->realname ? $user->realname : $user->name, as before. Note that blogapi_blogger_get_user_info() in core does exactly this.

I'm attaching a revised patch that implements this. This is essentially the same as the first patch I posted in comment #2, but that one was created against a non-clean version of blogtitle (the fix for #566416 had already been applied). Sorry about that. This patch is against clean blogtitle-6.x-1.2. It does also fix #566416: blog title is empty if not specified, so the patch there isn't needed if this one is applied.

nancydru’s picture

Try theme('username', ..., array('plain' => TRUE))

Andrew Schulman’s picture

Try theme('username', ..., array('plain' => TRUE))

That's what I was using in my previous patch. But the default theme_username() in D6 doesn't support 'plain', and other implementations need not support it. The D6 API describes theme_username() as returning "an HTML link to the user's page". So a user who doesn't have realname installed will in general end up with HTML markup in the link text-- which is exactly what Marcus reported here.

I thought of having blogtitle provides its own blogtitle_username() to theme the user name, but unless we arrange to have it forcibly override all other theme_username() implementations, there's no guarantee we won't get back HTML of unknown form. And if we do somehow forcibly override all other theme_username()s, then we're not really using the theming system-- we may as well just return the particular form we want, i.e. $user->realname ? $user->realname : $user->name.

Maybe function_exists('realname_username') ? realname_username($user, array('plain' => TRUE)) : $user->name would be slightly better.

In D7, theme_username() provides more options to specify how the username is to be rendered, so it should be possible to ask for just a plain text result, i.e. by suppressing the 'link_path' argument.

marcushenningsen’s picture

Status: Needs review » Reviewed & tested by the community

The patch 1_3 seems to work.

Thanks
Marcus

remi’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for your work! The patch files have been committed to version 1.3.

remi’s picture

Status: Fixed » Closed (fixed)