--- swfobject.module 2006-12-14 06:23:57.000000000 -0800
+++ swfobject_new.module 2007-04-03 10:20:28.000000000 -0700
@@ -35,6 +35,13 @@ function swfobject_settings() {
'#default_value' => variable_get('swfobject_debug', 'normal'),
'#options' => drupal_map_assoc(array('normal','debug'))
);
+ $form['swfobject_replace'] = array(
+ '#type' => 'select',
+ '#title' => t('On upload'),
+ '#description' => t('Whether you want to create a new unique file or replace the old one when re-uploading a file with the same name as a previous file.'),
+ '#default_value' => variable_get('swfobject_replace', 'Replace previous file'),
+ '#options' => drupal_map_assoc(array('Replace previous file','Create unique file name'))
+ );
return $form;
}
@@ -65,11 +72,15 @@ function swfobject_block($op = 'list', $
'#title' => t('Required Attributes'),
'#collapsible' => false
);
+ if (variable_get('swfobject_swf_'. $delta, '')) {
+ $form['req']['current_swf'] = array(
+ '#value' => t('Current swf: ') . str_replace(array('%h', '%t'), array(base_path(), path_to_theme()), variable_get('swfobject_swf_'. $delta, '')),
+ );
+ }
$form['req']['swfobject_swf_'. $delta] = array(
- '#type' => 'textfield',
- '#title' => t('Flash file (.swf) location'),
- '#default_value' => variable_get('swfobject_swf_'. $delta, 'gallery.swf'),
- '#description' => t('Enter the path to the flash file (example: "flash/gallery.swf").
Macros:
- %h (host name: http://www.example.com/)
- %t (path to theme: theme/yourtheme/)
')
+ '#type' => 'file',
+ '#title' => t('Upload Flash file (.swf)'),
+ '#description' => t('The Flash file to appear in the block.'),
);
$form['req']['swfobject_id_'.$delta] = array(
'#type' => 'textfield',
@@ -217,7 +228,7 @@ function swfobject_block($op = 'list', $
case 'save':
foreach($edit as $key=>$value){
- if(strpos($key, 'swfobject_') === 0){
+ if(strpos($key, 'swfobject_') === 0 && strpos($key, 'swfobject_swf_') !== 0){
if($value == 'default'){
// do not store default variables
variable_del($key);
@@ -226,6 +237,16 @@ function swfobject_block($op = 'list', $
}
}
}
+
+ // Save uploaded file
+ $file_dir = variable_get('file_directory_path', 'files') .'/swfobject';
+ if(!file_check_directory($file_dir)) {
+ mkdir($file_dir);
+ }
+ if($file = file_save_upload('swfobject_swf_'.$delta, $file_dir .'/'. $file->filename, (variable_get('swfobject_replace', 'Replace previous file') == 'Replace previous file' ? FILE_EXISTS_REPLACE : FILE_EXISTS_RENAME))) {
+ variable_set('swfobject_swf_'.$delta, base_path() . $file->filepath);
+ }
+
if(isset($edit['swfobject_provide_container_'.$delta])){
variable_set('swfobject_provide_container_'.$delta,
$edit['swfobject_provide_container_'.$delta]);
@@ -244,6 +265,17 @@ function swfobject_block($op = 'list', $
break;
}
}
+
+/*
+ * Implementation of hook_form_alter()
+ */
+function swfobject_form_alter($form_id, &$form) {
+ // Need to set encoding type in a form_alter because above block config form goes
+ // through block_admin_configure.
+ if ($form['module']['#value'] == 'swfobject' && $form_id == 'block_admin_configure') {
+ $form['#attributes']['enctype'] = 'multipart/form-data';
+ }
+}
// helper function for displaying the actual block
function theme_swfobject_block_view($delta = 1){