The next question in development.

I want a block to show up on user profile pages only if the profile page belongs to the current user. So I have :

Created a mini-panel with elements such as 'private messages' and 'buddy list'.

I then configured the block to show only if php code returns true with the following code:

<?php
global $node;
global $user;
if ($node->uid == $user->uid) return TRUE;
else return FALSE;
?>

Last, I go to the user profile panels and insert the new mini-panel into the profile page. But alas, it seems no matter what it shows up on all profile pages, not just just my own. What I have I done wrong?

Comments

WorldFallz’s picture

Couple of things--

-are you using the core profile module? core profile module does not produce nodes.
-i don't believe there is a global $node

Ceb’s picture

My core profile module is disabled and I am using the usernodes module. I had seen the 'global $node' used somewhere while lost on google so figured I'd give it a try as it made sense I'll look for other options.

WorldFallz’s picture

I've never used usernodes, so I'm not 100% sure, but try something like:

<?php
global $user;
$node = node_load(arg(1));
if ($node->uid == $user->uid) {
  return TRUE;
} else {
  return FALSE;
}
?>
binford2k’s picture

global $user;
return $user->uid == arg(1);

http://api.drupal.org/api/function/arg/6

Ceb’s picture

That code works beautifully if it is a block placed in a 'block location' and is filtering properly, but as mentioned in my other post, it is being ignored when imported into a panels page as a mini-panel.

Ceb’s picture

It would seem I may have had the right code in place 5 times already for all I know.

I also forgot to mention the use of the advanced profile kit, if it makes a difference.

BUT, the problem seems to be that by inserting a mini-panel into another panels page, the block visibility settings are being completely ignored.

The block at this moment says only to show if the php code returns true.... the current code is.

<?php
return FALSE;
?>

But still the block is showing up. So it seems it doesn't matter what code I use, it's being ignored.

Ceb’s picture

Well, for those of you who come here as a result of a search for something similar, the final workaround was to use the following code:

<?php
global $user;
if ($user->uid == arg(1) && arg(0) == 'user') {
return TRUE;
}
?>

and use it as a block rather than inserting it into a panel. As, apparently the block visibility is ignored by panels and has been mentioned in a few places on the forums with what appears to be no resolve.

ktonini’s picture

Figured this out if you'd still like to use panels.

I'm using Drupal 6, shouldn't be too much of a difference, if any.

Create a new block with the following code in the body:

<?php
global $user;
if ($user->uid == arg(1) && arg(0) == 'user') {
$blockView = module_invoke('MODULE NAME', 'block', 'view', 'MODULES BLOCK NAME OR BLOCK NUMBER');
print($blockView['content']);
}
?>

You should now have a block that "obeys" block filters but can be used in panels.

paul555’s picture

Hi all. I come back to this post so i can clarify some things. I created a block with the following custom code i found

<?php
global $user;
$myuid = $user->uid;
$node = content_profile_load(profile, $myuid);
$profileid = $node->nid;
?>

<?php print l("My profile","user/".$user->uid."/profile"); ?>
<br /><?php print l("Edit my profile","user/".$user->uid."/edit/profile"); ?>
<br /><?php print l("Contact me","user/".$user->uid."/contact"); ?>
<br /><?php print l("My photos","galleries/".$user->uid); ?>
<br /><?php print l("My friends","relationships/list"); ?>
<br /><?php print l("My private messages","messages"); ?>

I put this block in the user profile panel page i created. Now how can i combine the code from #comment-1761756 with the code i have in my block body in order it will be showed up only if the logged in user owns current profile?