Mailsave to CCK ImageField incompatible with Drupal 6.13?
jjjames - October 22, 2009 - 06:39
| Project: | Mailsave |
| Version: | 6.x-1.3 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Can someone please help me get mailsave to work with Drupal 6.13 and 6.14? Not sure what version of Drupal the incompatibility started, but I think it's important to keep up with the core. Any ideas?
Thanks!

#1
well the problems come from the ".info" file. It seems to use an old syntax.
Instead of:
dependencies = mailsave imagefieldit should be:
dependencies[] = mailsavedependencies[] = imagefield
I hope it helps.
#2
Thanks I'll give that a try!
#3
After a few tries... I successfully fixed
mailsave_to_imagefield...This is how the ".module" file looks by me.
<?php
/**
* Implementation of hook_perm
*/
function mailsave_to_imagefield_perm() {
return array(
'convert to imagefield',
);
}
/**
* Implementation of hook_mailsave().
* Try to convert images to imagefields
*/
function mailsave_to_imagefield_mailsave($node, $result, $i, $header, $mailbox) {
// See if conversion to image is needed
_mailsave_to_imagefield_attempt_image($node);
// Return the (possibly updated!) updated node
return $node;
}
/**
* Attempt to find images in the node and convert them to CCK imagefileds if they exit
*/
function _mailsave_to_imagefield_attempt_image(&$node) {
// If $node->mailsave_attachments is empty or imagefield not installed just return
if (!$node->mailsave_attachments || !module_exists('imagefield')) {
return;
}
// If user doesn't have image conversion permissions just return
if (!user_access('convert to imagefield')) {
// mailsave modules don't need to flag that the user doesn't have attach permission
// it just ignores the process silently
return;
}
// Query to find a CCK Imagefield attached to the node type
$node_type = content_types($node->type);
$field = FALSE;
$multiple = FALSE;
if (is_array($node_type['fields'])) {
foreach ($node_type['fields'] as $field_name => $field) {
if ($field['type'] == 'filefield' && $field['widget']['module'] == 'imagefield') {
$multiple = $field['multiple'];
break;
}
}
}
if (!$field) {
watchdog('mailsave', t('No CCK Imagefields found for content type %type.', array ('%type' => $node->type)));
return;
}
// Begin processing attachments
foreach ($node->mailsave_attachments as $key => $attachement) {
// Ensure we are using an object
$validators = array_merge(
filefield_widget_upload_validators($field),
imagefield_widget_upload_validators($field)
);
// Where do we store the files?
$files_path = filefield_widget_file_path($field, $user);
// Not sure what's the best here file_copy, file_move, file_save_data... at least, it works
$data = file_save_data(file_get_contents($attachement['filepath']), $attachement['filename']);
if (!$data) {
return;
}
// Create the file object
$image = field_file_save_file($data, $validators, $files_path, $user);
// Add the image info to the imagefield array
$node->{$field_name}[] = $image;
// Lets remove the CCK image we found from attachments
unset($node->mailsave_attachments[$key]);
// if this isn't a multiple image CCK imagefield then let's exit
if (!$multiple) return;
}
}
?>
On a side note... the (actual version) of mailsave_to_imagefield uses a completely outdated version of the filefield/imagefield API... and I think (as the imagefield is now more or less) only a CCK formatter, that the
mailsave_to_imagefieldmodule should be dropped in favour of amailsave_to_filefieldand be somewhat extended to add a few admin settings.Have fun!
#4
hi
so this is work for imagefield ?? where i must to put your code ??
thanks
#5
Well,
you can completely overwrite the ".module" file content (but don't forget to keep a backup)...
By the way, I tried it on a second installation (an other drupal site) but something didn't worked this time.. I'm still investigating...