added configuration for PHP Coding Standards Fixer, including its fixes, resolving #47

This commit is contained in:
El RIDO 2016-08-15 16:45:47 +02:00
parent 87926ce157
commit 72aac25f68
17 changed files with 114 additions and 90 deletions

1
.gitattributes vendored
View file

@ -8,4 +8,5 @@ tst/ export-ignore
.gitattributes export-ignore .gitattributes export-ignore
.github export-ignore .github export-ignore
.gitignore export-ignore .gitignore export-ignore
.php_cs export-ignore
.travis.yml export-ignore .travis.yml export-ignore

23
.php_cs Normal file
View file

@ -0,0 +1,23 @@
<?php
/**
* Configuration file for PHP Coding Standards Fixer (php-cs-fixer).
*
* On GitHub: https://github.com/FriendsOfPhp/php-cs-fixer
* More information: http://cs.sensiolabs.org/
*/
$finder = Symfony\CS\Finder\DefaultFinder::create()
->in('lib')
;
return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers(['concat_with_spaces', 'long_array_syntax', 'standardize_not_equal',
'operators_spaces', 'duplicate_semicolon',
'remove_leading_slash_use', 'align_equals',
'single_array_no_trailing_comma', 'phpdoc_indent', 'phpdoc_scalar',
'phpdoc_to_comment', 'phpdoc_trim',
'phpdoc_types', 'print_to_echo', 'self_accessor', 'single_quote',
'spaces_cast', 'ternary_spaces', 'phpdoc_order'])
->finder($finder)
;

View file

