mrickerby: #2201 - fixed PageView's recording of referrers.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@48905 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-01-31 04:30:36 +00:00
parent 03cabb839d
commit 536770caca

View File

@ -4,7 +4,15 @@
*/ */
/** /**
* Data object that represents any page view in the system. * Data object that logs statistics for any page view in the system.
*
* Inbound links from external websites are distinquished by a 'true'
* value in the FromExternal field. False values are
*
* The referring urls are recorded in the Referrer field.
*
* Information about the users browser version and operating system is also recorded.
*
* @package cms * @package cms
*/ */
class PageView extends DataObject { class PageView extends DataObject {
@ -40,60 +48,61 @@ class PageView extends DataObject {
$this->hitdata = $browscap->getBrowser(null, true); $this->hitdata = $browscap->getBrowser(null, true);
} }
/**
* gathers data for this page view and writes
* it to the data source.
*/
function record() { function record() {
$this->init(); $this->init();
$this->setBrowser(); $this->recordBrowser();
$this->setOS(); $this->recordOS();
$this->setUserID(); $this->recordUserID();
$this->setPageID(); $this->recordPageID();
$this->setIP(); $this->recordIP();
$this->recordFromExternal();
$this->recordReferrer();
$this->write(true); $this->write(true);
} }
function sanitize($str) { private function recordFromExternal() {
//TODO $http_host = "http://".$_SERVER['HTTP_HOST'];
return $str; if (!strstr($_SERVER['HTTP_REFERER'], $http_host) && $_SERVER['HTTP_REFERER'] != null)
$this->FromExternal = 1;
} }
function setBrowser() { private function recordBrowser() {
if (isset($this->hitdata['Browser'])) if (isset($this->hitdata['Browser']))
$this->setField('Browser', $this->hitdata['Browser']); $this->Browser = $this->hitdata['Browser'];
if (isset($this->hitdata['Version'])) if (isset($this->hitdata['Version']))
$this->setField('BrowserVersion', $this->hitdata['Version']); $this->BrowserVersion = $this->hitdata['Version'];
} }
function setOS() { private function recordReferrer() {
$this->Referrer = $_SERVER['HTTP_REFERER'];
}
private function recordOS() {
if(isset($this->hitdata['Platform'])) if(isset($this->hitdata['Platform']))
$this->setField('OS', $this->hitdata['Platform']); $this->OS = $this->hitdata['Platform'];
} }
function setUserID() { private function recordUserID() {
$isLogged = Session::get('loggedInAs'); $isLogged = Session::get('loggedInAs');
if($isLogged) { $id = ($isLogged) ? $isLogged : -1;
$id = $isLogged; $this->UserID = $id;
} else {
$id = -1;
}
$this->setField('UserID', $id);
} }
function setPageID() { private function recordPageID() {
$currentPage = Director::currentPage(); $currentPage = Director::currentPage();
if($currentPage) if ($currentPage) $this->PageID = $currentPage->ID;
$this->setField('PageID', $currentPage->ID);
} }
function setIP() { private function recordIP() {
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $this->IP = (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ip = $_SERVER['HTTP_X_FORWARDED_FOR']; ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$this->setField('IP', $ip);
} }
} }
?> ?>