What do you think about views integration of filed themed attachment with imagacache, that way we could display images in different formats, now it is all binded to default value set in configuration of this module?

Comments

vsalvans’s picture

Hi deepM

I've did this development on fbsmp module. I apologize to fbsmp developers because this is not the normal way to suggest a code change. Ask me any question or resource you need to adde this piece of code to the module if it's convinient.

Well, I changed the "fbsmp_views_handler_themed_attachment.inc" code to this

<?php

/**
 * @file
 *   Formats FBSMP attachment in Views.
 */

/**
 * Field handler to provide the themed attachment for FBSS status.
 */
class fbsmp_views_handler_field_themed_attachment extends views_handler_field {
  
  function init(&$view, $options) {
    parent::init($view, $options);
    $this->additional_fields['sid'] = array('table' => 'fbsmp', 'field' => 'sid');
    $this->additional_fields['type'] = array('table' => 'fbsmp', 'field' => 'type');
    $this->additional_fields['data'] = array('table' => 'fbsmp', 'field' => 'data');
  }
  
  function query() {
    $this->add_additional_fields();
  }
  
  function render($values) {
  
  	//dsm($this->options);
  
    $attachment = new stdClass();
    $attachment->sid = $values->{$this->aliases['sid']};
    $attachment->type = $values->{$this->aliases['type']};
    $attachment->data = unserialize($values->{$this->aliases['data']});
    $attachment->options['views'] = $this->options;
    $themed_attachment = fbsmp_render_attachment($attachment);
    if ($themed_attachment) {
      return '<div class="fbsmp clearfix fbss_attachment">'. $themed_attachment . '</div>'; // The fbss_attachment class is for backwards compatibility
    }
    return '';
  }
  
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    
    if (module_exists('imagecache')) {
    
    	$presets = imagecache_presets();
    	
    	$options = array();

    	foreach($presets as $preset) {
    		$options[$preset['presetname']] = $preset['presetname'];  
    	}
    
	    $form['imagecache_preset'] = array(
	      '#title' => t('ImageCache preset'),
	      '#type' => 'select',
	      '#options' => $options,
	    );    
    }

  }
  
}

and I changed the "photo.inc" code to this ... I put only the function changed :

/**
 * Implementation of hook_fbsmp_themed_attachment().
 */
function fbsmp_photo_fbsmp_themed_attachment($attachment) {
  $settings = fbsmp_load_plugin_settings('photo');
  if ($settings['imagecache_preset'] && module_exists('imagecache')) {
    if (isset($settings['class']) && $settings['class']) {
      $attributes = array('class' => $settings['class']);
    }
    list($presetname, $style) = split(':', $settings['imagecache_preset']);
    
    //dsm($attachment->views_options);
    
    if($attachment->options['views']['imagecache_preset']) $presetname = $attachment->options['views']['imagecache_preset'];
    
    return theme('fbsmp_photo_attachment_imagecache', $presetname, $style, $attachment, $settings['alt'], '', $attributes);
  }  
  return theme('fbsmp_photo_attachment_default', $attachment, $settings);
}

I can't attach any patch or file as I did other "dirty" changes for the project I working on.

hope it helps!

icecreamyou’s picture

Status: Active » Needs work

What do you think about views integration of filed themed attachment with imagacache, that way we could display images in different formats, now it is all binded to default value set in configuration of this module?

I think this is a good idea.

I apologize to fbsmp developers because this is not the normal way to suggest a code change. Ask me any question or resource you need to adde this piece of code to the module if it's convinient.

The most convenient thing would be if you could follow the git instructions and make a patch. That way the maintainers can just apply and commit, or at least easily review the patch; otherwise this will have to wait for one of the maintainers to go decipher your changes manually, which I don't have time to do at the moment.