From 73db135bcbf492f91336d433e9e16a6b95d631ad Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Sun, 9 May 2021 18:37:19 +0300 Subject: [PATCH 1/3] Display full path to the file/folder in the error message --- .../libraries/rules/xmlfiles.php | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/administrator/components/com_jedchecker/libraries/rules/xmlfiles.php b/administrator/components/com_jedchecker/libraries/rules/xmlfiles.php index 6564804..be981ec 100644 --- a/administrator/components/com_jedchecker/libraries/rules/xmlfiles.php +++ b/administrator/components/com_jedchecker/libraries/rules/xmlfiles.php @@ -51,6 +51,13 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule */ protected $errors; + /** + * Manifest's directory + * + * @var string + */ + protected $basedir; + /** * Initiates the search and check * @@ -97,9 +104,9 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule // Check declared files and folders do exist - $basedir = dirname($file) . '/'; + $this->basedir = dirname($file) . '/'; - $sitedir = $basedir; + $sitedir = ''; // Check: files[folder] (filename|folder)* // ( for package: files[folder] (file|folder)* ) @@ -108,7 +115,7 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule $node = $xml->files; // Get path to site files from "folder" attribute - $sitedir = $basedir . (isset($node['folder']) ? $node['folder'] . '/' : ''); + $sitedir = isset($node['folder']) ? $node['folder'] . '/' : ''; $this->checkFiles($node->filename, $sitedir); $this->checkFiles($node->file, $sitedir); @@ -119,7 +126,7 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule if (isset($xml->media)) { $node = $xml->media; - $dir = $basedir . (isset($node['folder']) ? $node['folder'] . '/' : ''); + $dir = isset($node['folder']) ? $node['folder'] . '/' : ''; $this->checkFiles($node->filename, $dir); $this->checkFiles($node->file, $dir); @@ -130,7 +137,7 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule if (isset($xml->fonts)) { $node = $xml->fonts; - $dir = $basedir . (isset($node['folder']) ? $node['folder'] . '/' : ''); + $dir = isset($node['folder']) ? $node['folder'] . '/' : ''; $this->checkFiles($node->filename, $dir); $this->checkFiles($node->file, $dir); @@ -141,12 +148,12 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule if (isset($xml->languages)) { $node = $xml->languages; - $dir = $basedir . (isset($node['folder']) ? $node['folder'] . '/' : ''); + $dir = isset($node['folder']) ? $node['folder'] . '/' : ''; $this->checkFiles($node->language, $dir); } - $admindir = $basedir; + $admindir = ''; // Check: administration files[folder] (filename|file|folder)* if (isset($xml->administration->files)) @@ -154,7 +161,7 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule $node = $xml->administration->files; // Get path to admin files from "folder" attribute - $admindir = $basedir . (isset($node['folder']) ? $node['folder'] . '/' : ''); + $admindir = isset($node['folder']) ? $node['folder'] . '/' : ''; $this->checkFiles($node->filename, $admindir); $this->checkFiles($node->file, $admindir); @@ -165,7 +172,7 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule if (isset($xml->administration->media)) { $node = $xml->administration->media; - $dir = $basedir . (isset($node['folder']) ? $node['folder'] . '/' : ''); + $dir = isset($node['folder']) ? $node['folder'] . '/' : ''; $this->checkFiles($node->filename, $dir); $this->checkFiles($node->file, $dir); @@ -176,7 +183,7 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule if (isset($xml->administration->languages)) { $node = $xml->administration->languages; - $dir = $basedir . (isset($node['folder']) ? $node['folder'] . '/' : ''); + $dir = isset($node['folder']) ? $node['folder'] . '/' : ''; $this->checkFiles($node->language, $dir); } @@ -186,7 +193,7 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule if (isset($xml->fileset->files)) { $node = $xml->fileset->files; - $dir = $basedir . (isset($node['folder']) ? $node['folder'] . '/' : ''); + $dir = isset($node['folder']) ? $node['folder'] . '/' : ''; $this->checkFiles($node->filename, $dir); $this->checkFiles($node->file, $dir); @@ -196,7 +203,7 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule // Check file: scriptfile if (isset($xml->scriptfile)) { - $this->checkFiles($xml->scriptfile, $basedir); + $this->checkFiles($xml->scriptfile); } // Check files: install sql file* @@ -310,7 +317,7 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule // Convert absolute path to relative (if matches extension path) if (strpos($folder, $extensionPath) === 0) { - $folder = $sitedir . substr($folder, strlen($extensionPath)); + $folder = $this->basedir . $sitedir . substr($folder, strlen($extensionPath)); if (!is_dir($folder)) { @@ -327,7 +334,7 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule { $folder = (string) $xml->namespace['path']; - if (!is_dir($admindir . $folder) && !is_dir($sitedir . $folder)) + if (!is_dir($this->basedir . $admindir . $folder) && !is_dir($this->basedir . $sitedir . $folder)) { $this->errors[] = JText::sprintf('COM_JEDCHECKER_XML_FILES_FOLDER_NOT_FOUND', $folder); } @@ -350,11 +357,11 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule * * @return void */ - protected function checkFiles($files, $dir) + protected function checkFiles($files, $dir = '') { foreach ($files as $file) { - $filename = $dir . $file; + $filename = $this->basedir . $dir . $file; if (is_file($filename)) { @@ -367,7 +374,7 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule continue; } - $this->errors[] = JText::sprintf('COM_JEDCHECKER_XML_FILES_FILE_NOT_FOUND', (string) $file); + $this->errors[] = JText::sprintf('COM_JEDCHECKER_XML_FILES_FILE_NOT_FOUND', $dir . $file); } } @@ -379,13 +386,13 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule * * @return void */ - protected function checkFolders($folders, $dir) + protected function checkFolders($folders, $dir = '') { foreach ($folders as $folder) { - if (!is_dir($dir . $folder)) + if (!is_dir($this->basedir . $dir . $folder)) { - $this->errors[] = JText::sprintf('COM_JEDCHECKER_XML_FILES_FOLDER_NOT_FOUND', (string) $folder); + $this->errors[] = JText::sprintf('COM_JEDCHECKER_XML_FILES_FOLDER_NOT_FOUND', $dir . $folder); } } } From 1b3b020322463946b91ec780ed515d0899c27ceb Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Mon, 10 May 2021 20:16:42 +0300 Subject: [PATCH 2/3] switch to use of JEDCheckerHelper in xmlfiles --- .../libraries/rules/xmlfiles.php | 66 ++----------------- 1 file changed, 7 insertions(+), 59 deletions(-) diff --git a/administrator/components/com_jedchecker/libraries/rules/xmlfiles.php b/administrator/components/com_jedchecker/libraries/rules/xmlfiles.php index be981ec..c1d04a6 100644 --- a/administrator/components/com_jedchecker/libraries/rules/xmlfiles.php +++ b/administrator/components/com_jedchecker/libraries/rules/xmlfiles.php @@ -13,6 +13,9 @@ defined('_JEXEC') or die('Restricted access'); // Include the rule base class require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/rule.php'; +// Include the helper class +require_once JPATH_COMPONENT_ADMINISTRATOR . '/libraries/helper.php'; + /** * class JedcheckerRulesXMLFiles @@ -229,79 +232,24 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule { $attributes = array('addfieldpath', 'addformpath', 'addrulepath'); + $element = JEDCheckerHelper::getElementName($xml); $extensionPath = false; - // @TODO move element name extraction into a helper (similar code is used in XMLinfo rule) - switch ((string) $xml['type']) + $type = (string) $xml['type']; + + switch ($type) { case 'module': - if (isset($xml->element)) - { - $element = (string) $xml->element; - } - else - { - $element = (string) $xml->name; - - if (isset($xml->files)) - { - foreach ($xml->files->children() as $child) - { - if (isset($child['module'])) - { - $element = (string) $child['module']; - break; - } - } - } - } - - $element = strtolower(JFilterInput::getInstance()->clean($element, 'cmd')); - $extensionPath = 'modules/' . $element . '/'; break; case 'plugin': - if (isset($xml->element)) - { - $element = (string) $xml->element; - } - else - { - $element = (string) $xml->name; - - if (isset($xml->files)) - { - foreach ($xml->files->children() as $child) - { - if (isset($child['plugin'])) - { - $element = (string) $child['plugin']; - break; - } - } - } - } - - $element = strtolower(JFilterInput::getInstance()->clean($element, 'cmd')); - $group = (string) $xml['group']; $extensionPath = 'plugins/' . $group . '/' . $element . '/'; break; case 'template': - if (isset($xml->element)) - { - $element = (string) $xml->element; - } - else - { - $element = (string) $xml->name; - } - - $element = strtolower(JFilterInput::getInstance()->clean($element, 'cmd')); - $extensionPath = 'templates/' . $element . '/'; } From 234abe600e613fd3217964ee89a88a965a5fcead Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Tue, 11 May 2021 23:46:12 +0300 Subject: [PATCH 3/3] switch to JEDCheckerHelper::findManifests --- .../com_jedchecker/libraries/rules/xmlfiles.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/administrator/components/com_jedchecker/libraries/rules/xmlfiles.php b/administrator/components/com_jedchecker/libraries/rules/xmlfiles.php index c1d04a6..d118af1 100644 --- a/administrator/components/com_jedchecker/libraries/rules/xmlfiles.php +++ b/administrator/components/com_jedchecker/libraries/rules/xmlfiles.php @@ -69,7 +69,7 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule public function check() { // Find all XML files of the extension - $files = JFolder::files($this->basedir, '\.xml$', true, true); + $files = JEDCheckerHelper::findManifests($this->basedir); // Iterate through all the xml files foreach ($files as $file) @@ -97,12 +97,6 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule return false; } - // Check if this is an extension manifest - if ($xml->getName() !== 'extension') - { - return false; - } - $this->errors = array(); // Check declared files and folders do exist @@ -245,7 +239,6 @@ class JedcheckerRulesXMLFiles extends JEDcheckerRule case 'plugin': $group = (string) $xml['group']; - $extensionPath = 'plugins/' . $group . '/' . $element . '/'; break;