--- subscriptions.module	2006-03-05 11:02:27.%N -0500 v1.33
+++ subscriptions.module	2006-03-05 11:59:01.%N -0500
@@ -1,5 +1,6 @@
 <?php
 // $Id: subscriptions.module,v 1.33 2006/03/04 23:55:35 c0c0c0 Exp $
+// 4.7 Forms API Patch 2006/03/05 -q0rban 
 
 /**
  * Implementation of hook_help().
@@ -39,7 +40,15 @@
   $mailevent .= "Alternativly, if you have the mailqueue module installed, you can send the messages ";
   $mailevent .= "to that module for handling.";
   if ( module_exist( 'mailqueue' ) ) {
-    $output = form_radios( t( "Mailer Event" ), "subscriptions_event", variable_get( "subscriptions_event", "insert" ), array( "insert" => t( "On Comment Insert/Update" ), "queue" => t( "Send to mail queue" ) ) , t( $mailevent ) );
+    $form_options = array( 'insert' => t( 'On Comment Insert/Update' ));
+    $form['subscription_settings']['subscriptions_event'] = array(
+      '#type'          => 'radios',
+      '#title'         => t('Mailer event'),
+      '#default_value' => variable_get( 'subscriptions_event', 'insert' ),
+      '#options'       => $form_options,
+      '#description'   => t( $mailevent )
+    );
+    $output = $form;
   }
   else {
     $output = "Subscription notifications will be sent upon insert/update.  This should be ";
@@ -57,8 +66,20 @@
   switch ($type) {
     case 'form':
       if (user_access('maintain subscriptions') && $category == 'account') {
-        return array(array('title' => t('Subscription settings'), 'data' => form_checkbox(t('Automatically subscribe to threads in which you post.'), 'subscriptions_auto', 1, isset($edit->subscriptions_auto) ? $edit->subscriptions_auto : $user->subscriptions_auto, t('Checking this box allows you to be automatically subscribe to any thread you create or post a comment to.'))));
-      }
+        $form['subscriptions'] = array(
+          '#type'        => 'fieldset', 
+          '#title'       => t('Subscription settings'), 
+          '#weight'      => 5, 
+          '#collapsible' => TRUE
+        );
+        $form['subscriptions']['subscriptions_auto'] = array(
+          '#type'          => 'checkbox',
+          '#title'         => t('Autosubscribe'),
+          '#default_value' => isset($edit['subscriptions_auto']) ? $edit['subscriptions_auto'] : $user->subscriptions_auto,
+          '#description'   => t('Checking this box allows you to be automatically subscribe to any thread you create or post a comment to.')
+        );
+      return $form;
+    }
   }
 }
 
@@ -71,8 +92,15 @@
   foreach ($vocabularies as $vocabulary) {
     $select[$vocabulary->vid] = $vocabulary->name;
   }
-  $output = form_select(t('Omitted vocabularies'), 'subscriptions_omitted_taxa', variable_get('subscriptions_omitted_taxa', array()), $select, t('Select vocabularies which should be <strong>omitted</strong> from subscription listings.'), '', 1);
-  return $output;
+  $form['sub_settings']['subscriptions_omitted_taxa'] = array(
+    '#type'          => 'select',
+    '#title'         => t('Omitted vocabularies'),
+    '#default_value' => variable_get('subscriptions_omitted_taxa', array()),
+    '#options'       => $select,
+    '#description'   => t('Select vocabularies which should be <strong>omitted</strong> from subscription listings.'),
+    '#multiple'      => TRUE
+  );
+  return $form;
 }
 
 /**
@@ -227,14 +255,7 @@
 
       $headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";
       $subject = t('[%site] %type subscription update for %name : %subject', array('%site' => variable_get('site_name', 'drupal'), '%type' => $strtype, '%name' => $subscriptions->name, '%subject' => $subj));
-      $body = t('Greetings, %name.
-
-A %type to which you have subscribed has been updated.  To view the thread,
-navigate to %url
-
---
-This is an automatic mail from %site.
-To manage your subscriptions, browse to %manage-url', array('%name' => $subscriptions->name, '%type' => $strtype, '%url' => url('node/'. $nid, NULL, $cid, 1), '%site' => variable_get('site_name', 'drupal'), '%manage-url' => url('subscriptions', NULL, NULL, 1)));
+      $body = t("Greetings, %name.\n\nA %type to which you have subscribed has been updated.\nTo view the thread, navigate to %url \n\n--\nThis is an automatic message from %site.\nTo manage your subscriptions, browse to %manage-url", array('%name' => $subscriptions->name, '%type' => $strtype, '%url' => url('node/'. $nid, NULL, $cid, 1), '%site' => variable_get('site_name', 'drupal'), '%manage-url' => url('subscriptions', NULL, NULL, 1)));
 
       // revert to original locale
       $locale = $initial_locale;
@@ -269,7 +290,7 @@
 /**
  * Implementation of hook_comment().
  */
