Skip to content

Commit

Permalink
Code formatting fixes
Browse files Browse the repository at this point in the history
Note that one substantive change was made in modMediaSource ~L1849: The default flag for htmlspecialchars_decode was changed in php 8.1, thus applying explicitly what was the default flag at the time this was originally written.
  • Loading branch information
smg6511 committed Feb 11, 2024
1 parent 864effa commit 7c56174
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 32 deletions.
2 changes: 2 additions & 0 deletions core/lexicon/en/file.inc.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

/**
* File English lexicon topic
*
* @language en
* @package modx
* @subpackage lexicon
*/

$_lang['directory'] = 'Directory';
$_lang['file_create'] = 'Create File';
$_lang['file_download'] = 'Download File';
Expand Down
67 changes: 35 additions & 32 deletions core/src/Revolution/Sources/modMediaSource.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace MODX\Revolution\Sources;

use Exception;
Expand Down Expand Up @@ -361,7 +362,6 @@ public function getContainerList($path)
$directories = $dirNames = $files = $fileNames = [];

if (!empty($path)) {

// Ensure the provided path can be read.
try {
$mimeType = $this->filesystem->mimeType($path);
Expand All @@ -375,16 +375,15 @@ public function getContainerList($path)
$this->addError('path', $this->xpdo->lexicon('file_folder_err_invalid'));
return [];
}

}

