Index: modules/img_assist/img_assist.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/img_assist.module,v
retrieving revision 1.54
diff -u -r1.54 img_assist.module
--- modules/img_assist/img_assist.module        30 Nov 2005 02:48:56 -0000 1.54
+++ modules/img_assist/img_assist.module        16 Dec 2005 14:03:25 -0000 @@ -1,5 +1,5 @@
 <?php
-// $Id: img_assist.module,v 1.54 2005-11-30 02:48:56 mathias Exp $
+// $Id: img_assist.module,v 1.54 2005/11/30 02:48:56 mathias Exp $
 // Authored by: Matt Westgate <drupal at asitis dot org>
 
 /**
@@ -8,7 +8,7 @@
  */
 
 /********************************************************************
- * Drupal Hooks
+ * Drupal Hooksimg_assist_menu()
  ********************************************************************/
 
 /**
@@ -135,17 +135,61 @@
   if (!$upload_enabled && !$image_enabled) {
     drupal_set_message(t('Neither Upload module or Image module are enabled. Img_assist needs one of these modules enabled in order to work. Please do that now.'), 'error');
   }
+  
+  $form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
 
-  $group = form_radios(t('Display img_assist on'), 'img_assist_all', variable_get('img_assist_all', 1), array(t('on specific pages'), t('on all textareas')));
+  $form['img_assist_access'] = array(
+    '#title' => t('Access settings'),
+    '#type' => 'fieldset',
+    '#collapsible' => true,
+    '#collapsed' => true,
+  );
+  $form['img_assist_access']['img_assist_all'] = array(
+    '#type' => 'radios',
+    '#title' => t('Display img_assist on'),
+    '#default_value' => variable_get('img_assist_all', 1),
+    '#options' => array(t('on specific pages'), t('on all textareas')),
+    );
+    
   if (!variable_get('img_assist_all', 1)) {
-    $group .= form_textarea(t('Pages'), 'img_assist_pages', variable_get('img_assist_pages', img_assist_help('admin/settings/img_assist#pages')), 40, 5, t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '<em>blog</em>' for the blog page and '<em>blog/*</em>' for every personal blog. '<em>&lt;front&gt;</em>' is the front page."));
-  }
-  $output = form_group_collapsible(t('Access settings'), $group, TRUE);
-
-  $group = form_checkboxes(t('Hide \'inline image link\' for the following node types'), 'img_assist_no_nodes', variable_get('img_assist_no_nodes', array()), $nodetypes, t('Check the node types you <strong>do not</strong> want the ability to add images to.'), NULL, TRUE);
-  $group .= form_textarea(t('Image HTML template'), 'img_assist_img_html', variable_get('img_assist_img_html', img_assist_help('img_assist/template')), 50, 10, t('Enter the HTML wrap around your image tag. You can use the following variables: <strong>%image-class</strong> - CSS class name of the image. The default is &quot;image&quot;, <strong>%img-link</strong> - a link to the original image, <strong>%node-link</strong> - a link to the original node containing the image, <strong>%nid</strong> - a nid of the original node containing the image, and <strong>%caption</strong> - a user-defined caption.'));
-  $group .= form_radios(t('Preload image captions'), 'img_assist_load_caption', variable_get('img_assist_load_caption', 1), array(t('Disabled'), t('Enabled')), t('If enabled, The body text from the image will be loaded as the caption by default.'));
-  $output .= form_group_collapsible(t('Image output settings'), $group, TRUE);
+    $form['img_assist_access']['img_assist_pages'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Pages'),
+      '#default_value' => variable_get('img_assist_pages', img_assist_help('admin/settings/img_assist#pages')),
+      '#cols' => 40,
+      '#rows' => 5,
+      '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '<em>blog</em>' for the blog page and '<em>blog/*</em>' for every personal blog. '<em>&lt;front&gt;</em>' is the front page."),
+    );
+  }
+  $form['img_assist_output'] = array(
+    '#title' => t('Image output settings'),
+    '#type' => 'fieldset',
+    '#collapsible' => true,
+    '#collapsed' => true,
+  );
+  $form['img_assist_output']['img_assist_no_nodes'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Hide \'inline image link\' for the following node types'),
+    '#default_value' => variable_get('img_assist_no_nodes', array('image')),
+    '#options' => node_get_types(),
+    '#description' => t('Check the node types you <strong>do not</strong> want the ability to add images to.'),
+  );
+  $form['img_assist_output']['img_assist_img_html'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Image HTML template'),
+    '#default_value' => variable_get('img_assist_img_html', img_assist_help('img_assist/template')),
+    '#cols' => 50,
+    '#rows' => 10,
+    '#description' => t('Enter the HTML wrap around your image tag. You can use the following variables: <strong>%image-class</strong> - CSS class name of the image. The default is &quot;image&quot;, <strong>%img-link</strong> - a link to the original image, <strong>%node-link</strong> - a link to the original node containing the image, <strong>%nid</strong> - a nid of the original node containing the image, and <strong>%caption</strong> - a user-defined caption.'),
+  );
+  $form['img_assist_output']['img_assist_load_caption'] = array(
+    '#type' => 'radios',
+    '#title' => t('Preload image captions'),
+    '#default_value' => variable_get('img_assist_load_caption', 1),
+    '#options' => array(t('Disabled'), t('Enabled')),
+    '#description' => t('If enabled, The body text from the image will be loaded as the caption by default.'),
+  );
+    
 
   if (module_exist('taxonomy')) {
     $vocs[0] = '<'. t('none') .'>';
@@ -153,12 +197,23 @@
       $vocs[$vid] = $voc->name;
     }
 
-    if ($voc) {
-      $preview  = form_select(t('Image preview filter'), 'img_assist_preview_filter', variable_get('img_assist_preview_filter', array()), $vocs, t('Select the vocabularies you want to be able to filter thumbnails by. This setting changes the behavior of img_assist at startup from loading all image thumbnails to displaying a list of image names until a filter is chosen.'), '', 1);
-    }
+   }
+  $form['img_assist_preview_settings'] = array(
+    '#title' => t('Preview settings'),
+    '#type' => 'fieldset',
+    '#collapsible' => true,
+    '#collapsed' => true,
+  );
+  if ($voc) {
+    $form['img_assist_preview_settings']['img_assist_preview_filter'] = array(
+      '#type' => 'select',
+      '#title' => t('Image preview filter'),
+      '#default_value' => variable_get('img_assist_preview_filter', array()),
+      '#options' => $vocs,
+      '#description' => t('Select the vocabularies you want to be able to filter thumbnails by. This setting changes the behavior of img_assist at startup from loading all image thumbnails to displaying a list of image names until a filter is chosen.'),
+      '#multiple' => 1,
+    );
   }
-
-  $group = $preview;
   if (function_exists('_image_get_sizes')) {
     foreach (_image_get_sizes() as $size) {
       if ($size['label']) {
@@ -167,13 +222,40 @@
     }
   }
   if ($derivatives) {
-    $group .= form_select(t('Default derivative selection'), 'default_label', variable_get('default_label', '_original'), $derivatives, t('Select a derivative to be highlighted by default when an image is selected in the img_assist preview pane.'));
-  }
-  $group .= form_textfield(t('Default width of image thumbnail previews'), 'img_assist_default_preview_width', variable_get('img_assist_default_preview_width', 75), 6, 6, t('Enter, in pixels, the default width of an image to display in the preview pane. The smaller this number, the more images you will be able to see without scrolling.'));
-  $group .= form_textfield(t('Max number of images to preview'), 'img_assist_preview_count', variable_get('img_assist_preview_count', 25), 6, 6, t('Enter the threshold of the number of images to display in the  directory preview pane. If there are more images for a given view, they will be displayed as hyperlinks.'));
-  $output .= form_group_collapsible(t('Preview settings'), $group, TRUE);
+    $form['img_assist_preview_settings']['default_label'] = array(
+      '#type' => 'select',
+      '#title' => t('Default derivative selection'),
+      '#default_value' => variable_get('default_label', '_original'),
+      '#options' => $derivatives,
+      '#description' => t('Select a derivative to be highlighted by default when an image is selected in the img_assist preview pane.'),
+    );
+  }
+  $form['img_assist_preview_settings']['img_assist_default_preview_width'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Default width of image thumbnail previews'),
+    '#default_value' => variable_get('img_assist_default_preview_width', 75),
+    '#size' => 6,
+    '#maxlength' => 6,
+    '#description' => t('Enter, in pixels, the default width of an image to display in the preview pane. The smaller this number, the more images you will be able to see without scrolling.'),
+  );
+  $form['img_assist_preview_settings']['img_assist_preview_count'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Max number of images to preview'),
+    '#default_value' => variable_get('img_assist_preview_count', 25),
+    '#size' => 6,
+    '#maxlength' => 6,
+    '#description' => t('Enter the threshold of the number of images to display in the  directory preview pane. If there are more images for a given view, they will be displayed as hyperlinks.'),
+  );
+  
+  return $form;
+}
 
-  return $output;
+/**
+ * Implementation of hook_elements().
+ */
+function img_assist_elements() {
+  $type['textarea'] = array('#process' => array('img_assist_textarea' => array()));
+  return $type;
 }
 
 /**
@@ -181,12 +263,13 @@
  *
  * Add image links underneath textareas.
  */
