You are here

function flashnode_content in Flash Node 5.2

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

Return the HTML string required to generate flash content, based on an array of user supplied arguments.

The substitution content is filtered according to the specified format, and if no format is specified use the default. This function is called by the macro filter, but may also be called directly from PHP.

Parameters

$args: Key Required? Comment nid Yes nid of the node containing the swf to display scaleheight No Scale the movie height/width to get requested height scalewidth No Scale the movie height/width to get the requested width xscale No Scale movie width by the specified factor yscale No Scale movie height by the specified factor scale No Scale height and width by the specified factor height No Over-ride stored height with the given value width No Over-ride stored width with the given value class No Include the given class in the $flash array flashvars No Include the specified flashvars string in the $flash array substitution No Over-ride stored substitution markup

$format: The filter format to apply to the substitution content. If no format is given then apply the default format.

Return value

Returns the HTML mark up for inserting the flash content, or returns nothing if the specified nid is not valid

1 call to flashnode_content()
flashnode_filter in ./flashnode.module
Implementation of hook_filter()

File

./flashnode.module, line 572

Code

function flashnode_content($args = array(), $format = FILTER_FORMAT_DEFAULT) {

  // If no $args['nid'], or $arg['nid'] not numeric supplied then return
  if (!is_numeric($args['nid'])) {
    return;
  }

  // Get the filepath from the database
  $flash['_flashnode'] = db_result(db_query("SELECT filepath FROM {files} WHERE filename='%s' AND nid=%d", '_flashnode', $args['nid']));

  // Did we find a valid flashnode entry? If not, return empty
  if (!$flash['_flashnode']) {
    return;
  }

  // Retrieve parameters associated with this file from {flashnode}
  $result = db_query("SELECT height, width, display, substitution, flashvars, base FROM {flashnode} WHERE nid=%d", $args['nid']);

  // Store all the settings in to the $flash array
  $result = db_fetch_object($result);
  foreach ($result as $parameter => $value) {
    $flash[$parameter] = $value;
  }

  /**
   * Process flashvars for PHP. To make the site flexible we can choose to let the
   * parent node use PHP format to create a dynamic flashvar. However, we might
   * want to allow other nodes to use that dynamic flash, but without letting
   * them have wider access to the PHP format. So we process flashvars against
   * the input format of the *parent* node, not this node. If the parent allows
   * PHP then the flashvars will be processed via the PHP filter. If the user
   * supplies new flashvars via the macro format then we process again later,
   * but this time against the format of the node where the macro is running.
   * This is so that the user doesn't get access to the PHP format via the macro!
   */

  // Get parent format, accounting for the fact a revision might be in use
  $parent_format = db_result(db_query('SELECT r.format FROM {node_revisions} r INNER JOIN {node} n ON n.vid = r.vid WHERE n.nid=%d', $args['nid']));

  // Call the _flashnode_php_flashvars function to do the work
  $flash['flashvars'] = _flashnode_php_flashvars($flash['flashvars'], $parent_format);

  // Remove $args['nid'] from the array
  unset($args['nid']);

  // Process the arguments array to modify the flash before rendering it
  if ($args) {
    foreach ($args as $parameter => $value) {
      $xscale = $yscale = 1;
      switch ($parameter) {

        // Adjust to given width, maintaining aspect ratio
        case 'scalewidth':
          if (is_numeric($value)) {
            $xscale = $yscale = $value / $flash['width'];
          }
          break;

        // Adjust to given height, maintaining aspect ratio
        case 'scaleheight':
          if (is_numeric($value)) {
            $xscale = $yscale = $value / $flash['height'];
          }
          break;

        // Scale width by given factor
        case 'xscale':
          if (is_numeric($value)) {
            $xscale = $value;
          }
          break;

        // Scale height by given factor
        case 'yscale':
          if (is_numeric($value)) {
            $yscale = $value;
          }
          break;

        // Scale both width and height by given factor
        case 'scale':
          if (is_numeric($value)) {
            $xscale = $yscale = $value;
          }
          break;

        // Set height or width to specific value
        case 'height':
        case 'width':
          if (is_numeric($value)) {
            $flash[$parameter] = $value;
          }
          break;

        // Add class to $flash array (this is from flashnode 5.1)
        // This will need updating when SWFTools is finalised.
        // May no longer be supported / relevant
        case 'class':
          $flash['class'] = $value;
          break;

        // Over-ride stored flashvars with alternatives
        case 'flashvars':

          // If flashvars was set by the macro this over-rides the stored values
          // this is to allow flash to be re-used. If & has been replaced by &
          // by another filter then we need to reverse that first
          $value = str_replace('&', '&', $value);
          $flash['flashvars'] = $value;

          // Process for PHP content
          $flash['flashvars'] = _flashnode_php_flashvars($flash['flashvars'], $format);
          break;

        // Over-ride stored substitution text with alternatives
        // Can use !default to retrieve default content
        case 'substitution':
          $flash['substitution'] = $value;
          break;

        // If none of the above, add the parameter and value to $options array
        default:
          $options[$parameter] = $value;
      }
    }
  }

  // Process substitution content through filters for this node
  $flash['substitution'] = check_markup($flash['substitution'], $format, FALSE);

  // Return markup
  return flashnode_display($flash, $options);
}