? .DS_Store
? nodeasblock.patch
Index: nodeasblock.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodeasblock/nodeasblock.module,v
retrieving revision 1.3.2.1
diff -u -p -r1.3.2.1 nodeasblock.module
--- nodeasblock.module	10 Nov 2006 21:56:53 -0000	1.3.2.1
+++ nodeasblock.module	24 Dec 2006 03:31:45 -0000
@@ -10,16 +10,25 @@
  * Implementation of hook_perm().
  */
 function nodeasblock_perm() {
-  return array('create blocks for nodes');
+  return array('create blocks for nodes', 'control position of node blocks');
 }
 
 
 function nodeasblock_form_alter($form_id, &$form) {
-  if (isset($form['type']) && 
-      $form['type']['#value'] .'_node_form' == $form_id &&
-      user_access('create blocks for nodes')) {
+  if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
+    $form['workflow']['nodeasblock'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Enable blocks from this node type'),
+      '#default_value' => variable_get('nodeasblock_'. $form['#node_type']->type, 1),
+      '#return_value' => 1,
+      '#description' => t('Allow users to make these nodes visible as sidebar blocks.'),
+    );
+  }
+  elseif (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id
+      && user_access('create blocks for nodes') && variable_get('nodeasblock_'. $form['type']['#value'], 1)) {
+    global $theme;
     $node = $form['#node'];
-    
+
     $form['nodeasblockset'] = array (
       '#type' => 'fieldset',
       '#title' => t('Provide a block'),
@@ -32,6 +41,26 @@ function nodeasblock_form_alter($form_id
       '#default_value' => $node->nodeasblock,
       '#description' => t('Check this box to create a block for this node. The block will contain the teaser. To administer the appearance of this block, you will need to visit !block_admin.', array('!block_admin' => l('admin/build/block', 'admin/build/block'))),
     );
+    
+    if (user_access('control position of node blocks')) {
+      if ($node->nid) {
+        $block = db_fetch_array(db_query("SELECT * FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", 'nodeasblock', $node->nid, $theme));
+      }
+      $form['nodeasblockset']['nodeasblock_region'] = array (
+        '#type' => 'select',
+        '#options' => system_region_list($theme),
+        '#title' => t('Region'),
+        '#default_value' => isset($block) ? $block['region'] : system_default_region($theme),
+        '#description' => t('The region of the page this block should appear in.'),
+        );
+      $form['nodeasblockset']['nodeasblock_weight'] = array (
+        '#type' => 'weight',
+        '#title' => t('Weight'),
+        '#default_value' => isset($block) ? $block['weight'] : 0,
+        '#description' => t('The weight of this block. Larger numbers move a block farther down in a region.')
+      );
+    }
+
   }
 }
 
@@ -43,13 +72,22 @@ function nodeasblock_nodeapi(&$node, $op
      return $output;
     case 'update':
     case 'insert':
+      global $theme;
       db_query("DELETE FROM {nodeasblock} WHERE nid = $node->nid");
       if ($node->nodeasblock) {
         db_query("INSERT INTO {nodeasblock} VALUES ($node->nid)");
       }
+
+      // If we were passed enough information, set the block visibility, region, and weight as well.
+      if ($node->nodeasblock && isset($node->nodeasblock_region)) {
+        $blocks = _block_rehash();
+        db_query("UPDATE {blocks} SET status = 1, region = '%s', weight = %d WHERE module = '%s' AND delta = '%s'",
+          $node->nodeasblock_region, $node->nodeasblock_weight, 'nodeasblock', $node->nid);
+      }
       break;
     case 'delete':
       db_query("DELETE FROM {nodeasblock} WHERE nid = $node->nid");
+      db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s'", 'nodeasblock', $node->nid);
       break;
   }
 }
