* @license PHP License * @package WB * @subpackage base */ /** * Simple AJAX stub * * Allow to call method via AJAX request * * @version 0.1.0 * @package WB * @subpackage base */ abstract class WBStatistic extends WBStdClass { /** * current tuser * @var WBUser_Auth */ protected $user; /** * request parameter * @var WBRequest */ protected $req; /** * session * @var patSession_Storage */ protected $sess; /** * tracking id */ private $trackid; /** * table object * @var WBDatasource_Table_Statistic */ protected $table; /** * primary key of user * @var string */ protected $uPrimary; /** * statistic feature enabled * @var bool */ protected $enabled = true; /** * store hints about this browser in session */ const SESS_KEY_HINT = 'wb.statistic.browser.hint'; /** * store initial session id for tracking */ const SESS_KEY_ID = 'wb.statistic.sessid'; /** * constructor * * Init user and request object. * */ public function __construct() { // see if feature is turned OFF if (!WBParam::get('wb/statistic/use', 1)) { $this->enabled = false; return; } WBClass::load('WBUser'); $this->user = WBUser::getCurrent(); $this->sess = WBClass::create('patSession'); $this->table = WBClass::create('WBDatasource_Table_Statistic'); $this->req = WBClass::create('WBRequest'); $this->uPrimary = $this->table->getIdentifier('user'); // tracking id if (!$this->sess->has(self::SESS_KEY_ID)) { $this->sess->set(self::SESS_KEY_ID, $this->sess->getId()); } $this->trackid = $this->sess->get(self::SESS_KEY_ID); } /** * Get id for user tracking * * @return string */ protected function getTrackingId() { return $this->trackid; } /** * receive users IP address * * * * @return string $addr */ protected function getAddress() { $addr = $this->getIpAddress(); // how to save the ip address switch (WBParam::get('wb/statistic/ip', 'save')) { case 'session': $addr = substr($this->sess->getId(), 32); break; case 'md5': $addr = md5($addr); break; case 'remove': $addr = ''; break; default: case 'save': break; } return $addr; } /** * locate ip address * * Find out latitute and longitude of ip address * * @todo to be implemented */ protected function locateAddress() { $addr = $this->getIpAddress(); return ''; } /** * get ip address of visitor * * @todo see how to handle HTTP_X_FORWARDED_FOR * @return string */ private function getIpAddress() { /* $addr = $this->req->getMeta('HTTP_X_FORWARDED_FOR', ''); */ $addr = $this->req->getMeta('REMOTE_ADDR', ''); return $addr; } } ?>