index.php

Go to the documentation of this file.
00001 <?php
00002 # streber - a php5 based project management system  (c) 2005-2007  / www.streber-pm.org
00003 # Distributed under the terms and conditions of the GPL as stated in lang/license.html
00004 
00023 error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE | E_STRICT |E_PARSE|E_CORE_ERROR|E_CORE_WARNING|E_COMPILE_ERROR);
00024 
00025 
00026 /********************************************************************************
00027 * setup framework
00028 ********************************************************************************/
00029 
00030 ### create a function to make sure we started at index.php ###
00031 function startedIndexPhp() {return true; }
00032 
00033 initialBasicFixes();
00034 initProfiler();
00035 
00036 ### include std functions ###
00037 require_once('std/common.inc.php');
00038 require_once('std/errorhandler.inc.php');
00039 require_once('conf/defines.inc.php');
00040 require_once('conf/conf.inc.php');
00041 
00042 
00043 ### if no db_settings start installation ###
00044 if(file_exists(confGet('DIR_SETTINGS').confGet('FILE_DB_SETTINGS'))) {
00045     require_once(confGet('DIR_SETTINGS').confGet('FILE_DB_SETTINGS'));
00046 }
00047 else {
00048     header("location:install/install.php");
00049     exit();
00050 }
00051 
00052 ### user-settings ##
00053 if(file_exists('customize.inc.php')) {
00054     require_once(confGet('DIR_STREBER') . 'customize.inc.php');
00055 }
00056 
00057 filterGlobalArrays();
00058 
00059 
00063 if(confGet('USE_PROFILER')) {
00064     require_once(confGet('DIR_STREBER') . "std/profiler.inc.php");
00065 }
00066 else {
00067     ###  define empty functions ###
00068     function measure_start($id){};
00069     function measure_stop($id){};
00070     function render_measures(){return '';};
00071 }
00072 
00073 measure_start('time_complete'); # measure complete time (stops before profiling)
00074 measure_start('core_includes'); # measure time for including core-components
00075 
00076 
00077 ### included database handler ###
00078 $db_type = confGet('DB_TYPE');
00079 if(file_exists("db/db_".$db_type."_class.php")){
00080     require_once(confGet('DIR_STREBER') . "db/db_".$db_type."_class.php");
00081 }
00082 else{
00083     trigger_error("Datebase handler not found for db-type '$db_type'", E_USER_ERROR);
00084 }
00085 
00086 
00087 ### include the core-classes (php5) ###
00088 require_once( confGet('DIR_STREBER') . 'db/db.inc.php');
00089 require_once( confGet('DIR_STREBER') . 'std/class_auth.inc.php');
00090 require_once( confGet('DIR_STREBER') . 'db/db_item.inc.php');
00091 require_once( confGet('DIR_STREBER') . 'std/class_pagehandler.inc.php');
00092 
00093 ### trigger db request ###
00094 $dbh = new DB_Mysql;
00095 if(!is_null(confGet('SQL_MODE'))) {
00096     $dbh->prepare('SET sql_mode = "'. confGet('SQL_MODE') .'"')->execute();
00097 }
00098 if ($result = $dbh->prepare('SELECT NOW()')) {
00099   $result->execute();
00100 }
00101 
00102 measure_stop( confGet('DIR_STREBER') . 'core_includes');
00103 
00107 measure_start('authorize');
00108 if(!$user = $auth->setCurUserByCookie()) {
00109     $user = $auth->setCurUserAsAnonymous();
00110 }
00111 measure_stop('authorize');
00112 
00113 
00115 {
00116     measure_start('language');
00117     if($user && !Auth::isAnonymousUser()) {
00118         $auth->storeUserCookie();                               # refresh user-cookie
00119 
00120         if(isset($auth->cur_user->language)
00121             && $auth->cur_user->language != ""
00122             && $auth->cur_user->language != "en"
00123         ) {
00124             setLang($auth->cur_user->language);
00125             Person::initFields();
00126         }
00127     }
00128     else {
00129         setLang(confGet('DEFAULT_LANGUAGE'));
00130         Person::initFields();
00131     }
00132     measure_stop('language');
00133 }
00134 
00136 measure_start('plugins');
00137 require_once( confGet('DIR_STREBER') . "std/constant_names.inc.php");
00138 require_once( confGet('DIR_STREBER') . "render/render_page.inc.php");
00139 require_once( confGet('DIR_STREBER') . "pages/_handles.inc.php");                 # already requires language-support
00140 measure_stop('plugins');
00141 
00142 if(function_exists('postInitCustomize')) {
00143     postInitCustomize();
00144 }
00145 
00146 measure_start('init2');
00147 global $PH;
00148 if($g_tags_removed) {
00149     new FeedbackWarning( __('For security reasons html tags were removed from passed variables')
00150     . " " . sprintf(__("Read more about %s."), $PH->getWikiLink('security settings')));
00151 }
00152 
00153 /********************************************************************************
00154 * route to pages
00155 ********************************************************************************/
00156 ### if index.php was called without target, check environment ###
00157 if(!$requested_page_id = get('go')) {
00158     require_once( confGet('DIR_STREBER') . "./std/check_version.inc.php");
00159     validateEnvironment();
00160 }
00161 
00162 
00163 
00164 $requested_page= $PH->getRequestedPage();
00165 
00166 ### pages with http auth ###
00167 
00168 
00169 if($requested_page->http_auth) {
00170 
00171     if(!$user) {
00172 
00173         if($user= Auth::getUserByHttpAuth()) {
00174 
00175             $PH->show($requested_page->id);
00176 
00177             exit();
00178         }
00179         else {
00180            echo __('Sorry.  Authentication failed');
00181            exit();
00182         }
00183     }
00184 }
00185 
00186 ### valid user or anonymous user ###
00187 if($user) {
00188 
00189     ### if no target-page show home ###
00190     if(!$requested_page_id) {
00191 
00192         ### if user has only one project go there ###
00193         $projects = $auth->cur_user->getProjects();
00194         if(count($projects) == 1) {
00195             new FeedbackMessage(sprintf(confGet('MESSAGE_WELCOME_ONEPROJECT'), $auth->cur_user->name,$projects[0]->name));
00196             $PH->show('projView',array('prj'=>$projects[0]->id));
00197         }
00198         else {
00199             new FeedbackMessage(confGet('MESSAGE_WELCOME_HOME'));
00200             $PH->show('home',array());
00201         }
00202         exit();
00203     }
00204 
00205     $PH->show($requested_page_id);
00206     exit();
00207 }
00208 
00209 ### anonymous pages like Login or License ###
00210 if($requested_page_id && $requested_page && $requested_page->valid_for_anonymous) {
00211     $PH->show($requested_page_id);
00212     exit();
00213 }
00214 
00215 ### identified by tuid (email notification, etc.)
00216 if(get('tuid') && $requested_page && $requested_page->valid_for_tuid) {
00217     if($auth->setCurUserByIdentifier(get('tuid'))) {
00218         log_message('...valid identifier-string(' . get('tuid') . ')', LOG_MESSAGE_DEBUG);
00219 
00220         ### set language ###
00221         if(isset($auth->cur_user->language)
00222             && $auth->cur_user->language != ""
00223             && $auth->cur_user->language != "en"
00224         ) {
00225             setLang($auth->cur_user->language);
00226         }
00227 
00228         ### store coookie ###
00229         $auth->storeUserCookie();
00230 
00231         ### render target page ###
00232         $PH->show($requested_page_id);
00233         exit();
00234     }
00235     else {
00236         new FeedbackWarning(__("Sorry, but this activation code is no longer valid. If you already have an account, you could enter you name and use the <b>forgot password link</b> below."));
00237         log_message('...invalid identifier-string(' . get('tuid') . ')', LOG_MESSAGE_DEBUG);
00238     }
00239 }
00240 
00241 
00242 ### all other request lead to login-form ###
00243 $PH->show('loginForm');
00244 exit();
00245 
00246 
00247 
00248 /********************************************************************
00249 * basic setup functions follow
00250 ********************************************************************/
00251 
00255 function initProfiler()
00256 {
00257     global $TIME_START;
00258     $TIME_START=microtime(1);
00259     global $DB_ITEMS_LOADED;
00260     $DB_ITEMS_LOADED=0;
00261 
00262     global $g_count_db_statements;
00263     $g_count_db_statements = 0;
00264 }
00265 
00266 
00270 function initialBasicFixes()
00271 {
00275     if (function_exists('date_default_timezone_set')) {
00276         $tz= @date_default_timezone_get();
00277         date_default_timezone_set($tz);
00278     }
00279 
00280     ini_set('zend.ze1_compatibility_mode', 0);
00281     ini_set("pcre.backtrack_limit", -1);                        # fix 5.2.0 prce bug with render_wiki
00282     if(function_exists('mb_internal_encoding')) {
00283         mb_internal_encoding("UTF-8");
00284     }
00285     #ini_set("mbstring.func_overload", 2);
00286 
00291     if(phpversion() < "5.0.0") {
00292         echo "Sorry, but Streber requires php5 or higher.";
00293         exit();
00294     }
00295 }
00296 
00297 
00313 function filterGlobalArrays()
00314 {
00315     ### clean global namespace from register globals ###
00316     if (@ini_get('register_globals')) {
00317        foreach ($_REQUEST as $key => $value) {
00318            unset($GLOBALS[$key]);
00319         }
00320     }
00321 
00322     clearRequestVars();
00323     addRequestVars($_GET);
00324     addRequestVars($_POST);
00325     addRequestVars($_COOKIE);
00326 
00327     $_COOKIE= $_GET= $_POST=array();
00328 }
00329 
00330 
00331 
00332 ?>
00333 
00334 
00335 
00336 

Generated on Sun Mar 4 17:19:28 2007 for streber by  doxygen 1.5.1-p1