mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
03cabb839d
commit
536770caca
@ -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
|
||||
*/
|
||||
class PageView extends DataObject {
|
||||
@ -40,60 +48,61 @@ class PageView extends DataObject {
|
||||
$this->hitdata = $browscap->getBrowser(null, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* gathers data for this page view and writes
|
||||
* it to the data source.
|
||||
*/
|
||||
function record() {
|
||||
$this->init();
|
||||
$this->setBrowser();
|
||||
$this->setOS();
|
||||
$this->setUserID();
|
||||
$this->setPageID();
|
||||
$this->setIP();
|
||||
$this->recordBrowser();
|
||||
$this->recordOS();
|
||||
$this->recordUserID();
|
||||
$this->recordPageID();
|
||||
$this->recordIP();
|
||||
$this->recordFromExternal();
|
||||
$this->recordReferrer();
|
||||
$this->write(true);
|
||||
}
|
||||
|
||||
function sanitize($str) {
|
||||
//TODO
|
||||
return $str;
|
||||
private function recordFromExternal() {
|
||||
$http_host = "http://".$_SERVER['HTTP_HOST'];
|
||||
if (!strstr($_SERVER['HTTP_REFERER'], $http_host) && $_SERVER['HTTP_REFERER'] != null)
|
||||
$this->FromExternal = 1;
|
||||
}
|
||||
|
||||
function setBrowser() {
|
||||
if(isset($this->hitdata['Browser']))
|
||||
$this->setField('Browser', $this->hitdata['Browser']);
|
||||
private function recordBrowser() {
|
||||
if (isset($this->hitdata['Browser']))
|
||||
$this->Browser = $this->hitdata['Browser'];
|
||||
|
||||
if(isset($this->hitdata['Version']))
|
||||
$this->setField('BrowserVersion', $this->hitdata['Version']);
|
||||
if (isset($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']))
|
||||
$this->setField('OS', $this->hitdata['Platform']);
|
||||
$this->OS = $this->hitdata['Platform'];
|
||||
}
|
||||
|
||||
function setUserID() {
|
||||
private function recordUserID() {
|
||||
$isLogged = Session::get('loggedInAs');
|
||||
if($isLogged) {
|
||||
$id = $isLogged;
|
||||
} else {
|
||||
$id = -1;
|
||||
}
|
||||
$this->setField('UserID', $id);
|
||||
$id = ($isLogged) ? $isLogged : -1;
|
||||
$this->UserID = $id;
|
||||
}
|
||||
|
||||
function setPageID() {
|
||||
private function recordPageID() {
|
||||
$currentPage = Director::currentPage();
|
||||
if($currentPage)
|
||||
$this->setField('PageID', $currentPage->ID);
|
||||
if ($currentPage) $this->PageID = $currentPage->ID;
|
||||
}
|
||||
|
||||
function setIP() {
|
||||
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
} else {
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
$this->setField('IP', $ip);
|
||||
private function recordIP() {
|
||||
$this->IP = (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
|
||||
? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user