For record user activity I'm using global token [user-name] and [user-id]. My pattern for node view action is: <a href="/user/[user-id]">[user-name]</a> view a node '<a href="[node-url]">[title]</a>'. Its work great when user is authorized, but when anonymous user view node, I see broken link to /user/0. How can I avoid this? Is it possible to make additional token to user's profile page (with aliased support)?

Thanks for help.

Comments

sirkitree’s picture

Title: Link to user's profile page problem » Provide clean url tokens to node author profile

In the case of an anonymous user, the uid is always going to be 0 and there isn't much we can do about that. We could probably create a new token that would detect if the uid is 0 and not create a link, but just report the 'Anonymous' user name.

You'll have to provide your own tokens for create clean url links as well. It would be helpful to more people than just yourself, I'm sure, and we've provided a way to extend the core tokens. If you take a look inside of the /activity/modules/comment.activity.inc file, you will see that we are extending the comment tokens there by creating the functions called comment_activity_token_list() and comment_activity_token_values(). This could also be done within the skeleton node.activity.inc file. Here is where you could create a new token that would use the node object's uid property in order to create a clean link to the node author's profile page or, if the uid is 0, just return text which is gotten from the site's designated 'Anonymous' user name.

drewish’s picture

what about the [author-link] token?

sirkitree’s picture

Please note that my above reply is incorrect and we are not providing an example to do this right now. It was taken out when we decided to provide the relevant node tokens because a comment is already associated with a node, so all of the node tokens are now available as well.

[author-uid/name/name-raw/mail/mail-raw] are available.
[author-link] could be created in /activity/modules/user.activity.inc

Scott Reynolds’s picture

Status: Active » Fixed

I went ahead and committed a whole bunch of these.

activity-node-link - link to the node
actiivity-node-creator-link - link to the node creator

activity-comment-author-link - link to the author of the comment

activity-user-link - link to the user.

After doing all that I realized that perhaps using theme('username') isn't a good thing. The reason why its potentially bad, is because the base line drupal implementation does

 if (user_access('access user profiles')) {
      $output = l($name, 'user/'. $object->uid, array('attributes' => array('title' => t('View user profile.'))));
    }
    else {
      $output = check_plain($name);
    }
  }

That means that if the user doesn't have permission to access user profiles then it won't render a link. So perhaps we need our own overridable theme function?

I leave that task to a separate ticket #580766: Provide a theme function that is virtually equivlent to theme_username

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sadist’s picture

hi scott.

i'm creating an activity template to record user comments. i used the token [activity-comment-author-link] and it recorded down but without Realname. i've been searching all over and the only issue created i got is this one.

the theme function that you posted here: http://drupal.org/node/580766 doesn't help at all. so is there anything else that i need to do?

cheers.

ee97083’s picture

Category: feature » support

Hi Scott!

This module is awesome but...I used [activity-node-creator-link] token for reporting when someone checked other person's Blog entry and the link is in fact created with the author's user name that created the entry but...the url points not to the profile of the node creator but to the profile of the user viewing the activity listing view!?! Why does it creates the text link well but not the url?

Can you help me please?

Regards

Scott Reynolds’s picture