aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2010-10-07 16:23:11 -0300
committerSilvio <silvio@devlet.com.br>2010-10-07 16:23:11 -0300
commit56d80e671b12e01acdf0cbc1ab3d704f89e0c35e (patch)
treecbff36bc68fb92d39e02fbcf2cea57467bffc227
parent80cc0b5f30b07529dd383fe1d9902f638a5f6048 (diff)
downloadmass_image_import-56d80e671b12e01acdf0cbc1ab3d704f89e0c35e.tar.gz
mass_image_import-56d80e671b12e01acdf0cbc1ab3d704f89e0c35e.tar.bz2
Adding mass_image_import_create_node_from()
-rw-r--r--mass_image_import.module60
1 files changed, 59 insertions, 1 deletions
diff --git a/mass_image_import.module b/mass_image_import.module
index d86ce64..9c20982 100644
--- a/mass_image_import.module
+++ b/mass_image_import.module
@@ -168,7 +168,8 @@ function mass_image_import_file($file) {
}
// Create the node object.
- if ($node = image_create_node_from($args['filepath'], $args['title'], $args['body'], $args['taxonomy'])) {
+ //if ($node = image_create_node_from($args['filepath'], $args['title'], $args['body'], $args['taxonomy'])) {
+ if ($node = mass_image_import_create_node_from($args['filepath'], $args['title'], $args['body'], $args['taxonomy'])) {
// Remove the original image now that the import has completed.
file_delete($args['filepath']);
}
@@ -198,3 +199,60 @@ function mass_image_import_batch_finished($success, $results, $operations) {
watchdog('image', 'Finished mass image import.');
drupal_set_message($message);
}
+
+/**
+ * Create an image entry. Contains some code from image_create_node_from().
+ *
+ * @see http://drupal.org/node/330421
+ * @todo
+ * Mime, content type, field name, taxonomy, etc.
+ */
+function mass_image_import_create_node_from($filepath, $title, $body, $taxonomy) {
+
+ $mime = 'image/jpeg';
+
+ // Make sure we can copy the file into our temp directory.
+ $original_path = $filepath;
+ if (!file_copy($filepath, _image_filename($filepath, IMAGE_ORIGINAL, TRUE))) {
+ return FALSE;
+ }
+
+ // File data.
+ $file = new stdClass();
+ $file->filename = basename($filepath);
+ $file->filepath = $filepath;
+ $file->filemime = $mime;
+ $file->filesize = filesize($filepath);
+ $file->uid = $uid;
+ $file->status = FILE_STATUS_PERMANENT;
+ $file->timestamp = time();
+ drupal_write_record('files', $file);
+
+ // Create the node.
+ $node = new StdClass();
+ $node->type = 'foto';
+ $node->body = $body;
+ $node->title = $title;
+
+ // Image field.
+ $node->field_foto = array(
+ array(
+ 'fid' => $file->fid,
+ 'title' => basename($file->filename),
+ 'filename' => $file->filename,
+ 'filepath' => $file->filepath,
+ 'filesize' => $file->filesize,
+ 'mimetype' => $mime,
+ 'description' => basename($file->filename),
+ 'list' => 1,
+ ),
+ );
+
+ $node->uid = 1;
+ $node->status = 1;
+ $node->active = 1;
+ $node->promote = 0;
+ node_save($node);
+
+ return $node;
+}