You are here

function theme_swftools_formatter_thumbnail in SWF Tools 6.3

Theme function to store and retrieve thumbnail images.

If called as a regular theme function it stores the path of the image, but if the retrieve flag is set it returns that path.

In effect this function is a local store to hold the most recently "seen" image on behalf of the swf themer. In order for this code to work the thumbnail theme function must come before the swf theme function, so it is necessary to order the fields appropriately on the content configuration page.

When caching thumbnails then if the element delta is zero the cache is flushed first to start a new collection of images.

Parameters

array $element: The CCK element to store.

bool $retrieve: When TRUE will return the currently stored path.

int $delta: If set then attempt to retrieve just the image at the specified delta, otherwise return the whole array of stored thumbnails.

Return value

mixed A string, or an array, holding the thumbnail filepaths.

Related topics

2 calls to theme_swftools_formatter_thumbnail()
theme_swftools_formatter_playlist in includes/swftools.theme.inc
Themes multiple value CCK content in to a playlist.
theme_swftools_formatter_swftools in includes/swftools.theme.inc
Themes a CCK element in to flash content.
1 string reference to 'theme_swftools_formatter_thumbnail'
swftools_theme in ./swftools.module
Implementation of hook_theme().

File

includes/swftools.theme.inc, line 229
Implements SWF Tools theme functions.

Code

function theme_swftools_formatter_thumbnail($element, $retrieve = FALSE, $delta = NULL) {

  // Create a static variable to hold the image path
  static $image_path = array();

  // It retrieving a previous thumbnail then return its path and reset the stored value
  // We may want to retrieve all cached thumbnails ($delta = NULL), or a specific thumbnail
  // in which case $delta is the one we want
  if ($retrieve) {
    if ($delta !== NULL) {
      if (isset($image_path[$delta])) {
        return $image_path[$delta];
      }
      else {
        return '';
      }
    }
    else {
      return $image_path ? $image_path : '';
    }
  }

  // If the delta is zero we are starting a new collection so reset in case
  // a retrieval call wasn't made by the theme function
  if ($element['#item']['#delta'] == 0) {
    $image_path = array();
  }

  // If the element is empty set the stored path to an empty string
  if (empty($element['#item']['fid']) && empty($element['#item']['value']) && empty($element['#item']['url'])) {
    $image_path[] = '';
    return;
  }

  // Initialise an empty string
  $image_url = '';

  // See if we're processing a filefield and get the appropriate value
  if (isset($element['#item']['filepath'])) {
    $image_url = $element['#item']['filepath'];
  }
  elseif (isset($element['#item']['url'])) {
    $image_url = $element['#item']['url'];

    // add the query to the base url, if necessary
    if (isset($element['#item']['query']) && strlen($element['#item']['query']) > 0) {
      $image_url .= '?' . $element['#item']['query'];
    }

    // add the fragment to the url, if necessary
    if (isset($element['#item']['fragment']) && strlen($element['#item']['fragment']) > 0) {
      $image_url .= '#' . $element['#item']['fragment'];
    }
  }
  else {
    $image_url = $element['#item']['value'];

    // Check this is a valid url
    $image_url = check_url($image_path);
  }

  // Store the result
  $image_path[] = $image_url;

  // Return nothing at this point
  return;
}