<?php
/**
* Installer for the Noostr application.
*
* @package Noostr
* @subpackage Installer
*/
/**
* Turn error display ON during development
*/
ini_set('display_errors', 1);
/**
* Initial contant declarations.
*/
define('SYSPATH', $_SERVER['DOCUMENT_ROOT']);
/**
* Installer constant.
*/
define('INSTALL', true);
/**
* Set the timer variable and start the site timer
*/
$timerstart = 0;
timer();
/**
* Load the initial user defineable settings
*/
include_once(SYSPATH.'/settings.php');
/**
* Initial constants declarations.
*/
define('CLASSES', ENGINE.'/classes');
define('INCLUDES', ENGINE.'/includes');
define('HANDLERS', ENGINE.'/handlers');
/**
* Configure the system, the site and the templates
*/
include_once(SYSPATH.'/'.INCLUDES.'/config.php');
/**
* Start the installer.
*/
// First, check to see if Noostr is already installed.
$go = true;
if (count($db->query('select * from '.PREFIX.'settings_site')) > 0) {
// Noostr is already installed!
$go = false;
}
if (form_required('step,admin,sitename') && $go) {
// If Noostr is not installed and the required POSTs are here, install the system.
if (form('step') == '2') {
echo "Installing system...<br />\n";
$pass = createuid(8);
$file = file_get_contents('noostr20100506.sql');
$file = str_replace("\n", "", $file);
$file = str_replace("%prefix%", PREFIX, $file);
$file = str_replace("%admin%", form('admin'), $file);
$file = str_replace("%sitename%", form('sitename'), $file);
$file = str_replace("%pass%", sha1($pass), $file);
$file = str_replace("%date%", date('Y/m/d h:i:s a'), $file);
$file = str_replace("%siteid%", createuid(32), $file);
//echo $file;
$statements = explode(';', $file);
for ($i = 0, $c = count($statements); $i < $c; $i++) {
//echo "Query $i: $statements[$i]<br />\n";
$db->query($statements[$i]);
}
echo "Done!<br />\n";
echo "Your password is <strong>$pass</strong> - do not lose it!<br /><br />\n";
echo '<a href="/">Click here.</a><br />';
}
} elseif (form_required('step') && !$go) {
// If Noostr is not installed and the required POSTs are here, upgrade the system.
if (form('step') == '10') {
echo "Upgrading system...<br />\n";
$file = file_get_contents('20100425-20100506.sql');
$file = str_replace("\n", "", $file);
$file = str_replace("%prefix%", PREFIX, $file);
$statements = explode(';', $file);
for ($i = 0, $c = count($statements); $i < $c; $i++) {
$db->query($statements[$i]);
}
echo "Done!<br />\n";
echo '<a href="/">Click here.</a><br />';
}
} elseif ($go) {
// Noostr is not installed!
?>
<p>Installer page!</p>
<form name="admininstall" action="<?php echo $_SERVER["SCRIPT_NAME"]; ?>" method="post">
<input name="step" id="step" type="hidden" value="2" />
<dl>
<dt>Name of your site:</dt>
<dd><input name="sitename" id="sitename" type="text" value="" /></dd>
<dt>Your login name:</dt>
<dd><input name="admin" id="admin" type="text" value="" /></dd>
</dl>
<input type="submit" name="submit" value="Submit!" />
</form>
<?php
} else {
// Noostr is installed - do we need to upgrade?
if ($site->lastUpdateCheck == null) {
// We need to upgrade!
?>
<p>Installer page!</p>
<p>Looks like there is an upgrade available.</p>
<form name="adminupgrade" action="<?php echo $_SERVER["SCRIPT_NAME"]; ?>" method="post">
<input name="step" id="step" type="hidden" value="10" />
<input type="submit" name="submit" value="Upgrade!" />
</form>
<?php
} else {
// Nothing to do here.
?>
<p>Installer page!</p>
<p>It looks like your system has already been installed and is up to date!</p>
<?php
}
}
/**
* We're done! Kill the database connection
*/
$db->disconnect();
/**
* Sets the start time and returns the end time of the page execution. Located
* in the index.php file so it can be run before any other operation.
*
* @global float $timerstart
* @param bool $end
* @return float
*/
function timer($end = false) {
global $timerstart;
$return = 0;
$time = microtime(true);
if ($end) {
$return = $time - $timerstart;
} else {
$timerstart = $time;
register_shutdown_function('timer', 'true');
$return = $time;
}
return $return;
}
?>