Release of v4.0.0-alpha8
Add power path override option on component level. Fix the sql build feature. #1032.
This commit is contained in:
107
libraries/vendor_jcb/VDM.Joomla/src/Utilities/ArrayHelper.php
Normal file
107
libraries/vendor_jcb/VDM.Joomla/src/Utilities/ArrayHelper.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
/**
|
||||
* Some array tricks helper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class ArrayHelper
|
||||
{
|
||||
/**
|
||||
* Check if have an array with a length
|
||||
*
|
||||
* @input array The array to check
|
||||
*
|
||||
* @returns int|false number of items in array on success
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function check($array, $removeEmptyString = false)
|
||||
{
|
||||
if (is_array($array) && ($nr = count((array) $array)) > 0)
|
||||
{
|
||||
// also make sure the empty strings are removed
|
||||
if ($removeEmptyString)
|
||||
{
|
||||
$array = array_filter($array);
|
||||
|
||||
if ($array === [])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return count($array);
|
||||
}
|
||||
|
||||
return $nr;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge an array of array's
|
||||
*
|
||||
* @input array The arrays you would like to merge
|
||||
*
|
||||
* @returns array|null merged array on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function merge($arrays): ?array
|
||||
{
|
||||
if(self::check($arrays))
|
||||
{
|
||||
$merged = [];
|
||||
foreach ($arrays as $array)
|
||||
{
|
||||
if (self::check($array))
|
||||
{
|
||||
$merged = array_merge($merged, $array);
|
||||
}
|
||||
}
|
||||
return $merged;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if arrays intersect
|
||||
*
|
||||
* @input array The first array
|
||||
* @input array The second array
|
||||
*
|
||||
* @returns bool true if intersect else false
|
||||
*
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public static function intersect($a_array, $b_array): bool
|
||||
{
|
||||
// flip the second array
|
||||
$b_array = array_flip($b_array);
|
||||
|
||||
// loop the first array
|
||||
foreach ($a_array as $v)
|
||||
{
|
||||
if (isset($b_array[$v]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* The Base64 Helper
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Base64Helper
|
||||
{
|
||||
/**
|
||||
* open base64 string if stored as base64 (in JCB)
|
||||
*
|
||||
* @param string|null $data The base64 string
|
||||
* @param string|null $key We store the string with that suffix :)
|
||||
* @param string|null $default The default switch
|
||||
*
|
||||
* @return string|null The opened string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function open(?string $data, ?string $key = '__.o0=base64=Oo.__', ?string $default = 'string'): ?string
|
||||
{
|
||||
// check that we have a string
|
||||
if (StringHelper::check($data))
|
||||
{
|
||||
// check if we have a key
|
||||
if (StringHelper::check($key))
|
||||
{
|
||||
if (strpos($data, $key) !== false)
|
||||
{
|
||||
return base64_decode(str_replace($key, '', $data));
|
||||
}
|
||||
}
|
||||
|
||||
// fallback to this, not perfect method
|
||||
if (base64_encode(base64_decode($data, true)) === $data)
|
||||
{
|
||||
return base64_decode($data);
|
||||
}
|
||||
}
|
||||
|
||||
// check if we should just return the string
|
||||
if ('string' === $default)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities\Component;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\Input\Input;
|
||||
use Joomla\Registry\Registry;
|
||||
use VDM\Joomla\Utilities\String\NamespaceHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Some component helper
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
abstract class Helper
|
||||
{
|
||||
/**
|
||||
* The current option
|
||||
*
|
||||
* @var string|null
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static ?string $option = null;
|
||||
|
||||
/**
|
||||
* The component manifest list cache
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static array $manifest = [];
|
||||
|
||||
/**
|
||||
* The component params list cache
|
||||
*
|
||||
* @var Registry[]
|
||||
* @since 3.0.11
|
||||
*/
|
||||
protected static array $params = [];
|
||||
|
||||
/**
|
||||
* Gets the parameter object for the component
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
*
|
||||
* @return Registry A Registry object.
|
||||
* @see Registry
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getParams(?string $option = null): Registry
|
||||
{
|
||||
// check that we have an option
|
||||
if (empty($option))
|
||||
{
|
||||
$option = self::getOption();
|
||||
}
|
||||
|
||||
// get global value
|
||||
if (!isset(self::$params[$option]) || !self::$params[$option] instanceof Registry)
|
||||
{
|
||||
self::$params[$option] = ComponentHelper::getParams($option);
|
||||
}
|
||||
|
||||
return self::$params[$option];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the component option
|
||||
*
|
||||
* @param string|null $option The option
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function setOption(?string $option): void
|
||||
{
|
||||
self::$option = $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the component option
|
||||
*
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return string|null A component option
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getOption(?string $default = 'empty'): ?string
|
||||
{
|
||||
if (empty(self::$option))
|
||||
{
|
||||
// get the option from the url input
|
||||
self::$option = (new Input)->getString('option', null);
|
||||
}
|
||||
|
||||
if (empty(self::$option))
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
|
||||
// Check if the getInput method exists in the application object
|
||||
if (method_exists($app, 'getInput'))
|
||||
{
|
||||
// get the option from the application
|
||||
self::$option = $app->getInput()->getCmd('option', $default);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the default value if getInput method does not exist
|
||||
self::$option = $default;
|
||||
}
|
||||
}
|
||||
|
||||
return self::$option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the component code name
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return string|null A component code name
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getCode(?string $option = null, ?string $default = null): ?string
|
||||
{
|
||||
// check that we have an option
|
||||
if (empty($option))
|
||||
{
|
||||
$option = self::getOption();
|
||||
}
|
||||
// option with com_
|
||||
if (is_string($option) && strpos($option, 'com_') === 0)
|
||||
{
|
||||
return strtolower(trim(substr($option, 4)));
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the component abstract helper class
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return string|null A component helper name
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function get(?string $option = null, ?string $default = null): ?string
|
||||
{
|
||||
// check that we have an option
|
||||
// and get the code name from it
|
||||
if (($code_name = self::getCode($option, null)) !== null)
|
||||
{
|
||||
// we build the helper class name
|
||||
$helper_name = '\\' . \ucfirst($code_name) . 'Helper';
|
||||
|
||||
// check if class exist
|
||||
if (class_exists($helper_name))
|
||||
{
|
||||
return $helper_name;
|
||||
}
|
||||
|
||||
// try loading namespace
|
||||
if (($namespace = self::getNamespace($option)) !== null)
|
||||
{
|
||||
$name = \ucfirst($code_name) . 'Helper';
|
||||
$namespace_helper = '\\' . $namespace . '\Administrator\Helper\\' . NamespaceHelper::safeSegment($name); // TODO target site or admin locations not just admin...
|
||||
if (class_exists($namespace_helper))
|
||||
{
|
||||
return $namespace_helper;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the component namespace if set
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return string|null A component namespace
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getNamespace(?string $option = null): ?string
|
||||
{
|
||||
$manifest = self::getManifest($option);
|
||||
|
||||
return $manifest->namespace ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the component abstract helper class
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return object|null A component helper name
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getManifest(?string $option = null): ?object
|
||||
{
|
||||
if ($option === null
|
||||
&& ($option = self::getOption($option)) === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// get global manifest_cache values
|
||||
if (!isset(self::$manifest[$option]))
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query->select($db->quoteName('manifest_cache'))
|
||||
->from($db->quoteName('#__extensions'))
|
||||
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
|
||||
->where($db->quoteName('element') . ' LIKE ' . $db->quote($option));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$manifest = $db->loadResult();
|
||||
self::$manifest[$option] = json_decode($manifest);
|
||||
} catch (\Exception $e) {
|
||||
// Handle the database error appropriately.
|
||||
self::$manifest[$option] = null;
|
||||
}
|
||||
}
|
||||
|
||||
return self::$manifest[$option];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the helper class of this component has a method
|
||||
*
|
||||
* @param string $method The method name to search for
|
||||
* @param string|null $option The option for the component.
|
||||
*
|
||||
* @return bool true if method exist
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function methodExists(string $method, ?string $option = null): bool
|
||||
{
|
||||
// get the helper class
|
||||
return ($helper = self::get($option, null)) !== null &&
|
||||
method_exists($helper, $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the helper class of this component has a method, and call it with the arguments
|
||||
*
|
||||
* @param string $method The method name to search for
|
||||
* @param array $arguments The arguments for function.
|
||||
* @param string|null $option The option for the component.
|
||||
*
|
||||
* @return mixed return whatever the method returns or null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function _(string $method, array $arguments = [], ?string $option = null)
|
||||
{
|
||||
// get the helper class
|
||||
if (($helper = self::get($option, null)) !== null &&
|
||||
method_exists($helper, $method))
|
||||
{
|
||||
// we know this is not ideal...
|
||||
// so we need to move these
|
||||
// functions to their own classes
|
||||
return call_user_func_array([$helper, $method], $arguments);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
363
libraries/vendor_jcb/VDM.Joomla/src/Utilities/FileHelper.php
Normal file
363
libraries/vendor_jcb/VDM.Joomla/src/Utilities/FileHelper.php
Normal file
@@ -0,0 +1,363 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Filesystem\Path;
|
||||
use Joomla\CMS\Filesystem\File;
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use Joomla\Archive\Archive;
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
|
||||
|
||||
/**
|
||||
* File helper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class FileHelper
|
||||
{
|
||||
/**
|
||||
* Trigger error notice only once
|
||||
*
|
||||
* @var bool
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
protected static $curlError = false;
|
||||
|
||||
/**
|
||||
* The zipper method
|
||||
*
|
||||
* @param string $workingDirectory The directory where the items must be zipped
|
||||
* @param string $filepath The path to where the zip file must be placed
|
||||
*
|
||||
* @return bool true On success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function zip($workingDirectory, &$filepath): bool
|
||||
{
|
||||
// store the current joomla working directory
|
||||
$joomla = getcwd();
|
||||
|
||||
// we are changing the working directory to the component temp folder
|
||||
chdir($workingDirectory);
|
||||
|
||||
// the full file path of the zip file
|
||||
$filepath = Path::clean($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 (also the hidden files)
|
||||
$files = Folder::files('.', '', true, true, array('.svn', 'CVS', '.DS_Store', '__MACOSX'), array('.*~'));
|
||||
|
||||
$zipArray = [];
|
||||
// setup the zip array
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$tmp = [];
|
||||
$tmp['name'] = str_replace('./', '', (string) $file);
|
||||
$tmp['data'] = self::getContent($file);
|
||||
$tmp['time'] = filemtime($file);
|
||||
$zipArray[] = $tmp;
|
||||
}
|
||||
|
||||
// change back to joomla working directory
|
||||
chdir($joomla);
|
||||
|
||||
// get the zip adapter
|
||||
$zip = (new Archive())->getAdapter('zip');
|
||||
|
||||
//create the zip file
|
||||
return (bool) $zip->create($filepath, $zipArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the content of a file
|
||||
*
|
||||
* @param string $path The path to the file
|
||||
* @param mixed $none The return value if no content was found
|
||||
*
|
||||
* @return string On success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function getContent($path, $none = '')
|
||||
{
|
||||
if (StringHelper::check($path))
|
||||
{
|
||||
// use basic file get content for now
|
||||
if (($content = @file_get_contents($path)) !== FALSE)
|
||||
{
|
||||
return $content;
|
||||
}
|
||||
// use curl if available
|
||||
elseif (function_exists('curl_version'))
|
||||
{
|
||||
// start curl
|
||||
$ch = curl_init();
|
||||
// set the options
|
||||
$options = [];
|
||||
$options[CURLOPT_URL] = $path;
|
||||
$options[CURLOPT_USERAGENT] = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12';
|
||||
$options[CURLOPT_RETURNTRANSFER] = TRUE;
|
||||
$options[CURLOPT_SSL_VERIFYPEER] = FALSE;
|
||||
// load the options
|
||||
curl_setopt_array($ch, $options);
|
||||
// get the content
|
||||
$content = curl_exec($ch);
|
||||
// close the connection
|
||||
curl_close($ch);
|
||||
|
||||
// return if found
|
||||
if (StringHelper::check($content))
|
||||
{
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
elseif (!self::$curlError)
|
||||
{
|
||||
// set the notice
|
||||
Factory::getApplication()->enqueueMessage('<h2>Curl Not Found!</h2><p>Please setup curl on your system, or the <b>Joomla Component</b> will not function correctly!</p>', 'Error');
|
||||
// load this notice only once
|
||||
self::$curlError = true;
|
||||
}
|
||||
}
|
||||
return $none;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a file to the server
|
||||
*
|
||||
* @param string $path The path and file name where to safe the data
|
||||
* @param string $data The data to safe
|
||||
*
|
||||
* @return bool true On success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function write($path, $data): bool
|
||||
{
|
||||
$klaar = false;
|
||||
if (StringHelper::check($data))
|
||||
{
|
||||
// open the file
|
||||
$fh = fopen($path, "w");
|
||||
if (!is_resource($fh))
|
||||
{
|
||||
return $klaar;
|
||||
}
|
||||
// write to the file
|
||||
if (fwrite($fh, $data))
|
||||
{
|
||||
// has been done
|
||||
$klaar = true;
|
||||
}
|
||||
// close file.
|
||||
fclose($fh);
|
||||
}
|
||||
return $klaar;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 array|null
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function getPaths($folder, $fileTypes = array('\.php', '\.js', '\.css', '\.less'), $recurse = true, $full = true): ?array
|
||||
{
|
||||
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 (ArrayHelper::check($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 (StringHelper::check($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( fn($file) => str_replace('./', '/', (string) $file), (array) ArrayHelper::merge($files));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function getPath($type = 'path', $target = 'filepath', $fileType = null, $key = '', $default = '', $createIfNotSet = true): string
|
||||
{
|
||||
// make sure to always have a string/path
|
||||
if(!StringHelper::check($default))
|
||||
{
|
||||
$default = JPATH_SITE . '/images/';
|
||||
}
|
||||
|
||||
// get the global settings
|
||||
$filePath = Helper::getParams()->get($target, $default);
|
||||
|
||||
// check the file path (revert to default only of not a hidden file path)
|
||||
if ('hiddenfilepath' !== $target && strpos((string) $filePath, (string) 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';
|
||||
// get the component helper
|
||||
$helper = Helper::get();
|
||||
// check if method exist in helper class
|
||||
if ($helper && Helper::methodExists('getCryptKey'))
|
||||
{
|
||||
$basickey = $helper::getCryptKey('basic', $basickey);
|
||||
}
|
||||
|
||||
// check the key
|
||||
if (!StringHelper::check($key))
|
||||
{
|
||||
$key = 'vDm';
|
||||
}
|
||||
|
||||
// set the file name
|
||||
if (StringHelper::check($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((string) $filePath, (string) JPATH_SITE) !== false)
|
||||
{
|
||||
$filePath = trim( str_replace( JPATH_SITE, '', (string) $filePath), '/');
|
||||
|
||||
return Uri::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 Uri::root();
|
||||
}
|
||||
|
||||
// sanitize the path
|
||||
return '/' . trim((string) $filePath, '/' ) . '/' . $fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if file exist
|
||||
*
|
||||
* @param string $path The url/path to check
|
||||
*
|
||||
* @return bool If exist true
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function exists($path): bool
|
||||
{
|
||||
$exists = false;
|
||||
// if this is a local path
|
||||
if (strpos($path, 'http:') === false && strpos($path, 'https:') === false)
|
||||
{
|
||||
if (file_exists($path))
|
||||
{
|
||||
$exists = true;
|
||||
}
|
||||
}
|
||||
// check if we can use curl
|
||||
elseif (function_exists('curl_version'))
|
||||
{
|
||||
// initiate curl
|
||||
$ch = curl_init($path);
|
||||
// CURLOPT_NOBODY (do not return body)
|
||||
curl_setopt($ch, CURLOPT_NOBODY, true);
|
||||
// make call
|
||||
$result = curl_exec($ch);
|
||||
// check return value
|
||||
if ($result !== false)
|
||||
{
|
||||
// get the http CODE
|
||||
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($statusCode !== 404)
|
||||
{
|
||||
$exists = true;
|
||||
}
|
||||
}
|
||||
// close the connection
|
||||
curl_close($ch);
|
||||
}
|
||||
elseif ($headers = @get_headers($path))
|
||||
{
|
||||
if(isset($headers[0]) && is_string($headers[0]) && strpos($headers[0],'404') === false)
|
||||
{
|
||||
$exists = true;
|
||||
}
|
||||
}
|
||||
return $exists;
|
||||
}
|
||||
|
||||
}
|
||||
|
187
libraries/vendor_jcb/VDM.Joomla/src/Utilities/FormHelper.php
Normal file
187
libraries/vendor_jcb/VDM.Joomla/src/Utilities/FormHelper.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use Joomla\CMS\Form\FormHelper as JoomlaFormHelper;
|
||||
use Joomla\CMS\Form\FormField;
|
||||
|
||||
|
||||
/**
|
||||
* Form Helper
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class FormHelper
|
||||
{
|
||||
/**
|
||||
* get the field xml
|
||||
*
|
||||
* @param array $attributes The array of attributes
|
||||
* @param array $options The options to apply to the XML element
|
||||
*
|
||||
* @return \SimpleXMLElement|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function xml(array $attributes, ?array $options = null): ?\SimpleXMLElement
|
||||
{
|
||||
// make sure we have attributes and a type value
|
||||
if (ArrayHelper::check($attributes))
|
||||
{
|
||||
// start field xml
|
||||
$XML = new \SimpleXMLElement('<field/>');
|
||||
|
||||
// load the attributes
|
||||
self::attributes($XML, $attributes);
|
||||
|
||||
// check if we have options
|
||||
if (ArrayHelper::check($options))
|
||||
{
|
||||
// load the options
|
||||
self::options($XML, $options);
|
||||
}
|
||||
|
||||
// return the field xml
|
||||
return $XML;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlAppend
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param mixed $node A SimpleXMLElement node to append to the XML element reference,
|
||||
* or a stdClass object containing a comment attribute to be injected
|
||||
* before the XML node and a fieldXML attribute containing a SimpleXMLElement
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function append(\SimpleXMLElement &$xml, $node)
|
||||
{
|
||||
if (!$node)
|
||||
{
|
||||
// element was not returned
|
||||
return;
|
||||
}
|
||||
|
||||
if ($node instanceof \stdClass)
|
||||
{
|
||||
if (property_exists($node, 'comment'))
|
||||
{
|
||||
self::comment($xml, $node->comment);
|
||||
}
|
||||
if (property_exists($node, 'fieldXML'))
|
||||
{
|
||||
self::append($xml, $node->fieldXML);
|
||||
}
|
||||
}
|
||||
elseif ($node instanceof \SimpleXMLElement)
|
||||
{
|
||||
$domXML = \dom_import_simplexml($xml);
|
||||
$domNode = \dom_import_simplexml($node);
|
||||
$domXML->appendChild($domXML->ownerDocument->importNode($domNode, true));
|
||||
$xml = \simplexml_import_dom($domXML);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlComment
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param string $comment The comment to inject
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function comment(\SimpleXMLElement &$xml, string $comment)
|
||||
{
|
||||
$domXML = \dom_import_simplexml($xml);
|
||||
$domComment = new \DOMComment($comment);
|
||||
$nodeTarget = $domXML->ownerDocument->importNode($domComment, true);
|
||||
$domXML->appendChild($nodeTarget);
|
||||
$xml = \simplexml_import_dom($domXML);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlAddAttributes
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param array $attributes The attributes to apply to the XML element
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function attributes(\SimpleXMLElement &$xml, array $attributes = [])
|
||||
{
|
||||
foreach ($attributes as $key => $value)
|
||||
{
|
||||
$xml->addAttribute($key, $value ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlAddOptions
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param array $options The options to apply to the XML element
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function options(\SimpleXMLElement &$xml, array $options = [])
|
||||
{
|
||||
foreach ($options as $key => $value)
|
||||
{
|
||||
$addOption = $xml->addChild('option');
|
||||
$addOption->addAttribute('value', $key ?? '');
|
||||
$addOption[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the field object
|
||||
*
|
||||
* @param array $attributes The array of attributes
|
||||
* @param string $default The default of the field
|
||||
* @param array $options The options to apply to the XML element
|
||||
*
|
||||
* @return FormField|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function field(array $attributes, string $default = '', ?array $options = null): ?FormField
|
||||
{
|
||||
// make sure we have attributes and a type value
|
||||
if (ArrayHelper::check($attributes) && isset($attributes['type']))
|
||||
{
|
||||
// get field type
|
||||
if (($field = JoomlaFormHelper::loadFieldType($attributes['type'], true)) === false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// get field xml
|
||||
$XML = self::xml($attributes, $options);
|
||||
|
||||
// setup the field
|
||||
$field->setup($XML, $default);
|
||||
|
||||
// return the field object
|
||||
return $field;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
253
libraries/vendor_jcb/VDM.Joomla/src/Utilities/GetHelper.php
Normal file
253
libraries/vendor_jcb/VDM.Joomla/src/Utilities/GetHelper.php
Normal file
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
|
||||
|
||||
/**
|
||||
* Some easy get...
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class GetHelper
|
||||
{
|
||||
/**
|
||||
* Get a Variable
|
||||
*
|
||||
* @param string|null $table The table from which to get the variable
|
||||
* @param mixed $where The value where
|
||||
* @param string $whereString The target/field string where/name
|
||||
* @param string $what The return field
|
||||
* @param string $operator The operator between $whereString/field and $where/value
|
||||
* @param string $main The component in which the table is found
|
||||
*
|
||||
* @return mixed string/int/float
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function var(?string $table = null, $where = null,
|
||||
string $whereString = 'user', string $what = 'id',
|
||||
string $operator = '=', ?string $main = null)
|
||||
{
|
||||
if(empty($where))
|
||||
{
|
||||
$where = Factory::getUser()->id;
|
||||
}
|
||||
|
||||
if(empty($main))
|
||||
{
|
||||
$main = Helper::getCode();
|
||||
}
|
||||
|
||||
// Get a db connection.
|
||||
$db = Factory::getDbo();
|
||||
|
||||
// Create a new query object.
|
||||
$query = $db->getQuery(true);
|
||||
$query->select($db->quoteName(array($what)));
|
||||
|
||||
if (empty($table))
|
||||
{
|
||||
$query->from($db->quoteName('#__' . $main));
|
||||
}
|
||||
else
|
||||
{
|
||||
$query->from($db->quoteName('#__' . $main . '_' . $table));
|
||||
}
|
||||
|
||||
if (is_numeric($where))
|
||||
{
|
||||
$query->where($db->quoteName($whereString) . ' ' . $operator . ' ' . (int) $where);
|
||||
}
|
||||
elseif (is_string($where))
|
||||
{
|
||||
$query->where($db->quoteName($whereString) . ' ' . $operator . ' ' . $db->quote((string)$where));
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
if ($db->getNumRows())
|
||||
{
|
||||
return $db->loadResult();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get array of variables
|
||||
*
|
||||
* @param string|null $table The table from which to get the variables
|
||||
* @param mixed $where The value where
|
||||
* @param string $whereString The target/field string where/name
|
||||
* @param string $what The return field
|
||||
* @param string $operator The operator between $whereString/field and $where/value
|
||||
* @param string $main The component in which the table is found
|
||||
* @param bool $unique The switch to return a unique array
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function vars(?string $table = null, $where = null,
|
||||
string $whereString = 'user', string $what = 'id', string $operator = 'IN',
|
||||
?string $main = null, bool $unique = true): ?array
|
||||
{
|
||||
if(empty($where))
|
||||
{
|
||||
$where = Factory::getUser()->id;
|
||||
}
|
||||
|
||||
if($main === null)
|
||||
{
|
||||
$main = Helper::getCode();
|
||||
}
|
||||
|
||||
if (!ArrayHelper::check($where) && $where > 0)
|
||||
{
|
||||
$where = [$where];
|
||||
}
|
||||
|
||||
if (ArrayHelper::check($where))
|
||||
{
|
||||
// prep main <-- why? well if $main='' is empty then $table can be categories or users
|
||||
if (StringHelper::check($main))
|
||||
{
|
||||
$main = '_' . ltrim($main, '_');
|
||||
}
|
||||
|
||||
// Get a db connection.
|
||||
$db = Factory::getDbo();
|
||||
|
||||
// Create a new query object.
|
||||
$query = $db->getQuery(true);
|
||||
$query->select($db->quoteName(array($what)));
|
||||
|
||||
if (empty($table))
|
||||
{
|
||||
$query->from($db->quoteName('#__' . $main));
|
||||
}
|
||||
else
|
||||
{
|
||||
$query->from($db->quoteName('#_' . $main . '_' . $table));
|
||||
}
|
||||
|
||||
// add strings to array search
|
||||
if ('IN_STRINGS' === $operator || 'NOT IN_STRINGS' === $operator)
|
||||
{
|
||||
$query->where($db->quoteName($whereString) . ' ' . str_replace('_STRINGS', '', $operator) . ' ("' . implode('","', $where) . '")');
|
||||
}
|
||||
else
|
||||
{
|
||||
$query->where($db->quoteName($whereString) . ' ' . $operator . ' (' . implode(',', $where) . ')');
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
if ($db->getNumRows())
|
||||
{
|
||||
if ($unique)
|
||||
{
|
||||
return array_unique($db->loadColumn());
|
||||
}
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get all strings between two other strings
|
||||
*
|
||||
* @param string $content The content to search
|
||||
* @param string $start The starting value
|
||||
* @param string $end The ending value
|
||||
*
|
||||
* @return array|null On success
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function allBetween(string $content, string $start, string $end): ?array
|
||||
{
|
||||
// reset bucket
|
||||
$bucket = [];
|
||||
for ($i = 0; ; $i++)
|
||||
{
|
||||
// search for string
|
||||
$found = self::between($content, $start, $end);
|
||||
|
||||
if (StringHelper::check($found))
|
||||
{
|
||||
// add to bucket
|
||||
$bucket[] = $found;
|
||||
|
||||
// build removal string
|
||||
$remove = $start . $found . $end;
|
||||
|
||||
// remove from content
|
||||
$content = str_replace($remove, '', $content);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// safety catch
|
||||
if ($i == 500)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// only return unique array of values
|
||||
if (ArrayHelper::check($bucket))
|
||||
{
|
||||
return array_unique($bucket);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get a string between two other strings
|
||||
*
|
||||
* @param string $content The content to search
|
||||
* @param string $start The starting value
|
||||
* @param string $end The ending value
|
||||
* @param string $default The default value if none found
|
||||
*
|
||||
* @return string On success / empty string on failure
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function between(string $content, string $start, string $end, string $default = ''): string
|
||||
{
|
||||
$array = explode($start, $content);
|
||||
if (isset($array[1]) && strpos($array[1], $end) !== false)
|
||||
{
|
||||
$array = explode($end, $array[1]);
|
||||
|
||||
// return string found between
|
||||
return $array[0];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Some easy get...
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class GetHelperExtrusion extends GetHelper
|
||||
{
|
||||
/**
|
||||
* get all strings between two other strings
|
||||
*
|
||||
* @param string $content The content to search
|
||||
* @param string $start The starting value
|
||||
* @param string $end The ending value
|
||||
*
|
||||
* @return array|null On success
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function allBetween(string $content, string $start, string $end): ?array
|
||||
{
|
||||
// reset bucket
|
||||
$bucket = [];
|
||||
for ($i = 0; ; $i++)
|
||||
{
|
||||
// search for string
|
||||
$found = self::between($content, $start, $end);
|
||||
|
||||
if (StringHelper::check($found))
|
||||
{
|
||||
// add to bucket
|
||||
$bucket[] = $found;
|
||||
|
||||
// build removal string
|
||||
$remove = $start . $found . $end;
|
||||
|
||||
// remove from content
|
||||
$content = str_replace($remove, '', $content);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// safety catch
|
||||
if ($i == 500)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// only return unique array of values
|
||||
if (ArrayHelper::check($bucket))
|
||||
{
|
||||
return array_unique($bucket);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get a string between two other strings
|
||||
*
|
||||
* @param string $content The content to search
|
||||
* @param string $start The starting value
|
||||
* @param string $end The ending value
|
||||
* @param string $default The default value if none found
|
||||
*
|
||||
* @return string On success / empty string on failure
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function between(string $content, string $start, string $end, string $default = ''): string
|
||||
{
|
||||
$array = explode($start, $content);
|
||||
if (isset($array[1]) && strpos($array[1], $end) !== false)
|
||||
{
|
||||
$array = explode($end, $array[1]);
|
||||
|
||||
// return string found between
|
||||
return $array[0];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
}
|
||||
|
215
libraries/vendor_jcb/VDM.Joomla/src/Utilities/GuidHelper.php
Normal file
215
libraries/vendor_jcb/VDM.Joomla/src/Utilities/GuidHelper.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
|
||||
|
||||
/**
|
||||
* Global Unique ID Helper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class GuidHelper
|
||||
{
|
||||
/**
|
||||
* Returns a GUIDv4 string
|
||||
*
|
||||
* Thanks to Dave Pearson (and other)
|
||||
* https://www.php.net/manual/en/function.com-create-guid.php#119168
|
||||
*
|
||||
* Uses the best cryptographically secure method
|
||||
* for all supported platforms with fallback to an older,
|
||||
* less secure version.
|
||||
*
|
||||
* @param bool $trim
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function get(bool $trim = true): string
|
||||
{
|
||||
// Windows
|
||||
if (function_exists('com_create_guid'))
|
||||
{
|
||||
if ($trim)
|
||||
{
|
||||
return trim(com_create_guid(), '{}');
|
||||
}
|
||||
return com_create_guid();
|
||||
}
|
||||
|
||||
// set the braces if needed
|
||||
$lbrace = $trim ? "" : chr(123); // "{"
|
||||
$rbrace = $trim ? "" : chr(125); // "}"
|
||||
|
||||
// OSX/Linux
|
||||
if (function_exists('openssl_random_pseudo_bytes'))
|
||||
{
|
||||
$data = openssl_random_pseudo_bytes(16);
|
||||
$data[6] = chr( ord($data[6]) & 0x0f | 0x40); // set version to 0100
|
||||
$data[8] = chr( ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
|
||||
return $lbrace . vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)) . $lbrace;
|
||||
}
|
||||
|
||||
// Fallback (PHP 4.2+)
|
||||
mt_srand((double) microtime() * 10000);
|
||||
$charid = strtolower( md5( uniqid( rand(), true)));
|
||||
$hyphen = chr(45); // "-"
|
||||
$guidv4 = $lbrace.
|
||||
substr($charid, 0, 8). $hyphen.
|
||||
substr($charid, 8, 4). $hyphen.
|
||||
substr($charid, 12, 4). $hyphen.
|
||||
substr($charid, 16, 4). $hyphen.
|
||||
substr($charid, 20, 12).
|
||||
$rbrace;
|
||||
return $guidv4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the Globally Unique Identifier ( and check if table already has this identifier)
|
||||
*
|
||||
* @param string $guid
|
||||
* @param string|null $table
|
||||
* @param int $id
|
||||
* @param string|null $component
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function valid($guid, ?string $table = null, int $id = 0, ?string $component = null): bool
|
||||
{
|
||||
// check if we have a string
|
||||
if (self::validate($guid))
|
||||
{
|
||||
// check if table already has this identifier
|
||||
if (StringHelper::check($table))
|
||||
{
|
||||
// check that we have the component code name
|
||||
if (!is_string($component))
|
||||
{
|
||||
$component = (string) Helper::getCode();
|
||||
}
|
||||
// Get the database object and a new query object.
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$query->select('COUNT(*)')
|
||||
->from('#__' . (string) $component . '_' . (string) $table)
|
||||
->where($db->quoteName('guid') . ' = ' . $db->quote($guid));
|
||||
|
||||
// remove this item from the list
|
||||
if ($id > 0)
|
||||
{
|
||||
$query->where($db->quoteName('id') . ' <> ' . (int) $id);
|
||||
}
|
||||
|
||||
// Set and query the database.
|
||||
$db->setQuery($query);
|
||||
$duplicate = (bool) $db->loadResult();
|
||||
|
||||
if ($duplicate)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the item by guid in a table
|
||||
*
|
||||
* @param string $guid
|
||||
* @param string $table
|
||||
* @param string|array $what
|
||||
* @param string|null $component
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function item($guid, $table, $what = 'a.id', ?string $component = null)
|
||||
{
|
||||
// check if we have a string
|
||||
// check if table already has this identifier
|
||||
if (self::validate($guid) && StringHelper::check($table))
|
||||
{
|
||||
// check that we have the component code name
|
||||
if (!is_string($component))
|
||||
{
|
||||
$component = (string) Helper::getCode();
|
||||
}
|
||||
// Get the database object and a new query object.
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
if (ArrayHelper::check($what))
|
||||
{
|
||||
$query->select($db->quoteName($what));
|
||||
}
|
||||
else
|
||||
{
|
||||
$query->select($what);
|
||||
}
|
||||
|
||||
$query->from($db->quoteName('#__' . (string) $component . '_' . (string) $table, 'a'))
|
||||
->where($db->quoteName('a.guid') . ' = ' . $db->quote($guid));
|
||||
|
||||
// Set and query the database.
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
if ($db->getNumRows())
|
||||
{
|
||||
if (ArrayHelper::check($what) || $what === 'a.*')
|
||||
{
|
||||
return $db->loadObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $db->loadResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the Globally Unique Identifier
|
||||
*
|
||||
* Thanks to Lewie
|
||||
* https://stackoverflow.com/a/1515456/1429677
|
||||
*
|
||||
* @param string $guid
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
protected static function validate($guid)
|
||||
{
|
||||
// check if we have a string
|
||||
if (StringHelper::check($guid))
|
||||
{
|
||||
return preg_match("/^(\{)?[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}(?(1)\})$/i", $guid);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
101
libraries/vendor_jcb/VDM.Joomla/src/Utilities/JsonHelper.php
Normal file
101
libraries/vendor_jcb/VDM.Joomla/src/Utilities/JsonHelper.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
/**
|
||||
* The json checker
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class JsonHelper
|
||||
{
|
||||
/**
|
||||
* Check if you have a json string
|
||||
*
|
||||
* @input string $string The json string to check
|
||||
*
|
||||
* @returns bool true on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function check($string): bool
|
||||
{
|
||||
if (StringHelper::check($string))
|
||||
{
|
||||
json_decode((string) $string);
|
||||
return (json_last_error() === JSON_ERROR_NONE);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a json object to a string
|
||||
*
|
||||
* @input string $value The json string to convert
|
||||
*
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function string($value, $separator = ", ", $table = null, $id = 'id', $name = 'name')
|
||||
{
|
||||
// do some table foot work
|
||||
$external = false;
|
||||
if (is_string($table) && strpos((string) $table, '#__') !== false)
|
||||
{
|
||||
$external = true;
|
||||
$table = str_replace('#__', '', (string) $table);
|
||||
}
|
||||
|
||||
// check if string is JSON
|
||||
$result = json_decode((string) $value, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE)
|
||||
{
|
||||
// is JSON
|
||||
if (ArrayHelper::check($result))
|
||||
{
|
||||
if (StringHelper::check($table))
|
||||
{
|
||||
$names = [];
|
||||
foreach ($result as $val)
|
||||
{
|
||||
if ($external)
|
||||
{
|
||||
if ($_name = GetHelper::var(null, $val, $id, $name, '=', $table))
|
||||
{
|
||||
$names[] = $_name;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($_name = GetHelper::var($table, $val, $id, $name))
|
||||
{
|
||||
$names[] = $_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ArrayHelper::check($names))
|
||||
{
|
||||
return (string) implode($separator, $names);
|
||||
}
|
||||
}
|
||||
return (string) implode($separator, $result);
|
||||
}
|
||||
return (string) json_decode((string) $value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
102
libraries/vendor_jcb/VDM.Joomla/src/Utilities/MathHelper.php
Normal file
102
libraries/vendor_jcb/VDM.Joomla/src/Utilities/MathHelper.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
/**
|
||||
* Basic Math Helper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class MathHelper
|
||||
{
|
||||
/**
|
||||
* bc math wrapper (very basic not for accounting)
|
||||
*
|
||||
* @param string $type The type bc math
|
||||
* @param int $val1 The first value
|
||||
* @param int $val2 The second value
|
||||
* @param int $scale The scale value
|
||||
*
|
||||
* @return string|int|null|bool
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function bc($type, $val1, $val2, $scale = 0)
|
||||
{
|
||||
// Validate input
|
||||
if (!is_numeric($val1) || !is_numeric($val2))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Build function name
|
||||
$function = 'bc' . $type;
|
||||
|
||||
// Use the bcmath function if available
|
||||
if (is_callable($function))
|
||||
{
|
||||
return $function($val1, $val2, $scale);
|
||||
}
|
||||
|
||||
// if function does not exist we use +-*/ operators (fallback - not ideal)
|
||||
switch ($type)
|
||||
{
|
||||
case 'mul':
|
||||
return (string) round($val1 * $val2, $scale);
|
||||
case 'div':
|
||||
if ($val2 == 0) return null; // Avoid division by zero
|
||||
return (string) round($val1 / $val2, $scale);
|
||||
case 'add':
|
||||
return (string) round($val1 + $val2, $scale);
|
||||
case 'sub':
|
||||
return (string) round($val1 - $val2, $scale);
|
||||
case 'pow':
|
||||
return (string) round(pow($val1, $val2), $scale);
|
||||
case 'comp':
|
||||
$diff = round($val1 - $val2, $scale);
|
||||
return ($diff > 0) ? 1 : (($diff < 0) ? -1 : 0);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic sum of an array with more precision
|
||||
*
|
||||
* @param array $array The values to sum
|
||||
* @param int $scale The scale value
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function sum($array, $scale = 4)
|
||||
{
|
||||
// use the bcadd function if available
|
||||
if (function_exists('bcadd'))
|
||||
{
|
||||
// set the start value
|
||||
$value = 0.0;
|
||||
// loop the values and run bcadd
|
||||
foreach($array as $val)
|
||||
{
|
||||
$value = bcadd($value, (string) $val, $scale);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
// fall back on array sum
|
||||
return array_sum($array);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
/**
|
||||
* Some object tricks
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class ObjectHelper
|
||||
{
|
||||
/**
|
||||
* Check if have an object with a length
|
||||
*
|
||||
* @input object The object to check
|
||||
*
|
||||
* @returns bool true on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function check($object)
|
||||
{
|
||||
if (is_object($object))
|
||||
{
|
||||
return count((array) $object) > 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two objects for equality based on their property values.
|
||||
*
|
||||
* Note that this method works only for simple objects that don't
|
||||
* contain any nested objects or resource references. If you need
|
||||
* to compare more complex objects, you may need to use a
|
||||
* more advanced method such as serialization or reflection.
|
||||
*
|
||||
* @param object|null $obj1 The first object to compare.
|
||||
* @param object|null $obj2 The second object to compare.
|
||||
*
|
||||
* @return bool True if the objects have the same key-value pairs and false otherwise.
|
||||
*/
|
||||
public static function equal(?object $obj1, ?object $obj2): bool
|
||||
{
|
||||
// if any is null we return false as that means there is a none object
|
||||
// we are not comparing null but objects
|
||||
// but we allow null as some objects while
|
||||
// not instantiate are still null
|
||||
if (is_null($obj1) || is_null($obj2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert the objects to arrays of their property values using get_object_vars.
|
||||
$array1 = get_object_vars($obj1);
|
||||
$array2 = get_object_vars($obj2);
|
||||
|
||||
// Compare the arrays using array_diff_assoc to detect any differences.
|
||||
$diff1 = array_diff_assoc($array1, $array2);
|
||||
$diff2 = array_diff_assoc($array2, $array1);
|
||||
|
||||
// If the arrays have the same key-value pairs, they will have no differences, so return true.
|
||||
return empty($diff1) && empty($diff2);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities\String;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Control the naming of a class and function
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class ClassfunctionHelper
|
||||
{
|
||||
/**
|
||||
* Making class or function name safe
|
||||
*
|
||||
* @input string The name you would like to make safe
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safe($name): string
|
||||
{
|
||||
// remove numbers if the first character is a number
|
||||
if (is_numeric(substr((string) $name, 0, 1)))
|
||||
{
|
||||
$name = StringHelper::numbers($name);
|
||||
}
|
||||
|
||||
// remove all spaces and strange characters
|
||||
return trim(preg_replace("/[^A-Za-z0-9_-]/", '', (string) $name));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities\String;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
|
||||
|
||||
/**
|
||||
* Control the naming of a field
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class FieldHelper
|
||||
{
|
||||
/**
|
||||
* The field builder switch
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
protected static $builder = false;
|
||||
|
||||
/**
|
||||
* Making field names safe
|
||||
*
|
||||
* @input string The string you would like to make safe
|
||||
* @input boolean The switch to return an ALL UPPER CASE string
|
||||
* @input string The string to use in white space
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safe($string, $allcap = false, $spacer = '_')
|
||||
{
|
||||
// get global value
|
||||
if (self::$builder === false)
|
||||
{
|
||||
self::$builder = Helper::getParams()->get('field_name_builder', 1);
|
||||
}
|
||||
|
||||
// use the new convention
|
||||
if (2 == self::$builder)
|
||||
{
|
||||
// 0nly continue if we have a string
|
||||
if (StringHelper::check($string))
|
||||
{
|
||||
// check that the first character is not a number
|
||||
if (is_numeric(substr((string)$string, 0, 1)))
|
||||
{
|
||||
$string = StringHelper::numbers($string);
|
||||
}
|
||||
|
||||
// remove all other strange characters
|
||||
$string = trim((string) $string);
|
||||
$string = preg_replace('/'.$spacer.'+/', ' ', $string);
|
||||
$string = preg_replace('/\s+/', ' ', $string);
|
||||
|
||||
// Transliterate string
|
||||
$string = StringHelper::transliterate($string);
|
||||
|
||||
// remove all and keep only characters and numbers
|
||||
$string = preg_replace("/[^A-Za-z0-9 ]/", '', (string) $string);
|
||||
|
||||
// replace white space with underscore (SAFEST OPTION)
|
||||
$string = preg_replace('/\s+/', (string) $spacer, $string);
|
||||
|
||||
// return all caps
|
||||
if ($allcap)
|
||||
{
|
||||
return strtoupper($string);
|
||||
}
|
||||
|
||||
// default is to return lower
|
||||
return strtolower($string);
|
||||
}
|
||||
// not a string
|
||||
return '';
|
||||
}
|
||||
|
||||
// return all caps
|
||||
if ($allcap)
|
||||
{
|
||||
return StringHelper::safe($string, 'U');
|
||||
}
|
||||
|
||||
// use the default (original behavior/convention)
|
||||
return StringHelper::safe($string);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities\String;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Control the naming of a namespace helper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class NamespaceHelper
|
||||
{
|
||||
/**
|
||||
* Making namespace safe
|
||||
*
|
||||
* @param string $string The namespace string you would like to make safe
|
||||
*
|
||||
* @return string on success
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safe(string $string): string
|
||||
{
|
||||
// Remove leading and trailing backslashes
|
||||
$string = trim($string, '\\');
|
||||
|
||||
// Split the string into namespace segments
|
||||
$segments = explode('\\', $string);
|
||||
|
||||
// make each segment safe
|
||||
$segments = array_map([self::class, 'safeSegment'], $segments);
|
||||
|
||||
// Join the namespace segments back together
|
||||
return implode('\\', $segments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Making one namespace segment safe
|
||||
*
|
||||
* @param string $string The namespace segment string you would like to make safe
|
||||
*
|
||||
* @return string on success
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeSegment(string $string): string
|
||||
{
|
||||
// Check if segment starts with a number
|
||||
if (preg_match("/^\d/", $string))
|
||||
{
|
||||
// Extract the starting number(s)
|
||||
preg_match("/^\d+/", $string, $matches);
|
||||
|
||||
if (isset($matches[0]))
|
||||
{
|
||||
$numberWord = StringHelper::numbers($matches[0]);
|
||||
$string = str_replace($matches[0], $numberWord, $string);
|
||||
}
|
||||
}
|
||||
|
||||
// Transliterate string TODO: look again as this makes it lowercase
|
||||
// $segment = StringHelper::transliterate($segment);
|
||||
|
||||
// Make sure segment only contains valid characters
|
||||
return preg_replace("/[^A-Za-z0-9]/", '', $string);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities\String;
|
||||
|
||||
|
||||
/**
|
||||
* Control the naming of a plugin
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class PluginHelper
|
||||
{
|
||||
/**
|
||||
* Making plugin folder name safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeFolderName(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'plg_' . strtolower($group) . '_' . strtolower(
|
||||
$codeName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Making plugin class name safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeClassName(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'Plg' . ucfirst($group) . ucfirst(
|
||||
$codeName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Making plugin install class name safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeInstallClassName(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'plg' . ucfirst($group) . ucfirst(
|
||||
$codeName
|
||||
) . 'InstallerScript';
|
||||
}
|
||||
|
||||
/**
|
||||
* Making language prefix safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeLangPrefix(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'PLG_' . strtoupper($group) . '_' . strtoupper(
|
||||
$codeName
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities\String;
|
||||
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
|
||||
|
||||
/**
|
||||
* Control the naming of a field type
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class TypeHelper
|
||||
{
|
||||
/**
|
||||
* The field builder switch
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
protected static $builder = false;
|
||||
|
||||
/**
|
||||
* Making field type name safe
|
||||
*
|
||||
* @param String $string The you would like to make safe
|
||||
* @param String $option The option for the component.
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safe($string, $option = null)
|
||||
{
|
||||
// get global value
|
||||
if (self::$builder === false)
|
||||
{
|
||||
self::$builder = Helper::getParams($option)->get('type_name_builder', 1);
|
||||
}
|
||||
|
||||
// use the new convention
|
||||
if (2 == self::$builder)
|
||||
{
|
||||
// 0nly continue if we have a string
|
||||
if (StringHelper::check($string))
|
||||
{
|
||||
// check that the first character is not a number
|
||||
if (is_numeric(substr($string, 0, 1)))
|
||||
{
|
||||
$string = StringHelper::numbers($string);
|
||||
}
|
||||
|
||||
// Transliterate string
|
||||
$string = StringHelper::transliterate($string);
|
||||
|
||||
// remove all and keep only characters and numbers and point (TODO just one point)
|
||||
$string = trim(preg_replace("/[^A-Za-z0-9_\.]/", '', (string) $string));
|
||||
|
||||
// best is to return lower (for all string equality in compiler)
|
||||
return strtolower($string);
|
||||
}
|
||||
// not a string
|
||||
return '';
|
||||
}
|
||||
|
||||
// use the default (original behaviour/convention)
|
||||
return StringHelper::safe($string);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
416
libraries/vendor_jcb/VDM.Joomla/src/Utilities/StringHelper.php
Normal file
416
libraries/vendor_jcb/VDM.Joomla/src/Utilities/StringHelper.php
Normal file
@@ -0,0 +1,416 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd September, 2020
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use Joomla\CMS\Filter\InputFilter;
|
||||
use Joomla\CMS\Language\Language;
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
|
||||
|
||||
/**
|
||||
* Some string tricks
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class StringHelper
|
||||
{
|
||||
/**
|
||||
* The Main Active Language
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static $langTag;
|
||||
|
||||
/**
|
||||
* Check if we have a string with a length
|
||||
*
|
||||
* @input string $string The string to check
|
||||
*
|
||||
* @returns bool true on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function check($string): bool
|
||||
{
|
||||
return is_string($string) && strlen($string) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorten a string
|
||||
*
|
||||
* @input string The sting that you would like to shorten
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function shorten($string, $length = 40, $addTip = true)
|
||||
{
|
||||
if (self::check($string))
|
||||
{
|
||||
$initial = strlen((string) $string);
|
||||
$words = preg_split('/([\s\n\r]+)/', (string) $string, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$words_count = count((array)$words);
|
||||
|
||||
$word_length = 0;
|
||||
$last_word = 0;
|
||||
for (; $last_word < $words_count; ++$last_word)
|
||||
{
|
||||
$word_length += strlen($words[$last_word]);
|
||||
if ($word_length > $length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$newString = implode(array_slice($words, 0, $last_word));
|
||||
$final = strlen($newString);
|
||||
if ($initial !== $final && $addTip)
|
||||
{
|
||||
$title = self::shorten($string, 400 , false);
|
||||
return '<span class="hasTip" title="' . $title . '" style="cursor:help">' . trim($newString) . '...</span>';
|
||||
}
|
||||
elseif ($initial !== $final && !$addTip)
|
||||
{
|
||||
return trim($newString) . '...';
|
||||
}
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Making strings safe (various ways)
|
||||
*
|
||||
* @input string The you would like to make safe
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safe($string, $type = 'L', $spacer = '_', $replaceNumbers = true, $keepOnlyCharacters = true)
|
||||
{
|
||||
if ($replaceNumbers === true)
|
||||
{
|
||||
// remove all numbers and replace with English text version (works well only up to millions)
|
||||
$string = self::numbers($string);
|
||||
}
|
||||
// 0nly continue if we have a string
|
||||
if (self::check($string))
|
||||
{
|
||||
// create file name without the extension that is safe
|
||||
if ($type === 'filename')
|
||||
{
|
||||
// make sure VDM is not in the string
|
||||
$string = str_replace('VDM', 'vDm', (string) $string);
|
||||
// Remove anything which isn't a word, whitespace, number
|
||||
// or any of the following caracters -_()
|
||||
// If you don't need to handle multi-byte characters
|
||||
// you can use preg_replace rather than mb_ereg_replace
|
||||
// Thanks @Łukasz Rysiak!
|
||||
// $string = mb_ereg_replace("([^\w\s\d\-_\(\)])", '', $string);
|
||||
$string = preg_replace("([^\w\s\d\-_\(\)])", '', $string);
|
||||
|
||||
// http://stackoverflow.com/a/2021729/1429677
|
||||
return preg_replace('/\s+/', ' ', (string) $string);
|
||||
}
|
||||
// remove all other characters
|
||||
$string = trim((string) $string);
|
||||
$string = preg_replace('/'.$spacer.'+/', ' ', $string);
|
||||
$string = preg_replace('/\s+/', ' ', $string);
|
||||
// Transliterate string
|
||||
$string = self::transliterate($string);
|
||||
// remove all and keep only characters
|
||||
if ($keepOnlyCharacters)
|
||||
{
|
||||
$string = preg_replace("/[^A-Za-z ]/", '', (string) $string);
|
||||
}
|
||||
// keep both numbers and characters
|
||||
else
|
||||
{
|
||||
$string = preg_replace("/[^A-Za-z0-9 ]/", '', (string) $string);
|
||||
}
|
||||
// select final adaptations
|
||||
if ($type === 'L' || $type === 'strtolower')
|
||||
{
|
||||
// replace white space with underscore
|
||||
$string = preg_replace('/\s+/', (string) $spacer, (string) $string);
|
||||
// default is to return lower
|
||||
return strtolower($string);
|
||||
}
|
||||
elseif ($type === 'W')
|
||||
{
|
||||
// return a string with all first letter of each word uppercase(no underscore)
|
||||
return ucwords(strtolower($string));
|
||||
}
|
||||
elseif ($type === 'w' || $type === 'word')
|
||||
{
|
||||
// return a string with all lowercase(no underscore)
|
||||
return strtolower($string);
|
||||
}
|
||||
elseif ($type === 'Ww' || $type === 'Word')
|
||||
{
|
||||
// return a string with first letter of the first word uppercase and all the rest lowercase(no underscore)
|
||||
return ucfirst(strtolower($string));
|
||||
}
|
||||
elseif ($type === 'WW' || $type === 'WORD')
|
||||
{
|
||||
// return a string with all the uppercase(no underscore)
|
||||
return strtoupper($string);
|
||||
}
|
||||
elseif ($type === 'U' || $type === 'strtoupper')
|
||||
{
|
||||
// replace white space with underscore
|
||||
$string = preg_replace('/\s+/', (string) $spacer, $string);
|
||||
// return all upper
|
||||
return strtoupper($string);
|
||||
}
|
||||
elseif ($type === 'F' || $type === 'ucfirst')
|
||||
{
|
||||
// replace white space with underscore
|
||||
$string = preg_replace('/\s+/', (string) $spacer, $string);
|
||||
// return with first character to upper
|
||||
return ucfirst(strtolower($string));
|
||||
}
|
||||
elseif ($type === 'cA' || $type === 'cAmel' || $type === 'camelcase')
|
||||
{
|
||||
// convert all words to first letter uppercase
|
||||
$string = ucwords(strtolower($string));
|
||||
// remove white space
|
||||
$string = preg_replace('/\s+/', '', $string);
|
||||
// now return first letter lowercase
|
||||
return lcfirst($string);
|
||||
}
|
||||
// return string
|
||||
return $string;
|
||||
}
|
||||
// not a string
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert none English strings to code usable string
|
||||
*
|
||||
* @input an string
|
||||
*
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function transliterate($string)
|
||||
{
|
||||
// set tag only once
|
||||
if (!self::check(self::$langTag))
|
||||
{
|
||||
// get global value
|
||||
self::$langTag = Helper::getParams()->get('language', 'en-GB');
|
||||
}
|
||||
|
||||
// Transliterate on the language requested
|
||||
$lang = Language::getInstance(self::$langTag);
|
||||
|
||||
return $lang->transliterate($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* make sure a string is HTML save
|
||||
*
|
||||
* @input an html string
|
||||
*
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function html($var, $charset = 'UTF-8', $shorten = false, $length = 40, $addTip = true)
|
||||
{
|
||||
if (self::check($var))
|
||||
{
|
||||
$filter = new InputFilter();
|
||||
$string = $filter->clean(
|
||||
html_entity_decode(
|
||||
htmlentities(
|
||||
(string) $var,
|
||||
ENT_COMPAT,
|
||||
$charset
|
||||
)
|
||||
),
|
||||
'HTML'
|
||||
);
|
||||
if ($shorten)
|
||||
{
|
||||
return self::shorten($string, $length, $addTip);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all int in a string to an English word string
|
||||
*
|
||||
* @input an string with numbers
|
||||
*
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function numbers($string)
|
||||
{
|
||||
// set numbers array
|
||||
$numbers = [];
|
||||
$search_replace= [];
|
||||
|
||||
// first get all numbers
|
||||
preg_match_all('!\d+!', (string) $string, $numbers);
|
||||
|
||||
// check if we have any numbers
|
||||
if (isset($numbers[0]) && ArrayHelper::check($numbers[0]))
|
||||
{
|
||||
foreach ($numbers[0] as $number)
|
||||
{
|
||||
$search_replace[$number] = self::number((int)$number);
|
||||
}
|
||||
|
||||
// now replace numbers in string
|
||||
$string = str_replace(array_keys($search_replace), array_values($search_replace), (string) $string);
|
||||
|
||||
// check if we missed any, strange if we did.
|
||||
return self::numbers($string);
|
||||
}
|
||||
|
||||
// return the string with no numbers remaining.
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an integer into an English word string
|
||||
* Thanks to Tom Nicholson <http://php.net/manual/en/function.strval.php#41988>
|
||||
*
|
||||
* @input an int
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function number($x)
|
||||
{
|
||||
$nwords = array( "zero", "one", "two", "three", "four", "five", "six", "seven",
|
||||
"eight", "nine", "ten", "eleven", "twelve", "thirteen",
|
||||
"fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
|
||||
"nineteen", "twenty", 30 => "thirty", 40 => "forty",
|
||||
50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eighty",
|
||||
90 => "ninety" );
|
||||
|
||||
if(!is_numeric($x))
|
||||
{
|
||||
$w = $x;
|
||||
}
|
||||
elseif(fmod($x, 1) != 0)
|
||||
{
|
||||
$w = $x;
|
||||
}
|
||||
else
|
||||
{
|
||||
if($x < 0)
|
||||
{
|
||||
$w = 'minus ';
|
||||
$x = -$x;
|
||||
}
|
||||
else
|
||||
{
|
||||
$w = '';
|
||||
// ... now $x is a non-negative integer.
|
||||
}
|
||||
|
||||
if($x < 21) // 0 to 20
|
||||
{
|
||||
$w .= $nwords[$x];
|
||||
}
|
||||
elseif($x < 100) // 21 to 99
|
||||
{
|
||||
$w .= $nwords[10 * floor($x/10)];
|
||||
$r = fmod($x, 10);
|
||||
if($r > 0)
|
||||
{
|
||||
$w .= ' ' . $nwords[$r];
|
||||
}
|
||||
}
|
||||
elseif($x < 1000) // 100 to 999
|
||||
{
|
||||
$w .= $nwords[floor($x/100)] .' hundred';
|
||||
$r = fmod($x, 100);
|
||||
if($r > 0)
|
||||
{
|
||||
$w .= ' and '. self::number($r);
|
||||
}
|
||||
}
|
||||
elseif($x < 1000000) // 1000 to 999999
|
||||
{
|
||||
$w .= self::number(floor($x/1000)) .' thousand';
|
||||
$r = fmod($x, 1000);
|
||||
if($r > 0)
|
||||
{
|
||||
$w .= ' ';
|
||||
if($r < 100)
|
||||
{
|
||||
$w .= 'and ';
|
||||
}
|
||||
$w .= self::number($r);
|
||||
}
|
||||
}
|
||||
else // millions
|
||||
{
|
||||
$w .= self::number(floor($x/1000000)) .' million';
|
||||
$r = fmod($x, 1000000);
|
||||
if($r > 0)
|
||||
{
|
||||
$w .= ' ';
|
||||
if($r < 100)
|
||||
{
|
||||
$w .= 'and ';
|
||||
}
|
||||
$w .= self::number($r);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Random Key
|
||||
*
|
||||
* @input int $size The size of the random string
|
||||
*
|
||||
* @returns a string
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function random(int $size): string
|
||||
{
|
||||
$bag = "abcefghijknopqrstuwxyzABCDDEFGHIJKLLMMNOPQRSTUVVWXYZabcddefghijkllmmnopqrstuvvwxyzABCEFGHIJKNOPQRSTUWXYZ";
|
||||
$key = [];
|
||||
$bagsize = strlen($bag) - 1;
|
||||
|
||||
for ($i = 0; $i < $size; $i++)
|
||||
{
|
||||
$get = rand(0, $bagsize);
|
||||
$key[] = $bag[$get];
|
||||
}
|
||||
|
||||
return implode($key);
|
||||
}
|
||||
|
||||
}
|
||||
|
1
libraries/vendor_jcb/VDM.Joomla/src/Utilities/index.html
Normal file
1
libraries/vendor_jcb/VDM.Joomla/src/Utilities/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
Reference in New Issue
Block a user