You are here

function theme_swftools_formatter_swftools in SWF Tools 6.3

Same name and namespace in other branches
  1. 6.2 swftools.module \theme_swftools_formatter_swftools()

Themes a CCK element in to flash content.

Parameters

array $element: The CCK element to render.

Return value

string A string of markup to produce the flash content, or nothing if the element was empty.

Related topics

1 string reference to 'theme_swftools_formatter_swftools'
swftools_theme in ./swftools.module
Implementation of hook_theme().

File

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

Code

function theme_swftools_formatter_swftools($element, $profile = array()) {

  // If the element is empty return
  if (empty($element['#item']['fid']) && empty($element['#item']['value']) && empty($element['#item']['url'])) {
    return '';
  }

  // See if a thumbnail image has been stored with this content
  $image = theme_swftools_formatter_thumbnail('', TRUE, $element['#item']['#delta']);

  // If an image was stored then set the thumbnail
  if ($image) {
    $data['othervars']['image'] = $image;
  }
  else {
    $data = array();
  }

  // Assign the profile
  $data['othervars']['profile'] = $profile ? $profile['profile'] : '';

  // See if we're processing a filefield and get the path and description
  if (isset($element['#item']['filepath'])) {
    $swf = $element['#item']['filepath'];
    $data['othervars']['title'] = $element['#item']['data']['description'];
    $source = 'filefield';
  }
  elseif (isset($element['#item']['url'])) {
    $swf = $element['#item']['url'];
    $data['othervars']['title'] = $element['#item']['title'];
    $source = 'link';

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

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

    // We need to run $swf through check_url to make sure it is safe, but rtmp isn't in the allowed protocols
    // This is configurable (see filter.module line 1182) but not sure if the variable is exposed
    // $swf = check_url($swf);
    // See if we have been given a stream by trying to explode the string
    $stream = explode(' ', $swf);

    // If the explode return 2 elements assume we have a stream, element[0] contains the source, element[1] the file
    if (count($stream) == 2) {
      $data['othervars']['stream'] = $stream[0];
      $swf = $stream[1];
    }
  }

  // Pass element to the swf tools processor by attaching it in othervars
  $data['othervars']['cck'] = $element;

  // Get the markup for the flash content from swf()
  $return = swf($swf, $data);

  // Add the download link if required (we are either using swftools formatter, or a profile with this option enabled)
  if ($element['#formatter'] == 'swftools' || !empty($profile['download_link'])) {
    switch ($source) {
      case 'filefield':
        $return .= "\n" . theme('filefield_formatter_default', $element);
        break;
      case 'link':
        $return .= "\n" . theme('link_formatter_default', $element);
        break;
    }
  }

  // Return the resulting markup
  return $return;
}