mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 04:38:27 +01:00
Minimum viable rewrite of File Inspector frontend
This commit is contained in:
parent
6f6556178f
commit
6095c94de3
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -193,7 +193,7 @@ class e107
|
||||
'e_bb_base' => '{e_HANDLER}bbcode_handler.php',
|
||||
'e_customfields' => '{e_HANDLER}e_customfields_class.php',
|
||||
'e_file' => '{e_HANDLER}file_class.php',
|
||||
'e_file_inspector' => '{e_HANDLER}e_file_inspector_json_phar.php',
|
||||
'e_file_inspector_json_phar' => '{e_HANDLER}e_file_inspector_json_phar.php',
|
||||
'e_form' => '{e_HANDLER}form_handler.php',
|
||||
'e_jshelper' => '{e_HANDLER}js_helper.php',
|
||||
'e_media' => '{e_HANDLER}media_class.php',
|
||||
@ -1609,9 +1609,9 @@ class e107
|
||||
*
|
||||
* @return e_file_inspector
|
||||
*/
|
||||
public static function getFileInspector()
|
||||
public static function getFileInspector($type = 'core')
|
||||
{
|
||||
return self::getSingleton('e_file_inspector');
|
||||
return self::getObject('e_file_inspector_json_phar', e_ADMIN . "core_image.php");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,6 +22,7 @@ abstract class e_file_inspector implements e_file_inspector_interface
|
||||
|
||||
protected $defaultDirsCache;
|
||||
protected $customDirsCache;
|
||||
private $undeterminable = array();
|
||||
|
||||
/**
|
||||
* e_file_inspector constructor
|
||||
@ -32,6 +33,16 @@ abstract class e_file_inspector implements e_file_inspector_interface
|
||||
{
|
||||
$this->database = $database;
|
||||
$this->loadDatabase();
|
||||
|
||||
$appRoot = e107::getInstance()->file_path;
|
||||
$this->undeterminable = array_map(function ($path)
|
||||
{
|
||||
return realpath($path) ? realpath($path) : $path;
|
||||
}, [
|
||||
$appRoot . "e107_config.php",
|
||||
$appRoot . e107::getFolder('admin') . "core_image.php",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,14 +176,14 @@ abstract class e_file_inspector implements e_file_inspector_interface
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function pathToDefaultPath($path)
|
||||
/**
|
||||
* Convert a custom site path to a default path
|
||||
* @param string $path Custom path
|
||||
* @return string
|
||||
*/
|
||||
public function customPathToDefaultPath($path)
|
||||
{
|
||||
if (!$this->customDirsCache)
|
||||
{
|
||||
$this->defaultDirsCache = e107::getInstance()->defaultDirs();
|
||||
$customDirs = e107::getInstance()->e107_dirs ? e107::getInstance()->e107_dirs : [];
|
||||
$this->customDirsCache = array_diff_assoc($customDirs, $this->defaultDirsCache);
|
||||
}
|
||||
if (!is_array($this->customDirsCache)) $this->populateDirsCache();
|
||||
foreach ($this->customDirsCache as $dirType => $customDir)
|
||||
{
|
||||
if (!isset($this->defaultDirsCache[$dirType])) continue;
|
||||
@ -186,6 +197,22 @@ abstract class e_file_inspector implements e_file_inspector_interface
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function defaultPathToCustomPath($path)
|
||||
{
|
||||
if (!is_array($this->customDirsCache)) $this->populateDirsCache();
|
||||
foreach ($this->customDirsCache as $dirType => $customDir)
|
||||
{
|
||||
if (!isset($this->defaultDirsCache[$dirType])) continue;
|
||||
|
||||
$defaultDir = $this->defaultDirsCache[$dirType];
|
||||
if ($customDir === $defaultDir) continue;
|
||||
|
||||
if (substr($path, 0, strlen($defaultDir)) === $defaultDir)
|
||||
$path = $customDir . substr($path, strlen($defaultDir));
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
private function getValidatedBitmask()
|
||||
{
|
||||
if ($this->validatedBitmask !== null) return $this->validatedBitmask;
|
||||
@ -206,6 +233,13 @@ abstract class e_file_inspector implements e_file_inspector_interface
|
||||
*/
|
||||
private function isDeterminable($absolutePath)
|
||||
{
|
||||
return is_file($absolutePath) && is_readable($absolutePath);
|
||||
return is_file($absolutePath) && is_readable($absolutePath) && !in_array($absolutePath, $this->undeterminable);
|
||||
}
|
||||
|
||||
protected function populateDirsCache()
|
||||
{
|
||||
$this->defaultDirsCache = e107::getInstance()->defaultDirs();
|
||||
$customDirs = e107::getInstance()->e107_dirs ? e107::getInstance()->e107_dirs : [];
|
||||
$this->customDirsCache = array_diff_assoc($customDirs, $this->defaultDirsCache);
|
||||
}
|
||||
}
|
@ -56,7 +56,7 @@ class e_file_inspector_json extends e_file_inspector
|
||||
*/
|
||||
public function getChecksums($path)
|
||||
{
|
||||
$path = $this->pathToDefaultPath($path);
|
||||
$path = $this->customPathToDefaultPath($path);
|
||||
return isset($this->coreImage[$path]) ? $this->coreImage[$path] : [];
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ class e_file_inspector_sqlphar extends e_file_inspector
|
||||
*/
|
||||
public function getChecksums($path)
|
||||
{
|
||||
$path = $this->pathToDefaultPath($path);
|
||||
$path = $this->customPathToDefaultPath($path);
|
||||
$statement = $this->coreImage->prepare("
|
||||
SELECT versions.version_string, file_hashes.hash
|
||||
FROM file_hashes
|
||||
|
@ -64,17 +64,12 @@ class e_file_inspectorTest extends \Codeception\Test\Unit
|
||||
$this->assertEquals(0, $result & e_file_inspector::VALIDATED_PRESENCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Create a stable interface for pathToDefaultPath()
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testPathToDefaultPath()
|
||||
public function testCustomPathToDefaultPath()
|
||||
{
|
||||
/** @var e_file_inspector $object */
|
||||
$object = $this->make('e_file_inspector');
|
||||
$class = new ReflectionClass(get_class($object));
|
||||
$method = $class->getMethod('pathToDefaultPath');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($object, 'populate_cache');
|
||||
$object->customPathToDefaultPath('populate_cache');
|
||||
$member = $class->getProperty('customDirsCache');
|
||||
$member->setAccessible(true);
|
||||
$customDirs = $member->getValue($object);
|
||||
@ -83,7 +78,26 @@ class e_file_inspectorTest extends \Codeception\Test\Unit
|
||||
|
||||
$input = "e963_admin/index.php";
|
||||
$expected = "e107_admin/index.php";
|
||||
$actual = $method->invoke($object, $input);
|
||||
$actual = $object->customPathToDefaultPath($input);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testDefaultPathToCustomPath()
|
||||
{
|
||||
/** @var e_file_inspector $object */
|
||||
$object = $this->make('e_file_inspector');
|
||||
$class = new ReflectionClass(get_class($object));
|
||||
$object->customPathToDefaultPath('populate_cache');
|
||||
$member = $class->getProperty('customDirsCache');
|
||||
$member->setAccessible(true);
|
||||
$customDirs = $member->getValue($object);
|
||||
$customDirs['ADMIN_DIRECTORY'] = 'e963_admin/';
|
||||
$member->setValue($object, $customDirs);
|
||||
|
||||
$input = "e107_admin/index.php";
|
||||
$expected = "e963_admin/index.php";
|
||||
$actual = $object->defaultPathToCustomPath($input);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user