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