]> git.mxchange.org Git - friendica.git/blob - index.php
1c069678135f1dd82d420da5fd81b65f7b1950bd
[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         call_hooks('init_1');
68 }
69
70
71
72 require_once("datetime.php");
73
74 date_default_timezone_set(($default_timezone) ? $default_timezone : 'UTC');
75
76 $a->init_pagehead();
77
78 session_start();
79
80 /**
81  *
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 
85  * link header. 
86  *
87  * What we really need to do is output the raw headers ourselves so we can keep them separate.
88  *
89  */
90  
91 // header('Link: <' . $a->get_baseurl() . '/amcd>; rel="acct-mgmt";');
92
93 if((x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login'))
94         require("auth.php");
95
96 if(! x($_SESSION,'authenticated'))
97         header('X-Account-Management-Status: none');
98
99 if(! x($_SESSION,'sysmsg'))
100         $_SESSION['sysmsg'] = '';
101
102 /*
103  * check_config() is responible for running update scripts. These automatically 
104  * update the DB schema whenever  we push a new one out. 
105  */
106
107
108 if($install)
109         $a->module = 'install';
110 else
111         check_config($a);
112
113
114 /**
115  *
116  * We have already parsed the server path into $->argc and $a->argv
117  *
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:
122  * 
123  * "module"_init
124  * "module"_post (only if there are $_POST variables)
125  * "module"_afterpost
126  * "module"_content - the string return of this function contains our page body
127  *
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.
131  */
132
133
134 if(strlen($a->module)) {
135         if(file_exists("mod/{$a->module}.php")) {
136                 include("mod/{$a->module}.php");
137                 $a->module_loaded = true;
138         }
139         else {
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']);
143                 }
144
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);
148         }
149 }
150
151 /* initialise content region */
152
153 if(! x($a->page,'content'))
154         $a->page['content'] = '';
155
156
157 /**
158  * Call module functions
159  */
160
161 if($a->module_loaded) {
162         $a->page['page_title'] = $a->module;
163         if(function_exists($a->module . '_init')) {
164                 $func = $a->module . '_init';
165                 $func($a);
166         }
167
168         if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error)
169                 && (function_exists($a->module . '_post'))
170                 && (! x($_POST,'auth-params'))) {
171                 $func = $a->module . '_post';
172                 $func($a);
173         }
174
175         if((! $a->error) && (function_exists($a->module . '_afterpost'))) {
176                 $func = $a->module . '_afterpost';
177                 $func($a);
178         }
179
180         if((! $a->error) && (function_exists($a->module . '_content'))) {
181                 $func = $a->module . '_content';
182                 $a->page['content'] .= $func($a);
183         }
184
185 }
186
187 // let javascript take you home
188
189 if(x($_SESSION,'visitor_home'))
190         $homebase = $_SESSION['visitor_home'];
191 elseif(local_user())
192         $homebase = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
193
194 if(isset($homebase))
195         $a->page['content'] .= '<script>var homebase="' . $homebase . '" ; </script>';
196
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.
199
200 if(stristr($_SESSION['sysmsg'], t('Permission denied'))) {
201         header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.'));
202 }
203
204 /**
205  *
206  * Report anything which needs to be communicated in the notification area (before the main body)
207  *
208  */
209         
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']);
214 }
215
216
217 call_hooks('page_end', $a->page['content']);
218
219
220 /**
221  *
222  * Add a place for the pause/resume Ajax indicator
223  *
224  */
225
226 $a->page['content'] .=  '<div id="pause"></div>';
227
228
229 /**
230  *
231  * Add the navigation (menu) template
232  *
233  */
234
235 if($a->module != 'install')
236         require_once('nav.php');
237
238 /**
239  *
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.
242  *
243  */
244
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']);
248
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)
252                 . '/style.css'
253         ));
254
255 $page    = $a->page;
256 $profile = $a->profile;
257
258 header("Content-type: text/html; charset=utf-8");
259
260 $template = 'view/' . $lang . '/' 
261         . ((x($a->page,'template')) ? $a->page['template'] : 'default' ) . '.php';
262
263 if(file_exists($template))
264         require_once($template);
265 else
266         require_once(str_replace($lang . '/', '', $template));
267
268 session_write_close();
269 exit;