Plugin: File Extension Icon
Posted: 30 June 2009 07:04 AM   [ Ignore ]  
Summer Student
Total Posts:  1
Joined  09-19-2007

Hi, decided to post my first official plugin here. It’s a small helper function that we’ve used in a couple of projects and found that it cleaned up the code a bit and saved us a couple of minutes in each project.

“File Extension Icon” returns an icon or the file type as text for a specific file, based on the file’s extension.

Usage

The plugin returns an icon (or the type as text) for a specific file based on the file extension (ie. .gif, .jpg, .pdf). The default parameters works great with the Silk icons by FamFamFam but you can customize the icons any way you want.

Basic usage:

{exp:file_ext_icon width="10" height="10"}http://www.somesite.com/some_file.jpg{/exp:file_ext_icon}

Returns:

<img src="/images/icons/jpg.png" alt="jpg" width="10" height="10" />

Making use of the print_type parameter (to add CSS class in this case):

<li class="{exp:file_ext_icon print_type='yes'}/some_file.jpg{/exp:file_ext_icon}">Text</li>

Returns:

<li class="jpg">Text</li>

Parameters (examples):

- widht: the icon image width in pixels (default is 16). (10)
- height: the icon image height in pixels (default is empty) (10)
- path: the path to the icon folder with trailing slash (default is ‘/images/icons/’). (path/to/file/)
- ext: the extension of the icon files (default is ‘png’). (type)
- class: the class of the image (default is empty). (className)
- print_type: returns the extension of the file, ignoring all other parameters. (yes/no)

Download plugin:

http://republiclabs.com/expressionengine/file_ext_icon/

 Signature 

Ragnar
Republic Factory

Profile
 
 
Posted: 30 June 2009 07:37 AM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2061
Joined  09-16-2004

Sweet, used php for this a while ago but this can come in handy for future projects… don’t forget to submit this to devot-ee.com as well.

 Signature 

Peace, e-man.
stookstudio.com, websites built with care and web standards. LinkedIn profile

Profile
 
 
Posted: 30 June 2009 06:32 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  19
Joined  09-23-2008

Nice functionality - helpful. However, I looked for jpeg.png among the famfam silk icons and did not find it there. I expect this means icons for all extensions must be pulled in from elsewhere/constructed first? Or—was I looking in the wrong place?

Profile
 
 
Posted: 01 July 2009 02:05 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Avatar
Total Posts:  22
Joined  01-09-2008

The default parameters works without parameters with the Silk icons as far as size (16x16px) and format (png), but you need to rename the icon files you wish to use.

All icons starting with “page_” are usually good for file extension icons and I know that many use the page_white_paint.png icon to represent jpeg’s. If you like it, just rename it to jpeg.png and you should be good to go.

 Signature 

Christofer
Republic Factory | Sandin Design

Profile
 
 
Posted: 01 July 2009 03:01 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  19
Joined  09-23-2008

OK - Thanks for the clarification.

Profile
 
 
Posted: 08 October 2009 10:36 AM   [ Ignore ]   [ # 5 ]  
Research Assistant
RankRankRank
Total Posts:  887
Joined  08-05-2005

This plugin is throwing errors with the latest build of EE - I had to disable gzip compression to get pages to show per this thread:

http://expressionengine.com/forums/viewthread/129456/

Now it’s showing an error like this:

Warning: filesize() [function.filesize]: stat failed for /path/path/public_htmlhttp://domain.com/images/uploads/general/myfile.pdf in /path/path/public_html/system/plugins/pi.file_ext_icon.php on line 26

Profile
 
 
Posted: 08 October 2009 11:01 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
RankRankRank
Total Posts:  887
Joined  08-05-2005

Disregard my message, I think now the error is a result of a modification to this plugin.

Profile
 
 
Posted: 08 October 2009 01:29 PM   [ Ignore ]   [ # 7 ]  
Summer Student
Avatar
Total Posts:  22
Joined  01-09-2008

Ok, but let us know if you do think there are some problems with the plugin so we can fix it. Cheers!

 Signature 

Christofer
Republic Factory | Sandin Design

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 03:47 PM
Total Registered Members: 120257 Total Logged-in Users: 71
Total Topics: 126393 Total Anonymous Users: 37
Total Replies: 664710 Total Guests: 322
Total Posts: 791103    
Members ( View Memberlist )