Index: field_copy.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/field_copy/field_copy.info,v
retrieving revision 1.2
diff -u -r1.2 field_copy.info
--- field_copy.info	4 Oct 2008 11:11:54 -0000	1.2
+++ field_copy.info	8 Feb 2009 22:22:40 -0000
@@ -1,5 +1,6 @@
-; $Id $
+; $Id$
 name = Field Copy
-description = "Allows copying one field's data to another field for all instances of a content type."
-dependencies = content
-package = CCK
\ No newline at end of file
+description = Allows copying one field's data to another field for all instances of a content type.
+dependencies[] = content
+package = CCK
+core = 6.x
\ No newline at end of file
Index: field_copy.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/field_copy/field_copy.module,v
retrieving revision 1.3
diff -u -r1.3 field_copy.module
--- field_copy.module	4 Oct 2008 11:12:06 -0000	1.3
+++ field_copy.module	9 Feb 2009 17:40:28 -0000
@@ -1,64 +1,57 @@
 <?php
-//$Id: field_copy.module,v 1.3 2008/10/04 11:12:06 regx Exp $
+// $Id: field_copy.module,v 1.3 2008/10/04 11:12:06 regx Exp $
 
 /**
-* @file: field_copy.module
-* cck copy body module for Drupal 5.x
-* Allows copying one field's data to another field for all instances of a content type..
-* ----------------------------------------------------------------------------
-* @author: regx (gvarnell@osoft.com)
-* @copyright: 2007-2008 Gary Varnell
-*/
-
-/** @annotation: @todo - Write Test */
-/** @annotation: @todo - Remove CCK dependancy */
-/** @annotation: @todo - Build Docs */
-/** @annotation: @todo - Add filters or at least a remove html filter */
-/** @annotation: @todo - Add seperate setting form watchdog options etc. */
-
+ * CCK copy module for Drupal 6.x.
+ * Allows copying one field's data to another field for all instances of a content type.
+ *
+ * @file:
+ * Setup the forms, menu entries and does the field copy process.
+ *
+ * @author: regx (gvarnell@osoft.com)
+ */
 
+/**
+ * @annotation: @todo - Write Test
+ * @annotation: @todo - Remove CCK dependancy
+ * @annotation: @todo - Build Docs
+ * @annotation: @todo - Add filters or at least a remove html filter
+ * @annotation: @todo - Add seperate setting form watchdog options etc.
+ */
  
-define('FIELD_COPY_DEBUG',0);
-$module_path = drupal_get_path('module','field_copy');
-drupal_add_css($module_path . '/field_copy.css','module','screen');
+define('FIELD_COPY_DEBUG', 0);
+$module_path = drupal_get_path('module', 'field_copy');
+drupal_add_css($module_path . '/field_copy.css', 'module', 'screen');
 
 /**
  * Implementation of hook_menu().
  */
