Errror on user profile page.

mdixoncm - July 31, 2007 - 09:13
Project:Flag content
Version:5.x-2.5
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:reviewed & tested by the community
Description

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

#1

jkamin - September 7, 2007 - 13:44

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!

#2

baja_tz - September 7, 2007 - 19:48

@jkamin

line 127 in flag_content.module not user.module

#3

incrn8 - September 26, 2007 - 13:27

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

AttachmentSize
flag_content_userprofile.patch 373 bytes

#4

rconstantine - September 28, 2007 - 00:51

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

#5

marcoBauli - December 4, 2007 - 10:35

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

#6

rconstantine - December 4, 2007 - 18:39
Status:active» reviewed & tested by the community

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

 
 

Drupal is a registered trademark of Dries Buytaert.