How to identify media filetypes within plugin context How to identify media filetypes within plugin context
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

How to identify media filetypes within plugin context

Started by thejake420, July 29, 2006, 11:20:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

thejake420

I am writing a plugin to provide code for "Show this video/picture on your site" functionality. I realize that this involves giving away the direct URL to the media within the code. (Which is fine for my purposes.)

The code itself is fairly simple... provide code with an IMG tag or an EMBED tag, and use {$normal_url} (already defined within the plugin) to provide the media URL.

However, since I have pictures and videos in the gallery, I will need to provide an IF (or switch, etc.) within codebase.php to provide the appropriate code, depending on whether it is a video or a picture. (Ideally, any other media type will simply not provide the "put this on your site" code on displayimage.php.)

That said, how can I have the plugin API determine the media type? For example, I know that {$pic_data['title']} will return the title. Is there a similar method for returning the media type? I'm sure I can find a bass-ackwards way of doing it, such as:

1. Get direct media URL and put it in a separate variable
2. Use PHP to Strip away everything except the last 3 characters of the URL (ie - the file extension, like gif, wmv, etc.)

echo substr('http://www.site.com/gallery/albums/albumname/filename.gif', -1, 3);

3. Process that value through a SWITCH/CASE statement
4. Based on the case, provide different code for each possibility.
5. Return that code in a cut & paste format to the user

That will work, but it will be quite inefficient. Surely there's some simpler method within the plugin API for determining whether the media type is a video or a picture...?


Jake

Nibbler

Coppermine has some functions like is_image(), is_movie(), is_audio() and is_document() that you can use. Just give it the filename and it will tell you true or false.

thejake420

Nibbler -

Thanks as always for the fast and knowledgeable reply. I'll give those a whirl and see what I can come up with.


Jake

thejake420

Well, after fiddling with it for a while, I ended up doing it the hard way anyway. LOL here's a snippet that can be modified for whatever purpose someone may desire:


default :
// Set up variables to reflect necessary JS link from TagBlitz
$linkcode = "<a onclick=\"NewWindow(this.href,'TagBlitz','650','500','no','center');return false\" onfocus=\"this.blur()\" href=\"http://tagblitz.com/submit/?url={$url}?pos=-{$pic_data['pid']}&msurl={$url}?pos=-{$pic_data['pid']}&amp;title={$title}&keys={$keys}\" target=\"_blank\" TITLE=\"TagBlitz.com allows you to share a page on over 50 social bookmarking websites and services. No signup, no hassle!\"><font color=\"blue\" size=\"+1\">TagBlitz This Page</font></a>";
$buttoncode = "<a onclick=\"NewWindow(this.href,'TagBlitz','650','500','no','center');return false\" onfocus=\"this.blur()\" href=\"http://tagblitz.com/submit/?url={$url}?pos=-{$pic_data['pid']}&msurl={$url}?pos=-{$pic_data['pid']}&amp;title={$title}&keys={$keys}\" target=\"_blank\"><img src=\"http://www.tagblitz.com/img/button_tagblitzthis1.gif\" border=\"0\" ALT=\"TagBlitz.com allows you to share a page on over 50 social bookmarking websites and services. No signup, no hassle!\"></a>";
// Redefine download URL
$normal_url = get_pic_url($pic_data, 'normal');
$fullsized_url = get_pic_url($pic_data);
$thisfiletype = $fullsized_url;
$thisfiletype = substr("$thisfiletype", -3);
switch ($thisfiletype){
case "gif":
$leechcode = "<img src=\"http://www.jakesjokes.com/gallery/{$fullsized_url}\" alt=\"Over 50,000 free jokes, videos, pictures, and more at JakesJokes.com!\"><br><a title=\"Thousands of free jokes and videos\" href=\"http://www.jakesjokes.com\" target=\"_top\">Funny jokes, pictures, and videos</a>";
break;

// Other similar image case situations (jpg, png, bmp, etc.) removed for this post due to length.
case "swf":
$leechcode = "<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'
        codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0'
        width=\"320\" height=\"240\">
        <param name='movie' value=\"http://www.jakesjokes.com/gallery/{$fullsized_url}\">
        <param name='quality' value=\"high\">
        <param name='bgcolor' value='#FFFFFF'>
        <param name='loop' value=\"true\">
        <EMBED src=\"http://www.jakesjokes.com/gallery/{$fullsized_url}\" quality='high' bgcolor='#FFFFFF' width=\"320\"
        height=\"240\" loop=\"true\" type='application/x-shockwave-flash'
        pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>
        </EMBED>
        </OBJECT>
<br><a title=\"Thousands of free jokes and videos\" href=\"http://www.jakesjokes.com\" target=\"_top\">Funny jokes, pictures, and videos</a>";
break;

// Other similar media case situations (avi, wmv, swf, mp3, etc.) removed from this post due to length.


Following the example above, similar case situations (avi, bmp, mp3, etc.) can easily be set up with the appropriate code to display the media on a remote site. (Bear in mind that this code endorses direct leeching off of my server. If you want to have a "passthrough" page such as remotevideo.php that does the actual display of the media, you'll need to set that up on your own, and pass the appropriate variables as needed.)


Jake

core212

where do we install this? a little direction please?? thanks!