-function subscriptions_comment($op, $comment) {
+function subscriptions_comment($comment, $op) {
   global $user;
   $strsent = '!';
   // TODO: it appears the comment status is not provided by this hook... we'll have to look into that later
@@ -308,17 +329,38 @@
         user_save($user, array('subscriptions_subscribe' => $node->subscriptions_subscribe));
       }
       break;
-    case 'form post':
-      if (!$user->subscriptions_auto && $node->comment == 2 && $user->uid) {
-        $allsubs = subscriptions_get_user();
-        $val = isset($node->subscriptions_subscribe) ? $node->subscriptions_subscribe : $allsubs['node'][$node->nid] ? 1 : $user->subscriptions_subscribe;
-        return form_item(t('Subscribe'), form_checkbox(t('Receive notification of replies to this %name.', array('%name' => node_invoke($node, 'node_name'))), 'subscriptions_subscribe', 1, $val));
-      }
-      break;
   }
 }
 
 /**
+ * Implementation of hook_form_alter().
+ */
+function subscriptions_form_alter($form_id, &$form) {
+  global $user;
+  $node->comment = variable_get("comment_$node->type", COMMENT_NODE_READ_WRITE);
+  if (!$user->subscriptions_auto && $node->comment == COMMENT_NODE_READ_WRITE && $user->uid) {
+    $allsubs = subscriptions_get_user();
+    $val = isset($node->subscriptions_subscribe) ? $node->subscriptions_subscribe : $allsubs['node'][$node->nid] ? 1 : $user->subscriptions_subscribe;
+
+    if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
+      $node = $form['#node'];
+      $form['subscriptions'] = array(
+        '#type'        => 'fieldset',
+        '#title'       => t('Subscriptions'),
+        '#collapsible' => TRUE,
+        '#weight'      => 0,
+      );
+      $form['subscriptions']['subscriptions_subscribe'] = array(
+        '#type'          => 'checkbox', 
+        '#title'         => t('Subscribe'),
+	  		'#description'   => t('Receive notification of replies or comments to this node.'),
+        '#default_value' => $val, 
+      );
+    }
+	 }
+}
+
+/**
  * Implementation of hook_menu().
  */
 function subscriptions_menu($may_cache) {
@@ -464,7 +506,12 @@
       // omit undesired vocabularies from listing
       $vocabularies = taxonomy_get_vocabularies();
       $omits = variable_get('subscriptions_omitted_taxa', array());
-      foreach ($omits as $omit) {
+      if (is_array ($omits)) {
+        foreach ($omits as $omit) {
+          unset($vocabularies[$omit]);
+        } 
+      }
+      else {
         unset($vocabularies[$omit]);
       }
       foreach ($vocabularies as $vocab) {
@@ -475,10 +522,7 @@
       }
       // concatenate the arrays
       $headers = array(t('type'), t('title'), t('subscribers'));
-      if (!is_array($subrowsn)) $subrowsn=array();
-      if (!is_array($subrowsb)) $subrowsb=array();
-      if (!is_array($subrowst)) $subrowst=array();
-      $subrows = array_merge($subrowsn, $subrowsb, $subrowst);
+      $subrows = array_merge((array) $subrowsn, (array) $subrowsb, (array) $subrowst);
       // assemble output
       if (!$subrows) {
         $message .= t('<p>No threads or categories are currently subscribed.</p>');
@@ -507,8 +551,13 @@
       // omit undesired vocabularies from listing
       $vocabularies = taxonomy_get_vocabularies();
       $omits = variable_get('subscriptions_omitted_taxa', array());
-      foreach ($omits as $omit) {
-        unset($vocabularies[$omit]);
+      if (is_array ($omits)) {
+        foreach ($omits as $omit) {
+          unset($vocabularies[$omit]);
+        } 
+      }
+      else {
+        unset($vocabularies[$omits]);
       }
       foreach ($vocabularies as $vocab) {
         $tree = taxonomy_get_tree($vocab->vid);
