code style
This commit is contained in:
parent
918de8f0c4
commit
afaa111d22
4 changed files with 18 additions and 14 deletions
|
@ -306,7 +306,7 @@ class i18n
|
||||||
case 'zh':
|
case 'zh':
|
||||||
return ($n > 1 ? 1 : 0);
|
return ($n > 1 ? 1 : 0);
|
||||||
case 'pl':
|
case 'pl':
|
||||||
return ($n == 1 ? 0 : $n%10 >= 2 && $n %10 <=4 && ($n%100 < 10 || $n%100 >= 20) ? 1 : 2);
|
return ($n == 1 ? 0 : $n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
|
||||||
// en, de
|
// en, de
|
||||||
default:
|
default:
|
||||||
return ($n != 1 ? 1 : 0);
|
return ($n != 1 ? 1 : 0);
|
||||||
|
@ -386,7 +386,7 @@ class i18n
|
||||||
protected static function _matchLanguage($a, $b) {
|
protected static function _matchLanguage($a, $b) {
|
||||||
$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]) break;
|
if ($a[$i] !== $b[$i]) break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,13 +45,16 @@ abstract class persistence
|
||||||
* @access public
|
* @access public
|
||||||
* @static
|
* @static
|
||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @return void
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getPath($filename = null)
|
public static function getPath($filename = null)
|
||||||
{
|
{
|
||||||
if(strlen($filename)) {
|
if (strlen($filename))
|
||||||
|
{
|
||||||
return self::$_path . DIRECTORY_SEPARATOR . $filename;
|
return self::$_path . DIRECTORY_SEPARATOR . $filename;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return self::$_path;
|
return self::$_path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +95,7 @@ abstract class persistence
|
||||||
$writtenBytes = @file_put_contents(
|
$writtenBytes = @file_put_contents(
|
||||||
$file,
|
$file,
|
||||||
'Allow from none' . PHP_EOL .
|
'Allow from none' . PHP_EOL .
|
||||||
'Deny from all'. PHP_EOL,
|
'Deny from all' . PHP_EOL,
|
||||||
LOCK_EX
|
LOCK_EX
|
||||||
);
|
);
|
||||||
if ($writtenBytes === false || $writtenBytes < 30) {
|
if ($writtenBytes === false || $writtenBytes < 30) {
|
||||||
|
@ -116,7 +119,8 @@ abstract class persistence
|
||||||
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);
|
||||||
}
|
}
|
||||||
@chmod($file, 0640); // protect file access
|
@chmod($file, 0640); // protect file access
|
||||||
|
|
|
@ -42,7 +42,7 @@ class privatebin_data extends privatebin_abstract
|
||||||
array_key_exists('dir', $options)
|
array_key_exists('dir', $options)
|
||||||
) 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 privatebin_data)) {
|
if (!(self::$_instance instanceof privatebin_data)) {
|
||||||
self::$_instance = new self;
|
self::$_instance = new self;
|
||||||
self::_init();
|
self::_init();
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ class privatebin_data extends privatebin_abstract
|
||||||
*/
|
*/
|
||||||
public function read($pasteid)
|
public function read($pasteid)
|
||||||
{
|
{
|
||||||
if(!$this->exists($pasteid)) return false;
|
if (!$this->exists($pasteid)) return false;
|
||||||
$paste = json_decode(
|
$paste = json_decode(
|
||||||
file_get_contents(self::_dataid2path($pasteid) . $pasteid)
|
file_get_contents(self::_dataid2path($pasteid) . $pasteid)
|
||||||
);
|
);
|
||||||
|
@ -111,7 +111,7 @@ class privatebin_data extends privatebin_abstract
|
||||||
$dir = dir($discdir);
|
$dir = dir($discdir);
|
||||||
while (false !== ($filename = $dir->read()))
|
while (false !== ($filename = $dir->read()))
|
||||||
{
|
{
|
||||||
if (is_file($discdir.$filename)) @unlink($discdir.$filename);
|
if (is_file($discdir . $filename)) @unlink($discdir . $filename);
|
||||||
}
|
}
|
||||||
$dir->close();
|
$dir->close();
|
||||||
|
|
||||||
|
@ -289,7 +289,7 @@ class privatebin_data extends privatebin_abstract
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
self::$_dir . '.htaccess',
|
self::$_dir . '.htaccess',
|
||||||
'Allow from none' . PHP_EOL .
|
'Allow from none' . PHP_EOL .
|
||||||
'Deny from all'. PHP_EOL
|
'Deny from all' . PHP_EOL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,8 +311,8 @@ class privatebin_data extends privatebin_abstract
|
||||||
*/
|
*/
|
||||||
private static function _dataid2path($dataid)
|
private static function _dataid2path($dataid)
|
||||||
{
|
{
|
||||||
return self::$_dir . substr($dataid,0,2) . DIRECTORY_SEPARATOR .
|
return self::$_dir . substr($dataid, 0, 2) . DIRECTORY_SEPARATOR .
|
||||||
substr($dataid,2,2) . DIRECTORY_SEPARATOR;
|
substr($dataid, 2, 2) . DIRECTORY_SEPARATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -115,7 +115,7 @@ class trafficlimiter extends persistence
|
||||||
$tl = $GLOBALS['traffic_limiter'];
|
$tl = $GLOBALS['traffic_limiter'];
|
||||||
|
|
||||||
// purge file of expired IPs to keep it small
|
// purge file of expired IPs to keep it small
|
||||||
foreach($tl as $key => $time)
|
foreach ($tl as $key => $time)
|
||||||
{
|
{
|
||||||
if ($time + self::$_limit < $now)
|
if ($time + self::$_limit < $now)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue