code cleanup
This commit is contained in:
76
install.php
76
install.php
@@ -16,21 +16,21 @@ $page = Array(
|
||||
// this breaks the dispaly of licenses if enabled
|
||||
$config['minify_html'] = false;
|
||||
|
||||
if(file_exists($config['has_installed'])) {
|
||||
if (file_exists($config['has_installed'])) {
|
||||
|
||||
// Check the version number
|
||||
$version = trim(file_get_contents($config['has_installed']));
|
||||
if(empty($version))
|
||||
if (empty($version))
|
||||
$version = 'v0.9.1';
|
||||
|
||||
$boards = listBoards();
|
||||
|
||||
switch($version) {
|
||||
switch ($version) {
|
||||
case 'v0.9':
|
||||
case 'v0.9.1':
|
||||
// Upgrade to v0.9.2-dev
|
||||
|
||||
foreach($boards as &$_board) {
|
||||
foreach ($boards as &$_board) {
|
||||
// Add `capcode` field after `trip`
|
||||
query(sprintf("ALTER TABLE `posts_%s` ADD `capcode` VARCHAR( 50 ) NULL AFTER `trip`", $_board['uri'])) or error(db_error());
|
||||
|
||||
@@ -51,7 +51,7 @@ if(file_exists($config['has_installed'])) {
|
||||
$version = 'v0.9.2-dev-1';
|
||||
// Upgrade to v0.9.2-dev-2
|
||||
|
||||
foreach($boards as &$_board) {
|
||||
foreach ($boards as &$_board) {
|
||||
// Increase field sizes
|
||||
query(sprintf("ALTER TABLE `posts_%s` CHANGE `subject` `subject` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL", $_board['uri'])) or error(db_error());
|
||||
query(sprintf("ALTER TABLE `posts_%s` CHANGE `name` `name` VARCHAR( 35 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL", $_board['uri'])) or error(db_error());
|
||||
@@ -59,7 +59,7 @@ if(file_exists($config['has_installed'])) {
|
||||
case 'v0.9.2-dev-2':
|
||||
// Upgrade to v0.9.2-dev-3 (v0.9.2)
|
||||
|
||||
foreach($boards as &$_board) {
|
||||
foreach ($boards as &$_board) {
|
||||
// Add `custom_fields` field
|
||||
query(sprintf("ALTER TABLE `posts_%s` ADD `embed` TEXT NULL", $_board['uri'])) or error(db_error());
|
||||
}
|
||||
@@ -76,7 +76,7 @@ if(file_exists($config['has_installed'])) {
|
||||
query("ALTER TABLE `mods` ADD `boards` TEXT NOT NULL") or error(db_error());
|
||||
query("UPDATE `mods` SET `boards` = '*'") or error(db_error());
|
||||
case 'v0.9.3-dev-2':
|
||||
foreach($boards as &$_board) {
|
||||
foreach ($boards as &$_board) {
|
||||
query(sprintf("ALTER TABLE `posts_%s` CHANGE `filehash` `filehash` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL", $_board['uri'])) or error(db_error());
|
||||
}
|
||||
case 'v0.9.3-dev-3':
|
||||
@@ -86,7 +86,7 @@ if(file_exists($config['has_installed'])) {
|
||||
// add ban ID
|
||||
query("ALTER TABLE `bans` ADD `id` INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY ( `id` ), ADD UNIQUE (`id`)");
|
||||
case 'v0.9.3-dev-5':
|
||||
foreach($boards as &$_board) {
|
||||
foreach ($boards as &$_board) {
|
||||
// Increase subject field size
|
||||
query(sprintf("ALTER TABLE `posts_%s` CHANGE `subject` `subject` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL", $_board['uri'])) or error(db_error());
|
||||
}
|
||||
@@ -95,23 +95,23 @@ if(file_exists($config['has_installed'])) {
|
||||
$tables = Array(
|
||||
'bans', 'boards', 'ip_notes', 'modlogs', 'mods', 'mutes', 'noticeboard', 'pms', 'reports', 'robot', 'theme_settings', 'news'
|
||||
);
|
||||
foreach($boards as &$board) {
|
||||
foreach ($boards as &$board) {
|
||||
$tables[] = "posts_{$board['uri']}";
|
||||
}
|
||||
|
||||
foreach($tables as &$table) {
|
||||
foreach ($tables as &$table) {
|
||||
query("ALTER TABLE `{$table}` ENGINE = MYISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or error(db_error());
|
||||
}
|
||||
case 'v0.9.3-dev-7':
|
||||
foreach($boards as &$board) {
|
||||
foreach ($boards as &$board) {
|
||||
query(sprintf("ALTER TABLE `posts_%s` CHANGE `filename` `filename` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL", $board['uri'])) or error(db_error());
|
||||
}
|
||||
case 'v0.9.3-dev-8':
|
||||
foreach($boards as &$board) {
|
||||
foreach ($boards as &$board) {
|
||||
query(sprintf("ALTER TABLE `posts_%s` ADD INDEX ( `thread` )", $board['uri'])) or error(db_error());
|
||||
}
|
||||
case 'v0.9.3-dev-9':
|
||||
foreach($boards as &$board) {
|
||||
foreach ($boards as &$board) {
|
||||
query(sprintf("ALTER TABLE `posts_%s`ADD INDEX ( `time` )", $board['uri'])) or error(db_error());
|
||||
query(sprintf("ALTER TABLE `posts_%s`ADD FULLTEXT (`body`)", $board['uri'])) or error(db_error());
|
||||
}
|
||||
@@ -132,11 +132,11 @@ if(file_exists($config['has_installed'])) {
|
||||
query("ALTER TABLE `news` ADD INDEX (`time`)") or error(db_error());
|
||||
query("ALTER TABLE `theme_settings` ADD INDEX (`theme`)") or error(db_error());
|
||||
case 'v0.9.4-dev-1':
|
||||
foreach($boards as &$board) {
|
||||
foreach ($boards as &$board) {
|
||||
query(sprintf("ALTER TABLE `posts_%s` ADD `sage` INT( 1 ) NOT NULL AFTER `locked`", $board['uri'])) or error(db_error());
|
||||
}
|
||||
case 'v0.9.4-dev-2':
|
||||
if(!isset($_GET['confirm'])) {
|
||||
if (!isset($_GET['confirm'])) {
|
||||
$page['title'] = 'License Change';
|
||||
$page['body'] = '<p style="text-align:center">You are upgrading to a version which uses an amended license. The licenses included with Tinyboard distributions prior to this version (v0.9.4-dev-2) are still valid for those versions, but no longer apply to this and newer versions.</p>' .
|
||||
'<textarea style="width:700px;height:370px;margin:auto;display:block;background:white;color:black" disabled>' . htmlentities(file_get_contents('LICENSE.md')) . '</textarea>
|
||||
@@ -151,14 +151,14 @@ if(file_exists($config['has_installed'])) {
|
||||
case 'v0.9.4-dev-3':
|
||||
case 'v0.9.4-dev-4':
|
||||
case 'v0.9.4':
|
||||
foreach($boards as &$board) {
|
||||
foreach ($boards as &$board) {
|
||||
query(sprintf("ALTER TABLE `posts_%s`
|
||||
CHANGE `subject` `subject` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL ,
|
||||
CHANGE `email` `email` VARCHAR( 30 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL ,
|
||||
CHANGE `name` `name` VARCHAR( 35 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL", $board['uri'])) or error(db_error());
|
||||
}
|
||||
case 'v0.9.5-dev-1':
|
||||
foreach($boards as &$board) {
|
||||
foreach ($boards as &$board) {
|
||||
query(sprintf("ALTER TABLE `posts_%s` ADD `body_nomarkup` TEXT NULL AFTER `body`", $board['uri'])) or error(db_error());
|
||||
}
|
||||
query("CREATE TABLE IF NOT EXISTS `cites` ( `board` varchar(8) NOT NULL, `post` int(11) NOT NULL, `target_board` varchar(8) NOT NULL, `target` int(11) NOT NULL, KEY `target` (`target_board`,`target`), KEY `post` (`board`,`post`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;") or error(db_error());
|
||||
@@ -192,7 +192,7 @@ if(file_exists($config['has_installed'])) {
|
||||
query("ALTER TABLE `bans` CHANGE `board` `board` VARCHAR( 120 ) NULL DEFAULT NULL") or error(db_error());
|
||||
query("ALTER TABLE `reports` CHANGE `board` `board` VARCHAR( 120 ) NULL DEFAULT NULL") or error(db_error());
|
||||
query("ALTER TABLE `modlogs` CHANGE `board` `board` VARCHAR( 120 ) NULL DEFAULT NULL") or error(db_error());
|
||||
foreach($boards as $board) {
|
||||
foreach ($boards as $board) {
|
||||
$query = prepare("UPDATE `bans` SET `board` = :newboard WHERE `board` = :oldboard");
|
||||
$query->bindValue(':newboard', $board['uri']);
|
||||
$query->bindValue(':oldboard', $board['id']);
|
||||
@@ -228,7 +228,7 @@ if(file_exists($config['has_installed'])) {
|
||||
die(Element('page.html', $page));
|
||||
}
|
||||
|
||||
if($step == 0) {
|
||||
if ($step == 0) {
|
||||
// Agreeement
|
||||
$page['body'] = '
|
||||
<textarea style="width:700px;height:370px;margin:auto;display:block;background:white;color:black" disabled>' . htmlentities(file_get_contents('LICENSE.md')) . '</textarea>
|
||||
@@ -237,7 +237,7 @@ if($step == 0) {
|
||||
</p>';
|
||||
|
||||
echo Element('page.html', $page);
|
||||
} elseif($step == 1) {
|
||||
} elseif ($step == 1) {
|
||||
$page['title'] = 'Pre-installation test';
|
||||
|
||||
$page['body'] = '<table class="test">';
|
||||
@@ -250,7 +250,7 @@ if($step == 0) {
|
||||
|
||||
function row($item, $result) {
|
||||
global $page, $config, $__is_error;
|
||||
if(!$result)
|
||||
if (!$result)
|
||||
$__is_error = true;
|
||||
$page['body'] .= '<tr><th>' . $item . '</th><td><img style="width:16px;height:16px" src="' . $config['dir']['static'] . ($result ? 'ok.png' : 'error.png') . '" /></td></tr>';
|
||||
}
|
||||
@@ -271,7 +271,7 @@ if($step == 0) {
|
||||
$drivers = PDO::getAvailableDrivers();
|
||||
|
||||
rheader('PDO drivers <em>(currently installed drivers)</em>');
|
||||
foreach($drivers as &$driver) {
|
||||
foreach ($drivers as &$driver) {
|
||||
row($driver, true);
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ if($step == 0) {
|
||||
</p>';
|
||||
|
||||
echo Element('page.html', $page);
|
||||
} elseif($step == 2) {
|
||||
} elseif ($step == 2) {
|
||||
// Basic config
|
||||
$page['title'] = 'Configuration';
|
||||
|
||||
@@ -304,9 +304,9 @@ if($step == 0) {
|
||||
|
||||
$drivers = PDO::getAvailableDrivers();
|
||||
|
||||
foreach($drivers as &$driver) {
|
||||
foreach ($drivers as &$driver) {
|
||||
$driver_txt = $driver;
|
||||
switch($driver) {
|
||||
switch ($driver) {
|
||||
case 'cubrid':
|
||||
$driver_txt = 'Cubrid';
|
||||
break;
|
||||
@@ -449,7 +449,7 @@ if($step == 0) {
|
||||
|
||||
|
||||
echo Element('page.html', $page);
|
||||
} elseif($step == 3) {
|
||||
} elseif ($step == 3) {
|
||||
$instance_config =
|
||||
'<?php
|
||||
|
||||
@@ -464,15 +464,15 @@ if($step == 0) {
|
||||
';
|
||||
|
||||
function create_config_from_array(&$instance_config, &$array, $prefix = '') {
|
||||
foreach($array as $name => $value) {
|
||||
if(is_array($value)) {
|
||||
foreach ($array as $name => $value) {
|
||||
if (is_array($value)) {
|
||||
$instance_config .= "\n";
|
||||
create_config_from_array($instance_config, $value, $prefix . '[\'' . addslashes($name) . '\']');
|
||||
$instance_config .= "\n";
|
||||
} else {
|
||||
$instance_config .= ' $config' . $prefix . '[\'' . addslashes($name) . '\'] = ';
|
||||
|
||||
if(is_numeric($value))
|
||||
if (is_numeric($value))
|
||||
$instance_config .= $value;
|
||||
else
|
||||
$instance_config .= "'" . addslashes($value) . "'";
|
||||
@@ -486,7 +486,7 @@ if($step == 0) {
|
||||
|
||||
$instance_config .= "\n";
|
||||
|
||||
if(@file_put_contents('inc/instance-config.php', $instance_config)) {
|
||||
if (@file_put_contents('inc/instance-config.php', $instance_config)) {
|
||||
header('Location: ?step=4', true, $config['redirect_http']);
|
||||
} else {
|
||||
$page['title'] = 'Manual installation required';
|
||||
@@ -500,7 +500,7 @@ if($step == 0) {
|
||||
';
|
||||
echo Element('page.html', $page);
|
||||
}
|
||||
} elseif($step == 4) {
|
||||
} elseif ($step == 4) {
|
||||
// SQL installation
|
||||
|
||||
buildJavascript();
|
||||
@@ -516,13 +516,13 @@ if($step == 0) {
|
||||
$queries[] = Element('posts.sql', Array('board' => 'b'));
|
||||
|
||||
$sql_errors = '';
|
||||
foreach($queries as &$query) {
|
||||
if(!query($query))
|
||||
foreach ($queries as &$query) {
|
||||
if (!query($query))
|
||||
$sql_errors .= '<li>' . db_error() . '</li>';
|
||||
}
|
||||
|
||||
$boards = listBoards();
|
||||
foreach($boards as &$_board) {
|
||||
foreach ($boards as &$_board) {
|
||||
setupBoard($_board);
|
||||
buildIndex();
|
||||
}
|
||||
@@ -530,22 +530,22 @@ if($step == 0) {
|
||||
$page['title'] = 'Installation complete';
|
||||
$page['body'] = '<p style="text-align:center">Thank you for using Tinyboard. Please remember to report any bugs you discover. <a href="http://tinyboard.org/docs/?p=Config">How do I edit the config files?</a></p>';
|
||||
|
||||
if(!empty($sql_errors)) {
|
||||
if (!empty($sql_errors)) {
|
||||
$page['body'] .= '<div class="ban"><h2>SQL errors</h2><p>SQL errors were encountered when trying to install the database. This may be the result of using a database which is already occupied with a Tinyboard installation; if so, you can probably ignore this.</p><p>The errors encountered were:</p><ul>' . $sql_errors . '</ul><p><a href="?step=5">Ignore errors and complete installation.</a></p></div>';
|
||||
} else {
|
||||
file_write($config['has_installed'], VERSION);
|
||||
if(!file_unlink(__FILE__)) {
|
||||
if (!file_unlink(__FILE__)) {
|
||||
$page['body'] .= '<div class="ban"><h2>Delete install.php!</h2><p>I couldn\'t remove <strong>install.php</strong>. You will have to remove it manually.</p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
echo Element('page.html', $page);
|
||||
} elseif($step == 5) {
|
||||
} elseif ($step == 5) {
|
||||
$page['title'] = 'Installation complete';
|
||||
$page['body'] = '<p style="text-align:center">Thank you for using Tinyboard. Please remember to report any bugs you discover.</p>';
|
||||
|
||||
file_write($config['has_installed'], VERSION);
|
||||
if(!file_unlink(__FILE__)) {
|
||||
if (!file_unlink(__FILE__)) {
|
||||
$page['body'] .= '<div class="ban"><h2>Delete install.php!</h2><p>I couldn\'t remove <strong>install.php</strong>. You will have to remove it manually.</p></div>';
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user