You are here

function theme_flashnode_markup in Flash Node 5.3

Same name and namespace in other branches
  1. 5.6 flashnode.module \theme_flashnode_markup()
  2. 6.3 flashnode.module \theme_flashnode_markup()
  3. 6.2 flashnode.module \theme_flashnode_markup()

Generate fallback HTML if the SWF Tools module is not available

Flash node uses SWF Tools to handle JavaScript replacement but this isn't always easy to set up. To assist users Flash node will fall back to direct HTML embedding if it can't find SWF Tools. This means Flash node will work 'out of the box' in a basic fashion, and is extended when SWF Tools is available rather than being entirely dependent upon it.

This function is called with an array of parameters that define a flashnode. See the description theme_flashnode for details.

1 theme call to theme_flashnode_markup()
theme_flashnode in ./flashnode.module
Create the HTML for insertion of Flash using SWFTools to do the work if available

File

./flashnode.module, line 1142

Code

function theme_flashnode_markup($flashnode, $options = array()) {

  // Generate HTML markup, using SWFTools if available, fallback if not
  if (function_exists('swf')) {

    // Add width, height and base to $params for SWFTools, rounding width and height to integers
    $params = array(
      'width' => round($flashnode['width']),
      'height' => round($flashnode['height']),
      'base' => $flashnode['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($flashnode['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.'),
    ));
    $options = array_merge($options, array(
      'html_alt' => $preview,
    ));
    $file = $flashnode['_flashnode'];

    // If using public download then encoding spaces that the upload module may have allowed
    // Private downloads will do this for us
    if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC) {
      $file = str_replace(' ', '%20', $file);
    }

    // Get HTML from SWF Tools
    $output .= swf(file_create_url($file), $params, $flashnode['flashvars'], $options, SWFDEFAULT, 0);

    // Return result
    return $output;
  }

  // Initialise variable to ensure we only show error once if trying to render mp3 or flv with basic embedding
  static $markup_error_shown = false;

  // If file type is flv or mp3 we can't show it without SWF Tools
  if (preg_match('@flv|mp3$@i', $flashnode['_flashnode'])) {
    if (!$markup_error_shown) {
      drupal_set_message(t('Flash node needs !swftools in order to play mp3 or flv files.', array(
        '!swftools' => l('SWF Tools', 'http://drupal.org/project/swftools'),
      )), 'warning');
      $markup_error_shown = true;
    }
    return;
  }

  // Use t() to substitute parameters in to basic Flash markup
  $output = t('<div class="flashnode"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="!width" height="!height" id="myMovieName"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="true" /><param name="movie" value="!filepath" /><param name="quality" value="high" /><param name="flashvars" value="!flashvars" /><param name="base" value="!base" /><embed src="!filepath" allowScriptAccess="sameDomain" allowFullScreen="true" quality="high" width="!width" height="!height" flashvars="!flashvars" name="myMovieName" align="" type="application/x-shockwave-flash" base="!base" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object></div>', array(
    '!height' => $flashnode['height'],
    '!width' => $flashnode['width'],
    '!filepath' => file_create_url($flashnode['_flashnode']),
    '!flashvars' => $flashnode['flashvars'],
    '!base' => $flashnode['base'],
  ));
  return $output;
}