How to get currently viewed Profile User Id -- or, even better, get code snippets inserted into Profile by modules
I am trying to set up some links on our site's users' account profile page which has been enhanced using the Advanced Profile module: That module doesn't show some of the cool features that the standard profile page does, such as Download this User's vCard, View this user's blog, etc. etc. which I need to let me users see on the profile.
So, It tried to just write php code in the body of a node that would put the Author's user ID into some links I wrote to link to these various features. The input format of the node body is set to PHP and it all displays correctly, but there is not user ID inserted. Now, I'm realizing it's probably that the Profile does not consider itself to have an Author or Author User ID.
So, where does this leave me? Is there some way to put the ID of the user of the Profile currently being viewed show up via PHP code? Or is there some other kind of replacement tag that I can use?
Even more simply, perhaps, can someone tell me how to find the code used for each module that inserts a link or other info into the standard user profile? I think that would be simplest -- I could just paste that to a block or node and show that on the Advanced Profile. I looked in all of the module folders for the modules that showed things in the profile, and searched the code within the module files for some profile code, and all I found was some comments mentioning the profiles, but not a spot of code that would display what those modules display on the profile.
Can anyone tell me how to do this?
Just in case this is helpful, here's the PHP code I tried to put into a node to display on the profile page:
<?php
print('
<ul>
<li><a href="/user/'.$node->uid.'/vcard">Download '.$user->name.'s vCard</a></li>
<li><a href="/privatemsg/new/'.$node->uid.'">Send '.$user->name.' a Private Message</a></li>
<li><a href="/mysite/'.$node->uid.'">View '.$user->name.'s MySite</a></li>
<li><a href="/blog/'.$node->uid.'">Visit '.$user->name.'s Blog</a></li>
</ul>
');
?>
When viewing a user profile,
When viewing a user profile, even if there is a pathauto alias hiding the real path, the underlying path that Drupal uses is user/uid# ... user is arg(0) and uid# is arg(1). Not sure how APK and/or node profiles may fit in the picture as I personally use core profiles. However in general, you can test for this path, and then capture arg(1) as the UID. If you are on a node which the author owns, you can ask it for $node->uid
Here's a snippet from some module code I was working on (originally idea from authorpane.module)
if (arg(0) == 'node') {// We're on a node page so load the node. UID of the node author can be acquired.
$node = menu_get_object();
$uid = $node->uid;
}
-- David
davidnewkerk.com | absolutecross.com
View my Drupal lessons & guides
Thanks for the info.
Thanks for the info. However, I don't know how to insert an argument into PHP code. Can anyone tell me how to do that?
Inserting info into a Profile page
The easiest way to add information to the Profile page is to write a module that uses the hook_user() hook. Here's a quick & dirty example that adds the vCard and Blog links, you should be able to figure out how to add the other two.
First you need a profilelinks.info file describing the module:
; $Id: profilelinks.info $name = Advanced Profile Links
description = Add some links to user profile pages.
core = 6.x
(There should be dependencies lines too, to tell Drupal what modules provide the vCards, blogs, etc. See http://drupal.org/node/206756 for an explanation of this file.)
Now for the actual module file, named profilelinks.module:
<?php
// $Id: profilelinks.module $
/**
* Implementation of hook_user().
*/
function profilelinks_user($op, &$edit, &$account, $category = NULL) {
switch($op) {
case 'view': // User's profile is being displayed.
$uid = $account->uid;
$name = $account->name;
// Add a "Links" section to the profile page.
$account->content['profilelinks'] = array(
'#type' => 'user_profile_category',
'#title' => t('Links'),
'#attributes' => array( 'class' => 'profilelinks' ),
'vcard' => array(
'#weight' => 1,
'#type' => 'user_profile_item',
'#title' => t('vCard'),
'#value' => l( t("Download $name's vCard"), "user/$uid/vcard" ),
),
'blog' => array(
'#weight' => 2,
'#type' => 'user_profile_item',
'#title' => t('Blog'),
'#value' => l( t("Visit $name's Blog"), "blog/$uid" ),
),
);
break;
}
}
Put both these files in a folder named "profilelinks", put that folder in your sites/all/modules folder, and enable the new module.