<?php if (!defined('PmWiki')) exit ();

/*  copyright 2006 Hans Bracker. 
    Build on code from swf.php copyright 2004 Patrick R. Michaud
    and from quicktime.php copyright 2006 Sebastian Siedentopf.
    This file is distributed under the terms of the GNU General Public 
    License as published by the Free Software Foundation; either 
    version 2 of the License, or (at your option) any later version.  

    This module enables embedding of Flash animations (.swf) files into
    wiki pages. 
    
    Width and height can be set with parameters inside the markup.
    Syntax: (:flash Attach:filename.swf [width=number] [height=number] :)
    Alt syntax: (:flash http://samplesite.com/path/filename.swf [width=number] [height=number] :)
    External resource (alt syntax embeddig with http://....) can be disabled
    by setting $EnableExternalResource = 0;
*/
// Version date
$RecipeInfo['Flash']['Version'] = '2006-10-28';


SDV($EnableExternalResource, 1);

Markup('flash', '<img', "/\\(:flash (.*?:)(.*?)(\\s.*?)?\\s*?:\\)/e", "ShowFlash('$1','$2','$3')");


function ShowFlash($imap, $path, $args) {
    global $UploadFileFmt, $pagename, $PageUrl, $PubDirUrl, $IMapLinkFmt, $EnableExternalResource;
    if ($EnableExternalResource==1 && $imap=='http:') {
        $exturl=1; 
        $FileUrl = 'http:'.$path; 
    }
    else {
        $filepath = FmtPageName("$UploadFileFmt/".$path, $pagename);
        if (file_exists($filepath))
            $IMapLinkFmt['Attach:'] = '$LinkUrl';
        $FileUrl = LinkUpload($pagename, $imap, $path, $path, $path); 
    }
    if (file_exists($filepath) || $exturl==1) {
        $args = ParseArgs($args);
        
        ## object tag
        $out = "\n<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ";
        $out .= " codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" ";
        if (isset($args['width']))
            $out .= " width=\"".$args['width']."\"";
        if (isset($args['height']))
            $out .= " height=\"".$args['height']."\"";  
        $out .= " >\n";
        ## parameter tags
        $out .= "<param name=\"movie\" value=\"$FileUrl\" />";
        $out .= "<param name=\"quality\" value=\"high\" />\n";
        ## embed tag
        $out .= "<embed src=\"$FileUrl\" quality=\"high\" ";
        if (isset($args['width']))
            $out .= " width=\"".$args['width']."\"";
        if (isset($args['height']))
            $out .= " height=\"".$args['height']."\""; 
        $out .= " pluginspage=\"http://www.macromedia.com/go/getflashplayer\"";
        $out .= " type=\"application/x-shockwave-flash\" >\n</embed></object>";
        return Keep($out);
    }
    if($imap=='http:')  return "";  
    else return Keep($FileUrl);
}