Difference between revisions of "Extension:Flashlets.php"

From Organic Design wiki
(should really define a constant for versions)
(tydier swf embedding)
Line 8: Line 8:
 
#  {{#Security:*|dev}}{{#Security:view|*}}{{php}}
 
#  {{#Security:*|dev}}{{#Security:view|*}}{{php}}
  
define('FLASHLETS_VERSION','1.0.0, 2007-04-01');
+
define('FLASHLETS_VERSION','1.0.1, 2007-04-17');
  
 
$wgFlashletsMagic          = "swf";                                  # The tag name for embedding a SWF
 
$wgFlashletsMagic          = "swf";                                  # The tag name for embedding a SWF
Line 89: Line 89:
 
# If the SWF exists, return the HTMLcode to request and embed the SWF otherwise return error information
 
# If the SWF exists, return the HTMLcode to request and embed the SWF otherwise return error information
 
if (file_exists("$file.swf")) {
 
if (file_exists("$file.swf")) {
$html = "\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=$ver,0,0,0\" width=\"$width\" height=\"$height\" id=\"$path\" type=\"application/x-shockwave-flash\" data=\"$path\"><param name=\"flashvars\" value=\"$flashvars\"><param name=\"movie\" value=\"$path\"><param name=\"quality\" value=\"$quality\"><param name=\"bgcolor\" value=\"$bgcolor\"><embed src=\"$path\" quality=\"$quality\" bgcolor=\"$bgcolor\" width=\"$width\" height=\"$height\" flashvars=\"$flashvars\" name=\"$path\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object></td></tr>\n";
+
$html = "\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
 +
<tr><td><object type=\"application/x-shockwave-flash\" data=\"$path\" width=\"width\" height=\"$height\">
 +
<param name=\"movie\" value=\"$path\" />
 +
<param name=\"bgcolor\" value=\"$bgcolor\"/>
 +
<param name=\"flashvars\" value=\"$flashvars\"/>
 +
<param name=\"quality\" value=\"$quality\"/>
 +
</object></td></tr>\n";
 
if ($caption) $html .= "\n<tr><td align=\"center\"><a href=\"$wgFlashletsPath/$swf.swf\">$caption</a></td></tr>\n";
 
if ($caption) $html .= "\n<tr><td align=\"center\"><a href=\"$wgFlashletsPath/$swf.swf\">$caption</a></td></tr>\n";
 
$html .= "</table>";
 
$html .= "</table>";

Revision as of 00:35, 17 May 2007

<?php

  1. Flashlets Extension
  2. - Allows ActionScript code to render in the page a SWF using the MTASC (http://www.mtasc.org) SWF compiler
  3. - Version 1.02 (2007-05-05)
  4. - See http://www.mediawiki.org/wiki/Extension:Flashlets for installation and usage details
  5. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  6. - Author: http://www.organicdesign.co.nz/nad
  7. {{#Security:*|dev}}{{#Security:view|*}}Template:Php

define('FLASHLETS_VERSION','1.0.1, 2007-04-17');

$wgFlashletsMagic = "swf"; # The tag name for embedding a SWF $wgFlashletsMTASC = "$IP/extensions/flashlets/mtasc/mtasc"; # Command used to launch the MTASC executable $wgFlashletsCP = "$IP/extensions/flashlets/std"; # Directory containing the MTASC class headers $wgFlashletsPath = $wgUploadPath; # The client-side path to the directory containing the SWF's $wgFlashletsDirectory = $wgUploadDirectory; # The server-side path to the directory containing the SWF's $wgFlashletsExpandTemplates = true; # Expand mediawiki templates before compiling $wgExtensionFunctions[] = 'wfSetupFlashlets';

$wgExtensionCredits['parserhook'][] = array(

       'name'        => 'Flashlets',
       'description' => 'Actionscript rendering of SWF movies',
       'url'         => 'http://www.mediawiki.org/wiki/Extension:Flashlets',
       'author'      => 'User:Nad',
       'version'     => FLASHLETS_VERSION
       );


class Flashlets {

var $version = FLASHLETS_VERSION; var $expire = 100; # Number of minutes a generated SWF lives for without being accessed var $container; # Location if the SWF container needed by the compiler

# Constructor function Flashlets() { global $IP,$wgParser,$wgFlashletsMagic; $this->container = "$IP/extensions/flashlets/container.swf"; $wgParser->setHook($wgFlashletsMagic,array($this,'tagHook')); }

# Convert the $magic tags to client-side javascript request code from its stored parameters function tagHook($actionscript,$argv,&$parser) { global $wgFlashletsMTASC,$wgFlashletsCP,$wgFlashletsDirectory,$wgFlashletsPath,$wgFlashletsExpandTemplates;

# convert args to command-line switches $width = isset($argv['width'])  ? intval($argv['width'])  : 300; $height = isset($argv['height'])  ? intval($argv['height']) : 200; $fps = isset($argv['fps'])  ? intval($argv['fps'])  : 25; $bgcolor = isset($argv['bgcolor']) ? $argv['bgcolor']  : '#ffffff'; $caption = isset($argv['caption']) ? $argv['caption']  : false; $ver = isset($argv['ver'])  ? $argv['ver']  : 6; /* # delete swf's older than cache-expiry $expiry = $now - $this->expire; if ($handle = opendir($wgFlashletsDirectory)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $stat = stat($file); #if ($stat[8] < $expire) unlink($file); } } } closedir($handle);

  • /

# expand templates before compiling if ($wgFlashletsExpandTemplates) $actionscript = $parser->replaceVariables($actionscript);

# create swf filename unique to the actionscript content and parameters $swf = md5("$actionscript$ver$width$height$fps"); $file = "$wgFlashletsDirectory/$swf"; $path = "$wgFlashletsPath/$swf.swf";

# Compile the SWF if it doesn't already exist if (!file_exists("$file.swf")) {

# Write the actionscript to a file for MTASC to compile from if ($handle = fopen("$file.as", 'w+')) { fwrite($handle,$actionscript); fclose($handle); $cont = $this->container; $sh = "$wgFlashletsMTASC -cp $wgFlashletsCP -swf $cont -out $file.swf -main -version $ver -header $width:$height:$fps $file.as 2>&1"; $html = shell_exec($sh); unlink("$file.as"); } else $html = "Could not open '$file.as' for writing!";

}

# If the SWF exists, return the HTMLcode to request and embed the SWF otherwise return error information if (file_exists("$file.swf")) {

$html = "\n

\n"; if ($caption) $html .= "\n\n"; $html .= "
<object type=\"application/x-shockwave-flash\" data=\"$path\" width=\"width\" height=\"$height\">

<param name=\"movie\" value=\"$path\" /> <param name=\"bgcolor\" value=\"$bgcolor\"/> <param name=\"flashvars\" value=\"$flashvars\"/> <param name=\"quality\" value=\"$quality\"/>

</object>
<a href=\"$wgFlashletsPath/$swf.swf\">$caption</a>

";

}

else $html = "\n
Could not compile SWF!

$html

\n";

return $html; }

}

  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupFlashlets() { global $wgFlashlets; $wgFlashlets = new Flashlets(); }

?>