Friday, January 23, 2009

Customising the user profile layout

(Thanks to Dublin Drupaller for starting this section of the handbook)

The PHP Snippets below are intended for use within a customised USER PROFILE page that simply enables you to “pull” specific content from your drupal database specific to a particular user and display it in the way you want.

They are intended for use with a phptemplate based theme and for Drupal site developers who do not have php programming knowledge but want to push out the boundaries of user profile pages and control precisely how they look.

See also Advanced Profile Kit for an alternate method of sprucing up your user profile pages.

Simple step-by-step instructions are provided.
The concept

Drupal is an extremely powerful tool for building online communities, in particular, allowing users to submit their own content to a community hub. A good illustration of this working well online might be the World famous myspace.com site, where bands/artists are able to submit content into their own page.

Drupal has all the tools available to create your own myspace.com style community hub.

These snippets are intended as a mini-repository and as an aid for site designers without php programming skills to create sophisticated User Profile Pages for members of their community.

Customised User Profile Pages maybe applied to many applications. myspace.com is primarily a site for artists & bands, but, similar techniques could be used for other applications such as a rzye.com (Drupal powered community hub) style professional networking hub or terminus1525 (Drupal powered community hub) for studios.
Getting Started - (Drupal 4.x and Drupal 5.x)

Step 1 - is to override the default User Profile page layout by uploading the special template.php file to your active theme folder.

$account, ‘fields’ => $fields));
}
?>

If you already have a template.php file in your active theme folder, simply add the above to the existing template.php file and upload it.

Step 2 - (Drupal 4.x and 5.x) is to create your customised user_profile.tpl.php file and upload that to your active theme folder.

If you’re starting from scratch, simply open notepad.exe or a similar text editor and paste in the snippets linked below to build your custom user profile page. Save it with the user_profile.tpl.php filename and upload it to your theme folder along with the template.php file.

Once you have got started with your first user_profile.tpl.php file, you can experiment with adding in more snippets or including HTML layout controls to get a feel for the flexibility this allows.
Getting Started - (Drupal 6.x)

Step 1 - is to override the default User Profile page layout by uploading a custom user-profile.tpl.php* file to your active theme folder.

Drupal will automatically detect the presence of your custom user-profile.tpl.php and override the default user profile layout. To make this happen, you need to rebuild the theme registry, which you can do by clearing the caches (for example using the button on the admin/settings/performance page), or simply by visiting the admin/build/modules page.

* note that in Drupal 6.x, your custom user profile layout file name uses a hyphen, instead of an underscore.

Step 2 - is to customise your user-profile.tpl.php layout file.

By default, all user profile data is printed out with the $user_profile variable. If there is a need to break it up you can use $profile instead.

As an example, the following snippet inserted in your custom user-profile.tpl.php will display the default user profile layout.

Available variables:

* $user_profile: All user profile data. Ready for print.
* $profile: Keyed array of profile categories and their items or other data provided by modules.

To check for all available data within $profile, insert the following snippet at the bottom of your custom user-profile.tpl.php.

Available variables

The following is a list of variables that is available to your custom user-profile.tpl.php.

'. check_plain(print_r($profile, 1)) .'

‘; ?>

How to use these snippets

Simply copy and paste these snippets into your custom user profile layout file and upload it to your active theme folder. Check to make sure that the snippet you are using is compatible for the version of Drupal you are using.

It’s recommended that you test your customised user_profile.tpl.php(Drupal 4.x or Drupal 5.x) or user-profile.tpl.php file (Drupal 6.x) on a test installation before adding to a live site.
Adding new snippets

Simply click on the ADD NEW CHILD PAGE link below and create a new handbook page. Include any dependencies, such as which version of Drupal you have tested the snippet with or extra modules that need to be enabled for the snippet to work.

PLEASE NOTE! The following snippets are user submitted. Use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.

* A basic User Profile Page to help get you started
* Customising the user profile pages (a “before” and “after” example with screenshots)
* User Profile avatar/picture Snippet
* Handling single-line profile fields
* Handling multi-line profile fields
* Handling checkbox profile fields
* Handling freeform profile fields
* Handling URL profile fields
* Recent weblog entries (titles) snippet
* Recent weblog entries (titles & teasers) snippet
* Add/delete to/from buddylist snippet
* Display a list of buddies snippet
* Display list of (x) recent posts (titles) snippet
* User “history” or “member for: (time)” snippet
* Adding layout and content to the default user profile theme
* allow users to choose whether certain profile fields are visible or hidden
* Allowing users to customize their profile
* Custom User Blocks and User Tables PHP Snippets
* Customising the user profile layout per role
* Display link to user’s embedded gallery (or not if it does not exist)
* Display a customisable “this user is [online/offline]” status message in the User Profile page
* Display a user friendly text message when profile fields are left blank
* Display a user’s points value from the userpoints.module
* Display recent nodes (titles & teasers) snippet
* Displaying counts from the Invite module
* Drupal V5.x warning: Cannot add header information
* Handling date profile fields
* Howto: Make the user profile layout compact (with css only)
* Insert Subscribed Organic Groups List
* Messages for unpublished profiles
* My Comments Block for Profiles
* Outputting full civiCRM profile to custom profile
* Outputting individual CiviCRM profile fields into custom Drupal profile
* User Profile Page
* User referral module
* Weight sorting for input fields (when the user fill the form) doesn’t apply - fix
* Insert user friendly “click here to add your..” links when user profile fields are left blank
* Display a date related notice or countdown snippet
* Send private message snippet
* Display a Skype “Call me” or “leave a voicemail” button depending on Users’ online/offline status
* Display users age based on a date-of-birth field
* insert a “view your order history” and “view [username]s store” link
* Show/hide certain profile fields depending on user role or user permissions

No comments: