Subscribe to Umbrella Development

Member Profiles – Default Tabs?

Posted by Umbrella On December - 7 - 2009

It was recently asked in the iLance forums how to set which tab is the default that appears on a members profile when someone clicks the link. Our goal here is to make the Full Profile tab be our default visible tab whenever someone clicks a username link to go to their profile. There are several ways to accomplish this, so lets review them.

First we need to know how iLance prints the username and it’s associated link. One might think it’s straight forward, and that editing the html template will do the trick. Sorry, that’s not the case. With a little digging you will find that iLance prints the users name and profile link with a function called print_username. You’ll find this function in the functions/core/ directory buried in the functions.php file.

The function accepts a number of parameters which you can see in the code below:

 

function print_username($userid, $mode = 'href', $bold = 0, $extra = '', $extraseo = '', $displayname = '')
{
  1. The userid...simple enough.
  2. The Mode, upon reviewing the code you will find that there are several modes for this function to handle. those being:
    href, plain, custom, and url.
  3. bold. A simple 1 or 0 will tell the function whether or not to make the link bold.
  4. extra: allows us to pass custom parameters to the url that will be placed inside the link
  5. extraseo: allows us to pass custom parameters to the url and will display the url and not return a link.
  6. The final one doesn't even warrant an explaination. :)

Now that we know our function lets look at a couple different ways to acheive our goal. The first and simplest approach is to hack the function to make it do what we want. Simple enough. I personally am not using SEO currently so in this example I will only show how to alter the regular links.

First we need to find everywhere in the code where we are building the link I've highlighted the relevant lines below so you can see what I'm talking about.


function print_username($userid, $mode = 'href', $bold = 0, $extra = '', $extraseo = '', $displayname = '')
{
        global $ilance, $myapi, $ilpage, $ilconfig;
       
        $username = fetch_user('username', intval($userid));
        $html = '';
       
        // modes: href and plain
        if (isset($mode) AND $mode == 'href')
        {
                $displayname = $username;
                // bold usernames?
                if (!empty($bold) AND $bold)
                {
                        $displayname = '<strong>'.$username.'</strong>';
                }
                // does admin use SEO urls?
                if ($ilconfig['globalauctionsettings_seourls'])
                {
                        $html .= '<a href="' . ((PROTOCOL_REQUEST == 'https') ? HTTPS_SERVER : HTTP_SERVER) . print_seo_url($ilconfig['memberslistingidentifier']) . '/' . construct_seo_url_name($username) . $extraseo . '" rel="nofollow">' . $displayname . '</a> ' . construct_username_bits(intval($userid));
                }
                else
                {
                        $html .= '<a href="' . ((PROTOCOL_REQUEST == 'https') ? HTTPS_SERVER : HTTP_SERVER) . $ilpage['members'] . '?id=' . intval($userid) . $extra . '&profile=1" rel="nofollow">' . $displayname . '</a> ' . construct_username_bits(intval($userid));
                }   
        }
        else if (isset($mode) AND $mode == 'plain')
        {
                $displayname = $username;
                // bold usernames?
                if (!empty($bold) AND $bold)
                {
                        $username = '<strong>'.$displayname.'</strong>';
                }
                $html = $username;
        }
        else if (isset($mode) AND $mode == 'custom')
        {
                // bold usernames?
                if (!empty($bold) AND $bold)
                {
                        $displayname = '<strong>'.$displayname.'</strong>';
                }
                // does admin use SEO urls?
                if ($ilconfig['globalauctionsettings_seourls'])
                {
                        $html .= '<a href="' . ((PROTOCOL_REQUEST == 'https') ? HTTPS_SERVER : HTTP_SERVER) . print_seo_url($ilconfig['memberslistingidentifier']) . '/' . construct_seo_url_name($username) . $extraseo . '" rel="nofollow">' . $displayname . '</a>';
                }
                else
                {
                        $html .= '<a href="' . ((PROTOCOL_REQUEST == 'https') ? HTTPS_SERVER : HTTP_SERVER) . $ilpage['members'] . '?id=' . intval($userid) . $extra . '" rel="nofollow">' . $displayname . '</a>';
                }
        }
        else if (isset($mode) AND $mode == 'url')
        {
                // does admin use SEO urls?
                if ($ilconfig['globalauctionsettings_seourls'])
                {
                        $html .= ((PROTOCOL_REQUEST == 'https') ? HTTPS_SERVER : HTTP_SERVER) . print_seo_url($ilconfig['memberslistingidentifier']) . '/' . construct_seo_url_name($username) . $extraseo;
                }
                else
                {
                        $html .= ((PROTOCOL_REQUEST == 'https') ? HTTPS_SERVER : HTTP_SERVER) . $ilpage['members'] . '?id=' . intval($userid) . $extra;
                }
        }
       
        return $html;
}

 

Now we need to alter the code. Lets take our first highlighted line as an example:


$html .= '<a href="' . ((PROTOCOL_REQUEST == 'https') ? HTTPS_SERVER : HTTP_SERVER) . $ilpage['members'] . '?id=' . intval($userid) . $extra . '" rel="nofollow">' . $displayname . '</a> ' . construct_username_bits(intval($userid));

make it look like this:


$html .= '<a href="' . ((PROTOCOL_REQUEST == 'https') ? HTTPS_SERVER : HTTP_SERVER) . $ilpage['members'] . '?id=' . intval($userid) . $extra . '&profile=1" rel="nofollow">' . $displayname . '</a> ' . construct_username_bits(intval($userid));

If you look closely you will notice right after the $extra.' we added &profile=1" so now it looks like this $extra . '&profile=1"

Now just do this for all three highlighted areas in the code and you're done! Right? Well, yes and no. You are if you don't mind a hackjob. The more elegant way to do this and the way it was meant to be used, albeit the more time consuming method is to use the function as it is supposed to be used. By setting the parameters the way you want them set when you call the function.

What did he just say?!!

Simple, throughout the iLance script the print_username function is called. Do a find all with your favorite editor and then recode the calls to the functions so they provide the desired results. Of course this is also the more code intense way as well and you will need to be familiar with php and html.

For example, the forum ask's how this can be achieved from auction area. So for example we will use a product or forward auction as an example. Navigate to a product auction on your marketplace. You will note that the page in the url that you are looking at is merch.php, open that file, follow the code to the correct template. In our case the template is listing_forward_auction.html now open that up. Follow the template html to where the link is appearing. You will find it is actually being parsed into the template as a variable called {seller}


{apihook[seller_infobit_table_start]}
        
        <table width="100%" border="0" cellpadding="9" cellspacing="1">
        <tr>
            <td width="35%"><span style="font-family: arial; font-size:15px;"><strong>{seller}</strong></span></td>

Now if we go back the the merch.php file, and scroll up until we find where $seller is being set we will find something like this:

$seller = print_username($res_project_user['user_id'], 'href', 0, '', '');

Now we would want to update this code to looke like this

$seller = print_username($res_project_user['user_id'], 'href', 0, '&profile=1', '');

 

Now you would just have to do this simple little change all over the place. The trick is finding where you want to do it and everywhere it occurs. How to accomplish this falls outside the realm of this tutorial, but hey, you're an iLancer, which means you'll find a way! The only real problem with this, is when you upgrade your changes will be over-written so make sure you make good notes of where you changed things.

 

Hope this tutorial helped some people. Now I turn it over to you, discuss...

About the Author

I'll write something soon.

6 Responses to “Member Profiles – Default Tabs?”

  1. Hammack says:

    Hi Frank,
    Re-visiting this request to make Profile the default, rather than Feedback. Instructions here are great, and I understand how/why it should work. In my case however it is not having the desired effect, as Feedback is still showing as default.

    I’m wondering if since I’m using SEO (SEF – Search Engine Friendly URLS feature) if that is preventing it from working as intended?

    Can you comment on this, or provide troubleshooting advice. And thanks again for a well done ‘how to’.

    Thanks

  2. Umbrella says:

    Just checked out your site. I don’t even see the full profile tab.

    SEO will definitely kill this tutorial.

    In the final step of the tutorial make the code look this

    $seller = print_username($res_project_user['user_id'], 'href', 0, '&profile=1', '-profile');
    

    That should take care of the seo problem for ya.

  3. Hammack says:

    Yes – I fixed the full profile tab. Can see now!

    The SEO code did fix the problem perfectly!!

    I still have a big challenge though.. as I have not been able to configure the same ‘default to Full Profile’ from other areas of the site.

    For example, “Find Services” creates a list of users with full profiles. Each list includes a link to the users profile/feedback area. When hovering over this link is shows the mysite/members/user_id, but I don’t think the call from the search result is {seller} rather I think it’s {data[username]} which I can’t seem to track down like {seller} and $seller. I think I’m getting lost with all different user id variations like {vendor}, {provider}, {user}, etc.

    My main goal however is simply to have the search results of service providers with listings to have the same result as achieved from forward auctions. (I don’t have reverse auctions). From the url it seems like members.php would have handled these, but it seems to be ‘not’ so.

    I know I’m making this more complicated, but I’m at least gaining a lot of understanding through the process.

    Hammack

  4. Umbrella says:

    I understand what you’re trying to accomplish. I’m sorry to say you’re going to have to get your hands dirty to achieve what you’re after. Pretty much you have to locate where your site is calling the print_username() function.

    I’d just do a site wide search for print_username( and then locate the area’s where you want to change the link and do exactly the same as you did in the above tutorial to achieve the desired tab results.

  5. Hammack says:

    Got dirty and now getting the default url from listings I’ve been after . Thanks!

  6. Umbrella says:

    Glad to be of some assistance. That’s why we’re here. :)

Leave a Reply

About Us

Founded in 2005, our primary goal is to provide efficient custom solutions to its clients. Your satisfaction is our primary goal here, so come in from the rain and hire Umbrella Today!

On Twitter