- 
-
-function field_copy_menu($may_cache) {
-if($may_cache){
-  $items[] = array(
-    'path' => 'admin/settings/field_copy',
-    'title' => t('Field Copy'),
-    'description' => t('Allows copying cck node body contents to another cck field.'),
-    'callback' => 'drupal_get_form',
-    'callback arguments' => array('field_copy_form'),
-    'access' => user_access('administer site configuration'),
-    'type' => MENU_NORMAL_ITEM, // optional
+function field_copy_menu() {
+  $items['admin/settings/field_copy'] = array(
+    'title' => 'Field Copy',
+    'description' => 'Allows copying cck node body contents to another cck field.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('field_copy_form'),
+    'access arguments' => array('administer site configuration'),
   );
-  $items[] = array(
-    'path' => 'admin/content/field_copy',
-    'title' => t('Field Copy'),
-    'description' => t('Allows copying cck node body contents to another cck field.'),
-    'callback' => 'drupal_get_form',
-    'callback arguments' => array('field_copy_form'),
-    'access' => user_access('administer content'),
-    'type' => MENU_NORMAL_ITEM, // optional
+  $items['admin/content/field_copy'] = array(
+    'title' => 'Field Copy',
+    'description' => 'Allows copying cck node body contents to another cck field.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('field_copy_form'),
+    'access arguments' => array('administer content'),
   );
+  return $items;
 }
- return $items;
-}
-//----------------------------------------------------------------------
 
 /**
-* @name field_copy_form()
-* Implementation of hook_menu().
-* @return array field_copy_form
-*/
-function field_copy_form(){
-  # get the content types
+ * Implementation of hook_menu().
+ *
+ * @name field_copy_form()
+ * @return array field_copy_form
+ */
+function field_copy_form() {
+  // Get the content types.
   $content_types = field_copy_get_content_types();
   //field_copy_debug($content_types);
 
@@ -67,11 +60,11 @@
     '#redirect' => FALSE,
   );
   
-  # add help to thr form
+  // Add help to the form.
   $form['help'] = array(
     '#type' => 'fieldset',
     '#title' => 'Help',
-    '#description' => field_copy_help('admin/help/field_copy'),
+    '#description' => field_copy_help('admin/help/field_copy', array()),
   );
   
   foreach($content_types as $c_type => $c_data){ 
@@ -81,13 +74,13 @@
       '#collapsible' => TRUE,
       '#collapsed' => FALSE,
       );
-      # now get the cck fields and add them to target list
+      // Now get the cck fields and add them to target list.
       $options = array();
       foreach($c_data['fields'] as $c_field){
-        $options = array_merge($options,array($c_field['field_name'] => $c_field['field_name'] ));
+        $options = array_merge($options, array($c_field['field_name'] => $c_field['field_name'] ));
       }
-      //if(!empty($options)){ # uncomment to only handle cck fields
-        $options = array_merge($options,array(null => null,'title' => 'title', 'body' => 'body' ));
+      //if(!empty($options)){ // uncomment to only handle cck fields
+        $options = array_merge($options, array(null => null, 'title' => 'title', 'body' => 'body' ));
 
         ksort($options);
         $default = $edit['field'][$c_type]['source'];
@@ -134,10 +127,12 @@
 //  return drupal_get_form('field_copy_form');
 // }
 
-/** hook_help **/
-function field_copy_help($section) {
+/**
+ * Implementation of hook_help().
+ */
+function field_copy_help($path, $arg) {
 //print "$section <br/>";
-  switch ($section) {
+  switch ($path) {
     case "admin/help#field_copy":
       return t("Settings for field_copy");
       break;
@@ -153,63 +148,64 @@
       To reset the form hit the reset button.");
       break;
   }
-} //end hook_help
+}
 
 
 /**
-* @name field_copy_form_validate
-* @desc implementation of hook_validate
-* Checks that source and Target fields are defined and have the same field type
-*/
-function field_copy_form_validate($formid,$form_values) {
-  # get the content types
+ * Implementation of hook_validate().
+ *
+ * @name field_copy_form_validate
+ * Checks that source and Target fields are defined and have the same field type
+ */
+function field_copy_form_validate($form, &$form_state) {
+  // Get the content types.
   
-  if($form_values['op'] == t('Reset')){
+  if($form_state['values']['op'] == t('Reset')){
     drupal_goto('admin/content/field_copy');
   }
   $content_types = field_copy_get_content_types();
   field_copy_debug($content_types);
-  foreach($form_values['field'] as $fv_c_type => $fv_c_data){
-    #make sure both target and source are defined
+  foreach($form_state['values']['field'] as $fv_c_type => $fv_c_data){
+    // Make sure both target and source are defined.
     $source = $fv_c_data['source'];
     $target = $fv_c_data['target'];
     if($source || $target){
       if(!$source){
-        form_set_error('field]['.$fv_c_type.'][source',t('%type has a target set, but no source',array('%type' => $fv_c_type)));
+        form_set_error('field]['.$fv_c_type.'][source', t('%type has a target set, but no source', array('%type' => $fv_c_type)));
       }
       elseif(!$target){
-          form_set_error('field]['.$fv_c_type.'][target',t('%type has a source set, but no target',array('%type' => $fv_c_type)));
+          form_set_error('field]['.$fv_c_type.'][target', t('%type has a source set, but no target', array('%type' => $fv_c_type)));
       }
-      #make sure target and source are not the same
+      // Make sure target and source are not the same.
       if($source == $target){
-        form_set_error('field]['.$fv_c_type.'][source',t('%type source and target fields are the same - that would be kinda pointless don\'t you think?.',array('%type' => $fv_c_type)));
+        form_set_error('field]['.$fv_c_type.'][source', t('%type source and target fields are the same - that would be kinda pointless don\'t you think?.', array('%type' => $fv_c_type)));
       }
     }
     
 
-    #both source and target are set, make sure they are the same type
-    # add body and title as text field types to the content_types - this just makes the content type check easier
+    // Both source and target are set, make sure they are the same type.
+    // Add body and title as text field types to the content_types - this just makes the content type check easier.
     
     $content_types[$fv_c_type]['fields']['title']['type'] = 'text';
     $content_types[$fv_c_type]['fields']['body']['type'] = 'text';
     
     if($content_types[$fv_c_type]['fields'][$source]['type'] != $content_types[$fv_c_type]['fields'][$target]['type']){
-      form_set_error('field]['.$fv_c_type.'][source',t('%type source and target fields are a different data types',array('%type' => $fv_c_type)));
+      form_set_error('field]['.$fv_c_type.'][source', t('%type source and target fields are a different data types', array('%type' => $fv_c_type)));
     }
   }
 }
 
 
-function field_copy_form_submit($formid,$form_values){
-  foreach($form_values['field'] as $fv_c_type => $fv_c_data){
+function field_copy_form_submit($form, &$form_state) {
+  foreach($form_state['values']['field'] as $fv_c_type => $fv_c_data){
     $source = $fv_c_data['source'];
     $target = $fv_c_data['target'];
     $nullify = $fv_c_data['nullify'];
     if(!empty($source) && !empty($target)){
-      field_copy_copy_field($fv_c_type,$source,$target,$nullify);
+      field_copy_copy_field($fv_c_type, $source, $target, $nullify);
     }
   }
-  drupal_set_message('DONE','status');
+  drupal_set_message(t('Field copy finished.'), 'status');
 }
 
 
@@ -218,10 +214,10 @@
 * @desc Just returns the content types via cck content_types() function
 */ 
 function field_copy_get_content_types($content_type = NULL){
-  # get the content types
-  include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc');
-  include_once('./'. drupal_get_path('module', 'content') .'/content_admin.inc');
-  include_once('./'. drupal_get_path('module', 'content') .'/content_crud.inc');
+  // get the content types
+  include_once(drupal_get_path('module', 'node') .'/content_types.inc');
+  include_once(drupal_get_path('module', 'content') .'/includes/content.admin.inc');
+  include_once(drupal_get_path('module', 'content') .'/includes/content.crud.inc');
   $content_types = content_types($content_type);
   //field_copy_debug($content_types);
   return $content_types;
@@ -230,41 +226,40 @@
 
 
 /**
-* @name field_copy_copy_field
-* @desc copies source field value to target field value for all nodes of type
-* ie. node 1 target = node 1 source 
-* Checks that source and Target fields are defined and have the same field type
-* These checks are mostly identical to the form validate chacks, but we need them here so that this function
-* can be used as an API call. The main difference is that errors here are logged to watchdog
-*/
-function field_copy_copy_field($content_type,$source_field,$target_field,$nullify_source = FALSE){
+ * @name field_copy_copy_field
+ * @desc copies source field value to target field value for all nodes of type
+ * ie. node 1 target = node 1 source 
+ * Checks that source and Target fields are defined and have the same field type
+ * These checks are mostly identical to the form validate chacks, but we need them here so that this function
+ * can be used as an API call. The main difference is that errors here are logged to watchdog
+ */
+function field_copy_copy_field($content_type, $source_field, $target_field, $nullify_source = FALSE){
   $content_types = field_copy_get_content_types($content_type);
-  # make sure source and target types are same data type
+  // Make sure source and target types are same data type.
   $content_types['fields']['title']['type'] = 'text';
   $content_types['fields']['body']['type'] = 'text';
   if($content_types['fields'][$source_field]['type'] != $content_types['fields'][$target_field]['type']){
-    $error = t('%type field %source and %target have different data types',array('%type' => $content_type,'%source'=>$source_field,'%target' =>$target_field));
-    drupal_set_message($error,'error');
-    watchdog('field_copy', $error,  WATCHDOG_ERROR);
+    $error = t('%type field %source and %target have different data types', array('%type' => $content_type, '%source'=>$source_field, '%target' =>$target_field));
+    drupal_set_message($error, 'error');
+    //watchdog('field_copy', $error,  WATCHDOG_ERROR);
     return;
   }
-  # make sure target and source are not the same field
+  // Make sure target and source are not the same field.
   if($source_field == $target_field){
-    $error = t('%type source %source and target %target are the same. Nothing to do!',array('%type' => $content_type,'%source'=>$source_field,'%target' =>$target_field));
-    drupal_set_message($error,'error');
-    watchdog('field_copy', $error,  WATCHDOG_ERROR);
+    $error = t('%type source %source and target %target are the same. Nothing to do!', array('%type' => $content_type, '%source'=>$source_field, '%target' =>$target_field));
+    drupal_set_message($error, 'error');
+    //watchdog('field_copy', $error,  WATCHDOG_ERROR);
     return;
   }
   
-  # get all nodes of type and do replacement
-  $result = db_query("SELECT nid FROM {node} WHERE type = '%s'",$content_type);
+  // Get all nodes of type and do replacement.
+  $result = db_query("SELECT nid FROM {node} WHERE type = '%s'", $content_type);
   while($row = db_fetch_array($result)){
     $nid = $row['nid'];
     $node = node_load(array('nid' => $nid));
     //field_copy_debug($node);
-    # get references to the node source and target fields
-    # If we are copying from body/title to a cck field 
-    # We need to set the target refernece to the cck_field[0]['value'] 
+    // Get references to the node source and target fields.
+    // If we are copying from body/title to a cck field we need to set the target refernece to the cck_field[0]['value'].
     switch ($source_field) {
       case 'body':
       case 'title':
@@ -281,9 +276,9 @@
       default:
       $n_target_field = &$node->$target_field;
     }
-    # same logic for source field
-    # If we are copying to a title/body field from a cck field 
-    # We need to set the source refernece to the cck_field[0]['value'] 
+    // Same logic for source field.
+    // If we are copying to a title/body field from a cck field.
+    // We need to set the source reference to the cck_field[0]['value'].
     switch ($target_field) {
       case 'body':
       case 'title':
@@ -300,29 +295,29 @@
       default:
       $n_source_field = &$node->$source_field;
     }
-    # everything should be set now, do the copy
-    
+
+    // Everything should be set now, do the copy.
     $n_target_field = $n_source_field;
     if($nullify_source){
       $n_source_field = '';
     }
     node_save($node);
-    drupal_set_message(t('Type %type - Copying %source to %target for node ',array('%type' => $content_type, '%source' => $source_field,'%target' => $target_field)) . l($row['nid'],'node/' . $row['nid'],null,true));
-  } // end while
+    drupal_set_message(t('Type %type - copying %source to %target for node', array('%type' => $content_type, '%source' => $source_field, '%target' => $target_field)) .' '. l($row['nid'], 'node/' . $row['nid']) .'.');
+  }
 }
 
 
 
-/** Begin Helper Functions
--------------------------------------------------------------------------------------------------  **/
+/**
+ * Helper functions.
+ */
 function field_copy_debug($msg){
   if(FIELD_COPY_DEBUG){
     if(is_array($msg) || is_object($msg)){
-      drupal_set_message('<pre>' . print_r($msg,true) . '</pre>','debug');
+      drupal_set_message('<pre>' . print_r($msg, true) . '</pre>', 'debug');
     }
    else{
-      drupal_set_message('field_copy: ' . $msg,'debug');
+      drupal_set_message('field_copy: ' . $msg, 'debug');
     }
   }
-}
-?>
\ No newline at end of file
+}
\ No newline at end of file

