I've been searching for this but can't find a satisfactory answer.

In a users profile there is a "Track" tab. This shows everything the user has added to the site. this is useful for the user who's profile it is, but it seems this is also viewable by any other user too.

Is it possible to make a users track tab only be visible to them and not other users?

If not is it possible to prevent certain content types appearing under the track tab?

Thanks

Comments

CleanCutRogue’s picture

You can theme the tab away, or create a module for it. When I create websites, I usually create a "glue" module just for that site that forces all the modules to behave the way I want by implementing various hooks and overriding theme-able (phptemplate_theme_whatever) functions. That way I don't have to muck with the user-submitted modules much and don't have all the functionality of my site tied to theme.

If you want a quick and dirty fix (that unfortunately ties your site's desired functionality to its selected theme) Add the code below to your theme's template.php file:

<?php
function phptemplate_remove_tab($label, &$vars) {
  $tabs = explode("\n", $vars['tabs']);
  $vars['tabs'] = '';

  foreach($tabs as $tab) {
    if(strpos($tab, '>'. $label .'<') === FALSE) {
      $vars['tabs'] .= $tab . "\n";
    }
  }
}

function _phptemplate_variables($hook, $vars = array()) {
  global $user;
  if ($hook == 'page') {
    if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) == $user->uid) {
        phptemplate_remove_tab('Track', &$vars);
      }
  }
}
?>

Please note: if you already have a function in your template.php file called _phptemplate_variables the you must add the functionality of this function to that one. If you need help with that, paste your template.php file's function here and I'll give ya a hand. Also note that this simply hides the tab. If a user knows the url, he can still see what another user on your site is up to by typing it directly. If you want to change that and don't want to develop a module, here's a quick and dirty fix for that:

at the top of your template.php file add the following:

<?php
global $user;
if (arg(0)=='user' && is_numeric(arg(1)) && arg(2)=='track' && arg(1)!=$user->uid) drupal_goto('access_denied');
?>
Allthegearnoidea’s picture

Thanks for this I have to go off to my real job (the one that pays me) now, but I'll give this a whirl tonight. I'll let you know how I get on.

Thanks

Support for families with children with medical conditions: http://www.parentsown.co.uk
Buy allergen free foods from http://www.freefromforkids.co.uk

Allthegearnoidea’s picture

Hi

Thanks for your help. I've added the code but it doesn't seem to have done anything.

Here is my template.php with the code added (the 'Track' (name of the tab) I have changed to 'My Messages' as that is what I changed the name of the tab to in my site):

/**
* Catch the theme_user_profile function, and redirect through the template api
*/
function phptemplate_user_profile($user, $fields = array()) {
  // Pass to phptemplate, including translating the parameters to an associative array. The element names are the names that the variables
  // will be assigned within your template.
  /* potential need for other code to extract field info */
return _phptemplate_callback('user_profile', array('user' => $user, 'fields' => $fields));
  }
function phptemplate_remove_tab($label, &$vars) {
  $tabs = explode("\n", $vars['tabs']);
  $vars['tabs'] = '';

  foreach($tabs as $tab) {
    if(strpos($tab, '>'. $label .'<') === FALSE) {
      $vars['tabs'] .= $tab . "\n";
    }
  }
}

function _phptemplate_variables($hook, $vars = array()) {
  global $user;
  if ($hook == 'page') {
    if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) == $user->uid) {
        phptemplate_remove_tab('My Messages', &$vars);
      }
  }
}

Any clues as to why it might not be working. As you can see I am clearly no pro. So any help would be great.

Thanks

Support for families with children with medical conditions: http://www.parentsown.co.uk
Buy allergen free foods from http://www.freefromforkids.co.uk

CleanCutRogue’s picture

hm... not sure... do you have a link to your site so I can look more closely at the construction of the tab html?

Allthegearnoidea’s picture

www.parentsown.co.uk

Thanks for your help on this.

Meanwhile I'll keep fiddling to see if it's something I'm doing wrong.

Support for families with children with medical conditions: http://www.parentsown.co.uk
Buy allergen free foods from http://www.freefromforkids.co.uk

CleanCutRogue’s picture

Wow - not sure how I messed it up like that :-) That's what I get for not testing my code. The following should work. It should remove the "My Messages" tab from any profile you view that isn't your own. Is that what you're trying to do?

<?php
function phptemplate_remove_tab($label, &$vars) {
  $tabs = explode("\n", $vars['tabs']);
  $new_tabs = array();
  $vars['tabs'] = '';

  foreach($tabs as $tab) {
    if(strpos($tab, '>'. $label .'<') === FALSE) {
      $new_tabs[] = $tab;
    }
  }
  $vars['tabs']=implode ($new_tabs,"\n");
}

