[5] | 1 | <?php |
---|
[362] | 2 | /** |
---|
| 3 | * The Strangecode Codebase - a general application development framework for PHP |
---|
| 4 | * For details visit the project site: <http://trac.strangecode.com/codebase/> |
---|
[396] | 5 | * Copyright 2001-2012 Strangecode, LLC |
---|
[468] | 6 | * |
---|
[362] | 7 | * This file is part of The Strangecode Codebase. |
---|
[5] | 8 | * |
---|
[362] | 9 | * The Strangecode Codebase is free software: you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License as published by the |
---|
| 11 | * Free Software Foundation, either version 3 of the License, or (at your option) |
---|
| 12 | * any later version. |
---|
[468] | 13 | * |
---|
[362] | 14 | * The Strangecode Codebase is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
| 17 | * details. |
---|
[468] | 18 | * |
---|
[362] | 19 | * You should have received a copy of the GNU General Public License along with |
---|
| 20 | * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. |
---|
| 21 | */ |
---|
| 22 | |
---|
[468] | 23 | /** |
---|
[362] | 24 | * _config.inc.php lives in the document root of the site/application. It is the beginning of everything. |
---|
| 25 | * |
---|
[5] | 26 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
[803] | 27 | * @version 1.4 |
---|
[27] | 28 | * @since 03 Dec 2005 19:09:32 |
---|
[5] | 29 | */ |
---|
[468] | 30 | |
---|
[27] | 31 | // The constant __FILE__ must be an absolute directory path, starting with / on unix or C: on windows. |
---|
| 32 | // To work around a PHP bug always include this config file with: require_once dirname(__FILE__) . '/_config.inc.php'; |
---|
| 33 | if (!preg_match('!^(/|[A-Z]:)!', __FILE__)) { |
---|
[42] | 34 | 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); |
---|
[5] | 35 | } |
---|
| 36 | |
---|
[27] | 37 | // First things first. Define the globally used directory paths. |
---|
| 38 | // The parent directory of all application DocRoots. |
---|
[5] | 39 | define('COMMON_BASE', realpath(dirname(__FILE__) . '/../')); |
---|
[27] | 40 | |
---|
[468] | 41 | // The DocRoot for this application. SITE_BASE is different from $_SERVER['DOCUMENT_ROOT'] because the |
---|
[27] | 42 | // latter does not change when using the apache Alias directive or URL Rewriting to define a site. |
---|
[5] | 43 | define('SITE_BASE', dirname(__FILE__)); |
---|
| 44 | |
---|
[339] | 45 | // Set include path for all templates and libraries. |
---|
[803] | 46 | ini_set('include_path', join(PATH_SEPARATOR, [ |
---|
[94] | 47 | COMMON_BASE, |
---|
| 48 | SITE_BASE . '/_templates', |
---|
[101] | 49 | get_include_path(), |
---|
[803] | 50 | ])); |
---|
[5] | 51 | |
---|
[803] | 52 | // Define server environments. |
---|
| 53 | // Use this to toggle feature flags via, e.g., `if (ENVIRONMENT === PRODUCTION) { seriousStuff(); }` |
---|
| 54 | define('PRODUCTION', 'production'); |
---|
| 55 | define('DEVELOPMENT', 'development'); |
---|
| 56 | define('LOCAL', 'local'); |
---|
| 57 | switch (getenv('ENVIRONMENT')) { |
---|
| 58 | case 'production': |
---|
| 59 | define('ENVIRONMENT', PRODUCTION); |
---|
| 60 | break; |
---|
| 61 | case 'dev': |
---|
| 62 | case 'staging': |
---|
| 63 | define('ENVIRONMENT', DEVELOPMENT); |
---|
| 64 | break; |
---|
| 65 | case 'local': |
---|
| 66 | define('ENVIRONMENT', LOCAL); |
---|
| 67 | break; |
---|
| 68 | } |
---|
| 69 | |
---|
[5] | 70 | // Include core libraries. |
---|
| 71 | require_once 'codebase/lib/Utilities.inc.php'; |
---|
[27] | 72 | require_once 'codebase/lib/App.inc.php'; |
---|
[5] | 73 | |
---|
[27] | 74 | // Primary application class. |
---|
[295] | 75 | $app =& App::getInstance('public'); |
---|
[803] | 76 | $app->setParam([ |
---|
[295] | 77 | 'site_name' => 'WWW Public Site', |
---|
[5] | 78 | 'site_email' => 'hello@example.com', |
---|
[252] | 79 | 'redirect_home_url' => '/', |
---|
[316] | 80 | 'images_path' => '/i', |
---|
[5] | 81 | |
---|
[679] | 82 | 'php_timezone' => null, |
---|
[5] | 83 | 'date_format' => 'd M Y', |
---|
[679] | 84 | 'time_format' => 'H:i', |
---|
[5] | 85 | 'sql_date_format' => '%e %b %Y', |
---|
| 86 | 'sql_time_format' => '%k:%i', |
---|
| 87 | 'character_set' => 'utf-8', |
---|
| 88 | |
---|
[576] | 89 | 'enable_session' => defined('_NOSESSION') ? false : true, // Enable session unless _NOSESSION is defined. |
---|
[27] | 90 | 'enable_db_session_handler' => false, |
---|
[5] | 91 | 'session_use_cookies' => true, |
---|
[392] | 92 | 'session_use_trans_sid' => false, // Disable this for high-security sites where session-ID theft is a risk. |
---|
[5] | 93 | |
---|
[295] | 94 | // 'ssl_domain' => 'www.example.com', |
---|
[803] | 95 | // 'ssl_enabled' => ENVIRONMENT === PRODUCTION, |
---|
[295] | 96 | |
---|
| 97 | 'enable_db' => true, |
---|
[5] | 98 | 'db_always_debug' => false, |
---|
[803] | 99 | 'db_debug' => false, |
---|
[5] | 100 | 'db_die_on_failure' => true, |
---|
[803] | 101 | 'db_create_tables' => true, /// Disable after site launch. |
---|
[5] | 102 | |
---|
[803] | 103 | 'display_errors' => ENVIRONMENT !== PRODUCTION, |
---|
[432] | 104 | 'error_reporting' => E_ALL & ~E_DEPRECATED & ~E_STRICT, |
---|
[5] | 105 | |
---|
[545] | 106 | 'log_directory' => '/tmp', |
---|
[256] | 107 | 'log_filename' => 'site_log', |
---|
[803] | 108 | 'log_file_priority' => ENVIRONMENT === PRODUCTION ? LOG_DEBUG : LOG_DEBUG, |
---|
| 109 | 'log_email_priority' => ENVIRONMENT === PRODUCTION ? LOG_WARNING : false, |
---|
| 110 | 'log_sms_priority' => ENVIRONMENT === PRODUCTION ? LOG_ALERT : false, |
---|
| 111 | 'log_screen_priority' => ENVIRONMENT === PRODUCTION ? LOG_WARNING : LOG_INFO, |
---|
[392] | 112 | // Email address to receive log event emails. Use multiple addresses by separating them with commas. |
---|
| 113 | 'log_to_email_address' => 'my-emailalert-address@example.com', |
---|
| 114 | // SMS Email address to receive log event SMS messages. Use multiple addresses by separating them with commas. |
---|
| 115 | 'log_to_sms_address' => 'my-smsalert-address@example.com', |
---|
[5] | 116 | |
---|
[803] | 117 | // Prettify json when testing. |
---|
| 118 | 'json_options' => ENVIRONMENT === PRODUCTION ? 0 : JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES, |
---|
| 119 | ]); |
---|
[295] | 120 | |
---|
[136] | 121 | // Start application-based functionality: database, session, environment, ini setup, etc. |
---|
[27] | 122 | // Most configuration parameters must be set before starting the App. |
---|
[5] | 123 | $app->start(); |
---|
| 124 | |
---|
[295] | 125 | // Global DB object. Automatically pre-configured by $app->start(). |
---|
[136] | 126 | $db =& DB::getInstance(); |
---|
| 127 | |
---|
[295] | 128 | // Global Auth object. |
---|
| 129 | require_once 'codebase/lib/Auth_SQL.inc.php'; |
---|
| 130 | $auth = new Auth_SQL('public'); |
---|
[803] | 131 | $auth->setParam([ |
---|
[252] | 132 | 'db_table' => 'user_tbl', |
---|
| 133 | 'db_primary_key' => 'user_id', |
---|
[295] | 134 | 'login_url' => '/login.php', |
---|
| 135 | 'login_timeout' => 260000, // 72 hours |
---|
| 136 | 'idle_timeout' => 86400, // 24 hours |
---|
[803] | 137 | ]); |
---|
[5] | 138 | |
---|
[295] | 139 | // Load preferences for the user. |
---|
| 140 | require_once 'codebase/lib/Prefs.inc.php'; |
---|
[803] | 141 | $prefs = new Prefs('permanent', [ |
---|
[480] | 142 | 'storagetype' => ($auth->isLoggedIn() ? 'database' : 'session'), |
---|
[295] | 143 | 'user_id' => $auth->get('user_id'), |
---|
[803] | 144 | ]); |
---|
| 145 | $prefs->setDefaults([ |
---|
| 146 | 'dark-mode' => true, |
---|
| 147 | ]); |
---|
[295] | 148 | $prefs->load(); |
---|
| 149 | |
---|
| 150 | // Global record-locking object. |
---|
| 151 | require_once 'codebase/lib/Lock.inc.php'; |
---|
| 152 | $lock =& Lock::getInstance($auth); |
---|
[803] | 153 | $lock->setParam([ |
---|
[295] | 154 | 'timeout' => 0, |
---|
| 155 | 'auto_timeout' => 1800, |
---|
| 156 | 'error_url' => '/lock.php', |
---|
[803] | 157 | ]); |
---|
[295] | 158 | |
---|
| 159 | // Global cache object. |
---|
| 160 | require_once 'codebase/lib/Cache.inc.php'; |
---|
| 161 | $cache = new Cache('global'); |
---|
[803] | 162 | $cache->setParam(['enabled' => ENVIRONMENT === PRODUCTION]); |
---|
[295] | 163 | |
---|
| 164 | // Setup CSS files to include. These will always be available. |
---|
[5] | 165 | require_once 'codebase/lib/CSS.inc.php'; |
---|
| 166 | $css = new CSS(); |
---|
[803] | 167 | $css->setParam(['cache_css' => ENVIRONMENT === PRODUCTION]); |
---|
[27] | 168 | $css->setFile('codebase/css/codebase.inc.css'); |
---|
| 169 | $css->setFile('codebase/css/utilities.inc.css'); |
---|
[295] | 170 | // $css->setFile('html/css/screen.inc.css'); |
---|
[5] | 171 | |
---|
[295] | 172 | // Nav class for titles, breadcrumbs, and page features. |
---|
| 173 | // Global navigation titles, breadcrumbs, and page features. |
---|
[202] | 174 | require_once 'codebase/lib/Navigation.inc.php'; |
---|
[803] | 175 | $nav = new Navigation([ |
---|
[202] | 176 | 'path_delimiter' => ' / ', |
---|
| 177 | 'last_crumb_format' => '<b>%s</b>', |
---|
[803] | 178 | ]); |
---|
[5] | 179 | |
---|
[295] | 180 | // Global site-specific configuration. |
---|
[803] | 181 | // $cfg = []; |
---|
[295] | 182 | // require_once 'global/config.inc.php'; |
---|