From 1279a5d2f9aade91cabc9d77fb5125266e6ddf65 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Mon, 8 Mar 2021 05:55:21 +0200 Subject: [PATCH] Added the namespacing for the file and folder classes to the compiler. gh-682 --- README.md | 4 +- admin/README.txt | 4 +- admin/compiler/joomla_3/Helper.php | 4 +- admin/compiler/joomla_3/Helper_site.php | 4 +- admin/helpers/compiler/e_Interpretation.php | 1 + admin/helpers/componentbuilder.php | 63 +++++++++++---------- componentbuilder.xml | 2 +- site/helpers/componentbuilder.php | 63 +++++++++++---------- 8 files changed, 76 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 475569ee1..8591c96d4 100644 --- a/README.md +++ b/README.md @@ -143,11 +143,11 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 7th March, 2021 ++ *Last Build*: 8th March, 2021 + *Version*: 2.12.8 + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **292184** ++ *Line count*: **292190** + *Field count*: **1629** + *File count*: **1935** + *Folder count*: **322** diff --git a/admin/README.txt b/admin/README.txt index 475569ee1..8591c96d4 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -143,11 +143,11 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 7th March, 2021 ++ *Last Build*: 8th March, 2021 + *Version*: 2.12.8 + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **292184** ++ *Line count*: **292190** + *Field count*: **1629** + *File count*: **1935** + *Folder count*: **322** diff --git a/admin/compiler/joomla_3/Helper.php b/admin/compiler/joomla_3/Helper.php index e79f4ac62..0b9d24c5a 100644 --- a/admin/compiler/joomla_3/Helper.php +++ b/admin/compiler/joomla_3/Helper.php @@ -569,12 +569,12 @@ abstract class ###Component###Helper $filePath = $path . '/' . $name . '.php'; $fullPathModel = $fullPathModels . '/' . $name . '.php'; // check if it exists - if (JFile::exists($filePath)) + if (File::exists($filePath)) { // get the file require_once $filePath; } - elseif (JFile::exists($fullPathModel)) + elseif (File::exists($fullPathModel)) { // get the file require_once $fullPathModel; diff --git a/admin/compiler/joomla_3/Helper_site.php b/admin/compiler/joomla_3/Helper_site.php index 76663f887..3fa55d7fb 100644 --- a/admin/compiler/joomla_3/Helper_site.php +++ b/admin/compiler/joomla_3/Helper_site.php @@ -201,12 +201,12 @@ abstract class ###Component###Helper $filePath = $path . '/' . $name . '.php'; $fullPathModel = $fullPathModels . '/' . $name . '.php'; // check if it exists - if (JFile::exists($filePath)) + if (File::exists($filePath)) { // get the file require_once $filePath; } - elseif (JFile::exists($fullPathModel)) + elseif (File::exists($fullPathModel)) { // get the file require_once $fullPathModel; diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index bef848bac..22bc9b7cc 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -22346,6 +22346,7 @@ class Interpretation extends Fields break; case 'admin.helper': case 'site.helper': + $headers[] = 'use Joomla\CMS\Filesystem\File;'; $headers[] = 'use Joomla\CMS\Language\Language;'; $headers[] = 'use Joomla\Registry\Registry;'; $headers[] = 'use Joomla\String\StringHelper;'; diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index 6d9acf9b3..e05ce28a5 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -19,6 +19,10 @@ use Joomla\Utilities\ArrayHelper; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use Joomla\Archive\Archive; +use Joomla\CMS\Filesystem\File; +use Joomla\CMS\Filesystem\Folder; +use Joomla\CMS\Filesystem\Path; /** * Componentbuilder component helper. @@ -796,7 +800,7 @@ abstract class ComponentbuilderHelper // set the path to the form validation rules $path = JPATH_LIBRARIES . '/src/Form/Rule'; // check if the path exist - if (!JFolder::exists($path)) + if (!Folder::exists($path)) { return false; } @@ -805,7 +809,7 @@ abstract class ComponentbuilderHelper // go to that folder chdir($path); // load all the files in this path - $items = JFolder::files('.', '\.php', true, true); + $items = Folder::files('.', '\.php', true, true); // change back to Joomla working directory chdir($joomla); // make sure we have an array @@ -1108,7 +1112,7 @@ abstract class ComponentbuilderHelper */ public static function getAllFilePaths($folder, $fileTypes = array('\.php', '\.js', '\.css', '\.less'), $recurse = true, $full = true) { - if (JFolder::exists($folder)) + if (Folder::exists($folder)) { // we must first store the current woking directory $joomla = getcwd(); @@ -1121,18 +1125,18 @@ abstract class ComponentbuilderHelper foreach ($fileTypes as $type) { // get a list of files in the current directory tree - $files[] = JFolder::files('.', $type, $recurse, $full); + $files[] = Folder::files('.', $type, $recurse, $full); } } elseif (self::checkString($fileTypes)) { // get a list of files in the current directory tree - $files[] = JFolder::files('.', $fileTypes, $recurse, $full); + $files[] = Folder::files('.', $fileTypes, $recurse, $full); } else { // get a list of files in the current directory tree - $files[] = JFolder::files('.', '.', $recurse, $full); + $files[] = Folder::files('.', '.', $recurse, $full); } // change back to Joomla working directory chdir($joomla); @@ -2191,9 +2195,9 @@ abstract class ComponentbuilderHelper md5($image_data) === $target['hash']) { // create the JCB type path if it does not exist - if (!JFolder::exists(JPATH_ROOT . "/administrator/components/com_componentbuilder/assets/images/$type")) + if (!Folder::exists(JPATH_ROOT . "/administrator/components/com_componentbuilder/assets/images/$type")) { - JFolder::create(JPATH_ROOT . "/administrator/components/com_componentbuilder/assets/images/$type"); + Folder::create(JPATH_ROOT . "/administrator/components/com_componentbuilder/assets/images/$type"); } // only set the image if the data match the hash self::writeFile($path, $image_data); @@ -2697,29 +2701,30 @@ abstract class ComponentbuilderHelper chdir($workingDIR); // the full file path of the zip file - $filepath = JPath::clean($filepath); + $filepath = Path::clean($filepath); - // delete an existing zip file (or use an exclusion parameter in JFolder::files() - JFile::delete($filepath); + // delete an existing zip file (or use an exclusion parameter in Folder::files() + File::delete($filepath); // get a list of files in the current directory tree - $files = JFolder::files('.', '', true, true); + $files = Folder::files('.', '', true, true); $zipArray = array(); // setup the zip array foreach ($files as $file) { - $tmp = array(); - $tmp['name'] = str_replace('./', '', $file); - $tmp['data'] = JFile::read($file); - $tmp['time'] = filemtime($file); - $zipArray[] = $tmp; + $tmp = array(); + $tmp['name'] = str_replace('./', '', $file); + $tmp['data'] = self::getFileContents($file); + $tmp['time'] = filemtime($file); + $zipArray[] = $tmp; } // change back to joomla working directory chdir($joomla); // get the zip adapter - $zip = JArchive::getAdapter('zip'); + $adapter = new Archive(); + $zip = $adapter->getAdapter('zip'); //create the zip file if ($zip->create($filepath, $zipArray)) @@ -2774,7 +2779,7 @@ abstract class ComponentbuilderHelper */ public static function removeFolder($dir, $ignore = false) { - if (JFolder::exists($dir)) + if (Folder::exists($dir)) { $it = new RecursiveDirectoryIterator($dir); $it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); @@ -2804,7 +2809,7 @@ abstract class ComponentbuilderHelper { continue; } - JFolder::delete($file_dir); + Folder::delete($file_dir); } else { @@ -2823,13 +2828,13 @@ abstract class ComponentbuilderHelper { continue; } - JFile::delete($file_dir); + File::delete($file_dir); } } // delete the root folder if not ignore found if (!self::checkArray($ignore)) { - return JFolder::delete($dir); + return Folder::delete($dir); } return true; } @@ -4118,11 +4123,10 @@ abstract class ComponentbuilderHelper { $filePath = $default; } - jimport('joomla.filesystem.folder'); // create the folder if it does not exist - if ($createIfNotSet && !JFolder::exists($filePath)) + if ($createIfNotSet && !Folder::exists($filePath)) { - JFolder::create($filePath); + Folder::create($filePath); } // setup the file name $fileName = ''; @@ -4187,11 +4191,10 @@ abstract class ComponentbuilderHelper self::$params = JComponentHelper::getParams('com_componentbuilder'); } $folderPath = self::$params->get($target, $default); - jimport('joomla.filesystem.folder'); // create the folder if it does not exist - if ($createIfNotSet && !JFolder::exists($folderPath)) + if ($createIfNotSet && !Folder::exists($folderPath)) { - JFolder::create($folderPath); + Folder::create($folderPath); } // return the url if ('url' === $type) @@ -7680,12 +7683,12 @@ abstract class ComponentbuilderHelper $filePath = $path . '/' . $name . '.php'; $fullPathModel = $fullPathModels . '/' . $name . '.php'; // check if it exists - if (JFile::exists($filePath)) + if (File::exists($filePath)) { // get the file require_once $filePath; } - elseif (JFile::exists($fullPathModel)) + elseif (File::exists($fullPathModel)) { // get the file require_once $fullPathModel; diff --git a/componentbuilder.xml b/componentbuilder.xml index 65cdb247c..3206007f6 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 7th March, 2021 + 8th March, 2021 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com http://www.joomlacomponentbuilder.com diff --git a/site/helpers/componentbuilder.php b/site/helpers/componentbuilder.php index becf72b36..80558bf24 100644 --- a/site/helpers/componentbuilder.php +++ b/site/helpers/componentbuilder.php @@ -16,6 +16,10 @@ use Joomla\CMS\Language\Language; use Joomla\Registry\Registry; use Joomla\String\StringHelper; use Joomla\Utilities\ArrayHelper; +use Joomla\Archive\Archive; +use Joomla\CMS\Filesystem\File; +use Joomla\CMS\Filesystem\Folder; +use Joomla\CMS\Filesystem\Path; /** * Componentbuilder component helper @@ -793,7 +797,7 @@ abstract class ComponentbuilderHelper // set the path to the form validation rules $path = JPATH_LIBRARIES . '/src/Form/Rule'; // check if the path exist - if (!JFolder::exists($path)) + if (!Folder::exists($path)) { return false; } @@ -802,7 +806,7 @@ abstract class ComponentbuilderHelper // go to that folder chdir($path); // load all the files in this path - $items = JFolder::files('.', '\.php', true, true); + $items = Folder::files('.', '\.php', true, true); // change back to Joomla working directory chdir($joomla); // make sure we have an array @@ -1105,7 +1109,7 @@ abstract class ComponentbuilderHelper */ public static function getAllFilePaths($folder, $fileTypes = array('\.php', '\.js', '\.css', '\.less'), $recurse = true, $full = true) { - if (JFolder::exists($folder)) + if (Folder::exists($folder)) { // we must first store the current woking directory $joomla = getcwd(); @@ -1118,18 +1122,18 @@ abstract class ComponentbuilderHelper foreach ($fileTypes as $type) { // get a list of files in the current directory tree - $files[] = JFolder::files('.', $type, $recurse, $full); + $files[] = Folder::files('.', $type, $recurse, $full); } } elseif (self::checkString($fileTypes)) { // get a list of files in the current directory tree - $files[] = JFolder::files('.', $fileTypes, $recurse, $full); + $files[] = Folder::files('.', $fileTypes, $recurse, $full); } else { // get a list of files in the current directory tree - $files[] = JFolder::files('.', '.', $recurse, $full); + $files[] = Folder::files('.', '.', $recurse, $full); } // change back to Joomla working directory chdir($joomla); @@ -2188,9 +2192,9 @@ abstract class ComponentbuilderHelper md5($image_data) === $target['hash']) { // create the JCB type path if it does not exist - if (!JFolder::exists(JPATH_ROOT . "/administrator/components/com_componentbuilder/assets/images/$type")) + if (!Folder::exists(JPATH_ROOT . "/administrator/components/com_componentbuilder/assets/images/$type")) { - JFolder::create(JPATH_ROOT . "/administrator/components/com_componentbuilder/assets/images/$type"); + Folder::create(JPATH_ROOT . "/administrator/components/com_componentbuilder/assets/images/$type"); } // only set the image if the data match the hash self::writeFile($path, $image_data); @@ -2694,29 +2698,30 @@ abstract class ComponentbuilderHelper chdir($workingDIR); // the full file path of the zip file - $filepath = JPath::clean($filepath); + $filepath = Path::clean($filepath); - // delete an existing zip file (or use an exclusion parameter in JFolder::files() - JFile::delete($filepath); + // delete an existing zip file (or use an exclusion parameter in Folder::files() + File::delete($filepath); // get a list of files in the current directory tree - $files = JFolder::files('.', '', true, true); + $files = Folder::files('.', '', true, true); $zipArray = array(); // setup the zip array foreach ($files as $file) { - $tmp = array(); - $tmp['name'] = str_replace('./', '', $file); - $tmp['data'] = JFile::read($file); - $tmp['time'] = filemtime($file); - $zipArray[] = $tmp; + $tmp = array(); + $tmp['name'] = str_replace('./', '', $file); + $tmp['data'] = self::getFileContents($file); + $tmp['time'] = filemtime($file); + $zipArray[] = $tmp; } // change back to joomla working directory chdir($joomla); // get the zip adapter - $zip = JArchive::getAdapter('zip'); + $adapter = new Archive(); + $zip = $adapter->getAdapter('zip'); //create the zip file if ($zip->create($filepath, $zipArray)) @@ -2771,7 +2776,7 @@ abstract class ComponentbuilderHelper */ public static function removeFolder($dir, $ignore = false) { - if (JFolder::exists($dir)) + if (Folder::exists($dir)) { $it = new RecursiveDirectoryIterator($dir); $it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); @@ -2801,7 +2806,7 @@ abstract class ComponentbuilderHelper { continue; } - JFolder::delete($file_dir); + Folder::delete($file_dir); } else { @@ -2820,13 +2825,13 @@ abstract class ComponentbuilderHelper { continue; } - JFile::delete($file_dir); + File::delete($file_dir); } } // delete the root folder if not ignore found if (!self::checkArray($ignore)) { - return JFolder::delete($dir); + return Folder::delete($dir); } return true; } @@ -4115,11 +4120,10 @@ abstract class ComponentbuilderHelper { $filePath = $default; } - jimport('joomla.filesystem.folder'); // create the folder if it does not exist - if ($createIfNotSet && !JFolder::exists($filePath)) + if ($createIfNotSet && !Folder::exists($filePath)) { - JFolder::create($filePath); + Folder::create($filePath); } // setup the file name $fileName = ''; @@ -4184,11 +4188,10 @@ abstract class ComponentbuilderHelper self::$params = JComponentHelper::getParams('com_componentbuilder'); } $folderPath = self::$params->get($target, $default); - jimport('joomla.filesystem.folder'); // create the folder if it does not exist - if ($createIfNotSet && !JFolder::exists($folderPath)) + if ($createIfNotSet && !Folder::exists($folderPath)) { - JFolder::create($folderPath); + Folder::create($folderPath); } // return the url if ('url' === $type) @@ -6896,12 +6899,12 @@ abstract class ComponentbuilderHelper $filePath = $path . '/' . $name . '.php'; $fullPathModel = $fullPathModels . '/' . $name . '.php'; // check if it exists - if (JFile::exists($filePath)) + if (File::exists($filePath)) { // get the file require_once $filePath; } - elseif (JFile::exists($fullPathModel)) + elseif (File::exists($fullPathModel)) { // get the file require_once $fullPathModel;