]> git.mxchange.org Git - friendica.git/blob - index.php
Merge branch 'master' of git://github.com/friendika/friendika
[friendica.git] / index.php
1 <?php
2
3 /**
4  *
5  * Friendika
6  *
7  */
8
9 /**
10  *
11  * bootstrap the application
12  *
13  */
14
15 require_once('boot.php');
16
17 $a = new App;
18
19 /**
20  *
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.
23  *
24  */
25
26 $install = ((file_exists('.htconfig.php')) ? false : true);
27
28 @include(".htconfig.php");
29
30 /**
31  *
32  * Get the language setting directly from system variables, bypassing get_config()
33  * as database may not yet be configured.
34  *
35  */
36
37 $lang = ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
38         
39 load_translation_table($lang);
40
41 /**
42  *
43  * Try to open the database;
44  *
45  */
46
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);
50
51
52 /**
53  *
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
61  *
62  */
63
64 if(! $install) {
65         require_once("session.php");
66         load_hooks();
67 }
68
69 require_once("datetime.php");
70
71 date_default_timezone_set(($default_timezone) ? $default_timezone : 'UTC');
72
73 $a->init_pagehead();
74
75 session_start();
76
77 /**
78  *
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 
82  * link header. 
83  *
84  * What we really need to do is output the raw headers ourselves so we can keep them separate.
85  *
86  */
87  
88 // header('Link: <' . $a->get_baseurl() . '/amcd>; rel="acct-mgmt";');
89
90 if((x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login'))
91         require("auth.php");
92
93 if(! x($_SESSION,'authenticated'))
94         header('X-Account-Management-Status: none');
95
96 if(! x($_SESSION,'sysmsg'))
97         $_SESSION['sysmsg'] = '';
98
99 /*
100  * check_config() is responible for running update scripts. These automatically 
101  * update the DB schema whenever  we push a new one out. 
102  */
103
104
105 if($install)
106         $a->module = 'install';
107 else
108         check_config($a);
109
110
111 /**
112  *
113  * We have already parsed the server path into $->argc and $a->argv
114  *
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:
119  * 
120  * "module"_init
121  * "module"_post (only if there are $_POST variables)
122  * "module"_afterpost
123  * "module"_content - the string return of this function contains our page body
124  *
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.
128  */
129
130
131 if(strlen($a->module)) {
132         if(file_exists("mod/{$a->module}.php")) {
133                 include("mod/{$a->module}.php");
134                 $a->module_loaded = true;
135         }
136         else {
137                 if((x($_SERVER,'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
138                         logger('index.php: dreamhost_error_hack invoked');
139                         goaway($a->get_baseurl() . $_SERVER['REQUEST_URI']);
140                 }
141
142                 logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG);
143                 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
144                 notice( t('Page not found.' ) . EOL);
145         }
146 }
147
148 if($a->module_loaded) {
149         $a->page['page_title'] = $a->module;
150         if(function_exists($a->module . '_init')) {
151                 $func = $a->module . '_init';
152                 $func($a);
153         }
154
155         if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error)
156                 && (function_exists($a->module . '_post'))
157                 && (! x($_POST,'auth-params'))) {
158                 $func = $a->module . '_post';
159                 $func($a);
160         }
161
162         if((! $a->error) && (function_exists($a->module . '_afterpost'))) {
163                 $func = $a->module . '_afterpost';
164                 $func($a);
165         }
166
167         if((! $a->error) && (function_exists($a->module . '_content'))) {
168                 $func = $a->module . '_content';
169                 if(! x($a->page,'content'))
170                         $a->page['content'] = '';
171                 $a->page['content'] .= $func($a);
172         }
173
174 }
175
176 if(stristr($_SESSION['sysmsg'], t('Permission denied'))) {
177         header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.'));
178 }
179
180 /**
181  *
182  * Report anything which needs to be communicated in the notification area (before the main body)
183  *
184  */
185         
186 if(x($_SESSION,'sysmsg')) {
187         $a->page['content'] = "<div id=\"sysmsg\" class=\"error-message\">{$_SESSION['sysmsg']}</div>\r\n"
188                 . ((x($a->page,'content')) ? $a->page['content'] : '');
189         unset($_SESSION['sysmsg']);
190 }
191
192 /**
193  *
194  * Add a place for the pause/resume Ajax indicator
195  *
196  */
197
198 $a->page['content'] .=  '<div id="pause"></div>';
199
200
201 /**
202  *
203  * Add the navigation (menu) template
204  *
205  */
206
207 if($a->module != 'install')
208         require_once('nav.php');
209
210 /**
211  *
212  * Build the page - now that we have all the components
213  * Make sure the desired theme exists, though if the default theme doesn't exist we're stuffed.
214  *
215  */
216
217 if((x($_SESSION,'theme')) && (! file_exists('view/theme/' . $_SESSION['theme'] . '/style.css')))
218         unset($_SESSION['theme']);
219
220 $a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array(
221         '$stylesheet' => $a->get_baseurl() . '/view/theme/'
222                 . ((x($_SESSION,'theme')) ? $_SESSION['theme'] : 'default')
223                 . '/style.css'
224         ));
225
226 $page    = $a->page;
227 $profile = $a->profile;
228
229 header("Content-type: text/html; charset=utf-8");
230
231 $template = 'view/' . $lang . '/' 
232         . ((x($a->page,'template')) ? $a->page['template'] : 'default' ) . '.php';
233
234 if(file_exists($template))
235         require_once($template);
236 else
237         require_once(str_replace($lang . '/', '', $template));
238
239 session_write_close();
240 exit;