You are here

function flashnode_display in Flash Node 5.3

Same name and namespace in other branches
  1. 5.2 flashnode.module \flashnode_display()

Create the HTML for insertion of Flash using SWFTools to do the work

This function is called by flashnode_display and flashnode_content.

Parameters

$file: A correctly structured array that defines an item of flash content. Must include keys _flashnode (path to the file), width, height, substitution (string containing HTML mark up for the substitution content), and optionally flashvars. Other keys may be included and they will be passed through to SWFTools.

Return value

An HTML string for rendering the flash content

File

./flashnode.module, line 543

Code

function flashnode_display($file, $options = NULL) {

  // Modify height and width to comply with limits, if required
  $max_width = variable_get('flashnode_max_width', 0);
  $max_height = variable_get('flashnode_max_height', 0);

  // Check width first
  if ($max_width) {
    if ($file['width'] > $max_width) {
      $scale = $max_width / $file['width'];
      $file['width'] = $file['width'] * $scale;
      $file['height'] = $file['height'] * $scale;
    }
  }

  // Then check height
  if ($max_height) {
    if ($file['height'] > $max_height) {
      $scale = $max_height / $file['height'];
      $file['width'] = $file['width'] * $scale;
      $file['height'] = $file['height'] * $scale;
    }
  }

  // Add width, height and base to $params for SWFTools, rounding width and height to integers
  $params = array(
    'width' => round($file['width']),
    'height' => round($file['height']),
    'base' => $file['base'],
  );

  // Retrieve default substitution content if required
  // Note we are bypassing the filters here, so we assume the administrator
  // created valid mark-up that everyone else can use!
  $preview = t($file['substitution'], array(
    '!default' => variable_get('flashnode_default_html_alt', 'You are missing some Flash content that should appear here! Perhaps your browser cannot display it, or maybe it did not initialise correctly.'),
  ));

  // Construct filepath

  //$filepath = base_path().file_create_path($file['_flashnode']);
  $filepath = $file['_flashnode'];

  // Call swf to generate output

  //function swf($filepath, $html_alt = SWFDEFAULT, $params = SWFDEFAULT, $flashvars = SWFDEFAULT, $othervars = SWFDEFAULT, $method = SWFDEFAULT, $debug = FALSE)
  $output .= swf($filepath, $params, $file['flashvars'], array(
    'html_alt' => $preview,
  ), SWFDEFAULT, 0);

  // Return the HTML
  return $output;
}