function image_node_import_prepare in Node import 5
Implementation of hook_node_import_prepare().
File
- supported/
image.inc, line 22 - Support for image module.
Code
function image_node_import_prepare(&$node, $preview) {
$errors = array();
if ($node->type == 'image') {
if (empty($node->node_import_images)) {
$errors[] = t('You need to specify an image for this content type.');
unset($node->node_import_images);
}
else {
$filename = $node->node_import_images;
$filepath = variable_get('file_directory_path', 'files') . '/' . variable_get('image_default_path', 'images');
$check = file_create_path($filepath . '/' . $filename);
if (!file_exists($check)) {
$errors[] = t('Image %filename not found. You need to upload it to %filepath first.', array(
'%filename' => $filename,
'%filepath' => $filepath,
));
unset($node->node_import_images);
}
else {
if (!($image_info = image_get_info($check))) {
// Ensure it's a valid image.
$errors[] = t('The file %filename does not appear to be an image.', array(
'%filename' => $filename,
));
unset($node->node_import_images);
}
else {
if (!$preview) {
$filename = $node->node_import_images;
$filepath = variable_get('file_directory_path', 'files') . '/' . variable_get('image_default_path', 'images');
$filepath = file_create_path($filepath . '/' . $filename);
$node->images = array(
IMAGE_ORIGINAL => $filepath,
);
}
}
}
}
}
return $errors;
}