Location: PHPKode > scripts > NBBS Wizard > nbbs-wizard/install.php
<?
/*
NBBS Wizard - Wizard Component & Installation Wizard
Extracted from: The Next BBS - Forums Software
Copyright (C) 2005 Chris F. Ravenscroft

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Questions? We can be reached at http://forums.sf.net
*/

class Preinstall
{
	function Preinstall($filename, $redirect)
	{
		$this->extractData($filename);
		$this->info('Wizard ready.<br /><br /><div align="center"><a href="'.$redirect.'">Start Installation Wizard</div>');
	}

        function throwError($e)
        {
                ?>
                <div align='center'>
                <font color='red'><b>
                <?=$e;?>
                </b></font>
                <?
                exit;
        }

	function info($msg, $bNoLF=false)
	{
		$lf = $bNoLF ? '' : '<br />';
		print $msg.$lf."\n";
		ob_flush();
		flush();
	}

        function mkdir($dirname)
        {
                if(@is_dir($dirname) || @empty($dirname))
                {
                        return true;
                }

                $subdirname = substr($dirname, 0, strrpos($dirname, '/'));
                if($this->mkdir($subdirname))
                {
                        if(!@file_exists($dirname))
                        {
                                return @mkdir($dirname);
                        }
                }
        }

	function extractData($filename)
	{
		$this->info('Uncompressing data', true);
		$zf = @zip_open($filename);
		if(!$zf)
			$this->throwError('Unable to read data - please ensure that file '.$filename.' is present and php supports zip');
                while($fres = @zip_read($zf))
		{
			$this->info('.', true);
			zip_entry_open($zf, $fres);
			$zipentrydata = '';
			while(false!==($data=zip_entry_read($fres)))
			{
				$zipentrydata .= $data;
			}
			$zipentryname = zip_entry_name($fres);
			$ndir = dirname(str_replace('/', DIRECTORY_SEPARATOR, $zipentryname));
			if($ndir!='.')
				$this->mkdir($ndir);
			if(strrpos($zipentryname, DIRECTORY_SEPARATOR)+1 != strlen($zipentryname)) // Not a directory?
			{
				$f = @fopen($zipentryname, "w+");
				if(!$f)
					$this->throwError('Unable to create '.$zipentryname.' - please check directory write permissions and try again');
				if(!@fwrite($f, $zipentrydata))
					$this->throwError('Unable to write to '.$zipentryname.' - this should never happen');
				@fclose($f);
			}
			@zip_entry_close($fres);
		}
		@zip_close($zf);
		$this->info('<font color="green">[OK]</font>');
	}
}

new Preinstall('install.data', 'newinstall.php');

?>
Return current item: NBBS Wizard