Difference between revisions of "Extension:Flashlets.php"
m |
m |
||
Line 7: | Line 7: | ||
# - Author: http://www.organicdesign.co.nz/nad | # - Author: http://www.organicdesign.co.nz/nad | ||
− | $wgFlashletsMagic = "swf"; # the tag name for embedding a SWF | + | $wgFlashletsMagic = "swf"; # the tag name for embedding a SWF |
+ | $wgFlashletsMTASC = "mtasc"; # Command used to launch the MTASC executable | ||
+ | $wgFlashletsCP = "/usr/local/mtasc"; # Directory containing the MTASC class headers | ||
$wgExtensionFunctions[] = 'wfSetupFlashlets'; | $wgExtensionFunctions[] = 'wfSetupFlashlets'; | ||
Line 13: | Line 15: | ||
var $version = '1.00, 2007-03-30'; | var $version = '1.00, 2007-03-30'; | ||
− | |||
− | |||
var $expire = 100; # Number of minutes a generated SWF lives for without being accessed | var $expire = 100; # Number of minutes a generated SWF lives for without being accessed | ||
# Constructor | # Constructor | ||
− | function Flashlets( | + | function Flashlets() { |
− | global $wgParser | + | global $wgParser,$wgFlashletsMagic; |
− | + | $wgParser->setHook($wgFlashletsMagic,array($this,'tagHook')); | |
− | $wgParser->setHook($ | ||
} | } | ||
# Convert the $magic tags to client-side javascript request code from its stored parameters | # Convert the $magic tags to client-side javascript request code from its stored parameters | ||
function tagHook($actionscript,$argv,&$parser) { | function tagHook($actionscript,$argv,&$parser) { | ||
− | global $wgUploadDirectory,$wgUploadPath; | + | global $wgUploadDirectory,$wgUploadPath,$wgFlashletsMTASC,$wgFlashletsCP; |
# convert args to command-line switches | # convert args to command-line switches | ||
Line 52: | Line 51: | ||
fwrite($handle,$actionscript); | fwrite($handle,$actionscript); | ||
fclose($handle); | fclose($handle); | ||
− | $ | + | $sh = "$wgFlashletsMTASC -cp $wgFlashletsCP -v $switches -swf $swf.swf $swf.as 2>&1"; |
− | |||
$html = shell_exec($sh); | $html = shell_exec($sh); | ||
unlink("$swf.as"); | unlink("$swf.as"); | ||
Line 71: | Line 69: | ||
# Called from $wgExtensionFunctions array when initialising extensions | # Called from $wgExtensionFunctions array when initialising extensions | ||
function wfSetupFlashlets() { | function wfSetupFlashlets() { | ||
− | global $wgFlashlets | + | global $wgFlashlets; |
− | $wgFlashlets = new Flashlets( | + | $wgFlashlets = new Flashlets(); |
} | } | ||
?> | ?> |
Revision as of 11:34, 31 March 2007
<?
- Flashlets Extension
- - Allows ActionScript code to render in the page a SWF using the MTASC (http://www.mtasc.org) SWF compiler
- - Version 1.00 (2007-03-30)
- - See http://www.mediawiki.org/wiki/Extension:Flashlets for installation and usage details
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: http://www.organicdesign.co.nz/nad
$wgFlashletsMagic = "swf"; # the tag name for embedding a SWF $wgFlashletsMTASC = "mtasc"; # Command used to launch the MTASC executable $wgFlashletsCP = "/usr/local/mtasc"; # Directory containing the MTASC class headers $wgExtensionFunctions[] = 'wfSetupFlashlets';
class Flashlets {
var $version = '1.00, 2007-03-30'; var $expire = 100; # Number of minutes a generated SWF lives for without being accessed
# Constructor function Flashlets() { global $wgParser,$wgFlashletsMagic; $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 $wgUploadDirectory,$wgUploadPath,$wgFlashletsMTASC,$wgFlashletsCP;
# 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); $sh = "$wgFlashletsMTASC -cp $wgFlashletsCP -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; }
}
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupFlashlets() { global $wgFlashlets; $wgFlashlets = new Flashlets(); }
?>