--- clipper.module.cvs	Wed Dec 14 02:07:34 2005
+++ clipper.module	Sun Dec 18 22:17:50 2005
@@ -1,6 +1,6 @@
 <?php
 // $Id: clipper.module,v 1.11 2005-12-13 22:28:02 ber Exp $
-
+// tag: 4.6
 /**
  * @file
  * Enables users to bind nodes together via references.
@@ -44,21 +44,6 @@ function clipper_menu($may_cache) {
 }
 
 /**
- * Implementation of form_alter
- */
-function clipper_form_alter($form_id, &$form) {
-  if (isset($form['type'])) {
-    if ($form['type']['#value'] .'_node_settings' == $form_id) {
-      $form = array_merge(clipper_node_settings($form['type']['#value']), $form);
-    }
-    if ($form['type']['#value'] .'_node_form' == $form_id) {
-      $node = $form['#node'];
-      $form['clipper_parent'] = clipper_form($node);
-    }
-  }
-}
-
-/**
  * Implementation of hook_nodeapi().
  */
 function clipper_nodeapi(&$node, $op) {
@@ -69,20 +54,37 @@ function clipper_nodeapi(&$node, $op) {
       case 'validate':
         clipper_validate($node);
       break;
+      
       case 'insert':
         clipper_insert($node);
       break;
+      
       case 'update':
         clipper_update($node);
       break;
+      
       case 'delete':
         clipper_delete($node);
       break;
+      
       case 'load':
         return clipper_load($node);
+        
+      case 'form pre':
+        return clipper_form($node);
+        
       case 'view':
         $node->body .= theme('clipper_view', $node);
       break;
+      
+      case 'settings':
+        $list = node_list();
+        foreach ($list as $type) {
+          $node_list[$type] = $type;
+        }
+        $form  = form_radios(t('Relations display'), 'clipper_'. $node->type, variable_get('clipper_'. $node->type, 0), array(t('Disabled'), t('Enabled')), t('Should parent or child relationships of this content type be displayed?'));
+        $form .= form_checkboxes(t('Relatable content types'), 'clipper_'. $node->type .'_relatable', variable_get('clipper_'. $node->type .'_relatable', array()), clipper_node_get_types(), t('Choose which content types, if any, this content type can become a child of.'));
+        return $form;
     }
   }
 }
