|
@@ -11,9 +11,9 @@
|
|
|
|
|
|
|
|
namespace PrivateBin\Model;
|
|
namespace PrivateBin\Model;
|
|
|
|
|
|
|
|
-use Exception;
|
|
|
|
|
use PrivateBin\Controller;
|
|
use PrivateBin\Controller;
|
|
|
use PrivateBin\Persistence\ServerSalt;
|
|
use PrivateBin\Persistence\ServerSalt;
|
|
|
|
|
+use PrivateBin\TranslatedException;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Paste
|
|
* Paste
|
|
@@ -47,14 +47,14 @@ class Paste extends AbstractModel
|
|
|
* Get paste data.
|
|
* Get paste data.
|
|
|
*
|
|
*
|
|
|
* @access public
|
|
* @access public
|
|
|
- * @throws Exception
|
|
|
|
|
|
|
+ * @throws TranslatedException
|
|
|
* @return array
|
|
* @return array
|
|
|
*/
|
|
*/
|
|
|
public function get()
|
|
public function get()
|
|
|
{
|
|
{
|
|
|
$data = $this->_store->read($this->getId());
|
|
$data = $this->_store->read($this->getId());
|
|
|
if ($data === false) {
|
|
if ($data === false) {
|
|
|
- throw new Exception(Controller::GENERIC_ERROR, 64);
|
|
|
|
|
|
|
+ throw new TranslatedException(Controller::GENERIC_ERROR, 64);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// check if paste has expired and delete it if necessary.
|
|
// check if paste has expired and delete it if necessary.
|
|
@@ -62,7 +62,7 @@ class Paste extends AbstractModel
|
|
|
$now = time();
|
|
$now = time();
|
|
|
if ($data['meta']['expire_date'] < $now) {
|
|
if ($data['meta']['expire_date'] < $now) {
|
|
|
$this->delete();
|
|
$this->delete();
|
|
|
- throw new Exception(Controller::GENERIC_ERROR, 63);
|
|
|
|
|
|
|
+ throw new TranslatedException(Controller::GENERIC_ERROR, 63);
|
|
|
}
|
|
}
|
|
|
// We kindly provide the remaining time before expiration (in seconds)
|
|
// We kindly provide the remaining time before expiration (in seconds)
|
|
|
$data['meta']['time_to_live'] = $data['meta']['expire_date'] - $now;
|
|
$data['meta']['time_to_live'] = $data['meta']['expire_date'] - $now;
|
|
@@ -93,13 +93,13 @@ class Paste extends AbstractModel
|
|
|
* Store the paste's data.
|
|
* Store the paste's data.
|
|
|
*
|
|
*
|
|
|
* @access public
|
|
* @access public
|
|
|
- * @throws Exception
|
|
|
|
|
|
|
+ * @throws TranslatedException
|
|
|
*/
|
|
*/
|
|
|
public function store()
|
|
public function store()
|
|
|
{
|
|
{
|
|
|
// Check for improbable collision.
|
|
// Check for improbable collision.
|
|
|
if ($this->exists()) {
|
|
if ($this->exists()) {
|
|
|
- throw new Exception('You are unlucky. Try again.', 75);
|
|
|
|
|
|
|
+ throw new TranslatedException(self::COLLISION_ERROR, 75);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$this->_data['meta']['salt'] = ServerSalt::generate();
|
|
$this->_data['meta']['salt'] = ServerSalt::generate();
|
|
@@ -111,7 +111,7 @@ class Paste extends AbstractModel
|
|
|
$this->_data
|
|
$this->_data
|
|
|
) === false
|
|
) === false
|
|
|
) {
|
|
) {
|
|
|
- throw new Exception('Error saving document. Sorry.', 76);
|
|
|
|
|
|
|
+ throw new TranslatedException('Error saving document. Sorry.', 76);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -119,7 +119,6 @@ class Paste extends AbstractModel
|
|
|
* Delete the paste.
|
|
* Delete the paste.
|
|
|
*
|
|
*
|
|
|
* @access public
|
|
* @access public
|
|
|
- * @throws Exception
|
|
|
|
|
*/
|
|
*/
|
|
|
public function delete()
|
|
public function delete()
|
|
|
{
|
|
{
|
|
@@ -143,13 +142,13 @@ class Paste extends AbstractModel
|
|
|
* @access public
|
|
* @access public
|
|
|
* @param string $parentId
|
|
* @param string $parentId
|
|
|
* @param string $commentId
|
|
* @param string $commentId
|
|
|
- * @throws Exception
|
|
|
|
|
|
|
+ * @throws TranslatedException
|
|
|
* @return Comment
|
|
* @return Comment
|
|
|
*/
|
|
*/
|
|
|
public function getComment($parentId, $commentId = '')
|
|
public function getComment($parentId, $commentId = '')
|
|
|
{
|
|
{
|
|
|
if (!$this->exists()) {
|
|
if (!$this->exists()) {
|
|
|
- throw new Exception('Invalid data.', 62);
|
|
|
|
|
|
|
+ throw new TranslatedException(self::INVALID_DATA_ERROR, 62);
|
|
|
}
|
|
}
|
|
|
$comment = new Comment($this->_conf, $this->_store);
|
|
$comment = new Comment($this->_conf, $this->_store);
|
|
|
$comment->setPaste($this);
|
|
$comment->setPaste($this);
|
|
@@ -201,7 +200,6 @@ class Paste extends AbstractModel
|
|
|
* Check if paste has discussions enabled.
|
|
* Check if paste has discussions enabled.
|
|
|
*
|
|
*
|
|
|
* @access public
|
|
* @access public
|
|
|
- * @throws Exception
|
|
|
|
|
* @return bool
|
|
* @return bool
|
|
|
*/
|
|
*/
|
|
|
public function isOpendiscussion()
|
|
public function isOpendiscussion()
|
|
@@ -240,13 +238,13 @@ class Paste extends AbstractModel
|
|
|
*
|
|
*
|
|
|
* @access protected
|
|
* @access protected
|
|
|
* @param array $data
|
|
* @param array $data
|
|
|
- * @throws Exception
|
|
|
|
|
|
|
+ * @throws TranslatedException
|
|
|
*/
|
|
*/
|
|
|
protected function _validate(array &$data)
|
|
protected function _validate(array &$data)
|
|
|
{
|
|
{
|
|
|
// reject invalid or disabled formatters
|
|
// reject invalid or disabled formatters
|
|
|
if (!array_key_exists($data['adata'][self::ADATA_FORMATTER], $this->_conf->getSection('formatter_options'))) {
|
|
if (!array_key_exists($data['adata'][self::ADATA_FORMATTER], $this->_conf->getSection('formatter_options'))) {
|
|
|
- throw new Exception('Invalid data.', 75);
|
|
|
|
|
|
|
+ throw new TranslatedException(self::INVALID_DATA_ERROR, 75);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// discussion requested, but disabled in config or burn after reading requested as well, or invalid integer
|
|
// discussion requested, but disabled in config or burn after reading requested as well, or invalid integer
|
|
@@ -257,7 +255,7 @@ class Paste extends AbstractModel
|
|
|
)) ||
|
|
)) ||
|
|
|
($data['adata'][self::ADATA_OPEN_DISCUSSION] !== 0 && $data['adata'][self::ADATA_OPEN_DISCUSSION] !== 1)
|
|
($data['adata'][self::ADATA_OPEN_DISCUSSION] !== 0 && $data['adata'][self::ADATA_OPEN_DISCUSSION] !== 1)
|
|
|
) {
|
|
) {
|
|
|
- throw new Exception('Invalid data.', 74);
|
|
|
|
|
|
|
+ throw new TranslatedException(self::INVALID_DATA_ERROR, 74);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// reject invalid burn after reading
|
|
// reject invalid burn after reading
|
|
@@ -265,7 +263,7 @@ class Paste extends AbstractModel
|
|
|
$data['adata'][self::ADATA_BURN_AFTER_READING] !== 0 &&
|
|
$data['adata'][self::ADATA_BURN_AFTER_READING] !== 0 &&
|
|
|
$data['adata'][self::ADATA_BURN_AFTER_READING] !== 1
|
|
$data['adata'][self::ADATA_BURN_AFTER_READING] !== 1
|
|
|
) {
|
|
) {
|
|
|
- throw new Exception('Invalid data.', 73);
|
|
|
|
|
|
|
+ throw new TranslatedException(self::INVALID_DATA_ERROR, 73);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|