User Profiles Version 2

Submitted by Michelle on Tue, 08/28/2007 - 22:20

As of February 6, 2008 I am marking this tutorial as deprecated. You can do everything in here with Advanced Profile faster and easier. It's still in alpha but is less buggy than this nearly year old tutorial. It's had a good run and made a lot of people happy but it's time to move on. I just don't have the time to support it anymore.

Please don't link to this page; use http://shellmultimedia.com/misc/user-profiles instead.

Goal: The aim of this tutorial is to walk you through every step you need to create a user profile like this one.

Skill level: This is a complex tutorial involving several modules. While I tried to make it as easy to follow as possible, it is not meant for beginners to Drupal and is not a quick drop-in solution. Please read it over and make sure you understand the concepts before attempting it. If you have problems, please use the support forum and I will answer if I am able.

Notes:

  • This tutorial assumes Drupal version 5.x
  • This does not use the core profile module or the bio module
  • The steps assume you want a profile exactly like mine. Most likely you'll want to do different things for your profile. I will try to provide alternates where possible but I'm not going to explore every possible permutation. I'll mark these alternates with [DIY...]
  • This tutorial only discusses the one user = one profile page method. You can get much more advanced using multiple nodes and pageroute, but that's beyond the scope of this tutorial.
  • You will be told to add things to your template.php file. If your theme doesn't have one, create a blank file in your theme with this name. The snippits are shown surrounded by < ? php and ? > (without the spaces) so the codefilter picks them up. You only need one < ? php at the top of your file and should not put them around every snippit.
  • If you are using subthemes, put the .tpl.php files in your subdirectory.

Modules needed:

  • Automatic Nodetitles - Not strictly needed, but it's handy so users don't have to put a title on their profiles and to keep the title consistant. If you don't use this, you'll need to adjust node-uprofile-edit.tpl.php so users can enter a title.
  • Buddylist - Allows users to designate other users as their "buddy". We will show a list of buddies on the profile page. If you don't use buddylist, take out the references to it. Unfortunately, I didn't do a check for the module so you will have problems if you don't remove the references yourself.
  • CCK - We need this to create the content type for nodeprofile to use. Also enable the field type modules that come with it as well as content copy.
  • Date - CCK date field used for birthdate. Also needs the adodb date library if you have people born before 1970. Just unzip it into the date directory.
  • Guestbook - Allows others to comment on a profile in a bit more organized way than simply enabling comments.
  • Link - CCK link field.
  • Node Profile (5.x-1.1 or later) - This is what allows us to make profiles out of nodes.
  • Node Profile Bonus - This has the code for taking over the user view page as well as fixes for the registration page. This is included in the zip and does not come with the nodeprofile module. You'll need to manually copy nodeprofile_bonus.module and nodeprofile_bonus.info into your nodeprofile module directory.
  • Node Family - Required by Node Profile
  • Private Message - We will check if the user allows private messages and add a link to do it if so. If you don't want private messaging on your site, you can skip this. Be sure to take out the reference in the node-uprofile.tpl.php file. Note: Prvatemsg has some new dependencies since this was written so get those as well.
  • Subform Element - Required by Node Profile
  • Token - Used by auotmatic nodetitles. WARNING: some versions of Token cause a WSOD when used with Link. If you are getting strange WSOD problems, try the dev version of Token.
  • Usernode - This is just used for the buddylist view.
  • Views - We will use this for the user's recent posts, the buddy list, and also searching users. Don't forget to enable the views UI module as well.

Step 1 - Getting prepared

  1. Download and install all the above modules.
  2. Set the user access control (?q=admin/user/access) for: buddylist, guestbook, privatemsg, user module (access user profiles) like like this. Note that you won't have permissions for the uprofile content until you create it in step 2.
  3. Configure buddylist (?q=admin/settings/buddylist) and privatmsg (?q=admin/settings/privatemsg) to taste. See guestbook section below before bothering with config.
  4. Set usernodes to not be promoted to front page (?q=admin/content/types/usernode)
  5. Download the file User-Profile-Tutorial.zip attached to this tutorial. This contains as much of my profile as I was able to export to save you time copying and pasting.

Step 2 - Creating and configuring the profile content type
Create the content type (see note at end of "Add the fields" section):

  1. Go to Administer -> Content Management -> Content Types -> [Add Content Type] (?q=admin/content/types/add)
  2. Name: User Profile
  3. Type: uprofile [DIY: If you name this something else, you will need to change it a few of the tutorial files or things will break.]
  4. Description: Whatever you want
  5. Title field label: If you're using auto_nodetitles this will be hidden.
  6. Body field label: Empty this out as we don't need the body
  7. Default options: Uncheck promoted to front page
  8. Maximum population: 1
  9. Check "Use this content type as a nodeprofile for users"
  10. Comments / attachments / pms: Disable all of these
  11. Save content type

Add the fields:

  1. Go to Administer -> Content Management -> Content Types -> [Import] (?q=admin/content/types/import)
  2. Content type: User Profile
  3. Paste in the contents of "User-Profile_uprofile-cck-fields.txt" found in the attached zip. Click submit. [DIY - Edit the User Profile content type and manually add all the fields that you want users to enter in their profile.]
  4. Your content type should now look like screenshots/User-Profile-Content-Type.jpg

Note: The reason I had you create the content type first and then import into it is that there seems to be a bug with groups not getting created when you create the content type at the same time. You can get around this by doing the import twice if you don't want to manually create the type.

Fix the fields display:

  1. Edit the User Profile content type you just created and click the tab for "Display Fields" (?q=admin/content/types/uprofile/display)
  2. Change all the labels for the fields to "inline". The groups can stay set to "above". This doesn't come across with the importing, unfortunately.
  3. Submit