@ -98,7 +98,7 @@ class Configuration
*/ */
public function __construct() public function __construct()
{ {
$config = array(); $config = array();
$configFile = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini'; $configFile = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini';
if (is_readable($configFile)) { if (is_readable($configFile)) {
$config = parse_ini_file($configFile, true); $config = parse_ini_file($configFile, true);

View file

@ -71,7 +71,7 @@ class Database extends AbstractData
public static function getInstance($options = null) public static function getInstance($options = null)
{ {
// if needed initialize the singleton // if needed initialize the singleton
if (!(self::$_instance instanceof Database)) { if (!(self::$_instance instanceof self)) {
self::$_instance = new self; self::$_instance = new self;
} }
@ -89,17 +89,17 @@ class Database extends AbstractData
array_key_exists('opt', $options) array_key_exists('opt', $options)
) { ) {
// set default options // set default options
$options['opt'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $options['opt'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$options['opt'][PDO::ATTR_EMULATE_PREPARES] = false; $options['opt'][PDO::ATTR_EMULATE_PREPARES] = false;
$options['opt'][PDO::ATTR_PERSISTENT] = true; $options['opt'][PDO::ATTR_PERSISTENT] = true;
$db_tables_exist = true; $db_tables_exist = true;
// setup type and dabase connection // setup type and dabase connection
self::$_type = strtolower( self::$_type = strtolower(
substr($options['dsn'], 0, strpos($options['dsn'], ':')) substr($options['dsn'], 0, strpos($options['dsn'], ':'))
); );
$tableQuery = self::_getTableQuery(self::$_type); $tableQuery = self::_getTableQuery(self::$_type);
self::$_db = new PDO( self::$_db = new PDO(
$options['dsn'], $options['dsn'],
$options['usr'], $options['usr'],
$options['pwd'], $options['pwd'],
@ -168,8 +168,8 @@ class Database extends AbstractData
} }
$opendiscussion = $burnafterreading = false; $opendiscussion = $burnafterreading = false;
$attachment = $attachmentname = ''; $attachment = $attachmentname = '';
$meta = $paste['meta']; $meta = $paste['meta'];
unset($meta['postdate']); unset($meta['postdate']);
$expire_date = 0; $expire_date = 0;
if (array_key_exists('expire_date', $paste['meta'])) { if (array_key_exists('expire_date', $paste['meta'])) {
@ -222,14 +222,14 @@ class Database extends AbstractData
!array_key_exists($pasteid, self::$_cache) !array_key_exists($pasteid, self::$_cache)
) { ) {
self::$_cache[$pasteid] = false; self::$_cache[$pasteid] = false;
$paste = self::_select( $paste = self::_select(
'SELECT * FROM ' . self::_sanitizeIdentifier('paste') . 'SELECT * FROM ' . self::_sanitizeIdentifier('paste') .
' WHERE dataid = ?', array($pasteid), true ' WHERE dataid = ?', array($pasteid), true
); );
if (false !== $paste) { if (false !== $paste) {
// create object // create object
self::$_cache[$pasteid] = new stdClass; self::$_cache[$pasteid] = new stdClass;
self::$_cache[$pasteid]->data = $paste['data']; self::$_cache[$pasteid]->data = $paste['data'];
$meta = json_decode($paste['meta']); $meta = json_decode($paste['meta']);
@ -253,9 +253,9 @@ class Database extends AbstractData
self::$_cache[$pasteid]->attachmentname = $paste['attachmentname']; self::$_cache[$pasteid]->attachmentname = $paste['attachmentname'];
} }
} }
self::$_cache[$pasteid]->meta = $meta; self::$_cache[$pasteid]->meta = $meta;
self::$_cache[$pasteid]->meta->postdate = (int) $paste['postdate']; self::$_cache[$pasteid]->meta->postdate = (int) $paste['postdate'];
$expire_date = (int) $paste['expiredate']; $expire_date = (int) $paste['expiredate'];
if ( if (
$expire_date > 0 $expire_date > 0
) { ) {
@ -368,12 +368,12 @@ class Database extends AbstractData
$comments = array(); $comments = array();
if (count($rows)) { if (count($rows)) {
foreach ($rows as $row) { foreach ($rows as $row) {
$i = $this->getOpenSlot($comments, (int) $row['postdate']); $i = $this->getOpenSlot($comments, (int) $row['postdate']);
$comments[$i] = new stdClass; $comments[$i] = new stdClass;
$comments[$i]->id = $row['dataid']; $comments[$i]->id = $row['dataid'];
$comments[$i]->parentid = $row['parentid']; $comments[$i]->parentid = $row['parentid'];
$comments[$i]->data = $row['data']; $comments[$i]->data = $row['data'];
$comments[$i]->meta = new stdClass; $comments[$i]->meta = new stdClass;
$comments[$i]->meta->postdate = (int) $row['postdate']; $comments[$i]->meta->postdate = (int) $row['postdate'];
if (array_key_exists('nickname', $row) && !empty($row['nickname'])) { if (array_key_exists('nickname', $row) && !empty($row['nickname'])) {
$comments[$i]->meta->nickname = $row['nickname']; $comments[$i]->meta->nickname = $row['nickname'];
@ -415,7 +415,7 @@ class Database extends AbstractData
protected function _getExpiredPastes($batchsize) protected function _getExpiredPastes($batchsize)
{ {
$pastes = array(); $pastes = array();
$rows = self::_select( $rows = self::_select(
'SELECT dataid FROM ' . self::_sanitizeIdentifier('paste') . 'SELECT dataid FROM ' . self::_sanitizeIdentifier('paste') .
' WHERE expiredate < ? LIMIT ?', array(time(), $batchsize) ' WHERE expiredate < ? LIMIT ?', array(time(), $batchsize)
); );
@ -440,7 +440,7 @@ class Database extends AbstractData
private static function _exec($sql, array $params) private static function _exec($sql, array $params)
{ {
$statement = self::$_db->prepare($sql); $statement = self::$_db->prepare($sql);
$result = $statement->execute($params); $result = $statement->execute($params);
$statement->closeCursor(); $statement->closeCursor();
return $result; return $result;
} }
@ -486,7 +486,7 @@ class Database extends AbstractData
$sql = 'SELECT tabname FROM systables '; $sql = 'SELECT tabname FROM systables ';
break; break;
case 'mssql': case 'mssql':
$sql = "SELECT name FROM sysobjects " $sql = 'SELECT name FROM sysobjects '
. "WHERE type = 'U' ORDER BY name"; . "WHERE type = 'U' ORDER BY name";
break; break;
case 'mysql': case 'mysql':
@ -496,22 +496,22 @@ class Database extends AbstractData
$sql = 'SELECT table_name FROM all_tables'; $sql = 'SELECT table_name FROM all_tables';
break; break;
case 'pgsql': case 'pgsql':
$sql = "SELECT c.relname AS table_name " $sql = 'SELECT c.relname AS table_name '
. "FROM pg_class c, pg_user u " . 'FROM pg_class c, pg_user u '
. "WHERE c.relowner = u.usesysid AND c.relkind = 'r' " . "WHERE c.relowner = u.usesysid AND c.relkind = 'r' "
. "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) " . 'AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) '
. "AND c.relname !~ '^(pg_|sql_)' " . "AND c.relname !~ '^(pg_|sql_)' "
. "UNION " . 'UNION '
. "SELECT c.relname AS table_name " . 'SELECT c.relname AS table_name '
. "FROM pg_class c " . 'FROM pg_class c '
. "WHERE c.relkind = 'r' " . "WHERE c.relkind = 'r' "
. "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) " . 'AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) '
. "AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner) " . 'AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner) '
. "AND c.relname !~ '^pg_'"; . "AND c.relname !~ '^pg_'";
break; break;
case 'sqlite': case 'sqlite':
$sql = "SELECT name FROM sqlite_master WHERE type='table' " $sql = "SELECT name FROM sqlite_master WHERE type='table' "
. "UNION ALL SELECT name FROM sqlite_temp_master " . 'UNION ALL SELECT name FROM sqlite_temp_master '
. "WHERE type='table' ORDER BY name"; . "WHERE type='table' ORDER BY name";
break; break;
default: default:
@ -569,7 +569,7 @@ class Database extends AbstractData
private static function _createPasteTable() private static function _createPasteTable()
{ {
list($main_key, $after_key) = self::_getPrimaryKeyClauses(); list($main_key, $after_key) = self::_getPrimaryKeyClauses();
$dataType = self::$_type === 'pgsql' ? 'TEXT' : 'BLOB'; $dataType = self::$_type === 'pgsql' ? 'TEXT' : 'BLOB';
self::$_db->exec( self::$_db->exec(
'CREATE TABLE ' . self::_sanitizeIdentifier('paste') . ' ( ' . 'CREATE TABLE ' . self::_sanitizeIdentifier('paste') . ' ( ' .
"dataid CHAR(16) NOT NULL$main_key, " . "dataid CHAR(16) NOT NULL$main_key, " .
@ -594,7 +594,7 @@ class Database extends AbstractData
private static function _createCommentTable() private static function _createCommentTable()
{ {
list($main_key, $after_key) = self::_getPrimaryKeyClauses(); list($main_key, $after_key) = self::_getPrimaryKeyClauses();
$dataType = self::$_type === 'pgsql' ? 'text' : 'BLOB'; $dataType = self::$_type === 'pgsql' ? 'text' : 'BLOB';
self::$_db->exec( self::$_db->exec(
'CREATE TABLE ' . self::_sanitizeIdentifier('comment') . ' ( ' . 'CREATE TABLE ' . self::_sanitizeIdentifier('comment') . ' ( ' .
"dataid CHAR(16) NOT NULL$main_key, " . "dataid CHAR(16) NOT NULL$main_key, " .

View file

@ -49,7 +49,7 @@ class Filesystem extends AbstractData
self::$_dir = $options['dir'] . DIRECTORY_SEPARATOR; self::$_dir = $options['dir'] . DIRECTORY_SEPARATOR;
} }
// if needed initialize the singleton // if needed initialize the singleton
if (!(self::$_instance instanceof Filesystem)) { if (!(self::$_instance instanceof self)) {
self::$_instance = new self; self::$_instance = new self;
self::_init(); self::_init();
} }
@ -161,7 +161,7 @@ class Filesystem extends AbstractData
public function createComment($pasteid, $parentid, $commentid, $comment) public function createComment($pasteid, $parentid, $commentid, $comment)
{ {
$storagedir = self::_dataid2discussionpath($pasteid); $storagedir = self::_dataid2discussionpath($pasteid);
$filename = $pasteid . '.' . $commentid . '.' . $parentid; $filename = $pasteid . '.' . $commentid . '.' . $parentid;
if (is_file($storagedir . $filename)) { if (is_file($storagedir . $filename)) {
return false; return false;
} }
@ -181,7 +181,7 @@ class Filesystem extends AbstractData
public function readComments($pasteid) public function readComments($pasteid)
{ {
$comments = array(); $comments = array();
$discdir = self::_dataid2discussionpath($pasteid); $discdir = self::_dataid2discussionpath($pasteid);
if (is_dir($discdir)) { if (is_dir($discdir)) {
// Delete all files in discussion directory // Delete all files in discussion directory
$dir = dir($discdir); $dir = dir($discdir);
@ -192,13 +192,13 @@ class Filesystem extends AbstractData
// - parentid is the comment this comment replies to (It can be pasteid) // - parentid is the comment this comment replies to (It can be pasteid)
if (is_file($discdir . $filename)) { if (is_file($discdir . $filename)) {
$comment = json_decode(file_get_contents($discdir . $filename)); $comment = json_decode(file_get_contents($discdir . $filename));
$items = explode('.', $filename); $items = explode('.', $filename);
// Add some meta information not contained in file. // Add some meta information not contained in file.
$comment->id = $items[1]; $comment->id = $items[1];
$comment->parentid = $items[2]; $comment->parentid = $items[2];
// Store in array // Store in array
$key = $this->getOpenSlot($comments, (int) $comment->meta->postdate); $key = $this->getOpenSlot($comments, (int) $comment->meta->postdate);
$comments[$key] = $comment; $comments[$key] = $comment;
} }
} }
@ -236,7 +236,7 @@ class Filesystem extends AbstractData
*/ */
protected function _getExpiredPastes($batchsize) protected function _getExpiredPastes($batchsize)
{ {
$pastes = array(); $pastes = array();
$firstLevel = array_filter( $firstLevel = array_filter(
scandir(self::$_dir), scandir(self::$_dir),
'self::_isFirstLevelDir' 'self::_isFirstLevelDir'
@ -244,7 +244,7 @@ class Filesystem extends AbstractData
if (count($firstLevel) > 0) { if (count($firstLevel) > 0) {
// try at most 10 times the $batchsize pastes before giving up // try at most 10 times the $batchsize pastes before giving up
for ($i = 0, $max = $batchsize * 10; $i < $max; ++$i) { for ($i = 0, $max = $batchsize * 10; $i < $max; ++$i) {
$firstKey = array_rand($firstLevel); $firstKey = array_rand($firstLevel);
$secondLevel = array_filter( $secondLevel = array_filter(
scandir(self::$_dir . $firstLevel[$firstKey]), scandir(self::$_dir . $firstLevel[$firstKey]),
'self::_isSecondLevelDir' 'self::_isSecondLevelDir'
@ -257,7 +257,7 @@ class Filesystem extends AbstractData
} }
$secondKey = array_rand($secondLevel); $secondKey = array_rand($secondLevel);
$path = self::$_dir . $firstLevel[$firstKey] . $path = self::$_dir . $firstLevel[$firstKey] .
DIRECTORY_SEPARATOR . $secondLevel[$secondKey]; DIRECTORY_SEPARATOR . $secondLevel[$secondKey];
if (!is_dir($path)) { if (!is_dir($path)) {
continue; continue;
@ -270,7 +270,7 @@ class Filesystem extends AbstractData
continue; continue;
} }
$thirdKey = array_rand($thirdLevel); $thirdKey = array_rand($thirdLevel);
$pasteid = $thirdLevel[$thirdKey]; $pasteid = $thirdLevel[$thirdKey];
if (in_array($pasteid, $pastes)) { if (in_array($pasteid, $pastes)) {
continue; continue;
} }

View file

@ -77,7 +77,7 @@ class Filter
public static function formatHumanReadableSize($size) public static function formatHumanReadableSize($size)
{ {
$iec = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'); $iec = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
$i = 0; $i = 0;
while (($size / 1024) >= 1) { while (($size / 1024) >= 1) {
$size = $size / 1024; $size = $size / 1024;
$i++; $i++;

View file

@ -114,8 +114,8 @@ class I18n
$args = func_get_args(); $args = func_get_args();
if (is_array(self::$_translations[$messageId])) { if (is_array(self::$_translations[$messageId])) {
$number = (int) $args[1]; $number = (int) $args[1];
$key = self::_getPluralForm($number); $key = self::_getPluralForm($number);
$max = count(self::$_translations[$messageId]) - 1; $max = count(self::$_translations[$messageId]) - 1;
if ($key > $max) { if ($key > $max) {
$key = $max; $key = $max;
} }
@ -143,7 +143,7 @@ class I18n
// check if the lang cookie was set and that language exists // check if the lang cookie was set and that language exists
if (array_key_exists('lang', $_COOKIE) && in_array($_COOKIE['lang'], $availableLanguages)) { if (array_key_exists('lang', $_COOKIE) && in_array($_COOKIE['lang'], $availableLanguages)) {
$match = $_COOKIE['lang']; $match = $_COOKIE['lang'];
} }
// find a translation file matching the browsers language preferences // find a translation file matching the browsers language preferences
else { else {
@ -153,7 +153,7 @@ class I18n
} }
// load translations // load translations
self::$_language = $match; self::$_language = $match;
self::$_translations = ($match == 'en') ? array() : json_decode( self::$_translations = ($match == 'en') ? array() : json_decode(
file_get_contents(self::_getPath($match . '.json')), file_get_contents(self::_getPath($match . '.json')),
true true
@ -319,7 +319,7 @@ class I18n
protected static function _getMatchingLanguage($acceptedLanguages, $availableLanguages) protected static function _getMatchingLanguage($acceptedLanguages, $availableLanguages)
{ {
$matches = array(); $matches = array();
$any = false; $any = false;
foreach ($acceptedLanguages as $acceptedQuality => $acceptedValues) { foreach ($acceptedLanguages as $acceptedQuality => $acceptedValues) {
$acceptedQuality = floatval($acceptedQuality); $acceptedQuality = floatval($acceptedQuality);
if ($acceptedQuality === 0.0) { if ($acceptedQuality === 0.0) {
@ -372,7 +372,7 @@ class I18n
{ {
$a = explode('-', $a); $a = explode('-', $a);
$b = explode('-', $b); $b = explode('-', $b);
for ($i=0, $n = min(count($a), count($b)); $i < $n; ++$i) { for ($i = 0, $n = min(count($a), count($b)); $i < $n; ++$i) {
if ($a[$i] !== $b[$i]) { if ($a[$i] !== $b[$i]) {
break; break;
} }

View file

@ -33,7 +33,7 @@ class Json
public static function encode($input) public static function encode($input)
{ {
$jsonString = json_encode($input); $jsonString = json_encode($input);
$errorCode = json_last_error(); $errorCode = json_last_error();
if ($errorCode === JSON_ERROR_NONE) { if ($errorCode === JSON_ERROR_NONE) {
return $jsonString; return $jsonString;
} }

View file

@ -67,9 +67,9 @@ abstract class AbstractModel
*/ */
public function __construct(Configuration $configuration, AbstractData $storage) public function __construct(Configuration $configuration, AbstractData $storage)
{ {
$this->_conf = $configuration; $this->_conf = $configuration;
$this->_store = $storage; $this->_store = $storage;
$this->_data = new stdClass; $this->_data = new stdClass;
$this->_data->meta = new stdClass; $this->_data->meta = new stdClass;
} }

View file

@ -133,7 +133,7 @@ class Comment extends AbstractModel
*/ */
public function setPaste(Paste $paste) public function setPaste(Paste $paste)
{ {
$this->_paste = $paste; $this->_paste = $paste;
$this->_data->meta->pasteid = $paste->getId(); $this->_data->meta->pasteid = $paste->getId();
} }
@ -199,12 +199,12 @@ class Comment extends AbstractModel
$icon = $this->_conf->getKey('icon'); $icon = $this->_conf->getKey('icon');
if ($icon != 'none') { if ($icon != 'none') {
$pngdata = ''; $pngdata = '';
$hmac = TrafficLimiter::getHash(); $hmac = TrafficLimiter::getHash();
if ($icon == 'identicon') { if ($icon == 'identicon') {
$identicon = new Identicon(); $identicon = new Identicon();
$pngdata = $identicon->getImageDataUri($hmac, 16); $pngdata = $identicon->getImageDataUri($hmac, 16);
} elseif ($icon == 'vizhash') { } elseif ($icon == 'vizhash') {
$vh = new Vizhash16x16(); $vh = new Vizhash16x16();
$pngdata = 'data:image/png;base64,' . base64_encode( $pngdata = 'data:image/png;base64,' . base64_encode(
$vh->generate($hmac) $vh->generate($hmac)
); );

View file

@ -62,11 +62,11 @@ class Paste extends AbstractModel
if (!property_exists($data->meta, 'salt')) { if (!property_exists($data->meta, 'salt')) {
$data->meta->salt = ServerSalt::get(); $data->meta->salt = ServerSalt::get();
} }
$data->comments = array_values($this->getComments()); $data->comments = array_values($this->getComments());
$data->comment_count = count($data->comments); $data->comment_count = count($data->comments);
$data->comment_offset = 0; $data->comment_offset = 0;
$data->{'@context'} = 'js/paste.jsonld'; $data->{'@context'} = 'js/paste.jsonld';
$this->_data = $data; $this->_data = $data;
return $this->_data; return $this->_data;
} }
@ -85,7 +85,7 @@ class Paste extends AbstractModel
} }
$this->_data->meta->postdate = time(); $this->_data->meta->postdate = time();
$this->_data->meta->salt = serversalt::generate(); $this->_data->meta->salt = serversalt::generate();
// store paste // store paste
if ( if (
@ -247,7 +247,7 @@ class Paste extends AbstractModel
throw new Exception('Invalid data.', 73); throw new Exception('Invalid data.', 73);
} }
$this->_data->meta->burnafterreading = true; $this->_data->meta->burnafterreading = true;
$this->_data->meta->opendiscussion = false; $this->_data->meta->opendiscussion = false;
} }
} }
@ -296,7 +296,7 @@ class Paste extends AbstractModel
* *
* @access public * @access public
* @throws Exception * @throws Exception
* @return boolean * @return bool
*/ */
public function isBurnafterreading() public function isBurnafterreading()
{ {
@ -313,7 +313,7 @@ class Paste extends AbstractModel
* *
* @access public * @access public
* @throws Exception * @throws Exception
* @return boolean * @return bool
*/ */
public function isOpendiscussion() public function isOpendiscussion()
{ {

View file

@ -119,7 +119,7 @@ abstract class AbstractPersistence
protected static function _store($filename, $data) protected static function _store($filename, $data)
{ {
self::_initialize(); self::_initialize();
$file = self::$_path . DIRECTORY_SEPARATOR . $filename; $file = self::$_path . DIRECTORY_SEPARATOR . $filename;
$writtenBytes = @file_put_contents($file, $data, LOCK_EX); $writtenBytes = @file_put_contents($file, $data, LOCK_EX);
if ($writtenBytes === false || $writtenBytes < strlen($data)) { if ($writtenBytes === false || $writtenBytes < strlen($data)) {
throw new Exception('unable to write to file ' . $file, 13); throw new Exception('unable to write to file ' . $file, 13);

View file

@ -72,8 +72,8 @@ class PurgeLimiter extends AbstractPersistence
return true; return true;
} }
$file = 'purge_limiter.php'; $file = 'purge_limiter.php';
$now = time(); $now = time();
$content = '<?php' . PHP_EOL . '$GLOBALS[\'purge_limiter\'] = ' . $now . ';' . PHP_EOL; $content = '<?php' . PHP_EOL . '$GLOBALS[\'purge_limiter\'] = ' . $now . ';' . PHP_EOL;
if (!self::_exists($file)) { if (!self::_exists($file)) {
self::_store($file, $content); self::_store($file, $content);

View file

@ -114,7 +114,7 @@ class TrafficLimiter extends AbstractPersistence
$path = self::getPath($file); $path = self::getPath($file);
require $path; require $path;
$now = time(); $now = time();
$tl = $GLOBALS['traffic_limiter']; $tl = $GLOBALS['traffic_limiter'];
// purge file of expired hashes to keep it small // purge file of expired hashes to keep it small
foreach ($tl as $key => $time) { foreach ($tl as $key => $time) {
@ -129,7 +129,7 @@ class TrafficLimiter extends AbstractPersistence
$result = false; $result = false;
} else { } else {
$tl[$hash] = time(); $tl[$hash] = time();
$result = true; $result = true;
} }
self::_store( self::_store(
$file, $file,

View file

@ -168,14 +168,14 @@ class PrivateBin
file_put_contents( file_put_contents(
PATH . $dir . DIRECTORY_SEPARATOR . '.htaccess', PATH . $dir . DIRECTORY_SEPARATOR . '.htaccess',
'Allow from none' . PHP_EOL . 'Allow from none' . PHP_EOL .
'Deny from all'. PHP_EOL, 'Deny from all' . PHP_EOL,
LOCK_EX LOCK_EX
); );
} }
} }
$this->_conf = new Configuration; $this->_conf = new Configuration;
$this->_model = new Model($this->_conf); $this->_model = new Model($this->_conf);
$this->_request = new Request; $this->_request = new Request;
$this->_urlBase = array_key_exists('REQUEST_URI', $_SERVER) ? $this->_urlBase = array_key_exists('REQUEST_URI', $_SERVER) ?
htmlspecialchars($_SERVER['REQUEST_URI']) : '/'; htmlspecialchars($_SERVER['REQUEST_URI']) : '/';
@ -223,8 +223,8 @@ class PrivateBin
); );
} }
$data = $this->_request->getParam('data'); $data = $this->_request->getParam('data');
$attachment = $this->_request->getParam('attachment'); $attachment = $this->_request->getParam('attachment');
$attachmentname = $this->_request->getParam('attachmentname'); $attachmentname = $this->_request->getParam('attachmentname');
// Ensure content is not too big. // Ensure content is not too big.
@ -247,7 +247,7 @@ class PrivateBin
} }
// The user posts a comment. // The user posts a comment.
$pasteid = $this->_request->getParam('pasteid'); $pasteid = $this->_request->getParam('pasteid');
$parentid = $this->_request->getParam('parentid'); $parentid = $this->_request->getParam('parentid');
if (!empty($pasteid) && !empty($parentid)) { if (!empty($pasteid) && !empty($parentid)) {
$paste = $this->_model->getPaste($pasteid); $paste = $this->_model->getPaste($pasteid);
@ -365,7 +365,7 @@ class PrivateBin
try { try {
$paste = $this->_model->getPaste($dataid); $paste = $this->_model->getPaste($dataid);
if ($paste->exists()) { if ($paste->exists()) {
$data = $paste->get(); $data = $paste->get();
$this->_doesExpire = property_exists($data, 'meta') && property_exists($data->meta, 'expire_date'); $this->_doesExpire = property_exists($data, 'meta') && property_exists($data->meta, 'expire_date');
if (property_exists($data->meta, 'salt')) { if (property_exists($data->meta, 'salt')) {
unset($data->meta->salt); unset($data->meta->salt);
@ -407,7 +407,7 @@ class PrivateBin
// label all the expiration options // label all the expiration options
$expire = array(); $expire = array();
foreach ($this->_conf->getSection('expire_options') as $time => $seconds) { foreach ($this->_conf->getSection('expire_options') as $time => $seconds) {
$expire[$time] = ($seconds == 0) ? I18n::_(ucfirst($time)): Filter::formatHumanReadableTime($time); $expire[$time] = ($seconds == 0) ? I18n::_(ucfirst($time)) : Filter::formatHumanReadableTime($time);
} }
// translate all the formatter options // translate all the formatter options
@ -462,7 +462,7 @@ class PrivateBin
$type = ''; $type = '';
} }
$content = '{}'; $content = '{}';
$file = PUBLIC_PATH . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . $type . '.jsonld'; $file = PUBLIC_PATH . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . $type . '.jsonld';
if (is_readable($file)) { if (is_readable($file)) {
$content = str_replace( $content = str_replace(
'?jsonld=', '?jsonld=',
@ -492,7 +492,7 @@ class PrivateBin
if ($status) { if ($status) {
$result['message'] = I18n::_($message); $result['message'] = I18n::_($message);
} else { } else {
$result['id'] = $message; $result['id'] = $message;
$result['url'] = $this->_urlBase . '?' . $message; $result['url'] = $this->_urlBase . '?' . $message;
} }
$result += $other; $result += $other;

View file

@ -16,7 +16,7 @@ namespace PrivateBin;
* Request * Request
* *
* parses request parameters and provides helper functions for routing * parses request parameters and provides helper functions for routing
*/ */
class Request class Request
{ {
/** /**
@ -184,7 +184,7 @@ class Request
private function _detectJsonRequest() private function _detectJsonRequest()
{ {
$hasAcceptHeader = array_key_exists('HTTP_ACCEPT', $_SERVER); $hasAcceptHeader = array_key_exists('HTTP_ACCEPT', $_SERVER);
$acceptHeader = $hasAcceptHeader ? $_SERVER['HTTP_ACCEPT'] : ''; $acceptHeader = $hasAcceptHeader ? $_SERVER['HTTP_ACCEPT'] : '';
// simple cases // simple cases
if ( if (

View file

@ -110,10 +110,10 @@ class Vizhash16x16
for ($i = 0; $i < 7; ++$i) { for ($i = 0; $i < 7; ++$i) {
$action = $this->getInt(); $action = $this->getInt();
$color = imagecolorallocate($image, $r, $g, $b); $color = imagecolorallocate($image, $r, $g, $b);
$r = $r0 = ($r0 + $this->getInt() / 25) % 256; $r = $r0 = ($r0 + $this->getInt() / 25) % 256;
$g = $g0 = ($g0 + $this->getInt() / 25) % 256; $g = $g0 = ($g0 + $this->getInt() / 25) % 256;
$b = $b0 = ($b0 + $this->getInt() / 25) % 256; $b = $b0 = ($b0 + $this->getInt() / 25) % 256;
$this->drawshape($image, $action, $color); $this->drawshape($image, $action, $color);
} }
@ -180,10 +180,10 @@ class Vizhash16x16
private function degrade($img, $direction, $color1, $color2) private function degrade($img, $direction, $color1, $color2)
{ {
if ($direction == 'h') { if ($direction == 'h') {
$size = imagesx($img); $size = imagesx($img);
$sizeinv = imagesy($img); $sizeinv = imagesy($img);
} else { } else {
$size = imagesy($img); $size = imagesy($img);
$sizeinv = imagesx($img); $sizeinv = imagesx($img);
} }
$diffs = array( $diffs = array(
@ -228,8 +228,8 @@ class Vizhash16x16
ImageFilledPolygon($image, $points, 4, $color); ImageFilledPolygon($image, $points, 4, $color);
break; break;
default: default:
$start = $this->getInt() * 360 /256; $start = $this->getInt() * 360 / 256;
$end = $start + $this->getInt() * 180 / 256; $end = $start + $this->getInt() * 180 / 256;
ImageFilledArc($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $start, $end, $color, IMG_ARC_PIE); ImageFilledArc($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $start, $end, $color, IMG_ARC_PIE);
} }
} }