From 80cbb6fb06494cabecedf2964d2003cb8bb27211 Mon Sep 17 00:00:00 2001
From: jpayne <jpayne@696648.no-reply.drupal.org>
Date: Wed, 25 Jul 2012 14:54:16 -0400
Subject: [PATCH] Issue #1552388 by acrazyanimal: Add a Write only option to display the reply form, but not the thread.

---
 reply.field.inc |   23 +++++++++++++----------
 reply.module    |   16 +++++++++-------
 2 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/reply.field.inc b/reply.field.inc
index 64479e1..a9c043b 100644
--- a/reply.field.inc
+++ b/reply.field.inc
@@ -41,9 +41,10 @@ function reply_field_settings_form($field, $instance, $has_data) {
     '#title' => t('Default access on new content'),
     '#options' => array(
       REPLY_INHERIT => t('Inherit'),
-      REPLY_ACCESS_NONE => t('Disabled (Hidden)'),
-      REPLY_ACCESS_READ => t('Read only (Closed)'),
-      REPLY_ACCESS_FULL => t('Read and write (Open)')
+      REPLY_ACCESS_NONE  => t('Disabled (Hidden)'),
+      REPLY_ACCESS_READ  => t('Read only (Closed)'),
+      REPLY_ACCESS_WRITE => t('Write only (Hidden thread)'),
+      REPLY_ACCESS_FULL  => t('Read and write (Open)')
     ),
     '#default_value' => isset($field['settings']['access']) ? $field['settings']['access'] : REPLY_INHERIT
   );
@@ -91,9 +92,10 @@ function reply_field_instance_settings_form($field, $instance) {
     '#title' => t('Default access on new content'),
     '#options' => array(
       REPLY_INHERIT => t('Inherit'),
-      REPLY_ACCESS_NONE => t('Disabled (Hidden)'),
-      REPLY_ACCESS_READ => t('Read only (Closed)'),
-      REPLY_ACCESS_FULL => t('Read and write (Open)')
+      REPLY_ACCESS_NONE  => t('Disabled (Hidden)'),
+      REPLY_ACCESS_READ  => t('Read only (Closed)'),
+      REPLY_ACCESS_WRITE => t('Write only (Hidden thread)'),
+      REPLY_ACCESS_FULL  => t('Read and write (Open)')
     ),
     '#default_value' => isset($instance['settings']['access']) ? $instance['settings']['access'] : REPLY_INHERIT
   );
@@ -227,9 +229,10 @@ function reply_field_widget_form(&$form, &$form_state, $field, $instance, $langc
     '#title' => t('Access'),
     '#options' => array(
       REPLY_INHERIT => t('Inherit'),
-      REPLY_ACCESS_NONE => t('Disabled (Hidden)'),
-      REPLY_ACCESS_READ => t('Read only (Closed)'),
-      REPLY_ACCESS_FULL => t('Read and write (Open)')
+      REPLY_ACCESS_NONE  => t('Disabled (Hidden)'),
+      REPLY_ACCESS_READ  => t('Read only (Closed)'),
+      REPLY_ACCESS_WRITE => t('Write only (Hidden thread)'),
+      REPLY_ACCESS_FULL  => t('Read and write (Open)')
     ),
     '#default_value' => isset($items[$delta]['access']) ? $items[$delta]['access'] : REPLY_INHERIT
   );
@@ -282,4 +285,4 @@ function reply_field_widget_error($element, $error, $form, &$form_state) {
 function reply_field_delete_instance($instance) {
   $ids = reply_get_instance($instance['id']);
   reply_delete_multiple($ids);
-}
\ No newline at end of file
+}
diff --git a/reply.module b/reply.module
index d85c3e8..6b1b811 100644
--- a/reply.module
+++ b/reply.module
@@ -6,6 +6,7 @@ define('REPLY_FORM_PAGE_CUSTOM', 2);
 define('REPLY_ACCESS_NONE', 0);
 define('REPLY_ACCESS_READ', 1);
 define('REPLY_ACCESS_FULL', 2);
+define('REPLY_ACCESS_WRITE', 4);
 define('REPLY_LIST_FLAT', 1);
 define('REPLY_LIST_TREE', 2);
 define('REPLY_STATUS_DISABLED', 0);
