first commit

This commit is contained in:
Llewellyn van der Merwe 2023-03-22 00:43:11 +02:00
commit a68612f656
Signed by: Llewellyn
GPG Key ID: A9201372263741E7
32 changed files with 4111 additions and 0 deletions

212
README.md Normal file
View File

@ -0,0 +1,212 @@
```
███████╗██╗ ██╗██████╗ ███████╗██████╗
██╔════╝██║ ██║██╔══██╗██╔════╝██╔══██╗
███████╗██║ ██║██████╔╝█████╗ ██████╔╝
╚════██║██║ ██║██╔═══╝ ██╔══╝ ██╔══██╗
███████║╚██████╔╝██║ ███████╗██║ ██║
╚══════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝
██████╗ ██████╗ ██╗ ██╗███████╗██████╗ ███████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗██╔════╝
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝███████╗
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗╚════██║
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║███████║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝╚══════╝
```
### What is JCB Super Powers?
The Joomla Component Builder (JCB) Super Power features are designed to enhance JCB's functionality and streamline the development process. These Super Powers enable developers to efficiently manage and share their custom powers across multiple JCB instances through repositories hosted on [https://git.vdm.dev/[username]/[repository-name]](https://git.vdm.dev). JCB Super Powers are managed using a combination of layers, events, tasks, methods, switches, and algorithms, which work together to provide powerful customization and extensibility options. More details on JCB Super Powers can be found in the [Super Powers Documentation](https://git.vdm.dev/joomla/super-powers/wiki).
In summary, JCB Super Powers offer a flexible and efficient way to manage and share functionalities between JCB instances. By utilizing a sophisticated system of layers, events, tasks, methods, switches, and algorithms, developers can seamlessly integrate JCB core powers and their custom powers. For more information on how to work with JCB Super Powers, refer to the [Super Powers User Guide](https://git.vdm.dev/joomla/super-powers/wiki).
### What can I find here?
This repository contains an index (see below) of all the approved powers within the JCB GUI. During the compilation of a component, these powers are automatically added to the repository, ensuring a well-organized and accessible collection of functionalities.
# Index of powers
- **Namespace**: [VDM\Joomla](#vdm-joomla)
- **trait Utilities** | [Details](src/79d765b3-7319-4988-9730-446c7f347020) | [Code](src/79d765b3-7319-4988-9730-446c7f347020/code.php) | [Settings](src/79d765b3-7319-4988-9730-446c7f347020/settings.json) | [79d765b3-7319-4988-9730-446c7f347020](src/79d765b3-7319-4988-9730-446c7f347020)
- **Namespace**: [VDM\Joomla\Utilities](#vdm-joomla-utilities)
- **abstract class ArrayHelper** | [Details](src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a) | [Code](src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a/code.php) | [Settings](src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a/settings.json) | [0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a](src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a)
- **abstract class FileHelper** | [Details](src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0) | [Code](src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0/code.php) | [Settings](src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0/settings.json) | [a223b31e-ea1d-4cdf-92ae-5f9becffaff0](src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0)
- **abstract class GetHelper** | [Details](src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc) | [Code](src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc/code.php) | [Settings](src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc/settings.json) | [db87c339-5bb6-4291-a7ef-2c48ea1b06bc](src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc)
- **abstract class GuidHelper** | [Details](src/9c513baf-b279-43fd-ae29-a585c8cbc4f0) | [Code](src/9c513baf-b279-43fd-ae29-a585c8cbc4f0/code.php) | [Settings](src/9c513baf-b279-43fd-ae29-a585c8cbc4f0/settings.json) | [9c513baf-b279-43fd-ae29-a585c8cbc4f0](src/9c513baf-b279-43fd-ae29-a585c8cbc4f0)
- **abstract class JsonHelper** | [Details](src/4b225c51-d293-48e4-b3f6-5136cf5c3f18) | [Code](src/4b225c51-d293-48e4-b3f6-5136cf5c3f18/code.php) | [Settings](src/4b225c51-d293-48e4-b3f6-5136cf5c3f18/settings.json) | [4b225c51-d293-48e4-b3f6-5136cf5c3f18](src/4b225c51-d293-48e4-b3f6-5136cf5c3f18)
- **abstract class MathHelper** | [Details](src/152c8793-8b75-4715-996a-257b9f65451c) | [Code](src/152c8793-8b75-4715-996a-257b9f65451c/code.php) | [Settings](src/152c8793-8b75-4715-996a-257b9f65451c/settings.json) | [152c8793-8b75-4715-996a-257b9f65451c](src/152c8793-8b75-4715-996a-257b9f65451c)
- **abstract class ObjectHelper** | [Details](src/91004529-94a9-4590-b842-e7c6b624ecf5) | [Code](src/91004529-94a9-4590-b842-e7c6b624ecf5/code.php) | [Settings](src/91004529-94a9-4590-b842-e7c6b624ecf5/settings.json) | [91004529-94a9-4590-b842-e7c6b624ecf5](src/91004529-94a9-4590-b842-e7c6b624ecf5)
- **abstract class StringHelper** | [Details](src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef) | [Code](src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/code.php) | [Settings](src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/settings.json) | [1f28cb53-60d9-4db1-b517-3c7dc6b429ef](src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef)
- **Namespace**: [VDM\Joomla\Utilities\Component](#vdm-joomla-utilities-component)
- **abstract class Helper** | [Details](src/640b5352-fb09-425f-a26e-cd44eda03f15) | [Code](src/640b5352-fb09-425f-a26e-cd44eda03f15/code.php) | [Settings](src/640b5352-fb09-425f-a26e-cd44eda03f15/settings.json) | [640b5352-fb09-425f-a26e-cd44eda03f15](src/640b5352-fb09-425f-a26e-cd44eda03f15)
# Class Diagrams
## VDM Joomla
> namespace VDM\Joomla
```uml
@startuml
namespace VDM\Joomla #Azure {
class Utilities << (T,Orange) >> #Turquoise {
+ static $langTag
+ {static} checkString() : bool
+ {static} shorten()
+ {static} safeString()
+ {static} safeClassFunctionName()
+ {static} safeFieldName()
+ {static} safeTypeName()
+ {static} safeNamespace()
+ {static} transliterate()
+ {static} htmlEscape()
+ {static} replaceNumbers()
+ {static} numberToString()
+ {static} randomkey() : string
+ {static} checkJson() : bool
+ {static} jsonToString()
+ {static} checkArray() : int
+ {static} mergeArrays()
+ {static} checkObject() : bool
+ {static} getVar() : mix
+ {static} getVars() : array
+ {static} getAllBetween() : array
+ {static} getBetween() : string
+ {static} bcmath() : float|int
+ {static} bcsum() : float|int
+ {static} createPluginClassName() : string
+ {static} GUID() : string
+ {static} validGUID() : bool
+ {static} getGUID() : mix
# {static} validateGUID() : bool
+ {static} zip() : bool
+ {static} getFileContents() : string
+ {static} writeFile() : bool
+ {static} getAllFilePaths() : void
+ {static} getFilePath() : string
+ {static} urlExists() : bool
+ {static} setComponentOption()
}
}
@enduml
```
## VDM Joomla Utilities
> namespace VDM\Joomla\Utilities
```uml
@startuml
namespace VDM\Joomla\Utilities #DarkCyan {
abstract ArrayHelper #Orange {
+ {static} check()
+ {static} merge() : ?array
+ {static} intersect() : bool
}
abstract FileHelper #Orange {
# static $curlError
+ {static} zip() : bool
+ {static} getContent() : string
+ {static} write() : bool
+ {static} getPaths() : void
+ {static} getPath() : string
+ {static} exists() : bool
}
abstract GetHelper #Orange {
+ {static} var() : mixed
+ {static} vars() : ?array
+ {static} allBetween() : ?array
+ {static} between() : string
}
abstract GuidHelper #Orange {
+ {static} get() : string
+ {static} valid() : bool
+ {static} item() : mix
# {static} validate() : bool
}
abstract JsonHelper #Orange {
+ {static} check() : bool
+ {static} string()
}
abstract MathHelper #Orange {
+ {static} bc() : int
+ {static} sum() : float
}
abstract ObjectHelper #Orange {
+ {static} check()
+ {static} equal() : bool
}
abstract StringHelper #Orange {
+ static $langTag
+ {static} check() : bool
+ {static} shorten()
+ {static} safe()
+ {static} transliterate()
+ {static} html()
+ {static} numbers()
+ {static} number()
+ {static} random() : string
}
}
@enduml
```
## VDM Joomla Utilities Component
> namespace VDM\Joomla\Utilities\Component
```uml
@startuml
namespace VDM\Joomla\Utilities\Component #Olive {
abstract Helper #Orange {
+ {static} getParams() : Registry
+ {static} getOption() : ?string
+ {static} getCode() : ?string
+ {static} get() : ?string
+ {static} methodExists() : bool
+ {static} _() : mixed
}
}
@enduml
```
---
```
██╗ ██████╗ ██████╗ ███╗ ███╗██╗ █████╗
██║██╔═══██╗██╔═══██╗████╗ ████║██║ ██╔══██╗
██║██║ ██║██║ ██║██╔████╔██║██║ ███████║
██ ██║██║ ██║██║ ██║██║╚██╔╝██║██║ ██╔══██║
╚█████╔╝╚██████╔╝╚██████╔╝██║ ╚═╝ ██║███████╗██║ ██║
╚════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
██████╗ ██████╗ ███╗ ███╗██████╗ ██████╗ ███╗ ██╗███████╗███╗ ██╗████████╗
██╔════╝██╔═══██╗████╗ ████║██╔══██╗██╔═══██╗████╗ ██║██╔════╝████╗ ██║╚══██╔══╝
██║ ██║ ██║██╔████╔██║██████╔╝██║ ██║██╔██╗ ██║█████╗ ██╔██╗ ██║ ██║
██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║ ██║██║╚██╗██║██╔══╝ ██║╚██╗██║ ██║
╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚██████╔╝██║ ╚████║███████╗██║ ╚████║ ██║
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝╚═╝ ╚═══╝ ╚═╝
██████╗ ██╗ ██╗██╗██╗ ██████╗ ███████╗██████╗
██╔══██╗██║ ██║██║██║ ██╔══██╗██╔════╝██╔══██╗
██████╔╝██║ ██║██║██║ ██║ ██║█████╗ ██████╔╝
██╔══██╗██║ ██║██║██║ ██║ ██║██╔══╝ ██╔══██╗
██████╔╝╚██████╔╝██║███████╗██████╔╝███████╗██║ ██║
╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚═╝ ╚═╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,52 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# abstract class ArrayHelper (Details)
> namespace: **VDM\Joomla\Utilities**
```uml
@startuml
abstract ArrayHelper #Orange {
+ {static} check($array, $removeEmptyString = false)
+ {static} merge($arrays) : ?array
+ {static} intersect($a_array, $b_array) : bool
}
note right of ArrayHelper::check
Check if have an array with a length
since: 3.2.0
end note
note right of ArrayHelper::merge
Merge an array of array's
since: 3.0.9
return: ?array
end note
note right of ArrayHelper::intersect
Check if arrays intersect
since: 3.1.1
return: bool
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View 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;
}
}

View File

@ -0,0 +1,16 @@
{
"add_head": "0",
"extends": "0",
"extends_custom": "",
"guid": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a",
"implements": null,
"implements_custom": "",
"load_selection": null,
"name": "ArrayHelper",
"power_version": "1.0.0",
"system_name": "Utilities Array Helper",
"type": "abstract class",
"use_selection": null,
"namespace": "VDM\\Joomla\\Utilities.ArrayHelper",
"description": "Some array tricks helper\r\n\r\n@since 3.0.9"
}

View File

@ -0,0 +1,51 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# abstract class MathHelper (Details)
> namespace: **VDM\Joomla\Utilities**
```uml
@startuml
abstract MathHelper #Orange {
+ {static} bc(string $type, int $val1, ...) : int
+ {static} sum(array $array, int $scale = 4) : float
}
note right of MathHelper::bc
bc math wrapper (very basic not for accounting)
since: 3.0.9
return: int
arguments:
string $type
int $val1
int $val2
int $scale
end note
note right of MathHelper::sum
Basic sum of an array with more precision
since: 3.0.9
return: float
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,103 @@
<?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 int
*
* @since 3.0.9
*/
public static function bc($type, $val1, $val2, $scale = 0)
{
// build function name
$function = 'bc' . $type;
// use the bcmath function if available
if (function_exists($function))
{
return $function($val1, $val2, $scale);
}
// if function does not exist we use +-*/ operators (fallback - not ideal)
switch ($type)
{
// Multiply two numbers
case 'mul':
return (string) round($val1 * $val2, $scale);
break;
// Divide of two numbers
case 'div':
return (string) round($val1 / $val2, $scale);
break;
// Adding two numbers
case 'add':
return (string) round($val1 + $val2, $scale);
break;
// Subtract one number from the other
case 'sub':
return (string) round($val1 - $val2, $scale);
break;
// Raise an arbitrary precision number to another
case 'pow':
return (string) round(pow($val1, $val2), $scale);
break;
// Compare two arbitrary precision numbers
case 'comp':
return (round($val1,2) == round($val2,2));
break;
}
return false;
}
/**
* 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);
}
}

View File

@ -0,0 +1,16 @@
{
"add_head": "0",
"extends": "0",
"extends_custom": "",
"guid": "152c8793-8b75-4715-996a-257b9f65451c",
"implements": null,
"implements_custom": "",
"load_selection": null,
"name": "MathHelper",
"power_version": "1.0.0",
"system_name": "Utilities Math Helper",
"type": "abstract class",
"use_selection": null,
"namespace": "VDM\\Joomla\\Utilities.MathHelper",
"description": "Basic Math Helper\r\n\r\n@since 3.0.9"
}

View File

@ -0,0 +1,108 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# abstract class StringHelper (Details)
> namespace: **VDM\Joomla\Utilities**
```uml
@startuml
abstract StringHelper #Orange {
+ static $langTag
+ {static} check($string) : bool
+ {static} shorten($string, $length = 40, ...)
+ {static} safe($string, $type = 'L', ...)
+ {static} transliterate($string)
+ {static} html($var, $charset = 'UTF-8', ...)
+ {static} numbers($string)
+ {static} number($x)
+ {static} random(int $size) : string
}
note right of StringHelper::check
Check if we have a string with a length
since: 3.0.9
return: bool
end note
note left of StringHelper::shorten
Shorten a string
since: 3.0.9
arguments:
$string
$length = 40
$addTip = true
end note
note right of StringHelper::safe
Making strings safe (various ways)
since: 3.0.9
arguments:
$string
$type = 'L'
$spacer = '_'
$replaceNumbers = true
$keepOnlyCharacters = true
end note
note left of StringHelper::transliterate
Convert none English strings to code usable string
since: 3.0.9
end note
note right of StringHelper::html
make sure a string is HTML save
since: 3.0.9
arguments:
$var
$charset = 'UTF-8'
$shorten = false
$length = 40
$addTip = true
end note
note left of StringHelper::numbers
Convert all int in a string to an English word string
since: 3.0.9
end note
note right of StringHelper::number
Convert an integer into an English word string
Thanks to Tom Nicholson <http://php.net/manual/en/function.strval.php#41988>
since: 3.0.9
end note
note left of StringHelper::random
Random Key
since: 3.0.9
return: string
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View 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 you would like to shorten
*
* @returns string on success
*
* @since 3.0.9
*/
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, null, 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);
}
}

