Skip to content

Commit

Permalink
Updates index.php to match our coding standard
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Stovell <[email protected]>
  • Loading branch information
Sesquipedalian committed Nov 28, 2023
1 parent d91ddff commit 3589f77
Showing 1 changed file with 45 additions and 31 deletions.
76 changes: 45 additions & 31 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,104 +29,118 @@
* 1. Define some constants we need.
*/

if (!defined('SMF'))
if (!defined('SMF')) {
define('SMF', 1);
}

if (!defined('SMF_VERSION'))
if (!defined('SMF_VERSION')) {
define('SMF_VERSION', '3.0 Alpha 1');
}

if (!defined('SMF_FULL_VERSION'))
if (!defined('SMF_FULL_VERSION')) {
define('SMF_FULL_VERSION', 'SMF ' . SMF_VERSION);
}

if (!defined('SMF_SOFTWARE_YEAR'))
if (!defined('SMF_SOFTWARE_YEAR')) {
define('SMF_SOFTWARE_YEAR', '2023');
}

if (!defined('JQUERY_VERSION'))
if (!defined('JQUERY_VERSION')) {
define('JQUERY_VERSION', '3.6.3');
}

if (!defined('POSTGRE_TITLE'))
if (!defined('POSTGRE_TITLE')) {
define('POSTGRE_TITLE', 'PostgreSQL');
}

if (!defined('MYSQL_TITLE'))
if (!defined('MYSQL_TITLE')) {
define('MYSQL_TITLE', 'MySQL');
}

if (!defined('SMF_USER_AGENT'))
if (!defined('SMF_USER_AGENT')) {
define('SMF_USER_AGENT', 'Mozilla/5.0 (' . php_uname('s') . ' ' . php_uname('m') . ') AppleWebKit/605.1.15 (KHTML, like Gecko) SMF/' . strtr(SMF_VERSION, ' ', '.'));
}

if (!defined('TIME_START'))
if (!defined('TIME_START')) {
define('TIME_START', microtime(true));
}

if (!defined('SMF_SETTINGS_FILE'))
if (!defined('SMF_SETTINGS_FILE')) {
define('SMF_SETTINGS_FILE', __DIR__ . '/Settings.php');
}

if (!defined('SMF_SETTINGS_BACKUP_FILE'))
if (!defined('SMF_SETTINGS_BACKUP_FILE')) {
define('SMF_SETTINGS_BACKUP_FILE', dirname(SMF_SETTINGS_FILE) . '/' . pathinfo(SMF_SETTINGS_FILE, PATHINFO_FILENAME) . '_bak.php');
}

/*
* 2. Load the Settings.php file.
*/

if (!is_file(SMF_SETTINGS_FILE) || !is_readable(SMF_SETTINGS_FILE))
if (!is_file(SMF_SETTINGS_FILE) || !is_readable(SMF_SETTINGS_FILE)) {
die('File not readable: ' . basename(SMF_SETTINGS_FILE));
}

// Don't load it twice.
if (in_array(SMF_SETTINGS_FILE, get_included_files()))
if (in_array(SMF_SETTINGS_FILE, get_included_files())) {
return;
}

// If anything goes wrong loading Settings.php, make sure the admin knows it.
if (SMF === 1)
{
if (SMF === 1) {
error_reporting(E_ALL);
ob_start();
}

// This is wrapped in a closure to keep the global namespace clean.
call_user_func(function()
{
require_once(SMF_SETTINGS_FILE);
call_user_func(function () {
require_once SMF_SETTINGS_FILE;

// Ensure $sourcedir is valid.
$sourcedir = rtrim($sourcedir, "\\/");
if ((empty($sourcedir) || !is_dir(realpath($sourcedir))))
{
$boarddir = rtrim($boarddir, "\\/");
$sourcedir = rtrim($sourcedir, '\\/');

if ((empty($sourcedir) || !is_dir(realpath($sourcedir)))) {
$boarddir = rtrim($boarddir, '\\/');

if (empty($boarddir) || !is_dir(realpath($boarddir)))
if (empty($boarddir) || !is_dir(realpath($boarddir))) {
$boarddir = __DIR__;
}

if (is_dir($boarddir . '/Sources'))
if (is_dir($boarddir . '/Sources')) {
$sourcedir = $boarddir . '/Sources';
}
}

// We need this class, or nothing works.
if (!is_file($sourcedir . '/Config.php') || !is_readable($sourcedir . '/Config.php'))
if (!is_file($sourcedir . '/Config.php') || !is_readable($sourcedir . '/Config.php')) {
die('File not readable: (Sources)/Config.php');
}

// Pass all the settings to SMF\Config.
require_once($sourcedir . '/Config.php');
require_once $sourcedir . '/Config.php';
SMF\Config::set(get_defined_vars());
});

// Devs want all error messages, but others don't.
if (SMF === 1)
if (SMF === 1) {
error_reporting(!empty(SMF\Config::$db_show_debug) ? E_ALL : E_ALL & ~E_DEPRECATED);
}

/*
* 3. Load some other essential includes.
*/

require_once(SMF\Config::$sourcedir . '/Autoloader.php');
require_once SMF\Config::$sourcedir . '/Autoloader.php';

// Ensure we don't trip over disabled internal functions
require_once(SMF\Config::$sourcedir . '/Subs-Compat.php');
require_once SMF\Config::$sourcedir . '/Subs-Compat.php';


/*********************************************************************
* From this point forward, do stuff specific to normal forum loading.
*********************************************************************/

if (SMF === 1)
{
if (SMF === 1) {
(new SMF\Forum())->execute();
}

Expand Down

0 comments on commit 3589f77

Please sign in to comment.