@@ -773,20 +774,20 @@ function reply_load_entity($entity_id, $entity_type, $instance_id) {
 function template_preprocess_replies(&$vars) {
   $vars = array_merge($vars, $vars['elements']);
   $vars['replies'] = array();
-
-  if ($vars['access'] <> REPLY_ACCESS_NONE && !empty($vars['elements']['replies']) && (user_access('administer replies') || user_access('view '. $vars['bundle'] .' reply'))) {
+  
+  if (($vars['access'] & (REPLY_ACCESS_READ | REPLY_ACCESS_FULL)) && !empty($vars['elements']['replies']) && (user_access('administer replies') || user_access('view '. $vars['bundle'] .' reply'))) {
     foreach ($vars['elements']['replies'] AS $reply) {
       $vars['replies'][$reply->id]['#markup'] = theme('reply', array('elements' => array('reply' => $reply, 'display' => $vars['display'], 'access' => $vars['access'], 'allow_reply' => $vars['allow_reply'], 'bundle' => $vars['bundle'])));
     }
   }
 
   $vars['reply_form'] = '';
-  if ($vars['access'] == REPLY_ACCESS_FULL && $vars['form'] == REPLY_FORM_PAGE_SAME && (user_access('administer replies') || user_access('post '. $vars['bundle'] .' reply'))) {
+  if (($vars['access'] & (REPLY_ACCESS_FULL | REPLY_ACCESS_WRITE)) && $vars['form'] == REPLY_FORM_PAGE_SAME && (user_access('administer replies') || user_access('post '. $vars['bundle'] .' reply'))) {
     $vars['reply_form'] = drupal_get_form('reply_add_form', $vars['entity_id'], $vars['instance_id'], 0);
   }
 
   $vars['links'] = '';
-  if ($vars['access'] == REPLY_ACCESS_FULL && $vars['form'] == REPLY_FORM_PAGE_CUSTOM && (user_access('administer replies') || user_access('post '. $vars['bundle'] .' reply'))) {
+  if (($vars['access'] & (REPLY_ACCESS_FULL | REPLY_ACCESS_WRITE)) && $vars['form'] == REPLY_FORM_PAGE_CUSTOM && (user_access('administer replies') || user_access('post '. $vars['bundle'] .' reply'))) {
     $vars['links']['add_reply']['#markup'] = l(t('Add reply'), 'reply/add/'. $vars['entity_id'] .'/'. $vars['instance_id'] .'/0');
   }
 }
@@ -820,7 +821,7 @@ function template_preprocess_reply(&$vars) {
   $vars['entity_type'] = $reply->entity_type;
 
   $vars['links'] = '';
-  if (isset($vars['access']) && $vars['access'] == REPLY_ACCESS_FULL) {
+  if (isset($vars['access']) && ($vars['access'] & (REPLY_ACCESS_FULL | REPLY_ACCESS_WRITE))) {
     if (reply_access('reply', $reply)) {
       $vars['links']['reply']['#markup'] = l(t('Reply'), 'reply/add/'. $reply->entity_id .'/'. $reply->instance_id .'/'. $reply->id, array('query' => array('destination' => $_GET['q'])));
     }
@@ -897,7 +898,7 @@ function reply_add_form($form, &$form_state, $entity_id, $instance_id, $parent =
   $settings = reply_settings($bundle, $field_info['settings'], $instance->data['settings'], $entity_settings);
 
   // Check settings
-  if ($settings['access'] != REPLY_ACCESS_FULL) {
+  if (!($settings['access'] & (REPLY_ACCESS_FULL | REPLY_ACCESS_WRITE))) {
     if ($settings['form'] == REPLY_FORM_PAGE_CUSTOM) {
       //@todo watchdog
       drupal_goto($redirect['path']);
@@ -1267,7 +1268,7 @@ function reply_access($op, $reply, $account = NULL, $entity_id = NULL) {
     $entity_settings = empty($entity_settings) ? $instance->data['settings'] : reset($entity_settings);
     $settings = reply_settings($field['settings']['bundle'], $field_info['settings'], $instance->data['settings'], $entity_settings);
 
-    if ($settings['access'] != REPLY_ACCESS_FULL || ($op == 'reply' && $settings['allow_reply'] != REPLY_ALLOW_REPLY)) {
+    if (!($settings['access'] & (REPLY_ACCESS_FULL | REPLY_ACCESS_WRITE)) || ($op == 'reply' && $settings['allow_reply'] != REPLY_ALLOW_REPLY)) {
       $rights[$account->uid][$cid][$op] = FALSE;
       return FALSE;
     }
@@ -1478,6 +1479,7 @@ function reply_bundle_edit_form($form, &$form_state, $bundle = NULL) {
     '#options' => array(
       REPLY_ACCESS_NONE => t('Disabled (Hidden)'),
       REPLY_ACCESS_READ => t('Read only (Closed)'),
+      REPLY_ACCESS_WRITE => t('Write only (Hidden thread)'),
       REPLY_ACCESS_FULL => t('Read and write (Open)')
     ),
     '#default_value' => isset($bundle->access) ? $bundle->access : REPLY_ACCESS_FULL
-- 
1.7.2.3

