]> git.mxchange.org Git - friendica.git/blob - index.php
4ad5f17e203d5387b4394a2d758d48af2f76008e
[friendica.git] / index.php
1 <?php
2
3 require_once("boot.php");
4
5 $a = new App;
6
7 $debug_text = ''; // Debugging functions should never be used on production systems.
8
9 // Setup the language and database.
10
11 $install = ((file_exists('.htconfig.php')) ? false : true);
12
13 @include(".htconfig.php");
14
15 // get language setting directly from system variables, bypassing get_config()
16 // as database may not yet be configured.
17
18 $lang = ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
19         
20 load_translation_table($lang);
21
22 require_once("dba.php");
23 $db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
24         unset($db_host, $db_user, $db_pass, $db_data);
25
26 if(! $install)
27         require_once("session.php");
28
29 require_once("datetime.php");
30
31 date_default_timezone_set(($default_timezone) ? $default_timezone : 'UTC');
32
33 $a->init_pagehead();
34
35 session_start();
36
37 // header('Link: <' . $a->get_baseurl() . '/amcd>; rel="acct-mgmt";');
38
39 if((x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login'))
40         require("auth.php");
41
42 if(! x($_SESSION,'authenticated'))
43         header('X-Account-Management-Status: none');
44
45 if(! x($_SESSION,'sysmsg'))
46         $_SESSION['sysmsg'] = '';
47
48 if($install)
49         $a->module = 'install';
50 else
51         check_config($a);
52
53 if(strlen($a->module)) {
54         if(file_exists("mod/{$a->module}.php")) {
55                 include("mod/{$a->module}.php");
56                 $a->module_loaded = true;
57         }
58         else {
59                 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
60                 notice( t('Page not found.' ) . EOL);
61         }
62 }
63
64 if($a->module_loaded) {
65         $a->page['page_title'] = $a->module;
66         if(function_exists($a->module . '_init')) {
67                 $func = $a->module . '_init';
68                 $func($a);
69         }
70
71         if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error)
72                 && (function_exists($a->module . '_post'))
73                 && (! x($_POST,'auth-params'))) {
74                 $func = $a->module . '_post';
75                 $func($a);
76         }
77
78         if((! $a->error) && (function_exists($a->module . '_afterpost'))) {
79                 $func = $a->module . '_afterpost';
80                 $func($a);
81         }
82
83         if((! $a->error) && (function_exists($a->module . '_content'))) {
84                 $func = $a->module . '_content';
85                 if(! x($a->page,'content'))
86                         $a->page['content'] = '';
87                 $a->page['content'] .= $func($a);
88         }
89
90 }
91
92 if(stristr($_SESSION['sysmsg'], t('Permission denied'))) {
93         header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.'));
94 }
95
96 // report anything important happening
97         
98 if(x($_SESSION,'sysmsg')) {
99         $a->page['content'] = "<div id=\"sysmsg\" class=\"error-message\">{$_SESSION['sysmsg']}</div>\r\n"
100                 . ((x($a->page,'content')) ? $a->page['content'] : '');
101         unset($_SESSION['sysmsg']);
102 }
103
104
105 // Feel free to comment out this line on production sites.
106 $a->page['content'] .= $debug_text;
107
108 $a->page['content'] .=  '<div id="pause"></div>';
109 // build page
110
111
112 // Navigation (menu) template
113 if($a->module != 'install')
114         require_once("nav.php");
115
116 // make sure the desired theme exists, though if the default theme doesn't exist we're stuffed.
117
118 if((x($_SESSION,'theme')) && (! file_exists('view/theme/' . $_SESSION['theme'] . '/style.css')))
119         unset($_SESSION['theme']);
120
121 $a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array(
122         '$stylesheet' => $a->get_baseurl() . '/view/theme/'
123                 . ((x($_SESSION,'theme')) ? $_SESSION['theme'] : 'default')
124                 . '/style.css'
125         ));
126
127 $page    = $a->page;
128 $profile = $a->profile;
129
130 header("Content-type: text/html; charset=utf-8");
131
132 $template = 'view/' . $lang . '/' 
133         . ((x($a->page,'template')) ? $a->page['template'] : 'default' ) . '.php';
134
135 if(file_exists($template))
136         require_once($template);
137 else
138         require_once(str_replace($lang . '/', '', $template));
139
140 session_write_close();
141 exit;