This commit was manufactured as part of Drupal's Great Git Migration to

create tag 'DRUPAL-6--3-1'.

Sprout from master 2009-05-31 20:39:05 UTC Nathan Haug <quicksketch@35821.no-reply.drupal.org> '#477232 by wulff: Adding Danish translation.'
Cherrypick from master 2009-07-03 22:47:08 UTC Nathan Haug <quicksketch@35821.no-reply.drupal.org> '#470090 by DeFr: Don't node_load() to check file deletions on new revisions.':
    filefield.install
    filefield.js
    filefield.module
    filefield_field.inc
    views/filefield.views_convert.inc
parent 20ad4396
......@@ -55,7 +55,8 @@ function filefield_requirements($phase) {
// Report Drupal version
if ($phase == 'runtime') {
$implementation = filefield_progress_implementation();
$apache = strpos($_SERVER["SERVER_SOFTWARE"], 'Apache') !== FALSE;
$apache = strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== FALSE;
$fastcgi = strpos($_SERVER['SERVER_SOFTWARE'], 'mod_fastcgi') !== FALSE || strpos($_SERVER["SERVER_SOFTWARE"], 'mod_fcgi') !== FALSE;
$php_52 = version_compare(phpversion(), '5.2.0', '>');
$description = NULL;
if (!$apache || !$php_52) {
......@@ -63,6 +64,11 @@ function filefield_requirements($phase) {
$description = $t('Your server is not capable of displaying file upload progress. File upload progress requires PHP 5.2 and an Apache server.');
$severity = REQUIREMENT_INFO;
}
elseif ($fastcgi) {
$value = $t('Not enabled');
$description = $t('Your server is not capable of displaying file upload progress. File upload progress requires PHP be run with mod_php and not as FastCGI.');
$severity = REQUIREMENT_INFO;
}
elseif (!$implementation && extension_loaded('apc')) {
$value = $t('Not enabled');
$description = $t('Your server is capable of displaying file upload progress through APC, but it is not enabled. Add <code>apc.rfc1867 = 1</code> to your php.ini configuration. Alternatively, it is recommended to use <a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress</a>, which supports more than one simultaneous upload.');
......
......@@ -42,6 +42,13 @@ Drupal.behaviors.filefieldButtons = function(context) {
.bind('mousedown', Drupal.filefield.progressBar);
};
/**
* Open links to files within the node form in a new window.
*/
Drupal.behaviors.filefieldPreviewLinks = function(context) {
$('div.filefield-element div.widget-preview a').click(Drupal.filefield.openInNewWindow).attr('target', '_blank');
}
/**
* Admin enhancement: only show the "Files listed by default" when needed.
*/
......@@ -117,5 +124,9 @@ Drupal.filefield = {
}, 500);
}
},
openInNewWindow: function(event) {
window.open(this.href, 'filefieldPreview', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=500,height=550');
return false;
}
};
......@@ -10,14 +10,14 @@
*/
// FileField API hooks should always be available.
include_once dirname(__FILE__) .'/field_file.inc';
include_once dirname(__FILE__) . '/field_file.inc';
include_once dirname(__FILE__) . '/filefield_widget.inc';
/**
* Implementation of hook_init().
*/
function filefield_init() {
// File hooks and callbacks may be used by any module.
module_load_include('inc', 'filefield', 'filefield_widget');
drupal_add_css(drupal_get_path('module', 'filefield') .'/filefield.css');
// Conditional module support.
......@@ -120,8 +120,7 @@ function filefield_theme() {
}
/**
* Implementation of hook_file_download(). Yes, *that* hook that causes
* any attempt for file upload module interoperability to fail spectacularly.
* Implementation of hook_file_download().
*/
function filefield_file_download($file) {
$file = file_create_path($file);
......@@ -132,7 +131,7 @@ function filefield_file_download($file) {
return;
}
// Find out if any filefield contains this file, and if so, which field
// Find out if any file field contains this file, and if so, which field
// and node it belongs to. Required for later access checking.
$cck_files = array();
foreach (content_fields() as $field) {
......@@ -155,7 +154,7 @@ function filefield_file_download($file) {
}
}
}
// If no filefield item is involved with this file, we don't care about it.
// If no file field item is involved with this file, we don't care about it.
if (empty($cck_files)) {
return;
}
......@@ -169,37 +168,38 @@ function filefield_file_download($file) {
}
// So the overall field view permissions are not denied, but if access is
// denied for a specific node containing the file, deny the download as well.
// It's probably a little too restrictive, but I can't think of a
// better way at the moment. Input appreciated.
// (And yeah, node access checks also include checking for 'access content'.)
// denied for ALL nodes containing the file, deny the download as well.
// Node access checks also include checking for 'access content'.
$nodes = array();
$denied = FALSE;
foreach ($cck_files as $field_name => $field_files) {
foreach ($field_files as $revision_id => $content) {
// Checking separately for each revision is probably not the best idea -
// what if 'view revisions' is disabled? So, let's just check for the
// current revision of that node.
if (isset($nodes[$content['nid']])) {
continue; // don't check the same node twice
continue; // Don't check the same node twice.
}
$node = node_load($content['nid']);
if (!node_access('view', $node)) {
if ($denied == FALSE && $node = node_load($content['nid']) && node_access('view', $node)) {
// You don't have permission to view the node this file is attached to.
return -1;
$denied = TRUE;
}
$nodes[$content['nid']] = $node;
}
if ($denied) {
return -1;
}
}
// Well I guess you can see this file.
// Access is granted.
$name = mime_header_encode($file->filename);
$type = mime_header_encode($file->filemime);
// Serve images and text inline for the browser to display rather than download.
$disposition = ereg('^(text/|image/)', $file->filemime) ? 'inline' : 'attachment';
// Serve images and text inline for display rather than download.
$disposition = (ereg('^(text/|image/)', $file->filemime) || ereg('flash$', $file->filemime)) ? 'inline' : 'attachment';
return array(
'Content-Type: '. $type .'; name='. $name,
'Content-Length: '. $file->filesize,
'Content-Disposition: '. $disposition .'; filename='. $name,
'Content-Type: ' . $type . '; name='. $name,
'Content-Length: ' . $file->filesize,
'Content-Disposition: ' . $disposition . '; filename="' . $name . '"',
'Cache-Control: private',
);
}
......
......@@ -155,14 +155,15 @@ function filefield_field_update($node, $field, &$items, $teaser, $page) {
}
// If this is a new node there are no old items to worry about.
if ($node->is_new) {
// On new revisions, old files are always maintained in the previous revision.
if ($node->is_new || !empty($node->revision)) {
return;
}
// Delete items from original node if no new revision was created.
// Delete items from original node.
$orig = node_load($node->nid);
// If there are, figure out which ones must go.
if (empty($node->revision) && !empty($orig->$field['field_name'])) {
if (!empty($orig->$field['field_name'])) {
foreach ($orig->$field['field_name'] as $oitem) {
if (isset($oitem['fid']) && !in_array($oitem['fid'], $curfids)) {
// For hook_file_references, remember that this is being deleted.
......
<?php
// $Id$
/**
* @file
* Field conversion for fields handled by this module.
*/
/**
* Implementation of hook_views_convert().
*/
function filefield_views_convert($display, $type, &$view, $field, $id = NULL) {
static $filefield_fields;
static $filefield_filters;
static $filefield_arguments;
if (!isset($filefield_fields)) {
$filefield_fields = $filefield_filters = $filefield_arguments = array();
foreach (content_fields() as $content_field) {
if ($content_field['module'] == 'filefield') {
$result = module_invoke('filefield', 'field_settings', 'views data', $content_field);
if (!empty($result)) {
foreach ($result as $table => $fields) {
unset($fields['table']);
foreach ($fields as $filefield_field => $definition) {
switch ($filefield_field) {
case $content_field['field_name'] .'_fid':
$filefield_fields[$filefield_field] = array(
'table' => $table,
'field' => $filefield_field,
);
$filefield_arguments['content: '. $content_field['field_name']] = &$filefield_fields[$filefield_field];
break;
case $content_field['field_name'] .'_list':
$filefield_filters[$content_field['field_name'] .'_fid_not null'] = array(
'table' => $table,
'field' => $filefield_field,
);
break;
}
}
}
}
}
}
}
switch ($type) {
case 'field':
if (isset($filefield_fields[$field['field']])) {
$multiple = array();
switch ($field['handler']) {
case 'content_views_field_handler_ungroup':
$view->set_item_option($display, 'field', $id, 'multiple', array('group' => FALSE));
break;
case 'content_views_field_handler_last':
$multiple['multiple_reversed'] = TRUE;
case 'content_views_field_handler_first':
$multiple['multiple_number'] = 1;
$view->set_item_option($display, 'field', $id, 'multiple', $multiple);
break;
}
$view->set_item_option($display, 'field', $id, 'format', $field['options']);
}
break;
case 'filter':
if (isset($filefield_filters[$field['field']])) {
$filter = $filefield_filters[$field['field']];
$item = $view->get_item($display, 'filter', $id);
$item['value'] = $field['value'];
$item['table'] = $filter['table'];
$item['field'] = $filter['field'];
$view->set_item($display, 'filter', $id, $item);
}
break;
case 'argument':
if (isset($filefield_arguments[$field['type']])) {
$argument = $filefield_arguments[$field['type']];
$options = $field['argoptions'];
$view->add_item($display, 'argument', $argument['table'], $argument['field'], $options, $field['id']);
}
break;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment