I would be very grateful if anybody could help with this piece of code. I´d like to integrate it in custom user-profile.tpl.php, following php snippet to restrict access to user profile: Display allowed only to approved friends. I assume something ($flag) should be after "&& is_numeric(arg(1))"...
<?php
global $user;
if (arg(0) == 'user' && $user->uid == arg(1) && is_numeric(arg(1)) && ??? )
{
print "<div class=\"profile\">" . $user_profile . "</div>";
}
else {
print sorry;
}
?>
Thank you.
Comments
Comment #1
sirkitree commentedFlag friend has a function that lists a users friends. I would set this to a variable and then check to make sure the current user's uid is within that array of friends.
@see flag_friend_get_friends().
Comment #2
miljats commentedThanks sirkitree. I appreciate your effort to help me but I just do not know how to implement $friend->uid into it. :(
Is this what I´m looking for?:
Comment #3
sirkitree commentedActually if what you are trying to do is permit access to the url (ex: /user/4) then you should really be working with hook_menu_alter(), not implementing logic in your tpl file. That's a big slap on the wrist. ;)
Here's the concept.
The menu router system that provides [user/%user_uid_optional] (you can find this in user.module) has an 'access callback'. This points to a function that determines whether the current user (gloabl $user) has access to this url.
So if you want to only allow a user's friends to view their profile, you need to override the current 'access callback' with your own. Here is how to do this:
1. In your own custom module, implement hook_menu_alter() in order to override the typical function that is called.
2. Implement this custom access callback.
NOTE: code untested. Please test thoroughly before implementing on a production site.
Comment #4
miljats commentedI have created custom module "friendaccess" with "accessfriend.module" file. accessfriend.module contains this code:
rest of code:
i have put at the end of theme template.php. (that is right place?)
Result is that I can not see any profile and on profile page stays warning:
Thanks anyway, sorry for bothering and stealing your time.
Comment #5
miljats commentedSorry for the opening of previously closed thread, but one solution came out after few days of research.
This piece of code embedded into custom user profile template seems to be working.
I would be grateful if someone could review and confirm the correctness of the code.
Only the profile owner, profile owner's friends and the administrators have access to user profile.
Comment #6
sirkitree commentedClosing due to inactivity.