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