Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-01-21 08:54:32

Vitruvius
Plugin Author
Registered: 2004-09-21
Posts: 125

[plugin] [ORPHAN] srh_file_icon

srh_file_icon displays either the file extension (eg PDF, DOC, ZIP) or an icon image for a file. Icon images must be present in the /images directory for each file type required (eg pdf.png, doc.png — filenames should be lowercase). The icon image type (eg png, gif) can also be specified.

Version 0.1 can be downloaded here

Use: <txp:srh_file_icon displaytype=”“ imagetype=”“ />
attributes:

  • displaytype – ‘text’ or ‘image’ defaults to ‘text’
  • imagetype – the type of image file used for the icon, defaults to png

You can get your file icons here:

http://www.zap.org.au/documents/icons/file-icons/sample.html

This plugin is a far more basic verion of mrz_file_preview (which did a lot more and was written by someone who knows PHP).

This is my first plugin, and if you look at the code you can probably tell I don’t know PHP at all. If I keep reading my PHP book, I might get around to adding some other obvious attributes like class, width & height, alt-text etc.

shaun

Offline

#2 2007-01-21 15:49:45

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: [plugin] [ORPHAN] srh_file_icon

sweet! I was just looking for somrething like this.

Thanks

Offline

#3 2007-01-21 17:04:41

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: [plugin] [ORPHAN] srh_file_icon

Sounds like a nice plugin, thanks. Care to put up a sample page so we can see how it works?

Offline

#4 2007-01-22 04:17:42

Vitruvius
Plugin Author
Registered: 2004-09-21
Posts: 125

Re: [plugin] [ORPHAN] srh_file_icon

Good to hear someone can make use of this.

You can see an example of the plugin in action at this page

Unfortunately only PDFs are listed on that page – but you’ll get the idea.

The plugin is used in a form used for the listing of files. It enables the construction of the link for each file being an icon, file size and file type. That part of the file form looks like this:

<txp:file_download_link> <txp:srh_file_icon displaytype="image" /> </txp:file_download_link>
<txp:file_download_link><txp:file_download_size format="auto" decimals="0" />
 <txp:srh_file_icon /></txp:file_download_link>

Shaun

Last edited by Vitruvius (2007-01-22 04:18:06)

Offline

#5 2007-02-14 22:00:31

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: [plugin] [ORPHAN] srh_file_icon

Vitruvius – nice plugin! Thanks very much for this.

Offline

#6 2007-04-09 20:31:50

mwillse
Member
From: brooklyn, ny
Registered: 2006-06-26
Posts: 83
Website

Re: [plugin] [ORPHAN] srh_file_icon

Great utility!

Note that it doesn’t seem to be consistent with capitalization. It outputs pdf.png and JPG.png. Name your icon files accordingly because some browsers are picky.

Offline

#7 2012-12-02 18:27:21

gfdesign
Member
From: Argentina
Registered: 2009-04-20
Posts: 401

Re: [plugin] [ORPHAN] srh_file_icon

I know it’s is an orphan plugin, but anybody does know if it possible create a conditional rule when the icon image doesn’t exist?
Thanks

Offline

#8 2012-12-02 19:45:21

gfdesign
Member
From: Argentina
Registered: 2009-04-20
Posts: 401

Re: [plugin] [ORPHAN] srh_file_icon

I reply my self. In those cases is necessary to add next lines inside <head> tags

<script type='text/javascript'>
//<![CDATA[
// Script to substitute broken images
function ImagenOk(img) {
if (!img.complete) return false;
if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) return false;
return true;
}
function RevisarImagenesRotas() {
var replacementImg = "<txp:site_url/>images/no_icon.gif";
for (var i = 0; i < document.images.length; i++) {
if (!ImagenOk(document.images[i])) {
document.images[i].src = replacementImg;
}}}
window.onload=RevisarImagenesRotas;
// ]]>
</script>

I hope it be helpful to somebody else.

Offline

#9 2012-12-03 07:44:15

SuMu
Member
From: Germany - Wuppertal
Registered: 2008-03-06
Posts: 242
Website

Re: [plugin] [ORPHAN] srh_file_icon

Hi

icon, use CSS, no plugin:

a[href^="http://de.wikipedia.org"]  {
padding:5px 16px 5px 0;background:transparent url(icons/wikipedia.gif) no-repeat center right}
a[href^="http://www.amazon.de"]  {
padding:5px 16px 5px 0;background:transparent url(icons/amazon.gif) no-repeat center right}
/*a[href *="de.wikipedia.org"]{padding:5px 16px 5px 0;background:transparent url(icons/wikipedia.gif) no-repeat center right}*/
a[href$='.pdf']{padding:5px 20px 5px 0;background:transparent url(icons/icon_pdf.gif) no-repeat center right}
a[href$='.txt']{padding:5px 20px 5px 0;background:transparent url(icons/icon_txt.gif) no-repeat center right}
a[href$='.zip'],a[href$='.rar'],a[href$='.gzip'],a[href$='.bzip'],a[href$='.ace']{padding:5px 20px 5px 0;background:transparent url(icons/icon_archive.gif) no-repeat center right}
a[href ^="skype:"]{padding:5px 20px 5px 0;background:transparent url(icons/icon_skype.gif) no-repeat center right}

maybe it will help someone


viele Grüße
SuMu

Psychomuell + blogZicke

Offline

#10 2012-12-03 12:17:45

gfdesign
Member
From: Argentina
Registered: 2009-04-20
Posts: 401

Re: [plugin] [ORPHAN] srh_file_icon

Hi Susanne
I’m not sure if your solution serves when you don’t know what extension of file the user will upload. Also, the links are not to websites as you point, in my case are links pointing to files uploaded from TXP.
Anyway, many thanks for your suggestion.
Regards

Offline

Board footer

Powered by FluxBB