/[drupal]/drupal/modules/upload/upload.module
ViewVC logotype

Contents of /drupal/modules/upload/upload.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.268 - (show annotations) (download) (as text)
Sun Nov 1 21:55:31 2009 UTC (3 weeks, 5 days ago) by webchick
Branch: MAIN
Changes since 1.267: +2 -2 lines
File MIME type: text/x-php
#612396 by jim0203 and dman: Fixed Notice: Undefined index: process_input() in _form_builder_handle_input_element().
1 <?php
2 // $Id: upload.module,v 1.267 2009/11/01 12:11:10 dries Exp $
3
4 /**
5 * @file
6 * File-handling and attaching files to nodes.
7 *
8 */
9
10 /**
11 * Implement hook_help().
12 */
13 function upload_help($path, $arg) {
14 switch ($path) {
15 case 'admin/help#upload':
16 $output = '<p>' . t('The upload module allows users to upload files to the site. The ability to upload files is important for members of a community who want to share work. It is also useful to administrators who want to keep uploaded files connected to posts.') . '</p>';
17 $output .= '<p>' . t('Users with the upload files permission can upload attachments to posts. Uploads may be enabled for specific content types on the content types settings page. Each user role can be customized to limit or control the file size of uploads, or the maximum dimension of image files.') . '</p>';
18 $output .= '<p>' . t('For more information, see the online handbook entry for <a href="@upload">Upload module</a>.', array('@upload' => 'http://drupal.org/handbook/modules/upload/')) . '</p>';
19 return $output;
20 case 'admin/config/media/uploads':
21 return '<p>' . t('Users with the <a href="@permissions">upload files permission</a> can upload attachments. Users with the <a href="@permissions">view uploaded files permission</a> can view uploaded attachments. You can choose which post types can take attachments on the <a href="@types">content types settings</a> page.', array('@permissions' => url('admin/config/people/permissions'), '@types' => url('admin/structure/types'))) . '</p>';
22 }
23 }
24
25 /**
26 * Implement hook_theme().
27 */
28 function upload_theme() {
29 return array(
30 'upload_attachments' => array(
31 'render element' => 'elements',
32 ),
33 'upload_form_current' => array(
34 'render element' => 'form',
35 ),
36 'upload_form_new' => array(
37 'render element' => 'form',
38 ),
39 );
40 }
41
42 /**
43 * Implement hook_permission().
44 */
45 function upload_permission() {
46 return array(
47 'upload files' => array(
48 'title' => t('Upload files'),
49 'description' => t('Attach images and other files to content.'),
50 ),
51 'view uploaded files' => array(
52 'title' => t('View uploaded files'),
53 'description' => t('View and download files attached to content.'),
54 ),
55 );
56 }
57
58 /**
59 * Inject links into $node for attachments.
60 */
61 function upload_node_links(stdClass $node, $build_mode) {
62 $links = array();
63
64 // Display a link with the number of attachments
65 $num_files = 0;
66 foreach ($node->files as $file) {
67 if ((object)$file->list) {
68 $num_files++;
69 }
70 }
71 if ($num_files) {
72 $links['upload_attachments'] = array(
73 'title' => format_plural($num_files, '1 attachment', '@count attachments'),
74 'href' => "node/$node->nid",
75 'attributes' => array('title' => t('Read full article to view attachments.')),
76 'fragment' => 'attachments'
77 );
78 $node->content['links']['upload_attachments'] = array(
79 '#theme' => 'links',
80 '#links' => $links,
81 '#attributes' => array('class' => array('links', 'inline')),
82 );
83 }
84 }
85
86 /**
87 * Implement hook_menu().
88 */
89 function upload_menu() {
90 $items['upload/js'] = array(
91 'page callback' => 'upload_js',
92 'access arguments' => array('upload files'),
93 'type' => MENU_CALLBACK,
94 );
95 $items['admin/config/media/uploads'] = array(
96 'title' => 'File uploads',
97 'description' => 'Control how files may be attached to content.',
98 'page callback' => 'drupal_get_form',
99 'page arguments' => array('upload_admin_settings'),
100 'access arguments' => array('administer site configuration'),
101 'type' => MENU_NORMAL_ITEM,
102 'file' => 'upload.admin.inc',
103 );
104 return $items;
105 }
106
107 /**
108 * Determine the limitations on files that a given user may upload. The user
109 * may be in multiple roles so we select the most permissive limitations from
110 * all of their roles.
111 *
112 * @param $user
113 * A Drupal user object.
114 * @return
115 * An associative array with the following keys:
116 * 'extensions'
117 * A white space separated string containing all the file extensions this
118 * user may upload.
119 * 'file_size'
120 * The maximum size of a file upload in bytes.
121 * 'user_size'
122 * The total number of bytes for all for a user's files.
123 * 'resolution'
124 * A string specifying the maximum resolution of images.
125 */
126 function _upload_file_limits($user) {
127 $file_limit = variable_get('upload_uploadsize_default', 1);
128 $user_limit = variable_get('upload_usersize_default', 1);
129 $all_extensions = explode(' ', variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'));
130 foreach ($user->roles as $rid => $name) {
131 $extensions = variable_get("upload_extensions_$rid", variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'));
132 $all_extensions = array_merge($all_extensions, explode(' ', $extensions));
133
134 // A zero value indicates no limit, take the least restrictive limit.
135 $file_size = variable_get("upload_uploadsize_$rid", variable_get('upload_uploadsize_default', 1)) * 1024 * 1024;
136 $file_limit = ($file_limit && $file_size) ? max($file_limit, $file_size) : 0;
137
138 $user_size = variable_get("upload_usersize_$rid", variable_get('upload_usersize_default', 1)) * 1024 * 1024;
139 $user_limit = ($user_limit && $user_size) ? max($user_limit, $user_size) : 0;
140 }
141 $all_extensions = implode(' ', array_unique($all_extensions));
142 return array(
143 'extensions' => $all_extensions,
144 'file_size' => $file_limit,
145 'user_size' => $user_limit,
146 'resolution' => variable_get('upload_max_resolution_x', 0) . 'x' . variable_get('upload_max_resolution_y', 0),
147 );
148 }
149
150 /**
151 * Implement hook_file_download().
152 */
153 function upload_file_download($uri) {
154 $file = db_query("SELECT f.*, u.nid FROM {file} f INNER JOIN {upload} u ON f.fid = u.fid WHERE uri = :uri", array(':uri' => $uri))->fetchObject();
155
156 if ($file && user_access('view uploaded files') && ($node = node_load($file->nid)) && node_access('view', $node)) {
157 return array(
158 'Content-Type' => $file->filemime,
159 'Content-Length' => $file->filesize,
160 );
161 }
162 else {
163 return -1;
164 }
165 }
166
167 /**
168 * Save new uploads and store them in the session to be associated to the node
169 * on upload_save.
170 *
171 * @param $node
172 * A node object to associate with uploaded files.
173 */
174 function upload_node_form_submit(&$form, &$form_state) {
175 global $user;
176
177 $limits = _upload_file_limits($user);
178 $validators = array(
179 'file_validate_extensions' => array($limits['extensions']),
180 'file_validate_image_resolution' => array($limits['resolution']),
181 'file_validate_size' => array($limits['file_size'], $limits['user_size']),
182 );
183
184 // Save new file uploads.
185 if (user_access('upload files') && ($file = file_save_upload('upload', $validators, 'public://'))) {
186 $file->list = variable_get('upload_list_default', 1);
187 $file->description = $file->filename;
188 $file->weight = 0;
189 $file->new = TRUE;
190 $form['#node']->files[$file->fid] = $file;
191 $form_state['values']['files'][$file->fid] = (array)$file;
192 }
193
194 if (isset($form_state['values']['files'])) {
195 foreach ($form_state['values']['files'] as $fid => $file) {
196 $form_state['values']['files'][$fid]['new'] = !empty($form['#node']->files[$fid]->new);
197 }
198 }
199
200 // Order the form according to the set file weight values.
201 if (!empty($form_state['values']['files'])) {
202 $microweight = 0.001;
203 foreach ($form_state['values']['files'] as $fid => $file) {
204 if (is_numeric($fid)) {
205 $form_state['values']['files'][$fid]['#weight'] = $file['weight'] + $microweight;
206 $microweight += 0.001;
207 }
208 }
209 uasort($form_state['values']['files'], 'element_sort');
210 }
211 }
212
213 function upload_form_alter(&$form, $form_state, $form_id) {
214 if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
215 $form['workflow']['upload'] = array(
216 '#type' => 'radios',
217 '#title' => t('Attachments'),
218 '#default_value' => variable_get('upload_' . $form['#node_type']->type, 1),
219 '#options' => array(t('Disabled'), t('Enabled')),
220 );
221 }
222
223 if (!empty($form['#node_edit_form'])) {
224 $node = $form['#node'];
225 if (variable_get("upload_$node->type", TRUE)) {
226 // Attachments fieldset
227 $form['attachments'] = array(
228 '#type' => 'fieldset',
229 '#access' => user_access('upload files'),
230 '#title' => t('File attachments'),
231 '#collapsible' => TRUE,
232 '#collapsed' => empty($node->files),
233 '#group' => 'additional_settings',
234 '#attached' => array(
235 'js' => array(drupal_get_path('module', 'upload') . '/upload.js'),
236 ),
237 '#description' => t('Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.'),
238 '#weight' => 30,
239 );
240
241 // Wrapper for fieldset contents (used by ajax.js).
242 $form['attachments']['wrapper'] = array();
243
244 // Make sure necessary directories for upload.module exist and are
245 // writable before displaying the attachment form.
246 $path = file_directory_path();
247 $temp = file_directory_path('temporary');
248 // Note: pass by reference
249 if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY) || !file_prepare_directory($temp, FILE_CREATE_DIRECTORY)) {
250 $form['attachments']['#description'] = t('File attachments are disabled. The file directories have not been properly configured.');
251 if (user_access('administer site configuration')) {
252 $form['attachments']['#description'] .= ' ' . t('Please visit the <a href="@admin-file-system">file system configuration page</a>.', array('@admin-file-system' => url('admin/config/media/file-system')));
253 }
254 else {
255 $form['attachments']['#description'] .= ' ' . t('Please contact the site administrator.');
256 }
257 }
258 else {
259 $form['attachments']['wrapper'] += _upload_form($node);
260 }
261 $form['#submit'][] = 'upload_node_form_submit';
262 }
263 }
264 }
265
266 /**
267 * Implement hook_file_load().
268 */
269 function upload_file_load($files) {
270 // Add the upload specific data into the file object.
271 $result = db_query('SELECT * FROM {upload} u WHERE u.fid IN (:fids)', array(':fids' => array_keys($files)))->fetchAll(PDO::FETCH_ASSOC);
272 foreach ($result as $record) {
273 foreach ($record as $key => $value) {
274 $files[$record['fid']]->$key = $value;
275 }
276 }
277 }
278
279 /**
280 * Implement hook_file_references().
281 */
282 function upload_file_references($file) {
283 // If upload.module is still using a file, do not let other modules delete it.
284 $file_used = (bool) db_query_range('SELECT 1 FROM {upload} WHERE fid = :fid', 0, 1, array(':fid' => $file->fid))->fetchField();
285 if ($file_used) {
286 // Return the name of the module and how many references it has to the file.
287 return array('upload' => $count);
288 }
289 }
290
291 /**
292 * Implement hook_file_delete().
293 */
294 function upload_file_delete($file) {
295 // Delete all information associated with the file.
296 db_delete('upload')->condition('fid', $file->fid)->execute();
297 }
298
299 /**
300 * Implement hook_node_load().
301 */
302 function upload_node_load($nodes, $types) {
303 // Collect all the revision ids for nodes with upload enabled.
304 $node_vids = array();
305 foreach ($nodes as $node) {
306 if (variable_get("upload_$node->type", 1) == 1) {
307 $node_vids[$node->vid] = $node->vid;
308 $node->files = array();
309 }
310 }
311 // If there are no vids then there's no point trying to load files.
312 if (empty($node_vids)) {
313 return;
314 }
315
316 // Fetch the fids associated with these node revisions.
317 $result = db_query('SELECT u.fid, u.nid, u.vid FROM {upload} u WHERE u.vid IN (:node_vids) ORDER BY u.weight, u.fid', array(':node_vids' => $node_vids));
318
319 // The same file may be attached to several nodes (e.g. translated nodes) so
320 // simply calling db_query()->fetchAllAssoc('fid') would return one node
321 // per file. Instead we build one array with the file ids for
322 // file_load_multiple() and another array with upload records so we can match
323 // files back to the nodes.
324 $fids = array();
325 $uploads = array();
326 foreach ($result as $record) {
327 $fids[] = $record->fid;
328 $uploads[] = $record;
329 }
330
331 $files = file_load_multiple($fids);
332 foreach ($uploads as $upload) {
333 $nodes[$upload->nid]->files[$upload->fid] = $files[$upload->fid];
334 }
335 }
336
337 /**
338 * Implement hook_node_view().
339 */
340 function upload_node_view(stdClass $node, $build_mode) {
341 if (!isset($node->files)) {
342 return;
343 }
344
345 if (user_access('view uploaded files') && $build_mode != 'rss') {
346 if (count($node->files)) {
347 if ($build_mode == 'full') {
348 // Add the attachments list to node body with a heavy weight to ensure
349 // they're below other elements.
350 $node->content['files'] = array(
351 '#files' => $node->files,
352 '#theme' => 'upload_attachments',
353 '#weight' => 50,
354 );
355 }
356 else {
357 upload_node_links($node, $build_mode);
358 }
359 }
360 }
361
362 if ($build_mode == 'rss') {
363 // Add the first file as an enclosure to the RSS item. RSS allows only one
364 // enclosure per item. See: http://en.wikipedia.org/wiki/RSS_enclosure
365 foreach ($node->files as $file) {
366 if ($file->list) {
367 break;
368 }
369 }
370 if ($file->list) {
371 $node->rss_elements[] = array(
372 'key' => 'enclosure',
373 'attributes' => array(
374 'url' => file_create_url($file->uri),
375 'length' => $file->filesize,
376 'type' => $file->filemime
377 )
378 );
379 }
380 }
381 }
382
383 /**
384 * Implement hook_node_insert().
385 */
386 function upload_node_insert(stdClass $node) {
387 if (user_access('upload files')) {
388 upload_save($node);
389 }
390 }
391
392 /**
393 * Implement hook_node_update().
394 */
395 function upload_node_update(stdClass $node) {
396 if (user_access('upload files')) {
397 upload_save($node);
398 }
399 }
400
401 /**
402 * Implement hook_node_delete().
403 */
404 function upload_node_delete(stdClass $node) {
405 db_delete('upload')->condition('nid', $node->nid)->execute();
406 if (!is_array($node->files)) {
407 return;
408 }
409 foreach ($node->files as $file) {
410 file_delete($file);
411 }
412 }
413
414 /**
415 * Implement hook_node_revision_delete().
416 */
417 function upload_node_revision_delete(stdClass $node) {
418 db_delete('upload')->condition('vid', $node->vid)->execute();
419 if (!is_array($node->files)) {
420 return;
421 }
422 foreach ($node->files as $file) {
423 file_delete($file);
424 }
425 }
426
427 /**
428 * Implement hook_node_search_result().
429 */
430 function upload_node_search_result(stdClass $node) {
431 return isset($node->files) && is_array($node->files) ? format_plural(count($node->files), '1 attachment', '@count attachments') : NULL;
432 }
433
434 /**
435 * Displays file attachments in table
436 *
437 * @ingroup themeable
438 */
439 function theme_upload_attachments($variables) {
440 $elements = $variables['elements'];
441
442 $header = array(t('Attachment'), t('Size'));
443 $rows = array();
444 foreach ($elements['#files'] as $file) {
445 $file = (object)$file;
446 if ($file->list && empty($file->remove)) {
447 $href = file_create_url($file->uri);
448 $text = $file->description ? $file->description : $file->filename;
449 $rows[] = array(l($text, $href), format_size($file->filesize));
450 }
451 }
452 if (count($rows)) {
453 return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('class' => array('attachments'))));
454 }
455 }
456
457 /**
458 * Determine how much disk space is occupied by a user's uploaded files.
459 *
460 * @param $uid
461 * The integer user id of a user.
462 * @return
463 * The amount of disk space used by the user in bytes.
464 */
465 function upload_space_used($uid) {
466 return file_space_used($uid);
467 }
468
469 /**
470 * Determine how much disk space is occupied by uploaded files.
471 *
472 * @return
473 * The amount of disk space used by uploaded files in bytes.
474 */
475 function upload_total_space_used() {
476 return db_query('SELECT SUM(f.filesize) FROM {file} f INNER JOIN {upload} u ON f.fid = u.fid')->fetchField();
477 }
478
479 function upload_save(stdClass $node) {
480 if (empty($node->files) || !is_array($node->files)) {
481 return;
482 }
483
484 foreach ($node->files as $fid => $file) {
485 // Convert file to object for compatibility
486 $file = (object)$file;
487
488 // Remove file. Process removals first since no further processing
489 // will be required.
490 if (!empty($file->remove)) {
491 // Remove the reference from this revision.
492 db_delete('upload')->condition('fid', $file->fid)->condition('vid', $node->vid)->execute();
493 // Try a soft delete, if the file isn't used elsewhere it'll be deleted.
494 file_delete($file);
495 // Remove it from the session in the case of new uploads,
496 // that you want to disassociate before node submission.
497 unset($node->files[$fid]);
498 // Move on, so the removed file won't be added to new revisions.
499 continue;
500 }
501
502 // Create a new revision, or associate a new file needed.
503 if (!empty($node->old_vid) || $file->new) {
504 db_insert('upload')
505 ->fields(array(
506 'fid' => $file->fid,
507 'nid' => $node->nid,
508 'vid' => $node->vid,
509 'list' => $file->list,
510 'description' => $file->description,
511 'weight' => $file->weight,
512 ))
513 ->execute();
514 }
515 // Update existing revision.
516 else {
517 db_update('upload')
518 ->fields(array(
519 'list' => $file->list,
520 'description' => $file->description,
521 'weight' => $file->weight,
522 ))
523 ->condition('fid', $file->fid, '=')
524 ->condition('vid', $node->vid, '=')
525 ->execute();
526 }
527 $file->status |= FILE_STATUS_PERMANENT;
528 $file = file_save($file);
529 }
530 }
531
532 function _upload_form(stdClass $node) {
533 global $user;
534
535 $form = array(
536 '#theme' => 'upload_form_new',
537 '#cache' => TRUE,
538 '#prefix' => '<div id="attach-wrapper">',
539 '#suffix' => '</div>',
540 );
541
542 if (!empty($node->files) && is_array($node->files)) {
543 $form['files']['#theme'] = 'upload_form_current';
544 $form['files']['#tree'] = TRUE;
545 foreach ($node->files as $file) {
546 $file = (object)$file;
547 $key = $file->fid;
548
549 $form['files'][$key]['description'] = array('#type' => 'textfield', '#default_value' => !empty($file->description) ? $file->description : $file->filename, '#maxlength' => 256, '#description' => '<small>' . file_create_url($file->uri) . '</small>');
550 $form['files'][$key]['size'] = array('#markup' => format_size($file->filesize));
551 $form['files'][$key]['remove'] = array('#type' => 'checkbox', '#default_value' => !empty($file->remove));
552 $form['files'][$key]['list'] = array('#type' => 'checkbox', '#default_value' => $file->list);
553 $form['files'][$key]['weight'] = array('#type' => 'weight', '#delta' => count($node->files), '#default_value' => $file->weight);
554 $form['files'][$key]['filename'] = array('#type' => 'value', '#value' => $file->filename);
555 $form['files'][$key]['uri'] = array('#type' => 'value', '#value' => $file->uri);
556 $form['files'][$key]['filemime'] = array('#type' => 'value', '#value' => $file->filemime);
557 $form['files'][$key]['filesize'] = array('#type' => 'value', '#value' => $file->filesize);
558 $form['files'][$key]['fid'] = array('#type' => 'value', '#value' => $file->fid);
559 $form['files'][$key]['new'] = array('#type' => 'value', '#value' => FALSE);
560 }
561 }
562
563 if (user_access('upload files')) {
564 $limits = _upload_file_limits($user);
565
566 $limit_description = t('The maximum size of file uploads is %filesize.', array('%filesize' => format_size($limits['file_size']))) . ' ';
567 if (!empty($limits['resolution'])) {
568 if (image_get_toolkit()) {
569 $limit_description .= t('Images larger than %resolution will be resized.', array('%resolution' => $limits['resolution'])) . ' ';
570 }
571 else {
572 $limit_description .= t('Images may not be larger than %resolution.', array('%resolution' => $limits['resolution'])) . ' ';
573 }
574 }
575 $limit_description .= t('Only files with the following extensions may be uploaded: %extensions.', array('%extensions' => $limits['extensions'])) . ' ';
576
577 $form['new']['#weight'] = 10;
578 $form['new']['upload'] = array(
579 '#type' => 'file',
580 '#title' => t('Attach new file'),
581 '#size' => 40,
582 '#description' => $limit_description,
583 );
584 $form['new']['attach'] = array(
585 '#type' => 'submit',
586 '#value' => t('Attach'),
587 '#name' => 'attach',
588 '#ajax' => array(
589 'path' => 'upload/js',
590 'wrapper' => 'attach-wrapper',
591 'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
592 ),
593 '#submit' => array('node_form_submit_build_node'),
594 );
595 }
596
597 return $form;
598 }
599
600 /**
601 * Theme the attachments list.
602 *
603 * @ingroup themeable
604 */
605 function theme_upload_form_current($variables) {
606 $form = $variables['form'];
607
608 $header = array('', t('Delete'), t('List'), t('Description'), t('Weight'), t('Size'));
609 drupal_add_tabledrag('upload-attachments', 'order', 'sibling', 'upload-weight');
610
611 foreach (element_children($form) as $key) {
612 // Add class to group weight fields for drag and drop.
613 $form[$key]['weight']['#attributes']['class'] = array('upload-weight');
614
615 $row = array('');
616 $row[] = drupal_render($form[$key]['remove']);
617 $row[] = drupal_render($form[$key]['list']);
618 $row[] = drupal_render($form[$key]['description']);
619 $row[] = drupal_render($form[$key]['weight']);
620 $row[] = drupal_render($form[$key]['size']);
621 $rows[] = array('data' => $row, 'class' => array('draggable'));
622 }
623 $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'upload-attachments')));
624 $output .= drupal_render_children($form);
625 return $output;
626 }
627
628 /**
629 * Theme the attachment form.
630 * Note: required to output prefix/suffix.
631 *
632 * @ingroup themeable
633 */
634 function theme_upload_form_new($variables) {
635 drupal_add_tabledrag('upload-attachments', 'order', 'sibling', 'upload-weight');
636 $output = drupal_render_children($variables['form']);
637 return $output;
638 }
639
640 /**
641 * Menu-callback for JavaScript-based uploads.
642 */
643 function upload_js() {
644 $cached_form_state = array();
645 $files = array();
646
647 // Load the form from the Form API cache.
648 if (!($cached_form = form_get_cache($_POST['form_build_id'], $cached_form_state)) || !isset($cached_form['#node']) || !isset($cached_form['attachments'])) {
649 form_set_error('form_token', t('Validation error, please try again. If this error persists, please contact the site administrator.'));
650 $output = theme('status_messages');
651 print drupal_json_encode(array('status' => TRUE, 'data' => $output));
652 drupal_exit();
653 }
654
655 $form_state = array('values' => $_POST);
656
657 // Handle new uploads, and merge tmp files into node-files.
658 upload_node_form_submit($cached_form, $form_state);
659
660 if (!empty($form_state['values']['files'])) {
661 foreach ($form_state['values']['files'] as $fid => $file) {
662 if (isset($cached_form['#node']->files[$fid])) {
663 $files[$fid] = $cached_form['#node']->files[$fid];
664 }
665 }
666 }
667
668 $node = $cached_form['#node'];
669
670 $node->files = $files;
671
672 $form = _upload_form($node);
673
674 unset($cached_form['attachments']['wrapper']['new']);
675 $cached_form['attachments']['wrapper'] = array_merge($cached_form['attachments']['wrapper'], $form);
676
677 $cached_form['attachments']['#collapsed'] = FALSE;
678
679 form_set_cache($_POST['form_build_id'], $cached_form, $cached_form_state);
680
681 foreach ($files as $fid => $file) {
682 if (is_numeric($fid)) {
683 $form['files'][$fid]['description']['#default_value'] = $form_state['values']['files'][$fid]['description'];
684 $form['files'][$fid]['list']['#default_value'] = !empty($form_state['values']['files'][$fid]['list']);
685 $form['files'][$fid]['remove']['#default_value'] = !empty($form_state['values']['files'][$fid]['remove']);
686 $form['files'][$fid]['weight']['#default_value'] = $form_state['values']['files'][$fid]['weight'];
687 }
688 }
689
690 // Render the form for output.
691 $form += array(
692 '#tree' => FALSE,
693 '#parents' => array(),
694 );
695 $form_state = array('submitted' => FALSE, 'programmed' => FALSE, 'process_input' => FALSE, 'complete form' => FALSE);
696 $form_id = 'upload_js';
697 drupal_alter('form', $form, $form_state, $form_id);
698 $form = form_builder('upload_js', $form, $form_state);
699 $output = theme('status_messages') . drupal_render($form);
700
701 $commands = array();
702 $commands[] = ajax_command_replace(NULL, $output);
703
704 // AJAX uploads use an <iframe> and some browsers have problems with the
705 // 'text/javascript' Content-Type header with iframes. Passing FALSE to
706 // ajax_render() prevents the header from being sent.
707 ajax_render($commands, FALSE);
708 }

  ViewVC Help
Powered by ViewVC 1.1.2