Problem :

When the module is set to not allow flagging of users an error occurs when browsing another user's profile.

warning: Invalid argument supplied for foreach() in C:\wamp\www\communull\modules\user\user.module on line 1507.

Solution :

Simple change, just need to set the $items in the user_view function to default to being an empty array. Line 127 - $items=array();

I don't have the tools to create a proper patch on me at the moment - sorry.

(nice module BTW)

Mike

CommentFileSizeAuthor
#3 flag_content_userprofile.patch373 bytesdavemybes

Comments

jkamin’s picture

Hi - I just put in a support request before realizing you had addressed this issue already. thanks for that! Problem is, I don't understand the first thing about PHP so nothing is intuitive. I tried adding the code in that you suggested - but not on line 127, rather on line 1506 or thereabouts. This is what I did on the user.module page:

function user_view($uid = 0) {
global $user;
$items=array();
$account = user_load(array('uid' => $uid));
if ($account === FALSE || ($account->access == 0 && !user_access('administer users'))) {
return drupal_not_found();
}

but I'm still getting the error on the user profile pages. If you can give me more detailed instructions on where to put $items=array() I'd be enormously grateful. thanks!

baja_tz’s picture

@jkamin

line 127 in flag_content.module not user.module

davemybes’s picture

StatusFileSize
new373 bytes

Thanks for that fix, works like a charm. Here's a patch :)

rconstantine’s picture

I think that the above solution suppresses the error from going to the screen but not the log. At least I think. So I changed the function to this:

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
        break;
      }

      $links = flag_content_link(FLAG_CONTENT_TYPE_USER, $account);
      if (empty($links)) {
       break;
      }
      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;
   }
}
marcoBauli’s picture

solution #4 above fixes the warning both on user page and watchdog, thx rconstantine ;)

rconstantine’s picture

Status: Active » Reviewed & tested by the community

Then this should be added to the module's code.

pomliane’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

This version of Flag content is not supported anymore. The issue is closed for this reason.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.

This issue has been automagically closed by a script.