Hi, I've come across an error when I have anonymous users unable to flag content and they are viewing a users profile.

I tracked it down to...

function flag_content_user($op, &$edit, &$account, $category = NULL) {
  global $user;

  switch($op) {
    case 'view':
      if ($user->uid == $account->uid) {
        // User is viewing their own user page, don't show them anything
        return array();
      }

      $links = flag_content_link(FLAG_CONTENT_TYPE_USER, $account);
      foreach($links as $key => $value) {
        $items[] = array(
          'class' => $key,
          'value' => l($value['title'], $value['href'], $value['attributes']),
        );
      }
      return array(t('Flag user') => $items);

    case 'delete':
      db_query("DELETE FROM {flag_content} WHERE eid = %d AND type = '%s'", $account->uid, FLAG_CONTENT_TYPE_USER);
      break;
   }
}

It looks like if flag_content_link() returns an empty array the foreach loop in flag_content_user() never loops which results in $items array not being created. This then messes up user.module when we... return array(t('Flag user') => $items);
I was able to bandaid the problem by adding...

$items = array();

Here is what the function looks like for me now.

function flag_content_user($op, &$edit, &$account, $category = NULL) {
  global $user;

  switch($op) {
    case 'view':
      if ($user->uid == $account->uid) {
        // User is viewing their own user page, don't show them anything
        return array();
      }
      
      $items = array();
      $links = flag_content_link(FLAG_CONTENT_TYPE_USER, $account);
      foreach($links as $key => $value) {
        $items[] = array(
          'class' => $key,
          'value' => l($value['title'], $value['href'], $value['attributes']),
        );
      }
      return array(t('Flag user') => $items);

    case 'delete':
      db_query("DELETE FROM {flag_content} WHERE eid = %d AND type = '%s'", $account->uid, FLAG_CONTENT_TYPE_USER);
      break;
   }
}
CommentFileSizeAuthor
#2 flag_content.module-186504.patch345 bytesGreg Go

Comments

mlncn’s picture

Confirming this bug (at least when using nodeprofile with an embedded profile).

And that rconstantine's proposal fixes it.

http://agaricdesign.com/project/wsf2008

Greg Go’s picture

Status: Active » Needs review
StatusFileSize
new345 bytes

Thanks cois. Your fix works for me.

Attached is the same fix in patch form.

mlncn’s picture

Status: Needs review » Reviewed & tested by the community

Checked patch. In use. This works!

Fixes a multitude of issues with other modules.

kbahey’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 5.x

Thanks

Anonymous’s picture

Status: Fixed » Closed (fixed)

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