function flashnode_content in Flash Node 6.3
Same name and namespace in other branches
- 5.6 flashnode.module \flashnode_content()
- 5.2 flashnode.module \flashnode_content()
- 5.3 flashnode.module \flashnode_content()
- 6.2 flashnode.module \flashnode_content()
Given a flash node nid and option parameters return the HTML string required to generate the required flash content (this is used by the macro system)
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
2 calls to flashnode_content()
- flashnode_filter in ./
flashnode.module - Implementation of hook_filter()
- views_handler_field_flashnode_content::render in views/
views_handler_field_flashnode_content.inc
File
- ./
flashnode.module, line 595
Code
function flashnode_content($args = array(), $format = FILTER_FORMAT_DEFAULT) {
// If no $args['nid'], or $arg['nid'] not numeric then set an error
if (!is_numeric($args['nid'])) {
$error = t('Incorrectly specified macro - <em>nid</em> not specified, or not numeric.');
}
else {
// Try loading via node_load
$node = node_load($args['nid']);
// If type isn't flashnode we can't do anything with this node so set an error
if ($node->type != 'flashnode') {
$error = t('Macro tried to load node @nid which is not a flash node.', array(
'@nid' => $args['nid'],
));
}
}
// If the initial phase failed display a message and log in watchdog for admin
if ($error) {
//drupal_set_message($error, 'error');
watchdog('flashnode', $error, NULL, WATCHDOG_ERROR);
return;
}
/**
* 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!
*/
// Call the _flashnode_php_flashvars function to do the work
$node->flashnode['flashvars'] = _flashnode_php_flashvars($node->flashnode['flashvars'], $node->format);
// Remove $args['nid'] from the array as this isn't a flash modifying parameter
unset($args['nid']);
// Set default scaling parameters
$xscale = $yscale = 1;
// Initialise options array
$options = array();
// Process the arguments array to modify the flash before rendering it
if ($args) {
foreach ($args as $parameter => $value) {
switch ($parameter) {
// Adjust to given width, maintaining aspect ratio
case 'scalewidth':
if (is_numeric($value) && $node->flashnode['width'] > 0) {
$xscale = $yscale = $value / $node->flashnode['width'];
}
break;
// Adjust to given height, maintaining aspect ratio
case 'scaleheight':
if (is_numeric($value) && $node->flashnode['height'] > 0) {
$xscale = $yscale = $value / $node->flashnode['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)) {
$node->flashnode[$parameter] = $value;
}
break;
// Add class to $node->flashnode array (this is from flashnode 5.1)
// This will need updating when SWFTools is finalised.
// May no longer be supported / relevant
case 'class':
$node->flashnode['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);
$node->flashnode['flashvars'] = $value;
// Process for PHP content
$node->flashnode['flashvars'] = _flashnode_php_flashvars($node->flashnode['flashvars'], $format);
break;
// Over-ride stored substitution text with alternatives
// Can use !default to retrieve default content
case 'substitution':
$node->flashnode['substitution'] = $value;
break;
// If none of the above, add the parameter and value to $options array
default:
$options[$parameter] = $value;
}
}
}
// Apply scaling
$node->flashnode['height'] = $node->flashnode['height'] * $yscale;
$node->flashnode['width'] = $node->flashnode['width'] * $xscale;
// Process substitution content through filters for this node
$node->flashnode['substitution'] = check_markup($node->flashnode['substitution'], $format, FALSE);
// Return markup
return theme('flashnode', $node->flashnode, FALSE, $options);
}