try {
$re = '#^(.*?/|)(' . implode('|', array_map('preg_quote', $skipFiles)) . ')/?$#';
$contents = $this->filesystem->listContents($path)
->filter(function(StorageAttributes $attributes) use ($re) {
->filter(function (StorageAttributes $attributes) use ($re) {
return !preg_match($re, $attributes->path());
})
->filter(function(StorageAttributes $attributes) use ($properties) {
->filter(function (StorageAttributes $attributes) use ($properties) {
if ($attributes->isDir()) {
return $this->hasPermission('directory_list');
} elseif ($attributes->isFile()) {
Expand Down Expand Up @@ -420,9 +419,7 @@ public function getContainerList($path)
$directories[$file_name]['menu'] = [
'items' => $this->getListDirContextMenu(),
];

}
elseif ($object instanceof FileAttributes) {
} elseif ($object instanceof FileAttributes) {
// @TODO review/refactor extension and mime_type would be better for filesystems that
// may not always have an extension on it. For example would be S3 and you have an HTML file
// but the name is just myPage - $this->filesystem->getMimetype($object['path']);
Expand All @@ -449,9 +446,7 @@ public function getContainerList($path)
foreach ($files as $file) {
$ls[] = $file;
}

return $ls;

} catch (FilesystemException $e) {
$this->addError('path', $e->getMessage());
$this->xpdo->log(modX::LOG_LEVEL_ERROR, $e->getMessage());
Expand Down Expand Up @@ -486,14 +481,12 @@ public function getObjectsInContainer($path)
$files = $fileNames = [];

if (!empty($path) && $path != DIRECTORY_SEPARATOR) {

try {
$mimeType = $this->filesystem->mimeType($path);
} catch (FilesystemException | UnableToRetrieveMetadata $e) {
$this->addError('path', $e->getMessage());
$this->xpdo->log(modX::LOG_LEVEL_ERROR, $e->getMessage());
return [];

}

// Ensure this is a directory.
Expand All @@ -511,7 +504,11 @@ public function getObjectsInContainer($path)
return [];
}
foreach ($contents as $object) {
if (in_array($object['path'], $skipFiles) || in_array(trim($object['path'], DIRECTORY_SEPARATOR), $skipFiles) || (in_array($fullPath . $object['path'], $skipFiles))) {
if (
in_array($object['path'], $skipFiles) ||
in_array(trim($object['path'], DIRECTORY_SEPARATOR), $skipFiles) ||
in_array($fullPath . $object['path'], $skipFiles)
) {
continue;
}
if ($object instanceof DirectoryAttributes && !$this->hasPermission('directory_list')) {
Expand Down Expand Up @@ -1013,12 +1010,10 @@ public function renameObject($oldPath, $newName)
if (!$this->filesystem->fileExists($oldPath)) {
$this->addError('name', $this->xpdo->lexicon('file_err_invalid'));
return false;
}
elseif ($this->checkFileExists() && $this->filesystem->fileExists($newPath)) {
} elseif ($this->checkFileExists() && $this->filesystem->fileExists($newPath)) {
$this->addError('name', sprintf($this->xpdo->lexicon('file_err_ae'), $newName));
return false;
}
elseif (!$this->checkFileType($newName)) {
} elseif (!$this->checkFileType($newName)) {
return false;
}
} catch (FilesystemException | UnableToRetrieveMetadata $e) {
Expand Down Expand Up @@ -1066,8 +1061,7 @@ public function updateObject($path, $content)
try {
if (!$this->checkFileType($path)) {
return false;
}
elseif (!$this->filesystem->fileExists($path)) {
} elseif (!$this->filesystem->fileExists($path)) {
$this->addError('file', $this->xpdo->lexicon('file_err_nf') . ': ' . $path);
return false;
}
Expand Down Expand Up @@ -1153,7 +1147,7 @@ public function uploadObjectsToContainer($container, array $objects = [])
continue;
}

if ((boolean)$this->xpdo->getOption('upload_translit')) {
if ((bool)$this->xpdo->getOption('upload_translit')) {
$newName = $this->xpdo->filterPathSegment($file['name']);

// If the file name is different after filtering, call OnFileManagerFileRename
Expand Down Expand Up @@ -1194,7 +1188,7 @@ public function uploadObjectsToContainer($container, array $objects = [])
$this->xpdo->log(modX::LOG_LEVEL_ERROR, $e->getMessage());
}
}

$objects[$key] = $file;
}

Expand Down Expand Up @@ -1246,7 +1240,6 @@ public function setVisibility($path, $visibility)
$this->filesystem->setVisibility($path, $visibility);
return true;
}

} catch (FilesystemException | UnableToSetVisibility $e) {
$this->addError('path', $this->xpdo->lexicon('file_err_nf') . ' ' . $e->getMessage());
}
Expand Down Expand Up @@ -1546,13 +1539,15 @@ public function setProperties($properties, $merge = false)

if (!empty($propertyArray['options'])) {
foreach ($propertyArray['options'] as $optionKey => &$option) {
if (empty($option['text']) && !empty($option['name'])) $option['text'] = $option['name'];
if (empty($option['text']) && !empty($option['name'])) {
$option['text'] = $option['name'];
}
unset($option['menu'], $option['name']);
}
}

if ($propertyArray['type'] == 'combo-boolean' && is_numeric($propertyArray['value'])) {
$propertyArray['value'] = (boolean)$propertyArray['value'];
$propertyArray['value'] = (bool)$propertyArray['value'];
}

$propertiesArray[$key] = $propertyArray;
Expand Down Expand Up @@ -1585,7 +1580,7 @@ public function prepareSrcForThumb($src)
return '';
}
} catch (FilesystemException | UnableToRetrieveMetadata $e) {
$this->xpdo->log(modX::LOG_LEVEL_ERROR,$e->getMessage());
$this->xpdo->log(modX::LOG_LEVEL_ERROR, $e->getMessage());
return '';
}

Expand Down Expand Up @@ -1648,9 +1643,9 @@ public function findPolicy($context = '')
$enabled = true;
$context = 'mgr';
if ($context === $this->xpdo->context->get('key')) {
$enabled = (boolean)$this->xpdo->getOption('access_media_source_enabled', null, true);
$enabled = (bool)$this->xpdo->getOption('access_media_source_enabled', null, true);
} elseif ($obj = $this->xpdo->getContext($context)) {
$enabled = (boolean)$obj->getOption('access_media_source_enabled', true);
$enabled = (bool)$obj->getOption('access_media_source_enabled', true);
}
if ($enabled) {
if (empty($this->_policies) || !isset($this->_policies[$context])) {
Expand Down Expand Up @@ -1747,9 +1742,9 @@ public function clearCache(array $options = [])

$options[xPDO::OPT_CACHE_KEY] = $this->getOption('cache_media_sources_key', $options, 'media_sources');
$options[xPDO::OPT_CACHE_HANDLER] = $this->getOption('cache_media_sources_handler', $options, $this->getOption(xPDO::OPT_CACHE_HANDLER, $options));
$options[xPDO::OPT_CACHE_FORMAT] = (integer)$this->getOption('cache_media_sources_format', $options, $this->getOption(xPDO::OPT_CACHE_FORMAT, $options, xPDOCacheManager::CACHE_PHP));
$options[xPDO::OPT_CACHE_ATTEMPTS] = (integer)$this->getOption('cache_media_sources_attempts', $options, $this->getOption(xPDO::OPT_CACHE_ATTEMPTS, $options, 10));
$options[xPDO::OPT_CACHE_ATTEMPT_DELAY] = (integer)$this->getOption('cache_media_sources_attempt_delay', $options, $this->getOption(xPDO::OPT_CACHE_ATTEMPT_DELAY, $options, 1000));
$options[xPDO::OPT_CACHE_FORMAT] = (int)$this->getOption('cache_media_sources_format', $options, $this->getOption(xPDO::OPT_CACHE_FORMAT, $options, xPDOCacheManager::CACHE_PHP));
$options[xPDO::OPT_CACHE_ATTEMPTS] = (int)$this->getOption('cache_media_sources_attempts', $options, $this->getOption(xPDO::OPT_CACHE_ATTEMPTS, $options, 10));
$options[xPDO::OPT_CACHE_ATTEMPT_DELAY] = (int)$this->getOption('cache_media_sources_attempt_delay', $options, $this->getOption(xPDO::OPT_CACHE_ATTEMPT_DELAY, $options, 1000));

if ($c->prepare() && $c->stmt->execute()) {
while ($row = $c->stmt->fetch(PDO::FETCH_ASSOC)) {
Expand Down Expand Up @@ -1851,7 +1846,7 @@ protected function buildFileList($path, $ext, $image_extensions, $bases, $proper
$editAction = $this->getEditActionId();
$canSave = $this->checkPolicy('save');
$canRemove = $this->checkPolicy('remove');
$id = rawurlencode(htmlspecialchars_decode($path));
$id = rawurlencode(htmlspecialchars_decode($path, ENT_COMPAT));

$cls = [];

Expand Down Expand Up @@ -1912,7 +1907,15 @@ protected function buildFileList($path, $ext, $image_extensions, $bases, $proper
$imageWidth = $this->ctx->getOption('filemanager_image_width', 400);
$imageHeight = $this->ctx->getOption('filemanager_image_height', 300);
$preview_image = $this->buildManagerImagePreview($path, $ext, $imageWidth, $imageHeight, $bases, $properties);
$file_list['qtip'] = '<img src="' . $preview_image['src'] . '" width="' . $preview_image['width'] . '" height="' . $preview_image['height'] . '" alt="' . $path . '" />';
// Once minimum php requirement is brought up to 7.4+, heredoc closing can be indented
$file_list['qtip'] = <<<QTIP
<img
src="{$preview_image['src']}"
width="{$preview_image['width']}"
height="{$preview_image['height']}"
alt="{$path}"
>
QTIP;
}
}

Expand Down Expand Up @@ -2361,7 +2364,7 @@ protected function getImageDimensions($path, $ext)
try {
$file = $this->filesystem->read($path);
} catch (FilesystemException $e) {
$this->addError('file',$e->getMessage());
$this->addError('file', $e->getMessage());
}
$size = @getimagesize($this->getBasePath() . $path);
if (is_array($size)) {
Expand Down

0 comments on commit 7c56174

Please sign in to comment.