* Copyright 2001-2012 Strangecode, LLC
*
* This file is part of The Strangecode Codebase.
*
* The Strangecode Codebase 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 3 of the License, or (at your option)
* any later version.
*
* The Strangecode Codebase 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
* The Strangecode Codebase. If not, see .
*/
/**
* _config.inc.php lives in the document root of the site/application. It is the beginning of everything.
*
* @author Quinn Comendant
* @version 1.4
* @since 03 Dec 2005 19:09:32
*/
// The constant __FILE__ must be an absolute directory path, starting with / on unix or C: on windows.
// To work around a PHP bug always include this config file with: require_once dirname(__FILE__) . '/_config.inc.php';
if (!preg_match('!^(/|[A-Z]:)!', __FILE__)) {
trigger_error('_config.inc.php include must be specified with an absolute file path (eg: "require_once dirname(__FILE__) . \'/_config.inc.php\';"', E_USER_ERROR);
}
// First things first. Define the globally used directory paths.
// The parent directory of all application DocRoots.
define('COMMON_BASE', realpath(dirname(__FILE__) . '/../'));
// The DocRoot for this application. SITE_BASE is different from $_SERVER['DOCUMENT_ROOT'] because the
// latter does not change when using the apache Alias directive or URL Rewriting to define a site.
define('SITE_BASE', dirname(__FILE__));
// Set include path for all templates and libraries.
ini_set('include_path', join(PATH_SEPARATOR, [
COMMON_BASE,
SITE_BASE . '/_templates',
get_include_path(),
]));
// Define server environments.
// Use this to toggle feature flags via, e.g., `if (ENVIRONMENT === PRODUCTION) { seriousStuff(); }`
define('PRODUCTION', 'production');
define('DEVELOPMENT', 'development');
define('LOCAL', 'local');
switch (getenv('ENVIRONMENT')) {
case 'production':
define('ENVIRONMENT', PRODUCTION);
break;
case 'dev':
case 'staging':
define('ENVIRONMENT', DEVELOPMENT);
break;
case 'local':
define('ENVIRONMENT', LOCAL);
break;
}
// Include core libraries.
require_once 'codebase/lib/Utilities.inc.php';
require_once 'codebase/lib/App.inc.php';
// Primary application class.
$app =& App::getInstance('public');
$app->setParam([
'site_name' => 'WWW Public Site',
'site_email' => 'hello@example.com',
'redirect_home_url' => '/',
'images_path' => '/i',
'php_timezone' => null,
'date_format' => 'd M Y',
'time_format' => 'H:i',
'sql_date_format' => '%e %b %Y',
'sql_time_format' => '%k:%i',
'character_set' => 'utf-8',
'enable_session' => defined('_NOSESSION') ? false : true, // Enable session unless _NOSESSION is defined.
'enable_db_session_handler' => false,
'session_use_cookies' => true,
'session_use_trans_sid' => false, // Disable this for high-security sites where session-ID theft is a risk.
// 'ssl_domain' => 'www.example.com',
// 'ssl_enabled' => ENVIRONMENT === PRODUCTION,
'enable_db' => true,
'db_always_debug' => false,
'db_debug' => false,
'db_die_on_failure' => true,
'db_create_tables' => true, /// Disable after site launch.
'display_errors' => ENVIRONMENT !== PRODUCTION,
'error_reporting' => E_ALL & ~E_DEPRECATED & ~E_STRICT,
'log_directory' => '/tmp',
'log_filename' => 'site_log',
'log_file_priority' => ENVIRONMENT === PRODUCTION ? LOG_DEBUG : LOG_DEBUG,
'log_email_priority' => ENVIRONMENT === PRODUCTION ? LOG_WARNING : false,
'log_sms_priority' => ENVIRONMENT === PRODUCTION ? LOG_ALERT : false,
'log_screen_priority' => ENVIRONMENT === PRODUCTION ? LOG_WARNING : LOG_INFO,
// Email address to receive log event emails. Use multiple addresses by separating them with commas.
'log_to_email_address' => 'my-emailalert-address@example.com',
// SMS Email address to receive log event SMS messages. Use multiple addresses by separating them with commas.
'log_to_sms_address' => 'my-smsalert-address@example.com',
// Prettify json when testing.
'json_options' => ENVIRONMENT === PRODUCTION ? 0 : JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE,
]);
// Start application-based functionality: database, session, environment, ini setup, etc.
// Most configuration parameters must be set before starting the App.
$app->start();
// Global DB object. Automatically pre-configured by $app->start().
$db =& DB::getInstance();
// Global Auth object.
require_once 'codebase/lib/Auth_SQL.inc.php';
$auth = new Auth_SQL('public');
$auth->setParam([
'db_table' => 'user_tbl',
'db_primary_key' => 'user_id',
'login_url' => '/login.php',
'login_timeout' => 260000, // 72 hours
'idle_timeout' => 86400, // 24 hours
]);
// Load preferences for the user.
require_once 'codebase/lib/Prefs.inc.php';
$prefs = new Prefs('permanent', [
'storagetype' => ($auth->isLoggedIn() ? 'database' : 'session'),
'user_id' => $auth->get('user_id'),
]);
$prefs->setDefaults([
'dark-mode' => true,
]);
$prefs->load();
// Global record-locking object.
require_once 'codebase/lib/Lock.inc.php';
$lock =& Lock::getInstance($auth);
$lock->setParam([
'timeout' => 0,
'auto_timeout' => 1800,
'error_url' => '/lock.php',
]);
// Global cache object.
require_once 'codebase/lib/Cache.inc.php';
$cache = new Cache('global');
$cache->setParam(['enabled' => ENVIRONMENT === PRODUCTION]);
// Setup CSS files to include. These will always be available.
require_once 'codebase/lib/CSS.inc.php';
$css = new CSS();
$css->setParam(['cache_css' => ENVIRONMENT === PRODUCTION]);
$css->setFile('codebase/css/codebase.inc.css');
$css->setFile('codebase/css/utilities.inc.css');
// $css->setFile('html/css/screen.inc.css');
// Nav class for titles, breadcrumbs, and page features.
// Global navigation titles, breadcrumbs, and page features.
require_once 'codebase/lib/Navigation.inc.php';
$nav = new Navigation([
'path_delimiter' => ' / ',
'last_crumb_format' => '%s',
]);
// Global site-specific configuration.
// $cfg = [];
// require_once 'global/config.inc.php';