2015-09-27 03:03:55 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-11 11:58:15 +02:00
|
|
|
* PrivateBin
|
2015-09-27 03:03:55 +02:00
|
|
|
*
|
|
|
|
* a zero-knowledge paste bin
|
|
|
|
*
|
2016-07-11 11:58:15 +02:00
|
|
|
* @link https://github.com/PrivateBin/PrivateBin
|
2015-09-27 03:03:55 +02:00
|
|
|
* @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
|
2016-07-19 13:56:52 +02:00
|
|
|
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
|
2015-11-09 21:39:42 +01:00
|
|
|
* @version 0.22
|
2015-09-27 03:03:55 +02:00
|
|
|
*/
|
|
|
|
|
2016-07-21 17:09:48 +02:00
|
|
|
namespace PrivateBin;
|
|
|
|
|
|
|
|
use PrivateBin\model\paste;
|
|
|
|
|
2015-09-27 03:03:55 +02:00
|
|
|
/**
|
|
|
|
* model
|
|
|
|
*
|
2016-07-11 11:58:15 +02:00
|
|
|
* Factory of PrivateBin instance models.
|
2015-09-27 03:03:55 +02:00
|
|
|
*/
|
|
|
|
class model
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Configuration.
|
|
|
|
*
|
|
|
|
* @var configuration
|
|
|
|
*/
|
|
|
|
private $_conf;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data storage.
|
|
|
|
*
|
2016-07-11 11:58:15 +02:00
|
|
|
* @var privatebin_abstract
|
2015-09-27 03:03:55 +02:00
|
|
|
*/
|
|
|
|
private $_store = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Factory constructor.
|
|
|
|
*
|
|
|
|
* @param configuration $conf
|
2016-07-15 17:02:59 +02:00
|
|
|
* @return void
|
2015-09-27 03:03:55 +02: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 17:09:48 +02:00
|
|
|
$paste = new paste($this->_conf, $this->_getStore());
|
2016-07-26 08:19:35 +02:00
|
|
|
if ($pasteId !== null) {
|
|
|
|
$paste->setId($pasteId);
|
|
|
|
}
|
2015-09-27 03:03:55 +02:00
|
|
|
return $paste;
|
|
|
|
}
|
|
|
|
|
2016-07-15 17:02:59 +02:00
|
|
|
/**
|
|
|
|
* Checks if a purge is necessary and triggers it if yes.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function purge()
|
|
|
|
{
|
|
|
|
purgelimiter::setConfiguration($this->_conf);
|
2016-07-26 08:19:35 +02:00
|
|
|
if (purgelimiter::canPurge()) {
|
2016-07-15 17:02:59 +02:00
|
|
|
$this->_getStore()->purge($this->_conf->getKey('batchsize', 'purge'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-27 03:03:55 +02:00
|
|
|
/**
|
|
|
|
* Gets, and creates if neccessary, a store object
|
2016-07-15 17:02:59 +02:00
|
|
|
*
|
|
|
|
* @return privatebin_abstract
|
2015-09-27 03:03:55 +02:00
|
|
|
*/
|
|
|
|
private function _getStore()
|
|
|
|
{
|
2016-07-26 08:19:35 +02:00
|
|
|
if ($this->_store === null) {
|
2015-09-27 03:03:55 +02:00
|
|
|
$this->_store = forward_static_call(
|
2016-07-22 15:31:42 +02:00
|
|
|
array($this->_conf->getKey('class', 'model'), 'getInstance'),
|
2015-09-27 03:03:55 +02:00
|
|
|
$this->_conf->getSection('model_options')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $this->_store;
|
|
|
|
}
|
2016-07-11 11:58:15 +02:00
|
|
|
}
|