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");
72 require_once("datetime.php");
74 date_default_timezone_set(($default_timezone) ? $default_timezone : 'UTC');
82 * For Mozilla auth manager - still needs sorting, and this might conflict with LRDD header.
83 * Apache/PHP lumps the Link: headers into one - and other services might not be able to parse it
84 * this way. There's a PHP flag to link the headers because by default this will over-write any other
87 * What we really need to do is output the raw headers ourselves so we can keep them separate.
91 // header('Link: <' . $a->get_baseurl() . '/amcd>; rel="acct-mgmt";');
93 if((x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login'))
96 if(! x($_SESSION,'authenticated'))
97 header('X-Account-Management-Status: none');
99 if(! x($_SESSION,'sysmsg'))
100 $_SESSION['sysmsg'] = '';
103 * check_config() is responible for running update scripts. These automatically
104 * update the DB schema whenever we push a new one out.
109 $a->module = 'install';
116 * We have already parsed the server path into $->argc and $a->argv
118 * $a->argv[0] is our module name. We will load the file mod/{$a->argv[0]}.php
119 * and use it for handling our URL request.
120 * The module file contains a few functions that we call in various circumstances
121 * and in the following order:
124 * "module"_post (only if there are $_POST variables)
126 * "module"_content - the string return of this function contains our page body
128 * Modules which emit other serialisations besides HTML (XML,JSON, etc.) should do
129 * so within the module init and/or post functions and then invoke killme() to terminate
130 * further processing.
134 if(strlen($a->module)) {
135 if(file_exists("mod/{$a->module}.php")) {
136 include("mod/{$a->module}.php");
137 $a->module_loaded = true;
140 if((x($_SERVER,'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
141 logger('index.php: dreamhost_error_hack invoked');
142 goaway($a->get_baseurl() . $_SERVER['REQUEST_URI']);
145 logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG);
146 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
147 notice( t('Page not found.' ) . EOL);
151 /* initialise content region */
153 if(! x($a->page,'content'))
154 $a->page['content'] = '';
158 * Call module functions
161 if($a->module_loaded) {
162 $a->page['page_title'] = $a->module;
163 if(function_exists($a->module . '_init')) {
164 $func = $a->module . '_init';
168 if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error)
169 && (function_exists($a->module . '_post'))
170 && (! x($_POST,'auth-params'))) {
171 $func = $a->module . '_post';
175 if((! $a->error) && (function_exists($a->module . '_afterpost'))) {
176 $func = $a->module . '_afterpost';
180 if((! $a->error) && (function_exists($a->module . '_content'))) {
181 $func = $a->module . '_content';
182 $a->page['content'] .= $func($a);
187 // let javascript take you home
189 if(x($_SESSION,'visitor_home'))
190 $homebase = $_SESSION['visitor_home'];
192 $homebase = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
195 $a->page['content'] .= '<script>var homebase="' . $homebase . '" ; </script>';
197 // now that we've been through the module content, see if the page reported
198 // a permission problem and if so, a 403 response would seem to be in order.
200 if(stristr($_SESSION['sysmsg'], t('Permission denied'))) {
201 header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.'));
206 * Report anything which needs to be communicated in the notification area (before the main body)
210 if(x($_SESSION,'sysmsg')) {
211 $a->page['content'] = "<div id=\"sysmsg\" class=\"error-message\">{$_SESSION['sysmsg']}</div>\r\n"
212 . ((x($a->page,'content')) ? $a->page['content'] : '');
213 unset($_SESSION['sysmsg']);
217 call_hooks('page_end', $a->page['content']);
222 * Add a place for the pause/resume Ajax indicator
226 $a->page['content'] .= '<div id="pause"></div>';
231 * Add the navigation (menu) template
235 if($a->module != 'install')
236 require_once('nav.php');
240 * Build the page - now that we have all the components
241 * Make sure the desired theme exists, though if the default theme doesn't exist we're stuffed.
245 $default_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : 'default');
246 if((x($_SESSION,'theme')) && (! file_exists('view/theme/' . $_SESSION['theme'] . '/style.css')))
247 unset($_SESSION['theme']);
249 $a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array(
250 '$stylesheet' => $a->get_baseurl() . '/view/theme/'
251 . ((x($_SESSION,'theme')) ? $_SESSION['theme'] : $default_theme)
256 $profile = $a->profile;
258 header("Content-type: text/html; charset=utf-8");
260 $template = 'view/' . $lang . '/'
261 . ((x($a->page,'template')) ? $a->page['template'] : 'default' ) . '.php';
263 if(file_exists($template))
264 require_once($template);
266 require_once(str_replace($lang . '/', '', $template));
268 session_write_close();