2007-09-16 17:37:33 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2008-01-08 07:37:50 +01:00
|
|
|
* @package cms
|
2007-09-16 17:37:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data object that represents any page view in the system.
|
|
|
|
*/
|
|
|
|
class PageView extends DataObject {
|
|
|
|
|
|
|
|
static $db = array(
|
|
|
|
"IP" => "Varchar(255)",
|
|
|
|
"Browser" => "Varchar(255)",
|
|
|
|
"BrowserVersion" => "Decimal",
|
|
|
|
"FromExternal" => "Boolean",
|
|
|
|
"Referrer" => "Varchar(255)",
|
|
|
|
"SearchEngine" => "Boolean",
|
|
|
|
"Keywords" => "Varchar(255)",
|
|
|
|
"OS" => "Varchar(255)"
|
|
|
|
);
|
|
|
|
|
|
|
|
static $has_one = array(
|
|
|
|
"Page" => "SiteTree",
|
|
|
|
"User" => "Member"
|
|
|
|
);
|
|
|
|
|
|
|
|
static $has_many = array();
|
|
|
|
|
|
|
|
static $many_many = array();
|
|
|
|
|
|
|
|
static $belongs_many_many = array();
|
|
|
|
|
|
|
|
static $defaults = array();
|
|
|
|
|
2007-09-16 17:40:27 +02:00
|
|
|
protected $hitdata = null;
|
2007-09-16 17:37:33 +02:00
|
|
|
|
|
|
|
function init() {
|
2007-10-05 03:58:21 +02:00
|
|
|
$browscap = new Browscap();
|
|
|
|
$this->hitdata = $browscap->getBrowser(null, true);
|
2007-09-16 17:37:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function record() {
|
|
|
|
$this->init();
|
|
|
|
$this->setBrowser();
|
|
|
|
$this->setOS();
|
|
|
|
$this->setUserID();
|
|
|
|
$this->setPageID();
|
|
|
|
$this->setIP();
|
|
|
|
$this->write(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function sanitize($str) {
|
|
|
|
//TODO
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setBrowser() {
|
2007-10-05 03:58:21 +02:00
|
|
|
if(isset($this->hitdata['Browser']))
|
|
|
|
$this->setField('Browser', $this->hitdata['Browser']);
|
2007-09-16 17:40:27 +02:00
|
|
|
|
2007-10-05 03:58:21 +02:00
|
|
|
if(isset($this->hitdata['Version']))
|
|
|
|
$this->setField('BrowserVersion', $this->hitdata['Version']);
|
2007-09-16 17:37:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setOS() {
|
2007-10-05 03:58:21 +02:00
|
|
|
if(isset($this->hitdata['Platform']))
|
|
|
|
$this->setField('OS', $this->hitdata['Platform']);
|
2007-09-16 17:37:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setUserID() {
|
|
|
|
$isLogged = Session::get('loggedInAs');
|
|
|
|
if($isLogged) {
|
|
|
|
$id = $isLogged;
|
|
|
|
} else {
|
|
|
|
$id = -1;
|
|
|
|
}
|
|
|
|
$this->setField('UserID', $id);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPageID() {
|
|
|
|
$currentPage = Director::currentPage();
|
2007-09-16 17:52:56 +02:00
|
|
|
if($currentPage)
|
|
|
|
$this->setField('PageID', $currentPage->ID);
|
2007-09-16 17:37:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setIP() {
|
2007-09-16 17:40:27 +02:00
|
|
|
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
2007-09-16 17:37:33 +02:00
|
|
|
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
|
|
} else {
|
|
|
|
$ip = $_SERVER['REMOTE_ADDR'];
|
|
|
|
}
|
|
|
|
$this->setField('IP', $ip);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-16 17:40:27 +02:00
|
|
|
?>
|