? restricted-content-998416.patch
Index: restricted_content.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/restricted_content/restricted_content.module,v
retrieving revision 1.13
diff -u -p -r1.13 restricted_content.module
--- restricted_content.module	27 Nov 2009 00:03:49 -0000	1.13
+++ restricted_content.module	14 Dec 2010 22:26:37 -0000
@@ -188,3 +188,108 @@ function restricted_content_var($name, $
 
   return variable_get($name, isset($default) || !isset($defaults[$name]) ? $default : $defaults[$name]);
 }
+
+/**
+ *  Implementation of hook_menu_link_alter().
+ *  Adds a restricted-content class to menu links
+ */
+function restricted_content_menu_link_alter(&$item, $menu) {
+  //if the node is marked as restricted add restricted content class
+  if ($node->restricted = TRUE) {
+     $item['options']['attributes']['class'] = 'restricted-content';
+  }
+}
+
+/**
+ * Implementation of hook_action_info().
+ */
+function restricted_content_action_info() {
+  return array(
+    'restrict_content_action' => array(
+      'description' => t('Add restricted content conditions for a node'),
+      'configurable' => TRUE,
+      'type' => 'node',
+      'hooks' => array(
+        'nodeapi' => array('alter')
+      )
+    ),
+    'unrestrict_content_action' => array(
+      'description' => t('Remove restricted content conditions for a node'),
+      'type' => 'node',
+      'configurable' => FALSE,
+      'hooks' => array(
+        'nodeapi' => array('delete')
+      )
+    )
+  );
+}
+
+/**
+ * Action to restrict a node.
+ *
+ * @param $node
+ *   A node object.
+ * @param $context
+ *   An array providing more information about the context of the call to this action.
+ *
+ * @ingroup actions
+ * @see restrict_content_action_form()
+ * @see restrict_content_action_submit()
+ */
+function restrict_content_action($node, $context) {
+    // drupal_set_message(print_r($context['rids'], TRUE));
+  $rids = array_keys(array_filter($context['rids']));
+  db_query("DELETE FROM {restricted_content} WHERE nid = %d", $node->nid);
+  if ($rids) {
+    db_query("INSERT INTO {restricted_content} VALUES (%d, '%s')", $node->nid, serialize($rids));
+  }
+}
+
+/**
+ * Form builder; Prepare a form for selecting restricted roles.
+ *
+ * @ingroup forms
+ * @see restrict_content_action()
+ * @see restrict_content_action_submit()
+ */
+function restrict_content_action_form($context) {
+  $form = array();
+  $form['#node']->restricted_content = isset($context->restricted_content) ? $context->restricted_content : NULL;
+  $form['#node']->type = NULL;
+  restricted_content_node_form($form);
+  $form['restricted_content']['#weight'] = 0;
+  $form['restricted_content']['#collapsed'] = FALSE;
+  $form['restricted_content']['#description'] = t('The roles selected will be granted access to restricted content.');
+  return $form;
+}
+
+/**
+ * Process restrict_content_action_form form submissions.
+ *
+ * @see restrict_content_action()
+ */
+function restrict_content_action_submit($form, $form_state) {
+   return array('rids' => $form_state['values']['restricted_content']['rids']);
+}
+
+/**
+ * Action to unrestrict a node.
+ *
+ */
+function unrestrict_content_action($node, $context) {
+  if ($node->restricted = TRUE) {
+    $node->restricted_content['rids'] = $context->restricted_content['rids'];
+  }
+  module_invoke('restricted_content', 'nodeapi', $node, 'delete');
+}
+
+
+/**
+ * Implementation of hook_views_api().
+ */
+function restricted_content_views_api() {
+  return array(
+    'api' => 2,
+    'path' => drupal_get_path('module', 'restricted_content'),
+  );
+}
\ No newline at end of file
Index: restricted_content.views.inc
===================================================================
RCS file: restricted_content.views.inc
diff -N restricted_content.views.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ restricted_content.views.inc	14 Dec 2010 22:26:37 -0000
@@ -0,0 +1,48 @@
+<?php
+function restricted_content_views_data() {
+  $data = array();
+
+  $data['restricted_content']['table']['group'] = t('Node');
+
+  $data['restricted_content']['table']['join'] = array(
+    'node' => array(
+      'left_field' => 'nid',
+      'field' => 'nid',
+    ),
+    'restricted_content' => array(
+      'left_field' => 'nid',
+      'field' => 'nid',
+    ),
+  );
+
+  $data['restricted_content']['nid'] = array(
+    'title' => t('Restricted content'),
+    'help' => t('Whether or not the node is restricted.'),
+    'field' => array(
+      'handler' => 'views_handler_field_boolean',
+      'click sortable' => TRUE,
+    ),
+    'filter' => array(
+      'handler' => 'restricted_content_handler_bool',
+      'label' => t('Restricted'),
+      'type' => 'yes-no',
+    ),
+  );
+
+  return $data;
+
+}
+
+function restricted_content_views_handlers() {
+  return array(
+    'info' => array(
+      'path' => drupal_get_path('module', 'restricted_content'),
+    ),
+    'handlers' => array(
+      'restricted_content_handler_bool' => array(
+        'parent' => 'views_handler_filter_boolean_operator',
+        'file' => 'restricted_content_handler_bool.inc',
+      ),
+    ),
+  );
+}
\ No newline at end of file
Index: restricted_content_handler_bool.inc
===================================================================
RCS file: restricted_content_handler_bool.inc
diff -N restricted_content_handler_bool.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ restricted_content_handler_bool.inc	14 Dec 2010 22:26:37 -0000
@@ -0,0 +1,10 @@
+<?php
+
+class restricted_content_handler_bool extends views_handler_filter_boolean_operator {
+  
+  function query() {
+    $this->ensure_my_table();
+    $qualified_name = "$this->table_alias.$this->real_field"; 
+    $this->query->add_where($this->options['group'], $qualified_name . (empty($this->value) ? " = 0 OR $qualified_name IS NULL" : ' IS NOT NULL'));
+  }
+}
\ No newline at end of file
