t('IMCE file browser'), 'label' => t('File browser'), 'description' => t('Select a file to use from a file browser.'), 'process' => 'filefield_source_imce_process', 'value' => 'filefield_source_imce_value', 'weight' => -1, ); return $source; } /** * Implementation of hook_menu(). */ function filefield_source_imce_menu() { $items = array(); $items['filefield/imce/%/%'] = array( 'page callback' => 'filefield_source_imce_page', 'page arguments' => array(2, 3), 'access callback' => 'filefield_edit_access', 'access arguments' => array(2, 3), 'file' => 'sources/imce.inc', 'type' => MENU_CALLBACK, ); return $items; } /** * Implementation of hook_theme(). */ function filefield_source_imce_theme() { return array( 'filefield_source_imce_element' => array( 'arguments' => array('element' => NULL), 'file' => 'sources/imce.inc', ), ); } /** * Implementation of hook_filefield_source_settings(). */ function filefield_source_imce_settings($op, $field) { $return = array(); // Add settings to the FileField widget form. return $return; } /** * A #process callback to extend the filefield_widget element type. */ function filefield_source_imce_process($element, $edit, &$form_state, $form) { $field = content_fields($element['#field_name'], $element['#type_name']); $element['filefield_imce'] = array( '#weight' => 100.5, '#access' => empty($element['fid']['#value']), '#theme' => 'filefield_source_imce_element', '#description' => filefield_sources_element_validation_help($element['#upload_validators']), ); $filepath_id = $element['#id'] . '-imce-path'; $display_id = $element['#id'] . '-imce-display'; $select_id = $element['#id'] . '-imce-select'; $element['filefield_imce']['file_path'] = array( '#type' => 'hidden', '#value' => '', '#id' => $filepath_id, '#attributes' => array( 'onchange' => "if (!jQuery('#$select_id').attr('disabled')) { jQuery('#$select_id').mousedown().disable(); jQuery('#$display_id').html(this.value); }", ), ); $imce_function = 'window.open(\'' . url('filefield/imce/' . $element['#type_name'] . '/' . $element['#field_name'], array('query' => 'app=' . rawurlencode($field['widget']['label']) . '|url@' . $filepath_id)) . '\', \'\', \'width=760,height=560,resizable=1\'); return false;'; $element['filefield_imce']['display_path'] = array( '#type' => 'markup', '#value' => '' . t('No file selected') . ' (' . t('browse') . ')', ); $element['filefield_imce']['select'] = array( '#type' => 'submit', '#value' => t('Select'), '#submit' => array('node_form_submit_build_node'), '#name' => $element['#name'] . '[filefield_imce][button]', '#id' => $select_id, '#attributes' => array('style' => 'display: none;'), '#ahah' => array( 'path' => 'filefield/ahah/'. $element['#type_name'] .'/'. $element['#field_name'] .'/'. $element['#delta'], 'wrapper' => $element['#id'] .'-ahah-wrapper', 'method' => 'replace', 'effect' => 'fade', ), ); return $element; } /** * A #filefield_value_callback function. */ function filefield_source_imce_value($element, &$item) { if (isset($item['filefield_imce']['file_path']) && $item['filefield_imce']['file_path'] != '') { if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC) { $file_path = preg_replace('/^' . preg_quote(base_path(), '/') . '/', '', $item['filefield_imce']['file_path']); } else { $file_path = preg_replace('/^' . preg_quote(url('system/files'), '/') . '/', file_directory_path(), $item['filefield_imce']['file_path']); } // Resolve the file path to an FID. if ($fid = db_result(db_query("SELECT fid FROM {files} WHERE filepath = '%s'", rawurldecode($file_path)))) { $file = field_file_load($fid); if (filefield_sources_element_validate($element, (object) $file)) { $item = array_merge($item, $file); } } else { form_error($element, t('The selected file could not be used because the file does not exist in the database.')); } // No matter what happens, clear the value from the file path field. $item['filefield_imce']['file_path'] = ''; } } /** * Theme the output of the autocomplete field. */ function theme_filefield_source_imce_element($element) { $output = theme('markup', $element['display_path']) . theme('hidden', $element['file_path']) . theme('submit', $element['select']); return '