mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-14 09:44:55 +02:00
* stop using global $cache variable, use Singleton pattern instead
This commit is contained in:
@@ -14,15 +14,17 @@ class Visitors
|
||||
private $sessionTime; // time session will live
|
||||
private $data; // cached data
|
||||
private $cacheEnabled;
|
||||
private $cache;
|
||||
|
||||
public function __construct($sessionTime = 10)
|
||||
{
|
||||
global $cache;
|
||||
$this->cacheEnabled = ($cache && $cache->enabled());
|
||||
$this->cache = Cache::getInstance();
|
||||
|
||||
$this->cacheEnabled = $this->cache->enabled();
|
||||
if($this->cacheEnabled)
|
||||
{
|
||||
$tmp = '';
|
||||
if($cache->fetch('visitors', $tmp))
|
||||
if($this->cache->fetch('visitors', $tmp))
|
||||
$this->data = unserialize($tmp);
|
||||
else
|
||||
$this->data = array();
|
||||
@@ -40,9 +42,8 @@ class Visitors
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
global $cache;
|
||||
if($this->cacheEnabled)
|
||||
$cache->set('visitors', serialize($this->data), 120);
|
||||
$this->cache->set('visitors', serialize($this->data), 120);
|
||||
}
|
||||
|
||||
public function visitorExists($ip)
|
||||
@@ -101,10 +102,10 @@ class Visitors
|
||||
if($this->cacheEnabled) {
|
||||
foreach($this->data as $ip => &$details)
|
||||
$details['ip'] = $ip;
|
||||
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
|
||||
global $db;
|
||||
return $db->query('SELECT ' . $db->fieldName('ip') . ', ' . $db->fieldName('lastvisit') . ', ' . $db->fieldName('page') . ' FROM ' . $db->tableName(TABLE_PREFIX . 'visitors') . ' ORDER BY ' . $db->fieldName('lastvisit') . ' DESC')->fetchAll();
|
||||
}
|
||||
|
Reference in New Issue
Block a user