handle scrutinizer issues (mostly changes in API documentation)
This commit is contained in:
parent
8fd3e680e4
commit
909ff2daa7
|
@ -199,12 +199,13 @@ class Controller
|
||||||
// Ensure last paste from visitors IP address was more than configured amount of seconds ago.
|
// Ensure last paste from visitors IP address was more than configured amount of seconds ago.
|
||||||
TrafficLimiter::setConfiguration($this->_conf);
|
TrafficLimiter::setConfiguration($this->_conf);
|
||||||
if (!TrafficLimiter::canPass()) {
|
if (!TrafficLimiter::canPass()) {
|
||||||
return $this->_return_message(
|
$this->_return_message(
|
||||||
1, I18n::_(
|
1, I18n::_(
|
||||||
'Please wait %d seconds between each post.',
|
'Please wait %d seconds between each post.',
|
||||||
$this->_conf->getKey('limit', 'traffic')
|
$this->_conf->getKey('limit', 'traffic')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->_request->getData();
|
$data = $this->_request->getData();
|
||||||
|
@ -213,18 +214,20 @@ class Controller
|
||||||
array_key_exists('parentid', $data) &&
|
array_key_exists('parentid', $data) &&
|
||||||
!empty($data['parentid']);
|
!empty($data['parentid']);
|
||||||
if (!FormatV2::isValid($data, $isComment)) {
|
if (!FormatV2::isValid($data, $isComment)) {
|
||||||
return $this->_return_message(1, I18n::_('Invalid data.'));
|
$this->_return_message(1, I18n::_('Invalid data.'));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
$sizelimit = $this->_conf->getKey('sizelimit');
|
$sizelimit = $this->_conf->getKey('sizelimit');
|
||||||
// Ensure content is not too big.
|
// Ensure content is not too big.
|
||||||
if (strlen($data['ct']) > $sizelimit) {
|
if (strlen($data['ct']) > $sizelimit) {
|
||||||
return $this->_return_message(
|
$this->_return_message(
|
||||||
1,
|
1,
|
||||||
I18n::_(
|
I18n::_(
|
||||||
'Paste is limited to %s of encrypted data.',
|
'Paste is limited to %s of encrypted data.',
|
||||||
Filter::formatHumanReadableSize($sizelimit)
|
Filter::formatHumanReadableSize($sizelimit)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The user posts a comment.
|
// The user posts a comment.
|
||||||
|
@ -236,7 +239,8 @@ class Controller
|
||||||
$comment->setData($data);
|
$comment->setData($data);
|
||||||
$comment->store();
|
$comment->store();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->_return_message(1, $e->getMessage());
|
$this->_return_message(1, $e->getMessage());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
$this->_return_message(0, $comment->getId());
|
$this->_return_message(0, $comment->getId());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -79,7 +79,7 @@ abstract class AbstractData
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $pasteid
|
* @param string $pasteid
|
||||||
* @return stdClass|false
|
* @return array|false
|
||||||
*/
|
*/
|
||||||
abstract public function read($pasteid);
|
abstract public function read($pasteid);
|
||||||
|
|
||||||
|
|
|
@ -75,73 +75,71 @@ class Database extends AbstractData
|
||||||
self::$_instance = new self;
|
self::$_instance = new self;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($options)) {
|
// set table prefix if given
|
||||||
// set table prefix if given
|
if (array_key_exists('tbl', $options)) {
|
||||||
if (array_key_exists('tbl', $options)) {
|
self::$_prefix = $options['tbl'];
|
||||||
self::$_prefix = $options['tbl'];
|
}
|
||||||
|
|
||||||
|
// initialize the db connection with new options
|
||||||
|
if (
|
||||||
|
array_key_exists('dsn', $options) &&
|
||||||
|
array_key_exists('usr', $options) &&
|
||||||
|
array_key_exists('pwd', $options) &&
|
||||||
|
array_key_exists('opt', $options)
|
||||||
|
) {
|
||||||
|
// set default options
|
||||||
|
$options['opt'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
|
||||||
|
$options['opt'][PDO::ATTR_EMULATE_PREPARES] = false;
|
||||||
|
$options['opt'][PDO::ATTR_PERSISTENT] = true;
|
||||||
|
$db_tables_exist = true;
|
||||||
|
|
||||||
|
// setup type and dabase connection
|
||||||
|
self::$_type = strtolower(
|
||||||
|
substr($options['dsn'], 0, strpos($options['dsn'], ':'))
|
||||||
|
);
|
||||||
|
$tableQuery = self::_getTableQuery(self::$_type);
|
||||||
|
self::$_db = new PDO(
|
||||||
|
$options['dsn'],
|
||||||
|
$options['usr'],
|
||||||
|
$options['pwd'],
|
||||||
|
$options['opt']
|
||||||
|
);
|
||||||
|
|
||||||
|
// check if the database contains the required tables
|
||||||
|
$tables = self::$_db->query($tableQuery)->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||||
|
|
||||||
|
// create paste table if necessary
|
||||||
|
if (!in_array(self::_sanitizeIdentifier('paste'), $tables)) {
|
||||||
|
self::_createPasteTable();
|
||||||
|
$db_tables_exist = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize the db connection with new options
|
// create comment table if necessary
|
||||||
if (
|
if (!in_array(self::_sanitizeIdentifier('comment'), $tables)) {
|
||||||
array_key_exists('dsn', $options) &&
|
self::_createCommentTable();
|
||||||
array_key_exists('usr', $options) &&
|
$db_tables_exist = false;
|
||||||
array_key_exists('pwd', $options) &&
|
}
|
||||||
array_key_exists('opt', $options)
|
|
||||||
) {
|
|
||||||
// set default options
|
|
||||||
$options['opt'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
|
|
||||||
$options['opt'][PDO::ATTR_EMULATE_PREPARES] = false;
|
|
||||||
$options['opt'][PDO::ATTR_PERSISTENT] = true;
|
|
||||||
$db_tables_exist = true;
|
|
||||||
|
|
||||||
// setup type and dabase connection
|
// create config table if necessary
|
||||||
self::$_type = strtolower(
|
$db_version = Controller::VERSION;
|
||||||
substr($options['dsn'], 0, strpos($options['dsn'], ':'))
|
if (!in_array(self::_sanitizeIdentifier('config'), $tables)) {
|
||||||
);
|
self::_createConfigTable();
|
||||||
$tableQuery = self::_getTableQuery(self::$_type);
|
// if we only needed to create the config table, the DB is older then 0.22
|
||||||
self::$_db = new PDO(
|
if ($db_tables_exist) {
|
||||||
$options['dsn'],
|
$db_version = '0.21';
|
||||||
$options['usr'],
|
|
||||||
$options['pwd'],
|
|
||||||
$options['opt']
|
|
||||||
);
|
|
||||||
|
|
||||||
// check if the database contains the required tables
|
|
||||||
$tables = self::$_db->query($tableQuery)->fetchAll(PDO::FETCH_COLUMN, 0);
|
|
||||||
|
|
||||||
// create paste table if necessary
|
|
||||||
if (!in_array(self::_sanitizeIdentifier('paste'), $tables)) {
|
|
||||||
self::_createPasteTable();
|
|
||||||
$db_tables_exist = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create comment table if necessary
|
|
||||||
if (!in_array(self::_sanitizeIdentifier('comment'), $tables)) {
|
|
||||||
self::_createCommentTable();
|
|
||||||
$db_tables_exist = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create config table if necessary
|
|
||||||
$db_version = Controller::VERSION;
|
|
||||||
if (!in_array(self::_sanitizeIdentifier('config'), $tables)) {
|
|
||||||
self::_createConfigTable();
|
|
||||||
// if we only needed to create the config table, the DB is older then 0.22
|
|
||||||
if ($db_tables_exist) {
|
|
||||||
$db_version = '0.21';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$db_version = self::_getConfig('VERSION');
|
|
||||||
}
|
|
||||||
|
|
||||||
// update database structure if necessary
|
|
||||||
if (version_compare($db_version, Controller::VERSION, '<')) {
|
|
||||||
self::_upgradeDatabase($db_version);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Exception(
|
$db_version = self::_getConfig('VERSION');
|
||||||
'Missing configuration for key dsn, usr, pwd or opt in the section model_options, please check your configuration file', 6
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update database structure if necessary
|
||||||
|
if (version_compare($db_version, Controller::VERSION, '<')) {
|
||||||
|
self::_upgradeDatabase($db_version);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Exception(
|
||||||
|
'Missing configuration for key dsn, usr, pwd or opt in the section model_options, please check your configuration file', 6
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$_instance;
|
return self::$_instance;
|
||||||
|
@ -250,8 +248,9 @@ class Database extends AbstractData
|
||||||
list($createdKey) = self::_getVersionedKeys(1);
|
list($createdKey) = self::_getVersionedKeys(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$paste['meta'] = Json::decode($paste['meta']);
|
try {
|
||||||
if (!is_array($paste['meta'])) {
|
$paste['meta'] = Json::decode($paste['meta']);
|
||||||
|
} catch (Exception $e) {
|
||||||
$paste['meta'] = array();
|
$paste['meta'] = array();
|
||||||
}
|
}
|
||||||
$paste = self::upgradePreV1Format($paste);
|
$paste = self::upgradePreV1Format($paste);
|
||||||
|
@ -474,7 +473,7 @@ class Database extends AbstractData
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @param bool $firstOnly if only the first row should be returned
|
* @param bool $firstOnly if only the first row should be returned
|
||||||
* @throws PDOException
|
* @throws PDOException
|
||||||
* @return array
|
* @return array|false
|
||||||
*/
|
*/
|
||||||
private static function _select($sql, array $params, $firstOnly = false)
|
private static function _select($sql, array $params, $firstOnly = false)
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,7 +63,7 @@ class Json
|
||||||
*/
|
*/
|
||||||
private static function _detectError()
|
private static function _detectError()
|
||||||
{
|
{
|
||||||
$errorCode = json_last_error();
|
$errorCode = json_last_error();
|
||||||
if ($errorCode === JSON_ERROR_NONE) {
|
if ($errorCode === JSON_ERROR_NONE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ class DataStore extends AbstractPersistence
|
||||||
* @access public
|
* @access public
|
||||||
* @static
|
* @static
|
||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @return \stdClass|false $data
|
* @return array|false $data
|
||||||
*/
|
*/
|
||||||
public static function get($filename)
|
public static function get($filename)
|
||||||
{
|
{
|
||||||
|
|
|
@ -184,7 +184,7 @@ class Request
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $param
|
* @param string $param
|
||||||
* @param string $default
|
* @param string|array $default
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getParam($param, $default = '')
|
public function getParam($param, $default = '')
|
||||||
|
|
Loading…
Reference in New Issue