I've noticed two potential problems with the friendfeed_menu function. I think there are a couple of checks that should be performed to determine if the FriendFeed tab should be visible.

First, user_access('view friendfeeds') is not checked by this function, or anywhere else in the module, even though the permission is settable. It's my guess that this permission setting would not be relevant for the block view, since blocks have their own permission management, but I'd expect it to be in effect here.

Secondly, I would think that this tab should only be displayed if the FriendFeed username and API key are set for the user. (Or alternately, the tab would display a message that these parameters aren't set, rather than generating an error message, which is the current behavior.)

Micah

Comments

robloach’s picture

Title: FriendFeed menu item visibility checks » FriendFeed Tab only when user has a FriendFeed

Ah, again the Drupal 5 menu system....

As for the second point... Good idea.... I'll switch this issue to reference that.

micahw156’s picture

Status: Active » Needs review
StatusFileSize
new619 bytes

Not sure if this is the best approach or not. I looked at the way the existing code works, and it seems silly to put the code to check for this before calling the tab, especially in light of the changes being made via #274763: Error retrieving feed from FriendFeed.

Instead, I wrapped the call with a simple check that displays a message when the user's FriendFeed configuration is incomplete. I'm totally open to better verbiage here. Here's a simple patch that implements this check. Let me know what you think.

Micah

robertjwhitney’s picture

So should I patch this into the friendfeed module to try it? Or somewhere else.

micahw156’s picture

@robertjwhitney Yes, this patch is an update to friendfeed.module.

robloach’s picture

What if we stuck the check right in the function itself and then did this instead?

$friendfeed = friendfeed_user_view($user, $service, $start, $num);
return empty($friendfeed) ? '<p>' . t('This user does not have a FriendFeed configuration.') . '</p>' : $friendfeed;
dugh’s picture

StatusFileSize
new9.35 KB

This appears to work for me, it hides the FriendFeed menu item from view if there is no FriendFeed stuff configured:

function friendfeed_menu($may_cache) {
  if (!$may_cache) {
    if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0) {
      //My additions:
      $user = user_load(array('uid' => arg(1)));
      if (!($user->friendfeed_username && $user->friendfeed_key)) {
         return NULL;
      }
    ....

Here also is a little addition to put the FriendFeed configuration form in its own category when you edit your profile:

function friendfeed_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
  case 'categories':
    return array('friendfeed' => array('name' => 'friendfeed',
         'title' => t('FriendFeed'),
         'weight' => 5));
    break;

  case 'form':
    if ($category == 'friendfeed')            
      return array(

And lastly here is a change to add the FriendFeed badge at the top of the feeds list so that people can subscribe to you:

In function friendfeed_user_view I changed:

theme('friendfeed_user_feed',$feed);
to:
theme('friendfeed_user_feed',$feed,$user->friendfeed_username);

and my function theme_friendfeed_user_feed starts out like so:

function theme_friendfeed_user_feed($feed, $username) {
  $output = '';
  if (isset($feed->entries) && is_array($feed->entries)) {
    $output = t('<a href="http://friendfeed.com/@username"><img
alt="View my FriendFeed" style="border:0;" align="right"
src="http://friendfeed.com/embed/badge/@username/hide_stats-1/format-png/width-300" /></a>',
array('@username' =>  check_plain($username)));
    $output .= '<dl>';

I attached my whole friendfeed.module file.

It's working on our department site, see for example http://itls.usu.edu/people/doug-holton

Thanks for this module by the way. The activitystream module really had serious problems that were too much for me to try to fix myself.

dugh’s picture

StatusFileSize
new9.37 KB

Here's the file with a parenthesis restored (I was making other minor changes too that weren't important).
And also I added a check_plain for security: check_plain($username)

dugh’s picture

All of the above changes still work in drupal 6, too, except for the first one to hide the menu tab if the person hasn't entered friendfeed info.

I tried making a drupal 6 version but it's not working yet. I thought I'd go ahead and post what I have in case one of you knows the problem.

I based it on the _contact_user_tab_access %user menu tab example near the bottom of this page:
http://drupal.org/node/209056
and here http://api.drupal.org/api/function/_contact_user_tab_access/6

function _friendfeed_user_tab_access($account) {
  return user_access('view friendfeeds') &&
         !empty($account->friendfeed_username) &&
         !empty($account->friendfeed_key);
}

function friendfeed_menu() {
  return array(
    'user/%user/friendfeed' => array(
      'title' => 'FriendFeed',
      'description' => 'View FriendFeed status.',
      'page callback' => 'friendfeed_user_view',
      'page arguments' => array(1),
      'access callback' => '_friendfeed_user_tab_access',
      'access arguments' => array(1),
      'type' => MENU_LOCAL_TASK,
    ),
  );
}

Do I need to change the 'access arguments' for example, or what.

dugh’s picture

StatusFileSize
new9.41 KB

I guess I just needed to clear my cache, it's working now. The tab is hidden if the user has no friendfeed info.

micahw156’s picture

Status: Needs review » Closed (won't fix)

Drupal 5 has reached end of life, so I am closing all D5 issues in my list. If this issue still applies with Version 6.x or later, please reopen this issue with correct version tag.