I have a drupal site www.symbiandev.net and have some articles. I just want full pages to be shown to registered users. How can I manage this?
My homepage is /node and articles are node/3, node/4 ....

Comments

chx’s picture

Cook a custom block:

if (arg(0) == 'node' && is_numeric(arg(1))) {
  $node = node_load(array('nid' => arg(1)));
  if ($node->nid && !user_access('access pages')) {
    drupal_access_denied();
    module_invoke_all('exit');
    exit;
  }
}

You may change that user_access('access pages') to whatever you please.

--
Drupal development: making the world better, one patch at a time. | A bedroom without a teddy is like a face without a smile.

DelphiMan’s picture

Thanks. it is very useful for me

jvincher’s picture

Not sure if I understand this. Would you add this to the body of each node you're trying to protect? I am not completely sure how creating a block would solve this.

DelphiMan’s picture

create a php-code block

<?php
global $user;
if (!$user->uid) {
if (arg(0) == 'node' && is_numeric(arg(1))) {
  $node = node_load(array('nid' => arg(1)));
  if ($node->nid && !user_access('access pages')) {
    drupal_access_denied();
    module_invoke_all('exit');
    exit;
  }
}
} else {
  return;
}
?>

this will effect only anon users.

path parameter in new block page will define which content will be effected
(I am not sure that this is a good code. I don't know PHP much. but it works as I want)

Jaza’s picture

Have a look at this page on my site, I think it's got what you're attempting to do:

http://www.greenash.net.au/resources/studynotes_essays

Try clicking on any of the nodes that are previewed on this page. You'll see that the previews are viewable by all users, but that only registered users can access the full text versions.

I did this by using the taxonomy access module to protect my nodes, and then by hacking one of the functions in the taxonomy module so that it ignores access permissions when generating a list of node previews (very basic hack).

Your query has prompted me to do something I've been meaning to for a few months now: publish my hack. So here is a link to the article I just wrote, with the code itself and a bit of instructions on using it:

Showing sneak previews in Drupal

Hope that helps!

Jeremy Epstein - GreenAsh

Jeremy Epstein - GreenAsh

DelphiMan’s picture

Thanks. I used the other solution but yours will be useful for so many people,I sure.

jvincher’s picture

Thanks for the clarifying article, Jeremy. This should do the trick quite nicely.

jvincher’s picture

I've been playing with this a bit more with interesting results.

Combining Jaza's hack and the prvacy byrole module gets the result I was looking for. Teasers show because of the hack, full text pages are restricted. A nice side-effect of using the privacy byrole module is that it solves the issue that Jaza described (bypassing taxonomy would still give full access). Privacy byrole solves that problem because the node is no longer visible for views other than the taxonomy view.

Just my 2c.

goldengalaxy’s picture

Hi Jazz,

both links below lead to page not found. Can you please please post your tutorial here for this functionality?

http://www.greenash.net.au/resources/studynotes_essays
http://greenash.net.au/posts/thoughts/sneak_previews_drupal/