function _itweak_upload_preprocess_files in iTweak Upload 6.2
Same name and namespace in other branches
- 7.3 itweak_upload.module \_itweak_upload_preprocess_files()
Worker function for preprocessing node & comment files.
Parameters
$files: Array of file objects (descriptors from node).
$thumbnails: Returned array of gallery images.
$files_display: Selects one of the display modes of the attachments.
$setting_name: One of 'upload', 'teaser', 'node' ot 'comment'
$node_type: Node type.
$group: Group name for handler grouping option
Return value
Count of files left in the $files.
2 calls to _itweak_upload_preprocess_files()
- itweak_upload_comment in ./
itweak_upload.module - Implementation of hook_comment(). Add attachments to the comment on view or preview. Here we intercept attachments from comment_upload.module, and render them ourselves. It is critical to be before comment_upload.module in {system} (lower weight).
- itweak_upload_nodeapi in ./
itweak_upload.module - Implementation of hook_nodeapi().
File
- ./
itweak_upload.module, line 981 - iTweakUpload - Tweak attachments display and file upload forms.
Code
function _itweak_upload_preprocess_files(&$files, &$thumbnails, $files_display, $setting_name, $node_type, $group) {
$derivative = _itweak_upload_get_derivative($setting_name, $node_type);
$show_title = _itweak_upload_get_setting('thumbnail_title', '', $node_type, 1);
$show_caption = FALSE;
// FIXME - setting: = variable_get('itweak_upload_thumbnail_caption', 0);
// Build list of attached files and filter out images.
$thumbnails = array();
$cnt_other = 0;
foreach ($files as $fid => $file) {
$file = (object) $file;
if ($file->list && empty($file->remove) && file_exists(file_create_path($file->filepath))) {
// Check if user can download the file - no preview if can't.
// Honor the value already set
$access = isset($file->access) ? $file->access : TRUE;
$filepath = $file->filepath;
$basepath = file_directory_path();
if (strpos($filepath, $basepath) === 0) {
$filepath = substr($filepath, strlen($basepath) + 1);
// Remove base to be consistent with file_download() and
// to not confuse other modules in hook_file_download if file is public
}
// Call hook_file_download regardless of public downloads - accomodate private_upload.module
// Undocumented 2nd argument, TRUE indicates it is just an access check
// Works with download_count.module patched by [#720686] #1
$headers = module_invoke_all('file_download', $filepath, TRUE);
$access = !in_array(-1, $headers);
if (is_object($files[$fid])) {
$files[$fid]->access = $access;
}
else {
$files[$fid]['access'] = $access;
}
$preview = FALSE;
if ($access && $files_display > 1) {
$options = _itweak_upload_get_link_options($file, $setting_name, $node_type, $group);
$preview = module_invoke_all('itweak_upload_preview', $file, $derivative, $show_title, $show_caption, $options);
}
if ($files_display == 1 || !$preview || $preview['#type'] != 'item') {
$cnt_other += 1;
}
else {
if (is_object($files[$fid])) {
$files[$fid]->preview = $preview;
$files[$fid]->preview_options = $options;
}
else {
$files[$fid]['preview'] = $preview;
$files[$fid]['preview_options'] = $options;
}
if ($files_display == 2) {
// Show image with regular files, just use thumbnail
$cnt_other += 1;
}
else {
if ($files_display > 2) {
// Show image in the gallery
$thumbnails[] = (object) $files[$fid];
// Mark file as hidden so image won't appear as attachment, but keep it in the list
if (is_object($files[$fid])) {
$files[$fid]->hidden = true;
}
else {
$files[$fid]['hidden'] = true;
}
}
}
}
}
}
return $cnt_other;
}