2015-09-27 09:03:55 +08:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-11 17:58:15 +08:00
|
|
|
* PrivateBin
|
2015-09-27 09:03:55 +08:00
|
|
|
*
|
|
|
|
* a zero-knowledge paste bin
|
|
|
|
*
|
2016-07-11 17:58:15 +08:00
|
|
|
* @link https://github.com/PrivateBin/PrivateBin
|
2015-09-27 09:03:55 +08:00
|
|
|
* @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
|
2016-07-19 19:56:52 +08:00
|
|
|
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
|
2015-11-10 04:39:42 +08:00
|
|
|
* @version 0.22
|
2015-09-27 09:03:55 +08:00
|
|
|
*/
|
|
|
|
|
2016-07-21 23:09:48 +08:00
|
|
|
namespace PrivateBin;
|
|
|
|
|
|
|
|
use PrivateBin\model\paste;
|
|
|
|
|
2015-09-27 09:03:55 +08:00
|
|
|
/**
|
|
|
|
* model
|
|
|
|
*
|
2016-07-11 17:58:15 +08:00
|
|
|
* Factory of PrivateBin instance models.
|
2015-09-27 09:03:55 +08:00
|
|
|
*/
|
|
|
|
class model
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Configuration.
|
|
|
|
*
|
|
|
|
* @var configuration
|
|
|
|
*/
|
|
|
|
private $_conf;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data storage.
|
|
|
|
*
|
2016-07-11 17:58:15 +08:00
|
|
|
* @var privatebin_abstract
|
2015-09-27 09:03:55 +08:00
|
|
|
*/
|
|
|
|
private $_store = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Factory constructor.
|
|
|
|
*
|
|
|
|
* @param configuration $conf
|
2016-07-15 23:02:59 +08:00
|
|
|
* @return void
|
2015-09-27 09:03:55 +08:00
|
|
|
*/
|
|
|
|
public function __construct(configuration $conf)
|
|
|
|
{
|
|
|
|
$this->_conf = $conf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a paste, optionally a specific instance.
|
|
|
|
*
|
|
|
|
* @param string $pasteId
|
|
|
|
* @return model_paste
|
|
|
|
*/
|
|
|
|
public function getPaste($pasteId = null)
|
|
|
|
{
|
2016-07-21 23:09:48 +08:00
|
|
|
$paste = new paste($this->_conf, $this->_getStore());
|
2015-09-27 09:03:55 +08:00
|
|
|
if ($pasteId !== null) $paste->setId($pasteId);
|
|
|
|
return $paste;
|
|
|
|
}
|
|
|
|
|
2016-07-15 23:02:59 +08:00
|
|
|
/**
|
|
|
|
* Checks if a purge is necessary and triggers it if yes.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function purge()
|
|
|
|
{
|
|
|
|
purgelimiter::setConfiguration($this->_conf);
|
|
|
|
if (purgelimiter::canPurge())
|
|
|
|
{
|
|
|
|
$this->_getStore()->purge($this->_conf->getKey('batchsize', 'purge'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-27 09:03:55 +08:00
|
|
|
/**
|
|
|
|
* Gets, and creates if neccessary, a store object
|
2016-07-15 23:02:59 +08:00
|
|
|
*
|
|
|
|
* @return privatebin_abstract
|
2015-09-27 09:03:55 +08:00
|
|
|
*/
|
|
|
|
private function _getStore()
|
|
|
|
{
|
2016-07-21 23:09:48 +08:00
|
|
|
// FIXME
|
|
|
|
// Workaround so that config value don't need to be changed
|
|
|
|
$callable = str_replace(
|
|
|
|
array('privatebin_data', 'privatebin_db'),
|
|
|
|
array('PrivateBin\\data\\data', 'PrivateBin\\data\\db'),
|
|
|
|
$this->_conf->getKey('class', 'model')
|
|
|
|
);
|
|
|
|
|
2015-09-27 09:03:55 +08:00
|
|
|
if ($this->_store === null)
|
|
|
|
{
|
|
|
|
$this->_store = forward_static_call(
|
2016-07-21 23:09:48 +08:00
|
|
|
array($callable, 'getInstance'),
|
2015-09-27 09:03:55 +08:00
|
|
|
$this->_conf->getSection('model_options')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $this->_store;
|
|
|
|
}
|
2016-07-11 17:58:15 +08:00
|
|
|
}
|