New Helper Classes and other bug fixes #887

Merged
Llewellyn merged 12 commits from staging into master 2022-04-04 16:42:57 +00:00
20 changed files with 824 additions and 793 deletions
Showing only changes of commit ec827b7369 - Show all commits

View File

@ -143,13 +143,13 @@ 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*: 10th March, 2022
+ *Last Build*: 12th March, 2022
+ *Version*: 2.12.15
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **286315**
+ *Line count*: **286346**
+ *Field count*: **1580**
+ *File count*: **1848**
+ *File count*: **1850**
+ *Folder count*: **260**
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com).

View File

@ -143,13 +143,13 @@ 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*: 10th March, 2022
+ *Last Build*: 12th March, 2022
+ *Version*: 2.12.15
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **286315**
+ *Line count*: **286346**
+ *Field count*: **1580**
+ *File count*: **1848**
+ *File count*: **1850**
+ *Folder count*: **260**
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com).

View File

@ -29059,7 +29059,7 @@ function vdm_dkim() {
if (strpos($power->description, '/*') === false)
{
// make this description escaped
$power->description = '/**' . PHP_EOL . ' * ' . implode(' * ', explode(PHP_EOL, $power->description)) . PHP_EOL . ' */';
$power->description = '/**' . PHP_EOL . ' * ' . implode(PHP_EOL . ' * ', explode(PHP_EOL, $power->description)) . PHP_EOL . ' */';
}
$code[] = PHP_EOL . $power->description;
}

View File

