1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 12:20:44 +02:00

Minimum viable rewrite of File Inspector frontend

This commit is contained in:
Nick Liu
2020-03-27 00:27:46 -05:00
parent 6f6556178f
commit 6095c94de3
7 changed files with 534 additions and 691 deletions

View File

@@ -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");
}
/**

View File

@@ -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);
}
}

View File

@@ -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] : [];
}

View File

@@ -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