| 114 |
if ($rids && !array_intersect(unserialize($rids), array_keys($user->roles))) { |
if ($rids && !array_intersect(unserialize($rids), array_keys($user->roles))) { |
| 115 |
|
|
| 116 |
$node_type = drupal_strtolower(node_get_types('name', $node)); |
$node_type = drupal_strtolower(node_get_types('name', $node)); |
| 117 |
$node->body = t('This @node-type has been restricted to certain users.', array('@node-type' => $node_type)); |
$node->body = strtr(restricted_content_var('message'), array('@node-type' => $node_type)); |
| 118 |
|
//$node->body = t('This @node-type has been restricted to certain users.', array('@node-type' => $node_type)); |
| 119 |
$node->restricted = TRUE; |
$node->restricted = TRUE; |
| 120 |
$node->comment = COMMENT_NODE_DISABLED; |
$node->comment = COMMENT_NODE_DISABLED; |
| 121 |
|
|
| 122 |
// Add a register link of the user is anonymous and can register for an |
// Add a register link of the user is anonymous and can register for an |
| 123 |
// account. |
// account. |
| 124 |
if (!$user->uid && variable_get('user_register', 1)) { |
if (!$user->uid && variable_get('user_register', 1)) { |
| 125 |
$node->body .= ' '. t('Please <a href="@link-register">register for a user account</a> to view this @node-type.', array('@link-register' => url('user/register'), '@node-type' => $node_type)); |
//$node->body .= ' '. t('Please <a href="@link-register">register for a user account</a> to view this @node-type.', array('@link-register' => url('user/register'), '@node-type' => $node_type)); |
| 126 |
|
$node->body .= ' '. strtr(restricted_content_var('message_anon'), array('@link-register' => url('user/register'), '@node-type' => $node_type)); |
| 127 |
} |
} |
| 128 |
|
|
| 129 |
$node->teaser = $node->body; |
$node->teaser = $node->body; |
| 141 |
} |
} |
| 142 |
} |
} |
| 143 |
|
|
| 144 |
|
function restricted_content_variables() { |
| 145 |
|
return array( |
| 146 |
|
'restricted_content_message' => t('This @node-type has been restricted to certain users.'), |
| 147 |
|
'restricted_content_message_anon' => t('Please <a href="@link-register">register for a user account</a> to view this @node-type.'), |
| 148 |
|
); |
| 149 |
|
} |
| 150 |
|
|
| 151 |
|
function restricted_content_var($name) { |
| 152 |
|
static $defaults = NULL; |
| 153 |
|
if (!isset($defaults)) { |
| 154 |
|
$defaults = restricted_content_variables(); |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
$name = 'restricted_content_'. $name; |
| 158 |
|
|
| 159 |
|
return variable_get($name, $defaults[$name]); |
| 160 |
|
} |
| 161 |
|
|
| 162 |
function restricted_content_preprocess_node(&$vars) { |
function restricted_content_preprocess_node(&$vars) { |
| 163 |
if (!empty($vars['node']->restricted)) { |
if (!empty($vars['node']->restricted)) { |
| 164 |
//echo "<pre>"; var_export($vars); echo "</pre>";// die(); |
//echo "<pre>"; var_export($vars); echo "</pre>";// die(); |