Skip to content

Commit

Permalink
port the autodetection of site_url from the sqlite-fixes branch into …
Browse files Browse the repository at this point in the history
…this branch
  • Loading branch information
DavidGoodwin committed May 28, 2014
1 parent e9c92ff commit af078a8
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions website_code/php/database_library_sqlite.php
Expand Up @@ -58,18 +58,35 @@ function database_setup($database_location) {
if (!$ok) {
die("SQLite installation failed.");
}

$db->query("UPDATE sitedetails SET site_url = 'http://{$_SERVER['HTTP_HOST']}/'");

$http = 'http';
if(isset($_SERVER['HTTPS'])) {
$http = 'https';
}
$site_root = $http . '://' . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI'] . '/';
// Remove any top level trailing script names from the uri (i.e. http://host/**index.php**)
if(preg_match('!(.*)/([a-z]+.php)$!i', $site_root, $matches)) {
$site_root = $matches[1] . '/';
}
// Ensure we do not have zillions of trailing slashes.
while(substr($site_root, -1) == '/') {
$site_root = substr($site_root, 0, -1);
}
$site_root .= '/';

// this ought to work and cope with https vs http urls - as long as the first url requested isn't within a subdir.
$db->query("UPDATE sitedetails SET site_url = '" . $db->escapeString($site_root). "'");

$root_path = realpath(dirname(__FILE__) . '/../../');

$db->query("UPDATE sitedetails SET root_file_path = '$root_path/'");
$db->query("UPDATE sitedetails SET import_path = '$root_path/import'");

$db->close();
} else {
die("Can't find : $schema_file");
}

return true;
}

0 comments on commit af078a8

Please sign in to comment.