Project

General

Profile

Feature #18344 ยป bug_7720.diff

Administrator Admin, 2008-03-01 22:47

View differences:

typo3/sysext/cms/tslib/class.tslib_fe.php (Arbeitskopie)
exit;
} elseif (!$GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db)) {
$this->printError('Cannot connect to the current database, "'.TYPO3_db.'"','Database Error');
$this->statistics(503);
exit;
}
} else {
......
exit;
}
$this->printError('The current username, password or host was not accepted when the connection to the database was attempted to be established!','Database Error');
$this->statistics(503);
exit;
}
......
$this->id = $theFirstPage['uid'];
} else {
$this->printError('No pages are found on the rootlevel!');
$this->statistics(503);
exit;
}
}
......
$this->pageNotFoundAndExit('The requested page does not exist!');
} else {
$this->printError('The requested page does not exist!');
$this->statistics(404);
exit;
}
}
......
$this->pageNotFoundAndExit('The requested page does not exist!');
} else {
$this->printError('The requested page does not exist!');
$this->statistics(404);
exit;
}
}
......
// If not rootline we're off...
if (!count($this->rootLine)) {
$this->printError('The requested page didn\'t have a proper connection to the tree-root! <br /><br />('.$this->sys_page->error_getRootLine.')');
$this->statistics(503);
exit;
}
......
if ($this->checkRootlineForIncludeSection()) {
if (!count($this->rootLine)) {
$this->printError('The requested page was not accessible!');
$this->statistics(503);
exit;
} else {
$el = reset($this->rootLine);
......
} else {
$pageLog[] = $page['uid'];
$this->printError('Page shortcuts were looping in uids '.implode(',',$pageLog).'...!');
$this->statistics(500);
exit;
}
}
......
*/
function pageNotFoundAndExit($reason='', $header='') {
$header = $header ? $header : $this->TYPO3_CONF_VARS['FE']['pageNotFound_handling_statheader'];
$this->statistics(404); // ...will we ever get that far?
$this->pageNotFoundHandler($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling'], $header, $reason);
exit;
}
......
if (!is_array($this->pSetup)) {
$this->printError('The page is not configured! [type= '.$this->type.']['.$this->sPre.']');
$this->statistics(503);
exit;
} else {
$this->config['config']=Array();
......
$this->config['rootLine'] = $this->tmpl->rootLine;
$this->config['mainScript'] = trim($this->config['config']['mainScript']) ? trim($this->config['config']['mainScript']) : 'index.php';
// STAT:
$theLogFile = $this->TYPO3_CONF_VARS['FE']['logfile_dir'].$this->config['config']['stat_apache_logfile'];
// Add PATH_site left to $theLogFile if the path is not absolute yet
if (!t3lib_div::isAbsPath($theLogFile)) $theLogFile = PATH_site.$theLogFile;
// Initialize statistics handling: Check filename and permissions
$setStatPageName = $this->statistics_init();
if ($this->config['config']['stat_apache'] && $this->config['config']['stat_apache_logfile'] && !strstr($this->config['config']['stat_apache_logfile'],'/')) {
if (t3lib_div::isAllowedAbsPath($theLogFile)) {
if (!@is_file($theLogFile)) {
touch($theLogFile); // Try to create the logfile
t3lib_div::fixPermissions($theLogFile);
}
if (@is_file($theLogFile) && @is_writable($theLogFile)) {
$this->config['stat_vars']['logFile'] = $theLogFile;
$setStatPageName = true; // Set page name later on
} else {
$GLOBALS['TT']->setTSlogMessage('Could not set logfile path. Check filepath and permissions.',3);
}
}
}
$this->config['FEData'] = $this->tmpl->setup['FEData'];
$this->config['FEData.'] = $this->tmpl->setup['FEData.'];
}
$GLOBALS['TT']->pull();
} else {
$this->printError('No template found!');
$this->statistics(503);
exit;
}
}
......
// Initialize charset settings etc.
$this->initLLvars();
// We want nice names, so we need to know the charset
if ($setStatPageName) {
if ($this->config['config']['stat_apache_niceTitle']) {
$shortTitle = $this->csConvObj->specCharsToASCII($this->renderCharset,$this->page['title']);
} else {
$shortTitle = $this->page['title'];
}
$shortTitle = substr(preg_replace('/[^.[:alnum:]_-]/','_',$shortTitle),0,30);
$pageName = $this->config['config']['stat_apache_pagenames'] ? $this->config['config']['stat_apache_pagenames'] : '[path][title]--[uid].html';
$pageName = str_replace('[title]', $shortTitle ,$pageName);
$pageName = str_replace('[uid]',$this->page['uid'],$pageName);
$pageName = str_replace('[alias]',$this->page['alias'],$pageName);
$pageName = str_replace('[type]',$this->type,$pageName);
$temp = $this->config['rootLine'];
array_pop($temp);
if ($this->config['config']['stat_apache_noRoot']) {
array_shift($temp);
}
$len = t3lib_div::intInRange($this->config['config']['stat_titleLen'],1,100,20);
if ($this->config['config']['stat_apache_niceTitle']) {
$path = $this->csConvObj->specCharsToASCII($this->renderCharset,$this->sys_page->getPathFromRootline($temp,$len));
} else {
$path = $this->sys_page->getPathFromRootline($temp,$len);
}
$this->config['stat_vars']['pageName'] = str_replace('[path]', preg_replace('/[^.[:alnum:]\/_-]/','_',$path.'/'), $pageName);
if ($setStatPageName) {
$this->statistics_init_pagename();
}
// No cache
......
$redirectUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR').'index.php?id='.$this->id.'&type='.$this->type;
if ($this->config['config']['simulateStaticDocuments_dontRedirectPathInfoError']) {
$this->printError('PATH_INFO was not configured for this website, and the URL tries to find the page by PATH_INFO!<br /><br /><a href="'.htmlspecialchars($redirectUrl).'">Click here to get to the right page.</a>','Error: PATH_INFO not configured');
$this->statistics(503);
} else {
header('Location: '.t3lib_div::locationHeaderUrl($redirectUrl));
$this->statistics(302);
}
exit;
// $this->set_no_cache(); // Set no_cache if PATH_INFO is NOT used as simulateStaticDoc. and if absRefPrefix_force shows that such an URL has been passed along.
......
}
/**
* Initialize file-based statistics handling: Check filename and permissions, and create the logfile if it does not exist yet.
* This function should be called with care because it might overwrite existing settings otherwise.
*
* @return boolean True if statistics are enabled (will require some more processing after charset handling is initialized)
* @access private
*/
function statistics_init() {
$setStatPageName = false;
$theLogFile = $this->TYPO3_CONF_VARS['FE']['logfile_dir'].strftime($this->config['config']['stat_apache_logfile']);
// Add PATH_site left to $theLogFile if the path is not absolute yet
if (!t3lib_div::isAbsPath($theLogFile)) $theLogFile = PATH_site.$theLogFile;
if ($this->config['config']['stat_apache'] && $this->config['config']['stat_apache_logfile'] && !strstr($this->config['config']['stat_apache_logfile'],'/')) {
if (t3lib_div::isAllowedAbsPath($theLogFile)) {
if (!@is_file($theLogFile)) {
touch($theLogFile); // Try to create the logfile
t3lib_div::fixPermissions($theLogFile);
}
if (@is_file($theLogFile) && @is_writable($theLogFile)) {
$this->config['stat_vars']['logFile'] = $theLogFile;
$setStatPageName = true; // Set page name later on
} else {
$GLOBALS['TT']->setTSlogMessage('Could not set logfile path. Check filepath and permissions.',3);
}
}
}
return $setStatPageName;
}
/**
* Set the pagename for the logfile entry
*
* @return void
* @access private
*/
function statistics_init_pagename() {
// Make life easier and accept variants for utf-8
if (preg_match('/utf-?8/i', $this->config['config']['stat_apache_niceTitle'])) {
$this->config['config']['stat_apache_niceTitle'] = 'utf-8';
}
if ($this->config['config']['stat_apache_niceTitle'] == 'utf-8') {
$shortTitle = $this->csConvObj->utf8_encode($this->page['title'],$this->renderCharset);
} elseif ($this->config['config']['stat_apache_niceTitle']) {
$shortTitle = $this->csConvObj->specCharsToASCII($this->renderCharset,$this->page['title']);
} else {
$shortTitle = $this->page['title'];
}
$len = t3lib_div::intInRange($this->config['config']['stat_apache_pageLen'],1,100,30);
if ($this->config['config']['stat_apache_niceTitle'] == 'utf-8') {
$shortTitle = rawurlencode($this->csConvObj->substr('utf-8',$shortTitle,0,$len));
} else {
$shortTitle = substr(preg_replace('/[^.[:alnum:]_-]/','_',$shortTitle),0,$len);
}
$pageName = $this->config['config']['stat_apache_pagenames'] ? $this->config['config']['stat_apache_pagenames'] : '[path][title]--[uid].html';
$pageName = str_replace('[title]', $shortTitle ,$pageName);
$pageName = str_replace('[uid]',$this->page['uid'],$pageName);
$pageName = str_replace('[alias]',$this->page['alias'],$pageName);
$pageName = str_replace('[type]',$this->type,$pageName);
$pageName = str_replace('[request_uri]',t3lib_div::getIndpEnv('REQUEST_URI'),$pageName);
$temp = $this->config['rootLine'];
if ($temp) { // rootLine does not exist if this function is called at early stage (e.g. if DB connection failed)
array_pop($temp);
if ($this->config['config']['stat_apache_noRoot']) {
array_shift($temp);
}
$len = t3lib_div::intInRange($this->config['config']['stat_titleLen'],1,100,20);
if ($this->config['config']['stat_apache_niceTitle'] == 'utf-8') {
$path = '';
$c = count($temp);
for ($i=0; $i<$c; $i++) {
if ($temp[$i]['uid']) {
$p = $this->csConvObj->crop('utf-8',$this->csConvObj->utf8_encode($temp[$i]['title'],$this->renderCharset),$len,"\xE2\x80\xA6"); // U+2026; HORIZONTAL ELLIPSIS
$path.= '/' . rawurlencode($p);
}
}
} elseif ($this->config['config']['stat_apache_niceTitle']) {
$path = $this->csConvObj->specCharsToASCII($this->renderCharset,$this->sys_page->getPathFromRootline($temp,$len));
} else {
$path = $this->sys_page->getPathFromRootline($temp,$len);
}
} else {
$path = ''; // If rootLine is missing, we just drop some functionality...
}
if ($this->config['config']['stat_apache_niceTitle'] == 'utf-8') {
$this->config['stat_vars']['pageName'] = str_replace('[path]', $path.'/', $pageName);
} else {
$this->config['stat_vars']['pageName'] = str_replace('[path]', preg_replace('/[^.[:alnum:]\/_-]/','_',$path.'/'), $pageName);
}
}
/**
* Saves hit statistics
*
* @param integer HTTP status code
* @return void
*/
function statistics() {
if ($this->config['config']['stat'] &&
function statistics($status=200) {
// TODO: This is very hardcoded and needs to be solved better :-)
if (!is_array($this->config['config'])) {
$this->config['config'] = array(
'stat' => 1,
'stat_apache' => 1,
'stat_apache_logfile' => 'www-mysite-com.log',
'stat_apache_pagenames' => '[request_uri]'
);
$doStatistics = $this->statistics_init();
if ($doStatistics) {
$this->statistics_init_pagename();
} else {
return false;
}
}
if (is_array($this->config['config']) && $this->config['config']['stat'] &&
(!strcmp('',$this->config['config']['stat_typeNumList']) || t3lib_div::inList(str_replace(' ','',$this->config['config']['stat_typeNumList']), $this->type)) &&
(!$this->config['config']['stat_excludeBEuserHits'] || !$this->beUserLogin) &&
(!$this->config['config']['stat_excludeIPList'] || !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'),str_replace(' ','',$this->config['config']['stat_excludeIPList'])))) {
......
// Apache:
if ($this->config['config']['stat_apache'] && $this->config['stat_vars']['pageName']) {
if (@is_file($this->config['stat_vars']['logFile'])) {
$LogLine = ((t3lib_div::getIndpEnv('REMOTE_HOST') && !$this->config['config']['stat_apache_noHost']) ? t3lib_div::getIndpEnv('REMOTE_HOST') : t3lib_div::getIndpEnv('REMOTE_ADDR')).' - - '.Date('[d/M/Y:H:i:s +0000]',$GLOBALS['EXEC_TIME']).' "GET '.$this->config['stat_vars']['pageName'].' HTTP/1.1" 200 '.strlen($this->content);
if (!$this->config['config']['stat_apache_notExtended']) {
$LogLine.= ' "'.t3lib_div::getIndpEnv('HTTP_REFERER').'" "'.t3lib_div::getIndpEnv('HTTP_USER_AGENT').'"';
if (@is_file($this->config['stat_vars']['logFile'])) {
// Build a log line (format is derived from the NCSA extended/combined log format)
// Log part 1: Remote hostname / address
$LogLine = (t3lib_div::getIndpEnv('REMOTE_HOST') && !$this->config['config']['stat_apache_noHost']) ? t3lib_div::getIndpEnv('REMOTE_HOST') : t3lib_div::getIndpEnv('REMOTE_ADDR');
// Log part 2: Fake the remote logname
$LogLine.= ' -';
// Log part 3: Remote username
$LogLine.= ' '.($this->loginUser?$this->fe_user->user['username']:'-');
// Log part 4: Time
$LogLine.= ' '.date('[d/M/Y:H:i:s +0000]',$GLOBALS['EXEC_TIME']);
// Log part 5: First line of request (the request filename)
$LogLine.= ' "GET '.$this->config['stat_vars']['pageName'];
// Log part 6: Status and content length (ignores special content like admin panel!)
$LogLine.= ' HTTP/1.1" '.intval($status).' '.strlen($this->content);
if (!$this->config['config']['stat_apache_notExtended']) {
$referer = t3lib_div::getIndpEnv('HTTP_REFERER');
$LogLine.= ' "'.($referer?$referer:'-').'" "'.t3lib_div::getIndpEnv('HTTP_USER_AGENT').'"';
}
$GLOBALS['TT']->push('Write to log file (fputs)');
    (1-1/1)