@@ -151,6 +153,7 @@ function clipper_form($node) {
   // if this node has no relatable content types, then
   // we don't need to show this form, so return now.
   if (count($relatable_types) == 0) { return; }
+  if ($relatable_types == 0) { return; } //keve
 
   // passed in the URL to autocomplete.
   $completable_types = implode(',', $relatable_types);
@@ -158,7 +161,7 @@ function clipper_form($node) {
   // we determine the human names of $relatable_types above
   // so that we can refer to them in our help text.
   $relatable_types_human = NULL;
-  $content_types         = node_get_types();
+  $content_types         = clipper_node_get_types();
   foreach ($relatable_types as $relatable_type) {
     $relatable_types_human .= "$content_types[$relatable_type], ";
   }
@@ -169,14 +172,14 @@ function clipper_form($node) {
   $parents = array();
   if ($node->clipper->parents) {
     foreach ($node->clipper->parents as $parent) {
-      $parent    = node_load($parent);
+      $parent    = node_load( array( 'nid' => $parent));
       $parents[] = $parent->title;
     }
   }
 
   // an 'add child content type' has been clicked.
   if (arg(3) == 'childof' && is_numeric(arg(4))) {
-    $parent    = node_load(arg(4));
+    $parent    = node_load( array( 'nid' => arg(4)));
     $parents[] = $parent->title;
   }
 
@@ -194,14 +197,7 @@ function clipper_form($node) {
     $node->clipper_parent = implode(', ', $clean_parents);
   }
 
-  return array(
-    '#title' => t('Parent entries'),
-    '#type' => 'textfield',
-    '#default_value' => $node->clipper_parent,
-    '#autocomplete_path' => 'clipper/autocomplete/'.$completable_types,
-    '#description' => t('A comma-separated list of content titles related to this entry (Example: My Vacation, "A Trip to Paris, France"). This entry can be related to the following content types: %types', array('%type' => $relatable_types_human)),
-    '#weight'  => -10,
-  );
+  return clipper_form_autocomplete(t('Parent entries'), 'clipper_parent', $node->clipper_parent, 60, 250, "clipper/autocomplete/$completable_types", t('A comma-separated list of content titles related to this entry (Example: My Vacation, "A Trip to Paris, France"). This entry can be related to the following content types: '.$relatable_types_human.'.'), NULL, TRUE);
 }
 
 /**
@@ -229,31 +225,6 @@ function clipper_validate($node) {
 }
 
 /**
- * NodeAPI: settings form on each node.
- */
-function clipper_node_settings($type) {
-  $form['relations'] = array(
-    '#title' => t('Relations'),
-    '#type' => 'fieldset',
-  );
-  $form['relations']['clipper_'. $type] = array(
-    '#title' => t('Relations display'),
-    '#type' => 'radios',
-    '#default_value' => variable_get('clipper_'. $type, 0),
-    '#options' => array(t('Disabled'), t('Enabled')),
-    '#description' => t('Should parent or child relationships of this content type be displayed?'),
-  );
-  $form['relations']['clipper_'. $type .'_relatable'] = array(
-    '#title' => t('Relatable content types'),
-    '#type' => 'checkboxes',
-    '#default_value' => variable_get('clipper_'. $type .'_relatable', array()),
-    '#options' => node_get_types(),
-    '#description' => t('Choose which content types, if any, this content type can become a child of.'),
-  );
-  return $form;
-}
-
-/**
  * Theme: displays the parent/child relationships of this node. The display
  * will only occur if "Relations display" is enabled on this content type.
  */
@@ -264,7 +235,7 @@ function theme_clipper_view($node) {
 
     if ($node->clipper->parents) {
       foreach ($node->clipper->parents as $parent) {
-        $parent  = node_load($parent);
+        $parent  = node_load( array( 'nid' => $parent));
         $items[] = theme('clipper_item', $parent);
       }
 
@@ -273,7 +244,7 @@ function theme_clipper_view($node) {
 
     if ($node->clipper->children) {
       foreach ($node->clipper->children as $child) {
-        $child   = node_load($child);
+        $child   = node_load( array( 'nid' =>$child ));
         $items[] = theme('clipper_item', $child);
       }
 
@@ -339,12 +310,14 @@ function clipper_link($type, $node = NUL
   // for those type that allow THIS node to be its parent, we have
   // to load in all our _relatable configs to figure it out.
   $children      = array();
-  $content_types = node_get_types();
+  $content_types = clipper_node_get_types();
   foreach ($content_types as $content_type => $content_type_description) {
     $relatable_types = variable_get('clipper_'. $content_type .'_relatable', array());
-    foreach ($relatable_types as $relatable_type) {
-      if ($node->type == $relatable_type) {
-        $children[$content_type] = $content_type_description;
+    if ($relatable_types != 0) { //keve
+      foreach ($relatable_types as $relatable_type) {
+        if ($node->type == $relatable_type) {
+          $children[$content_type] = $content_type_description;
+        }
       }
     }
   }
@@ -408,3 +381,28 @@ function clipper_autocomplete($node_type
     exit();
   }
 }
+
+function clipper_node_get_types() {
+        $list = node_list();
+        foreach ($list as $type) {
+          $node_list[$type] = $type;
+        }
+        return $node_list;
+}
+
+function clipper_form_autocomplete($title, $name, $value, $size, $maxlength, $callback_path, $description = NULL, $attributes = NULL, $required = FALSE) {
+  //drupal_add_js('misc/autocomplete.js');
+
+  $size = $size ? ' size="'. $size .'"' : '';
+
+  $output = theme('form_element', $title, '<input type="text" maxlength="'. $maxlength .'" class="'. _form_get_class('form-text form-autocomplete', $required, _form_get_error($name)) .'" name="edit['. $name .']" id="edit-'. clipper_form_clean_id($name) .'"'. $size .' value="'. check_plain($value) .'"'. drupal_attributes($attributes) .' />', $description, 'edit-'. $name, $required, _form_get_error($name));
+  $output .= '<input class="autocomplete" type="hidden" id="edit-'. clipper_form_clean_id($name) .'-autocomplete" value="'. check_url(url($callback_path, NULL, NULL, TRUE)) .'" disabled="disabled" />';
+
+  return $output;
+}
+
+function clipper_form_clean_id($id = NULL) {
+  $id = str_replace('][', '-', $id);
+  return $id;
+}
+?>
\ No newline at end of file
