Difference between revisions of "Extension:Flashlets.php"
m |
m |
||
Line 28: | Line 28: | ||
global $wgUploadDirectory,wgUploadPath; | global $wgUploadDirectory,wgUploadPath; | ||
− | + | # convert args to command-line switches | |
− | + | # delete swf's older than cache-expiry | |
$expiry = $now - $this->cacheExpire; | $expiry = $now - $this->cacheExpire; | ||
if ($handle = opendir('.')) { | if ($handle = opendir('.')) { | ||
Line 42: | Line 42: | ||
closedir($handle); | closedir($handle); | ||
− | + | # create swf filename unique to the actionscript content and parameters | |
$swf = $wgUploadDirectory.md5($actionscript.$switches); | $swf = $wgUploadDirectory.md5($actionscript.$switches); | ||
− | + | # Compile the SWF if it doesn't already exist | |
if (!file_exists($swf)) { | if (!file_exists($swf)) { | ||
Line 58: | Line 58: | ||
$html = shell_exec("$mtasc $swf.as $switches -swf $swf.swf"); | $html = shell_exec("$mtasc $swf.as $switches -swf $swf.swf"); | ||
unlink("$swf.as"); | unlink("$swf.as"); | ||
+ | |||
} | } | ||
Revision as of 10:36, 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 $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->cacheExpire; 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)) {
# Write the actionscript to a file for MTASC to compile from if ($handle = fopen("$swf.as", 'w+')) { fwrite($handle,$actionscript); fclose($handle); }
# Compile and remove the actionscript $mtasc = $this->mtasc; $html = shell_exec("$mtasc $swf.as $switches -swf $swf.swf"); unlink("$swf.as");
}
# If the SWF exists, return the HTMLcode to request and embed the SWF otherwise return error information
if (file_exists($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,$wgFlashletsMagic; $wgFlashlets = new Flashlets($wgFlashletsMagic); }
} ?>