PHP < 5.6 compatibility and StyleCI recommendations
This commit is contained in:
parent
4f06feef81
commit
9f26894b2e
@ -27,7 +27,7 @@ class Configuration
|
||||
*
|
||||
* @const string
|
||||
*/
|
||||
const PROTECTION_LINE = ';<?php http_response_code(403); /*' . PHP_EOL;
|
||||
const PROTECTION_LINE = ';<?php http_response_code(403); /*';
|
||||
|
||||
/**
|
||||
* parsed configuration
|
||||
@ -116,7 +116,7 @@ class Configuration
|
||||
// don't overwrite already converted file
|
||||
if (!is_file($configFile)) {
|
||||
$iniHandle = fopen($configIni, 'r', false, $context);
|
||||
file_put_contents($configFile, self::PROTECTION_LINE);
|
||||
file_put_contents($configFile, self::PROTECTION_LINE . PHP_EOL);
|
||||
file_put_contents($configFile, $iniHandle, FILE_APPEND);
|
||||
fclose($iniHandle);
|
||||
}
|
||||
@ -128,7 +128,7 @@ class Configuration
|
||||
if (is_readable($configIniSample)) {
|
||||
if (!is_readable($configSample)) {
|
||||
$iniSampleHandle = fopen($configIniSample, 'r', false, $context);
|
||||
file_put_contents($configSample, self::PROTECTION_LINE);
|
||||
file_put_contents($configSample, self::PROTECTION_LINE . PHP_EOL);
|
||||
file_put_contents($configSample, $iniSampleHandle, FILE_APPEND);
|
||||
fclose($iniSampleHandle);
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class Filesystem extends AbstractData
|
||||
if (!$this->exists($pasteid)) {
|
||||
return false;
|
||||
}
|
||||
$paste = self::_decodeFile(self::_dataid2path($pasteid) . $pasteid . '.php');
|
||||
$paste = DataStore::get(self::_dataid2path($pasteid) . $pasteid . '.php');
|
||||
if (property_exists($paste->meta, 'attachment')) {
|
||||
$paste->attachment = $paste->meta->attachment;
|
||||
unset($paste->meta->attachment);
|
||||
@ -210,7 +210,7 @@ class Filesystem extends AbstractData
|
||||
// - commentid is the comment identifier itself.
|
||||
// - parentid is the comment this comment replies to (It can be pasteid)
|
||||
if (is_file($discdir . $filename)) {
|
||||
$comment = self::_decodeFile($discdir . $filename);
|
||||
$comment = DataStore::get($discdir . $filename);
|
||||
$items = explode('.', $filename);
|
||||
// Add some meta information not contained in file.
|
||||
$comment->id = $items[1];
|
||||
@ -285,7 +285,7 @@ class Filesystem extends AbstractData
|
||||
}
|
||||
$thirdLevel = array_filter(
|
||||
array_map(
|
||||
function($filename) {
|
||||
function ($filename) {
|
||||
return strlen($filename) >= 20 ?
|
||||
substr($filename, 0, -4) :
|
||||
$filename;
|
||||
@ -385,17 +385,4 @@ class Filesystem extends AbstractData
|
||||
{
|
||||
return (bool) preg_match('/^[a-f0-9]{2}$/', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a paste or comment file.
|
||||
*
|
||||
* @access private
|
||||
* @static
|
||||
* @param string $file
|
||||
* @return array
|
||||
*/
|
||||
private static function _decodeFile($file)
|
||||
{
|
||||
return json_decode(substr(file_get_contents($file), strlen(DataStore::PROTECTION_LINE . PHP_EOL)));
|
||||
}
|
||||
}
|
||||
|
@ -51,4 +51,17 @@ class DataStore extends AbstractPersistence
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the data
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param string $filename
|
||||
* @return array $data
|
||||
*/
|
||||
public static function get($filename)
|
||||
{
|
||||
return json_decode(substr(file_get_contents($filename), strlen(self::PROTECTION_LINE . PHP_EOL)));
|
||||
}
|
||||
}
|
||||
|
@ -134,15 +134,15 @@ class FilesystemTest extends PHPUnit_Framework_TestCase
|
||||
public function testOldFilesGetConverted()
|
||||
{
|
||||
// generate 10 (default purge batch size) pastes in the old format
|
||||
$paste = Helper::getPaste();
|
||||
$comment = Helper::getComment();
|
||||
$paste = Helper::getPaste();
|
||||
$comment = Helper::getComment();
|
||||
$commentid = Helper::getCommentId();
|
||||
$ids = array();
|
||||
$ids = array();
|
||||
for ($i = 0, $max = 10; $i < $max; ++$i) {
|
||||
// PHPs mt_rand only supports 32 bit or up 0x7fffffff on 64 bit systems to be precise :-/
|
||||
$dataid = str_pad(dechex(mt_rand(0, mt_getrandmax())), 8, '0', STR_PAD_LEFT) .
|
||||
str_pad(dechex(mt_rand(0, mt_getrandmax())), 8, '0', STR_PAD_LEFT);
|
||||
$storagedir = $this->_path . DIRECTORY_SEPARATOR . substr($dataid, 0, 2) .
|
||||
$storagedir = $this->_path . DIRECTORY_SEPARATOR . substr($dataid, 0, 2) .
|
||||
DIRECTORY_SEPARATOR . substr($dataid, 2, 2) . DIRECTORY_SEPARATOR;
|
||||
$ids[$dataid] = $storagedir;
|
||||
|
||||
|
@ -111,7 +111,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testViewUrlShortener()
|
||||
{
|
||||
$shortener = 'https://shortener.example.com/api?link=';
|
||||
$shortener = 'https://shortener.example.com/api?link=';
|
||||
$options = parse_ini_file(CONF, true);
|
||||
$options['main']['urlshortener'] = $shortener;
|
||||
Helper::createIniFile(CONF, $options);
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
use PrivateBin\Data\Database;
|
||||
use PrivateBin\Persistence\ServerSalt;
|
||||
|
||||
require_once 'PrivateBinTest.php';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user