Difference between revisions of "Extension:Flashlets.php"

From Organic Design wiki
(verbose)
m
Line 53: Line 53:
 
fclose($handle);
 
fclose($handle);
 
$mtasc = $this->mtasc;
 
$mtasc = $this->mtasc;
$sh = "$mtasc -v $swf.as $switches -out $swf.swf 2>&1";
+
$sh = "$mtasc -v $switches -swf $swf.swf $swf.as 2>&1";
 
$html = shell_exec($sh);
 
$html = shell_exec($sh);
 
unlink("$swf.as");
 
unlink("$swf.as");

Revision as of 11:18, 31 March 2007

<?

  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.00 (2007-03-30)
  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

$wgFlashletsMagic = "swf"; # the tag name for embedding a SWF $wgExtensionFunctions[] = 'wfSetupFlashlets';

class Flashlets {

var $version = '1.00, 2007-03-30'; var $magic = 'swf'; var $mtasc = 'mtasc'; # Command use to launch the MTASC compiler var $expire = 100; # Number of minutes a generated SWF lives for without being accessed

# Constructor function Flashlets($magic) { global $wgParser; $this->magic = $magic; $wgParser->setHook($magic,array($this,'tagHook')); }

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

# convert args to command-line switches

# delete swf's older than cache-expiry $expiry = $now - $this->expire; if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $stat = stat($file); #if ($stat[8] < $expire) unlink($file); } } } closedir($handle);

# create swf filename unique to the actionscript content and parameters $swf = "$wgUploadDirectory/".md5($actionscript.$switches);

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

# Write the actionscript to a file for MTASC to compile from if ($handle = fopen("$swf.as", 'w+')) { fwrite($handle,$actionscript); fclose($handle); $mtasc = $this->mtasc; $sh = "$mtasc -v $switches -swf $swf.swf $swf.as 2>&1"; $html = shell_exec($sh); unlink("$swf.as"); } else $html = "Could not optn '$swf.as' for writing!";

}

# If the SWF exists, return the HTMLcode to request and embed the SWF otherwise return error information if (file_exists("$swf.swf")) $html = "<object...$wgUploadPath/$swf.swf</object>";

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

$html

\n";

return $html; }

}

  1. Called from $wgExtensionFunctions array when initialising extensions

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

?>