Index: flashnode.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flashnode/flashnode.module,v
retrieving revision 1.48
diff -u -r1.48 flashnode.module
--- flashnode.module 12 Nov 2008 21:36:17 -0000 1.48
+++ flashnode.module 21 Jul 2009 07:42:33 -0000
@@ -1,5 +1,5 @@
flashnode['filepath']) {
form_set_error('flashfile', t('You must upload a file.'));
}
+
+ if($_FILES['files']['name']['flashfile'] != '' && !preg_match('/^[-_. a-zA-Z0-9]+$/',$_FILES['files']['name']['flashfile'])) {
+ form_set_error('flashfile', t('The filename can only contain letters, numbers, spaces, periods, hyphens and underscores.'));
+ }
// Check width is valid (if not empty it must be numeric)
if (!empty($node->flashnode['width']) && !is_numeric($node->flashnode['width'])) {
@@ -194,6 +198,29 @@
// Check flash directory exists and is writable
_flashnode_check_settings();
+ // If a new node initialise the flashnode elements
+ if (!isset($node->flashnode)) {
+ drupal_set_message(t('New node'));
+ $node->flashnode = array(
+ 'filepath' => '',
+ 'filename' => '',
+ 'fid' => '',
+ 'display' => variable_get('flashnode_default_display', FLASHNODE_TEASER_AND_BODY),
+ 'width' => '',
+ 'height' => '',
+ 'substitution' => '!default',
+ 'flashvars' => '',
+ 'base' => variable_get('flashnode_default_base', ''),
+ 'params' => '',
+ );
+ }
+
+ // Prevent notice errors in case _height and _width haven't been set yet
+ $node->flashnode += array(
+ '_height' => null,
+ '_width' => null,
+ );
+
// Begin form construct
$form['#attributes'] = array('enctype' => 'multipart/form-data');
@@ -201,10 +228,10 @@
$form['flashnode']['#tree'] = TRUE;
// Lifted from image.module to handle upload and previews
- if ($node->new_file) {
+ if (isset($node->new_file)) {
$form['new_file'] = array('#type' => 'value', '#value' => TRUE);
}
-
+
$form['flashnode']['filepath'] = array('#type' => 'value', '#value' => $node->flashnode['filepath']);
$form['flashnode']['filename'] = array('#type' => 'value', '#value' => $node->flashnode['filename']);
$form['flashnode']['fid'] = array('#type' => 'value', '#value' => $node->flashnode['fid']);
@@ -234,7 +261,7 @@
$form['flashnode']['flashfile'] = array(
'#type' => 'file',
'#title' => t('Flash file'),
- '#description' => $node->flashnode['fid'] ? t('Current file is %filename. Click "Browse..." to upload a different file.', array('%filename' => basename($node->flashnode['filepath']))) : t('Click "Browse..." to select a file to upload.'),
+ '#description' => $node->flashnode['fid'] ? t('Current file is %filename. Click "Browse..." to upload a different file.
Note: The filename can only contain letters, numbers, spaces, periods, hyphens and underscores.', array('%filename' => basename($node->flashnode['filepath']))) : t('Click "Browse..." to select a file to upload.'),
'#tree' => FALSE,
);
@@ -256,7 +283,8 @@
$form['flashnode']['basic']['display'] = array(
'#type' => 'radios',
'#title' => t('Display in'),
- '#default_value' => isset($node->flashnode['display']) ? $node->flashnode['display'] : variable_get('flashnode_default_display', FLASHNODE_TEASER_AND_BODY),
+// '#default_value' => isset($node->flashnode['display']) ? $node->flashnode['display'] : variable_get('flashnode_default_display', FLASHNODE_TEASER_AND_BODY),
+ '#default_value' => $node->flashnode['display'],
'#options' => array(
FLASHNODE_TEASER_AND_BODY => t('Teaser and body'),
FLASHNODE_TEASER_ONLY => t('Teaser only'),
@@ -306,7 +334,8 @@
'#type' => 'textarea',
'#title' => t('Substitution content'),
'#rows' => 5,
- '#default_value' => isset($node->flashnode['substitution']) ? $node->flashnode['substitution'] : '!default',
+// '#default_value' => isset($node->flashnode['substitution']) ? $node->flashnode['substitution'] : '!default',
+ '#default_value' => $node->flashnode['substitution'],
'#parents' => array('flashnode', 'substitution'),
'#description' => t('If a javascript method is used to embed flash then this is the content that users will see if they are unable to, or choose not to, display the flash content. This content uses the same input format as the body. The default content may be used by entering @default.', array('@default' => '!default')),
);
@@ -325,7 +354,8 @@
$form['flashnode']['advanced']['base'] = array(
'#type' => 'textfield',
'#title' => t('Base'),
- '#default_value' => isset($node->flashnode['base']) ? $node->flashnode['base'] : variable_get('flashnode_default_base', ''),
+// '#default_value' => isset($node->flashnode['base']) ? $node->flashnode['base'] : variable_get('flashnode_default_base', ''),
+ '#default_value' => $node->flashnode['base'],
'#parents' => array('flashnode', 'base'),
'#description' => t('Over-ride the default setting with a different base path here if necessary. This setting is needed for movies that use ActionScription functions such as %loadmovie with unqualified paths. Leave blank to let flash node generate a default that points to %defaultbase.', array('%loadmovie' => 'loadMovie()', '%defaultbase' => file_create_url(''))),
);
@@ -366,9 +396,16 @@
$node->flashnode[$parameter] = $value;
}
- // Generate default base path if not set
- if (!$flashnode['base']) {
- $flashnode['base'] = file_create_url('');
+ // The current Drupal database cannot handle NULL in an integer field,
+ // so if NULL was intended then zero got stored. Assume for now that
+ // zero means NULL, and that no-one would intend a zero width or height.
+ // This isn't necessarily true, but will have to do for now!
+ if (!$node->flashnode['height']) {
+ $node->flashnode['height'] = null;
+ }
+
+ if (!$node->flashnode['width']) {
+ $node->flashnode['width'] = null;
}
}
}
@@ -1003,8 +1040,13 @@
}
}
+ // If no base path has been set then create a default
+ if (!$flashnode['base']) {
+ $flashnode['base'] = file_create_url('');
+ }
+
// Generate output
- $output .= theme('flashnode_markup', $flashnode, $options);
+ $output = theme('flashnode_markup', $flashnode, $options);
// Return the HTML
return $output;
@@ -1031,12 +1073,18 @@
// Generate HTML markup, using SWF Tools if available, fallback if not
if (defined('SWFTOOLS_INSTALLED')) {
- // Add width, height and base to $params for SWF Tools, rounding width and height to integers
- $params = array(
- 'width' => round($flashnode['width']),
- 'height' => round($flashnode['height']),
- 'base' => $flashnode['base'],
- );
+ // If a width is defined, add it to $params, else leave undefined
+ if (round($flashnode['width'])) {
+ $params['width'] = round($flashnode['width']);
+ }
+
+ // If a height is defined, add it to $params, else leave undefined
+ if (round($flashnode['height'])) {
+ $params['height'] = round($flashnode['height']);
+ }
+
+ // Store base setting to parameters array
+ $params['base'] = $flashnode['base'];
// Create additional parameters if any are provided, and merge
$params = array_merge($params, flashnode_get_params($flashnode['params']));
@@ -1054,15 +1102,17 @@
'othervars' => $othervars,
);
+ // Assign filepath to $file
$file = $flashnode['filepath'];
- // If using public download then encoding spaces that the upload module may have allowed
+ // If using public download then encode 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);
}
- $output .= swf(file_create_url($file), $options);
+ // Generate markup by calling swf()
+ $output = swf(file_create_url($file), $options);
// Return result
return $output;
@@ -1080,14 +1130,23 @@
return;
}
+ // Create path to the swf file
+ $filepath = file_create_url($flashnode['filepath']);
+
+ // Discard $base_root since this isn't needed for a local file
+ $filepath = str_replace($GLOBALS['base_root'], '', $filepath);
+
+ // Do the same for the base path
+ $basepath = str_replace($GLOBALS['base_root'], '', $flashnode['base']);
+
// Use t() to substitute parameters in to basic Flash markup
$output = t('