3 * pre.php - Automatically prepend to every page.
5 * Copyright 1999-2001, VA Linux Systems
6 * Copyright 2010, Roland Mas <lolando@debian.org>
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once $gfcommon.'include/escapingUtils.php';
26 if (isset($_SERVER) && array_key_exists('PHP_SELF', $_SERVER) && $_SERVER['PHP_SELF']) {
27 $_SERVER['PHP_SELF'] = htmlspecialchars($_SERVER['PHP_SELF']);
30 if (isset($GLOBALS) && array_key_exists('PHP_SELF', $GLOBALS) && $GLOBALS['PHP_SELF']) {
31 $GLOBALS['PHP_SELF'] = htmlspecialchars($GLOBALS['PHP_SELF']);
34 // Block link prefetching (Moz prefetching, Google Web Accelerator, others)
35 // http://www.google.com/webmasters/faq.html#prefetchblock
36 if (getStringFromServer('HTTP_X_moz') === 'prefetch'){
37 header(getStringFromServer('SERVER_PROTOCOL') . ' 404 Prefetch Forbidden');
38 trigger_error('Prefetch request forbidden.');
42 if (!isset($no_gz_buffer) || !$no_gz_buffer) {
43 ob_start("ob_gzhandler");
47 require $gfcommon.'include/config.php';
48 require $gfcommon.'include/config-vars.php';
50 forge_read_config_file ($gfconfig.'/config.ini') ;
51 forge_read_config_dir ($gfconfig.'/config.ini.d/') ;
52 if (($ecf = forge_get_config ('extra_config_files')) != NULL) {
53 $ecfa = explode (',', $ecf) ;
54 foreach ($ecfa as $cf) {
56 forge_read_config_file ($cf) ;
59 if (($ecd = forge_get_config ('extra_config_dirs')) != NULL) {
60 $ecda = explode (',', $ecd) ;
61 foreach ($ecda as $cd) {
63 forge_read_config_file ($cd) ;
67 // Get constants used for flags or status
68 require $gfcommon.'include/constants.php';
70 // Base error library for new objects
71 require_once $gfcommon.'include/Error.class.php';
73 // Database abstraction
74 require_once $gfcommon.'include/database-pgsql.php';
76 if (!$GLOBALS['gfconn']) {
77 print forge_get_config ('forge_name')." Could Not Connect to Database: ".db_error();
82 require_once $gfcommon.'include/session.php';
85 require_once $gfcommon.'include/System.class.php';
86 if (!forge_get_config('account_manager_type')) {
87 $sys_account_manager_type='UNIX';
89 require_once $gfcommon.'include/system/'.forge_get_config('account_manager_type').'.class.php';
90 $amt = forge_get_config('account_manager_type') ;
93 // User-related classes and functions
94 require_once $gfcommon.'include/User.class.php';
96 // Project-related classes and functions
97 require_once $gfcommon.'include/Group.class.php';
99 // Permission-related functions
100 require_once $gfcommon.'include/Permission.class.php';
103 require_once $gfcommon.'include/Plugin.class.php' ;
104 require_once $gfcommon.'include/PluginManager.class.php' ;
106 // SCM-specific plugins subsystem
107 require_once $gfcommon.'include/SCMPlugin.class.php' ;
109 setup_plugin_manager () ;
112 if (forge_get_config('use_jabber')) {
113 require_once $gfcommon.'include/Jabber.class.php';
116 if (isset($_SERVER['SERVER_SOFTWARE'])) { // We're on the web
117 // exit_error() and variants (for the web)
118 require_once $gfwww.'include/exit.php';
120 // Library to determine browser settings
121 require_once $gfwww.'include/browser.php';
123 // HTML layout class, may be overriden by the Theme class
124 require_once $gfwww.'include/Layout.class.php';
126 // Various HTML utilities
127 require_once $gfcommon.'include/utils.php';
129 // Library to set up context help
130 require_once $gfwww.'include/help.php';
132 // Various HTML libs like button bar, themable
133 require_once $gfwww.'include/html.php';
135 // Forms key generation
136 require_once $gfcommon.'include/forms.php';
138 // Determine if there's a web session running
141 plugin_hook('after_session_set');
144 if (!session_loggedin() && forge_get_config ('force_login') == 1 ) {
145 $expl_pathinfo = explode('/',getStringFromServer('REQUEST_URI'));
146 if (getStringFromServer('REQUEST_URI')!='/' && $expl_pathinfo[1]!='account' && $expl_pathinfo[1]!='export' ) exit_not_logged_in();
147 // Show proj* export even if not logged in when force login
148 // If not default web project page would be broken
149 if ($expl_pathinfo[1]=='export' && !ereg("^proj", $expl_pathinfo[2])) exit_not_logged_in();
152 // Insert this page view into the database
153 require_once $gfwww.'include/logger.php';
155 // If logged in, set up a $LUSER var referencing
156 // the logged in user's object
157 if (session_loggedin()) {
158 $LUSER =& session_get_user();
159 $LUSER->setUpTheme();
160 putenv ('TZ='. $LUSER->getTimeZone());
161 header ('Cache-Control: private');
164 require_once forge_get_config('themes_root').forge_get_config('default_theme').'/Theme.class.php';
165 $HTML = new Theme () ;
166 } else { // Script run from cron or a command line
167 require_once $gfwww.'include/squal_exit.php';
171 require_once $gfcommon.'include/gettext.php';
172 require_once $gfcommon.'include/group_section_texts.php';
174 setup_gettext_from_context();
181 $LUSER - Logged in user object
188 // c-file-style: "bsd"