Hi
I am using views 2 to create a list of download nodes with direct links to their attached files for download. iTweak work great for displaying the mime type icons when viewing a single node but does not seem to do anything when displaying attached files in views. Is there a way to do this using iTweak or do I have to create a custom view field template and have all the mime type icons in my theme?
If its in my theme I could do the following perhaps:
$ext = // get extension
if( file_exists(“./icons/”.$ext.”.png”) ){
$img = “./icons/”.$ext.”.png”;
} else {
$img = “./icons/unkown.png”;
}
print “”;
Thanks!
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | views-template-for-field.tpl_.php_.txt | 2.78 KB | geerlingguy |
| #5 | attached-file-icon.png | 52.57 KB | geerlingguy |
| #1 | download list.jpg | 28.08 KB | vincetingey |
Comments
Comment #1
vincetingey commentedThis is an screenshot of what it currently looks like. I'd prefer to display the icons to the left of the file name or just the icons.
Comment #2
vincetingey commentedWell since no one replied I came up with a solution for myself without hacking this module! I created a custom views field template that parses the xhtml and replaces links with the appropriate image icon depending on the file extension. Here it is for everyone to enjoy!
Place this file in your template directory and name it using the views template theming conventions. This will vary depending on your view name. Mine was called "views-view-field--form-downloads--page--upload-fid.tpl.php"
Your custom icons will need to be in your theme directory or somewhere else.
Comment #3
iva2k commented@grand_master_v - Good to hear you solved your problem.
Looking at the issue and proposed code, I think the issue deserves some solution functioning "out of the box" for users of the module. This will probably include the use of module's .CSS and sprite images for mime types. Unfortunately, solution in #2 uses a set of separate images, and does not rely on CSS, which makes it hard and questionable to include into the module's code. Also, that approach makes no use of thumbnails.
Given that "fixed" status means that solution is committed into code & CVS, which it is not, I'm changing to "needs work" to indicate that there's a need to do some more R&D. That probably needs to be proper integration with views (via hooks), using existing sprites and thumbnails and relying on CSS which maps MIME types to sprite position. I have no bandwidth to look into that. Anyone up to the task? I will review all submitted patches.
Comment #4
vincetingey commentedHi Ilya,
Thanks for looking into this. I know my solution is just a kludgy work around but it did solve my problem. I agree that proper out of the box integration would be best, however I do not have the expertise or time to code this either. Also sorry for setting the ticket to fixed. Since I found a solution to my problem I thought that I should change the status to fixed.
Cheers!
- Vince
Comment #5
geerlingguy commentedIf you could add a new field either under the 'Upload' set of fields or under another heading, that would be best. The field could be called 'Attached file icon' or something like that (see screenshot of views edit page).
(This would have to work around the problem of multiple files per node, of course... which could be tricky).
Comment #6
geerlingguy commentedI've attached an alternate template I'm using with my view to simply grab a link and print an image (using the images provided by iTweak instead of my own images). (Note: I've also updated my script on my site to use PHP's pathinfo() function to grab the file extension, as it's more secure/faster).
Comment #7
shenzhuxi commentedBetter solution for #6
Use file mime instead
if($output){
/** Define image root directory **/
$image_dir = drupal_get_path('module', 'itweak_upload') . '/images/mime/16/';
/** Default image for unknown file types **/
$file_image = "_default.png";
switch ($output) {
case 'application/postscript':
$file_image = "ai.png";
break;
case 'application/msword':
$file_image = "doc.png";
break;
case 'application/x-gtar':
$file_image = "tar.png";
break;
case 'id':
$file_image = "id.png";
break;
case 'image/jpeg':
$file_image = "jpeg.png";
break;
case 'image/jpeg':
$file_image = "jpeg.png";
break;
case 'application/pdf':
$file_image = "pdf.png";
break;
case 'image/png':
$file_image = "png.png";
break;
case 'application/vnd.ms-powerpoint':
$file_image = "pptx.png";
break;
case 'psd':
$file_image = "psd.png";
break;
case 'mov':
$file_image = "quicktime.png";
break;
case 'mp4':
$file_image = "quicktime.png";
break;
case 'm4v':
$file_image = "quicktime.png";
break;
case 'application/rar':
$file_image = "rar.png";
break;
case 'image/svg+xml':
$file_image = "svg.png";
break;
case 'application/x-shockwave-flash':
$file_image = "swf.png";
break;
case 'application/vnd.ms-excel':
$file_image = "xlsx.png";
break;
case 'application/zip':
$file_image = "zip.png";
break;
}
/** image location **/
$file_image = $image_dir.$file_image;
print theme('image', $file_image);
}
Comment #8
iva2k commentedThis would be a nice feature.
I can't tidy it up due to lack of free time, but will review a proper patch.
Standards to aim for:
- should use CSS and mime image sprites (same as the method already used by iTweak Upload)
- should be views API code, not a template file to put into theme directory (to have no additional user installation steps)
- patch should conform to Drupal guidelines, and be based on 6.x-2.x-dev code
Comment #9
lolandese commentedSubscribe
Comment #10
iva2k commentedI'm stopping any development for D6 version of this module. Still open to review submitted patches. There is a hope that D7 code may get some attention (D7 has MIME icons support in core so it may be already solved there), but due to complete rewrite it is not going to be portable.
Comment #11
iva2k commentedI assume thumbnails are also desirable to have.