-function img_assist_textarea($op, $name) {
-  if ($op == 'post' && _img_assist_page_match() && !strstr($_GET['q'], 'img_assist/add/image')) {
-    $anchor = '<div class="img_assist-button"><a class="img_assist-link" id="img_assist-link-edit-'. $name .'" title="' . t('Click here to add images') . '" href="'. url('img_assist/add', 'textarea=edit['. $name. ']') .'" onclick="window.open(this.href, \'img_assist_link\', \'width=500,height=625,scrollbars=yes,status=yes,resizable=yes\'); return false">';
+function img_assist_textarea($element) {
+  if (_img_assist_page_match($node) && !strstr($_GET['q'], 'img_assist/add/image')) {
+    $anchor = '<div class="img_assist-button"><a class="img_assist-link" id="img_assist-link-'. $element['#id'] .'" title="' . t('Click here to add images') . '" href="'. url('img_assist/add', 'textarea='. $element['#name']) .'" onclick="window.open(this.href, \'img_assist_link\', \'width=500,height=625,scrollbars=yes,status=yes,resizable=yes\'); return false">';
     $image = '<img src="'. drupal_get_path('module', 'img_assist') .'/add-image.jpg" width="36" height="25" />';
-    return $anchor. $image . '</a></div>';
+    $element['#suffix'] .= $anchor. $image . '</a></div>';
   }
+  return $element;
 }
 
 /********************************************************************
@@ -201,7 +284,6 @@
 
   $textarea = $_GET['textarea'] ? $_GET['textarea'] : variable_get('img_assist_textarea', $textarea);
   variable_set('img_assist_textarea', $textarea);
-
   $head = '';
   $editor = '';
   if ($_GET['editor']) {
@@ -336,23 +418,10 @@
   $img_assist_dir = drupal_get_path('module', 'img_assist');
 
   switch ($op) {
-    case t('Preview'):
-      $edit = node_validate($edit);
-      drupal_set_title(t('Preview'));
-      $output .= node_preview($edit);
-      break;
-
     case t('Submit'):
-      if ($nid = node_submit($edit)) {
-        // Pass along the editor instance if there is one.
-        drupal_goto('img_assist/add', 'editor='. $_GET['editor']. '&textarea='. variable_get('img_assist_textarea', ''));
-      }
-      else {
-        drupal_set_title(t('Submit'));
-        $output .= node_preview($edit);
-      }
+      $output .= img_assist_node_add('image',$op);
+      drupal_goto('img_assist/add', 'editor='. $_GET['editor']. '&textarea='. variable_get('img_assist_textarea', ''));
       break;
-
     default:
       $output .= node_add('image');
   }
@@ -606,11 +675,16 @@
         $has_tid = true;
       }
       $voc = taxonomy_get_vocabulary($vid);
-      $filterbar .= _taxonomy_term_select($voc->name, 'taxonomy', $tid[$i], $vid, '', 0, '<'. t('none') .'>');
+      $form[$voc->name] = _taxonomy_term_select($voc->name, 'taxonomy', $tid[$i], $vid, '', 0, '<'. t('none') .'>');
       $i++;
     }
-    $filterbar .= '</td><td valign="bottom">'. form_submit(t('Go'));
-    $filterbar = form($filterbar). '</td></tr></table>';
+    $form['submit'] = array(
+      '#type' => 'submit',
+      '#prefix' => '</td><td valign="bottom">',
+      '#suffix' => '</td></tr>',
+      '#value' => t('Go')
+    );
+    $filterbar .= drupal_get_form('img_assist_filters', $form). '</table>';
   }
 
   $resize = '<a title="' . t('Smaller thumbnails') . '" href="javascript: resizeImgs(-25);">[-]</a> <a title="' . t('Larger thumbnails') . '" href="javascript: resizeImgs(25);">[+]</a>';
@@ -707,7 +781,15 @@
     $output .= l("<img src=\"".file_create_url($dsp_img->filepath)."\" $dim border=\"1\" />", "img_assist/load/properties/$dsp_img->fid", array('target' => 'img_assist_properties'), NULL, NULL, FALSE, TRUE);
     $output .= "<br />". l($img->title, "node/$dsp_img->nid", array('target' => '_blank')). " ($dsp_img->width x $dsp_img->height)\n";
     if ($image_module_image) {
-      $output .= form(form_select(t('Select a derivative'), 'label', $selected, $options, NULL, 'onchange=parent.img_assist_properties.location.href=this.options[selectedIndex].value'));
+      $form['label'] = array(
+       '#type' => 'select',
+       '#title' => t('Select a derivative'),
+       '#default_value' => $selected,
+       '#options' => $options,
+       '#description' => NULL,
+       '#attributes' => array('onchange' => 'parent.img_assist_properties.location.href=this.options[selectedIndex].value'),
+      );
+      $output .= drupal_get_form('img_assist_load_preview', $form);
     }
 
     /* If the directory view is the one invoking this function  */
@@ -731,7 +813,7 @@
   $img_assist_editor = variable_get('img_assist_editor', '');
 
   $on_submit_hook = $img_assist_editor. '_img_assist_on_submit';
-  $on_click = function_exists($on_submit_hook) ? $on_submit_hook() : 'create_image(this.form);';
+  $on_click = function_exists($on_submit_hook) ? $on_submit_hook() : 'create_image(document.forms[0]);';
 
   if (!$id) {
     $id = arg(3);
@@ -752,69 +834,113 @@
     }
   }
 
-  // This isn't too much of a hack in my opinion as there aren't any security
-  // breeches with this user permission, it's just an advanced option that's
-  // confusing for beginners.
-  $ft_hide = '';
-  if (!user_access('choose format type')) {
-    $ft_hide = 'style="display:none;"';
-  }
-
-  $preview     = form_button(t('Show code'), 'preview', 'button', array('onClick' => 'img_preview(this.form)')). '&nbsp;';
-  $alt         = form_textfield(t('Image description for the visually impaired'), 'alt', $img->title, 55, 255);
-  $dim_txt     = t('Image size in pixels');
-  $width_txt   = t('Width');
-  $width       = form_textfield(null, 'width', $img->width, 3, 5, null, array('onKeyUp' => "resizew(this.form, $img->width, $img->height)"));
-  $height_txt  = t('Height');
-  $height      = form_textfield(null, 'height', $img->height, 3, 5, null, array('onKeyUp' => "resizeh(this.form, $img->width, $img->height)"));
-  $aspect      = form_checkbox(t('Maintain aspect ratio'), 'aspect', 1, 1, null);
-  $caption     = form_textarea(t('Image caption (optional)'), 'caption', $img->caption, 70, 2);
-  $id_field    = form_hidden('fid', $img->fid);
-  $id_field   .= form_hidden('nid', $img->nid);
-  $id_field   .= form_hidden('filepath', file_create_url($img->filepath));
-  $id_field   .= form_hidden('nodePath', url("node/$img->nid"));
-  $id_field   .= form_hidden('origWidth', $img->width);
-  $id_field   .= form_hidden('origHeight', $img->height);
-  $format_type = '<span '. $ft_hide .' class="format-type"><input type="radio" class="form-radio" name="formatType" value="filter" /> '. t('filter');
-  $format_type .= '&nbsp;<input type="radio" class="form-radio" name="formatType" value="html" /> '. t('html'). '</span>';
-  $submit      = $preview . form_button(t('Insert image'), 'op', 'button', array('onClick' => $on_click. 'javascript:top.window.close();')). '&nbsp;';
-  $thumb       = form_group(t('Image to use'), $label);
+  $form['imgtouse'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Image to use'),
+    '#prefix' => '<table width="100%"><tr><td width="50%" style="vertical-align: top;">',
+    '#suffix' => '</td>'
+  );
+  $form['imgtouse']['alt'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Image description for the visually impaired'),
+    '#default_value' => $img->title,
+    '#size' => 55,
+    '#maxlength' => 255,
+  );
+  $form['imgtouse']['caption'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Image caption (optional)'),
+    '#default_value' => $img->caption,
+    '#cols' => 70,
+    '#rows' => 2,
+  );
+  $form['imgsize'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Image size in pixels'),
+    '#prefix' => '<td width="50%" style="vertical-align: top;">',
+    '#suffix' => '</td></tr></table>'
+  );
+    $form['imgsize']['width'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Width'),
+    '#default_value' => $img->width,
+    '#size' => 3,
+    '#maxlength' => 5,
+    '#description' => null,
+    '#attributes' => array('onKeyUp' => "resizew(this.form, $img->width, $img->height)"),
+  );
+  $form['imgsize']['height'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Height'),
+    '#default_value' => $img->height,
+    '#size' => 3,
+    '#maxlength' => 5,
+    '#description' => null,
+    '#attributes' => array('onKeyUp' => "resizeh(this.form, $img->width, $img->height)"),
+  );
+  $form['imgsize']['aspect'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Maintain aspect ratio'),
+    '#return_value' => 1,
+    '#default_value' => 1,
+    '#description' => null,
+  );
+  $form['id_field']['fid'] = array(
+    '#type' => 'hidden',
+    '#value' => $img->fid,
+  );
+  $form['id_field']['nid'] = array(
+    '#type' => 'hidden',
+    '#value' => $img->nid,
+  );
+  $form['id_field']['filepath'] = array(
+    '#type' => 'hidden',
+    '#value' => file_create_url($img->filepath),
+  );
+  $form['id_field']['nodePath'] = array(
+    '#type' => 'hidden',
+    '#value' => url("node/$img->nid",NULL,NULL,TRUE),
+  );
+  $form['id_field']['origWidth'] = array(
+    '#type' => 'hidden',
+    '#value' => $img->width,
+  );
+  $form['id_field']['origHeight'] = array(
+    '#type' => 'hidden',
+    '#value' => $img->height,
+  );
+  if (user_access('choose format type')) {
+    $form['formatType'] = array(
+      '#type' => 'radios',
+      '#title' => t('format type'),
+      '#options' => array('filter' => t('filter'), 'html' => t('html')),
+    );
+  }
+  $form['preview'] = array(
+    '#type' => 'button',
+    '#value' => t('Show code'),
+    '#button_type' => 'button',
+    '#attributes' => array('onClick' => "img_preview(document.forms[0]);")
+  );
+  $form['insert'] = array(
+    '#type' => 'button',
+    '#value' => t('Insert image'),
+    '#weight' => 19,
+    '#attributes' => array('onClick' => $on_click . "javascript:top.window.close();"),
+  );
 
-$output = <<<EOD
-  <table width="100%">
-    <tr><td colspan="2">$alt</td></tr>
+$output = drupal_get_form('img_assist_load_properties', $form);
+$output .= <<<EOD
 
-    <tr valign="top">
-      <td width="50%">
-        $thumb
-      </td>
-      <td width="50%">
-        <fieldset>
-          <legend>$dim_txt</legend>
-          <table cellpadding="3" cellspacing="0">
-            <tr><td align="right">$width_txt</td><td>$width</td></tr>
-            <tr><td align="right">$height_txt</td><td>$height</td></tr>
-            <tr><td>&nbsp;</td><td>$aspect</td></tr>
-          </table>
-        </fieldset>
-      </td>
-    </tr>
-
-    <tr><td colspan="2">$caption</td></tr>
-    <tr>
-      <td colspan="2" align="right"><p>$format_type $id_field $submit</p></td>
-    </tr>
-  </table>
   <script language="JavaScript">
     // Preset the output format type based on parent context.
-    document.forms[0].formatType[1].checked = 1;
+    document.forms[0]['edit[formatType]'][1].checked = 1;
     if (parent.hasInputFormat && parent.editor == '') {
-      document.forms[0].formatType[0].checked = 1;
+      document.forms[0]['edit[formatType]'][0].checked = 1;
     }
   </script>
 EOD;
-
-  return ($id > 0 ? form($output) : t('<p>Once you\'ve clicked on an above image, you can modify its properties in this pane.</p>'));
+return ($id > 0 ? $output : t('<p>Once you\'ve clicked on an above image, you can modify its properties in this pane.</p>'));
 }
 
 /********************************************************************
@@ -1044,4 +1170,147 @@
     return $page_match;
   }
 }
+
+
+/**
+ *
+ */
+
+function img_assist_node_add($type) {
+  global $user;
+
+  $edit = isset($_POST['edit']) ? $_POST['edit'] : '';
+
+  // If a node type has been specified, validate its existence.
+  if (node_access('create', $type)) {
+    // Initialize settings:
+    $node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type);
+
+    $output = img_assist_node_form($node);
+    drupal_set_title(t('Submit %name', array('%name' => node_get_name($node))));
+  }
+  else {
+    $output = t('You are not allowed to create content.');
+  }
+  return $output;
+}
+
+function img_assist_node_form($node) {
+  $op = isset($_POST['op']) ? $_POST['op'] : '';
+
+  $node = array2object($node);
+  node_object_prepare($node);
+
+  // Set the id of the top-level form tag
+  $form['#attributes']['id'] = 'node-form';
+
+  /**
+   * Basic node information.
+   * These elements are just values so they are not even sent to the client.
+   */
+  $form['nid']     = array('#type' => 'value', '#value' => $node->nid);
+  $form['vid']     = array('#type' => 'value', '#value' => $node->vid);
+  $form['uid']     = array('#type' => 'value', '#value' => $node->uid);
+  $form['created'] = array('#type' => 'value', '#value' => $node->created);
+  $form['changed'] = array('#type' => 'value', '#value' => $node->changed);
+  $form['type']    = array('#type' => 'value', '#value' => $node->type);
+  $form['#node']   = $node;
+
+  // Get the node-specific bits.
+  $form = array_merge($form, node_invoke($node, 'form'));
+  if (!isset($form['title']['#weight'])) {
+    $form['title']['#weight'] = -18;
+  }
+  if (!isset($form['body']['#weight'])) {
+    $form['body']['#weight'] = -17;
+  }
+
+  // If this is a new node, fill in the default values.
+  $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
+  if (!isset($node->status)) {
+    $node->status = in_array('status', $node_options);
+  }
+  if (!isset($node->moderate)) {
+    $node->moderate = in_array('moderate', $node_options);
+  }
+  if (!isset($node->promote)) {
+    $node->promote = in_array('promote', $node_options);
+  }
+  if (!isset($node->sticky)) {
+    $node->sticky = in_array('sticky', $node_options);
+  }
+  if (!isset($node->revision)) {
+    $node->revision = in_array('revision', $node_options);
+  }
+
+  if (user_access('administer nodes')) {
+    // Node author information
+    $form['author'] = array('#type' => 'fieldset', '#title' => t('Authoring information'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => -5);
+    $form['author']['name'] = array('#type' => 'textfield', '#title' => t('Authored by'), '#maxlength' => 60, '#autocomplete_path' => 'user/autocomplete', '#required' => TRUE, '#default_value' => $node->name, '#weight' => -1);
+    $form['author']['date'] = array('#type' => 'textfield', '#title' => t('Authored on'), '#maxlength' => 25, '#required' => TRUE, '#default_value' => $node->date);
+
+
+    // Node options for administrators
+    $form['options'] = array('#type' => 'fieldset', '#title' => t('Publishing options'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => -5);
+    $form['options']['status']   = array('#type' => 'checkbox', '#title' => t('Published'), '#default_value' => $node->status);
+    $form['options']['moderate'] = array('#type' => 'checkbox', '#title' => t('In moderation queue'), '#default_value' => $node->moderate);
+    $form['options']['promote']  = array('#type' => 'checkbox', '#title' => t('Promoted to front page'), '#default_value' => $node->promote);
+    $form['options']['sticky']   = array('#type' => 'checkbox', '#title' => t('Sticky at top of lists'), '#default_value' => $node->sticky);
+    $form['options']['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $node->revision);
+  }
+  else {
+    // Don't show node options because the user doesn't have admin access.
+    $form['status']   = array('#type' => 'value', '#value' => $node->status);
+    $form['moderate'] = array('#type' => 'value', '#value' => $node->moderate);
+    $form['promote']  = array('#type' => 'value', '#value' => $node->promote);
+    $form['sticky']   = array('#type' => 'value', '#value' => $node->sticky);
+    $form['revision'] = array('#type' => 'value', '#value' => $node->revision);
+  }
+
+  // Add the buttons.
+  $form['preview'] = array('#type' => 'button', '#value' => t('Preview'), '#weight' => 19);
+
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'), '#weight' => 20);
+  if ($node->nid && node_access('delete', $node)) {
+    $form['delete'] = array('#type' => 'button', '#value' => t('Delete'), '#weight' => 21);
+  }
+
+  if ($op == t('Preview')) {
+    $form['#after_build'] = 'node_form_add_preview';
+  }
+
+  return drupal_get_form($node->type . '_node_form', $form, 'img_assist_node_form');
+}
+
+function img_assist_node_form_validate($form_id, $edit) {
+  node_validate($edit);
+}
+
+function img_assist_node_form_submit($form_id, $edit) {
+  global $user;
+
+  // Fix up the node when required:
+  $node = node_submit($edit);
+
+  // Prepare the node's body:
+  if ($node->nid) {
+    // Check whether the current user has the proper access rights to
+    // perform this operation:
+    if (node_access('update', $node)) {
+      node_save($node);
+      watchdog('content', t('%type: updated %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
+      $msg = t('The %post was updated.', array ('%post' => node_get_name($node)));
+    }
+  }
+  else {
+    // Check whether the current user has the proper access rights to
+    // perform this operation:
+    if (node_access('create', $node)) {
+      node_save($node);
+      watchdog('content', t('%type: added %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
+      $msg = t('Your %post was created.', array ('%post' => node_get_name($node)));
+    }
+  }
+}
+
 ?>
