function plupload_imagefield_create_node_from in Plupload integration 6
Helper wrapper around the cck code to create a node of this type. Largely copied from imagefield_import.module
Parameters
$temp_filename: string path to the file
$name: string name to use for the file
Return value
$node a node object.
1 call to plupload_imagefield_create_node_from()
File
- ./
plupload.module, line 251
Code
function plupload_imagefield_create_node_from($temp_filepath, $file_name, $options) {
// Only get files from Drupal's tmp directory.
$directory = file_directory_temp();
if (file_check_location($temp_filepath, $directory)) {
// Only get files where we can get some image info.
if ($info = image_get_info($temp_filepath)) {
// Let the options array override the variable if it's set
// The drupal_ prefix is removed at this point
if (isset($options['plupload_import_field_type'])) {
$plupload_import_field_type = $options['plupload_import_field_type'];
unset($options['plupload_import_field_type']);
}
else {
$plupload_import_field_type = variable_get('plupload_import_field_type', 'photo:::field_photo');
}
// Figure out which node and field to put this into.
list($type, $field_name) = split(':::', $plupload_import_field_type);
// Get the field and its validators.
$field = content_fields($field_name, $type);
$validators = imagefield_widget_upload_validators($field);
// make sure that the directory exists
$directory = filefield_widget_file_path($field);
field_file_check_directory($directory, FILE_CREATE_DIRECTORY);
// Create some defaults that imagefield expects.
$form_state_values = array(
'title' => $file_name,
'body' => '',
'field_photo' => array(
0 => array(
'fid' => 0,
'list' => '1',
'filepath' => '',
'filename' => '',
'filemime' => '',
'filesize' => 0,
'filefield_upload' => 'Upload',
'filefield_remove' => 'Remove',
'upload' => 0,
),
'node_status' => NULL,
),
);
// Save the file and create a node.
if ($file = field_file_save_file($temp_filepath, $validators, $directory)) {
$file['original_path'] = $temp_filepath;
// Add the description if the settings call for it (it can be turned off).
if ($field['description_field'] === '1') {
$file['data']['description'] = '';
}
// Add the default alt and title text if configured to have defaults (they're always 'on').
$file['data']['alt'] = isset($field['widget']['alt']) ? $field['widget']['alt'] : '';
$file['data']['title'] = isset($field['widget']['title']) ? $field['widget']['title'] : '';
// Set list status to default.
$file['list'] = $field['list_field'] === '1' && $field['list_default'] === 0 ? '0' : '1';
$node = _plupload_imagefield_import_create_node($field, $form_state_values, $file, $options);
file_delete($temp_filepath);
}
}
}
return $node;
}