source: trunk/docs/examples/_config.inc.php @ 803

Last change on this file since 803 was 803, checked in by anonymous, 4 months ago

Bring config file up-to-date

File size: 6.6 KB
Line 
1<?php
2/**
3 * The Strangecode Codebase - a general application development framework for PHP
4 * For details visit the project site: <http://trac.strangecode.com/codebase/>
5 * Copyright 2001-2012 Strangecode, LLC
6 *
7 * This file is part of The Strangecode Codebase.
8 *
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.
13 *
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.
18 *
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
23/**
24 * _config.inc.php lives in the document root of the site/application. It is the beginning of everything.
25 *
26 * @author  Quinn Comendant <quinn@strangecode.com>
27 * @version 1.4
28 * @since   03 Dec 2005 19:09:32
29 */
30
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';
33if (!preg_match('!^(/|[A-Z]:)!', __FILE__)) {
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);
35}
36
37// First things first. Define the globally used directory paths.
38// The parent directory of all application DocRoots.
39define('COMMON_BASE', realpath(dirname(__FILE__) . '/../'));
40
41// The DocRoot for this application. SITE_BASE is different from $_SERVER['DOCUMENT_ROOT'] because the
42// latter does not change when using the apache Alias directive or URL Rewriting to define a site.
43define('SITE_BASE', dirname(__FILE__));
44
45// Set include path for all templates and libraries.
46ini_set('include_path', join(PATH_SEPARATOR, [
47    COMMON_BASE,
48    SITE_BASE . '/_templates',
49    get_include_path(),
50]));
51
52// Define server environments.
53// Use this to toggle feature flags via, e.g., `if (ENVIRONMENT === PRODUCTION) { seriousStuff(); }`
54define('PRODUCTION', 'production');
55define('DEVELOPMENT', 'development');
56define('LOCAL', 'local');
57switch (getenv('ENVIRONMENT')) {
58case 'production':
59    define('ENVIRONMENT', PRODUCTION);
60    break;
61case 'dev':
62case 'staging':
63    define('ENVIRONMENT', DEVELOPMENT);
64    break;
65case 'local':
66    define('ENVIRONMENT', LOCAL);
67    break;
68}
69
70// Include core libraries.
71require_once 'codebase/lib/Utilities.inc.php';
72require_once 'codebase/lib/App.inc.php';
73
74// Primary application class.
75$app =& App::getInstance('public');
76$app->setParam([
77    'site_name' => 'WWW Public Site',
78    'site_email' => 'hello@example.com',
79    'redirect_home_url' => '/',
80    'images_path' => '/i',
81
82    'php_timezone' => null,
83    'date_format' => 'd M Y',
84    'time_format' => 'H:i',
85    'sql_date_format' => '%e %b %Y',
86    'sql_time_format' => '%k:%i',
87    'character_set' => 'utf-8',
88
89    'enable_session' => defined('_NOSESSION') ? false : true, // Enable session unless _NOSESSION is defined.
90    'enable_db_session_handler' => false,
91    'session_use_cookies' => true,
92    'session_use_trans_sid' => false, // Disable this for high-security sites where session-ID theft is a risk.
93
94    // 'ssl_domain' => 'www.example.com',
95    // 'ssl_enabled' => ENVIRONMENT === PRODUCTION,
96
97    'enable_db' => true,
98    'db_always_debug' => false,
99    'db_debug' => false,
100    'db_die_on_failure' => true,
101    'db_create_tables' => true, /// Disable after site launch.
102
103    'display_errors' => ENVIRONMENT !== PRODUCTION,
104    'error_reporting' => E_ALL & ~E_DEPRECATED & ~E_STRICT,
105
106    'log_directory' => '/tmp',
107    'log_filename' => 'site_log',
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,
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',
116
117    // Prettify json when testing.
118    'json_options' => ENVIRONMENT === PRODUCTION ? 0 : JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES,
119]);
120
121// Start application-based functionality: database, session, environment, ini setup, etc.
122// Most configuration parameters must be set before starting the App.
123$app->start();
124
125// Global DB object. Automatically pre-configured by $app->start().
126$db =& DB::getInstance();
127
128// Global Auth object.
129require_once 'codebase/lib/Auth_SQL.inc.php';
130$auth = new Auth_SQL('public');
131$auth->setParam([
132    'db_table'          => 'user_tbl',
133    'db_primary_key'    => 'user_id',
134    'login_url'         => '/login.php',
135    'login_timeout' => 260000, // 72 hours
136    'idle_timeout' => 86400, // 24 hours
137]);
138
139// Load preferences for the user.
140require_once 'codebase/lib/Prefs.inc.php';
141$prefs = new Prefs('permanent', [
142    'storagetype' => ($auth->isLoggedIn() ? 'database' : 'session'),
143    'user_id' => $auth->get('user_id'),
144]);
145$prefs->setDefaults([
146    'dark-mode' => true,
147]);
148$prefs->load();
149
150// Global record-locking object.
151require_once 'codebase/lib/Lock.inc.php';
152$lock =& Lock::getInstance($auth);
153$lock->setParam([
154    'timeout' => 0,
155    'auto_timeout' => 1800,
156    'error_url' => '/lock.php',
157]);
158
159// Global cache object.
160require_once 'codebase/lib/Cache.inc.php';
161$cache = new Cache('global');
162$cache->setParam(['enabled' => ENVIRONMENT === PRODUCTION]);
163
164// Setup CSS files to include. These will always be available.
165require_once 'codebase/lib/CSS.inc.php';
166$css = new CSS();
167$css->setParam(['cache_css' => ENVIRONMENT === PRODUCTION]);
168$css->setFile('codebase/css/codebase.inc.css');
169$css->setFile('codebase/css/utilities.inc.css');
170// $css->setFile('html/css/screen.inc.css');
171
172// Nav class for titles, breadcrumbs, and page features.
173// Global navigation titles, breadcrumbs, and page features.
174require_once 'codebase/lib/Navigation.inc.php';
175$nav = new Navigation([
176    'path_delimiter' => ' / ',
177    'last_crumb_format' => '<b>%s</b>',
178]);
179
180// Global site-specific configuration.
181// $cfg = [];
182// require_once 'global/config.inc.php';
Note: See TracBrowser for help on using the repository browser.