Has anybody hard coded the user.module to pull the (x) most recent images on their profile page?

Within the user.module I see the theme_user_profile() function. Is it possible to insert a $sql query here and display the results without overriding the module?

Ideally, I would like to have the code pull the latest 5 thumbnail images on and display on their user profile page.

Comments

mdixoncm’s picture

Its definitely not a good idea to go changing the actual Drupal core, no matter how tempting it can get you in a bit of a pickle when you come to upgrade etc ...

You have a couple of options - you can certainly override the user_profile theme, there is a nice example in the handbook here http://drupal.org/node/44481

In an ideal world you would try to aviod putting lots of SQL into your tpl file, you could perhaps put it into the phptemplate funtion in your template.php file (add data to the user object before passing it into the user_profile.tpl) ... (if your just wanting to make a couple of changes then this is hte method i would use)

BUT - I guess the "proper" grown up way of doing it would be to create a new module that implemented the hook_user - this allows you to add extra stuff to the $user object before it is displayed on screen ...

Good luck,

Mike

Mike,
Are you opinionated? HumanOpinion.org - a new drupal based site
from Computerminds

v1nce’s picture

I know it's not best to edit the core code but this would be a one-off and I can docuement it for future upgrades.

I didn't want to go the template.php override because I would have to rewrite everything that interacts with the user module.

Has anybody else implemented pulling the latest (x) thumbnail images to a user's profile page?

I'll have a look at the hook_user if the above isn't possible.

-------------------------------------
CommunityTraveler

mdixoncm’s picture

You wouldn't have to rewrite anything is you went the template.php route ... if you follow the stuff in the link i posted you will end up with this in your template.php file ...

function phptemplate_profile_profile($user, $fields = array()) {
 /**
 * This snippet catches the default user list pages layout
 * and looks for a profile_profile.tpl.php file in the same folder
 * which has the new layout.
 */
return _phptemplate_callback('profile_profile', array('user' => $user, 'fields' => $fields));
  }

Then modifiy this to add the extra info in here ...

function phptemplate_profile_profile($user, $fields = array()) {
//Do the extra work here
$result = db_result(db_query("SELECT field FROM my_table WHERE uid=%d",$user->uid));
$user->new_value = $result;
return _phptemplate_callback('profile_profile', array('user' => $user, 'fields' => $fields));
  }

The $user object that you have in the tpl file will now contain an extra property ->new_value and you can then do what you need to with it (the new value could be an array, object, whatever it doesn't matter) ...

Hope this helps :)

PS - I really would try and stay away from modifying core, I know it sometimes seems like the easy route but its a slippery slope (i've been there) to a nightmare un-upgradable system!!

Mike,
Are you opinionated? HumanOpinion.org - a new drupal based site
from Computerminds

v1nce’s picture

The code you reference there is for the /profile list page. I'm needing to work with the /user pages. I still don't see how overriding with the template.php file like http://drupal.org/node/35728 you wouldn't have to recode a bunch of snippets to include everything in the user_profile.tpl.php that was originally called by the user.module.

-------------------------------------
CommunityTraveler