Posted by sadist on January 10, 2010 at 4:22pm
9 followers
Jump to:
| Project: | Facebook-style Statuses (Microblog) |
| Version: | 6.x-2.x-dev |
| Component: | Code - Functionality |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
at the moment, there's permission option to set user to be able to post on all profiles. this is going to be hectic for a social networking site to let anyone to post on any other profile.
so, is there a way to only make the user to be able to only post on related user's profile?
Comments
#1
Yes, you will need to implement hook_facebook_status_post_access_alter() in a custom module.
For example, from what I can tell from the Flag Friend API, you might do this to allow users only to post on their friends' profiles:
<?phpfunction example_facebook_status_post_access_alter(&$allow, $owner, $poster) {
if (module_exists('flag_friend')) {
$flag = flag_get_flag('friend');
if (flag_friend_determine_friend_status($flag, $owner->uid, $poster->uid) != FLAG_FRIEND_FLAGGED) {
$allow = FALSE;
}
}
}
?>
#2
i would like the same feature, im using UserRelationships though
#3
use this
<?php
function example_facebook_status_post_access_alter(&$allow, $owner, $poster) {
if ($owner->uid == $poster->uid){
return;
}
if (module_exists('user_relationships_api')) {
$relationships = user_relationships_load(array('between' => array($owner->uid, $poster->uid)));
$allowed = FALSE;
foreach ($relationships as $relationship) {
if ($relationship->approved){
$allowed = TRUE;
break;
}
}
$allow = $allowed;
}
}
?>
#4
thank you
#5
Re #3, don't set
$allow = $allowedat the end because$allowedmight beTRUEbut another module may previously have set$allowtoFALSEand you shouldn't overwrite it.$allowisTRUEby default, and you should only change it if you're going to set it toFALSE.#6
Thanks IceCreamYou.
<?php
function example_facebook_status_post_access_alter(&$allow, $owner, $poster) {
// return if !$allow, means some other module set it to FALSE already
// and we don't need to have access check here if $owner == $poster.
if (!$allow || $owner->uid == $poster->uid){
return;
}
if (module_exists('user_relationships_api')) {
$relationships = user_relationships_load(array('between' => array($owner->uid, $poster->uid)));
$allowed = FALSE;
foreach ($relationships as $relationship) {
if ($relationship->approved){
$allowed = TRUE;
break;
}
}
$allow = $allowed;
}
}
?>
#7
NP. Added a link to this thread from the docs (but if you got here from the docs, this is not the place to post your problems! Open a new issue, please).
#8
4vinoth, could you share with what and how you do? sorry, i'm very new at creating own custom module.
#9
@sadist documentation is your friend.
#10
just out of curiosity, why do you recommend creating a new module for this single function instead of adding it as a patch to fbss module?
#11
subscribe
#12
@adam_c Because more would go into adding it to FBSS than what you see here. Not everyone would want the functionality it adds, so I'd have to add a setting, but there are several relationship modules, and it would be a pain to support them all. In addition, once one relationship-module-related feature was added, there are several more features that are complementary. For example, users would expect a setting that would allow choosing which relationships would allow or disallow posting (i.e. only allow posting if you're a friend, not a fan). Many other implied features have to do with Views. It's difficult to keep up with (not to mention support) all of those for several different modules, and it's almost impossible to build default Views that everyone can use if there are relationship-module-specific rules in there. In other words, it implies a lot of bloat (and a lot of maintenance work for me) that a lot of users wouldn't even use.
Obviously, asking users to create a new module for this is not the most user-friendly method, but that's how it goes when there's such a wide range of uses. That's why the APIs exist. But nothing is stopping you from adding a Facebook-style Statuses Relationships module on drupal.org if you feel strongly about it. :-)
#13
Ok if i can get it to work i will upload it.
I went through the drupal book on making modules, did what it said but after i installed the module it killed the whole site so i then had to disable the module directly in the DB and then run update.php just to get the site back.
Could you tell me where i've gone wrong please, below is exactly what is in the .moule file:
<?php
// $Id$
function fb_friend_perm() {
return array('use fb friend content');
}
function fb_friend_facebook_status_post_access_alter(&$allow, $owner, $poster) {
// return if !$allow, means some other module set it to FALSE already
// and we don't need to have access check here if $owner == $poster.
if (!$allow || $owner->uid == $poster->uid){
return;
}
if (module_exists('user_relationships_api')) {
$relationships = user_relationships_load(array('between' => array($owner->uid, $poster->uid)));
$allowed = FALSE;
foreach ($relationships as $relationship) {
if ($relationship->approved){
$allowed = TRUE;
break;
}
}
$allow = $allowed;
}
}
the module is called fb_friend and there is purposfully no ending
?>
I suspect it's something to do with the function title?
#14
@adam_c That should be a separate issue.
#15
Icecreamyou, I tried making a module with your code and it did not work, bUT I think the problem is with flag friend. I'm going to post an issue there. When I go to look at a users friends it shows that I am friends with them when in fact I know I'm not.
#16
The code in this issue is not supported, only suggested. I haven't personally tested it.
#17
@adam_c
the code you tried was suggested for user relationships module.
#18
Hi IceCreamYou
where i must placed the code, please help, step by step
Thanks
#19
@ngudiono http://drupal.org/node/680614#comment-2500918
#20
hi,
i need the option share this status to public or friends which i very next to photo and video attachment.this is my requirement.i use user relationship module for friends adding.how i achieve this by using above code.i try code as per your steps but cant get my desired result.did u give any idea to change the code based on my requirements.
thanks
#21
@vasan.85:
This issue explains how administrators can make all status updates visible only to friends. It seems that you have a different requirement -- the ability for users to choose who can see their status updates before posting each status -- which belongs in a different thread. Feel free to reopen your original issue if that is the purpose for which you intended it. (However, what you're asking is not currently possible. You will probably have to hire a developer to do it for you.)
In the future, please keep in mind that issues with the "closed" status are finished. That means that you usually should not post new comments in closed issues. (And if you do have a legitimate reason to post a comment in a closed issue, your comment will rarely receive a response unless you reopen the issue.) For more information, please read http://is.gd/ejKpo and http://bit.ly/cRCwuh
#22
Hi,
I found that this was a problem for me as well. I have flag_friend module installed and needed to limit access to who could/could not post on my wall.
after reading here I was able to make some alterations and voila.
<?php
/**
* Alter user access.
*
* @param $allow
* Whether the action is permitted to be taken. Change this only if you can
* decide conclusively that the action is definitely (not) permitted.
* @param $op
* The action being taken. One of add, converse, delete, edit, view,
* view_stream, generate.
* @param $args
* An array of additional arguments. Varies depending on $op.
* @see facebook_status_user_access()
*/
function CUSTOM_facebook_status_user_access_alter(&$allow, $op, $args) {
global $user;
switch ($op) {
case 'add':
$flag = flag_get_flag('friend');
$recipient = isset($args[0]) ? $args[0] : $user;
$type = isset($args[1]) ? $args[1] : 'user';
$sender = isset($args[2]) ? $args[2] : $user;
$context = facebook_status_determine_context($type);
//Updating one's own status should ALWAYS be allowed.
if ($type == 'user' && $context['handler']->recipient_id($recipient) == $sender->uid) {
$allow = true;
}
// if there is no flag between sender & recipient then dont allow them to post
elseif (flag_friend_determine_friend_status($flag, $sender->uid, $recipient->uid ) != FLAG_FRIEND_FLAGGED) {
$allow = False;
}
break;
}
}
?>
Hope this helps somebody.
ps. you will need to place this code into a custom module and have flags/flags_friend installed/working..