function _itweak_upload_preprocess_files in iTweak Upload 7.3
Same name and namespace in other branches
- 6.2 itweak_upload.module \_itweak_upload_preprocess_files()
Worker function for preprocessing filefield files.
Parameters
$files: Array of file objects (descriptors from filefield).
$thumbnails: Returned array of gallery images.
$display: $display parameter from hook_field_formatter_view().
$entity_type: $entity_type parameter from hook_field_formatter_view().
$entity: $entity parameter from hook_field_formatter_view().
$field_type: Field type to pass as 2nd arg to hook_file_download()
Return value
Count of files left in the $files.
1 call to _itweak_upload_preprocess_files()
- itweak_upload_field_formatter_view in ./
itweak_upload.module - Implements hook_field_formatter_view().
File
- ./
itweak_upload.module, line 1051 - iTweakUpload - Tweak attachments display and file upload forms.
Code
function _itweak_upload_preprocess_files(&$files, &$thumbnails, $display, $entity_type, $entity, $field_type = 'file') {
//drupal_set_message('DEBUG _itweak_upload_preprocess_files display=<pre>'.htmlentities(print_r($display,1)).'</pre>');
$settings = $display['settings'];
$files_display_mode = $settings['files_display_mode'];
$thumbnail_style = $settings['thumbnail_style'];
$open_image_style = $settings['open_image_style'];
$show_title = $settings['show_title'];
$show_caption = $settings['show_caption'];
// Build list of attached files and filter out images.
$thumbnails = array();
$cnt_other = 0;
foreach ($files as $delta => $file) {
//drupal_set_message('DEBUG 1 delta='.$delta.' file=<pre>'.htmlentities(print_r($file,1)).'</pre>');
$file = (object) $file;
if (!isset($file->display)) {
$file->display = TRUE;
}
// imagefield does not have display property
if ($file->display && empty($file->remove) && file_exists($file->uri)) {
$file->lightbox_supported = _itweak_upload_lightbox_supported($file, $open_image_style);
if (empty($file->filemime)) {
$file->filemime = file_get_mimetype($file->uri);
}
// Check if user can download the file - no preview if can't.
// Honor the value already set
if (!isset($file->access)) {
$file->access = TRUE;
}
// Call hook_file_download regardless of public downloads - accomodate private_upload.module
// Undocumented 2nd argument is $field_type in file_file_download()
// Undocumented 3rd argument, TRUE indicates it is just an access check
// Works with download_count.module patched by [#720686] #1
$headers = module_invoke_all('file_download', $file->uri, $field_type, TRUE);
//drupal_set_message('DEBUG 2 headers=<pre>'.htmlentities(print_r($headers,1)).'</pre>');
if (in_array(-1, $headers) || empty($headers)) {
$file->access = FALSE;
}
if ($file->lightbox_supported && $open_image_style != '_original' && $open_image_style != '_none') {
$file->path = $open_image_style != '' ? image_style_url($open_image_style, $file->uri) : file_create_url($file->uri);
}
$preview = FALSE;
if ($file->access && $files_display_mode > ITU_DISPLAY_ALL_FILES_NO_THUMBNAILS) {
if ($file->lightbox_supported && $open_image_style != '_none') {
$options = _itweak_upload_lightbox_get_link_options($file, $display, $entity_type, $entity);
}
else {
$options = array();
}
$preview = module_invoke_all('itweak_upload_preview', $file, $thumbnail_style, $show_title, $show_caption, $options);
}
//drupal_set_message('DEBUG 3 delta='.$delta.' cnt_other='.$cnt_other.' file=<pre>'.htmlentities(print_r($file,1)).'</pre>');
if ($files_display_mode == ITU_DISPLAY_ALL_FILES_NO_THUMBNAILS || !$preview || $preview['#type'] != 'item') {
$cnt_other += 1;
// Leave in the files list
}
else {
$file->preview = $preview;
$file->preview_options = $options;
if ($files_display_mode == ITU_DISPLAY_ALL_FILES_WITH_THUMBNAILS) {
// Show image with regular files, just use thumbnail
$cnt_other += 1;
}
else {
if ($files_display_mode > ITU_DISPLAY_ALL_FILES_WITH_THUMBNAILS) {
// Show image in the gallery
$thumbnails[] = $file;
// Mark file as hidden so image won't appear as attachment, but keep it in the list
$file->hidden = true;
}
}
}
//drupal_set_message('DEBUG 4 delta='.$delta.' cnt_other='.$cnt_other.' file=<pre>'.htmlentities(print_r($file,1)).'</pre>');
}
if (is_object($files[$delta])) {
$files[$delta] = $file;
}
else {
$files[$delta] = (array) $file;
}
}
//drupal_set_message('DEBUG 5 cnt_other='.$cnt_other.' settings=<pre>'.htmlentities(print_r($settings,1)).'</pre> files=<pre>'.htmlentities(print_r($files,1)).'</pre><br> thumbnails=<pre>'.htmlentities(print_r($thumbnails,1)).'</pre>');
return $cnt_other;
}