Set the nodeprofile options:

  1. Edit the User Profile content type you just created and click the tab for "Node profile" (?q=admin/content/types/uprofile/nodeprofile) This tab is added by the nodeprofile module. If you don't see it, make sure you checked the box to make this type a nodeprofile node. Also make sure you have the latest version of nodeprofile as it's a new feature.
  2. Keep unchecked "Integrate this node profile with user categories."
  3. Check "Show this node profile during user registration." [DIY: Leave unchecked if you don't want it on the reg screen]
  4. User page display style: Display it as full node view
  5. Uncheck "Include an edit link to the display"
  6. Weight: 10 (this makes it come under username/email on the registration page but is unneeded otherwise)
  7. Submit

Access control:

  1. Go to Administer > User management > Access control (?q=admin/user/access)
  2. Set the permissions on "create uprofile content" and "edit own uprofile content".

Step 3 - Take over the user account view tab
By default, the nodeprofile module will put your user profile as a section on the user account view tab (located at /user/#). This is fine for simple profiles but doesn't look right for a full featured profile. [See screenshots/User-Account-Default-View.jpg]

This step makes the user profile take over the entire view tab. The downside is that you will lose anything that other modules add to this page. If you add a module that normally has a link on the user view page, make sure you provide alternate access to it. If you are fine with the way it displays by default, you can skip this step.

  1. Make sure the node_profile_bonus module is enabled. This has code for removing everything that's not a profile from the page and also adds an "Edit Profile" tab to the user account page for easy access.
  2. If you want to change your Edit tab to Edit Account to make things clearer, you need to add this code to your template.php:

    <?php
       
    if (arg(0) == 'user') {
         
    $vars['tabs'] = str_replace('Edit</a>', 'Edit Account</a>', $vars['tabs']);
        }
    ?>

    Adding this code is tricky because it needs to go in the _phptemplate_variables function. If you don't already have this function in your template.php, you can just add the entire function:

    <?php
    function _phptemplate_variables($hook, $vars) {
      if (
    $hook == 'page') {
        if (
    arg(0) == 'user') {
         
    $vars['tabs'] = str_replace('Edit</a>', 'Edit Account</a>', $vars['tabs']);
        }
        return
    $vars;
      }
    }
    ?>

    If you already have the function, you will need to merge it. The line "if ($hook == 'page') {" will likely already be there. So just put the code after that as it is in the first snippit.

  3. Add this code to your template.php:
    <?php
    // Override the display of the nodeprofile to just show the node itself and not the surrounding markup or the tabs.
    // Theming of the nodeprofile will be handled separately. Note that this affects it wherever it is displayed and
    // not only on the user page.
    function phptemplate_nodeprofile_display_box($element, $content) {
     
    $head = isset($element['#title']) ? '<h2 class="nodeprofile-title">'. check_plain($element['#title']) .'</h2>' : '';

      return
    $content;
    }

    // Override the entire user account view page to not show the categories or to seperate items into divs.
    // Note that this is set up to still show everything that is thrown on this page. Getting rid of non-nodeprofile
    // sections is done in the node_profile_bonus module by unsetting them but could also be done here by conditionally
    // printing them to begin with.
    function phptemplate_user_profile($account, $fields) {
      foreach (
    $fields as $category => $items) {
        foreach (
    $items as $item) {
         
    $output .= $item['value'] ;
        }
      }

     
    // Returning nothing from this function causes the entire page to whitescreen, so let's put something in by default
      // A better idea might be to load up some sort of standard thing that has the views and just not the profile fields
     
    if (empty($output)) {
       
    $output = "This user has not filled out a user profile.";
      }

      return
    $output;
    }
    ?>

Your user account page (?q=user/1) should now look like this: screenshots/User-Account-After-Page-Take-Over.jpg

Step 4 - Taxonomy
My profile uses taxonomy for some of the fields. I did this so you can click on a term and see all the other users with that term. With some coding, the taxonomy is used as though it was a normal CCK field.

Go to Administer > Content management > Categories (?q=admin/content/taxonomy). Create the following vocabularies: Communities, Hobbies, Reading, Music, TV and Movies. Communities is a multi select with the terms entered in via add term. The others are freetagging. Note: If you add these in a different order or choose different vocabularies, you will need to alter the node-uprofile.tpl.php code and the input form to match.

[DIY - Most people reading this are not going to want preset communities. Feel free to skip that vocab and add it as a normal CCK text field if you want and I'll make notes where you need to delete references to it later.]

Attach each of these vocabularies to your User Profile content type.

Step 5 - Add the views

  1. Go to Administer > Site building > Views > [Import] (?q=admin/build/views/import)
  2. Import the contents of User-Profile_User-tracker-view.txt. Submit and save the view. This view will display all the posts by a particular user.
  3. Import the contents of User-Profile_Buddylist-view.txt. Change the filter for node type to usernode. I don't know why this doesn't import correctly. Submit and save the view. This view will display the photo and name of all the user's buddies from the buddylist module. Make sure that you have a default user photo set or you will get errors if the user doesn't have a photo.
  4. To theme the buddylist view so that we get rid of the list markup, add this to your template.php. This code is all stock except for what is being returned at the end.
    <?php
    function phptemplate_views_view_list_buddylist_of_uid($view, $nodes, $type) {
     
    $fields = _views_get_fields();

     
    $taken = array();

     
    // Set up the fields in nicely named chunks.
     
    foreach ($view->field as $id => $field) {
       
    $field_name = $field['field'];
        if (isset(
    $taken[$field_name])) {
         
    $field_name = $field['queryname'];
        }
       
    $taken[$field_name] = true;
       
    $field_names[$id] = $field_name;
      }

     
    // Set up some variables that won't change.
     
    $base_vars = array(
       
    'view' => $view,
       
    'view_type' => $type,
      );

      foreach (
    $nodes as $i => $node) {
       
    $vars = $base_vars;
       
    $vars['node'] = $node;
       
    $vars['count'] = $i;
       
    $vars['stripe'] = $i % 2 ? 'even' : 'odd';
        foreach (
    $view->field as $id => $field) {
         
    $name = $field_names[$id];
         
    $vars[$name] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
          if (isset(
    $field['label'])) {
           
    $vars[$name . '_label'] = $field['label'];
          }
        }
       
    $items[] = _phptemplate_callback('views-list-buddylist_of_uid', $vars);
      }
      if (
    $items) {
        return
    implode(" ",$items);
      }
    }
    ?>
  5. Copy views-list-buddylist_of_uid.tpl.php to your theme directory. This formats the view to just show photo and name with no extra divs. The end result of this, the step above, and the CSS that will be added later is a mini thumbnail gallery of buddies.

A screenshot isn't possible at this point because these additions won't show up on the profile page until you get to the theming section.

Step 6 - Add the guestbook
Note: Advanced Profile doesnot use the guestbook module and I don't plan on trying to convert guestbook entries. If you plan on converting to advprofile, I reccomend leaving this step out.

The guestbook has been tweaked quite a bit to work as a commenting system on the profile page. This has made some of the options on the guestbook module non functional:

  • Anonymous users are not allowed to add entries.
  • Comments are turned off. (Instead, it's been modded so the user can post to his/her own guestbook.)
  • The pager is hard coded in the .tpl and ignores the options.
  • The add comment form is always on the page and not just linked to.

Directions:

  1. Copy guestbook.tpl.php to your theme dir. This controls the overall display of the guestbook section
  2. Copy guestbook-entry.tpl.php to your theme dir. This controls the display of a single guestbook entry
  3. Copy guestbook-form-entry-form.tpl.php to your theme dir. This controls whether the entry form or a note is displayed
  4. Add this code to your template.php:

    <?php
    // These overrides load custom .tpl files to handle the guestbook display as a whole, a single entry display, and the input form
    function phptemplate_guestbook($uid, $entries, $comment_entry, $limit = 20) {
      return
    _phptemplate_callback('guestbook', array('uid'=>$uid, 'entries'=>$entries, 'comment_entry' => $comment_entry, 'limit' => 20));
    }

    function
    phptemplate_guestbook_entry($uid, $entry, $comment_entry = NULL, $confirm_delete = false) {
      return
    _phptemplate_callback('guestbook-entry', array('uid'=>$uid, 'entry'=>$entry, 'comment_entry' => NULL, 'confirm_delete' => false));
    }

    function
    phptemplate_guestbook_form_entry_form($form) {
      return
    _phptemplate_callback('guestbook-form-entry-form', array('form'=>$form));
    }
    ?>

  5. While modifying module code is not recommended, there were a few changes I couldn't find a better way to do. I've put my modified version of guestbook.module into the zip file. You will need to overwrite the stock guestbook.module with this. All my changes are marked with //MAC and commented. If a new version of guestbook comes out, these changes will need to be merged in. That's why modifying modules is a bad idea. If anyone has a better way of doing it, I'd love to hear it. These are the changes:
    • Added a separate query so the guestbook on the profile page shows the last 5 entries with newest on top and the regular guestbook page shows them with oldest on top.
    • Removed the title from the text area on the add entry form as it was redundant.
    • Allowed users to post on their own guestbook
    • Changed the link on the poster's name/photo to go to their profile rather than their guestbook.

    I've also included a .patch file for those who prefer to make the changes to the module that way.

A screenshot isn't possible at this point because these additions won't show up on the profile page until you get to the theming section.

Step 7 - User gallery
The user gallery section depends on how you handle image galleries on your site and is beyond the scope of this tutorial. On my site, I used the following tutorial to make galleries: http://drupal.org/node/144725 . If you do it that way, you can use the view I included for a mini user gallery. To use this view, uncomment these lines in node-uprofile.tpl.php:

// $view = views_get_view('gallery_user');
// print views_build_view('embed', $view, array($profileuser->uid), false, false);

Then import the view found in User-Profile_Views_User-gallery.txt.

Other suggestions can be found in the comments here and here.

Step 8 - Theming the profile

  1. Copy node-uprofile.tpl.php to your theme directory. This contains all the code and fields for the user profile page and the teaser. Your account view page should now look like screenshots/User-Account-Before-CSS.jpg
  2. The CSS used for the user profile can be found in User-Profile-CSS.txt. Paste the contents of that file into your theme's .css file and edit to taste.
  3. Copy the "profile" directory into the "images" directory of your theme. This contains icons used by node-uprofile.tpl.php.

Step 9 - Theme the input form
The default input form you get after adding all the fields and taxonomy to your usernode can be overwhelming, so I moved things around and simplified them. If you want to use my simplified edit form:

  1. Add node-uprofile-edit.tpl.php to your theme directory.
  2. Add this code to your template.php to call it:

    <?php
    function phptemplate_node_form($form) {
       if (
    $form['#node']->type == 'uprofile') {
         return
    _phptemplate_callback('node-uprofile-edit', array('form' => $form));
      }
      else {
         return
    theme_node_form($form);
      }
    }
    ?>

  3. Because the taxonomy terms are given by number instead of name, you may need to adjust this file if the terms don't show up as they should. For example, print drupal_render($form['taxonomy']['tags']['2']) ; will print the textbox to put in terms for vocabulary ID #2. If that's the wrong vocabulary, change the "2" to the right number.
  4. If you opted to not make a term for community, leave out this part:
    print "Which community do you live in? If you don't live in the area, you can leave this blank.";
    print drupal_render($form['taxonomy']['1']);

Step 10 - Searchable view of profiles

  1. Go to Administer > Site building > Views > [Import] (?q=admin/build/views/import)
  2. Import the contents of User-Profile_User-listing-view.txt. Submit and save the view. This view will display a filterable list of all users with profiles.
  3. If your taxonomy is not set up as Communities, Hobbies, Reading, Music, TV and Movies numbered 1-5, the view will complain. You'll have to edit the view to change the numbers before importing.

Note: - If you want to display all users regardless of whether they have profiles, you will need to get the views_fusion module. There are instructions on drupal.org on how to use it but, honestly, I couldn't figure it out. Since I have the nodeprofile on the registration page, all users will have profiles, so I elected to take the easy way out and just do a view on nodeprofiles.

Step 11 - Redirect usernode / nodeprofile
One annoyance with having usernode and nodeprofile and the user page is you end up with paths going 3 different places. If you use the included node-usernode.tpl.php, it has a 301 redirect to the user page. node-uprofile.tpl.php also has this at the top. So anything that sends you to either the usernode or the nodeprofile node will zap you over to the user account page instead. Since it uses a 301, it's SEO friendly. There's probably better ways of doing it, but this is a nice global fix so I didn't have to worry about hunting down every link and fixing it.

Step 12 - Further plans

  • Selectable color scheme. I was thinking it would be nice to have a few different CSS options for users. Not quite on the level of MySpace but maybe allow them to choose from a pre-defined list. This could be done by adding another field to the nodeprofile and a little code to load CSS based on the value.
  • Limit viewing to people on buddy list. I'd like to give users the option to hide their profile information from anyone who's not on their buddylist. This would work in conjunction with setting the buddylist option to make people get approval before adding someone as a buddy. I haven't looked into the best way to do this, but it shouldn't be too hard to determine if the logged in user is a buddy and use if tests around the printing of the fields to control the display.

Comments

1 comment posted
Archived comments from dev site

Comments

it works!!!

The tutorial works and as expected it's even more awesome. I really like the new feature to redirect users to the user profile. Great work as always Michelle.

Great!

Thanks for testing it. I'll move it over to the live site when I have a bit more time.

Thanks,

Michelle

found a little mistake!

I was testing out my profiles today and there seems to be a little mistake on your node-uprofile-edit.tpl.php file.

print &quot;Which community do you live in? If you don&#039;t live in the area, you can leave this blank.&quot;;<br />print drupal_render($form[&#039;taxonomy&#039;][&#039;6&#039;]);

The community selection list doesn't show up when editing a profile, if community was your first vocabulary. If anyone else had this problem just change the 6 to a 1 or to whatever number is your vocabulary (you can see this hovering over the list terms link in the taxonomy admin section).

Oops

Community is 6 on my site. Thanks for the catch. I'll make the change before I put the tut live.

If I don't get any other comments, I'll likely make the switch sometime this weekend. If I don't go into labor first... ;)

Michelle

something's wrong....

I by far am no drupal coder, I generally stick to the Css/Design side. So Kudos on the Tut, however I've ran into a problem.

I followed the tutorial, and looked back over it several times, to make sure I didn't neglect anything, and for the life of me can't figure out what I did wrong.

When I go to my user account, and click edit my profile, it works perfectly fine. I can edit my name and whatnot, but then when i hit submit, and try to view it, it says "this user has not created a profile" and no matter how many times I fill out my info and submit it, it won't 'stick'. Any suggestions on what I might have done wrong?

Ok update on the previous

Ok update on the previous post. I logged out as admin, and then created a dummy account, like a normal user would do. and now the information takes. Apparently the admin can't create a profile with the above tut, or maybe I screwed something up. Either way its worth looking into I guess.

All in all, thanks for the tut, I may not be able to have my own profile with my admin account, but atleast everyone else can.

-cheers

apparently I'm not a good tester!!!

I get the same problem as you, but i actually think it's a good thing that the admin account isn't displayed in the userlisting, but I am puzzled as to why this happens. I also found another small mistake, the birthdate field isn't included in the node-uprofile-edit.tpl.php, so you have to add this line after the first name field:

print drupal_render($form[&#039;field_birthdate&#039;]);

I'm glad there is another person testing it, I thought that some stuff like the admin not showing up was a mistake in my code, because I modified some stuff. Another thing, the userlisting does display the age and the gender, but not the community and interests, does this happen on yours too? Well I'll look more into it, maybe it has something to do with my categories although I checked already, but I might have missed something. We'll just have to try to figure out how to solve our problems because Michelle will have her hands full this weekend. As soon as I find somethingout I'll post again, and if anyone has the same problem or found a solution/suggestion please post it. Cheers!!! And if your read this Michelle don't worry you got bigger things to worry about!!! Good luck with everything ;) !!!!!!!!!!!!!

this is not the ideal solution

I actually cheated a bit, I was suspecting that the variables in the teaser part of node-uprofile.tpl.php weren't working properly, because the render fields would display properly but not variables. What I did was I used the node-uprofile.tpl.php from my take on the old user profile tutorial, and used the content templates from that as well (I got some mistakes at first, but eventually got it to work after taking the gallery part I did from the comments, and some other variables). At least it works for me now, but I will still try to get the node-uprofile.tpl.php to work like Michelle intended it to, because I think it's more convenient than using content templates. Well, if anyone had the same problems I did and is desparate to get their site working, I suggest using content templates for now. Hopefully soon someone will find a solution, I know I will keep trying.

template.php problems

My avatars arnt showing up. I think Ive messed up my template.php.
I don't suppose someone could post a working one here?
please!!
Thanks

Thanks for testing... not sure when I'll get to this

I wanted to say thanks for testing this. I've not been feeling well and am not up to anything that takes much thinking right now. I don't know if this means labor is imminent or just another false alarm. At any rate, it may be a while before I can deal with user profile stuff so I wanted to let you know your work hasn't gone unnoticed; I just am not up to dealing with it right now.

Thanks,

Michelle

profile privacy

Hi!
Thanks for your great tutorial.

Please, what you think, will be possible to use this uprofile node with profile privacy module?

With this module user can celect which fields will be public and which not.

Thanks
Igor
somvprahe.sk

I'm using the zen-theme, how

I'm using the zen-theme, how can I merge the template.php code?

<font color="#000000"><font color="#0000BB">&lt;?php<br /></font><font color="#007700">function </font><font color="#0000BB">_phptemplate_variables</font><font color="#007700">(</font><font color="#0000BB">$hook</font><font color="#007700">, </font><font color="#0000BB">$vars</font><font color="#007700">) {<br />&nbsp; if (</font><font color="#0000BB">$hook </font><font color="#007700">== </font><font color="#DD0000">'page'</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp; if (</font><font color="#0000BB">arg</font><font color="#007700">(</font><font color="#0000BB">0</font><font color="#007700">) == </font><font color="#DD0000">'user'</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000BB">$vars</font><font color="#007700">[</font><font color="#DD0000">'tabs'</font><font color="#007700">] = </font><font color="#0000BB">str_replace</font><font color="#007700">(</font><font color="#DD0000">'Edit&lt;/a&gt;'</font><font color="#007700">, </font><font color="#DD0000">'Edit Account&lt;/a&gt;'</font><font color="#007700">, </font><font color="#0000BB">$vars</font><font color="#007700">[</font><font color="#DD0000">'tabs'</font><font color="#007700">]);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; return </font><font color="#0000BB">$vars</font><font color="#007700">;<br />&nbsp; }<br />}<br /></font><font color="#0000BB">?&gt;</font></font>

function _phptemplate_variables($hook, $vars = array()) {<br />&nbsp; switch ($hook) {<br />&nbsp;&nbsp;&nbsp; // Send a new variable, $logged_in, to page.tpl.php to tell us if the current user is logged in or out.<br />&nbsp;&nbsp;&nbsp; case &#039;page&#039;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // get the currently logged in user<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; global $user;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // An anonymous user has a user id of zero.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($user-&gt;uid &gt; 0) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // The user is logged in.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $vars[&#039;logged_in&#039;] = TRUE;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // The user has logged out.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $vars[&#039;logged_in&#039;] = FALSE;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

After finishing the tutorial

After finishing the tutorial the usernode still has a "Title" (the same as the username)... is it possible to remove this completely?

Thanks

Stupid me, it was all about

Stupid me, it was all about editing the "node-uprofile.tpl.php"....

Anyway, thanks for your tutorial, it's excellent!

Issue with linking to other users

Hello there,

Great tut, thanks for your time and hard work!

I am having a weird issue, and can not find the source at all.

When I am logged in and go to click on another user's name, it takes me to the "node-uprofile.tpl.php" instead of the "page.tpl.php". So all the fields and info are kinda just floating. This only happens if I go to other user pages... if I click on my own name all is normal...

Anyone else run into this issue?

Thanks for your time!

Dale

I can't get it to work

I was working through this tutorial very nicely and everything was ok up to step 3. I compared my uprofile screen to the example and it was the same. I then worked through to step 8 where the uprofile template is uploaded to the theme folder. At this point there is another example to compare with, but unfortunately, my uprofile screen does not look the same. The only difference between my step 8 screen and my step 3 screen was that no post information is now displayed. Apart from that, they look the same. I was expecting the views to have moved some things around the screen as in the example.

I've checked and double-checked all the steps and I can't find anything I've missed.

You can see my test site here: http://profile.fantasyf1game.net.

This tutorial is brilliant and I'm sure its just me making a stupid mistake, so any help would be greatly appreciated.

Thanks for all your hard work.

Ian

Had the Same Problem

Hi Ian,

I had the same problem. The reason is that I was using the attached .zip file code from the "live" post while working off of this one. Try the following:

1. Download the zip file attached to this post.
2. Delete all Views created during this tutorial.
3. Recreate the Views using the newly downloaded code.
3. Re-copy all files from the newly downloaded zip file to the template folder (Garland in my case). There were a LOT of changes to these files and you'll notice that as you go to overwrite the files you currently have, that the file sizes have changed. Files I did this with were (in alphabetical order):
a. guestbook.module (not in the theme folder, but I still used the latest to be on the safe side)

b. guestbook.tpl.php (overwrote the previous file)
c. guestbook-entry.tpl.php (overwrote the previous file)
d. guestbook-form-entry-form.tpl.php (overwrote the previous file)
e. Updated both nodeprofile_bonus.info and nodeprofile_bonus.module (again, not in the template, but still worth mentioning that the module file has changed)
f. node-uprofile.tpl.php (HUGE changes to this one - this will make MOST of the difference).
g. node-uprofile-edit.tpl.php

h. node-usernode.tpl.php
i. Get the latest changes in User-Profile-CSS.txt and change the style.css file in your template.
j. views-list-buddylist_of_uid.tpl.php

This worked for me and my profile looked IDENTICAL to yours. I still have some formatting issues, but it's MUCH better with the latest code. Let me know if this works for you.

Cheers!

Travis

Thanks, that worked.

DOH! I knew it was me making a simple error!

Thanks very much Travis. Your suggestions worked brilliantly.

One more thing...

I'm assuming you have your drupal install in a subdirectory as I do (since you only have one column showing).

Change the path on line 113 in node-uprofile.tpl.php from:
/sites/all/modules...etc.

To:

/drupal/sites/all/modules....etc.

This should fix the formatting issue (assuming the rest of what I said works).

Cheers!

Travis

Congratulations on the new

Congratulations on the new addition to your family and thank you so much for this easy to follow tutorial. It works for me and I'm using 5.1 drupal and the latest of each of the modules.

$taxonomy

just as a reminder.

using contemplate? -> $taxonomy is the way to go.

using template files? -> $node->taxonomy is it ;)

Thanks for your great work, Michelle - highly appreciated.

Works great, but here is a curve

I've modified the userprofile somewhat from your tutorial. Here is an example of a profile page (not much difference at this point). Here is an example that I am working on: http://www.clubalbuquerque.com/user/rachelgirl My real problem is that I am trying to use the imagefield CCK field in the profile for the user photo, rather than the normal user photo in the edit section. This will hopefully help me out with views. Indeed, I have a simple userlist http://www.clubalbuquerque.com/userlist2

My real problem is with the buddy list. I cannot seem to mesh your supplied view to get the photos from the imagefield. Any suggestions would be great. User-Profile_Views_Buddylist.txt. I have not much experience with views fusion but have tried to work that. Am just getting nowhere.

Thanks

Node Profile Bonus?

I cannot seem to find nodeprofile_bonus.module and nodeprofile_bonus.info anywhere. Are they supposed to be in the downloaded Node Profile zip? I cannot find them in there. Please help.

Thanks,
Rachael

Found it

Silly me. It's in the zip for this tutorial.

it does not work!!!

for me the tutorial ends at step 5.4
after pasting the code, the screen of my browser went blank!!!!! i have to remove the code from my template to 'see ' my drupalsite....
ok i step to 6...and i got the same prob's with the guestbook thing: after pasting the snippet to my template my screen went blank again!!!

any ideas

someone?

No freetagging terms

I don't know why, but Hobbies, Reading, Music. TV and Movies (none of the freetagging taxonomy fields) are showing up. I've already gone through the tutorial twice and everything else works. It's a shame because the clickable tags were what I was really looking forward to.... I've looked in node-uprofile.tpl.php and node-uprofile-edit.tpl.php and am not sure what I'm doing wrong. My vocabulary numbers are as follows

Communities: 17
Hobbies: 18
Reading: 19
Music: 20
TV: 21
Movies:22

Am I supposed to edit something in node-uprofile.tpl.php?

Is this right here?

print &quot;Which community do you live in? If you don&#039;t live in the area, you can leave this blank.&quot;;<br />print drupal_render($form[&#039;taxonomy&#039;][&#039;17&#039;]);<br /><br />print drupal_render($form[&#039;field_about_me&#039;][&#039;0&#039;][&#039;value&#039;]);<br /><br />print &quot;&lt;p&gt;Click on the arrows next to the sections below to expand them and fill in the information:&lt;/p&gt;&quot;;<br /><br />print &quot;Basic information:&quot;;<br />print drupal_render($form[&#039;field_first_name&#039;][&#039;0&#039;][&#039;value&#039;]);<br />print drupal_render($form[&#039;group_stats&#039;]);<br />print &#039;&lt;br /&gt;&#039;;<br /><br />print &quot;Share your interests:&quot;;<br />print &#039;&lt;fieldset class=&quot; collapsible collapsed&quot;&gt;&lt;legend&gt;Interests&lt;/legend&gt;&#039;;<br />print drupal_render($form[&#039;field_interests&#039;][&#039;0&#039;][&#039;value&#039;]);<br />print drupal_render($form[&#039;taxonomy&#039;][&#039;tags&#039;][&#039;18&#039;]) ;<br />print drupal_render($form[&#039;taxonomy&#039;][&#039;tags&#039;][&#039;19&#039;]) ;<br />print drupal_render($form[&#039;taxonomy&#039;][&#039;tags&#039;][&#039;20&#039;]) ;<br />print drupal_render($form[&#039;taxonomy&#039;][&#039;tags&#039;][&#039;21&#039;]) ;

Possible solutions

I see that your tags in the ...edit.tpl.php code you cited are one off, or you are missing the first and the last vocabularies. They should not be relative to zero but an exact match to the term number. You need to add a line for 17 and a line for 22. Make sure the node-uprofile.tpl.php has the corresponding numbers coded.

Secondly you must make sure you click on User Profile when you create the vocabulary. You can go back into edit and check it if you forgot. I forgot myself on a couple of them and had to go back and fix it, then they showed up. Also nothing shows on the profile display if the user did not enter anything.

-Edwin

Error

Great tutorial. I am pretty sure that I followed the tutorial (User profiles take 2) with each step. I kind of skiped Step 4 though. When I go to My Account I have my Username displayed, the View, Edit Account and Edit Profile tabs then I get the following error.

&nbsp;&nbsp;&nbsp; * warning: Invalid argument supplied for foreach() in /home/****/public_html/modules/views/views_query.inc on line 81.<br />&nbsp;&nbsp;&nbsp; * warning: Invalid argument supplied for foreach() in /home/****/public_html/modules/views/views_query.inc on line 16.<br />&nbsp;&nbsp;&nbsp; * warning: Invalid argument supplied for foreach() in /home/****/public_html/modules/views/views_query.inc on line 195.<br />&nbsp;&nbsp;&nbsp; * warning: Invalid argument supplied for foreach() in /home/****/public_html/modules/views/modules/views_node.inc on line 801.<br />&nbsp;&nbsp;&nbsp; * warning: Invalid argument supplied for foreach() in /home/****/public_html/modules/views/views_rss.module on line 56.

Under that I get my Picture then the User Profile with only View link (without other tabs) and the rest of profile and guestbook entries.

Any ideas what may have gone wrong? Thanks!

Unfortunately, I still have

Unfortunately, I still have not resolved this error. Any ideas please?

Thanks!

Your errors

I strongly suspect it has to do with the fact that you didn't enter the taxonomy (Step 4). Maybe you should try entering the taxonomy and see if the problem goes away. If it does go away and you don't want the taxonomy you will have to change the code.

help

please help me

when im trying to add the fields instep 2 by pastung the contents of "User-Profile_uprofile-cck-fields.txt in the import stage i get this messege
Parse error: syntax error, unexpected T_STRING in C:\Program Files\xampp\htdocs\drupal-5.1\modules\cck\content_copy.module(251) : eval()'d code on line 1
and this one after going back

The import data is not valid import text.
warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\drupal-5.1\modules\cck\content_copy.module(251) : eval()'d code:1) in C:\Program Files\xampp\htdocs\drupal-5.1\includes\common.inc on line 311.

what am i doing wrong it seem like a stupid mistake cause no one ask about this.
thanks uri

Success and bug fix

Thanks, Michelle, for a much improved tutorial. I have gotten the process to work.

There is a bug in the node-uprofile.tpl.php that is causing the Interests not to show up on the userlisting.

I changed line 29 from:

&nbsp; <br />foreach ((array)$taxonomy as $item) {

to:

&nbsp; <br />foreach ((array)$node-&gt;taxonomy as $item) {

And it fixed the problem.

I also added field_interests to the view and added

&nbsp; <br />print $node-&gt;field_interests[0][&#039;value&#039;] . &#039;&lt;br /&gt;&#039;;

right before line 92, so I get their interests as filled in the Interests field as well as the taxonomy interests

Additionally, I wanted to see Age in the Stats on the full profile page, so I accomplished this with a total hack:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#000000"><font color="#0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#007700">if (</font><font color="#0000BB">is_array</font><font color="#007700">(</font><font color="#0000BB">$node</font><font color="#007700">-&gt;</font><font color="#0000BB">content</font><font color="#007700">[</font><font color="#DD0000">'group_stats'</font><font color="#007700">])) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (</font><font color="#0000BB">$node</font><font color="#007700">-&gt;</font><font color="#0000BB">content</font><font color="#007700">[</font><font color="#DD0000">'group_stats'</font><font color="#007700">] as </font><font color="#0000BB">$key </font><font color="#007700">=&gt; </font><font color="#0000BB">$value</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (</font><font color="#0000BB">is_array</font><font color="#007700">(</font><font color="#0000BB">$value</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (</font><font color="#0000BB">array_key_exists</font><font color="#007700">(</font><font color="#DD0000">'#value'</font><font color="#007700">, </font><font color="#0000BB">$value</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (</font><font color="#0000BB">$key</font><font color="#007700">==</font><font color="#DD0000">'field_birthdate'</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000BB">$birthdate </font><font color="#007700">= </font><font color="#0000BB">$node</font><font color="#007700">-&gt;</font><font color="#0000BB">field_birthdate</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">][</font><font color="#DD0000">'value'</font><font color="#007700">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000BB">$now </font><font color="#007700">= </font><font color="#0000BB">time</font><font color="#007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000BB">$then </font><font color="#007700">= </font><font color="#0000BB">strtotime</font><font color="#007700">(</font><font color="#0000BB">$birthdate</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000BB">$diff </font><font color="#007700">= </font><font color="#0000BB">date</font><font color="#007700">(</font><font color="#DD0000">'Y'</font><font color="#007700">, </font><font color="#0000BB">$now</font><font color="#007700">) - </font><font color="#0000BB">date</font><font color="#007700">(</font><font color="#DD0000">'Y'</font><font color="#007700">, </font><font color="#0000BB">$then</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#FF8000">// the next line is a total hack, bypassing theming. but at least the classes are consistent for css<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#007700">print </font><font color="#DD0000">'&lt;div class="field field-type-text field-field-age"&gt;&lt;div class="field-items"&gt;&lt;div class="field-item"&gt;&lt;div class="field-label-inline-first"&gt;Age: &lt;/div&gt;' </font><font color="#007700">. </font><font color="#0000BB">$diff </font><font color="#007700">. </font><font color="#DD0000">"&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;"</font><font color="#007700">; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print </font><font color="#0000BB">$value</font><font color="#007700">[</font><font color="#DD0000">'#value'</font><font color="#007700">] ;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000BB">?&gt;</font></font>

which replaces the php snippet starting at your line 264 of node-uprofile.tpl.php. I'm sure there's a better way to code it and I would like to see it if someone would oblige, or perhaps I'll figure it out eventually.

I have not implemented the gallery yet. My next task will be to try the user picture gallery as suggested in Step 7.

-Edwin Basye
http://sitesthatgrow.com

Image gallery problem

I followed step 7 and added an instance of the Image content type. The result is that the gallery_user view shows nothing but my User name as a link back to my profile. This is true in the embedded view of the profile itself as well as going to the url gallery/users. What did I leave out?

I solved the problem

I had to change the view. I changed the image field from "Display" to "Thickbox: square_thumbnail"

This seems to be in the view import text but did not import for me correctly.

Cool, it works!

Are the forms html-safe?

Thanks for the tutorial, Michelle. It helps so much and it explains the basics on how to properly create user profiles.

Anyway, the only thing I'm concern are the safety of forms entry (on the node-uprofile-edit.tpl.php and guestbook-form-entry-form.tpl.php). Are those forms already html/php-safe so that users can't enter malicious codes? If not, what extra codes do I need to add there in order to protect those forms from any intrusive command? Thanks in advance.

Doubt it

It's my understanding (and I may be wrong, but I'm fairly sure) that Drupal checks for malicious code on output, not on input, so these forms wouldn't be any different.

Michelle

Thanks, what a great tutorial

This tutorial worked brilliantly (after some initial teething problems, all down to my own stupidity!). Thanks very much for writing it.

Title field required error

Hi Michelle,

Thanks a lot for this brilliant tutorial - very helpful.

My problem is that I seem to be getting a 'Title field required' error when I click on my account >> edit profile and try to submit without adding any content. I was expecting it to tell me to enter all the other required fields, but the form won't submit without the title field - it seems. I've got the node profile bonus enabled and have even tried adding this code:

$form[&#039;title&#039;][&#039;#type&#039;] = &#039;value&#039;;<br />$form[&#039;title&#039;][&#039;#value&#039;] = &#039;User profile form&#039;;

to the node-uprofile-edit.tpl.php & node-uprofile.tpl.php but it hasn't worked!

Please help.

Regards, dantina

You need to activate these 2 contrib modules

1) Auto nodetitles
2) Token

Somehow these 2 modules are missing in the current version of the tutorial. I had the same problem before so I went back to the older version of the tutorial to find the solution above.

Anyway, after you activate these modules, go to content type>>create content type and check the box called "Automatically generate the node title and hide the node title field". It's located right at the beginning of the setting, under "Automatic Title Generation". Then at the "Pattern for the title" text entry, type "[author-name]"

It worked! Thanks

Thanks for this kilimanjaro. Your solution worked brilliantly.

Your welcome

Glad to help :)

��<�?�p�h�p� � �/�/� �$�I�d�:� �t�e�m�p�l�a WHAT????

Michelle... many thanks! if only as a noob to Drupal i can get this working.... it all goes pear shaped at stage 3 when i have to edit the template.php in Garland... all i get is a page of ��&lt;�?�p�h�p� � �/�/� �$�I�d�:� �t�e�m�p�l�a followed by Fatal error: Call to undefined function phptemplate_comment_wrapper() in C:\xampp\htdocs\drupal-5.2\drupal-5.2\themes\garland\node.tpl.php on line 1 what am i doing wrong here?

Can someone drop me a hint?

where am i going wrong with the template... please

groups not showing

All of the fields for my profile are showing except the ones that are parts of groups. Even the Interests section works, but that's because the fields are printed one-by-one for that section. I could do the same for the others, but it's such a pain. I did a bit of testing, and found that none of the group names are part of the $node object, or part of the $node->content array. Does anyone know how to fix that? Thanks

Cannot get buddlist to work in the profile view page

Is there a way I can test out the view to list all of your buddies directly?

In other words, can I do

sitenane.com/buddies-of-uid/1

to get all buddies of UID 1 (which is supposed to have 5 buddies)

Any other suggestions on how to approach debugging would be extremely helpful.

Thanks

Urgently need help

Hi There,

I'm hoping someone can give me advice on how to debug or trouble shoot this. Everything else worked perfectly for me. I've spent hours looking at this, but just need to be pointed in the right direction.

The user profile just used to list one buddy (and picture), now it lists zero.

Can someone please help.

Problem found

It turns out, I had usernode set to not be published as the default behavior. When it hit the view's filter on published, it of course didn't return any results. To debug, I rebuilt the entire view one piece at a time until it stopped working. Hope this helps someone else, who makes the same mistake.

I have a strange problem...

I have a strange problem... each time I a user, uprofile node gets unpublished...
Anyone knows how I may fix it? It's irritating as hell...

Thanks

Maybe this is the problem

Go to "content type" (at your admin page), click "edit" on your "user profile" content, then activates the "published" option (under "workflow" section).

All of my content types have

All of my content types have "published" selected, so there has to be something else... :(

A user at Drupal.org found

A user at Drupal.org found the solution, but where and how do I have to put the code?
http://drupal.org/node/166639

Problem with the render

Somewhere in this mess of comments, someone pointed out that avoiding drupal_render($form); causes this. So that trick doesn't work properly.

Michelle

There are 2 private modules

"Private Node" and "NodeProfile Privacy". Both modules allow the users to set their profiles private. Private Node also allow "only your buddylist" to view your profile.

So would these 2 modules be integrated with the next user profile tutorial? Since we are using customized nodeprofile and nodeprofile-edit pages, these 2 modules are not visible no matter what settings we set up at admin. I played around with the theme templates but with no luck either.

user tracker view

When I first implemented this tutorial I didn't notice that the user tracker view is not paging. I am getting the entire list of posts for a user, which can be quite long, and no paging links to page through the list. I need a solution to this or how to limit the view to a fixed number of posts or all posts within the last 2 weeks. I see that the view is set up to page with a number set per page (it was 15, I set it to 5), but it is not having an affect on the full profile display.

Posted by Michelle on Wed, 08/29/2007 - 08:13