Difference between revisions of "Extension:Flashlets.php"

From Organic Design wiki
m
m
Line 52: Line 52:
 
fwrite($handle,$actionscript);
 
fwrite($handle,$actionscript);
 
fclose($handle);
 
fclose($handle);
}
+
$mtasc = $this->mtasc;
 
+
$html = shell_exec("$mtasc $swf.as $switches -swf $swf.swf");
# Compile and remove the actionscript
+
unlink("$swf.as");
$mtasc = $this->mtasc;
+
} else $html = "Could not optn '$swf.as' for writing!";
$html = shell_exec("$mtasc $swf.as $switches -swf $swf.swf");
 
unlink("$swf.as");
 
  
 
}
 
}
Line 63: Line 61:
 
# 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($swf)) $html = "<object...$wgUploadPath/$swf.swf</object>";
 
if (file_exists($swf)) $html = "<object...$wgUploadPath/$swf.swf</object>";
else $html = "\n<br><b>Could not compile SWF!</b><br>$html<br>\n";
+
else $html = "\n<br><b>Could not compile SWF!</b><pre>$html</pre>\n";
  
 
return $html;
 
return $html;

Revision as of 10:50, 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)) {

# 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; $html = shell_exec("$mtasc $swf.as $switches -swf $swf.swf"); 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)) $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); }

?>