diff -u image_attach/image_attach.install image_attach_new/image_attach.install --- image_attach/image_attach.install 2006-05-03 16:04:25.000000000 -0400 +++ image_attach_new/image_attach.install 2006-08-26 13:47:14.000000000 -0400 @@ -7,6 +7,15 @@ } } +function image_attach_update_1() { + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql('ALTER TABLE {image_attach} DROP PRIMARY KEY'); + } + return $ret; +} + function image_attach_install() { switch ($GLOBALS['db_type']) { case 'mysqli': @@ -21,4 +30,4 @@ break; } -} \ No newline at end of file +} diff -u image_attach/image_attach.module image_attach_new/image_attach.module --- image_attach/image_attach.module 2006-08-26 12:27:10.000000000 -0400 +++ image_attach_new/image_attach.module 2006-08-28 09:38:27.000000000 -0400 @@ -37,7 +37,7 @@ '#title' => t('Attach Images'), '#default_value' => $enabled, '#options' => array(0 => t('Disabled'), 1 => t('Enabled')), - '#description' => t('Should this node allows users to upload an image?'), + '#description' => t('Should this node allow users to upload an image?'), ); } else { drupal_set_message(t('The image module is not installed. The image_attach module will not function without it.'), 'error'); @@ -52,12 +52,14 @@ $form['#attributes'] = array("enctype" => "multipart/form-data"); $form['image_attach'] = array('#type' => 'fieldset', '#title' => t('Attached Images'), '#collapsible' => TRUE); - if ($node->iid) { - $image = node_load($node->iid); - $form['image_attach']['image_thumbnail'] = array('#type' => 'item', '#title' => t('Thumbnail'), '#value' => image_display($image, 'thumbnail')); + if (!empty($node->images)) { + foreach ($node->images as $iid) { + $image = node_load($iid); + $form['image_attach']['image_thumbnail'][] = array('#type' => 'item', '#title' => t('Thumbnail'), '#value' => image_display($image, 'thumbnail')); + } } - $value = ($node->new_image) ? '#value' : '#default_value'; - $form['image_attach']['iid'] = array('#type' => 'hidden' , $value => $node->iid); +// $value = ($node->new_image) ? '#value' : '#default_value'; + $form['image_attach']['images'] = array('#type' => 'value' , '#value' => $node->images); $form['image_attach']['image'] = array('#type' => 'file', '#title' => t('Image')); $form['image_attach']['image_title'] = array('#type' => 'textfield', '#title' => t('Image title'), '#default_value' => ''); } @@ -85,31 +87,37 @@ if (!form_get_errors()) { $image = node_submit($image); node_save($image); - $node->iid = $image->nid; - $node->new_image = TRUE; + $node->images[] = $image->nid; + $node->new_image = TRUE; // NOTE: not needed anymore? } } - elseif ($_POST['edit']['iid']) { - $node->iid = $_POST['edit']['iid']; + elseif ($_POST['edit']['images']) { + $node->images = $_POST['edit']['images']; } break; case 'insert': case 'update': - if ($node->iid) { + if (!empty($node->images)) { db_query("DELETE FROM {image_attach} WHERE nid=%d", $node->nid); - db_query("INSERT INTO {image_attach} (nid, iid) VALUES (%d, %d)", $node->nid, $node->iid); + foreach ($node->images as $iid) { + db_query("INSERT INTO {image_attach} (nid, iid) VALUES (%d, %d)", $node->nid, $iid); + } } break; case 'delete': db_query("DELETE FROM {image_attach} WHERE nid=%d", $node->nid); break; case 'load': - $iid = db_result(db_query("SELECT iid FROM {image_attach} WHERE nid=%d", $node->nid)); - return array('iid' => $iid); + $images = array(); + $results = db_query("SELECT iid FROM {image_attach} WHERE nid=%d", $node->nid); + while ($image = db_fetch_object($results)) { + $images[] = $image->iid; + } + return array('images' => $images); // Pass the body and teaser objects to the theme again to add the images case 'view': - if($node->iid && function_exists('image_display')){ + if(!empty($node->images) && function_exists('image_display')){ $node->body = theme('image_attach_body', $node); if ($teaser){ $node->teaser = theme('image_attach_teaser', $node); @@ -127,13 +135,14 @@ function theme_image_attach_teaser($node){ theme_add_style(drupal_get_path('module', 'image_attach') .'/image_attach.css'); - $image = node_load($node->iid); - - $info = image_get_info(file_create_path($image->images['thumbnail'])); - $output = ''; - $output .= '
'; - $output .= l(image_display($image, 'thumbnail'), "node/$node->nid", array(), NULL, NULL, FALSE, TRUE); - $output .= '
'."\n"; + foreach($node->images as $iid) { + $image = node_load($iid); + + $info = image_get_info(file_create_path($image->images['thumbnail'])); + $output .= '
'; + $output .= l(image_display($image, 'thumbnail'), "node/$node->nid", array(), NULL, NULL, FALSE, TRUE); + $output .= '
'."\n"; + } $output .= $node->teaser; return $output; } @@ -144,13 +153,14 @@ function theme_image_attach_body($node){ theme_add_style(drupal_get_path('module', 'image_attach') .'/image_attach.css'); - $image = node_load($node->iid); + foreach($node->images as $iid) { + $image = node_load($iid); - $info = image_get_info(file_create_path($image->images['thumbnail'])); - $output = ''; - $output .= '
'; - $output .= l(image_display($image, 'thumbnail'), "node/$node->nid", array(), NULL, NULL, FALSE, TRUE); - $output .= '
'."\n"; + $info = image_get_info(file_create_path($image->images['thumbnail'])); + $output .= '
'; + $output .= l(image_display($image, 'thumbnail'), "node/$node->nid", array(), NULL, NULL, FALSE, TRUE); + $output .= '
'."\n"; + } $output .= $node->body; return $output; } diff -u image_attach/TODO.txt image_attach_new/TODO.txt --- image_attach/TODO.txt 2006-05-03 16:04:25.000000000 -0400 +++ image_attach_new/TODO.txt 2006-08-28 09:38:56.000000000 -0400 @@ -1,3 +1,7 @@ -* support multiple images +* allow multiple images to be submitted on a single form. (Multiple form elements? Ajax?) +* limit number of images allowed per node type +* allow weighting of order for display of images +* allow user to delete associations (will this also delete the image?) + * allow selection of derivative to use (though this can be overriden by the theme) * allow for using already uploaded images?