Hey,

I've installed imagefield_extended module to allow imagefield descriptions to have custom-formatted description text, showing html links, etc. I have hacked the module to show that field instead of the standard imagefield 'description,' limited to plain text only and 120 characters or less. Lame!
However, although its showing the description, it seems to be stripping HTML markup from the theme(), and I need to find a way to have HTML characters show.

Is there any way to have $caption keep HTML markup when passed through the theme function on line 311?

if ($imagecache_exists && $thumb_preset) {
      $thumb = theme('imagecache', $thumb_preset, $filepath, $alt_text, $caption);
    }

NOTE: I'm aware I should put this in my theme instead of hacking the .module. This will be done. I'm just making it work here first.

Please let me know. Thanks!

Here is the hacked function: Line 269-334:

/**
 * Implementation of template_preprocess_hook().
 *
 * Build a Galleria from an array of images. This is called in both cases
 * (i.e. building Galleria from CCK imagefield or from attached files).
 *
 * @param $images
 *   An array of file objects representing the images to be included in the Galleria
 * @return $vars
 *   Themed Galleria.
 */
function template_preprocess_galleria(&$vars) {
  $images = $vars['images'];
  $image_list = array();
  $i = 0;
  $imagecache_exists = module_exists('imagecache');
  $img_preset = variable_get('galleria_imagecache_preset', '');
  $thumb_preset = variable_get('galleria_thumb_imagecache_preset', '');
  $lightbox_integration = variable_get('galleria_lightbox', 'none');
  $lightbox_preset = variable_get('galleria_lightbox_preset', '');
  $nid = $vars['id'];
  $node = node_load($nid);
  foreach ($images as $image) {
 //HACKED - use $node->field_siteimage instead of $image->description.
 //HACKED - use $i as the count of the $node->field_siteimage array, to show description per image while in foreach() loop.
    $caption = ($image->description != $image->filename) ? $node->field_siteimage[$i]['data']['field_siteimage']['body'] : '';
    $filepath = $image->filepath;
    
    // We have the main image opening in a lightbox.
    if ($lightbox_integration != 'none') {
      // User has selected an Imagecache preset to resize the lightbox image.
      if ($lightbox_preset && $imagecache_exists) {
        $alt_text = imagecache_create_url($lightbox_preset, $filepath);
      }
      else {
        $alt_text = url($filepath, array('absolute' => TRUE));
      }
    }
    else {
      $alt_text = $image->alt;
    }

    if ($imagecache_exists && $thumb_preset) {
      $thumb = theme('imagecache', $thumb_preset, $filepath, $alt_text, $caption);
    }

    if ($imagecache_exists && $img_preset) {
      if ($thumb) {
        // There is an imagecache preset for both thumbnail and gallery image.
        $image = l($thumb, imagecache_create_url($img_preset, $filepath), array('html' => TRUE, 'attributes' => array('title' => $caption)));
      }
      else {
        // There is an imagecache preset for only the gallery image.
        $image = theme('imagecache', $img_preset, $filepath, $alt_text, $caption);
      }
    }
    else {
      if ($thumb) {
        // There is an imagecache preset for only the thumbnail image.
        $image = l($thumb, $filepath, array('html' => TRUE, 'attributes' => array('title' => $caption)));
      }
      else {
        // No imagecache presets selected.
        $image = theme('image', $filepath, $alt_text, $caption);
      }
    }

    $image_list[] = array(
      'data' => $image,
      'class' => ($i == 0) ? 'active' : '',
    );

    $i++;
  }

  $attribs = array(
    'class' => 'gallery clear-block',
  );

  $vars['thumbnails'] = theme('item_list', $image_list, NULL, 'ul', $attribs);
  $vars['image_count'] = $i;
  $vars['prev'] = t('previous');
  $vars['next'] = t('next');

  // jCarousel integration setup
  if (module_exists('jcarousel') && variable_get('galleria_jcarousel', 'enabled') == 'enabled' && $i > 1) {
    $options = array(
      'vertical' => (variable_get('galleria_jcarousel_vertical', 'false') == 'true') ? TRUE : FALSE,
      'visible' => variable_get('galleria_jcarousel_visible', '3'),
      'scroll' => variable_get('galleria_jcarousel_scroll', '3'),
      'animation' => variable_get('galleria_jcarousel_animation', 'fast'),
      'wrap' => variable_get('galleria_jcarousel_wrap', 'null'),
      'initCallback' => 'Drupal.galleria.jcarousel_initCallback',
    );
    jcarousel_add('.gallery', $options);
  }
}

Comments

mmgg’s picture

on the imagefield extended project page... it suggests recommended ways to handle textfields from imagefield extended

http://drupal.org/project/imagefield_extended

maybe this is the code you need?

Text field with tags (HTML)

<?php
# You can use filter_xss_admin for TRUSTED users.
$free_text = isset($data['free_text']['body']) ? filter_xss($data['free_text']['body']) : NULL;
?>
BawlmerMag’s picture

I'd like to be able to do this as well

corona ronin: Can you confirm that your function above is actually working for you? I've tried your code in version 6.x-1.0 in both the galleria.module and in my theme's template.php (replacing $node->field_siteimage with my own, obvs.) and can't get it to work.

rc2020’s picture

@BMag,

I never successfully got HTML in this field. I managed to integrate imagefield_extended, but there is no HTML in the field. I just gave up.

Good luck - post back if you find a solution!

Thanks...

forbesconrad’s picture

Here's my solution for HTML Galleria captions:

In jquery.galleria.js go to line 311 and change .text to .html.

This is what you're looking for:
// insert the caption
_wrapper.siblings('.caption').text(_thumb.attr('title'));

I also added the following to settings.php:

$conf['filefield_description_length'] = 1024;
$conf['filefield_description_type'] = 'textarea';

Just to be clear, I'm using the imagefield Galleria method.

dwadson’s picture

I had issues with using this line:

$nid = $vars['id']

"id" did not have the proper nid and as a result would not load the image caption. Instead, I used:

  if (arg(0)=='node' && is_numeric(arg(1)))
    {
      $nid = arg(1);
    }
drupalusering’s picture

Line 311 text to html worked. Thank you very much! i used _top attribute to resolve the url appendage issue.