]> git.mxchange.org Git - friendica.git/blob - index.php
c3933dc8b4681559964162aa21060c717dcd66b4
[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 database.
10
11 $install = ((file_exists('.htconfig.php')) ? false : true);
12
13 @include(".htconfig.php");
14 require_once("dba.php");
15 $db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
16         unset($db_host, $db_user, $db_pass, $db_data);
17
18 if(! $install)
19         require_once("session.php");
20
21 require_once("datetime.php");
22
23 date_default_timezone_set(($default_timezone) ? $default_timezone : 'UTC');
24
25 $a->init_pagehead();
26
27 session_start();
28
29
30 if((x($_SESSION,'authenticated')) || (x($_POST['auth-params'])))
31         require("auth.php");
32
33 if($install)
34         $a->module = 'install';
35 else
36         check_config($a);
37
38 if(strlen($a->module)) {
39         if(file_exists("mod/{$a->module}.php")) {
40                 include("mod/{$a->module}.php");
41                 $a->module_loaded = true;
42         }
43         else {
44                 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
45                 notice( t('Page not found' ) . EOL);
46         }
47 }
48
49 // invoke module functions
50 // Important: Modules normally do not emit content, unless you need it for debugging.
51 // The module_init, module_post, and module_afterpost functions process URL parameters and POST processing.
52 // The module_content function returns content text to this file where it is included on the page.
53 // Modules emitting XML/Atom, etc. should do so idirectly and promptly exit before the HTML page can be rendered.
54 // "Most" HTML resides in the view directory as text templates with macro substitution. 
55 // They look like HTML with PHP variables but only a couple pass through the PHP processor - those with .php extensions.
56 // The macro substitution is defined per page for the .tpl files. 
57 // Information transfer between functions can be accomplished via the App session '$a' and its related variables.
58 // x() queries both a variable's existence and that it is "non-zero" or "non-empty" depending on how it is called. 
59 // q() is the SQL query form. All string (%s) variables MUST be passed through dbesc(). 
60 // All int values MUST be cast to integer using intval(); 
61
62 if($a->module_loaded) {
63         $a->page['page_title'] = $a->module;
64         if(function_exists($a->module . '_init')) {
65                 $func = $a->module . '_init';
66                 $func($a);
67         }
68
69         if(($_SERVER['REQUEST_METHOD'] == 'POST') && (! $a->error)
70                 && (function_exists($a->module . '_post'))
71                 && (! x($_POST,'auth-params'))) {
72                 $func = $a->module . '_post';
73                 $func($a);
74         }
75
76         if((! $a->error) && (function_exists($a->module . '_afterpost'))) {
77                 $func = $a->module . '_afterpost';
78                 $func($a);
79         }
80
81         if((! $a->error) && (function_exists($a->module . '_content'))) {
82                 $func = $a->module . '_content';
83                 $a->page['content'] .= $func($a);
84         }
85
86 }
87
88 // report anything important happening
89         
90 if(x($_SESSION,'sysmsg')) {
91         $a->page['content'] = "<div id=\"sysmsg\" class=\"error-message\">{$_SESSION['sysmsg']}</div>\r\n"
92                 . $a->page['content'];
93         unset($_SESSION['sysmsg']);
94 }
95
96 if(stristr($_SESSION['sysmsg'], t('Permission denied'))) {
97         header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.'));
98 }
99
100
101 // Feel free to comment out this line on production sites.
102 $a->page['content'] .= $debug_text;
103
104 // build page
105
106 // Navigation (menu) template
107 if($a->module != 'install')
108         require_once("nav.php");
109
110 $a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array(
111         '$stylesheet' => $a->get_baseurl() . '/view/theme/'
112                 . ((x($_SESSION,'theme')) ? $_SESSION['theme'] : 'default')
113                 . '/style.css'
114         ));
115
116 $page    = $a->page;
117 $profile = $a->profile;
118
119 header("Content-type: text/html; charset=utf-8");
120
121 $template = "view/" 
122         . ((x($a->page,'template')) ? $a->page['template'] : 'default' ) 
123         . ".php";
124
125 require_once($template);
126
127 session_write_close();
128 exit;