| 83 |
$rids = db_result(db_query("SELECT rids FROM {restricted_content} WHERE nid = %d", $node->nid)); |
$rids = db_result(db_query("SELECT rids FROM {restricted_content} WHERE nid = %d", $node->nid)); |
| 84 |
if ($rids && !array_intersect(unserialize($rids), array_keys($user->roles))) { |
if ($rids && !array_intersect(unserialize($rids), array_keys($user->roles))) { |
| 85 |
|
|
| 86 |
$node_type = drupal_strtolower(node_get_types('name', $node)); |
$message = restricted_content_var('message'); |
|
$node->body = strtr(restricted_content_var('message'), array('@node-type' => $node_type)); |
|
|
//$node->body = t('This @node-type has been restricted to certain users.', array('@node-type' => $node_type)); |
|
| 87 |
$node->restricted = TRUE; |
$node->restricted = TRUE; |
| 88 |
$node->comment = COMMENT_NODE_DISABLED; |
$node->comment = COMMENT_NODE_DISABLED; |
| 89 |
|
|
| 90 |
// 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 |
| 91 |
// account. |
// account. |
| 92 |
if (!$user->uid && variable_get('user_register', 1)) { |
if (!$user->uid && variable_get('user_register', 1)) { |
| 93 |
//$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)); |
$message .= ' '. restricted_content_var('message_anon'); |
|
$node->body .= ' '. strtr(restricted_content_var('message_anon'), array('@link-register' => url('user/register'), '@node-type' => $node_type)); |
|
| 94 |
} |
} |
| 95 |
|
|
| 96 |
$node->teaser = $node->body; |
// Perform token replacement if token module is available. |
| 97 |
|
if (module_exists('token')) { |
| 98 |
|
$message = token_replace($message, 'node', $node); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
$node->teaser = $message; |
| 102 |
|
$node->body = $message; |
| 103 |
} |
} |
| 104 |
} |
} |
| 105 |
elseif ($op == 'alter' && !empty($node->restricted)) { |
/*elseif ($op == 'alter' && !empty($node->restricted)) { |
| 106 |
// Send a 403 if this is an individual page view. |
// Send a 403 if this is an individual page view. |
| 107 |
if ($page) { |
if ($page) { |
|
//drupal_access_denied(); |
|
| 108 |
drupal_set_header('HTTP/1.1 403 Forbidden'); |
drupal_set_header('HTTP/1.1 403 Forbidden'); |
| 109 |
} |
} |
| 110 |
|
}*/ |
| 111 |
|
} |
| 112 |
|
|
| 113 |
|
/** |
| 114 |
|
* Implementation of MODULE_preprocess_node(). |
| 115 |
|
*/ |
| 116 |
|
function restricted_content_preprocess_node(&$vars) { |
| 117 |
|
if (!empty($vars['node']->restricted)) { |
| 118 |
|
$vars['submitted'] = FALSE; |
| 119 |
|
$vars['picture'] = FALSE; |
| 120 |
|
$vars['taxonomy'] = FALSE; |
| 121 |
|
$vars['terms'] = FALSE; |
| 122 |
|
$vars['links'] = FALSE; |
| 123 |
|
$vars['node_url'] = request_uri(); |
| 124 |
|
} |
| 125 |
|
} |
| 126 |
|
|
| 127 |
// Unset the links. |
/** |
| 128 |
//unset($node->links); |
* Implementation of hook_token_list(). |
| 129 |
|
*/ |
| 130 |
|
function restricted_content_token_list($type = 'all') { |
| 131 |
|
$tokens['global']['site-register-url'] = t('The URL of the register user page'); |
| 132 |
|
if ($type == 'node' || $type == 'all') { |
| 133 |
|
$tokens['node']['type-name-lower'] = t('Node type (user-friendly version lowercased)'); |
| 134 |
} |
} |
| 135 |
|
return $tokens; |
| 136 |
} |
} |
| 137 |
|
|
| 138 |
|
/** |
| 139 |
|
* Implementation of hook_token_values(). |
| 140 |
|
*/ |
| 141 |
|
function restricted_content_token_values($type, $object = NULL) { |
| 142 |
|
$tokens['site-register-url'] = url('user/register'); |
| 143 |
|
if ($type == 'node') { |
| 144 |
|
$tokens['type-name-lower'] = drupal_strtolower(node_get_types('name', $object)); |
| 145 |
|
} |
| 146 |
|
return $tokens; |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
/** |
| 150 |
|
* Internal default variables for admin_links_var(). |
| 151 |
|
*/ |
| 152 |
function restricted_content_variables() { |
function restricted_content_variables() { |
| 153 |
return array( |
return array( |
| 154 |
'restricted_content_message' => t('This @node-type has been restricted to certain users.'), |
'restricted_content_message' => t('This !token1 has been restricted to certain users.', array('!token1' => module_exists('token') ? '[type-name-lower]' : t('content'))), |
| 155 |
'restricted_content_message_anon' => t('Please <a href="@link-register">register for a user account</a> to view this @node-type.'), |
'restricted_content_message_anon' => t('Please <a href="!token1">register for a user account</a> to view this !token2.', array('!token1' => module_exists('token') ? '[site-register-url]' : url('user/register'), '!token2' => module_exists('token') ? '[type-name-lower]' : t('content'))), |
| 156 |
); |
); |
| 157 |
} |
} |
| 158 |
|
|
| 159 |
|
/** |
| 160 |
|
* Internal implementation of variable_get(). |
| 161 |
|
*/ |
| 162 |
function restricted_content_var($name) { |
function restricted_content_var($name) { |
| 163 |
static $defaults = NULL; |
static $defaults = NULL; |
| 164 |
if (!isset($defaults)) { |
if (!isset($defaults)) { |
| 167 |
|
|
| 168 |
$name = 'restricted_content_'. $name; |
$name = 'restricted_content_'. $name; |
| 169 |
|
|
| 170 |
return variable_get($name, $defaults[$name]); |
// @todo Remove when I stop making spelling errors in variable names. |
| 171 |
} |
if (!isset($defaults[$name])) { |
| 172 |
|
watchdog('restricted_conte', 'Default variable for %variable not found.', array('%variable' => $name)); |
|
function restricted_content_preprocess_node(&$vars) { |
|
|
if (!empty($vars['node']->restricted)) { |
|
|
//echo "<pre>"; var_export($vars); echo "</pre>";// die(); |
|
|
$vars['submitted'] = FALSE; |
|
|
$vars['picture'] = FALSE; |
|
|
$vars['taxonomy'] = FALSE; |
|
|
$vars['terms'] = FALSE; |
|
|
$vars['links'] = FALSE; |
|
|
$vars['node_url'] = request_uri(); |
|
| 173 |
} |
} |
| 174 |
|
|
| 175 |
|
return variable_get($name, isset($defaults[$name]) ? $defaults[$name] : NULL); |
| 176 |
} |
} |