2

I have installed User Relationships for a project. User A is friends with user B. When user A posts a piece of content, currently it shows up on his front page, as well as user B's front page.

I just want any user to view their friends' content if they are viewing a friend's user profile. I created views for the content as menu tabs for the users. If someone is a friend, they should be able to view the content. Otherwise, it should remain private for the user.

To rephrase my desired functionality, a user's content should only be viewable by the owner, and by any friends, via a user menu tab.

2
  • (I'm posting as I'm going along here) I just stripped everything down. At this point, when two users are friends, they can see each other's content. Now, I need to figure out how a user can view their own content via a view, and how a user can view a specific friend's content via a view.
    – vintorg
    Sep 26, 2012 at 7:29
  • The solution that seems to make the most sense is using panels. I set up a profile in Panels, and it handles User Relationships already. I'm passing the uid as a context. So good so far.
    – vintorg
    Sep 28, 2012 at 2:15

2 Answers 2

1

There are two ways to manage access to content with the User Relationships module.

The node access module allows you to open up access to nodes to friends but does not provide any way to remove that access, you'll need another module to do that.

The panels module allows you to show and hide panes based on whether or not a relationship exists.

1

I have an idea with a little and simple module, tell me if it's what you wanted to do.


For this exemple you have to create in your DB a field that i will call vuid (for view uid : your uid + your friends uid).


Then use this function :

function get_list_art() {

//Place there what I describe after

  $sql = " SELECT {node}.nid, 
                  {node}.created,
                  {node_revisions}.title, 
                  {node_revisions}.body
           FROM {node}
           INNER JOIN {node_revisions}
            ON {node}.nid = {node_revisions}.nid
           WHERE {node}.uid = ".$vuivalues."
           AND {node_revisions}.body != ''
           ORDER BY {node}.created DESC
          ";

  $result = db_query(db_rewrite_sql($sql));

  $i = 0;
  while($art = db_fetch_array($result)) {
    $arts[$i]['nid'] = $art['nid']; 
    $arts[$i]['date'] = format_date($art['created']);
    $arts[$i]['title'] = $art['title']; 
    $arts[$i]['content'] = $art['body'];
    $i++;
  }

  return theme('list_art', $arts);
 }


/**
 * Implementation of hook_menu().
 **/
 function list_art_menu() {

  $items = array();

  $items['list_art'] = array(
    'title' => "",
    'page callback' => 'get_list_art',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK
  );

  return $items;
}

/**
 * Implementation of hook_theme().
 **/
function list_art_theme() {
  return array(
    'list_art' => array(
      'template' => 'list_art',
      'arguments' => array('arts' => NULL),
    ),
  );
}

So now I will explain what is my $vuidvalues in the $sql.

You have first to go search all the vuid that refer to your actual $user and implode this array to an SQL expression ( '1' OR '2' OR for exemple)


global $user;
$uiduser = $user->uid;

$vuidtabsql = " SELECT {user}.vuid, 
           FROM {user}
           WHERE {user}.uid = ".$uiduser.";

  $vuidtab = db_query(db_rewrite_sql($vuidtabsql));

$vuidvalues = "'".implode("' OR '", $vuidtab)."'";

That was for the .module

Then display the .tpl.php with :

<?php
// $Id$
?>
<h1>Your and your friends stream</h1>
<br>
<br>
<?php foreach($arts as $art) : ?>
<div class="node-blog-fond">
  <div class="node-blog-haut">

      <h2><?php print l($art['title'] , 'node/'.$art['nid']); ?></h2>
       <span class="submitted"><?php print $art['date']; ?></span>
      <p><?php print $art['content']; ?></p>
  </div>
  <div class="node-blog-bas"></div>
</div>
<br>
<?php endforeach; ?>

I just start to learn Drupal and I'm not yet a master of developpement but I hope it's helped.

Give me some feed back !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.