mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00: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
|
* @package cms
|
||||||
*/
|
*/
|
||||||
class PageView extends DataObject {
|
class PageView extends DataObject {
|
||||||
@ -34,66 +42,67 @@ class PageView extends DataObject {
|
|||||||
static $defaults = array();
|
static $defaults = array();
|
||||||
|
|
||||||
protected $hitdata = null;
|
protected $hitdata = null;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
$browscap = new Browscap();
|
$browscap = new Browscap();
|
||||||
$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'];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function recordReferrer() {
|
||||||
|
$this->Referrer = $_SERVER['HTTP_REFERER'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function setOS() {
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
x
Reference in New Issue
Block a user