11 * bootstrap the application
15 require_once('boot.php');
21 * Load the configuration file which contains our DB credentials.
22 * Ignore errors. If the file doesn't exist, we are running in installation mode.
26 $install = ((file_exists('.htconfig.php')) ? false : true);
28 @include(".htconfig.php");
32 * Get the language setting directly from system variables, bypassing get_config()
33 * as database may not yet be configured.
37 $lang = ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
39 load_translation_table($lang);
43 * Try to open the database;
47 require_once("dba.php");
48 $db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
49 unset($db_host, $db_user, $db_pass, $db_data);
54 * Important stuff we always need to do.
55 * Initialise authentication and date and time.
56 * Create the HTML head for the page, even if we may not use it (xml, etc.)
57 * The order of these may be important so use caution if you think they're all
58 * intertwingled with no logical order and decide to sort it out. Some of the
59 * dependencies have changed, but at least at one time in the recent past - the
60 * order was critical to everything working properly
65 require_once("session.php");
69 require_once("datetime.php");
71 date_default_timezone_set(($default_timezone) ? $default_timezone : 'UTC');
79 * For Mozilla auth manager - still needs sorting, and this might conflict with LRDD header.
80 * Apache/PHP lumps the Link: headers into one - and other services might not be able to parse it
81 * this way. There's a PHP flag to link the headers because by default this will over-write any other
84 * What we really need to do is output the raw headers ourselves so we can keep them separate.
88 // header('Link: <' . $a->get_baseurl() . '/amcd>; rel="acct-mgmt";');
90 if((x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login'))
93 if(! x($_SESSION,'authenticated'))
94 header('X-Account-Management-Status: none');
96 if(! x($_SESSION,'sysmsg'))
97 $_SESSION['sysmsg'] = '';
100 * check_config() is responible for running update scripts. These automatically
101 * update the DB schema whenever we push a new one out.
106 $a->module = 'install';
113 * We have already parsed the server path into $->argc and $a->argv
115 * $a->argv[0] is our module name. We will load the file mod/{$a->argv[0]}.php
116 * and use it for handling our URL request.
117 * The module file contains a few functions that we call in various circumstances
118 * and in the following order:
121 * "module"_post (only if there are $_POST variables)
123 * "module"_content - the string return of this function contains our page body
125 * Modules which emit other serialisations besides HTML (XML,JSON, etc.) should do
126 * so within the module init and/or post functions and then invoke killme() to terminate
127 * further processing.
130 if(strlen($a->module)) {
131 if(file_exists("mod/{$a->module}.php")) {
132 include("mod/{$a->module}.php");
133 $a->module_loaded = true;
136 if((x($_SERVER,'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
137 logger('index.php: dreamhost_error_hack invoked');
138 goaway($a->get_baseurl() . $_SERVER['REQUEST_URI']);
141 logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG);
142 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
143 notice( t('Page not found.' ) . EOL);
147 if($a->module_loaded) {
148 $a->page['page_title'] = $a->module;
149 if(function_exists($a->module . '_init')) {
150 $func = $a->module . '_init';
154 if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error)
155 && (function_exists($a->module . '_post'))
156 && (! x($_POST,'auth-params'))) {
157 $func = $a->module . '_post';
161 if((! $a->error) && (function_exists($a->module . '_afterpost'))) {
162 $func = $a->module . '_afterpost';
166 if((! $a->error) && (function_exists($a->module . '_content'))) {
167 $func = $a->module . '_content';
168 if(! x($a->page,'content'))
169 $a->page['content'] = '';
170 $a->page['content'] .= $func($a);
175 if(stristr($_SESSION['sysmsg'], t('Permission denied'))) {
176 header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.'));
181 * Report anything which needs to be communicated in the notification area (before the main body)
185 if(x($_SESSION,'sysmsg')) {
186 $a->page['content'] = "<div id=\"sysmsg\" class=\"error-message\">{$_SESSION['sysmsg']}</div>\r\n"
187 . ((x($a->page,'content')) ? $a->page['content'] : '');
188 unset($_SESSION['sysmsg']);
193 * Add a place for the pause/resume Ajax indicator
197 $a->page['content'] .= '<div id="pause"></div>';
202 * Add the navigation (menu) template
206 if($a->module != 'install')
207 require_once('nav.php');
211 * Build the page - now that we have all the components
212 * Make sure the desired theme exists, though if the default theme doesn't exist we're stuffed.
216 if((x($_SESSION,'theme')) && (! file_exists('view/theme/' . $_SESSION['theme'] . '/style.css')))
217 unset($_SESSION['theme']);
219 $a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array(
220 '$stylesheet' => $a->get_baseurl() . '/view/theme/'
221 . ((x($_SESSION,'theme')) ? $_SESSION['theme'] : 'default')
226 $profile = $a->profile;
228 header("Content-type: text/html; charset=utf-8");
230 $template = 'view/' . $lang . '/'
231 . ((x($a->page,'template')) ? $a->page['template'] : 'default' ) . '.php';
233 if(file_exists($template))
234 require_once($template);
236 require_once(str_replace($lang . '/', '', $template));
238 session_write_close();