I added this code to the image_attach module to optional display images in bodies.

new theme_image_attach_body($node) modified:

function theme_image_attach_body($node){

  if (variable_get('image_attach_body', 1)){
    drupal_add_css(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 .= '<div style="width: '. $info['width'] .'px" class="image-attach-body">';
    $output .= l(image_display($image, 'thumbnail'), "node/$node->nid", array(), NULL, NULL, FALSE, TRUE);
    $output .= '</div>'."\n";
  }
  return $output;
}

new image_attach_admin_settings() modified

function image_attach_admin_settings() {
  $form = array();
  
  $form['image_attach_existing'] = array(
    '#type' => 'radios',
    '#title' => t('Attach existing images'),
    '#default_value' => variable_get('image_attach_existing', 1),
    '#options' => array(0 => 'Disabled', 1 => 'Enabled'),
    '#description' => t('When enabled, will allow existing image nodes to be attached instead of uploading new images.')
  );
  $form['image_attach_body'] = array(
    '#type' => 'radios',
    '#title' => t('Attach existing images on body'),
    '#default_value' => variable_get('image_attach_body', 1),
    '#options' => array(0 => 'Disabled', 1 => 'Enabled'),
    '#description' => t('When enabled, will show the attached image to body.')
  );
  
  return system_settings_form($form);
}

sorry also for my horrible english.

Comments

drewish’s picture

Status: Needs review » Needs work

you english is fine, though you didn't submit a proper patch. see http://drupal.org/patch for more information. not submitting your changes as a patch makes it hard to tell what you're doing. by the look of it, i wonder if this patch is covered by: http://drupal.org/node/73854

psicomante’s picture

i will submit a patch, but that issue you linked to make the weight image configurable per node. It isn't a global configuration for ALL images.

Do you think that will be committed? Is it very useful.

drewish’s picture

submitting a patch makes it easier for me to understand what's going on with your changes. it probably won't be committed unless other people express an interest because i can't see the purpose. you could do the same thing by overriding the theme function.

psicomante’s picture

How can i ovverride the theme function? What should i add to the template.php?

psicomante’s picture

StatusFileSize
new3.27 KB

i've made a little patch. I'm not sure if it is stable to use the <none> string :)

drewish’s picture

Status: Needs work » Fixed

that other patch got committed so i think this is fixed.

drewish’s picture

Title: Optional display image attached in bodies » Make size of attached images configurable
Status: Fixed » Needs work

oh, i misunderstood the purpose of the patch.

you shouldn't be using a textfield, use a select. call _image_get_sizes() to get a list of the sizes to put into the drop down.

drewish’s picture

also, you've got tabs in that patch, replace them with spaces.

psicomante’s picture

Thanks drewish, i will modify the patch soon. Sorry for these errors.

psicomante’s picture

StatusFileSize
new5.36 KB

This patch couldn't be useful for all people. It creates two new variables for every node you enable image_attach. You could get a bit slower site if you have a lot of content types.

I'm thinking about a good uninstall function for all these variables stuff :)

drewish’s picture

looking much better. there's still some issues with inconsistent indenting. also since _image_attach_get_size_label() is only called from one place, don't bother making it a function at this point. just move that code back into the form.

a hook_uninstall wouldn't be a bad idea.

psicomante’s picture

StatusFileSize
new5.08 KB

Thanks for the guidelines. I have so much to learn :)

For the uninstall hook i don't know how implement "deleting variables for all nodes". I think the better solution is using regexp, but i'm not so sure.

Here is the last patch. I hope this is correct.

drewish’s picture

Status: Needs work » Needs review
StatusFileSize
new5.68 KB

okay, made some small changes to your patch but i really like it. i think it'll make a lot of people happy.

drewish’s picture

Status: Needs review » Fixed

okay, since the odds are, no one will review this i'll just commit it and wait for bug reports.

thanks for all your hard work on this Psicomante.

psicomante’s picture

Thanks drewish. It would be great add uninstall info to the module. If a user has a lot of node types, drupal will crate a lot of records in variables table. So that would be erased if you want to uninstall the module.

Sorry for my ugly and uglier english :P and Thanks to have committed the patch!

drewish’s picture

Psicomante, it's true, there are a lot of left over variables but that's an issue for a separate patch. feel free to open it ;)

Anonymous’s picture

Status: Fixed » Closed (fixed)