condition for attachment extension? <xen:if is="{$attachment.filename} == '*.mp3' ">

jacko

Well-known member
I am looking for a condition that will check attachment file extension.

I have already successfully created a condition for a filename:
<xen:if is="{$attachment.filename} == 'test.mp3' "> TEST TEXT </xen:if>
the line above will display TEST TEXT if the attachment file name is test.mp3

What I am trying to do is to have a condition that could display TEST TEXT for every attachment with the extension mp3. I tried something like this, but it doesn't work:
<xen:if is="{$attachment.filename} == '*.mp3' "> TEST TEXT </xen:if>
 
The file extension does not appear to be available.

I edited the attached_files template and added this to the top to debug the attachments array:

Code:
{xen:helper dump,$post.attachments}

This was the output for my test:

Code:
array(1) {
  [1] => array(16) {
    ["attachment_id"] => int(1)
    ["data_id"] => int(1)
    ["content_type"] => string(4) "post"
    ["content_id"] => int(133986)
    ["attach_date"] => int(1287947559)
    ["temp_hash"] => string(0) ""
    ["unassociated"] => int(0)
    ["view_count"] => int(1)
    ["filename"] => string(7) "198.gif"
    ["file_size"] => int(266)
    ["file_hash"] => string(32) "66652cf3f21d1559ffebca89d07e7c2b"
    ["width"] => int(32)
    ["height"] => int(32)
    ["thumbnail_width"] => int(32)
    ["thumbnail_height"] => int(32)
    ["thumbnailUrl"] => string(57) "data/attachments/0/1-66652cf3f21d1559ffebca89d07e7c2b.jpg"
  }
}

No file extension.

Of course you can get at the extension by operating on the filename with string functions, but I don't think you can do that within the templates themselves.
 
Looking into this briefly because I was curious, the determination of whether a file is an image or not happens at upload through upload.php - if it is detected as an image, it returns true and the thumbnailUrl value is set and then stored with the attachment data.

If it is not detected as an image, then it returns false and no value is set.

It's then a toss up as to how you attach the image from what I can gather. If you embed the image into the post, then the bb_code_tag_attach template is used and checks whether the attachment is valid and whether the user has permission to view the attachment or not. If it is the attachment details below the post, then it is the attached_files template is called.

Bare in mind I'm not a coder so could be quite wide of the mark, but it might be it will need to either be based of the filename (so a string function to read the last 3 characters, if it's possible like Jake says) or a modification to upload.php to tag the file in some way as an mp3 file.

I suppose it also depends in a way as to where you want the mp3 player to appear. Do you want it embedded into the message content or do you want it to appear in the attachments bit at the bottom?
 
Hi Jacko

Until it comes out try as beta 3

PHP:
<xen:if is="{$attachment.thumbnail_width} == '0' "><embed type="application/x-shockwave-flash" src="js/audio-player.swf?audioUrl={xen:link attachments, $attachment}" class="attachedFiles" style="height: 27px;width: 98%;" allowscriptaccess="never" quality="best" bgcolor="#ffffff" wmode="window" flashvars="playerMode=embedded" />
<br /></xen:if>

According to self-adapt js/audio-player.swf

player.webp
 
Hi Jacko

Until it comes out try as beta 3

PHP:
<xen:if is="{$attachment.thumbnail_width} == '0' "><embed type="application/x-shockwave-flash" src="js/audio-player.swf?audioUrl={xen:link attachments, $attachment}" class="attachedFiles" style="height: 27px;width: 98%;" allowscriptaccess="never" quality="best" bgcolor="#ffffff" wmode="window" flashvars="playerMode=embedded" />
<br /></xen:if>

According to self-adapt js/audio-player.swf

View attachment 5383
This will add a player to files that are neither images nor sound files, like .zip or .txt for example.
 
Top Bottom