View File

@ -0,0 +1,26 @@
{
"add_head": "1",
"extends": "0",
"extends_custom": "",
"guid": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef",
"implements": null,
"implements_custom": "",
"load_selection": {
"load_selection0": {
"load": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a"
}
},
"name": "StringHelper",
"power_version": "1.0.0",
"system_name": "Utilities String Helper",
"type": "abstract class",
"use_selection": {
"use_selection0": {
"use": "640b5352-fb09-425f-a26e-cd44eda03f15",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\Utilities.StringHelper",
"description": "Some string tricks\r\n\r\n@since 3.0.9",
"head": "use Joomla\\CMS\\Filter\\InputFilter;\r\nuse Joomla\\CMS\\Language\\Language;"
}

View File

@ -0,0 +1,51 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# abstract class JsonHelper (Details)
> namespace: **VDM\Joomla\Utilities**
```uml
@startuml
abstract JsonHelper #Orange {
+ {static} check($string) : bool
+ {static} string($value, $separator = ", ...)
}
note right of JsonHelper::check
Check if you have a json string
since: 3.0.9
return: bool
end note
note right of JsonHelper::string
Convert a json object to a string
since: 3.0.9
arguments:
$value
$separator = "
$table = null
$id = 'id'
$name = 'name'
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View 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;
}
}

View File

@ -0,0 +1,26 @@
{
"add_head": "0",
"extends": "0",
"extends_custom": "",
"guid": "4b225c51-d293-48e4-b3f6-5136cf5c3f18",
"implements": null,
"implements_custom": "",
"load_selection": {
"load_selection0": {
"load": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef"
},
"load_selection1": {
"load": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a"
},
"load_selection2": {
"load": "db87c339-5bb6-4291-a7ef-2c48ea1b06bc"
}
},
"name": "JsonHelper",
"power_version": "1.0.0",
"system_name": "Utilities Json Helper",
"type": "abstract class",
"use_selection": null,
"namespace": "VDM\\Joomla\\Utilities.JsonHelper",
"description": "The json checker\r\n\r\n@since 3.0.9"
}

View File

@ -0,0 +1,82 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# abstract class Helper (Details)
> namespace: **VDM\Joomla\Utilities\Component**
```uml
@startuml
abstract Helper #Orange {
+ {static} getParams(?string $option = null) : Registry
+ {static} getOption(string $default = 'empty') : ?string
+ {static} getCode(?string $option = null, ?string $default = null) : ?string
+ {static} get(string $option = null, string $default = null) : ?string
+ {static} methodExists(string $method, string $option = null) : bool
+ {static} _(string $method, array $arguments = [], ...) : mixed
}
note right of Helper::getParams
Gets the parameter object for the component
since: 3.0.11
return: Registry
end note
note right of Helper::getOption
Gets the component option
since: 3.0.11
return: ?string
end note
note right of Helper::getCode
Gets the component code name
since: 3.0.11
return: ?string
end note
note right of Helper::get
Gets the component abstract helper class
since: 3.0.11
return: ?string
end note
note right of Helper::methodExists
Check if the helper class of this component has a method
since: 3.0.11
return: bool
end note
note right of Helper::_
Check if the helper class of this component has a method, and call it with the arguments
since: 3.2.0
return: mixed
arguments:
string $method
array $arguments = []
?string $option = null
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,189 @@
<?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\Input\Input;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\Registry\Registry;
/**
* Some component helper
*
* @since 3.0.11
*/
abstract class Helper
{
/**
* The current option
*
* @var string
* @since 3.0.11
*/
public static string $option;
/**
* 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];
}
/**
* Gets 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', false);
}
if (self::$option)
{
return self::$option;
}
return $default;
}
/**
* 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, false)) !== false)
{
// we build the helper class name
$helper_name = '\\' . \ucfirst($code_name) . 'Helper';
// check if class exist
if (class_exists($helper_name))
{
return $helper_name;
}
}
return $default;
}
/**
* 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, false)) !== false &&
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, false)) !== false &&
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;
}
}

View File

@ -0,0 +1,17 @@
{
"add_head": "1",
"extends": "0",
"extends_custom": "",
"guid": "640b5352-fb09-425f-a26e-cd44eda03f15",
"implements": null,
"implements_custom": "",
"load_selection": null,
"name": "Helper",
"power_version": "1.0.0",
"system_name": "Utilities Component Helper",
"type": "abstract class",
"use_selection": null,
"namespace": "VDM\\Joomla\\Utilities.Component.Helper",
"description": "Some component helper\r\n\r\n@since 3.0.11",
"head": "use Joomla\\Input\\Input;\r\nuse Joomla\\CMS\\Component\\ComponentHelper;\r\nuse Joomla\\Registry\\Registry;"
}

View File

@ -0,0 +1,388 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# trait Utilities (Details)
> namespace: **VDM\Joomla**
```uml
@startuml
class Utilities << (T,Orange) >> #Turquoise {
+ static $langTag
+ {static} checkString($string) : bool
+ {static} shorten($string, $length = 40, ...)
+ {static} safeString($string, $type = 'L', ...)
+ {static} safeClassFunctionName($name)
+ {static} safeFieldName($string, $allcap = false, ...)
+ {static} safeTypeName($string)
+ {static} safeNamespace($string)
+ {static} transliterate($string)
+ {static} htmlEscape($var, $charset = 'UTF-8', ...)
+ {static} replaceNumbers($string)
+ {static} numberToString($x)
+ {static} randomkey($size) : string
+ {static} checkJson($string) : bool
+ {static} jsonToString($value, $sperator = ", ...)
+ {static} checkArray($array, $removeEmptyString = false) : int
+ {static} mergeArrays($arrays)
+ {static} checkObject($object) : bool
+ {static} getVar(string $table, string $where = null, ...) : mix
+ {static} getVars(string $table, string $where = null, ...) : array
+ {static} getAllBetween(string $content, string $start, ...) : array
+ {static} getBetween(string $content, string $start, ...) : string
+ {static} bcmath(string $type, int $val1, ...) : float|int
+ {static} bcsum(array $array, int $scale = 4) : float|int
+ {static} createPluginClassName($group, $name) : string
+ {static} GUID(bool $trim = true) : string
+ {static} validGUID(string $guid, string $table = null, ...) : bool
+ {static} getGUID(string $guid, string $table, ...) : mix
# {static} validateGUID(string $guid) : bool
+ {static} zip(string $workingDIR, string $filepath) : bool
+ {static} getFileContents(string $path, string/bool $none = '') : string
+ {static} writeFile(string $path, string $data) : bool
+ {static} getAllFilePaths(string $folder, array $fileTypes = array('\.php') : void
+ {static} getFilePath(string $type = 'path', string $target = 'filepath', ...) : string
+ {static} urlExists(string $path) : bool
+ {static} setComponentOption(String|null $option = null)
}
note right of Utilities::checkString
Check if have a string with a length
since: 3.0.9
return: bool
end note
note left of Utilities::shorten
Shorten a string
since: 3.0.9
arguments:
$string
$length = 40
$addTip = true
end note
note right of Utilities::safeString
Making strings safe (various ways)
since: 3.0.9
arguments:
$string
$type = 'L'
$spacer = '_'
$replaceNumbers = true
$keepOnlyCharacters = true
end note
note left of Utilities::safeClassFunctionName
Making class or function name safe
since: 3.0.9
end note
note right of Utilities::safeFieldName
Making field names safe
since: 3.0.9
arguments:
$string
$allcap = false
$spacer = '_'
end note
note left of Utilities::safeTypeName
Making field type name safe
since: 3.0.9
end note
note right of Utilities::safeNamespace
Making namespace safe
since: 3.0.9
end note
note left of Utilities::transliterate
since: 3.0.9
end note
note right of Utilities::htmlEscape
since: 3.0.9
arguments:
$var
$charset = 'UTF-8'
$shorten = false
$length = 40
end note
note left of Utilities::replaceNumbers
since: 3.0.9
end note
note right of Utilities::numberToString
Convert an integer into an English word string
Thanks to Tom Nicholson <http://php.net/manual/en/function.strval.php#41988>
since: 3.0.9
end note
note left of Utilities::randomkey
Random Key
since: 3.0.9
return: string
end note
note right of Utilities::checkJson
Check if you have a json string
since: 3.0.9
return: bool
end note
note left of Utilities::jsonToString
since: 3.0.9
arguments:
$value
$sperator = "
$table = null
$id = 'id'
$name = 'name'
end note
note right of Utilities::checkArray
Check if you have an array with a length
since: 3.0.9
return: int
end note
note left of Utilities::mergeArrays
Merge an array of array's
since: 3.0.9
end note
note right of Utilities::checkObject
Check if you have an object with a length
since: 3.0.9
return: bool
end note
note left of Utilities::getVar
Get a Variable
since: 3.0.9
return: mix
arguments:
string $table
string $where = null
string $whereString = 'user'
string $what = 'id'
string $operator = '='
string $main = null
end note
note right of Utilities::getVars
Get array of variables
since: 3.0.9
return: array
arguments:
string $table
string $where = null
string $whereString = 'user'
string $what = 'id'
string $operator = 'IN'
string $main = null
bool $unique = true
end note
note left of Utilities::getAllBetween
get all strings between two other strings
since: 3.0.9
return: array
arguments:
string $content
string $start
string $end
end note
note right of Utilities::getBetween
get a string between two other strings
since: 3.0.9
return: string
arguments:
string $content
string $start
string $end
string $default = ''
end note
note left of Utilities::bcmath
bc math wrapper (very basic not for accounting)
since: 3.0.9
return: float|int
arguments:
string $type
int $val1
int $val2
int $scale
end note
note right of Utilities::bcsum
Basic sum of an array with more precision
since: 3.0.9
return: float|int
end note
note left of Utilities::createPluginClassName
create plugin class name
since: 3.0.9
return: string
end note
note right of Utilities::GUID
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.
since: 3.0.9
return: string
end note
note left of Utilities::validGUID
Validate the Globally Unique Identifier ( and check if table already has this identifier)
since: 3.0.9
return: bool
arguments:
string $guid
string $table = null
int $id
string|null $component = null
end note
note right of Utilities::getGUID
get the ITEM of a GUID by table
since: 3.0.9
return: mix
arguments:
string $guid
string $table
string/array $what = 'a.id'
string|null $component = null
end note
note left of Utilities::validateGUID
Validate the Globally Unique Identifier
Thanks to Lewie
https://stackoverflow.com/a/1515456/1429677
return: bool
end note
note right of Utilities::zip
The zipper method
since: 3.0.9
return: bool
end note
note left of Utilities::getFileContents
get the content of a file
since: 3.0.9
return: string
end note
note right of Utilities::writeFile
Write a file to the server
since: 3.0.9
return: bool
end note
note left of Utilities::getAllFilePaths
get all the file paths in folder and sub folders
since: 3.0.9
return: void
end note
note right of Utilities::getFilePath
Get the file path or url
since: 3.0.9
return: string
arguments:
string $type = 'path'
string $target = 'filepath'
string $fileType = null
string $key = ''
string $default = ''
bool $createIfNotSet = true
end note
note left of Utilities::urlExists
Check if file exist
since: 3.0.9
return: bool
end note
note right of Utilities::setComponentOption
Set the component option
since: 3.0.11
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,669 @@
<?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;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\JsonHelper;
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;
use VDM\Joomla\Utilities\String\NamespaceHelper;
use VDM\Joomla\Utilities\String\PluginHelper;
use VDM\Joomla\Utilities\Component\Helper;
/**
* Basic shared utilities, a legacy implementation
*
* @since 3.0.9
*/
trait Utilities
{
/**
* The Main Active Language
*
* @var string
*
* @since 3.0.9
*/
public static $langTag;
/**
* Check if have a string with a length
*
* @input string $string The string to check
*
* @returns bool true on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use StringHelper::check($string);
*/
public static function checkString($string): bool
{
return StringHelper::check($string);
}
/**
* Shorten a string
*
* @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);
*/
public static function shorten($string, $length = 40, $addTip = true)
{
return StringHelper::shorten($string, $length, $addTip);
}
/**
* Making strings safe (various ways)
*
* @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);
*/
public static function safeString($string, $type = 'L', $spacer = '_', $replaceNumbers = true, $keepOnlyCharacters = true)
{
// set the local component option
self::setComponentOption();
return StringHelper::safe($string, $type, $spacer, $replaceNumbers, $keepOnlyCharacters);
}
/**
* Making class or function name safe
*
* @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);
*/
public static function safeClassFunctionName($name)
{
return ClassfunctionHelper::safe($name);
}
/**
* Making field names safe
*
* @input string The 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
*
* @deprecated 4.0 - Use FieldHelper::safe($string, $allcap, $spacer);
*/
public static function safeFieldName($string, $allcap = false, $spacer = '_')
{
// set the local component option
self::setComponentOption();
return FieldHelper::safe($string, $allcap, $spacer);
}
/**
* Making field type name safe
*
* @input string The you would like to make safe
*
* @returns string on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use TypeHelper::safe($string);
*/
public static function safeTypeName($string)
{
// set the local component option
self::setComponentOption();
return TypeHelper::safe($string);
}
/**
* Making namespace safe
*
* @input string The you would like to make safe
*
* @returns string on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use NamespaceHelper::safe($string);
*/
public static function safeNamespace($string)
{
return NamespaceHelper::safe($string);
}
/**
* @since 3.0.9
*
* @deprecated 4.0 - Use StringHelper::transliterate($string);
*/
public static function transliterate($string)
{
// set the local component option
self::setComponentOption();
return StringHelper::transliterate($string);
}
/**
* @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)
{
// set the local component option
self::setComponentOption();
return StringHelper::html($var, $charset, $shorten, $length);
}
/**
* @since 3.0.9
*
* @deprecated 4.0 - Use StringHelper::numbers($string);
*/
public static function replaceNumbers($string)
{
return StringHelper::numbers($string);
}
/**
* Convert an integer into an English word string
* Thanks to Tom Nicholson <http://php.net/manual/en/function.strval.php#41988>
*
* @input int $x an int
*
* @returns string a string
*
* @since 3.0.9
*
* @deprecated 4.0 - Use StringHelper::number($x);
*/
public static function numberToString($x)
{
return StringHelper::number($x);
}
/**
* Random Key
*
* @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);
*/
public static function randomkey($size): string
{
return StringHelper::random($size);
}
/**
* Check if you have a json string
*
* @input string $string The json string to check
*
* @returns bool true on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use JsonHelper::check($string);
*/
public static function checkJson($string): bool
{
return JsonHelper::check($string);
}
/**
* @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')
{
return JsonHelper::string($value, $sperator, $table, $id, $name);
}
/**
* Check if you have an array with a length
*
* @input mixed $array The array to check
* @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);
*/
public static function checkArray($array, $removeEmptyString = false): int
{
return ArrayHelper::check($array, $removeEmptyString);
}
/**
* Merge an array of array's
*
* @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);
*/
public static function mergeArrays($arrays)
{
return ArrayHelper::merge($arrays);
}
/**
* Check if you have an object with a length
*
* @input object $object The object to check
*
* @returns bool true on success
*
* @since 3.0.9
*
* @deprecated 4.0 - Use ObjectHelper::check($object);
*/
public static function checkObject($object): bool
{
return ObjectHelper::check($object);
}
/**
* Get a Variable
*
* @param string $table The table from which to get the variable
* @param string $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 mix string/int/float
*
* @since 3.0.9
*
* @deprecated 4.0 - Use GetHelper::var($table, $where, $whereString, $what, $operator, $main);
*/
public static function getVar($table, $where = null, $whereString = 'user', $what = 'id', $operator = '=', $main = null)
{
// set the local component option
self::setComponentOption();
return GetHelper::var($table, $where, $whereString, $what, $operator, $main);
}
/**
* Get array of variables
*
* @param string $table The table from which to get the variables
* @param string $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
*
* @since 3.0.9
*
* @deprecated 4.0 - Use GetHelper::vars($table, $where, $whereString, $what, $operator, $main, $unique);
*/
public static function getVars($table, $where = null, $whereString = 'user', $what = 'id', $operator = 'IN', $main = null, $unique = true)
{
// set the local component option
self::setComponentOption();
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)
*
* @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 float|int
*
* @since 3.0.9
*
* @deprecated 4.0 - Use MathHelper::bc($type, $val1, $val2, $scale);
*/
public static function bcmath($type, $val1, $val2, $scale = 0)
{
return MathHelper::bc($type, $val1, $val2, $scale);
}
/**
* Basic sum of an array with more precision
*
* @param array $array The values to sum
* @param int $scale The scale value
*
* @return float|int
*
* @since 3.0.9
*
* @deprecated 4.0 - Use MathHelper::sum($array, $scale);
*/
public static function bcsum($array, $scale = 4)
{
return MathHelper::sum($array, $scale);
}
/**
* create plugin class name
*
* @input string The group name
* @input string The name
*
* @return string
*
* @since 3.0.9
*
* @deprecated 4.0 - Use PluginHelper::safe($name, $group);
*/
public static function createPluginClassName($group, $name)
{
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
* @param string|null $component
*
* @return bool
*
* @since 3.0.9
*
* @deprecated 4.0 - Use GuidHelper::valid($guid, $table, $id, $component);
*/
public static function validGUID($guid, $table = null, $id = 0, $component = null)
{
// set the local component option
self::setComponentOption();
return GuidHelper::valid($guid, $table, $id, $component);
}
/**
* get the ITEM of a GUID by table
*
* @param string $guid
* @param string $table
* @param string/array $what
* @param string|null $component
*
* @return mix
*
* @since 3.0.9
*
* @deprecated 4.0 - Use GuidHelper::valid($guid, $table, $id, $component);
*/
public static function getGUID($guid, $table, $what = 'a.id', $component = null)
{
// set the local component option
self::setComponentOption();
return GuidHelper::item($guid, $table, $what, $component);
}
/**
* 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);
}
/**
* get all the file paths in folder and sub folders
*
* @param string $folder The local path to parse
* @param array $fileTypes The type of files to get
*
* @return void
*
* @since 3.0.9
*
* @deprecated 4.0 - Use FileHelper::getPaths($folder, $fileTypes , $recurse, $full);
*/
public static function getAllFilePaths($folder, $fileTypes = array('\.php', '\.js', '\.css', '\.less'), $recurse = true, $full = true)
{
return FileHelper::getPaths($folder, $fileTypes , $recurse, $full);
}
/**
* 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
*
* @deprecated 4.0 - Use FileHelper::getPath($type, $target, $fileType, $key, $default, $createIfNotSet);
*/
public static function getFilePath($type = 'path', $target = 'filepath', $fileType = null, $key = '', $default = '', $createIfNotSet = true)
{
// set the local component option
self::setComponentOption();
return FileHelper::getPath($type, $target, $fileType, $key, $default, $createIfNotSet);
}
/**
* Check if file exist
*
* @param string $path The url/path to check
*
* @return bool If exist true
*
* @since 3.0.9
*
* @deprecated 4.0 - Use FileHelper::exists($path);
*/
public static function urlExists($path)
{
return FileHelper::exists($path);
}
/**
* Set the component option
*
* @param String|null $option The option for the component.
*
* @since 3.0.11
*/
public static function setComponentOption($option = null)
{
// set the local component option
if (empty($option))
{
if (empty(Helper::$option) && property_exists(__CLASS__, 'ComponentCodeName'))
{
Helper::$option = 'com_' . self::$ComponentCodeName;
}
}
else
{
Helper::$option = $option;
}
}
}

View File

@ -0,0 +1,73 @@
{
"add_head": "0",
"extends": "0",
"extends_custom": "",
"guid": "79d765b3-7319-4988-9730-446c7f347020",
"implements": null,
"implements_custom": "",
"load_selection": null,
"name": "Utilities",
"power_version": "1.0.0",
"system_name": "Utilities",
"type": "trait",
"use_selection": {
"use_selection0": {
"use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef",
"as": "default"
},
"use_selection1": {
"use": "4b225c51-d293-48e4-b3f6-5136cf5c3f18",
"as": "default"
},
"use_selection2": {
"use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a",
"as": "default"
},
"use_selection3": {
"use": "91004529-94a9-4590-b842-e7c6b624ecf5",
"as": "default"
},
"use_selection4": {
"use": "152c8793-8b75-4715-996a-257b9f65451c",
"as": "default"
},
"use_selection5": {
"use": "db87c339-5bb6-4291-a7ef-2c48ea1b06bc",
"as": "default"
},
"use_selection6": {
"use": "9c513baf-b279-43fd-ae29-a585c8cbc4f0",
"as": "default"
},
"use_selection7": {
"use": "a223b31e-ea1d-4cdf-92ae-5f9becffaff0",
"as": "default"
},
"use_selection8": {
"use": "9ef0eb24-aae4-4f5a-99af-d724db44808f",
"as": "default"
},
"use_selection9": {
"use": "a8935cbe-7701-40dc-bfd5-675f2d600954",
"as": "default"
},
"use_selection10": {
"use": "30c5b4c2-f75f-4d15-869a-f8bfedd87358",
"as": "default"
},
"use_selection11": {
"use": "ce8cf834-6bac-44fb-941c-861f7e046cc0",
"as": "default"
},
"use_selection12": {
"use": "3cf76fbf-fd95-4a33-878e-7aff6d36b7f6",
"as": "default"
},
"use_selection13": {
"use": "640b5352-fb09-425f-a26e-cd44eda03f15",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\Utilities",
"description": "Basic shared utilities, a legacy implementation\r\n\r\n@since 3.0.9"
}

View File

@ -0,0 +1,47 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# abstract class ObjectHelper (Details)
> namespace: **VDM\Joomla\Utilities**
```uml
@startuml
abstract ObjectHelper #Orange {
+ {static} check($object)
+ {static} equal(?object $obj1, ?object $obj2) : bool
}
note right of ObjectHelper::check
Check if have an object with a length
since: 3.0.9
end note
note right of ObjectHelper::equal
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.
return: bool
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -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);
}
}

View File

@ -0,0 +1,16 @@
{
"add_head": "0",
"extends": "0",
"extends_custom": "",
"guid": "91004529-94a9-4590-b842-e7c6b624ecf5",
"implements": null,
"implements_custom": "",
"load_selection": null,
"name": "ObjectHelper",
"power_version": "1.0.0",
"system_name": "Utilities Object Helper",
"type": "abstract class",
"use_selection": null,
"namespace": "VDM\\Joomla\\Utilities.ObjectHelper",
"description": "Some object tricks\r\n\r\n@since 3.0.9"
}

View File

@ -0,0 +1,80 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# abstract class GuidHelper (Details)
> namespace: **VDM\Joomla\Utilities**
```uml
@startuml
abstract GuidHelper #Orange {
+ {static} get(bool $trim = true) : string
+ {static} valid(string $guid, ?string $table = null, ...) : bool
+ {static} item(string $guid, string $table, ...) : mix
# {static} validate(string $guid) : bool
}
note right of GuidHelper::get
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.
since: 3.0.9
return: string
end note
note right of GuidHelper::valid
Validate the Globally Unique Identifier ( and check if table already has this identifier)
since: 3.0.9
return: bool
arguments:
string $guid
?string $table = null
int $id
?string $component = null
end note
note right of GuidHelper::item
get the item by guid in a table
since: 3.0.9
return: mix
arguments:
string $guid
string $table
string|array $what = 'a.id'
?string $component = null
end note
note right of GuidHelper::validate
Validate the Globally Unique Identifier
Thanks to Lewie
https://stackoverflow.com/a/1515456/1429677
since: 3.0.9
return: bool
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,214 @@
<?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 mix
*
* @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 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

@ -0,0 +1,29 @@
{
"add_head": "1",
"extends": "0",
"extends_custom": "",
"guid": "9c513baf-b279-43fd-ae29-a585c8cbc4f0",
"implements": null,
"implements_custom": "",
"load_selection": {
"load_selection0": {
"load": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a"
},
"load_selection1": {
"load": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef"
}
},
"name": "GuidHelper",
"power_version": "1.0.0",
"system_name": "Utilities GuidHelper",
"type": "abstract class",
"use_selection": {
"use_selection0": {
"use": "640b5352-fb09-425f-a26e-cd44eda03f15",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\Utilities.GuidHelper",
"description": "Global Unique ID Helper\r\n\r\n@since 3.0.9",
"head": "use Joomla\\CMS\\Factory;"
}

View File

@ -0,0 +1,86 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# abstract class FileHelper (Details)
> namespace: **VDM\Joomla\Utilities**
```uml
@startuml
abstract FileHelper #Orange {
# static $curlError
+ {static} zip(string $workingDirectory, string $filepath) : bool
+ {static} getContent(string $path, string/bool $none = '') : string
+ {static} write(string $path, string $data) : bool
+ {static} getPaths(string $folder, array $fileTypes = array('\.php') : void
+ {static} getPath(string $type = 'path', string $target = 'filepath', ...) : string
+ {static} exists(string $path) : bool
}
note right of FileHelper::zip
The zipper method
since: 3.0.9
return: bool
end note
note right of FileHelper::getContent
get the content of a file
since: 3.0.9
return: string
end note
note right of FileHelper::write
Write a file to the server
since: 3.0.9
return: bool
end note
note right of FileHelper::getPaths
get all the file paths in folder and sub folders
since: 3.0.9
return: void
end note
note right of FileHelper::getPath
Get the file path or url
since: 3.0.9
return: string
arguments:
string $type = 'path'
string $target = 'filepath'
string $fileType = null
string $key = ''
string $default = ''
bool $createIfNotSet = true
end note
note right of FileHelper::exists
Check if file exist
since: 3.0.9
return: bool
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View 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 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 = [];
$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;
}
/**
* get all the file paths in folder and sub folders
*
* @param string $folder The local path to parse
* @param array $fileTypes The type of files to get
*
* @return void
*
* @since 3.0.9
*/
public static function getPaths($folder, $fileTypes = array('\.php', '\.js', '\.css', '\.less'), $recurse = true, $full = true)
{
if (Folder::exists($folder))
{
// we must first store the current woking directory
$joomla = getcwd();
// we are changing the working directory to the component path
chdir($folder);
// make sure we have file type filter
if (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 false;
}
/**
* 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)
{
// 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)
{
$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;
}
}

View File

@ -0,0 +1,32 @@
{
"add_head": "1",
"extends": "0",
"extends_custom": "",
"guid": "a223b31e-ea1d-4cdf-92ae-5f9becffaff0",
"implements": null,
"implements_custom": "",
"load_selection": {
"load_selection0": {
"load": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a"
},
"load_selection1": {
"load": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef"
},
"load_selection2": {
"load": "91004529-94a9-4590-b842-e7c6b624ecf5"
}
},
"name": "FileHelper",
"power_version": "1.0.0",
"system_name": "Utilities FileHelper",
"type": "abstract class",
"use_selection": {
"use_selection0": {
"use": "640b5352-fb09-425f-a26e-cd44eda03f15",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\Utilities.FileHelper",
"description": "File helper\r\n\r\n@since 3.0.9",
"head": "use Joomla\\CMS\\Uri\\Uri;\r\nuse Joomla\\CMS\\Factory;\r\nuse Joomla\\CMS\\Language\\Text;\r\nuse Joomla\\CMS\\Filesystem\\Path;\r\nuse Joomla\\CMS\\Filesystem\\File;\r\nuse Joomla\\CMS\\Filesystem\\Folder;\r\nuse Joomla\\Archive\\Archive;"
}

View File

@ -0,0 +1,89 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# abstract class GetHelper (Details)
> namespace: **VDM\Joomla\Utilities**
```uml
@startuml
abstract GetHelper #Orange {
+ {static} var(?string $table = null, mixed $where = null, ...) : mixed
+ {static} vars(?string $table = null, mixed $where = null, ...) : ?array
+ {static} allBetween(string $content, string $start, ...) : ?array
+ {static} between(string $content, string $start, ...) : string
}
note right of GetHelper::var
Get a Variable
since: 3.0.9
return: mixed
arguments:
?string $table = null
mixed $where = null
string $whereString = 'user'
string $what = 'id'
string $operator = '='
?string $main = null
end note
note right of GetHelper::vars
Get array of variables
since: 3.0.9
return: ?array
arguments:
?string $table = null
mixed $where = null
string $whereString = 'user'
string $what = 'id'
string $operator = 'IN'
?string $main = null
bool $unique = true
end note
note right of GetHelper::allBetween
get all strings between two other strings
since: 3.0.9
return: ?array
arguments:
string $content
string $start
string $end
end note
note right of GetHelper::between
get a string between two other strings
since: 3.0.9
return: string
arguments:
string $content
string $start
string $end
string $default = ''
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View 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(is_null($main))
{
$main = Helper::getCode();
}
if (!ArrayHelper::check($where) && $where > 0)
{
$where = array($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;
}
}

View File

@ -0,0 +1,29 @@
{
"add_head": "1",
"extends": "0",
"extends_custom": "",
"guid": "db87c339-5bb6-4291-a7ef-2c48ea1b06bc",
"implements": null,
"implements_custom": "",
"load_selection": {
"load_selection0": {
"load": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a"
},
"load_selection1": {
"load": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef"
}
},
"name": "GetHelper",
"power_version": "1.0.0",
"system_name": "Utilities GetHelper",
"type": "abstract class",
"use_selection": {
"use_selection0": {
"use": "640b5352-fb09-425f-a26e-cd44eda03f15",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\Utilities.GetHelper",
"description": "Some easy get...\r\n\r\n@since 3.0.9",
"head": "use Joomla\\CMS\\Factory;"
}

92
super-powers.json Normal file
View File

@ -0,0 +1,92 @@
{
"0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a": {
"name": "ArrayHelper",
"type": "abstract class",
"namespace": "VDM\\Joomla\\Utilities",
"code": "src\/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a\/code.php",
"settings": "src\/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a\/settings.json",
"path": "src\/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a",
"guid": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a"
},
"640b5352-fb09-425f-a26e-cd44eda03f15": {
"name": "Helper",
"type": "abstract class",
"namespace": "VDM\\Joomla\\Utilities\\Component",
"code": "src\/640b5352-fb09-425f-a26e-cd44eda03f15\/code.php",
"settings": "src\/640b5352-fb09-425f-a26e-cd44eda03f15\/settings.json",
"path": "src\/640b5352-fb09-425f-a26e-cd44eda03f15",
"guid": "640b5352-fb09-425f-a26e-cd44eda03f15"
},
"1f28cb53-60d9-4db1-b517-3c7dc6b429ef": {
"name": "StringHelper",
"type": "abstract class",
"namespace": "VDM\\Joomla\\Utilities",
"code": "src\/1f28cb53-60d9-4db1-b517-3c7dc6b429ef\/code.php",
"settings": "src\/1f28cb53-60d9-4db1-b517-3c7dc6b429ef\/settings.json",
"path": "src\/1f28cb53-60d9-4db1-b517-3c7dc6b429ef",
"guid": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef"
},
"db87c339-5bb6-4291-a7ef-2c48ea1b06bc": {
"name": "GetHelper",
"type": "abstract class",
"namespace": "VDM\\Joomla\\Utilities",
"code": "src\/db87c339-5bb6-4291-a7ef-2c48ea1b06bc\/code.php",
"settings": "src\/db87c339-5bb6-4291-a7ef-2c48ea1b06bc\/settings.json",
"path": "src\/db87c339-5bb6-4291-a7ef-2c48ea1b06bc",
"guid": "db87c339-5bb6-4291-a7ef-2c48ea1b06bc"
},
"4b225c51-d293-48e4-b3f6-5136cf5c3f18": {
"name": "JsonHelper",
"type": "abstract class",
"namespace": "VDM\\Joomla\\Utilities",
"code": "src\/4b225c51-d293-48e4-b3f6-5136cf5c3f18\/code.php",
"settings": "src\/4b225c51-d293-48e4-b3f6-5136cf5c3f18\/settings.json",
"path": "src\/4b225c51-d293-48e4-b3f6-5136cf5c3f18",
"guid": "4b225c51-d293-48e4-b3f6-5136cf5c3f18"
},
"91004529-94a9-4590-b842-e7c6b624ecf5": {
"name": "ObjectHelper",
"type": "abstract class",
"namespace": "VDM\\Joomla\\Utilities",
"code": "src\/91004529-94a9-4590-b842-e7c6b624ecf5\/code.php",
"settings": "src\/91004529-94a9-4590-b842-e7c6b624ecf5\/settings.json",
"path": "src\/91004529-94a9-4590-b842-e7c6b624ecf5",
"guid": "91004529-94a9-4590-b842-e7c6b624ecf5"
},
"152c8793-8b75-4715-996a-257b9f65451c": {
"name": "MathHelper",
"type": "abstract class",
"namespace": "VDM\\Joomla\\Utilities",
"code": "src\/152c8793-8b75-4715-996a-257b9f65451c\/code.php",
"settings": "src\/152c8793-8b75-4715-996a-257b9f65451c\/settings.json",
"path": "src\/152c8793-8b75-4715-996a-257b9f65451c",
"guid": "152c8793-8b75-4715-996a-257b9f65451c"
},
"9c513baf-b279-43fd-ae29-a585c8cbc4f0": {
"name": "GuidHelper",
"type": "abstract class",
"namespace": "VDM\\Joomla\\Utilities",
"code": "src\/9c513baf-b279-43fd-ae29-a585c8cbc4f0\/code.php",
"settings": "src\/9c513baf-b279-43fd-ae29-a585c8cbc4f0\/settings.json",
"path": "src\/9c513baf-b279-43fd-ae29-a585c8cbc4f0",
"guid": "9c513baf-b279-43fd-ae29-a585c8cbc4f0"
},
"a223b31e-ea1d-4cdf-92ae-5f9becffaff0": {
"name": "FileHelper",
"type": "abstract class",
"namespace": "VDM\\Joomla\\Utilities",
"code": "src\/a223b31e-ea1d-4cdf-92ae-5f9becffaff0\/code.php",
"settings": "src\/a223b31e-ea1d-4cdf-92ae-5f9becffaff0\/settings.json",
"path": "src\/a223b31e-ea1d-4cdf-92ae-5f9becffaff0",
"guid": "a223b31e-ea1d-4cdf-92ae-5f9becffaff0"
},
"79d765b3-7319-4988-9730-446c7f347020": {
"name": "Utilities",
"type": "trait",
"namespace": "VDM\\Joomla",
"code": "src\/79d765b3-7319-4988-9730-446c7f347020\/code.php",
"settings": "src\/79d765b3-7319-4988-9730-446c7f347020\/settings.json",
"path": "src\/79d765b3-7319-4988-9730-446c7f347020",
"guid": "79d765b3-7319-4988-9730-446c7f347020"
}
}