Adds new helper classes.

This commit is contained in:
2022-04-04 17:35:08 +02:00
parent ec827b7369
commit c5be4ff5fa
15 changed files with 320 additions and 355 deletions

View File

@ -1025,51 +1025,6 @@ abstract class ComponentbuilderHelper
}
}
/**
* get all the file paths in folder and sub folders
*
* @param string $folder The local path to parse
* @param array $fileTypes The type of files to get
*
* @return void
*
*/
public static function getAllFilePaths($folder, $fileTypes = array('\.php', '\.js', '\.css', '\.less'), $recurse = true, $full = true)
{
if (Folder::exists($folder))
{
// we must first store the current woking directory
$joomla = getcwd();
// we are changing the working directory to the component path
chdir($folder);
// make sure we have file type filter
if (self::checkArray($fileTypes))
{
// get the files
foreach ($fileTypes as $type)
{
// get a list of files in the current directory tree
$files[] = Folder::files('.', $type, $recurse, $full);
}
}
elseif (self::checkString($fileTypes))
{
// get a list of files in the current directory tree
$files[] = Folder::files('.', $fileTypes, $recurse, $full);
}
else
{
// get a list of files in the current directory tree
$files[] = Folder::files('.', '.', $recurse, $full);
}
// change back to Joomla working directory
chdir($joomla);
// return array of files
return array_map( function($file) { return str_replace('./', '/', $file); }, (array) self::mergeArrays($files));
}
return false;
}
/**
* get all component IDs
*/
@ -3785,81 +3740,6 @@ abstract class ComponentbuilderHelper
return $exists;
}
/**
* Get the file path or url
*
* @param string $type The (url/path) type to return
* @param string $target The Params Target name (if set)
* @param string $fileType The kind of filename to generate (if not set no file name is generated)
* @param string $key The key to adjust the filename (if not set ignored)
* @param string $default The default path if not set in Params (fallback path)
* @param bool $createIfNotSet The switch to create the folder if not found
*
* @return string On success the path or url is returned based on the type requested
*
*/
public static function getFilePath($type = 'path', $target = 'filepath', $fileType = null, $key = '', $default = '', $createIfNotSet = true)
{
// make sure to always have a string/path
if(!self::checkString($default))
{
$default = JPATH_SITE . '/images/';
}
// get the global settings
if (!self::checkObject(self::$params))
{
self::$params = JComponentHelper::getParams('com_componentbuilder');
}
$filePath = self::$params->get($target, $default);
// check the file path (revert to default only of not a hidden file path)
if ('hiddenfilepath' !== $target && strpos($filePath, JPATH_SITE) === false)
{
$filePath = $default;
}
// create the folder if it does not exist
if ($createIfNotSet && !Folder::exists($filePath))
{
Folder::create($filePath);
}
// setup the file name
$fileName = '';
// Get basic key
$basickey = 'Th!s_iS_n0t_sAfe_buT_b3tter_then_n0thiug';
if (method_exists(get_called_class(), "getCryptKey"))
{
$basickey = self::getCryptKey('basic', $basickey);
}
// check the key
if (!self::checkString($key))
{
$key = 'vDm';
}
// set the file name
if (self::checkString($fileType))
{
// set the name
$fileName = trim(md5($type.$target.$basickey.$key) . '.' . trim($fileType, '.'));
}
else
{
$fileName = trim(md5($type.$target.$basickey.$key)) . '.txt';
}
// return the url
if ('url' === $type)
{
if (strpos($filePath, JPATH_SITE) !== false)
{
$filePath = trim( str_replace( JPATH_SITE, '', $filePath), '/');
return JURI::root() . $filePath . '/' . $fileName;
}
// since the path is behind the root folder of the site, return only the root url (may be used to build the link)
return JURI::root();
}
// sanitize the path
return '/' . trim( $filePath, '/' ) . '/' . $fileName;
}
/**
* Get the file path or url
*