function _phptemplate_variables($hook, $vars = array()) {
  global $user;
  if ($hook == 'page') {
    if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) != $user->uid) {
        phptemplate_remove_tab('My Messages', &$vars);
      }
  }
}
?>
Allthegearnoidea’s picture

That's exactly what I'm trying to do :-)

I'll have a go at implementing this tonight....

Nice to see you log in :-) Such a new site I always get excited when new users log in....Even if it was only to look at my code!

Thanks again for sticking with this one! I'll let you know how I get on!

Support for families with children with medical conditions: http://www.parentsown.co.uk
Buy allergen free foods from http://www.freefromforkids.co.uk

Allthegearnoidea’s picture

Thank you for your patience on this cleancutrogue.

The code didn't work i.e. it didn't remove the tab from any profile.

However with some digging back in my old stuff I found some code I implemented ages ago when i was playing with Drupal.

This code removes the tab effectively. But (of course), it removes it for all users regardless of whether you are looking at your profile or someone elses. How would I modify this to get it to show the tab on the logged in users profile but if that logged in user viewed anyone elses profile they would not see that persons My Messages tab?

/**
* Override or insert PHPTemplate variables into the templates.
*/
function _phptemplate_variables($hook, $vars) {
if ($hook == 'page') {
themename_removetab('My Messages', $vars); // replace themename with your theme's name
return $vars;
}
return array();
}

/**
* Removes a tab
*/
function themename_removetab($label, &$vars) { // replace themename with your theme's name
$tabs = explode("\n", $vars['tabs']);
$vars['tabs'] = '';

foreach($tabs as $tab) {
if(strpos($tab, '>' . $label . '<') === FALSE) {
$vars['tabs'] .= $tab . "\n";
}
}
}
?>

Thanks again for all your efforts.

Support for families with children with medical conditions: http://www.parentsown.co.uk
Buy allergen free foods from http://www.freefromforkids.co.uk

CleanCutRogue’s picture

the code is nearly the same as mine, but illustrates what I forgot... I forgot to return $vars; from my _phptemplate_variables implementation. In fact, my first solution would have worked if I would have remembered to return $vars;... so just add the return at the end of the function and all should work.

In other words:

<?php
function phptemplate_remove_tab($label, &$vars) {
  $tabs = explode("\n", $vars['tabs']);
  $new_tabs = array();
  $vars['tabs'] = '';

  foreach($tabs as $tab) {
    if(strpos($tab, '>'. $label .'<') === FALSE) {
      $new_tabs[] = $tab;
    }
  }
  $vars['tabs']=implode ($new_tabs,"\n");
}

function _phptemplate_variables($hook, $vars = array()) {
  global $user;
  if ($hook == 'page') {
    if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) != $user->uid) {
        phptemplate_remove_tab('My Messages', &$vars);
      }
  }
  return $vars;
}
?>
Allthegearnoidea’s picture

...you are a total genius!! Works like a dream! My Messages tab is visible to the logged in user but not to any user who is viewing another users profile.

Thank you so much for sticking with me on this one cleancutrogue. You really do the community justice. :-)

Thanks again.

Support for families with children with medical conditions: http://www.parentsown.co.uk
Buy allergen free foods from http://www.freefromforkids.co.uk

CleanCutRogue’s picture

I'm just sorry I forgot to return the variable! :-) Have fun!

crutch’s picture

I also need to hide the Track tab for all users except the current user. The reason is there seems to be no other way to show comments for a user. I've tried all kinds of view arguements and settings and also attempted to config nodecomment module which is not what I needed. So Track tab works for my purpose. However, since I have permissions so all users are able to view other users profiles, an users Track tab is also viewable by all users.

I'm using Zen and when attempting to add code to template.php it seems to not work. The page still renders but shows warning on screen. The tab is still viewable by all users.

Warning: Call-time pass-by-reference has been deprecated in C:\wamp\www\sites\all\themes\testsite\template.php on line 181

using...


function phptemplate_remove_tab($label, &$vars) {
  $tabs = explode("\n", $vars['tabs']);
  $vars['tabs'] = '';

  foreach($tabs as $tab) {
    if(strpos($tab, '>'. $label .'<') === FALSE) {
      $vars['tabs'] .= $tab . "\n";
    }
  }
}

function _phptemplate_variables($hook, $vars = array()) {
  global $user;
  if ($hook == 'page') {
    if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) == $user->uid) {
        phptemplate_remove_tab('Track', &$vars);
      }
  }
  return $vars;
}

halloffame’s picture

Is the code working for D6?

fehin’s picture

subscribing

bewhy’s picture

you can find a patch to add permissions at:
http://drupal.org/node/762962

I don't like any site where I don't have admin menu

francewhoa’s picture

Another way to do that is with Views modules. Read more at http://drupal.org/node/230632#comment-759623

Loving back your Drupal community result in multiple benefits for you