Hi,i am trying to make an extra "module" for advance profile to display only the icons of user's third party sites.

Can anybody tell me whats wrong with this code?

fuction get_icon($account_id){
  $result = db_query('SELECT s.uid, s.module, s.userid, s.userkey FROM {activitystream} s WHERE  userkey=NULL LIMIT 1',$account->uid,$account->module,$account->userid,$account->userkey);
  $action = db_fetch_object($result);

  $path= "activitystream/activitystream_'.$account->module.'/";
  theme_image(drupal_get_path('module', $path) . '/s.'.$account->module.'.png', $account->module);

return "(theme('activitystream_'.$account->module.'_icon')";
}

fuction get_icon should get the user's id and return the third's party site's icons.

Comments

akalsey’s picture

There's quite a few issues with this...

You probably want to pull from the activitystream_accounts table instead so you only get one icon for each account.

There isn't a column called userkey in any activitystream tables, so trying to use it in a where clause will result in errors.

You probably want the following sql instead: SELECT module FROM {activitystream_accounts} WHERE uid = %d

In your query you try and use an object called $account but it's not created anywhere.

Your db_query doesn't come anywhere close to matching how the db_query function works. You seem to be trying to pass in all the variables you want to fetch. You might want to have a look at the Drupal API docs at api.drupal.org and see how db_query is supposed to work.

You pull your database results into an object called $action but then try and get them from an object called $account.

The whole concept is going to fail for services that are fetched via user-supplied feeds. The theme function for those needs the data from the feed item in order to work. You'd probably need to grab unique values from the activitystream table, joined on the accounts table where the module is the feed module.

akalsey’s picture

There's also the fact that you have "fuction" instead of "function" so the code won't even compile.

And if you want more than one icon, you're going to have to run something multiple times. A loop somewhere is going to be necessary.

akalsey’s picture

Here, take a look at this code. It's untested, but the functions should do what you want.

function get_icon($account_id){
  $result = db_query('SELECT module FROM {activitystream_accounts} WHERE module != "activitystream_feed" uid= %d',$account_id);
  $icons = array();
  while ($module = db_fetch_object($result)) {
    if (function_exists('theme_'.$module.'_icon')) {
      $icons[] = theme($module.'_icon');
    }
  }
  $result = db_query('SELECT distinct(s.data) FROM {activitystream} s LEFT JOIN {node} n on s.nid = n.nid WHERE n.uid = %d',$account_id);
  while ($data = db_fetch_object($result)) {
    if (function_exists('theme_activitystream_feed_icon')) {
      $icons[] = theme('activitystream_feed_icon',$data);
    }
  }
  return theme('item_list',$icons);
}

You'll still need to get this into a module or a block somehow. And you'll need to pass in the uid of the user you want to show the icons for when you call it. It can't magically know who's icons you want.

akalsey’s picture

Status: Active » Closed (fixed)
skullJ’s picture

the $userkey added by me(facebbok need id and key)!

thank you i will try it