Index: restricted_content.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/restricted_content/restricted_content.module,v
retrieving revision 1.9
diff -u -p -r1.9 restricted_content.module
--- restricted_content.module 30 Apr 2009 15:56:19 -0000 1.9
+++ restricted_content.module 1 Jun 2009 12:54:41 -0000
@@ -145,8 +154,10 @@ function restricted_content_preprocess_n
*/
function restricted_content_token_list($type = 'all') {
$tokens['global']['site-register-url'] = t('The URL of the register user page');
+ $tokens['global']['site-login-url'] = t('The URL of the user login page');
if ($type == 'node' || $type == 'all') {
$tokens['node']['type-name-lower'] = t('Node type (user-friendly version lowercased)');
+ $tokens['node']['node-restricted-roles'] = t('The roles this content is restricted to');
}
return $tokens;
}
@@ -156,19 +167,32 @@ function restricted_content_token_list($
*/
function restricted_content_token_values($type, $object = NULL) {
$tokens['site-register-url'] = url('user/register');
+ $token['site-login-url'] = url('user/login');
if ($type == 'node') {
$tokens['type-name-lower'] = drupal_strtolower(node_get_types('name', $object));
+ $tokens['node-restricted-roles'] = restricted_content_list_roles($object);
}
return $tokens;
}
/**
+ * List the roles an item is restricted to.
+ */
+function restricted_content_list_roles($node) {
+ $all_roles = user_roles(TRUE);
+ $rids = unserialize(db_result(db_query("SELECT rids FROM {restricted_content} WHERE nid = %d", $node->nid)));
+ $restricted_roles = array_intersect_key($all_roles, array_flip($rids));
+ return count($restricted_roles) > 1 ? implode(', ', $restricted_roles) : implode('', $restricted_roles);
+}
+
+/**
* Internal default variables for admin_links_var().
*/
function restricted_content_variables() {
return array(
- 'restricted_content_message' => t('This !token-type-name has been restricted to certain users.', array('!token-type-name' => module_exists('token') ? '[type-name-lower]' : t('content'))),
- 'restricted_content_message_anon' => t('Please register for a user account to view this !token-type-name.', array('!token-type-name' => module_exists('token') ? '[type-name-lower]' : t('content'), '!token-register' => module_exists('token') ? '[site-url-register]' : url('user/register'))),
+ 'restricted_content_message' => t('This !token-type-name has been restricted to !roles.', array('!token-roles' => module_exists('token') ? '[node-restricted-roles]' : t('certain users.'), '!token-type-name' => module_exists('token') ? '[type-name-lower]' : t('content'))),
+ 'restricted_content_message_anon' => t('Please login or register for a user account to view this !token-type-name.', array('!token-type-name' => module_exists('token') ? '[type-name-lower]' : t('content'), '!token-register' => module_exists('token') ? '[site-url-register]' : url('user/register'), '!token-logn' => module_exists('token') ? '[site-url-login]' : url('user/login'))),
+ 'restricted_content_restrict_teaser' => TRUE,
);
}