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

Last change on this file since 683 was 679, checked in by anonymous, 5 years ago

Fix minor bugs. Detect http port and add to site_port, site_url, and page_url params of App.

File size: 6.4 KB
RevLine 
[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>
[295]27 * @version 1.3
[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';
33if (!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]39define('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]43define('SITE_BASE', dirname(__FILE__));
44
[339]45// Set include path for all templates and libraries.
[94]46ini_set('include_path', join(PATH_SEPARATOR, array(
47    COMMON_BASE,
48    SITE_BASE . '/_templates',
[101]49    get_include_path(),
[94]50)));
[5]51
52// Include core libraries.
53require_once 'codebase/lib/Utilities.inc.php';
[27]54require_once 'codebase/lib/App.inc.php';
[5]55
[27]56// Primary application class.
[295]57$app =& App::getInstance('public');
[5]58$app->setParam(array(
[295]59    'site_name' => 'WWW Public Site',
[5]60    'site_email' => 'hello@example.com',
[252]61    'redirect_home_url' => '/',
[316]62    'images_path' => '/i',
[5]63
[679]64    'php_timezone' => null,
[5]65    'date_format' => 'd M Y',
[679]66    'time_format' => 'H:i',
[5]67    'sql_date_format' => '%e %b %Y',
68    'sql_time_format' => '%k:%i',
69    'character_set' => 'utf-8',
70
[576]71    'enable_session' => defined('_NOSESSION') ? false : true, // Enable session unless _NOSESSION is defined.
[27]72    'enable_db_session_handler' => false,
[5]73    'session_use_cookies' => true,
[392]74    'session_use_trans_sid' => false, // Disable this for high-security sites where session-ID theft is a risk.
[5]75
[295]76    // 'ssl_domain' => 'www.example.com',
77    // 'ssl_enabled' => ($_SERVER['SERVER_NAME'] == 'www.example.com'),
78
79    'enable_db' => true,
[5]80    'db_always_debug' => false,
81    'db_debug' => true,
82    'db_die_on_failure' => true,
[295]83    'db_create_tables' => true, // Disable after site launch.
[5]84
85    'display_errors' => true,
[432]86    'error_reporting' => E_ALL & ~E_DEPRECATED & ~E_STRICT,
[5]87
[545]88    'log_directory' => '/tmp',
[256]89    'log_filename' => 'site_log',
[5]90    'log_file_priority' => LOG_DEBUG,
91    'log_email_priority' => false,
92    'log_sms_priority' => false,
93    'log_screen_priority' => false,
[392]94    // Email address to receive log event emails. Use multiple addresses by separating them with commas.
95    'log_to_email_address' => 'my-emailalert-address@example.com',
96    // SMS Email address to receive log event SMS messages. Use multiple addresses by separating them with commas.
97    'log_to_sms_address' => 'my-smsalert-address@example.com',
[5]98));
99
[665]100if ($app->isCLI()) {
[295]101    // DB credentials for command line scripts stored in a file with read rights
102    // given only to the user who will be executing the scripts: -rw-------
103    // This file includes $app-> method calls so this must be included after App::getInstance().
104    require_once 'global/db_auth.inc.php';
105}
106
[136]107// Start application-based functionality: database, session, environment, ini setup, etc.
[27]108// Most configuration parameters must be set before starting the App.
[5]109$app->start();
110
[295]111// Global DB object. Automatically pre-configured by $app->start().
[136]112$db =& DB::getInstance();
113
[295]114// Global Auth object.
115require_once 'codebase/lib/Auth_SQL.inc.php';
116$auth = new Auth_SQL('public');
[5]117$auth->setParam(array(
[252]118    'db_table'          => 'user_tbl',
119    'db_primary_key'    => 'user_id',
[295]120    'login_url'         => '/login.php',
121    'login_timeout' => 260000, // 72 hours
122    'idle_timeout' => 86400, // 24 hours
[5]123));
124
[295]125// Load preferences for the user.
126require_once 'codebase/lib/Prefs.inc.php';
[480]127$prefs = new Prefs('permanent', array(
128    'storagetype' => ($auth->isLoggedIn() ? 'database' : 'session'),
[295]129    'user_id' => $auth->get('user_id'),
130));
131$prefs->setDefaults(array(
[480]132    // ...
[295]133));
134$prefs->load();
[480]135// Load preferences for temporary usage.
136require_once 'codebase/lib/Prefs.inc.php';
137$c_prefs = new Prefs('config');
138$c_prefs->setParam(array(
139    'storagetype' => 'cookie',
140));
[295]141// Temporary prefs.
[480]142$c_prefs = new Prefs('settings');
143$c_prefs->setDefaults(array(
[295]144));
145
146// Global record-locking object.
147require_once 'codebase/lib/Lock.inc.php';
148$lock =& Lock::getInstance($auth);
149$lock->setParam(array(
150    'timeout' => 0,
151    'auto_timeout' => 1800,
152    'error_url' => '/lock.php',
153));
154
155// Global cache object.
156require_once 'codebase/lib/Cache.inc.php';
157$cache = new Cache('global');
[468]158$cache->setParam(array('enabled' => true)); // TODO: Enable caching after site launch.
[295]159
160// Setup CSS files to include. These will always be available.
[5]161require_once 'codebase/lib/CSS.inc.php';
162$css = new CSS();
[468]163$css->setParam(array('cache_css' => false)); // TODO: Enable caching after site launch.
[27]164$css->setFile('codebase/css/codebase.inc.css');
165$css->setFile('codebase/css/utilities.inc.css');
[295]166// $css->setFile('html/css/screen.inc.css');
[5]167
[295]168// Nav class for titles, breadcrumbs, and page features.
169// Global navigation titles, breadcrumbs, and page features.
[202]170require_once 'codebase/lib/Navigation.inc.php';
171$nav = new Navigation(array(
172    'path_delimiter' => ' / ',
173    'last_crumb_format' => '<b>%s</b>',
174));
[5]175
[295]176// Global site-specific configuration.
177// $cfg = array();
178// require_once 'global/config.inc.php';
179
Note: See TracBrowser for help on using the repository browser.