View source
<?php
function filebrowser_form_metadata($form_state, $fid) {
$content = _filebrowser_node_content_load($fid);
$node = node_load($content['nid']);
_filebrowser_load_files($node, $fid);
$form['#node'] = $node;
foreach ($node->file_listing as $name => &$file) {
if ($name != '.') {
$form[$file['fid']] = array(
'#type' => 'fieldset',
'#title' => $file['display-name'],
'#tree' => TRUE,
'#collapsible' => FALSE,
'#collapsed' => TRUE,
'#theme' => 'dir_listing_metadata_group',
);
$form[$file['fid']]['thumbnail'] = array(
'#type' => 'markup',
'#value' => _filebrowser_thumbnails_generate($node, $file),
);
foreach (_filebrowser_externals('metadata_info') as $name => $metadata) {
if (isset($metadata['writable']) && $metadata['writable']) {
$form[$file['fid']][$name] = array(
'#type' => 'textarea',
'#title' => $metadata['title'],
'#default_value' => $file[$name],
);
}
}
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('save'),
);
return $form;
}
function filebrowser_form_metadata_submit($form, $form_state) {
foreach ($form['#node']->file_listing as $name => $file) {
if (isset($file['fid']) && isset($form_state['values'][$file['fid']])) {
module_invoke_all('filebrowser_metadata_set', $file, $form_state['values'][$file['fid']]);
}
}
}
function filebrowser_page_delete($fids) {
$files_fid = explode(',', $fids);
return drupal_get_form('filebrowser_form_delete_confirm', $files_fid);
}
function filebrowser_update_thumbnails($fid) {
$content = _filebrowser_node_content_load($fid);
$node = node_load($content['nid']);
_filebrowser_load_files($node, $fid);
$form['#node'] = $node;
$batch = array(
'operations' => array(),
'title' => t('Processing Thumbnail Updating'),
'init_message' => t('Thumbnail updating is starting.'),
'progress_message' => t('Processed @current out of @total thumbnauls.'),
'error_message' => t('Thumbnail updating has encountered an error.'),
);
$thumbnailers = module_implements("filebrowser_thumbnailer_prepare");
foreach ($node->file_listing as $name => &$file) {
foreach ($thumbnailers as $thumbnailer) {
if ($node->file_handlers->{$thumbnailer}->enabled_thumbnailer) {
$operations = module_invoke($thumbnailer, "filebrowser_thumbnailer_prepare", $file, $node->file_handlers->{$thumbnailer});
if ($operations && count($operations)) {
$batch['operations'] = array_merge($batch['operations'], $operations);
}
}
}
}
if (count($batch['operations'])) {
batch_set($batch);
batch_process($_GET['destination']);
}
else {
drupal_set_message("No operation needed for thumbnail updating");
drupal_goto();
}
}