finishing changes in models, removing last md5 test cases, tightening up allowed POST data
This commit is contained in:
@@ -15,7 +15,6 @@ namespace PrivateBin\Model;
|
||||
use Exception;
|
||||
use Identicon\Identicon;
|
||||
use PrivateBin\Persistence\TrafficLimiter;
|
||||
use PrivateBin\FormatV2;
|
||||
use PrivateBin\Vizhash16x16;
|
||||
|
||||
/**
|
||||
@@ -33,29 +32,6 @@ class Comment extends AbstractModel
|
||||
*/
|
||||
private $_paste;
|
||||
|
||||
/**
|
||||
* Get comment data.
|
||||
*
|
||||
* @access public
|
||||
* @throws Exception
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
// @todo add support to read specific comment
|
||||
$comments = $this->_store->readComments($this->getPaste()->getId());
|
||||
foreach ($comments as $comment) {
|
||||
if (
|
||||
$comment->parentid == $this->getParentId() &&
|
||||
$comment->id == $this->getId()
|
||||
) {
|
||||
$this->_data = $comment;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the comment's data.
|
||||
*
|
||||
@@ -80,7 +56,7 @@ class Comment extends AbstractModel
|
||||
throw new Exception('You are unlucky. Try again.', 69);
|
||||
}
|
||||
|
||||
$this->_data->meta->postdate = time();
|
||||
$this->_data['meta']['created'] = time();
|
||||
|
||||
// store comment
|
||||
if (
|
||||
@@ -88,7 +64,7 @@ class Comment extends AbstractModel
|
||||
$pasteid,
|
||||
$this->getParentId(),
|
||||
$this->getId(),
|
||||
json_decode(json_encode($this->_data), true)
|
||||
$this->_data
|
||||
) === false
|
||||
) {
|
||||
throw new Exception('Error saving comment. Sorry.', 70);
|
||||
@@ -130,8 +106,8 @@ class Comment extends AbstractModel
|
||||
*/
|
||||
public function setPaste(Paste $paste)
|
||||
{
|
||||
$this->_paste = $paste;
|
||||
$this->_data->meta->pasteid = $paste->getId();
|
||||
$this->_paste = $paste;
|
||||
$this->_data['pasteid'] = $paste->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,7 +133,7 @@ class Comment extends AbstractModel
|
||||
if (!self::isValidId($id)) {
|
||||
throw new Exception('Invalid paste ID.', 65);
|
||||
}
|
||||
$this->_data->meta->parentid = $id;
|
||||
$this->_data['parentid'] = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,29 +144,22 @@ class Comment extends AbstractModel
|
||||
*/
|
||||
public function getParentId()
|
||||
{
|
||||
if (!property_exists($this->_data->meta, 'parentid')) {
|
||||
$this->_data->meta->parentid = '';
|
||||
if (!array_key_exists('parentid', $this->_data)) {
|
||||
$this->_data['parentid'] = '';
|
||||
}
|
||||
return $this->_data->meta->parentid;
|
||||
return $this->_data['parentid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set nickname.
|
||||
* Sanitizes data to conform with current configuration.
|
||||
*
|
||||
* @access public
|
||||
* @param string $nickname
|
||||
* @throws Exception
|
||||
* @access protected
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function setNickname($nickname)
|
||||
protected function _sanitize(array $data)
|
||||
{
|
||||
if (!FormatV2::isValid($nickname)) {
|
||||
throw new Exception('Invalid data.', 66);
|
||||
}
|
||||
$this->_data->meta->nickname = $nickname;
|
||||
|
||||
// If a nickname is provided, we generate an icon based on a SHA512 HMAC
|
||||
// of the users IP. (We assume that if the user did not enter a nickname,
|
||||
// the user wants to be anonymous and we will not generate an icon.)
|
||||
// we generate an icon based on a SHA512 HMAC of the users IP, if configured
|
||||
$icon = $this->_conf->getKey('icon');
|
||||
if ($icon != 'none') {
|
||||
$pngdata = '';
|
||||
@@ -205,9 +174,12 @@ class Comment extends AbstractModel
|
||||
);
|
||||
}
|
||||
if ($pngdata != '') {
|
||||
$this->_data->meta->vizhash = $pngdata;
|
||||
if (!array_key_exists('meta', $data)) {
|
||||
$data['meta'] = array();
|
||||
}
|
||||
$data['meta']['icon'] = $pngdata;
|
||||
}
|
||||
}
|
||||
// Once the icon is generated, we do not keep the IP address hash.
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user