Index: modules/upload/upload.admin.css
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload/upload.admin.css,v
retrieving revision 1.2
diff -u -p -r1.2 upload.admin.css
--- modules/upload/upload.admin.css 17 Oct 2009 12:10:31 -0000 1.2
+++ modules/upload/upload.admin.css 5 Dec 2009 17:27:11 -0000
@@ -1,19 +0,0 @@
-/* $Id: upload.admin.css,v 1.2 2009/10/17 12:10:31 dries Exp $ */
-
-div.form-item-resolution .description {
- clear: both;
-}
-
-div.form-item-resolution .form-type-textfield {
- float: left;
-}
-
-div.form-item-resolution .form-type-textfield label {
- font-weight: normal;
- font-size: 0.85em;
- color: #898989;
-}
-
-div.form-item-resolution .upload-max-resolution-x-wrapper .field-suffix {
- margin-right: 0.25em;
-}
Index: modules/upload/upload.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload/upload.admin.inc,v
retrieving revision 1.16
diff -u -p -r1.16 upload.admin.inc
--- modules/upload/upload.admin.inc 5 Sep 2009 15:05:05 -0000 1.16
+++ modules/upload/upload.admin.inc 5 Dec 2009 17:27:11 -0000
@@ -1,175 +0,0 @@
- format_size(file_upload_max_size()))) . '
';
- $more_info = t("Depending on your server environment, these settings may be changed in the system-wide php.ini file, a php.ini file in your Drupal root directory, in your Drupal site's settings.php file, or in the .htaccess file in your Drupal root directory.");
-
- if (!is_numeric($default_uploadsize) || ($default_uploadsize <= 0)) {
- form_set_error('upload_uploadsize_default', t('The %role file size limit must be a number and greater than zero.', array('%role' => t('default'))));
- }
- if (!is_numeric($default_usersize) || ($default_usersize < 0)) {
- form_set_error('upload_usersize_default', t('The %role file size limit must be a number zero or greater.', array('%role' => t('default'))));
- }
- if ($default_uploadsize * 1024 * 1024 > file_upload_max_size()) {
- form_set_error('upload_uploadsize_default', $exceed_max_msg . $more_info);
- $more_info = '';
- }
- if ($default_usersize && $default_uploadsize > $default_usersize) {
- form_set_error('upload_uploadsize_default', t('The %role maximum file size per upload is greater than the total file size allowed per user', array('%role' => t('default'))));
- }
-
- foreach ($form_state['values']['roles'] as $rid => $role) {
- $uploadsize = $form_state['values']['upload_uploadsize_' . $rid];
- $usersize = $form_state['values']['upload_usersize_' . $rid];
-
- if (!is_numeric($uploadsize) || ($uploadsize <= 0)) {
- form_set_error('upload_uploadsize_' . $rid, t('The %role file size limit must be a number and greater than zero.', array('%role' => $role)));
- }
- if (!is_numeric($usersize) || ($usersize < 0)) {
- form_set_error('upload_usersize_' . $rid, t('The %role file size limit must be a number zero or greater.', array('%role' => $role)));
- }
- if ($uploadsize * 1024 * 1024 > file_upload_max_size()) {
- form_set_error('upload_uploadsize_' . $rid, $exceed_max_msg . $more_info);
- $more_info = '';
- }
- if ($usersize && $uploadsize > $usersize) {
- form_set_error('upload_uploadsize_' . $rid, t('The %role maximum file size per upload is greater than the total file size allowed per user', array('%role' => $role)));
- }
- }
-}
-
-/**
- * Menu callback for the upload settings form.
- */
-function upload_admin_settings() {
- $upload_extensions_default = variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp');
- $upload_uploadsize_default = variable_get('upload_uploadsize_default', 1);
- $upload_usersize_default = variable_get('upload_usersize_default', 1);
-
- $form['settings_general'] = array(
- '#type' => 'fieldset',
- '#title' => t('General settings'),
- '#collapsible' => TRUE,
- '#attached'=> array(
- 'css' => array(drupal_get_path('module', 'upload') . '/upload.admin.css'),
- ),
- );
- $form['settings_general']['upload_max_resolution'] = array(
- '#type' => 'item',
- '#title' => t('Maximum resolution for uploaded images'),
- '#description' => t('The maximum allowed image size (e.g. 640x480). Set to 0x0 for no restriction. If an image toolkit is installed, files exceeding this value will be scaled down to fit.', array('!image-toolkit-link' => url('admin/config/media/image-toolkit'))),
- '#prefix' => '
' . t('Your PHP settings limit the maximum file size per upload to %size.', array('%size' => format_size(file_upload_max_size()))) . '
'); - - $roles = user_roles(FALSE, 'upload files'); - $form['roles'] = array('#type' => 'value', '#value' => $roles); - - foreach ($roles as $rid => $role) { - $form['settings_role_' . $rid] = array( - '#type' => 'fieldset', - '#title' => t('Settings for @role', array('@role' => $role)), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ); - $form['settings_role_' . $rid]['upload_extensions_' . $rid] = array( - '#type' => 'textfield', - '#title' => t('Permitted file extensions'), - '#default_value' => variable_get('upload_extensions_' . $rid, $upload_extensions_default), - '#maxlength' => 255, - '#description' => t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.'), - ); - $form['settings_role_' . $rid]['upload_uploadsize_' . $rid] = array( - '#type' => 'textfield', - '#title' => t('Maximum file size per upload'), - '#default_value' => variable_get('upload_uploadsize_' . $rid, $upload_uploadsize_default), - '#size' => 5, - '#maxlength' => 5, - '#description' => t('The maximum size of a file a user can upload. If an image is uploaded and a maximum resolution is set, the size will be checked after the file has been resized.'), - '#field_suffix' => t('MB'), - ); - $form['settings_role_' . $rid]['upload_usersize_' . $rid] = array( - '#type' => 'textfield', - '#title' => t('Total file size per user'), - '#default_value' => variable_get('upload_usersize_' . $rid, $upload_usersize_default), - '#size' => 7, - '#maxlength' => 7, - '#description' => t('The maximum size of all files a user can have on the site. Set to 0 for no restriction.'), - '#field_suffix' => t('MB'), - ); - } - - $form['#validate'] = array('upload_admin_settings_validate'); - - return system_settings_form($form, FALSE); -} Index: modules/upload/upload.info =================================================================== RCS file: /cvs/drupal/drupal/modules/upload/upload.info,v retrieving revision 1.11 diff -u -p -r1.11 upload.info --- modules/upload/upload.info 17 Nov 2009 21:24:19 -0000 1.11 +++ modules/upload/upload.info 5 Dec 2009 17:27:11 -0000 @@ -1,12 +0,0 @@ -; $Id: upload.info,v 1.11 2009/11/17 21:24:19 dries Exp $ -name = Upload -description = Allows users to upload and attach files to content. -package = Core -version = VERSION -core = 7.x -files[] = upload.module -files[] = upload.admin.inc -files[] = upload.install -files[] = upload.test -files[] = upload.tokens.inc -configure = admin/config/media/uploads Index: modules/upload/upload.install =================================================================== RCS file: /cvs/drupal/drupal/modules/upload/upload.install,v retrieving revision 1.17 diff -u -p -r1.17 upload.install --- modules/upload/upload.install 4 Dec 2009 16:49:48 -0000 1.17 +++ modules/upload/upload.install 5 Dec 2009 17:27:11 -0000 @@ -1,133 +0,0 @@ - 'Stores uploaded file information and table associations.', - 'fields' => array( - 'fid' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'Primary Key: The {file}.fid.', - ), - 'nid' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'The {node}.nid associated with the uploaded file.', - ), - 'vid' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'Primary Key: The {node}.vid associated with the uploaded file.', - ), - 'description' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - 'description' => 'Description of the uploaded file.', - 'translatable' => TRUE, - ), - 'list' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'size' => 'tiny', - 'description' => 'Whether the file should be visibly listed on the node: yes(1) or no(0).', - ), - 'weight' => array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'size' => 'tiny', - 'description' => 'Weight of this upload in relation to other uploads in this node.', - ), - ), - 'primary key' => array('vid', 'fid'), - 'foreign keys' => array( - 'fid' => array('files' => 'fid'), - 'nid' => array('node' => 'nid'), - 'vid' => array('node' => 'vid'), - ), - 'indexes' => array( - 'fid' => array('fid'), - 'nid' => array('nid'), - ), - ); - - return $schema; -} - - -/** - * Migrate upload module files from {files} to {file}. - */ -function upload_update_7000(&$sandbox) { - - /* - TODO: Fix the updates. This is broken. See http://drupal.org/node/329301#comment-1404336 - Also note new DB structure http://drupal.org/node/227232#comment-1683976 - */ - - if (!isset($sandbox['progress'])) { - // Initialize batch update information. - $sandbox['progress'] = 0; - $sandbox['last_fid_processed'] = -1; - $sandbox['max'] = db_query("SELECT COUNT(DISTINCT u.fid) FROM {upload} u")->fetchField(); - } - - // As a batch operation move records from {files} into the {file} table. - $limit = 500; - $result = db_query_range("SELECT DISTINCT u.fid FROM {upload} u ORDER BY u.vid", array(), 0, $limit); - foreach ($result as $record) { - $old_file = db_query('SELECT f.* FROM {files} f WHERE f.fid = :fid', array(':fid' => $record->fid))->fetch(PDO::FETCH_OBJ); - if (!$old_file) { - continue; - } - - $new_file = db_query('SELECT f.* FROM {files} f WHERE f.filepath = :filepath', array(':filepath' => $old_file->uri))->fetch(PDO::FETCH_OBJ); - if (!$new_file) { - // Re-save the file into the new {file} table. - $new_file = clone $old_file; - drupal_write_record('file', $new_file); - } - - // If the fid has changed we need to update the {upload} record to use the - // new id. - if (!empty($new_file->fid) && ($new_file->fid != $old_file->fid)) { - db_update('upload') - ->fields(array('fid' => $new_file->fid)) - ->condition('fid', $old_file->fid) - ->execute(); - } - - // Update our progress information for the batch update. - $sandbox['progress']++; - $sandbox['last_fid_processed'] = $old_file->fid; - } - - // Indicate our current progress to the batch update system. If there's no - // max value then there's nothing to update and we're finished. - $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); -} - Index: modules/upload/upload.js =================================================================== RCS file: /cvs/drupal/drupal/modules/upload/upload.js,v retrieving revision 1.3 diff -u -p -r1.3 upload.js --- modules/upload/upload.js 27 Apr 2009 20:19:38 -0000 1.3 +++ modules/upload/upload.js 5 Dec 2009 17:27:11 -0000 @@ -1,14 +0,0 @@ -// $Id: upload.js,v 1.3 2009/04/27 20:19:38 webchick Exp $ - -(function ($) { - -Drupal.behaviors.uploadFieldsetSummaries = { - attach: function (context) { - $('fieldset#edit-attachments', context).setSummary(function (context) { - var size = $('#upload-attachments tbody tr').size(); - return Drupal.formatPlural(size, '1 attachment', '@count attachments'); - }); - } -}; - -})(jQuery); Index: modules/upload/upload.module =================================================================== RCS file: /cvs/drupal/drupal/modules/upload/upload.module,v retrieving revision 1.272 diff -u -p -r1.272 upload.module --- modules/upload/upload.module 4 Dec 2009 16:49:48 -0000 1.272 +++ modules/upload/upload.module 5 Dec 2009 17:27:11 -0000 @@ -1,706 +0,0 @@ -' . 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.') . ''; - $output .= '' . 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.') . '
'; - $output .= '' . t('For more information, see the online handbook entry for Upload module.', array('@upload' => 'http://drupal.org/handbook/modules/upload/')) . '
'; - return $output; - case 'admin/config/media/uploads': - return '' . t('Users with the upload files permission can upload attachments. Users with the view uploaded files permission can view uploaded attachments. You can choose which post types can take attachments on the content types settings page.', array('@permissions' => url('admin/config/people/permissions'), '@types' => url('admin/structure/types'))) . '
'; - } -} - -/** - * Implements hook_theme(). - */ -function upload_theme() { - return array( - 'upload_attachments' => array( - 'render element' => 'elements', - ), - 'upload_form_current' => array( - 'render element' => 'form', - ), - 'upload_form_new' => array( - 'render element' => 'form', - ), - ); -} - -/** - * Implements hook_permission(). - */ -function upload_permission() { - return array( - 'upload files' => array( - 'title' => t('Upload files for content'), - ), - 'view uploaded files' => array( - 'title' => t('View and download uploaded files'), - ), - ); -} - -/** - * Inject links into $node for attachments. - */ -function upload_node_links($node, $build_mode) { - $links = array(); - - // Display a link with the number of attachments - $num_files = 0; - foreach ($node->files as $file) { - if ((object)$file->list) { - $num_files++; - } - } - if ($num_files) { - $links['upload_attachments'] = array( - 'title' => format_plural($num_files, '1 attachment', '@count attachments'), - 'href' => "node/$node->nid", - 'attributes' => array('title' => t('Read full article to view attachments.')), - 'fragment' => 'attachments' - ); - $node->content['links']['upload_attachments'] = array( - '#theme' => 'links', - '#links' => $links, - '#attributes' => array('class' => array('links', 'inline')), - ); - } -} - -/** - * Implements hook_menu(). - */ -function upload_menu() { - $items['upload/js'] = array( - 'page callback' => 'upload_js', - 'access arguments' => array('upload files'), - 'type' => MENU_CALLBACK, - ); - $items['admin/config/media/uploads'] = array( - 'title' => 'File uploads', - 'description' => 'Control how files may be attached to content.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('upload_admin_settings'), - 'access arguments' => array('administer site configuration'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'upload.admin.inc', - ); - return $items; -} - -/** - * Determine the limitations on files that a given user may upload. The user - * may be in multiple roles so we select the most permissive limitations from - * all of their roles. - * - * @param $user - * A Drupal user object. - * @return - * An associative array with the following keys: - * 'extensions' - * A white space separated string containing all the file extensions this - * user may upload. - * 'file_size' - * The maximum size of a file upload in bytes. - * 'user_size' - * The total number of bytes for all for a user's files. - * 'resolution' - * A string specifying the maximum resolution of images. - */ -function _upload_file_limits($user) { - $file_limit = variable_get('upload_uploadsize_default', 1); - $user_limit = variable_get('upload_usersize_default', 1); - $all_extensions = explode(' ', variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp')); - foreach ($user->roles as $rid => $name) { - $extensions = variable_get("upload_extensions_$rid", variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp')); - $all_extensions = array_merge($all_extensions, explode(' ', $extensions)); - - // A zero value indicates no limit, take the least restrictive limit. - $file_size = variable_get("upload_uploadsize_$rid", variable_get('upload_uploadsize_default', 1)) * 1024 * 1024; - $file_limit = ($file_limit && $file_size) ? max($file_limit, $file_size) : 0; - - $user_size = variable_get("upload_usersize_$rid", variable_get('upload_usersize_default', 1)) * 1024 * 1024; - $user_limit = ($user_limit && $user_size) ? max($user_limit, $user_size) : 0; - } - $all_extensions = implode(' ', array_unique($all_extensions)); - return array( - 'extensions' => $all_extensions, - 'file_size' => $file_limit, - 'user_size' => $user_limit, - 'resolution' => variable_get('upload_max_resolution_x', 0) . 'x' . variable_get('upload_max_resolution_y', 0), - ); -} - -/** - * Implements hook_file_download(). - */ -function upload_file_download($uri) { - $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(); - - if ($file && user_access('view uploaded files') && ($node = node_load($file->nid)) && node_access('view', $node)) { - return array( - 'Content-Type' => $file->filemime, - 'Content-Length' => $file->filesize, - ); - } - else { - return -1; - } -} - -/** - * Save new uploads and store them in the session to be associated to the node - * on upload_save. - * - * @param $node - * A node object to associate with uploaded files. - */ -function upload_node_form_submit(&$form, &$form_state) { - global $user; - - $limits = _upload_file_limits($user); - $validators = array( - 'file_validate_extensions' => array($limits['extensions']), - 'file_validate_image_resolution' => array($limits['resolution']), - 'file_validate_size' => array($limits['file_size'], $limits['user_size']), - ); - - // Save new file uploads. - if (user_access('upload files') && ($file = file_save_upload('upload', $validators, 'public://'))) { - $file->list = variable_get('upload_list_default', 1); - $file->description = $file->filename; - $file->weight = 0; - $file->new = TRUE; - $form['#node']->files[$file->fid] = $file; - $form_state['values']['files'][$file->fid] = (array)$file; - } - - if (isset($form_state['values']['files'])) { - foreach ($form_state['values']['files'] as $fid => $file) { - $form_state['values']['files'][$fid]['new'] = !empty($form['#node']->files[$fid]->new); - } - } - - // Order the form according to the set file weight values. - if (!empty($form_state['values']['files'])) { - $microweight = 0.001; - foreach ($form_state['values']['files'] as $fid => $file) { - if (is_numeric($fid)) { - $form_state['values']['files'][$fid]['#weight'] = $file['weight'] + $microweight; - $microweight += 0.001; - } - } - uasort($form_state['values']['files'], 'element_sort'); - } -} - -function upload_form_alter(&$form, &$form_state, $form_id) { - if ($form_id == 'node_type_form' && isset($form['identity']['type'])) { - $form['workflow']['upload'] = array( - '#type' => 'radios', - '#title' => t('Attachments'), - '#default_value' => variable_get('upload_' . $form['#node_type']->type, 1), - '#options' => array(t('Disabled'), t('Enabled')), - ); - } - - if (!empty($form['#node_edit_form'])) { - $node = $form['#node']; - if (variable_get("upload_$node->type", TRUE)) { - // Attachments fieldset - $form['attachments'] = array( - '#type' => 'fieldset', - '#access' => user_access('upload files'), - '#title' => t('File attachments'), - '#collapsible' => TRUE, - '#collapsed' => empty($node->files), - '#group' => 'additional_settings', - '#attached' => array( - 'js' => array(drupal_get_path('module', 'upload') . '/upload.js'), - ), - '#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.'), - '#weight' => 30, - ); - - // Wrapper for fieldset contents (used by ajax.js). - $form['attachments']['wrapper'] = array(); - - // Make sure necessary directories for upload.module exist and are - // writable before displaying the attachment form. - $path = file_directory_path(); - $temp = file_directory_path('temporary'); - // Note: pass by reference - if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY) || !file_prepare_directory($temp, FILE_CREATE_DIRECTORY)) { - $form['attachments']['#description'] = t('File attachments are disabled. The file directories have not been properly configured.'); - if (user_access('administer site configuration')) { - $form['attachments']['#description'] .= ' ' . t('Please visit the file system configuration page.', array('@admin-file-system' => url('admin/config/media/file-system'))); - } - else { - $form['attachments']['#description'] .= ' ' . t('Please contact the site administrator.'); - } - } - else { - $form['attachments']['wrapper'] += _upload_form($node, $form_state); - } - $form['#submit'][] = 'upload_node_form_submit'; - } - } -} - -/** - * Implements hook_file_load(). - */ -function upload_file_load($files) { - // Add the upload specific data into the file object. - $result = db_query('SELECT * FROM {upload} u WHERE u.fid IN (:fids)', array(':fids' => array_keys($files)))->fetchAll(PDO::FETCH_ASSOC); - foreach ($result as $record) { - foreach ($record as $key => $value) { - $files[$record['fid']]->$key = $value; - } - } -} - -/** - * Implements hook_file_references(). - */ -function upload_file_references($file) { - // If upload.module is still using a file, do not let other modules delete it. - $file_used = (bool) db_query_range('SELECT 1 FROM {upload} WHERE fid = :fid', 0, 1, array(':fid' => $file->fid))->fetchField(); - if ($file_used) { - // Return the name of the module and how many references it has to the file. - return array('upload' => $count); - } -} - -/** - * Implements hook_file_delete(). - */ -function upload_file_delete($file) { - // Delete all information associated with the file. - db_delete('upload')->condition('fid', $file->fid)->execute(); -} - -/** - * Implements hook_node_load(). - */ -function upload_node_load($nodes, $types) { - // Collect all the revision ids for nodes with upload enabled. - $node_vids = array(); - foreach ($nodes as $node) { - if (variable_get("upload_$node->type", 1) == 1) { - $node_vids[$node->vid] = $node->vid; - $node->files = array(); - } - } - // If there are no vids then there's no point trying to load files. - if (empty($node_vids)) { - return; - } - - // Fetch the fids associated with these node revisions. - $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)); - - // The same file may be attached to several nodes (e.g. translated nodes) so - // simply calling db_query()->fetchAllAssoc('fid') would return one node - // per file. Instead we build one array with the file ids for - // file_load_multiple() and another array with upload records so we can match - // files back to the nodes. - $fids = array(); - $uploads = array(); - foreach ($result as $record) { - $fids[] = $record->fid; - $uploads[] = $record; - } - - $files = file_load_multiple($fids); - foreach ($uploads as $upload) { - $nodes[$upload->nid]->files[$upload->fid] = $files[$upload->fid]; - } -} - -/** - * Implements hook_node_view(). - */ -function upload_node_view($node, $build_mode) { - if (!isset($node->files)) { - return; - } - - if (user_access('view uploaded files') && $build_mode != 'rss') { - if (count($node->files)) { - if ($build_mode == 'full') { - // Add the attachments list to node body with a heavy weight to ensure - // they're below other elements. - $node->content['files'] = array( - '#files' => $node->files, - '#theme' => 'upload_attachments', - '#weight' => 50, - ); - } - else { - upload_node_links($node, $build_mode); - } - } - } - - if ($build_mode == 'rss') { - // Add the first file as an enclosure to the RSS item. RSS allows only one - // enclosure per item. See: http://en.wikipedia.org/wiki/RSS_enclosure - foreach ($node->files as $file) { - if ($file->list) { - break; - } - } - if ($file->list) { - $node->rss_elements[] = array( - 'key' => 'enclosure', - 'attributes' => array( - 'url' => file_create_url($file->uri), - 'length' => $file->filesize, - 'type' => $file->filemime - ) - ); - } - } -} - -/** - * Implements hook_node_insert(). - */ -function upload_node_insert($node) { - if (user_access('upload files')) { - upload_save($node); - } -} - -/** - * Implements hook_node_update(). - */ -function upload_node_update($node) { - if (user_access('upload files')) { - upload_save($node); - } -} - -/** - * Implements hook_node_delete(). - */ -function upload_node_delete($node) { - db_delete('upload')->condition('nid', $node->nid)->execute(); - if (!is_array($node->files)) { - return; - } - foreach ($node->files as $file) { - file_delete($file); - } -} - -/** - * Implements hook_node_revision_delete(). - */ -function upload_node_revision_delete($node) { - db_delete('upload')->condition('vid', $node->vid)->execute(); - if (!is_array($node->files)) { - return; - } - foreach ($node->files as $file) { - file_delete($file); - } -} - -/** - * Implements hook_node_search_result(). - */ -function upload_node_search_result($node) { - return isset($node->files) && is_array($node->files) ? format_plural(count($node->files), '1 attachment', '@count attachments') : NULL; -} - -/** - * Displays file attachments in table - * - * @ingroup themeable - */ -function theme_upload_attachments($variables) { - $elements = $variables['elements']; - - $header = array(t('Attachment'), t('Size')); - $rows = array(); - foreach ($elements['#files'] as $file) { - $file = (object)$file; - if ($file->list && empty($file->remove)) { - $href = file_create_url($file->uri); - $text = $file->description ? $file->description : $file->filename; - $rows[] = array(l($text, $href), format_size($file->filesize)); - } - } - if (count($rows)) { - return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('class' => array('attachments')))); - } -} - -/** - * Determine how much disk space is occupied by a user's uploaded files. - * - * @param $uid - * The integer user id of a user. - * @return - * The amount of disk space used by the user in bytes. - */ -function upload_space_used($uid) { - return file_space_used($uid); -} - -/** - * Determine how much disk space is occupied by uploaded files. - * - * @return - * The amount of disk space used by uploaded files in bytes. - */ -function upload_total_space_used() { - return db_query('SELECT SUM(f.filesize) FROM {file} f INNER JOIN {upload} u ON f.fid = u.fid')->fetchField(); -} - -function upload_save($node) { - if (empty($node->files) || !is_array($node->files)) { - return; - } - - foreach ($node->files as $fid => $file) { - // Convert file to object for compatibility - $file = (object)$file; - - // Remove file. Process removals first since no further processing - // will be required. - if (!empty($file->remove)) { - // Remove the reference from this revision. - db_delete('upload')->condition('fid', $file->fid)->condition('vid', $node->vid)->execute(); - // Try a soft delete, if the file isn't used elsewhere it'll be deleted. - file_delete($file); - // Remove it from the session in the case of new uploads, - // that you want to disassociate before node submission. - unset($node->files[$fid]); - // Move on, so the removed file won't be added to new revisions. - continue; - } - - // Create a new revision, or associate a new file needed. - if (!empty($node->old_vid) || $file->new) { - db_insert('upload') - ->fields(array( - 'fid' => $file->fid, - 'nid' => $node->nid, - 'vid' => $node->vid, - 'list' => $file->list, - 'description' => $file->description, - 'weight' => $file->weight, - )) - ->execute(); - } - // Update existing revision. - else { - db_update('upload') - ->fields(array( - 'list' => $file->list, - 'description' => $file->description, - 'weight' => $file->weight, - )) - ->condition('fid', $file->fid, '=') - ->condition('vid', $node->vid, '=') - ->execute(); - } - $file->status |= FILE_STATUS_PERMANENT; - $file = file_save($file); - } -} - -function _upload_form($node, &$form_state) { - global $user; - - $form_state['cache'] = TRUE; - $form = array( - '#theme' => 'upload_form_new', - '#prefix' => '