コード例 #1
0
 public static function startUp()
 {
     if (array_key_exists('enableDebug', $GLOBALS['TL_CONFIG']) && $GLOBALS['TL_CONFIG']['enableDebug'] && !self::$fb) {
         // ok, this is tricky here. We need to use the defined user object before(!) we use the Database in getLoginStatus().
         // Otherwise we will end up in a race condition for the destructors (User wants to save Session::data into Database
         // which might be gone if we instanciate the other way around - finding this one was a major PITA, thanks to leo-unglaub
         // for helping me track that one down).
         // Backend?
         if (TL_MODE == 'BE') {
             BackendUser::getInstance();
         } else {
             if (TL_MODE == 'FE') {
                 FrontendUser::getInstance();
             } else {
                 return;
             }
         }
         $mayUseDebugger = false;
         // pre checks if debugging is allowed.
         if (array_key_exists('enableDebugUser', $GLOBALS['TL_CONFIG']) && strlen($GLOBALS['TL_CONFIG']['enableDebugUser'])) {
             $uid = self::getLoginStatus('BE_USER_AUTH');
             if ($uid && count(array_intersect(deserialize($GLOBALS['TL_CONFIG']['enableDebugUser']), array($uid)))) {
                 $mayUseDebugger = true;
             }
         }
         if ($mayUseDebugger || array_key_exists('enableDebugMember', $GLOBALS['TL_CONFIG']) && strlen($GLOBALS['TL_CONFIG']['enableDebugMember'])) {
             $uid = self::getLoginStatus('FE_USER_AUTH');
             if ($uid && count(array_intersect(deserialize($GLOBALS['TL_CONFIG']['enableDebugMember']), array($uid)))) {
                 $mayUseDebugger = true;
             }
         }
         if (!$mayUseDebugger) {
             return;
         }
         // starting up.
         $fb = TYPOlightDebugFirePHP::getInstance(true);
         self::$fb = $fb;
         if ($fb->detectClientExtension()) {
             // native encoding dumps way too many notices. Very bad when within error handler, as we can not capture it then.
             $fb->setOptions(array('useNativeJsonEncode' => false));
             $fb->setEnabled(true);
             set_error_handler(array('TYPOlightDebug', 'errorHandler'));
             error_reporting(E_ALL);
             ini_set('display_errors', false);
             register_shutdown_function('debug_shutdown');
             $fb->registerExceptionHandler();
             if (array_key_exists('logErrors', $GLOBALS['TL_CONFIG'])) {
                 foreach (deserialize($GLOBALS['TL_CONFIG']['logErrors']) as $k => $v) {
                     self::$log_severity = self::$log_severity + $v;
                 }
             }
             $GLOBALS['TL_DEBUG'] = new TYPOlightDebugArray(array_key_exists('TL_DEBUG', $GLOBALS) ? $GLOBALS['TL_DEBUG'] : array());
             $GLOBALS['TL_CONFIG']['debugMode'] = true;
             $GLOBALS['TL_CONFIG'] = new TYPOlightDebugConfig(array_key_exists('TL_CONFIG', $GLOBALS) ? $GLOBALS['TL_CONFIG'] : array());
             // check if gZip is active and usable (will get used by Template class). If it is not in use, we have to put an output handler into place to prevent headers from being sent too early.
             $arrEncoding = Environment::getInstance()->httpAcceptEncoding;
             if (!($GLOBALS['TL_CONFIG']['enableGZip'] && (in_array('gzip', $arrEncoding) || in_array('x-gzip', $arrEncoding)) && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression'))) {
                 ob_start();
                 ini_set('implicit_flush', true);
                 self::$ob_started = true;
             }
             //$fb->skipClassInTrace('Database_Statement->debugQuery');
             if (array_key_exists('hideCoreNotices', $GLOBALS['TL_CONFIG']) && $GLOBALS['TL_CONFIG']['hideCoreNotices']) {
                 self::skipNoticesInFile(TL_ROOT . '/system/functions.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/initialize.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/libraries/Controller.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/libraries/Database.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/libraries/Input.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/libraries/Model.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/libraries/Session.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/libraries/Search.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/libraries/System.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/libraries/Template.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/libraries/Widget.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/libraries/Environment.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/modules/backend');
                 self::skipNoticesInFile(TL_ROOT . '/system/modules/backend/dca');
                 self::skipNoticesInFile(TL_ROOT . '/system/modules/frontend');
                 self::skipNoticesInFile(TL_ROOT . '/system/drivers/DC_File.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/drivers/DC_Folder.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/drivers/DC_Table.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/drivers/DB_Mysqli.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/modules/registration/ModuleRegistration.php');
                 self::skipNoticesInFile(TL_ROOT . '/system/modules/memberlist/dca/tl_member.php');
             }
             if (array_key_exists('showNotices', $GLOBALS['TL_CONFIG']) && $GLOBALS['TL_CONFIG']['showNotices']) {
                 self::$showNotices = deserialize($GLOBALS['TL_CONFIG']['showNotices']);
             }
             $fb->setObjectFilter('DB_Mysqli_Result', array('resResult'));
             //$fb->setObjectFilter('Environment', array('*'));
             if (array_key_exists('logHooks', $GLOBALS['TL_CONFIG']) && $GLOBALS['TL_CONFIG']['logHooks']) {
                 $hooks = array_key_exists('logHookSelection', $GLOBALS['TL_CONFIG']) && $GLOBALS['TL_CONFIG']['logHookSelection'] ? deserialize($GLOBALS['TL_CONFIG']['logHookSelection']) : array();
                 //foreach(array_merge(array_keys($GLOBALS['TL_HOOKS']), $hooks) as $k)
                 foreach ($hooks as $k) {
                     if (!array_key_exists($k, $GLOBALS['TL_HOOKS'])) {
                         $GLOBALS['TL_HOOKS'][$k] = array();
                     }
                     //array_unshift($GLOBALS['TL_HOOKS'][$k],array('TYPOlightDebugHookCatcher', $k));
                     $GLOBALS['TL_HOOKS'][$k] = array(array('TYPOlightDebugHookCatcher', $k)) + $GLOBALS['TL_HOOKS'][$k];
                     $GLOBALS['TL_HOOKS'][$k][] = array('TYPOlightDebugHookCatcher', $k);
                 }
             }
             // add the clean up hooks
             $GLOBALS['TL_HOOKS']['outputFrontendTemplate'][] = array('TYPOlightDebug', 'ProcessDebugData');
             $GLOBALS['TL_HOOKS']['outputBackendTemplate'][] = array('TYPOlightDebug', 'ProcessDebugData');
             if (DIRECTORY_SEPARATOR != '/') {
                 self::$WarnRecursion = 'recursion detected in ' . TL_ROOT . '\\system\\modules\\debug\\FirePHPCore\\FirePHP.class.php on line ';
                 self::warn('Windows support is experimental.');
             } else {
                 self::$WarnRecursion = 'recursion detected in ' . TL_ROOT . '/system/modules/debug/FirePHPCore/FirePHP.class.php on line ';
             }
             self::group('Execution evironment');
             if (function_exists('posix_getpwuid') && function_exists('posix_geteuid') && function_exists('get_current_user')) {
                 $processUser = posix_getpwuid(posix_geteuid());
                 $processUser = $processUser['name'];
                 $scriptUser = get_current_user();
                 if ($processUser != $scriptUser) {
                     self::warn('Script owner: ' . $scriptUser . ' executed as: ' . $processUser);
                 } else {
                     self::info('Script owner: ' . $scriptUser . ' executed as: ' . $processUser);
                 }
             }
             self::info(isset($_GET) && count($_GET) ? $_GET : NULL, '$_GET data');
             self::info(isset($_POST) && count($_POST) ? $_POST : NULL, '$_POST data');
             self::info(isset($_SESSION) && count($_SESSION) ? $_SESSION : NULL, '$_SESSION data');
             self::info(isset($_ENV) && count($_ENV) ? $_ENV : NULL, '$_ENV data');
             $const = get_defined_constants(true);
             self::info($const['user'], 'CONST(app context)');
             self::groupEnd();
             self::log('TYPOlight debugger active (visit: http://www.cyberspectrum.de/ for the manual)');
             // finally set up the tick counter.
             self::$ticks = 0;
             register_tick_function(array('TYPOlightDebug', 'tick_handler'));
             declare (ticks=1);
         } else {
             // no firePHP present, hide the debug output, in future we will need a workaround for this (display debugdata in an iframe or something like that).
             $GLOBALS['TL_CONFIG']['debugMode'] = false;
         }
     }
 }