| 1 |
<?php
|
| 2 |
// $Id: upload_progress.module,v 1.3 2007/11/17 20:39:59 pfournier Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Add a progress par to selected node creation forms.
|
| 7 |
*
|
| 8 |
* @author Patrick Fournier, inspired by the video_upload module
|
| 9 |
*/
|
| 10 |
|
| 11 |
|
| 12 |
function upload_progress_perm() {
|
| 13 |
return array('administer upload progress');
|
| 14 |
}
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Implementation of hook_menu().
|
| 18 |
*/
|
| 19 |
function upload_progress_menu($may_cache) {
|
| 20 |
$items = array();
|
| 21 |
$access = user_access('administer upload progress');
|
| 22 |
|
| 23 |
if (!$may_cache) {
|
| 24 |
$items[] = array(
|
| 25 |
'path' => 'admin/settings/upload_progress',
|
| 26 |
'title' => t('Upload Progress'),
|
| 27 |
'description' => t('Enable or disable the upload progress for each node type.'),
|
| 28 |
'access' => $access,
|
| 29 |
'callback' => 'drupal_get_form',
|
| 30 |
'callback arguments' => array('upload_progress_settings')
|
| 31 |
);
|
| 32 |
}
|
| 33 |
|
| 34 |
return $items;
|
| 35 |
}
|
| 36 |
|
| 37 |
function upload_progress_settings() {
|
| 38 |
$form = array();
|
| 39 |
|
| 40 |
$types = drupal_map_assoc(node_get_types('names'));
|
| 41 |
$form['upload_progress_node_types'] = array(
|
| 42 |
'#type' => 'checkboxes',
|
| 43 |
'#title' => t('Node types'),
|
| 44 |
'#default_value' => variable_get('upload_progress_node_types', array()),
|
| 45 |
'#options' => $types,
|
| 46 |
'#description' => t('Add a progress bar while processing the following node types creation forms.'),
|
| 47 |
'#weight' => -10
|
| 48 |
);
|
| 49 |
|
| 50 |
$form['upload_progress_delay'] = array(
|
| 51 |
'#type' => 'textfield',
|
| 52 |
'#title' => t('Delay'),
|
| 53 |
'#size' => 3,
|
| 54 |
'#default_value' => variable_get('upload_progress_delay', 3),
|
| 55 |
'#field_suffix' => t('seconds'),
|
| 56 |
'#description' => t('Show the progress bar if processing is longer than this value.'),
|
| 57 |
'#weight' => -9
|
| 58 |
);
|
| 59 |
|
| 60 |
$form['upload_progress_message'] = array(
|
| 61 |
'#type' => 'textfield',
|
| 62 |
'#title' => t('Message'),
|
| 63 |
'#size' => 60,
|
| 64 |
'#default_value' => variable_get('upload_progress_message', t('Processing form... please wait.')),
|
| 65 |
'#field_suffix' => t('seconds'),
|
| 66 |
'#description' => t('Message to display while uploading.'),
|
| 67 |
'#weight' => -8
|
| 68 |
);
|
| 69 |
|
| 70 |
$form['#validate'] = array('upload_progress_validate' => array());
|
| 71 |
|
| 72 |
return system_settings_form($form);
|
| 73 |
}
|
| 74 |
|
| 75 |
function upload_progress_validate($form_id, $form_values) {
|
| 76 |
if (!is_numeric($form_values['upload_progress_delay'])) {
|
| 77 |
form_set_error('upload_progress_delay', t('Please enter a number.'));
|
| 78 |
}
|
| 79 |
}
|
| 80 |
|
| 81 |
/**
|
| 82 |
* Implementation of hook_form_alter()
|
| 83 |
* We use this to add a file upload field to the video creation form.
|
| 84 |
*/
|
| 85 |
function upload_progress_form_alter($form_id, &$form) {
|
| 86 |
$node_type = $form['type']['#value'];
|
| 87 |
|
| 88 |
if ($node_type != "") {
|
| 89 |
$node_type_name = node_get_types('name', $node_type);
|
| 90 |
$node_type_name_array = array_values(variable_get('upload_progress_node_types', array()));
|
| 91 |
|
| 92 |
if (in_array($node_type_name, $node_type_name_array, TRUE)) {
|
| 93 |
|
| 94 |
theme('upload_progress_get_script', variable_get('upload_progress_delay', 0));
|
| 95 |
$form['#suffix'] = theme('upload_progress_busy');
|
| 96 |
}
|
| 97 |
}
|
| 98 |
}
|
| 99 |
|
| 100 |
/**
|
| 101 |
* Import the upload_progress.js script
|
| 102 |
*/
|
| 103 |
function theme_upload_progress_get_script($delay) {
|
| 104 |
drupal_add_js(drupal_get_path('module', 'upload_progress') . '/upload_progress.js');
|
| 105 |
drupal_add_js(array('upload_progress' => array('delay' => $delay[0])), 'setting');
|
| 106 |
}
|
| 107 |
|
| 108 |
function theme_upload_progress_busy() {
|
| 109 |
$message = variable_get('upload_progress_message', t('Processing form... please wait.'));
|
| 110 |
|
| 111 |
return <<<CONTENT
|
| 112 |
<div id="sending" class="progress" style="display: none;">
|
| 113 |
<div class="status">$message</div>
|
| 114 |
<div class="bar"></div>
|
| 115 |
</div>
|
| 116 |
CONTENT;
|
| 117 |
}
|