hi,
I want to build a custom module to see if I (as logged-in user) have a relationship to an any user when viewing nodes created by an other user.
Someting like this.
Let's say we have a default drupal installation with two users "User A" and "User B" and the User Relationship module to create relationships between users.
- User A and User B have no "friends".
- User A logs in and he creates several blog entries.
- Then, User B logs in and he can see the blog entries made by User A on the frontpage. He can click on the title, read the whole node and comment on them if he likes to.
What I want to do is:
- write a custom module which checks if User A and User B are friends or not (if possible by using the User Relationship API).
- If there's no friendship relationship between them, User B should not have any access to the blog entries (neither the teaser on the frontpage nor the whole node).
- If they become friends then User B has access to read and comment on the blog entries.
I played around with hook_user_relationships($op, &$relationship) but couldn't get anything working.
I've also read the README.txt under sites/all/modules/user_relationships/user_relationships_api/ but I've no idea what to do with the information :(
How can I achieve this?
Thanks in advanced.
Best regards.
Comments
Ok, I managed to get some
Ok, I managed to get some information about nodes being viewed as teaser and as single page.
<?php
function MY_CUSTOM_MODULE_nodeapi(&$node, $op, $a3, $a4) {
GLOBAL $user;
$me = $user->uid;
$count = user_relationships_load(array("between"=>array($me, $node->uid), 'approved'=>1), array("count"=>TRUE));
switch($op) {
case "view":
if($count>0 || $node->uid==$me) {
if($a3) {
print "VIEW -> ".$node->title." | ".$node->type." | Status: Teaser | ".$node->name."<br/>";
}
if($a4) {
print "VIEW -> ".$node->title." | ".$node->type." | Status: Page | ".$node->name."<br/>";
}
}
break;
case "load":
if($count>0 || $node->uid==$me) {
print "LOAD -> ".$node->title." | ".$node->type." | ".$node->name."<br/>";
}
break;
}
}
?>
Now that I know which nodes are created either by me or by one of my friends, how can I unload/hide the nodes that were created by users who aren't my friends? I'v searched for functions like "hide" or "unload" on this page -> http://api.drupal.org/api but couldn't find anything useful.
I think the "view" case isn't really needed and everything has to happen in the "load" case (so, the nodes are hidden before they were viewed, right?) but what do I have to do?
Maybe put the nodes in a temporary "unpublished" status or something?
Thanks for any help :)
best regards.
me too! i want 1、the friends
me too!
i want
1、the friends can see each other‘s post,that's 2-way relationship(list in node,expand for full body like google buzz)
2、user can follow and be followed。in a user page he can see a list of his followed’s post,that's 1-way relationship
hi verynic, I think you're
hi verynic,
I think you're searching for something else than me. What you want is already able to build with User-Relationships module and Views module. In Views you can use the "relationship" and "filter" area to list only nodes that belong to a "friend". A one-way or two-way relationship can be done with the User Relationship module (maybe you need the Flag module too, but I'm not quite sure if you need it).
What I'm looking for is some sort of API functions to build a custom privacy module to give users more control over their one content.
My nodeapi hook function gives me the following output.
- I'm testing on a drupal installation with several different user accounts.
- Every user has created several nodes
- User A has only one friend (User B)
Each line shows me the (bootstrap?) status (LOAD or VIEW), the node-title, the node-type and the user name of who created it.
LOAD -> Test Gallery | gallery_assist | User A
VIEW -> Test Gallery | gallery_assist | Status: Teaser | User A
LOAD -> I'm a blog entry | blog | User A
VIEW -> I'm a blog entry | blog | Status: Teaser | User A
LOAD -> test | blog | User B
VIEW -> test | blog | Status: Teaser | User B
LOAD -> blahblahblahblah | blog | User B
VIEW -> blahblahblahblah | blog | Status: Teaser | User B
LOAD -> Test | event | User A
VIEW -> Test | event | Status: Teaser | User A
LOAD -> User A's second blog entry | blog | User A
VIEW -> User A's second blog entry | blog | Status: Teaser | User A
LOAD -> User B's Testblog | blog | User B
VIEW -> User B's Testblog | blog | Status: Teaser | User B
LOAD -> User A's Testbeitrag in seinem Blog | blog | User A
VIEW -> User A's Testbeitrag in seinem Blog | blog | Status: Teaser | User A
LOAD -> Graphic Design | blog | User B
VIEW -> Graphic Design | blog | Status: Teaser | User B
LOAD -> New Article | blog | User B
VIEW -> New Article | blog | Status: Teaser | User B
When I log-in as User A or User B this output will show me only nodes, created by me or by one of my friends (in this case there's only one friend).
Now I need a function to "hide" nodes which are not created by one my friends. I think it will get a bit mathematical (Set theory) here ;). To get all the other nodes I need to subtract the subset of nodes (my nodes and the nodes of my friends) from the set of all nodes.
I hope some one can help me.
best regards.
I found this post looking for
I found this post looking for a way to get User Relationship Node Acces to work. Maybe you'd like to use that as well.
Edit: The problem I had was that I hadn't re-visited permissions after enabling the UR Node Access module. See
sites/all/modules/user_relationships/user_relationship_node_access/README.txtfor instructions.I know this module, too. And
I know this module, too. And it's not working for me, because
1. Permissions are set on the node-level and not on the content-type-level
2. Basically this module gives the node-creator the possibility to decide who can "view", edit" and/or "delete" a node. But how is this going to be useful on a community page like for example Facebook? I never want anyone else than me (as the node-creator) to be able to edit or even delete my own nodes.
What drupal misses is a content privacy module that gives you (on the content-type-level) the option to decide who can see your own nodes (Nobody, Only Friends, All User). This is something fundamental for community pages and I don't know why drupal, as a really good framework for community pages, doesn't have such functionality?!
However, I'm using this module's code to learn how it integrates it's functionality into drupal. I'm new to module developing and there are many things I still don't know how to solve.
So, if someone could help me with the issues I described above I would be very thankful.
best regards.
.
The answer to this is always the same. Because no one who has needed it has written it and contributed back. Functionality doesn't appear magically. Everything that's in Drupal is there because someone needed it and gave back to the community.
Michelle
.
Hmm, that sounds logic and sad at the same time :-(.
I hope I can finsh what I've started now, so I can give something back! Drupal is just great :)
best regards.
Problem partly solved!
I solved the problem on my own. Reverse Engineering for president ;-)!
I'm not going to explain how I did it because I've no time right now but I will when I've got some spare time on my hands.
It's not finished, there's still a lot to do but right now, I've created a new page under user/edit/privacy with three radio buttons (Nobody, Only Friends, All User) for each content type and when I select "Only Friends" for blogs, all my blog nodes will be accessible only for my friends. That's awesome stuff! :).
Ok, I can't tell you more right now, I'm sorry!!!
thanks anyway.
best regards.
Congrats! ... and I'm
Congrats! ... and I'm eagerly waiting to hear about your solution. :)
-
@foggyperspectiv | foggyperspective.com (blog)
Thanks!
Thanks. I'm sorry I have no time to explain everything. I've finished a good part of it but there's still something to do. When I finish I'll come back and explain what I've done :-)
best regards.
Thanks!
Thanks. I'm sorry I have no time to explain everything. I've finished a good part of it but there's still something to do. When I finish I'll come back and explain what I've done :-)
best regards.
Definitely interested in your solution
subscribe