mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2024-03-22 13:10:41 +08:00
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)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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