Mailsave to CCK Imagefield module

Moonshine - August 13, 2007 - 22:41
Project:Mailsave
Version:5.x-2.0
Component:Code
Category:feature request
Priority:normal
Assigned:Moonshine
Status:closed
Description

Hello...

Got sidetracked with a bunch of work, but here is the module I created to convert attached images to CCK Imagefields. I should work with both the 1.x and 2.x Imagefield modules (2.x added Ajax uploading, tokenized paths, etc)

I'm also working on a bunch of cleanup scripts for US mobile providers that I'll turn in once complete.

Let me know if you have any questions, and thanks again for your work on mailsave :)

AttachmentSize
mailsave_to_imagefield.tar_.gz1.9 KB

#1

Moonshine - August 13, 2007 - 22:42

Sorry, looks like the site mangled the filename I uploaded. Should still work for you though, at least it did for me when I tried it here.

#2

Stuart Greenfield - August 15, 2007 - 18:21

Great - thanks for submitting this - I think you win the award for the first additional module for mailsave. I am away from home at the moment, but once back I'll take a look and get ready to merge this module in.

Will also be good to get some extra clean up filters. The contributions have run a little thin on the ground, so some new filters will be much appreciated!

#3

Stuart Greenfield - August 16, 2007 - 08:23

I have done a very quick initial test. I have never really used CCK / imagefield before, and I seem to be having a problem getting imagefield to identify that the attachment is a valid image format, so mailsave is attaching as a file, rather than adding the image to the image field. Where do you give imagefield its list of allowed filetypes? When I do a debug test the extensions list is empty...

If I quickly modify the mailsave to imagefield module to bypass the test, then when submitting an image it seems to work fine - the image appears in the image field as planned. It also seems to be properly interacting with the cleanup filter for my test message.

So the problem is me not knowing how to use imagefield properly I think :-)

#4

Stuart Greenfield - August 16, 2007 - 08:39

If I look in the imagefield module itself, it seems to validate files for upload using:

<?php
if (strpos($file['filemime'],'image') !== FALSE) {
?>

whereas the mailsave to imagefield module is using

<?php
if (strpos($cck_image_extensions, _file_ext($file['filename'])) !== FALSE ) {
?>

If I modify mailsave to imagefield then the attachment process seems to work?

#5

Moonshine - August 16, 2007 - 16:54

Hello..

If you look about 10 lines above that in the Imagefield module you should see it checking the allowed file extensions first. When creating an imagefield in a node you can give it a list extensions to allow, which is what I was checking against. Although it looks like they also allow an "empty" set to allow any extension (as long as filemime is an image).

So changed the code to allow for an empty set of extensions and added a mimetype check for completeness. Basically:

<?php
if ( (trim($cck_image_extensions) == "" || strpos($cck_image_extensions, _file_ext($file['filename'])) !== FALSE ) && strpos($file['filemime'], 'image/') !== FALSE )  {
?>

Thanks..

AttachmentSize
mailsave_to_imagefield-r2.tgz 1.93 KB

#6

Stuart Greenfield - August 16, 2007 - 17:24

I must be missing something here. I assumed that somewhere I would see a list of allowed image types, as I can see the line where the list of extensions is populated:

<?php
$cck_image_extensions
= $field_info['widget']['file_extensions'];
?>

but at no point have I found where I can input the list of types when I create an image field!?!

#7

Moonshine - August 16, 2007 - 17:38

Not sure which version of CCK Imagefield your testing with, but if you go into a Content Type (say Blog) and then choose "Add Field", give the field a name and choose "Imagefield", hit "Create Field". Then on the next page you will see an option labeled "Permitted upload file extensions.:" with a description "Extensions a user can upload to this field. Seperate extensions with a space and do not include the leading dot."

It is odd they don't mention an empty set will allow every image type though.

I actually changed that conditional a little more here to make it totally strict about finding "image/" in mimetype at the beginning:

<?php
if ( (trim($cck_image_extensions) == "" || strpos($cck_image_extensions, _file_ext($file['filename'])) !== FALSE ) && strpos($file['filemime'], 'image/') == 0 )  {
?>

AttachmentSize
mailsave_to_imagefield-r3.tgz 1.93 KB

#8

Stuart Greenfield - August 16, 2007 - 17:43

I got it - the file extension feature doesn't appear in the official release of imagefield which I fetched from CVS. It is there under branch 5-2 though, so now I have it :-)

#9

Moonshine - August 16, 2007 - 17:49

Ahh.. well that explains why they are letting an empty extension list take anything (for backwards compatability).

I guess I should probably check to make sure $field_info['widget']['file_extensions'] exists first also. Was that throwing an error for you when using Imagefield 5.x-1.x ?

#10

Moonshine - August 16, 2007 - 17:57

I guess it can't hurt to make sure $field_info['widget']['file_extensions'] exists, so I added that in there also.

AttachmentSize
mailsave_to_imagefield-r4.tgz 1.95 KB

#11

Stuart Greenfield - August 17, 2007 - 05:44

I did some tests and this module seems to be working fine. Now I have the right version of imagefield it makes things easier.

The modification to allow handling of "empty" extension lists is good since it means this should now be compatible with earlier versions of imagefield that don't have the extension limit (again, have tested the module against both versions and it seems good).

Not sure it's necessary to check for the presence of the extensions. If the string doesn't exist $cck_image_extensions just remains empty.

I've uploaded the module against the HEAD version of mailsave so it should be available for other users next time the package is rebuilt.

Thanks for your contribution on this one!

#12

Moonshine - August 17, 2007 - 16:58

Sounds good. :) If possible I think it's worth keeping the $cck_image_extensions check though. If they are using 1.x and it isn't defined, PHP will throw a "Notice" level error which gets logged for most people using a stock apache/php config.

One last side note. This little module is just one part of three that I've been working on for mobile blogging and pushing content to mobile phones.

I've been using it in conjunction with a written version of "Inline" which automatically includes the CCK images into the node body/teaster with configurable settings. You can see info on that at http://demo.netfocal.com (in case people end up looking for that sort of functionality). I submitted it to the Inline project in hopes of it being using for their 2.x branch as it has a bunch of items built-in that they have been discussing for years.

The 3rd part you might(?) be interested in for Mailsave. Basically I started out wanting something like Mailalias, so that users could keep their normal e-mail address and get auth'd for their phone address by Mailhandler. So I updated that for Drupal 5 and made changes so it's a lot more friendly. Basically with the proper rights, users can enter their mobile number, choose their provider from a pulldown, indicate if they have a cameraphone, and check a box about possible "fees" from their provider. (In their User Account screen)

Then, depending on their access rights, they will be able to submit blog entries and/or be able to choose content that's sent to their phone. There are functions to SMS/TXT or MMS/PHOTO messages to them via the provider e-mail gateways. (and functions just to get at the addresses for them). It's not finished yet, but I will be working on it over the summer as I get more and more phones to test. Not sure if that's something you'd be interested in including.

Thanks again for checking out the Imagefield addition so quickly...

#13

Stuart Greenfield - October 23, 2007 - 22:24
Status:reviewed & tested by the community» fixed

Mailsave v3 was released this evening, and includes mailsave_to_imagefield.

Thanks for your contribution!

#14

Anonymous - November 12, 2007 - 22:41
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.