How to add mime type detection to this?

Comments

quicksketch’s picture

Category: feature » support

I don't understand the request. Links do not have any "mime-type", they are just URLs.

chasz’s picture

but it would be nice to detect mp3, jpg/gif/png, flv etc.....then we can play around with the links

quicksketch’s picture

Please, you'll need to be more specific about what you're trying to accomplish. Link module is simply a mechanism for users inserting links, I'm getting the feeling what you're requesting is out of the scope of link.module.

chasz’s picture

what i am asking for is a generalised field that can add a "field" format based on mimetype.....

ie. if a link is an image then a CSS class/html/php is added, if it's an mp3 then another class is added etc

in effect it s about 3 modules in one LOL :D

1. links
2. filter
3. replacement tag

quicksketch’s picture

If needed, I'd suggest creating a module that implements hook_field_formatter_info() and adds a new formatter to links so that you can output them however you like. You can use the code in link.module as an example and create any kind of specialized output you like for links.

chasz’s picture

i was hoping to get an ADMIN input field that takes care of each formatter :D

instead of manually in the themes

EDIT, which section of the links.module has the formatter?

EDIT2: i effect i am asking for a "bbcode" module for links

dragonwize’s picture

The funcitonality is provided by the filefield module so I don't think link module needs to handle this.

chasz’s picture

filefield only handle file ON your server with drupal, not external server

dragonwize’s picture

Well you can't do mime detection unless you have local access to the file. Which means you would have to download the file to just to do mime detection. And mime detection itself is not perfect even if we could count on mime extensions in linux which we can't.

My best suggestion for you is since what you are asking is about display then you can easily do some quick tests on the filename (mp3, etc) in your template and act accordingly.

chasz’s picture

what about detecting the file extension then?? doing regex test on the last 4 characters

dragonwize’s picture

You can easily do that yourself in your template or template preprocessor function or as quicksketch suggested a hook_field_formatter_info() function. There is nothing to with the extension with link so you have to add custom code anyway.

quicksketch’s picture

Status: Active » Closed (fixed)

Closing, this is out of scope for link.module handling.

janusman’s picture

I have a need to scan a particular link CCK field I have and then be able to search for or filter by the MIME type of the remote resource (I guess I would grab the "Content-Type" header from the server's response).

Maybe that's what the request was about =)

I'm thinking this would be more appropriate in the Link Checker module, since it contacts the remote server to check links... it could then tag the node and/or field properly with the MIME Type from the response.