]> git.mxchange.org Git - friendica.git/blob - index.php
never enough comments
[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
67 require_once("datetime.php");
68
69 date_default_timezone_set(($default_timezone) ? $default_timezone : 'UTC');
70
71 $a->init_pagehead();
72
73 session_start();
74
75 /**
76  *
77  * For Mozilla auth manager - still needs sorting, and this might conflict with LRDD header.
78  * Apache/PHP lumps the Link: headers into one - and other services might not be able to parse it
79  * this way. There's a PHP flag to link the headers because by default this will over-write any other 
80  * link header. 
81  *
82  * What we really need to do is output the raw headers ourselves so we can keep them separate.
83  *
84  */
85  
86 // header('Link: <' . $a->get_baseurl() . '/amcd>; rel="acct-mgmt";');
87
88 if((x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login'))
89         require("auth.php");
90
91 if(! x($_SESSION,'authenticated'))
92         header('X-Account-Management-Status: none');
93
94 if(! x($_SESSION,'sysmsg'))
95         $_SESSION['sysmsg'] = '';
96
97 /*
98  * check_config() is responible for running update scripts. These automatically 
99  * update the DB schema whenever  we push a new one out. 
100  */
101
102
103 if($install)
104         $a->module = 'install';
105 else
106         check_config($a);
107
108
109 /**
110  *
111  * We have already parsed the server path into $->argc and $a->argv
112  *
113  * $a->argv[0] is our module name. We will load the file mod/{$a->argv[0]}.php
114  * and use it for handling our URL request.
115  * The module file contains a few functions that we call in various circumstances
116  * and in the following order:
117  * 
118  * "module"_init
119  * "module"_post (only if there are $_POST variables)
120  * "module"_afterpost
121  * "module"_content - the string return of this function contains our page body
122  *
123  */
124
125 if(strlen($a->module)) {
126         if(file_exists("mod/{$a->module}.php")) {
127                 include("mod/{$a->module}.php");
128                 $a->module_loaded = true;
129         }
130         else {
131                 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
132                 notice( t('Page not found.' ) . EOL);
133         }
134 }
135
136 if($a->module_loaded) {
137         $a->page['page_title'] = $a->module;
138         if(function_exists($a->module . '_init')) {
139                 $func = $a->module . '_init';
140                 $func($a);
141         }
142
143         if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error)
144                 && (function_exists($a->module . '_post'))
145                 && (! x($_POST,'auth-params'))) {
146                 $func = $a->module . '_post';
147                 $func($a);
148         }
149
150         if((! $a->error) && (function_exists($a->module . '_afterpost'))) {
151                 $func = $a->module . '_afterpost';
152                 $func($a);
153         }
154
155         if((! $a->error) && (function_exists($a->module . '_content'))) {
156                 $func = $a->module . '_content';
157                 if(! x($a->page,'content'))
158                         $a->page['content'] = '';
159                 $a->page['content'] .= $func($a);
160         }
161
162 }
163
164 if(stristr($_SESSION['sysmsg'], t('Permission denied'))) {
165         header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.'));
166 }
167
168 /**
169  *
170  * Report anything which needs to be communicated in the notification area (before the main body)
171  *
172  */
173         
174 if(x($_SESSION,'sysmsg')) {
175         $a->page['content'] = "<div id=\"sysmsg\" class=\"error-message\">{$_SESSION['sysmsg']}</div>\r\n"
176                 . ((x($a->page,'content')) ? $a->page['content'] : '');
177         unset($_SESSION['sysmsg']);
178 }
179
180 /**
181  *
182  * Add a place for the pause/resume Ajax indicator
183  *
184  */
185
186 $a->page['content'] .=  '<div id="pause"></div>';
187
188
189 /**
190  *
191  * Add the navigation (menu) template
192  *
193  */
194
195 if($a->module != 'install')
196         require_once("nav.php");
197
198 /**
199  *
200  * Build the page - now that we have all the components
201  * Make sure the desired theme exists, though if the default theme doesn't exist we're stuffed.
202  *
203  */
204
205 if((x($_SESSION,'theme')) && (! file_exists('view/theme/' . $_SESSION['theme'] . '/style.css')))
206         unset($_SESSION['theme']);
207
208 $a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array(
209         '$stylesheet' => $a->get_baseurl() . '/view/theme/'
210                 . ((x($_SESSION,'theme')) ? $_SESSION['theme'] : 'default')
211                 . '/style.css'
212         ));
213
214 $page    = $a->page;
215 $profile = $a->profile;
216
217 header("Content-type: text/html; charset=utf-8");
218
219 $template = 'view/' . $lang . '/' 
220         . ((x($a->page,'template')) ? $a->page['template'] : 'default' ) . '.php';
221
222 if(file_exists($template))
223         require_once($template);
224 else
225         require_once(str_replace($lang . '/', '', $template));
226
227 session_write_close();
228 exit;