]> git.mxchange.org Git - friendica.git/blob - index.php
personal config storage, template the vcard profile, logging failed uri's to help...
[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  * Modules which emit other serialisations besides HTML (XML,JSON, etc.) should do 
124  * so within the module init and/or post functions and then invoke killme() to terminate
125  * further processing.
126  */
127
128 if(strlen($a->module)) {
129         if(file_exists("mod/{$a->module}.php")) {
130                 include("mod/{$a->module}.php");
131                 $a->module_loaded = true;
132         }
133         else {
134                 logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG);
135                 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
136                 notice( t('Page not found.' ) . EOL);
137         }
138 }
139
140 if($a->module_loaded) {
141         $a->page['page_title'] = $a->module;
142         if(function_exists($a->module . '_init')) {
143                 $func = $a->module . '_init';
144                 $func($a);
145         }
146
147         if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error)
148                 && (function_exists($a->module . '_post'))
149                 && (! x($_POST,'auth-params'))) {
150                 $func = $a->module . '_post';
151                 $func($a);
152         }
153
154         if((! $a->error) && (function_exists($a->module . '_afterpost'))) {
155                 $func = $a->module . '_afterpost';
156                 $func($a);
157         }
158
159         if((! $a->error) && (function_exists($a->module . '_content'))) {
160                 $func = $a->module . '_content';
161                 if(! x($a->page,'content'))
162                         $a->page['content'] = '';
163                 $a->page['content'] .= $func($a);
164         }
165
166 }
167
168 if(stristr($_SESSION['sysmsg'], t('Permission denied'))) {
169         header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.'));
170 }
171
172 /**
173  *
174  * Report anything which needs to be communicated in the notification area (before the main body)
175  *
176  */
177         
178 if(x($_SESSION,'sysmsg')) {
179         $a->page['content'] = "<div id=\"sysmsg\" class=\"error-message\">{$_SESSION['sysmsg']}</div>\r\n"
180                 . ((x($a->page,'content')) ? $a->page['content'] : '');
181         unset($_SESSION['sysmsg']);
182 }
183
184 /**
185  *
186  * Add a place for the pause/resume Ajax indicator
187  *
188  */
189
190 $a->page['content'] .=  '<div id="pause"></div>';
191
192
193 /**
194  *
195  * Add the navigation (menu) template
196  *
197  */
198
199 if($a->module != 'install')
200         require_once('nav.php');
201
202 /**
203  *
204  * Build the page - now that we have all the components
205  * Make sure the desired theme exists, though if the default theme doesn't exist we're stuffed.
206  *
207  */
208
209 if((x($_SESSION,'theme')) && (! file_exists('view/theme/' . $_SESSION['theme'] . '/style.css')))
210         unset($_SESSION['theme']);
211
212 $a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array(
213         '$stylesheet' => $a->get_baseurl() . '/view/theme/'
214                 . ((x($_SESSION,'theme')) ? $_SESSION['theme'] : 'default')
215                 . '/style.css'
216         ));
217
218 $page    = $a->page;
219 $profile = $a->profile;
220
221 header("Content-type: text/html; charset=utf-8");
222
223 $template = 'view/' . $lang . '/' 
224         . ((x($a->page,'template')) ? $a->page['template'] : 'default' ) . '.php';
225
226 if(file_exists($template))
227         require_once($template);
228 else
229         require_once(str_replace($lang . '/', '', $template));
230
231 session_write_close();
232 exit;