PHP script to pack an addon using PHP 5.
Packing add-ons with PHP 5
If you have a server on localhost or want build extensions online may this will be helpful for you.
The following script makes a XPI using the ZipArchive of PHP 5 ( may work on PHP 4, I did not test it).
May need some modification to work under Linux.
<?PHP
$extension_file = "Add-on.xpi";
$extension_dir = "C:/zilla/addon-name/";
$jar_file = "addon-jar-name.jar";
$jar_dir = "C:/zilla/addon-name/chrome/";
// Recursive function to list all files on a directory
function list_directory($dir, &$list)
{
if ($dh = @opendir($dir))
{
while(($file = readdir($dh)) !== false)
{
if( $file != "." and $file != "..")
{
if(!eregi('jar$', $dir.$file) and !is_dir($dir.$file))
{
$list[] = str_replace("\\", "/", $dir.$file);
}
if(is_dir($dir.$file))
{
$newdir = $dir.$file."/";
chdir($newdir);
list_directory($newdir, $list);
}
}
}
@chdir("..");
}
return $list;
}
// Packing the jar file
$zip = new ZipArchive();
$filename = dirname(__FILE__)."/".$jar_file;
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE)
die("cannot open <".$filename.">");
$a = array();
$list = list_directory($jar_dir,$a);
for($a=0;$a<count($list);$a++)
$zip->addFile($list[$a],str_replace($jar_dir, "", $list[$a]));
$zip->close();
// Packing the add-on
$zip = new ZipArchive();
$filename = dirname(__FILE__)."/".$extension_file;
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE)
die("cannot open <".$filename.">");
$a = array();
$list = list_directory($extension_dir,$a);
for($a=0;$a<count($list);$a++)
{
if(strpos($list[$a], $jar_dir) === 0)
continue;
else
$zip->addFile($list[$a], str_replace($extension_dir, "", $list[$a]));
}
$zip->addFile(dirname(__FILE__)."/".$jar_file , "/chrome/".$jar_file);
$zip->close();
// Ask for Add-on instalation
echo "<script>window.open('".$extension_file."')</script>";
?>
Filled under scripts | Sat, 24 Nov 2007 16:04:01 MST