@ -2170,172 +2170,6 @@ abstract class ComponentbuilderHelper
return $default;
}
/**
* 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
*/
public static function GUID ($trim = true)
{
// Windows
if (function_exists('com_create_guid') === true)
{
if ($trim === true)
{
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') === true)
{
$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 $table
* @param int $id
* @return bool
*/
public static function validGUID ($guid, $table = null, $id = 0)
{
// check if we have a string
if (self::validateGUID($guid))
{
// check if table already has this identifier
if (self::checkString($table))
{
// Get the database object and a new query object.
$db = \JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT(*)')
->from('#__componentbuilder_' . (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 of a GUID by table
*
* @param string $guid
* @param string $table
* @param string/array $what
*
* @return mix
*/
public static function getGUID ($guid, $table, $what = 'a.id')
{
// check if we have a string
if (self::validateGUID($guid))
{
// check if table already has this identifier
if (self::checkString($table))
{
// Get the database object and a new query object.
$db = \JFactory::getDbo();
$query = $db->getQuery(true);
if (self::checkArray($what))
{
$query->select($db->quoteName($what));
}
else
{
$query->select($what);
}
$query->from($db->quoteName('#__componentbuilder_' . (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 (self::checkArray($what) || $what === 'a.*')
{
return $db->loadObject();
}
else
{
return $db->loadResult();
}
}
}
}
return false;
}
/**
* Validate the Globally Unique Identifier
*
* Thanks to Lewie
* https://stackoverflow.com/a/1515456/1429677
*
* @param string $guid
* @return bool
*/
protected static function validateGUID ($guid)
{
// check if we have a string
if (self::checkString($guid))
{
return preg_match("/^(\{)?[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}(?(1)\})$/i", $guid);
}
return false;
}
/**
* Tab/spacer bucket (to speed-up the build)
*
@ -2694,91 +2528,6 @@ abstract class ComponentbuilderHelper
}
/**
* The zipper method
*
* @param string $workingDIR 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
*
*/
public static function zip($workingDIR, &$filepath)
{
// store the current joomla working directory
$joomla = getcwd();
// we are changing the working directory to the component temp folder
chdir($workingDIR);
// 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 = array();
// setup the zip array
foreach ($files as $file)
{
$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
$adapter = new Archive();
$zip = $adapter->getAdapter('zip');
//create the zip file
if ($zip->create($filepath, $zipArray))
{
return true;
}
return false;
}
/**
* 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
*
*/
public static function writeFile($path, $data)
{
$klaar = false;
if (self::checkString($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;
}
/**
* Remove folders with files
*
@ -3807,70 +3556,6 @@ abstract class ComponentbuilderHelper
return false;
}
/**
* get between
*
* @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
*
*/
public static function getBetween($content, $start, $end, $default = '')
{
$r = explode($start, $content);
if (isset($r[1]))
{
$r = explode($end, $r[1]);
return $r[0];
}
return $default;
}
/**
* get all between
*
* @param string $content The content to search
* @param string $start The starting value
* @param string $end The ending value
*
* @return array On success
*
*/
public static function getAllBetween($content, $start, $end)
{
// reset bucket
$bucket = array();
for ($i = 0; ; $i++)
{
// search for string
$found = self::getBetween($content,$start,$end);
if (self::checkString($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
return array_unique($bucket);
}
/**
* Field Grouping https://docs.joomla.org/Form_field
**/
@ -4223,59 +3908,6 @@ abstract class ComponentbuilderHelper
}
/**
* get the content of a file
*
* @param string $path The path to the file
* @param string/bool $none The return value if no content was found
*
* @return string On success
*
*/
public static function getFileContents($path, $none = '')
{
if (self::checkString($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 = array();
$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 (self::checkString($content))
{
return $content;
}
}
elseif (property_exists('ComponentbuilderHelper', 'curlErrorLoaded') && !self::$curlErrorLoaded)
{
// set the notice
JFactory::getApplication()->enqueueMessage(JText::_('COM_COMPONENTBUILDER_HTWOCURL_NOT_FOUNDHTWOPPLEASE_SETUP_CURL_ON_YOUR_SYSTEM_OR_BCOMPONENTBUILDERB_WILL_NOT_FUNCTION_CORRECTLYP'), 'Error');
// load this notice only once
self::$curlErrorLoaded = true;
}
}
return $none;
}
/**
* the Crypt objects
**/

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="4" method="upgrade">
<name>COM_COMPONENTBUILDER</name>
<creationDate>10th March, 2022</creationDate>
<creationDate>12th March, 2022</creationDate>
<author>Llewellyn van der Merwe</author>
<authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail>
<authorUrl>http://www.joomlacomponentbuilder.com</authorUrl>

View File

@ -19,6 +19,8 @@ use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Utilities\MathHelper;
use VDM\Joomla\Utilities\GetHelper;
use VDM\Joomla\Utilities\GuidHelper;
use VDM\Joomla\Utilities\FileHelper;
use VDM\Joomla\Utilities\String\FieldHelper;
use VDM\Joomla\Utilities\String\TypeHelper;
use VDM\Joomla\Utilities\String\ClassfunctionHelper;
@ -27,7 +29,9 @@ use VDM\Joomla\Utilities\String\PluginHelper;
/**
* Basic shared utilities, a legacy implementation
* Basic shared utilities, a legacy implementation
*
* @since 3.0.9
*/
trait Utilities
{
@ -35,6 +39,8 @@ trait Utilities
* The Main Active Language
*
* @var string
*
* @since 3.0.9
*/
public static $langTag;
@ -44,6 +50,8 @@ trait Utilities
* @input string $string The string to check
*
* @returns bool true on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use StringHelper::check($string);
*/
@ -58,6 +66,8 @@ trait Utilities
* @input string $string That you would like to shorten
*
* @returns string on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use StringHelper::shorten($string, $length, $addTip);
*/
@ -72,6 +82,8 @@ trait Utilities
* @input string $string That you would like to make safe
*
* @returns string on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use StringHelper::safe($string, $type, $spacer, $replaceNumbers, $keepOnlyCharacters);
*/
@ -86,6 +98,8 @@ trait Utilities
* @input string The name you would like to make safe
*
* @returns string on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use ClassfunctionHelper::safe($name);
*/
@ -102,6 +116,8 @@ trait Utilities
* @input string The string to use in white space
*
* @returns string on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use FieldHelper::safe($string, $allcap, $spacer);
*/
@ -116,6 +132,8 @@ trait Utilities
* @input string The you would like to make safe
*
* @returns string on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use TypeHelper::safe($string);
*/
@ -130,6 +148,8 @@ trait Utilities
* @input string The you would like to make safe
*
* @returns string on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use NamespaceHelper::safe($string);
*/
@ -139,6 +159,8 @@ trait Utilities
}
/**
* @since 3.0.9
*
* @deprecated 4.0 - Use StringHelper::transliterate($string);
*/
public static function transliterate($string)
@ -147,6 +169,8 @@ trait Utilities
}
/**
* @since 3.0.9
*
* @deprecated 4.0 - Use StringHelper::html($var, $charset, $shorten, $length);
*/
public static function htmlEscape($var, $charset = 'UTF-8', $shorten = false, $length = 40)
@ -155,6 +179,8 @@ trait Utilities
}
/**
* @since 3.0.9
*
* @deprecated 4.0 - Use StringHelper::numbers($string);
*/
public static function replaceNumbers($string)
@ -169,6 +195,8 @@ trait Utilities
* @input int $x an int
*
* @returns string a string
*
* @since 3.0.9
*
* @deprecated 4.0 - Use StringHelper::number($x);
*/
@ -183,6 +211,8 @@ trait Utilities
* @input int $size the length of the string
*
* @returns string a string of random characters
*
* @since 3.0.9
*
* @deprecated 4.0 - Use StringHelper::random($size);
*/
@ -197,6 +227,8 @@ trait Utilities
* @input string $string The json string to check
*
* @returns bool true on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use JsonHelper::check($string);
*/
@ -206,6 +238,8 @@ trait Utilities
}
/**
* @since 3.0.9
*
* @deprecated 4.0 - Use JsonHelper::string($value, $sperator, $table, $id, $name);
*/
public static function jsonToString($value, $sperator = ", ", $table = null, $id = 'id', $name = 'name')
@ -220,6 +254,8 @@ trait Utilities
* @input bool $removeEmptyString Should we remove empty values
*
* @returns int number of items in array on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use ArrayHelper::check($array, $removeEmptyString);
*/
@ -234,6 +270,8 @@ trait Utilities
* @input mixed $arrays The arrays you would like to merge
*
* @returns mixed array on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use ArrayHelper::merge($arrays);
*/
@ -248,6 +286,8 @@ trait Utilities
* @input object $object The object to check
*
* @returns bool true on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use ObjectHelper::check($object);
*/
@ -267,6 +307,8 @@ trait Utilities
* @param string $main The component in which the table is found
*
* @return mix string/int/float
*
* @since 3.0.9
*
* @deprecated 4.0 - Use GetHelper::var($table, $where, $whereString, $what, $operator, $main);
*/
@ -287,6 +329,8 @@ trait Utilities
* @param bool $unique The switch to return a unique array
*
* @return array
*
* @since 3.0.9
*
* @deprecated 4.0 - Use GetHelper::vars($table, $where, $whereString, $what, $operator, $main, $unique);
*/
@ -295,6 +339,43 @@ trait Utilities
return GetHelper::vars($table, $where, $whereString, $what, $operator, $main, $unique);
}
/**
* 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 On success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use GetHelper::allBetween($content, $start, $end);
*/
public static function getAllBetween($content, $start, $end)
{
return GetHelper::allBetween($content, $start, $end);
}
/**
* 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
*
* @deprecated 4.0 - Use GetHelper::between($content, $start, $end, $default);
*/
public static function getBetween($content, $start, $end, $default = '')
{
return GetHelper::between($content, $start, $end, $default);
}
/**
* bc math wrapper (very basic not for accounting)
*
@ -303,7 +384,9 @@ trait Utilities
* @param int $val2 The second value
* @param int $scale The scale value
*
* @return int
* @return float|int
*
* @since 3.0.9
*
* @deprecated 4.0 - Use MathHelper::bc($type, $val1, $val2, $scale);
*/
@ -318,7 +401,9 @@ trait Utilities
* @param array $array The values to sum
* @param int $scale The scale value
*
* @return float
* @return float|int
*
* @since 3.0.9
*
* @deprecated 4.0 - Use MathHelper::sum($array, $scale);
*/
@ -333,7 +418,9 @@ trait Utilities
* @input string The group name
* @input string The name
*
* @return float
* @return string
*
* @since 3.0.9
*
* @deprecated 4.0 - Use PluginHelper::safe($name, $group);
*/
@ -341,6 +428,133 @@ trait Utilities
{
return PluginHelper::safeClassName($name, $group);
}
/**
* 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
*
* @deprecated 4.0 - Use GuidHelper::get($trim);
*/
public static function GUID($trim = true)
{
return GuidHelper::get($trim);
}
/**
* Validate the Globally Unique Identifier ( and check if table already has this identifier)
*
* @param string $guid
* @param string $table
* @param int $id
*
* @return bool
*
* @since 3.0.9
*
* @deprecated 4.0 - Use GuidHelper::valid($guid, $table, $id);
*/
public static function validGUID($guid, $table = null, $id = 0)
{
return GuidHelper::valid($guid, $table, $id);
}
/**
* get the ITEM of a GUID by table
*
* @param string $guid
* @param string $table
* @param string/array $what
*
* @return mix
*
* @since 3.0.9
*
* @deprecated 4.0 - Use GuidHelper::valid($guid, $table, $id);
*/
public static function getGUID($guid, $table, $what = 'a.id')
{
return GuidHelper::item($guid, $table, $what);
}
/**
* Validate the Globally Unique Identifier
*
* Thanks to Lewie
* https://stackoverflow.com/a/1515456/1429677
*
* @param string $guid
*
* @return bool
*
* @deprecated 4.0 - Use GuidHelper::validate($guid);
*/
protected static function validateGUID($guid)
{
return GuidHelper::validate($guid);
}
/**
* The zipper method
*
* @param string $workingDIR 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
*
* @deprecated 4.0 - Use FileHelper::zip($workingDIR, $filepath);
*/
public static function zip($workingDIR, &$filepath)
{
return FileHelper::zip($workingDIR, $filepath);
}
/**
* get the content of a file
*
* @param string $path The path to the file
* @param string/bool $none The return value if no content was found
*
* @return string On success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use FileHelper::getContent($path, $none);
*/
public static function getFileContents($path, $none = '')
{
return FileHelper::getContent($path, $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
*
* @deprecated 4.0 - Use FileHelper::write($path, $data);
*/
public static function writeFile($path, $data)
{
return FileHelper::write($path, $data);
}
}

View File

@ -14,7 +14,9 @@ namespace VDM\Joomla\Utilities;
/**
* Some array tricks helper
* Some array tricks helper
*
* @since 3.0.9
*/
abstract class ArrayHelper
{
@ -24,6 +26,8 @@ abstract class ArrayHelper
* @input array The array to check
*
* @returns bool/int number of items in array on success
*
* @since 3.0.9
*/
public static function check($array, $removeEmptyString = false)
{
@ -52,6 +56,8 @@ abstract class ArrayHelper
* @input array The arrays you would like to merge
*
* @returns array on success
*
* @since 3.0.9
*/
public static function merge($arrays)
{

View File

@ -0,0 +1,181 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @github Joomla Component Builder <https://github.com/vdm-io/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 Joomla\CMS\Language\Text;
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Filesystem\Folder;
use Joomla\Archive\Archive;
/**
* 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)
{
// 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 = array();
// setup the zip array
foreach ($files as $file)
{
$tmp = array();
$tmp['name'] = str_replace('./', '', $file);
$tmp['data'] = self::getContent($file);
$tmp['time'] = filemtime($file);
$zipArray[] = $tmp;
}
// change back to joomla working directory
chdir($joomla);
// get the zip adapter
$adapter = new Archive();
$zip = $adapter->getAdapter('zip');
//create the zip file
if ($zip->create($filepath, $zipArray))
{
return true;
}
return false;
}
/**
* get the content of a file
*
* @param string $path The path to the file
* @param string/bool $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 = array();
$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(Text::_('COM_COMPONENTBUILDER_HTWOCURL_NOT_FOUNDHTWOPPLEASE_SETUP_CURL_ON_YOUR_SYSTEM_OR_BCOMPONENTBUILDERB_WILL_NOT_FUNCTION_CORRECTLYP'), '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)
{
$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;
}
}

View File

@ -17,7 +17,9 @@ use Joomla\CMS\Factory;
/**
* Some easy get...
* Some easy get...
*
* @since 3.0.9
*/
abstract class GetHelper
{
@ -32,7 +34,8 @@ abstract class GetHelper
* @param string $main The component in which the table is found
*
* @return mix string/int/float
*
*
* @since 3.0.9
*/
public static function var($table, $where = null, $whereString = 'user', $what = 'id', $operator = '=', $main = 'componentbuilder')
{
@ -92,7 +95,8 @@ abstract class GetHelper
* @param bool $unique The switch to return a unique array
*
* @return array
*
*
* @since 3.0.9
*/
public static function vars($table, $where = null, $whereString = 'user', $what = 'id', $operator = 'IN', $main = 'componentbuilder', $unique = true)
{
@ -154,6 +158,71 @@ abstract class GetHelper
}
return false;
}
/**
* 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 On success
*
* @since 3.0.9
*/
public static function allBetween($content, $start, $end)
{
// reset bucket
$bucket = array();
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
return array_unique($bucket);
}
/**
* 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($content, $start, $end, $default = '')
{
$r = explode($start, $content);
if (isset($r[1]))
{
$r = explode($end, $r[1]);
return $r[0];
}
return $default;
}
}

View File

@ -0,0 +1,205 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @github Joomla Component Builder <https://github.com/vdm-io/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;
/**
* 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($trim = true)
{
// Windows
if (function_exists('com_create_guid') === true)
{
if ($trim === true)
{
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') === true)
{
$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 $table
* @param int $id
*
* @return bool
*
* @since 3.0.9
*/
public static function valid($guid, $table = null, $id = 0)
{
// check if we have a string
if (self::validate($guid))
{
// check if table already has this identifier
if (StringHelper::check($table))
{
// Get the database object and a new query object.
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT(*)')
->from('#__componentbuilder_' . (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
*
* @return mix
*
* @since 3.0.9
*/
public static function item($guid, $table, $what = 'a.id')
{
// check if we have a string
if (self::validate($guid))
{
// check if table already has this identifier
if (StringHelper::check($table))
{
// 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('#__componentbuilder_' . (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 false;
}
/**
* 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;
}
}

View File

@ -14,7 +14,9 @@ namespace VDM\Joomla\Utilities;
/**
* The json checker
* The json checker
*
* @since 3.0.9
*/
abstract class JsonHelper
{
@ -24,6 +26,8 @@ abstract class JsonHelper
* @input string $string The json string to check
*
* @returns bool true on success
*
* @since 3.0.9
*/
public static function check($string): bool
{
@ -36,6 +40,15 @@ abstract class JsonHelper
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

View File

@ -14,7 +14,9 @@ namespace VDM\Joomla\Utilities;
/**
* Basic Math Helper
* Basic Math Helper
*
* @since 3.0.9
*/
abstract class MathHelper
{
@ -27,7 +29,8 @@ abstract class MathHelper
* @param int $scale The scale value
*
* @return int
*
*
* @since 3.0.9
*/
public static function bc($type, $val1, $val2, $scale = 0)
{
@ -76,7 +79,8 @@ abstract class MathHelper
* @param int $scale The scale value
*
* @return float
*
*
* @since 3.0.9
*/
public static function sum($array, $scale = 4)
{

View File

@ -14,7 +14,9 @@ namespace VDM\Joomla\Utilities;
/**
* Some object tricks
* Some object tricks
*
* @since 3.0.9
*/
abstract class ObjectHelper
{
@ -24,6 +26,8 @@ abstract class ObjectHelper
* @input object The object to check
*
* @returns bool true on success
*
* @since 3.0.9
*/
public static function check($object)
{

View File

@ -17,17 +17,21 @@ use VDM\Joomla\Utilities\StringHelper;
/**
* Control the naming of a class and function
* 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
**/
* 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)
{
// remove numbers if the first character is a number

View File

@ -18,24 +18,30 @@ use VDM\Joomla\Utilities\StringHelper;
/**
* Control the naming of a field
* Control the naming of a field
*
* @since 3.0.9
*/
abstract class FieldHelper
{
/**
* The field builder switch
**/
* 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
**/
* 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

View File

@ -17,17 +17,21 @@ use VDM\Joomla\Utilities\StringHelper;
/**
* Control the naming of a namespace helper
* Control the naming of a namespace helper
*
* @since 3.0.9
*/
abstract class NamespaceHelper
{
/**
* Making namespace safe
*
* @input string The you would like to make safe
*
* @returns string on success
**/
* Making namespace safe
*
* @input string The you would like to make safe
*
* @returns string on success
*
* @since 3.0.9
*/
public static function safe($string)
{
// 0nly continue if we have a string

View File

@ -14,7 +14,9 @@ namespace VDM\Joomla\Utilities\String;
/**
* Control the naming of a plugin
* Control the naming of a plugin
*
* @since 3.0.9
*/
abstract class PluginHelper
{
@ -25,6 +27,8 @@ abstract class PluginHelper
* @input string $group The group name
*
* @returns string on success
*
* @since 3.0.9
*/
public static function safeFolderName($codeName, $group)
{
@ -46,6 +50,8 @@ abstract class PluginHelper
* @input string $group The group name
*
* @returns string on success
*
* @since 3.0.9
*/
public static function safeClassName($codeName, $group)
{
@ -67,6 +73,8 @@ abstract class PluginHelper
* @input string $group The group name
*
* @returns string on success
*
* @since 3.0.9
*/
public static function safeInstallClassName($codeName, $group)
{
@ -88,6 +96,8 @@ abstract class PluginHelper
* @input string $group The group name
*
* @returns string on success
*
* @since 3.0.9
*/
public static function safeLangPrefix($codeName, $group)
{

View File

@ -18,22 +18,28 @@ use VDM\Joomla\Utilities\StringHelper;
/**
* Control the naming of a field type
* Control the naming of a field type
*
* @since 3.0.9
*/
abstract class TypeHelper
{
/**
* The field builder switch
**/
* The field builder switch
*
* @since 3.0.9
*/
protected static $builder = false;
/**
* Making field type name safe
*
* @input string The you would like to make safe
*
* @returns string on success
**/
* Making field type name safe
*
* @input string The you would like to make safe
*
* @returns string on success
*
* @since 3.0.9
*/
public static function safe($string)
{
// get global value

View File

@ -19,7 +19,9 @@ use Joomla\CMS\Component\ComponentHelper;
/**
* Some string tricks
* Some string tricks
*
* @since 3.0.9
*/
abstract class StringHelper
{
@ -27,6 +29,8 @@ abstract class StringHelper
* The Main Active Language
*
* @var string
*
* @since 3.0.9
*/
public static $langTag;
@ -36,6 +40,8 @@ abstract class StringHelper
* @input string $string The string to check
*
* @returns bool true on success
*
* @since 3.0.9
*/
public static function check($string): bool
{
@ -53,6 +59,8 @@ abstract class StringHelper
* @input string The you would like to shorten
*
* @returns string on success
*
* @since 3.0.9
*/
public static function shorten($string, $length = 40, $addTip = true)
{
@ -94,6 +102,8 @@ abstract class StringHelper
* @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)
{
@ -195,6 +205,15 @@ abstract class StringHelper
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
@ -210,6 +229,15 @@ abstract class StringHelper
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)
{
if (self::check($var))
@ -237,6 +265,15 @@ abstract class StringHelper
}
}
/**
* 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
@ -270,6 +307,8 @@ abstract class StringHelper
*
* @input an int
* @returns a string
*
* @since 3.0.9
*/
public static function number($x)
{
@ -359,6 +398,8 @@ abstract class StringHelper
* Random Key
*
* @returns a string
*
* @since 3.0.9
*/
public static function random($size)
{

View File

@ -2167,172 +2167,6 @@ abstract class ComponentbuilderHelper
return $default;
}
/**
* 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
*/
public static function GUID ($trim = true)
{
// Windows
if (function_exists('com_create_guid') === true)
{
if ($trim === true)
{
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') === true)
{
$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 $table
* @param int $id
* @return bool
*/
public static function validGUID ($guid, $table = null, $id = 0)
{
// check if we have a string
if (self::validateGUID($guid))
{
// check if table already has this identifier
if (self::checkString($table))
{
// Get the database object and a new query object.
$db = \JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT(*)')
->from('#__componentbuilder_' . (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 of a GUID by table
*
* @param string $guid
* @param string $table
* @param string/array $what
*
* @return mix
*/
public static function getGUID ($guid, $table, $what = 'a.id')
{
// check if we have a string
if (self::validateGUID($guid))
{
// check if table already has this identifier
if (self::checkString($table))
{
// Get the database object and a new query object.
$db = \JFactory::getDbo();
$query = $db->getQuery(true);
if (self::checkArray($what))
{
$query->select($db->quoteName($what));
}
else
{
$query->select($what);
}
$query->from($db->quoteName('#__componentbuilder_' . (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 (self::checkArray($what) || $what === 'a.*')
{
return $db->loadObject();
}
else
{
return $db->loadResult();
}
}
}
}
return false;
}
/**
* Validate the Globally Unique Identifier
*
* Thanks to Lewie
* https://stackoverflow.com/a/1515456/1429677
*
* @param string $guid
* @return bool
*/
protected static function validateGUID ($guid)
{
// check if we have a string
if (self::checkString($guid))
{
return preg_match("/^(\{)?[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}(?(1)\})$/i", $guid);
}
return false;
}
/**
* Tab/spacer bucket (to speed-up the build)
*
@ -2691,91 +2525,6 @@ abstract class ComponentbuilderHelper
}
/**
* The zipper method
*
* @param string $workingDIR 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
*
*/
public static function zip($workingDIR, &$filepath)
{
// store the current joomla working directory
$joomla = getcwd();
// we are changing the working directory to the component temp folder
chdir($workingDIR);
// 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 = array();
// setup the zip array
foreach ($files as $file)
{
$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
$adapter = new Archive();
$zip = $adapter->getAdapter('zip');
//create the zip file
if ($zip->create($filepath, $zipArray))
{
return true;
}
return false;
}
/**
* 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
*
*/
public static function writeFile($path, $data)
{
$klaar = false;
if (self::checkString($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;
}
/**
* Remove folders with files
*
@ -3804,70 +3553,6 @@ abstract class ComponentbuilderHelper
return false;
}
/**
* get between
*
* @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
*
*/
public static function getBetween($content, $start, $end, $default = '')
{
$r = explode($start, $content);
if (isset($r[1]))
{
$r = explode($end, $r[1]);
return $r[0];
}
return $default;
}
/**
* get all between
*
* @param string $content The content to search
* @param string $start The starting value
* @param string $end The ending value
*
* @return array On success
*
*/
public static function getAllBetween($content, $start, $end)
{
// reset bucket
$bucket = array();
for ($i = 0; ; $i++)
{
// search for string
$found = self::getBetween($content,$start,$end);
if (self::checkString($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
return array_unique($bucket);
}
/**
* Field Grouping https://docs.joomla.org/Form_field
**/
@ -4220,59 +3905,6 @@ abstract class ComponentbuilderHelper
}
/**
* get the content of a file
*
* @param string $path The path to the file
* @param string/bool $none The return value if no content was found
*
* @return string On success
*
*/
public static function getFileContents($path, $none = '')
{
if (self::checkString($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 = array();
$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 (self::checkString($content))
{
return $content;
}
}
elseif (property_exists('ComponentbuilderHelper', 'curlErrorLoaded') && !self::$curlErrorLoaded)
{
// set the notice
JFactory::getApplication()->enqueueMessage(JText::_('COM_COMPONENTBUILDER_HTWOCURL_NOT_FOUNDHTWOPPLEASE_SETUP_CURL_ON_YOUR_SYSTEM_OR_BCOMPONENTBUILDERB_WILL_NOT_FUNCTION_CORRECTLYP'), 'Error');
// load this notice only once
self::$curlErrorLoaded = true;
}
}
return $none;
}
/**
* the Crypt objects
**/