? patch Index: contrib/image_attach/image_attach.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/image/contrib/image_attach/image_attach.install,v retrieving revision 1.12 diff -u -p -r1.12 image_attach.install --- contrib/image_attach/image_attach.install 6 Jan 2008 22:15:24 -0000 1.12 +++ contrib/image_attach/image_attach.install 6 Aug 2008 20:48:30 -0000 @@ -21,6 +21,7 @@ function image_attach_schema() { 'default' => 0, ), ), + 'primary key' => array('nid', 'iid') ); return $schema; } Index: contrib/image_attach/image_attach.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/image/contrib/image_attach/image_attach.module,v retrieving revision 1.40 diff -u -p -r1.40 image_attach.module --- contrib/image_attach/image_attach.module 16 Jun 2008 18:44:37 -0000 1.40 +++ contrib/image_attach/image_attach.module 6 Aug 2008 20:48:30 -0000 @@ -188,12 +188,14 @@ function image_attach_form_alter(&$form, $form['#validate'][] = 'image_attach_validate'; if (!empty($node->iid)) { - $image = node_load($node->iid); - $form['image_attach']['image_thumbnail'] = array( - '#type' => 'item', - '#title' => t('Thumbnail'), - '#value' => image_display($image, 'thumbnail') - ); + foreach ($node->iid as $iid) { + $image = node_load($iid); + $form['image_attach']['image_thumbnail'][] = array( + '#type' => 'item', + '#title' => t('Thumbnail'), + '#value' => image_display($image, 'thumbnail') + ); + } } if (variable_get('image_attach_existing', 1) && user_access('access content')) { $form['image_attach']['iid'] = array( @@ -201,7 +203,9 @@ function image_attach_form_alter(&$form, '#title' => t('Existing Image'), '#options' => _image_attach_get_image_nodes(), $value => empty($node->iid) ? NULL : $node->iid, - '#description' => t('Choose an image already existing on the server if you do not upload a new one.') + '#description' => t('Choose an image already existing on the server if you do not upload a new one.'), + '#multiple' => TRUE, + '#size' => 6 ); $form['image_attach'][] = array( '#type' => 'item', @@ -210,10 +214,12 @@ function image_attach_form_alter(&$form, ); } else { - $form['image_attach']['iid'] = array( - '#type' => 'hidden', - $value => empty($node->iid) ? NULL : $node->iid, - ); + foreach ($node->iid as $iid) { + $form['image_attach']['iid'][] = array( + '#type' => 'hidden', + $value => empty($iid) ? NULL : $iid, + ); + } } $form['image_attach']['image'] = array( '#type' => 'file', @@ -270,8 +276,11 @@ function image_attach_nodeapi(&$node, $o case 'update': if (isset($node->iid)) { db_query("DELETE FROM {image_attach} WHERE nid=%d", $node->nid); - if ($node->iid > 0) { - db_query("INSERT INTO {image_attach} (nid, iid) VALUES (%d, %d)", $node->nid, $node->iid); + if (count($node->iid)) { + $node->iid = is_array($node->iid) ? $node->iid : array($node->iid); + foreach ($node->iid as $iid) { + db_query("INSERT INTO {image_attach} (nid, iid) VALUES (%d, %d)", $node->nid, $iid); + } } } break; @@ -281,12 +290,16 @@ function image_attach_nodeapi(&$node, $o break; case 'load': - $iid = db_result(db_query("SELECT iid FROM {image_attach} WHERE nid=%d", $node->nid)); - return array('iid' => $iid); + $res = (db_query("SELECT iid FROM {image_attach} WHERE nid=%d", $node->nid)); + $iids = array(); + while($iid = db_fetch_array($res) ){ + $iids[] = $iid['iid']; + } + return array('iid' => $iids); // Pass the body and teaser objects to the theme again to add the images case 'view': - if ($node->iid) { + if (count($node->iid)) { $teaser_or_body = $teaser ? 'teaser' : 'body'; $node->content['image_attach'] = array( '#value' => theme("image_attach_{$teaser_or_body}", $node), @@ -297,12 +310,12 @@ function image_attach_nodeapi(&$node, $o case 'rss item': $ret = array(); - if ($node->iid && $image = node_load($node->iid)) { + if (count($node->iid) && $image = node_load($node->iid)) { $info = image_get_info(file_create_path($image->images[IMAGE_PREVIEW])); $ret[] = array( 'key' => 'enclosure', 'attributes' => array( - 'url' => url("image/view/{$node->iid}/". IMAGE_PREVIEW, array('absolute' => TRUE)), + 'url' => url("image/view/{$node->iid[0]}/". IMAGE_PREVIEW, array('absolute' => TRUE)), 'length' => $info['file_size'], 'type' => $info['mime_type'], ) @@ -346,47 +359,49 @@ function image_attach_theme() { * If you have additional image sizes you defined in image.module, you can use them by theming this function as well. */ function theme_image_attach_teaser($node) { + $output = ''; $img_size = variable_get('image_attach_size_teaser_'. $node->type, 'thumbnail'); if ($img_size != IMAGE_ATTACH_HIDDEN) { drupal_add_css(drupal_get_path('module', 'image_attach') .'/image_attach.css'); - - $image = node_load($node->iid); + + $image = node_load($node->iid[0]); if (!node_access('view', $image)) { // If the image is restricted, don't show it as an attachment. - return NULL; + return $output; } $info = image_get_info(file_create_path($image->images[$img_size])); - $output = '
'; - $output .= l(image_display($image, $img_size), "node/$node->nid", array('html' => TRUE)); + $output .= '
'; + $output .= l(image_display($image, $img_size), "node/$node->iid[0]", array('html' => TRUE)); $output .= '
'."\n"; - - return $output; } + return $output; } /** * Theme the body */ function theme_image_attach_body($node) { + $output = ''; $img_size = variable_get('image_attach_size_body_'. $node->type, IMAGE_THUMBNAIL); if ($img_size != IMAGE_ATTACH_HIDDEN) { drupal_add_css(drupal_get_path('module', 'image_attach') .'/image_attach.css'); - $image = node_load($node->iid); - if (!node_access('view', $image)) { - // If the image is restricted, don't show it as an attachment. - return NULL; + foreach ($node->iid as $iid) { + $image = node_load($iid); + if (!node_access('view', $image)) { + // If the image is restricted, don't show it as an attachment. + continue; + } + $info = image_get_info(file_create_path($image->images[$img_size])); + + $output .= '
'; + $output .= l(image_display($image, $img_size), "node/$iid", array('html' => TRUE)); + $output .= '
'."\n"; } - $info = image_get_info(file_create_path($image->images[$img_size])); - - $output = '
'; - $output .= l(image_display($image, $img_size), "node/$node->iid", array('html' => TRUE)); - $output .= '
'."\n"; - - return $output; } + return $output; }