Index: imagefield.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagefield/imagefield.module,v
retrieving revision 1.31
diff -u -p -r1.31 imagefield.module
--- imagefield.module	19 Apr 2007 23:50:05 -0000	1.31
+++ imagefield.module	18 Dec 2007 10:08:58 -0000
@@ -10,6 +10,9 @@
  */
 
 
+/**
+ * Implementation of hook_menu().
+ */
 function imagefield_menu($maycache) {
   $items = array();
   if (!$maycache && $_SESSION['imagefield']) {
@@ -81,12 +84,11 @@ function imagefield_field_settings($op, 
 }
 
 /**
- * insert a file into the database.
+ * Insert a file into the database.
  * @param $node
- *    node object file will be associated with.
+ *    Node object file will be associated with.
  * @param $file
- *    file to be inserted, passed by reference since fid should be attached.
- *    
+ *    File to be inserted, passed by reference since fid should be attached.  
  */
 function imagefield_file_insert($node, &$file, $field) {
   $fieldname = $field['field_name'];
@@ -109,15 +111,15 @@ function imagefield_file_insert($node, &
 
 
 /**
- * update the file record if necessary
+ * Update the file record if necessary
  * @param $node
  * @param $file
  * @param $field
  */
 function imagefield_file_update($node, &$file, $field) {
-  $file = (array)$file; 
+  $file = (array)$file;
   if ($file['flags']['delete'] == TRUE) {
-    if(_imagefield_file_delete($file, $field['field_name'])) {
+    if (_imagefield_file_delete($file, $field['field_name'])) {
       return array();
     }
   }
@@ -125,7 +127,7 @@ function imagefield_file_update($node, &
     return imagefield_file_insert($node, $file, $field);
   }
   else {
-    // if fid is not numeric here we should complain.
+    //If fid is not numeric here we should complain.
     // else we update the file table.  
   }
   return $file;
@@ -137,7 +139,7 @@ function imagefield_file_update($node, &
 function imagefield_field($op, $node, $field, &$node_field, $teaser, $page) {
   $fieldname = $field['field_name'];
   switch ($op) {
-    // called after content.module loads default data.
+    // Called after content.module loads default data.
     case 'load':
       $output = array();
       if (count($node_field)) {
@@ -147,7 +149,7 @@ function imagefield_field($op, $node, $f
         }
         $output = array($fieldname => $node_field);
       };
-      break; 
+      break;
 
     case 'view':
       $formatter = 'default';
@@ -158,30 +160,30 @@ function imagefield_field($op, $node, $f
         }
       }
       foreach ($node_field as $delta => $item) {
-        $node_field[$delta]['view'] = content_format($field, $item, $formatter); 
+        $node_field[$delta]['view'] = content_format($field, $item, $formatter);
       }
-      $output = theme('field', $node, $field, $node_field, $teaser, $page); 
+      $output = theme('field', $node, $field, $node_field, $teaser, $page);
       break;
 
-    // called before content.module defaults.
+    // Called before content.module defaults.
     case 'insert':
       foreach ($node_field as  $delta => $item) {
-        $node_field[$delta] = imagefield_file_insert($node, $item, $field); 
+        $node_field[$delta] = imagefield_file_insert($node, $item, $field);
       }
       imagefield_clear_field_session($fieldname);
       break;
 
-    // called before content.module defaults.
+    // Called before content.module defaults.
     case 'update':
       foreach ($node_field as $delta => $item) {
-        $node_field[$delta] = imagefield_file_update($node, $item, $field); 
+        $node_field[$delta] = imagefield_file_update($node, $item, $field);
       }
       imagefield_clear_field_session($fieldname);
       break;
 
     case 'delete':
       foreach ($node_field as $delta => $item) {
-        _imagefield_file_delete($item, $field['field_name']); 
+        _imagefield_file_delete($item, $field['field_name']);
       }
       break;
   }
@@ -208,13 +210,12 @@ function imagefield_widget_settings($op,
     case 'form':
       $form = array();
       $form['max_resolution'] = array (
-        '#type' => 'textfield', 
-        '#title' => t('Maximum resolution for Images'), 
+        '#type' => 'textfield',
+        '#title' => t('Maximum resolution for Images'),
         '#default_value' => $widget['max_resolution'] ? $widget['max_resolution'] : 0,
-        '#size' => 15, 
-        '#maxlength' => 10, 
-        '#description' => 
-        t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.')
+        '#size' => 15,
+        '#maxlength' => 10,
+        '#description' => t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.')
       );
       $form['image_path'] = array(
         '#type' => 'textfield', 
@@ -239,23 +240,23 @@ function imagefield_widget_settings($op,
         $options = array();
         $options['default'] = 'Default';
         $presets =  _imagecache_get_presets();
-        foreach($presets as $id => $name) {
+        foreach ($presets as $id => $name) {
           $options[$name] = $name;
         }
         $form['imagecache'] = array(
           '#type' => 'fieldset',
-          '#title' => 'Imagecache Options',
+          '#title' => 'ImageCache Options',
         );
         $form['imagecache']['teaser_preset'] = array(
           '#title' => t('Teaser preset'),
-          '#description' => t('Select the imagecache preset you want to handle thumbnails in the teaser.'),
+          '#description' => t('Select the ImageCache preset you want to handle thumbnails in the teaser.'),
           '#type' => 'select',
           '#options' =>  $options,
           '#default_value' => $widget['teaser_preset'] ? $widget['teaser_preset'] : 'default' ,
         );
         $form['imagecache']['body_preset'] = array(
           '#title' => t('Body preset'),
-          '#description' => t('Select the imagecache preset you want to handle thumbnails in the teaser.'),
+          '#description' => t('Select the ImageCache preset you want to handle thumbnails in the teaser.'),
           '#type' => 'select',
           '#options' =>  $options,
           '#default_value' => $widget['body_preset'] ? $widget['body_preset'] : 'default',
@@ -279,11 +280,11 @@ function imagefield_widget_settings($op,
  *   The form element containing the name of the directory to check.
  */ 
 function imagefield_check_directory($form_element) {
-  if(!empty($form_element['#value'])) {
-    // create each directory necessary if it doesn't exist
+  if (!empty($form_element['#value'])) {
+    // Create each directory necessary if it doesn't exist
     foreach(explode('/', $form_element['#value']) as $dir) {
       $dirs[] = $dir;
-      file_check_directory(file_create_path(implode($dirs,'/')), FILE_CREATE_DIRECTORY, $form_element['#parents'][0]);
+      file_check_directory(file_create_path(implode($dirs, '/')), FILE_CREATE_DIRECTORY, $form_element['#parents'][0]);
     }
   }
   return $form_element;
@@ -297,7 +298,7 @@ function _imagefield_scale_image($file, 
       $result = image_scale($file['filepath'], $file['filepath'], $width, $height);
       if ($result) {
         $file['filesize'] = filesize($file['filepath']);
-        drupal_set_message(t('The image was resized to fit within the maximum allowed resolution of %resolution pixels', array('%resolution' => $resolution)));      
+        drupal_set_message(t('The image was resized to fit within the maximum allowed resolution of %resolution pixels.', array('%resolution' => $resolution)));     
       }
     }
   }
@@ -345,7 +346,7 @@ function imagefield_widget($op, &$node, 
   $content_type = $field['type_name'];
   switch ($op) {
     case 'prepare form values':
-      // clean up the session if we weren't posted.
+      // Clean up the session if we weren't posted.
       if (!count($_POST)) {
         imagefield_clear_session();
       }
@@ -362,13 +363,14 @@ function imagefield_widget($op, &$node, 
             if (strpos($filepath, file_directory_path()) !== FALSE) {
               $filepath = trim(substr($filepath, strlen(file_directory_path())), '\\/');
             }
-            $filepath = 'system/files/' . $filepath;
+            $filepath = 'system/files/'. $filepath;
           }
           
           $file['fid'] = 'upload';
           $file['preview'] = $filepath;
           
-          // If a single field, mark any other images for deletion and delete files in session
+          // If a single field, mark any other images for deletion and delete
+          // files in session.
           if (!$field['multiple']) {
             if (is_array($node_field)) {
               foreach ($node_field as $delta => $session_file) {
@@ -377,7 +379,7 @@ function imagefield_widget($op, &$node, 
             }
             imagefield_clear_field_session($fieldname);
           }
-          // Add the file to the session
+          // Add the file to the session.
           $file_id = count($node_field) + count($_SESSION['imagefield'][$fieldname]);
           $_SESSION['imagefield'][$fieldname][$file_id] = $file;
         }
@@ -396,10 +398,8 @@ function imagefield_widget($op, &$node, 
       return $form;
 
     case 'validate':
-      if ($field['required']) {
-        if (!count($node_field)) {
-          form_set_error($fieldname, $field['widget']['label'] .' is required.');
-        }
+      if ($field['required'] && !count($node_field)) {
+        form_set_error($fieldname, $field['widget']['label'] .' is required.');
       }
       return;
   }
@@ -409,7 +409,7 @@ function _imagefield_widget_form($node, 
   $fieldname = $field['field_name'];
   drupal_add_css(drupal_get_path('module', 'imagefield') .'/imagefield.css');
  
-  $form = array(); 
+  $form = array();
   $form[$fieldname] = array(
     '#type' => 'fieldset',
     '#title' => t($field['widget']['label']),
@@ -431,8 +431,8 @@ function _imagefield_widget_form($node, 
   $form[$fieldname]['upload'] = array(
     '#type' => 'button',
     '#value' => t('Upload'),
-    '#name' => 'cck_imagefield_'.$fieldname.'_op',
-    '#attributes' => array('id' => $fieldname.'-attach-button'),
+    '#name' => 'cck_imagefield_'. $fieldname .'_op',
+    '#attributes' => array('id' => $fieldname .'-attach-button'),
     '#tree' => FALSE,
     '#weight' => 10,
   );
@@ -596,7 +596,7 @@ function theme_imagefield_edit_image_row
   if (isset($element['replace'])) {
     $output .= '<div class="imagefield-edit-image-replace">'. drupal_render($element['replace']) .'</div>';
   }
-  return $output;  
+  return $output; 
 }
 
 function theme_imagefield_image($file, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
