summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-12-06 00:27:40 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-12-06 00:27:40 +0000
commit882fa0ab33cec0aaa9ebe942cbfe759fcf8f4a4e (patch)
tree5364772baa2f9851876bff7f04437bae0fec8123 /modules
parentbb460ee72782448df391e00b881beca3e5f254b5 (diff)
downloadbrdo-882fa0ab33cec0aaa9ebe942cbfe759fcf8f4a4e.tar.gz
brdo-882fa0ab33cec0aaa9ebe942cbfe759fcf8f4a4e.tar.bz2
#563000 by drewish, quicksketch, catch, and yched: DIE upload module, DIE! Long live File module! :D
Diffstat (limited to 'modules')
-rw-r--r--modules/upload/upload.admin.css19
-rw-r--r--modules/upload/upload.admin.inc175
-rw-r--r--modules/upload/upload.info12
-rw-r--r--modules/upload/upload.install133
-rw-r--r--modules/upload/upload.js14
-rw-r--r--modules/upload/upload.module706
-rw-r--r--modules/upload/upload.test234
-rw-r--r--modules/upload/upload.tokens.inc45
8 files changed, 0 insertions, 1338 deletions
diff --git a/modules/upload/upload.admin.css b/modules/upload/upload.admin.css
deleted file mode 100644
index f8fc34b4e..000000000
--- a/modules/upload/upload.admin.css
+++ /dev/null
@@ -1,19 +0,0 @@
-/* $Id$ */
-
-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;
-}
diff --git a/modules/upload/upload.admin.inc b/modules/upload/upload.admin.inc
deleted file mode 100644
index 759cde460..000000000
--- a/modules/upload/upload.admin.inc
+++ /dev/null
@@ -1,175 +0,0 @@
-<?php
-// $Id$
-
-/**
- * @file
- * This file creates the administration form for the upload module.
- */
-
-/**
- * Form API callback to validate the upload settings form.
- */
-function upload_admin_settings_validate($form, &$form_state) {
- if (!is_numeric($form_state['values']['upload_max_resolution_x'])) {
- form_set_error('upload_max_resolution_x', t('The maximum allowed image width should be entered as a numeric value. Set to 0 for no restriction.'));
- }
- if (!is_numeric($form_state['values']['upload_max_resolution_y'])) {
- form_set_error('upload_max_resolution_y', t('The maximum allowed image height should be entered as a numeric value. Set to 0 for no restriction.'));
- }
-
- $default_uploadsize = $form_state['values']['upload_uploadsize_default'];
- $default_usersize = $form_state['values']['upload_usersize_default'];
-
- $exceed_max_msg = t('Your PHP settings limit the maximum file size per upload to %size.', array('%size' => format_size(file_upload_max_size()))) . '<br/>';
- $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 <a href="!image-toolkit-link">image toolkit</a> is installed, files exceeding this value will be scaled down to fit.', array('!image-toolkit-link' => url('admin/config/media/image-toolkit'))),
- '#prefix' => '<div class="form-item-wrapper form-item-resolution">',
- '#suffix' => '</div>',
- );
- $form['settings_general']['upload_max_resolution']['upload_max_resolution_x'] = array(
- '#type' => 'textfield',
- '#title' => t('Width'),
- '#default_value' => variable_get('upload_max_resolution_x', 0),
- '#size' => 5,
- '#maxlength' => 5,
- '#field_suffix' => t('x'),
- );
- $form['settings_general']['upload_max_resolution']['upload_max_resolution_y'] = array(
- '#type' => 'textfield',
- '#title' => t('Height'),
- '#default_value' => variable_get('upload_max_resolution_y', 0),
- '#size' => 5,
- '#maxlength' => 5,
- '#field_suffix' => t('px'),
- );
- $form['settings_general']['upload_list_default'] = array(
- '#type' => 'select',
- '#title' => t('List files by default'),
- '#default_value' => variable_get('upload_list_default', 1),
- '#options' => array(0 => t('No'), 1 => t('Yes')),
- '#description' => t('Display attached files when viewing a post.'),
- );
-
- $form['settings_general']['upload_extensions_default'] = array(
- '#type' => 'textfield',
- '#title' => t('Default permitted file extensions'),
- '#default_value' => $upload_extensions_default,
- '#maxlength' => 255,
- '#description' => t('Default extensions that users can upload. Separate extensions with a space and do not include the leading dot.'),
- );
- $form['settings_general']['upload_uploadsize_default'] = array(
- '#type' => 'textfield',
- '#title' => t('Default maximum file size per upload'),
- '#default_value' => $upload_uploadsize_default,
- '#size' => 5,
- '#maxlength' => 5,
- '#description' => t('The default maximum file size 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_general']['upload_usersize_default'] = array(
- '#type' => 'textfield',
- '#title' => t('Default total file size per user'),
- '#default_value' => $upload_usersize_default,
- '#size' => 7,
- '#maxlength' => 7,
- '#description' => t('The default maximum size of all files a user can have on the site. Set to 0 for no restriction. The least restrictive limit is used, so setting this to 0 will disable any role-specific total file size limits.'),
- '#field_suffix' => t('MB'),
- );
-
- $form['settings_general']['upload_max_size'] = array('#markup' => '<p>' . t('Your PHP settings limit the maximum file size per upload to %size.', array('%size' => format_size(file_upload_max_size()))) . '</p>');
-
- $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);
-}
diff --git a/modules/upload/upload.info b/modules/upload/upload.info
deleted file mode 100644
index 5111bde9e..000000000
--- a/modules/upload/upload.info
+++ /dev/null
@@ -1,12 +0,0 @@
-; $Id$
-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
diff --git a/modules/upload/upload.install b/modules/upload/upload.install
deleted file mode 100644
index 0e4637eee..000000000
--- a/modules/upload/upload.install
+++ /dev/null
@@ -1,133 +0,0 @@
-<?php
-// $Id$
-
-/**
- * @file
- * Install, update and uninstall functions for the upload module.
- */
-
-/**
- * @file
- * This is the install file for the upload module.
- */
-
-/**
- * Implements hook_schema().
- */
-function upload_schema() {
- $schema['upload'] = array(
- 'description' => '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']);
-}
-
diff --git a/modules/upload/upload.js b/modules/upload/upload.js
deleted file mode 100644
index 1aae5d1b7..000000000
--- a/modules/upload/upload.js
+++ /dev/null
@@ -1,14 +0,0 @@
-// $Id$
-
-(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);
diff --git a/modules/upload/upload.module b/modules/upload/upload.module
deleted file mode 100644
index 12feedac0..000000000
--- a/modules/upload/upload.module
+++ /dev/null
@@ -1,706 +0,0 @@
-<?php
-// $Id$
-
-/**
- * @file
- * File-handling and attaching files to nodes.
- *
- */
-
-/**
- * Implements hook_help().
- */
-function upload_help($path, $arg) {
- switch ($path) {
- case 'admin/help#upload':
- $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>';
- $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>';
- $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>';
- return $output;
- case 'admin/config/media/uploads':
- 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>';
- }
-}
-
-/**
- * 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 <a href="@admin-file-system">file system configuration page</a>.', 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' => '<div id="attach-wrapper">',
- '#suffix' => '</div>',
- );
-
- if (!empty($node->files) && is_array($node->files)) {
- $form['files']['#theme'] = 'upload_form_current';
- $form['files']['#tree'] = TRUE;
- foreach ($node->files as $file) {
- $file = (object)$file;
- $key = $file->fid;
-
- $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>');
- $form['files'][$key]['size'] = array('#markup' => format_size($file->filesize));
- $form['files'][$key]['remove'] = array('#type' => 'checkbox', '#default_value' => !empty($file->remove));
- $form['files'][$key]['list'] = array('#type' => 'checkbox', '#default_value' => $file->list);
- $form['files'][$key]['weight'] = array('#type' => 'weight', '#delta' => count($node->files), '#default_value' => $file->weight);
- $form['files'][$key]['filename'] = array('#type' => 'value', '#value' => $file->filename);
- $form['files'][$key]['uri'] = array('#type' => 'value', '#value' => $file->uri);
- $form['files'][$key]['filemime'] = array('#type' => 'value', '#value' => $file->filemime);
- $form['files'][$key]['filesize'] = array('#type' => 'value', '#value' => $file->filesize);
- $form['files'][$key]['fid'] = array('#type' => 'value', '#value' => $file->fid);
- $form['files'][$key]['new'] = array('#type' => 'value', '#value' => FALSE);
- }
- }
-
- if (user_access('upload files')) {
- $limits = _upload_file_limits($user);
-
- $limit_description = t('The maximum size of file uploads is %filesize.', array('%filesize' => format_size($limits['file_size']))) . ' ';
- if (!empty($limits['resolution'])) {
- if (image_get_toolkit()) {
- $limit_description .= t('Images larger than %resolution will be resized.', array('%resolution' => $limits['resolution'])) . ' ';
- }
- else {
- $limit_description .= t('Images may not be larger than %resolution.', array('%resolution' => $limits['resolution'])) . ' ';
- }
- }
- $limit_description .= t('Only files with the following extensions may be uploaded: %extensions.', array('%extensions' => $limits['extensions'])) . ' ';
-
- $form['new']['#weight'] = 10;
- $form['new']['upload'] = array(
- '#type' => 'file',
- '#title' => t('Attach new file'),
- '#size' => 40,
- '#description' => $limit_description,
- );
- $form['new']['attach'] = array(
- '#type' => 'submit',
- '#value' => t('Attach'),
- '#name' => 'attach',
- '#ajax' => array(
- 'path' => 'upload/js',
- 'wrapper' => 'attach-wrapper',
- 'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
- ),
- '#submit' => array('node_form_submit_build_node'),
- );
- }
-
- return $form;
-}
-
-/**
- * Theme the attachments list.
- *
- * @ingroup themeable
- */
-function theme_upload_form_current($variables) {
- $form = $variables['form'];
-
- $header = array('', t('Delete'), t('List'), t('Description'), t('Weight'), t('Size'));
- drupal_add_tabledrag('upload-attachments', 'order', 'sibling', 'upload-weight');
-
- foreach (element_children($form) as $key) {
- // Add class to group weight fields for drag and drop.
- $form[$key]['weight']['#attributes']['class'] = array('upload-weight');
-
- $row = array('');
- $row[] = drupal_render($form[$key]['remove']);
- $row[] = drupal_render($form[$key]['list']);
- $row[] = drupal_render($form[$key]['description']);
- $row[] = drupal_render($form[$key]['weight']);
- $row[] = drupal_render($form[$key]['size']);
- $rows[] = array('data' => $row, 'class' => array('draggable'));
- }
- $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'upload-attachments')));
- $output .= drupal_render_children($form);
- return $output;
-}
-
-/**
- * Theme the attachment form.
- * Note: required to output prefix/suffix.
- *
- * @ingroup themeable
- */
-function theme_upload_form_new($variables) {
- drupal_add_tabledrag('upload-attachments', 'order', 'sibling', 'upload-weight');
- $output = drupal_render_children($variables['form']);
- return $output;
-}
-
-/**
- * Menu-callback for JavaScript-based uploads.
- */
-function upload_js() {
- $cached_form_state = array();
- $files = array();
-
- // Load the form from the Form API cache.
- if (!($cached_form = form_get_cache($_POST['form_build_id'], $cached_form_state)) || !isset($cached_form['#node']) || !isset($cached_form['attachments'])) {
- form_set_error('form_token', t('Validation error, please try again. If this error persists, please contact the site administrator.'));
- $output = theme('status_messages');
- print drupal_json_encode(array('status' => TRUE, 'data' => $output));
- drupal_exit();
- }
-
- $form_state = array('values' => $_POST);
-
- // Handle new uploads, and merge tmp files into node-files.
- upload_node_form_submit($cached_form, $form_state);
-
- if (!empty($form_state['values']['files'])) {
- foreach ($form_state['values']['files'] as $fid => $file) {
- if (isset($cached_form['#node']->files[$fid])) {
- $files[$fid] = $cached_form['#node']->files[$fid];
- }
- }
- }
-
- $node = $cached_form['#node'];
-
- $node->files = $files;
-
- $form = _upload_form($node, $form_state);
-
- unset($cached_form['attachments']['wrapper']['new']);
- $cached_form['attachments']['wrapper'] = array_merge($cached_form['attachments']['wrapper'], $form);
-
- $cached_form['attachments']['#collapsed'] = FALSE;
-
- form_set_cache($_POST['form_build_id'], $cached_form, $cached_form_state);
-
- foreach ($files as $fid => $file) {
- if (is_numeric($fid)) {
- $form['files'][$fid]['description']['#default_value'] = $form_state['values']['files'][$fid]['description'];
- $form['files'][$fid]['list']['#default_value'] = !empty($form_state['values']['files'][$fid]['list']);
- $form['files'][$fid]['remove']['#default_value'] = !empty($form_state['values']['files'][$fid]['remove']);
- $form['files'][$fid]['weight']['#default_value'] = $form_state['values']['files'][$fid]['weight'];
- }
- }
-
- // Render the form for output.
- $form += array(
- '#tree' => FALSE,
- '#parents' => array(),
- );
- $form_state = array('submitted' => FALSE, 'programmed' => FALSE, 'process_input' => FALSE, 'complete form' => FALSE);
- $form_id = 'upload_js';
- drupal_alter('form', $form, $form_state, $form_id);
- $form = form_builder('upload_js', $form, $form_state);
- $output = theme('status_messages') . drupal_render($form);
-
- $commands = array();
- $commands[] = ajax_command_replace(NULL, $output);
-
- // AJAX uploads use an <iframe> and some browsers have problems with the
- // 'text/javascript' Content-Type header with iframes. Passing FALSE to
- // ajax_render() prevents the header from being sent.
- ajax_render($commands, FALSE);
-}
diff --git a/modules/upload/upload.test b/modules/upload/upload.test
deleted file mode 100644
index 31873acc9..000000000
--- a/modules/upload/upload.test
+++ /dev/null
@@ -1,234 +0,0 @@
-<?php
-// $Id$
-
-/**
- * @file
- * This file contains tests for the upload module.
- */
-
-
-class UploadTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Upload functionality',
- 'description' => 'Check content uploaded to nodes.',
- 'group' => 'Upload',
- );
- }
-
- function setUp() {
- parent::setUp('upload');
- }
-
- /**
- * Create node; upload files to node; and edit, and delete uploads.
- */
- function testNodeUpload() {
- global $base_url;
- $admin_user = $this->drupalCreateUser(array('administer site configuration'));
- $web_user = $this->drupalCreateUser(array('access content', 'edit own page content', 'upload files', 'view uploaded files'));
-
- $this->drupalLogin($admin_user);
-
- // Setup upload settings.
- $edit = array();
- $edit['upload_list_default'] = '1'; // Yes.
- $edit['upload_extensions_default'] = 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp';
- $edit['upload_uploadsize_default'] = '1.5';
- $edit['upload_usersize_default'] = '1.5';
- $this->drupalPost('admin/config/media/uploads', $edit, t('Save configuration'));
- $this->assertText('The configuration options have been saved.', 'Upload setting saved.');
-
- $this->drupalLogout();
- $this->drupalLogin($web_user);
-
- // Create a node and attempt to attach files.
- $node = $this->drupalCreateNode();
- $text_files = $this->drupalGetTestFiles('text');
- $files = array(current($text_files)->uri, next($text_files)->uri);
-
- $this->uploadFile($node, $files[0]);
- $this->uploadFile($node, $files[1]);
-
- // Check to see that uploaded file is listed in detail page and actually accessible.
- $this->assertText(basename($files[0]), basename($files[0]) . ' found on node.');
- $this->assertText(basename($files[1]), basename($files[1]) . ' found on node.');
-
- $this->checkUploadedFile(basename($files[0]));
- $this->checkUploadedFile(basename($files[1]));
-
- // Check that files are also accessible when using private files.
- variable_set('file_default_scheme', 'private');
- $this->checkUploadedFile(basename($files[0]));
- $this->checkUploadedFile(basename($files[1]));
-
- // Assure that the attachment link appears on teaser view and has correct count.
- $node = node_load($node->nid);
- $teaser = drupal_render(node_build($node, 'teaser'));
- $this->assertTrue(strpos($teaser, format_plural(2, '1 attachment', '@count attachments')), 'Attachments link found on node teaser.');
-
- // Fetch db record and use fid to rename and delete file.
- $upload = db_query('SELECT fid, description FROM {upload} WHERE nid = :nid', array(':nid' => $node->nid))->fetchObject();
- if ($upload) {
- // Rename file.
- $edit = array();
- $edit['files[' . $upload->fid . '][description]'] = $new_name = substr($upload->description, 1);
- $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- $this->assertRaw(t('Page %title has been updated.', array('%title' => $node->title[LANGUAGE_NONE][0]['value'])), 'File renamed successfully.');
-
- $this->assertText($new_name, $new_name . ' found on node.');
- $this->assertNoText($upload->description, $upload->description . ' not found on node.');
-
- // Delete a file.
- $edit = array();
- $edit['files[' . $upload->fid . '][remove]'] = TRUE;
- $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- $this->assertRaw(t('Page %title has been updated.', array('%title' => $node->title[LANGUAGE_NONE][0]['value'])), 'File deleted successfully.');
-
- $this->assertNoText($new_name, $new_name . ' not found on node.');
- $uri = 'public://' . $upload->description;
- $external_uri = file_stream_wrapper_get_instance_by_uri($uri)->getExternalUrl();
- $this->drupalGet($external_uri, array('external' => TRUE));
- $this->assertResponse(array(404), 'Uploaded ' . $upload->description . ' is not accessible.');
- }
- else {
- $this->fail('File upload record not found in database.');
- }
- }
-
- /**
- * Ensure the the file filter works correctly by attempting to upload a non-allowed file extension.
- */
- function testFilesFilter() {
- $admin_user = $this->drupalCreateUser(array('administer site configuration'));
- $web_user = $this->drupalCreateUser(array('access content', 'edit own page content', 'upload files', 'view uploaded files'));
-
- $this->drupalLogin($admin_user);
-
- // Setup upload settings.
- $settings = array();
- $settings['upload_list'] = '1'; // Yes.
- $settings['upload_extensions'] = 'html';
- $settings['upload_uploadsize'] = '1';
- $settings['upload_usersize'] = '1';
- $this->setUploadSettings($settings, $this->getSimpletestRoleId($web_user));
-
- $this->drupalLogin($web_user);
-
- $node = $this->drupalCreateNode();
-
- // Attempt to upload .txt file when .html is only extension allowed.
- $text_file = current($this->drupalGetTestFiles('text'));
- // Select a file that's less than the 1MB upload limit so we only test one
- // limit at a time.
- $this->uploadFile($node, $text_file->uri, FALSE);
- // Test the error message in two steps in case there are additional errors
- // that change the error message's format.
- $this->assertRaw(t('The specified file %name could not be uploaded.', array('%name' => $text_file->filename)), t('File %filepath was not allowed to be uploaded', array('%filepath' => $text_file->uri)));
- $this->assertRaw(t('Only files with the following extensions are allowed: %files-allowed.', array('%files-allowed' => $settings['upload_extensions'])), t('File extension cited as reason for failure'));
-
- // Attempt to upload .html file when .html is only extension allowed.
- $html_files = array_values($this->drupalGetTestFiles('html'));
- // Use the HTML file with the .html extension, $html_files[0] has a .txt
- // extension.
- $html_file = $html_files[1]->uri;
- $this->uploadFile($node, $html_file);
- $this->assertNoRaw(t('The specified file %name could not be uploaded.', array('%name' => basename($html_file))), t('File ' . $html_file . ' was allowed to be uploaded'));
- }
-
- /**
- * Attempt to upload a file that is larger than the maxsize and see that it fails.
- */
- function testLimit() {
- $files = $this->drupalGetTestFiles('text', 1310720); // 1 MB.
- $file = current($files)->uri;
-
- $admin_user = $this->drupalCreateUser(array('administer site configuration'));
- $web_user = $this->drupalCreateUser(array('access content', 'edit own page content', 'upload files', 'view uploaded files'));
-
- $this->drupalLogin($admin_user);
-
- // Setup upload settings.
- $settings = array();
- $settings['upload_list'] = '1'; // Yes.
- $settings['upload_extensions'] = 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp';
- $settings['upload_uploadsize'] = '0.5';
- $settings['upload_usersize'] = '1.5';
- $this->setUploadSettings($settings, $this->getSimpletestRoleId($web_user));
-
- $this->drupalLogin($web_user);
-
- $node = $this->drupalCreateNode();
-
- // Attempt to upload file which is bigger than the maximum size of 0.5 MB.
- $this->uploadFile($node, $file, FALSE);
-
- $info = stat($file);
- $filename = basename($file);
- $filesize = format_size($info['size']);
- $maxsize = format_size(parse_size(($settings['upload_uploadsize'] * 1024) . 'KB')); // Won't parse decimals.
- // Test the error message in two steps in case there are additional errors
- // that change the error message's format.
- $this->assertRaw(t('The specified file %name could not be uploaded.', array('%name' => $filename)), t('File upload was blocked'));
- $this->assertRaw(t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => $filesize, '%maxsize' => $maxsize)), t('File size cited as problem with upload'));
- }
-
- function setUploadSettings($settings, $rid = NULL) {
- $edit = array();
- foreach ($settings as $key => $value) {
- $edit[$key . '_default'] = $value;
- if ($rid !== NULL && $key != 'upload_list' && $key != 'upload_max_resolution_x' && $key != 'upload_max_resolution_y') {
- $edit[$key . '_' . $rid] = $value;
- }
- }
- $this->drupalPost('admin/config/media/uploads', $edit, 'Save configuration');
- $this->assertText('The configuration options have been saved.', 'Upload setting saved.');
- }
-
- /**
- * Upload file to specified node.
- *
- * @param object $node Node object.
- * @param string $filename Name of file to upload.
- * @param boolean $assert Assert that the node was successfully updated.
- */
- function uploadFile($node, $filename, $assert = TRUE) {
- $edit = array();
- $edit['files[upload]'] = $filename; //edit-upload
- $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- if ($assert) {
- $this->assertRaw(t('Page %title has been updated.', array('%title' => $node->title[LANGUAGE_NONE][0]['value'])), 'File attached successfully.');
- }
- }
-
- /**
- * Check that uploaded file is accessible and verify the contents against the original.
- *
- * @param string $filename Name of file to verify.
- */
- function checkUploadedFile($filename) {
- $file = 'public://' . $filename;
- $this->drupalGet(file_create_url($file), array('external' => TRUE));
- $this->assertResponse(array(200), 'Uploaded ' . $filename . ' is accessible.');
- $this->assertTrue(strpos($this->drupalGetHeader('Content-Type'), 'text/plain') === 0, t('MIME type is text/plain.'));
- $this->assertEqual(file_get_contents($file), $this->drupalGetContent(), 'Uploaded contents of ' . $filename . ' verified.');
- // Verify file actually is readable and writeable by PHP.
- $this->assertTrue(is_readable($file), t('Uploaded file is readable.'));
- $this->assertTrue(is_writeable($file), t('Uploaded file is writeable.'));
- }
-
- /**
- * Get the role id of the 'simpletest' role associated with a SimpleTest test user.
- *
- * @param object $user User object.
- * @return integer SimpleTest role id.
- */
- function getSimpletestRoleId($user) {
- foreach ($user->roles as $rid => $role) {
- if (preg_match('/s\d+/', $role)) {
- return $rid;
- }
- }
- return NULL;
- }
-}
diff --git a/modules/upload/upload.tokens.inc b/modules/upload/upload.tokens.inc
deleted file mode 100644
index 3fa28ee2d..000000000
--- a/modules/upload/upload.tokens.inc
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-// $Id$
-
-/**
- * @file
- * Builds placeholder replacement tokens for uploaded files attached to nodes.
- */
-
-/**
- * Implements hook_token_info().
- */
-function upload_token_info() {
- $results['tokens']['node'] = array(
- 'upload' => array(
- 'name' => t('File attachment'),
- 'description' => t('The first file attached to a node, if one exists.'),
- 'type' => 'file',
- )
- );
- return $results;
-}
-
-/**
- * Implements hook_tokens().
- */
-function upload_tokens($type, $tokens, array $data = array(), array $options = array()) {
- $replacements = array();
-
- if ($type == 'node' && !empty($data['node'])) {
- $node = $data['node'];
-
- foreach ($tokens as $name => $original) {
- if ($name == 'upload') {
- $upload = array_shift($node->files);
- $replacements[$original] = file_create_url($upload->filepath);
- }
- }
-
- if (($upload_tokens = token_find_with_prefix($tokens, 'upload')) && !empty($node->files) && $upload = array_shift($node->files)) {
- $replacements += token_generate('file', $upload_tokens, array('file' => $upload), $options);
- }
- }
-
- return $replacements;
-}