Hi, I'm using your module and I want to add the user's picture next to the list item. It would be easy for me to do this if the list items were rendered via a theme function which they currently are not. Here are the changes I made for this to be the case. Could you include them in your next release ? Thanks !

Add

/**
 * Implementation of hook_theme().
 */
function facebook_status_theme() {

  return array(
    'facebook_status_item' => array(
      'arguments' => array(
         'user_for_status' => NULL,
         'status_long' => NULL,
         'status' => NULL,
         'time' => NULL
      ),
    ),
  );
}
function theme_facebook_status_item($user_for_status,$status_long,$status,$time) {
  return t("<span class='fbs_list_item' title='@username @status_long'> !user @status_short <div class='submitted'>!time ago</div></span>", array('@username' => $user_for_status->name, '@status_long' => $status_long, '!user' => theme('username', $user_for_status), '@status_short' => $status, '!time' => $time, 1));
}

Change line 1022 (end of facebook_status_list_render function) to

          $list[] = theme('facebook_status_item',$user2, $row['status_fb'], $status,$time);

Thanks to these changes, I can add this to my template.php file to get the account picture:
function phptemplate_facebook_status_item($user_for_status,$status_long,$status,$time) {
return theme('user_picture',$user_for_status).t(" !user @status_short

", array('@username' => $user_for_status->name, '@status_long' => $status_long, '!user' => theme('username', $user_for_status), '@status_short' => $status, '!time' => $time, 1));
}

Comments

icecreamyou’s picture

Assigned: Unassigned » icecreamyou
Priority: Normal » Minor
Status: Active » Needs review

Sounds reasonable.

icecreamyou’s picture

I'd like to get equivalent code for the 5.x branch before I commit this to 6.x. Anyone care to write it?

icecreamyou’s picture

Actually, this should work for 5.x too, without facebook_status_theme(), right? I'll try to get this in my local copy sometime today--and I think this is the last issue I need to resolve before releasing a beta!

icecreamyou’s picture

Status: Needs review » Needs work

So... this is the last issue holding up a beta release, and I'd really like to get this resolved; but the code isn't working for me in 6.x. I tried using the exact code posted by PGiro, as well as this code:

/**
 * Implementation of hook_theme().
 */
function facebook_status_theme() {
  global $user;
  $status = facebook_status_get_status($user->uid);
  if (drupal_strlen($status[0]['status_fb']) > variable_get('facebook_status_max_block_len', variable_get('facebook_status_length', 192))) {
    $status_short = drupal_substr($status[0]['status_fb'], 0, variable_get('facebook_status_max_block_len', variable_get('facebook_status_length', 192))) .'...';
  }
  else {
    $status_short = $status[0]['status_fb'];
  }
  return array('facebook_status_item' => array(
    'arguments' => array(
      'account' => $user,
      'status_long' => $status[0]['status_fb'],
      'status_short' => $status_short,
      'time' => format_interval(time() - $status[0]['status_time']) . t(' ago')
      ),
    ),
  );
}

/**
 * Themes a user with their status for display in a list.
 *
 * @see facebook_status_theme()
 */
function theme_facebook_status_item($account, $status_long, $status_short, $time) {
  if (variable_get('facebook_status_mode', 1)) {
    return t("<span class='fbs_list_item' title='@username @status_long'> !user @status_short <div class='submitted'>!time</div></span>", array('@username' => $account->name, '@status_long' => $status_long, '!user' => theme('username', $account), '@status_short' => $status_short, '!time' => $time));
  }
  else {
    return t("<span class='fbs_list_item' title='@status_long'> !user @status_short <div class='submitted'>!time</div></span>", array('@username' => $account->name, '@status_long' => $status_long, '!user' => theme('username', $account), '@status_short' => $status_short, '!time' => $time));
  }
}

The second function is all that's needed for 5.x to work.

Any ideas?

PGiro’s picture

What is the problem ?

icecreamyou’s picture

Nothing shows up with anything called like this:

global $user;
print theme('facebook_status_item', $user, 'long status', 'short status', time());

But there are no errors logged, and this works fine:

global $user;
print theme_facebook_status_item($user, 'long status', 'short status', time());

So any blocks using facebook_status_list_render() display nothing.

PGiro’s picture

Did you clear your caches to force the theme registry to reload ?

I'm not a drupal expert but I don't think what you're doing in hook_theme() works. That method is not to actually theme anything, it's a hook to define all the functions in your code that can be called for theming.

icecreamyou’s picture

Status: Needs work » Fixed

Sure enough, that was it. Thanks. I'm about to commit all the changes from this week!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.