add piwik installation
This commit is contained in:
parent
90aa4ef157
commit
8c5d4f0c31
3197 changed files with 563902 additions and 0 deletions
145
www/analytics/core/Session/SaveHandler/DbTable.php
Normal file
145
www/analytics/core/Session/SaveHandler/DbTable.php
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Piwik\Session\SaveHandler;
|
||||
|
||||
use Piwik\Db;
|
||||
use Zend_Session;
|
||||
use Zend_Session_SaveHandler_Interface;
|
||||
|
||||
/**
|
||||
* Database-backed session save handler
|
||||
*
|
||||
*/
|
||||
class DbTable implements Zend_Session_SaveHandler_Interface
|
||||
{
|
||||
protected $config;
|
||||
protected $maxLifetime;
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
*/
|
||||
function __construct($config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->maxLifetime = ini_get('session.gc_maxlifetime');
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
Zend_Session::writeClose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open Session - retrieve resources
|
||||
*
|
||||
* @param string $save_path
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
*/
|
||||
public function open($save_path, $name)
|
||||
{
|
||||
Db::get()->getConnection();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close Session - free resources
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read session data
|
||||
*
|
||||
* @param string $id
|
||||
* @return string
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
$sql = 'SELECT ' . $this->config['dataColumn'] . ' FROM ' . $this->config['name']
|
||||
. ' WHERE ' . $this->config['primary'] . ' = ?'
|
||||
. ' AND ' . $this->config['modifiedColumn'] . ' + ' . $this->config['lifetimeColumn'] . ' >= ?';
|
||||
|
||||
$result = Db::get()->fetchOne($sql, array($id, time()));
|
||||
if (!$result)
|
||||
$result = '';
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write Session - commit data to resource
|
||||
*
|
||||
* @param string $id
|
||||
* @param mixed $data
|
||||
* @return boolean
|
||||
*/
|
||||
public function write($id, $data)
|
||||
{
|
||||
$sql = 'INSERT INTO ' . $this->config['name']
|
||||
. ' (' . $this->config['primary'] . ','
|
||||
. $this->config['modifiedColumn'] . ','
|
||||
. $this->config['lifetimeColumn'] . ','
|
||||
. $this->config['dataColumn'] . ')'
|
||||
. ' VALUES (?,?,?,?)'
|
||||
. ' ON DUPLICATE KEY UPDATE '
|
||||
. $this->config['modifiedColumn'] . ' = ?,'
|
||||
. $this->config['lifetimeColumn'] . ' = ?,'
|
||||
. $this->config['dataColumn'] . ' = ?';
|
||||
|
||||
Db::get()->query($sql, array($id, time(), $this->maxLifetime, $data, time(), $this->maxLifetime, $data));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Session - remove data from resource for
|
||||
* given session id
|
||||
*
|
||||
* @param string $id
|
||||
* @return boolean
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$sql = 'DELETE FROM ' . $this->config['name']
|
||||
. ' WHERE ' . $this->config['primary'] . ' = ?';
|
||||
|
||||
Db::get()->query($sql, array($id));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Garbage Collection - remove old session data older
|
||||
* than $maxlifetime (in seconds)
|
||||
*
|
||||
* @param int $maxlifetime timestamp in seconds
|
||||
* @return bool always true
|
||||
*/
|
||||
public function gc($maxlifetime)
|
||||
{
|
||||
$sql = 'DELETE FROM ' . $this->config['name']
|
||||
. ' WHERE ' . $this->config['modifiedColumn'] . ' + ' . $this->config['lifetimeColumn'] . ' < ?';
|
||||
|
||||
Db::get()->query($sql, array(time()));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
33
www/analytics/core/Session/SessionNamespace.php
Normal file
33
www/analytics/core/Session/SessionNamespace.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Session;
|
||||
|
||||
use Piwik\Common;
|
||||
use Zend_Session_Namespace;
|
||||
|
||||
/**
|
||||
* Session namespace.
|
||||
*
|
||||
*/
|
||||
class SessionNamespace extends Zend_Session_Namespace
|
||||
{
|
||||
/**
|
||||
* @param string $namespace
|
||||
* @param bool $singleInstance
|
||||
*/
|
||||
public function __construct($namespace = 'Default', $singleInstance = false)
|
||||
{
|
||||
if (Common::isPhpCliMode()) {
|
||||
self::$_readable = true;
|
||||
return;
|
||||
}
|
||||
|
||||
parent::__construct($namespace, $singleInstance);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue