Adds new utilities abstract classes as helper methods. Moves the helper class autoloader above the class. Adds option to override the settings.json file.
This commit is contained in:
9
libraries/jcb_powers/.htaccess
Normal file
9
libraries/jcb_powers/.htaccess
Normal file
@ -0,0 +1,9 @@
|
||||
# Apache 2.4+
|
||||
<IfModule mod_authz_core.c>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
|
||||
# Apache 2.0-2.2
|
||||
<IfModule !mod_authz_core.c>
|
||||
Deny from all
|
||||
</IfModule>
|
1
libraries/jcb_powers/VDM.Joomla/index.html
Normal file
1
libraries/jcb_powers/VDM.Joomla/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
346
libraries/jcb_powers/VDM.Joomla/src/Utilities.php
Normal file
346
libraries/jcb_powers/VDM.Joomla/src/Utilities.php
Normal file
@ -0,0 +1,346 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
||||
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla;
|
||||
|
||||
|
||||
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\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;
|
||||
|
||||
|
||||
/**
|
||||
* Basic shared utilities, a legacy implementation
|
||||
*/
|
||||
trait Utilities
|
||||
{
|
||||
/**
|
||||
* The Main Active Language
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $langTag;
|
||||
|
||||
/**
|
||||
* Check if have a string with a length
|
||||
*
|
||||
* @input string $string The string to check
|
||||
*
|
||||
* @returns bool true on success
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @deprecated 4.0 - Use StringHelper::safe($string, $type, $spacer, $replaceNumbers, $keepOnlyCharacters);
|
||||
*/
|
||||
public static function safeString($string, $type = 'L', $spacer = '_', $replaceNumbers = true, $keepOnlyCharacters = true)
|
||||
{
|
||||
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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @deprecated 4.0 - Use FieldHelper::safe($string, $allcap, $spacer);
|
||||
*/
|
||||
public static function safeFieldName($string, $allcap = false, $spacer = '_')
|
||||
{
|
||||
return FieldHelper::safe($string, $allcap, $spacer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Making field type name safe
|
||||
*
|
||||
* @input string The you would like to make safe
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @deprecated 4.0 - Use TypeHelper::safe($string);
|
||||
*/
|
||||
public static function safeTypeName($string)
|
||||
{
|
||||
return TypeHelper::safe($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Making namespace safe
|
||||
*
|
||||
* @input string The you would like to make safe
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @deprecated 4.0 - Use NamespaceHelper::safe($string);
|
||||
*/
|
||||
public static function safeNamespace($string)
|
||||
{
|
||||
return NamespaceHelper::safe($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 4.0 - Use StringHelper::transliterate($string);
|
||||
*/
|
||||
public static function transliterate($string)
|
||||
{
|
||||
return StringHelper::transliterate($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 4.0 - Use StringHelper::html($var, $charset, $shorten, $length);
|
||||
*/
|
||||
public static function htmlEscape($var, $charset = 'UTF-8', $shorten = false, $length = 40)
|
||||
{
|
||||
return StringHelper::html($var, $charset, $shorten, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @deprecated 4.0 - Use JsonHelper::check($string);
|
||||
*/
|
||||
public static function checkJson($string): bool
|
||||
{
|
||||
return JsonHelper::check($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @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 = 'componentbuilder')
|
||||
{
|
||||
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
|
||||
*
|
||||
* @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 = 'componentbuilder', $unique = true)
|
||||
{
|
||||
return GetHelper::vars($table, $where, $whereString, $what, $operator, $main, $unique);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @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 float
|
||||
*
|
||||
* @deprecated 4.0 - Use PluginHelper::safe($name, $group);
|
||||
*/
|
||||
public static function createPluginClassName($group, $name)
|
||||
{
|
||||
return PluginHelper::safeClassName($name, $group);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
||||
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
/**
|
||||
* Some array tricks helper
|
||||
*/
|
||||
abstract class ArrayHelper
|
||||
{
|
||||
/**
|
||||
* Check if have an array with a length
|
||||
*
|
||||
* @input array The array to check
|
||||
*
|
||||
* @returns bool/int number of items in array on success
|
||||
*/
|
||||
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)
|
||||
{
|
||||
foreach ($array as $key => $string)
|
||||
{
|
||||
if (empty($string))
|
||||
{
|
||||
unset($array[$key]);
|
||||
}
|
||||
}
|
||||
return self::check($array, false);
|
||||
}
|
||||
return $nr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge an array of array's
|
||||
*
|
||||
* @input array The arrays you would like to merge
|
||||
*
|
||||
* @returns array on success
|
||||
*/
|
||||
public static function merge($arrays)
|
||||
{
|
||||
if(self::check($arrays))
|
||||
{
|
||||
$arrayBuket = array();
|
||||
foreach ($arrays as $array)
|
||||
{
|
||||
if (self::check($array))
|
||||
{
|
||||
$arrayBuket = array_merge($arrayBuket, $array);
|
||||
}
|
||||
}
|
||||
return $arrayBuket;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
159
libraries/jcb_powers/VDM.Joomla/src/Utilities/GetHelper.php
Normal file
159
libraries/jcb_powers/VDM.Joomla/src/Utilities/GetHelper.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
||||
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
|
||||
|
||||
/**
|
||||
* Some easy get...
|
||||
*/
|
||||
abstract class GetHelper
|
||||
{
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
public static function var($table, $where = null, $whereString = 'user', $what = 'id', $operator = '=', $main = 'componentbuilder')
|
||||
{
|
||||
if(!$where)
|
||||
{
|
||||
$where = Factory::getUser()->id;
|
||||
}
|
||||
|
||||
// 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 $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
|
||||
*
|
||||
*/
|
||||
public static function vars($table, $where = null, $whereString = 'user', $what = 'id', $operator = 'IN', $main = 'componentbuilder', $unique = true)
|
||||
{
|
||||
if(!$where)
|
||||
{
|
||||
$where = Factory::getUser()->id;
|
||||
}
|
||||
|
||||
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 false;
|
||||
}
|
||||
|
||||
}
|
||||
|
89
libraries/jcb_powers/VDM.Joomla/src/Utilities/JsonHelper.php
Normal file
89
libraries/jcb_powers/VDM.Joomla/src/Utilities/JsonHelper.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
||||
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
/**
|
||||
* The json checker
|
||||
*/
|
||||
abstract class JsonHelper
|
||||
{
|
||||
/**
|
||||
* Check if you have a json string
|
||||
*
|
||||
* @input string $string The json string to check
|
||||
*
|
||||
* @returns bool true on success
|
||||
*/
|
||||
public static function check($string): bool
|
||||
{
|
||||
if (StringHelper::check($string))
|
||||
{
|
||||
json_decode($string);
|
||||
return (json_last_error() === JSON_ERROR_NONE);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function string($value, $separator = ", ", $table = null, $id = 'id', $name = 'name')
|
||||
{
|
||||
// do some table foot work
|
||||
$external = false;
|
||||
if (strpos($table, '#__') !== false)
|
||||
{
|
||||
$external = true;
|
||||
$table = str_replace('#__', '', $table);
|
||||
}
|
||||
|
||||
// check if string is JSON
|
||||
$result = json_decode($value, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE)
|
||||
{
|
||||
// is JSON
|
||||
if (ArrayHelper::check($result))
|
||||
{
|
||||
if (StringHelper::check($table))
|
||||
{
|
||||
$names = array();
|
||||
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($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
100
libraries/jcb_powers/VDM.Joomla/src/Utilities/MathHelper.php
Normal file
100
libraries/jcb_powers/VDM.Joomla/src/Utilities/MathHelper.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
||||
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
/**
|
||||
* Basic Math Helper
|
||||
*/
|
||||
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
|
||||
*
|
||||
*/
|
||||
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
|
||||
*
|
||||
*/
|
||||
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, $val, $scale);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
// fall back on array sum
|
||||
return array_sum($array);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
||||
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
/**
|
||||
* Some object tricks
|
||||
*/
|
||||
abstract class ObjectHelper
|
||||
{
|
||||
/**
|
||||
* Check if have an object with a length
|
||||
*
|
||||
* @input object The object to check
|
||||
*
|
||||
* @returns bool true on success
|
||||
*/
|
||||
public static function check($object)
|
||||
{
|
||||
if (is_object($object))
|
||||
{
|
||||
return count((array) $object) > 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
||||
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities\String;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Control the naming of a class and function
|
||||
*/
|
||||
abstract class ClassfunctionHelper
|
||||
{
|
||||
/**
|
||||
* Making class or function name safe
|
||||
*
|
||||
* @input string The name you would like to make safe
|
||||
*
|
||||
* @returns string on success
|
||||
**/
|
||||
public static function safe($name)
|
||||
{
|
||||
// remove numbers if the first character is a number
|
||||
if (is_numeric(substr($name, 0, 1)))
|
||||
{
|
||||
$name = StringHelper::numbers($name);
|
||||
}
|
||||
|
||||
// remove all spaces and strange characters
|
||||
return trim(preg_replace("/[^A-Za-z0-9_-]/", '', $name));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
||||
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities\String;
|
||||
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Control the naming of a field
|
||||
*/
|
||||
abstract class FieldHelper
|
||||
{
|
||||
/**
|
||||
* The field builder switch
|
||||
**/
|
||||
protected static $builder = false;
|
||||
|
||||
/**
|
||||
* Making field names safe
|
||||
*
|
||||
* @input string The string you would like to make safe
|
||||
* @input boolean The switch to return an ALL UPPER CASE string
|
||||
* @input string The string to use in white space
|
||||
*
|
||||
* @returns string on success
|
||||
**/
|
||||
public static function safe($string, $allcap = false, $spacer = '_')
|
||||
{
|
||||
// get global value
|
||||
if (self::$builder === false)
|
||||
{
|
||||
self::$builder = ComponentHelper::getParams('com_componentbuilder')->get('field_name_builder', 1);
|
||||
}
|
||||
|
||||
// use the new convention
|
||||
if (2 == self::$builder)
|
||||
{
|
||||
// 0nly continue if we have a string
|
||||
if (StringHelper::check($string))
|
||||
{
|
||||
// check that the first character is not a number
|
||||
if (is_numeric(substr($string, 0, 1)))
|
||||
{
|
||||
$string = StringHelper::numbers($string);
|
||||
}
|
||||
|
||||
// remove all other strange characters
|
||||
$string = trim($string);
|
||||
$string = preg_replace('/'.$spacer.'+/', ' ', $string);
|
||||
$string = preg_replace('/\s+/', ' ', $string);
|
||||
|
||||
// Transliterate string
|
||||
$string = StringHelper::transliterate($string);
|
||||
|
||||
// remove all and keep only characters and numbers
|
||||
$string = preg_replace("/[^A-Za-z0-9 ]/", '', $string);
|
||||
|
||||
// replace white space with underscore (SAFEST OPTION)
|
||||
$string = preg_replace('/\s+/', $spacer, $string);
|
||||
|
||||
// return all caps
|
||||
if ($allcap)
|
||||
{
|
||||
return strtoupper($string);
|
||||
}
|
||||
|
||||
// default is to return lower
|
||||
return strtolower($string);
|
||||
}
|
||||
// not a string
|
||||
return '';
|
||||
}
|
||||
|
||||
// return all caps
|
||||
if ($allcap)
|
||||
{
|
||||
return StringHelper::safe($string, 'U');
|
||||
}
|
||||
|
||||
// use the default (original behavior/convention)
|
||||
return StringHelper::safe($string);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
||||
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities\String;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Control the naming of a namespace helper
|
||||
*/
|
||||
abstract class NamespaceHelper
|
||||
{
|
||||
/**
|
||||
* Making namespace safe
|
||||
*
|
||||
* @input string The you would like to make safe
|
||||
*
|
||||
* @returns string on success
|
||||
**/
|
||||
public static function safe($string)
|
||||
{
|
||||
// 0nly continue if we have a string
|
||||
if (StringHelper::check($string))
|
||||
{
|
||||
// make sure it has not numbers
|
||||
$string = StringHelper::numbers($string);
|
||||
|
||||
// Transliterate string TODO: look again as this make it lowercase
|
||||
// $string = StringHelper::transliterate($string);
|
||||
|
||||
// first remove all [\] backslashes
|
||||
$string = str_replace('\\', '1', $string);
|
||||
|
||||
// remove all and keep only characters and [\] backslashes inside of the string
|
||||
$string = trim(preg_replace("/[^A-Za-z1]/", '', $string), '1');
|
||||
|
||||
// place the [\] backslashes back
|
||||
return trim(preg_replace("/1+/", '\\', $string));
|
||||
}
|
||||
// not a string
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
||||
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities\String;
|
||||
|
||||
|
||||
/**
|
||||
* Control the naming of a plugin
|
||||
*/
|
||||
abstract class PluginHelper
|
||||
{
|
||||
/**
|
||||
* Making plugin folder name safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*/
|
||||
public static function safeFolderName($codeName, $group)
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'plg_' . strtolower($group) . '_' . strtolower(
|
||||
$codeName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Making plugin class name safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*/
|
||||
public static function safeClassName($codeName, $group)
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'Plg' . ucfirst($group) . ucfirst(
|
||||
$codeName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Making plugin install class name safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*/
|
||||
public static function safeInstallClassName($codeName, $group)
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'plg' . ucfirst($group) . ucfirst(
|
||||
$codeName
|
||||
) . 'InstallerScript';
|
||||
}
|
||||
|
||||
/**
|
||||
* Making language prefix safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*/
|
||||
public static function safeLangPrefix($codeName, $group)
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'PLG_' . strtoupper($group) . strtoupper(
|
||||
$codeName
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
||||
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities\String;
|
||||
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Control the naming of a field type
|
||||
*/
|
||||
abstract class TypeHelper
|
||||
{
|
||||
/**
|
||||
* The field builder switch
|
||||
**/
|
||||
protected static $builder = false;
|
||||
|
||||
/**
|
||||
* Making field type name safe
|
||||
*
|
||||
* @input string The you would like to make safe
|
||||
*
|
||||
* @returns string on success
|
||||
**/
|
||||
public static function safe($string)
|
||||
{
|
||||
// get global value
|
||||
if (self::$builder === false)
|
||||
{
|
||||
self::$builder = ComponentHelper::getParams('com_componentbuilder')->get('type_name_builder', 1);
|
||||
}
|
||||
|
||||
// use the new convention
|
||||
if (2 == self::$builder)
|
||||
{
|
||||
// 0nly continue if we have a string
|
||||
if (StringHelper::check($string))
|
||||
{
|
||||
// check that the first character is not a number
|
||||
if (is_numeric(substr($string, 0, 1)))
|
||||
{
|
||||
$string = StringHelper::numbers($string);
|
||||
}
|
||||
|
||||
// Transliterate string
|
||||
$string = StringHelper::transliterate($string);
|
||||
|
||||
// remove all and keep only characters and numbers and point (TODO just one point)
|
||||
$string = trim(preg_replace("/[^A-Za-z0-9\.]/", '', $string));
|
||||
|
||||
// best is to return lower (for all string equality in compiler)
|
||||
return strtolower($string);
|
||||
}
|
||||
// not a string
|
||||
return '';
|
||||
}
|
||||
|
||||
// use the default (original behaviour/convention)
|
||||
return StringHelper::safe($string);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
379
libraries/jcb_powers/VDM.Joomla/src/Utilities/StringHelper.php
Normal file
379
libraries/jcb_powers/VDM.Joomla/src/Utilities/StringHelper.php
Normal file
@ -0,0 +1,379 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 30th April, 2015
|
||||
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
||||
* @gitea Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use Joomla\CMS\Filter\InputFilter;
|
||||
use Joomla\CMS\Language\Language;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Some string tricks
|
||||
*/
|
||||
abstract class StringHelper
|
||||
{
|
||||
/**
|
||||
* The Main Active Language
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $langTag;
|
||||
|
||||
/**
|
||||
* Check if we have a string with a length
|
||||
*
|
||||
* @input string $string The string to check
|
||||
*
|
||||
* @returns bool true on success
|
||||
*/
|
||||
public static function check($string): bool
|
||||
{
|
||||
if (is_string($string) && strlen($string) > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorten a string
|
||||
*
|
||||
* @input string The you would like to shorten
|
||||
*
|
||||
* @returns string on success
|
||||
*/
|
||||
public static function shorten($string, $length = 40, $addTip = true)
|
||||
{
|
||||
if (self::check($string))
|
||||
{
|
||||
$initial = strlen($string);
|
||||
$words = preg_split('/([\s\n\r]+)/', $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
|
||||
*/
|
||||
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);
|
||||
// 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);
|
||||
}
|
||||
// remove all other characters
|
||||
$string = trim($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);
|
||||
}
|
||||
// keep both numbers and characters
|
||||
else
|
||||
{
|
||||
$string = preg_replace("/[^A-Za-z0-9 ]/", '', $string);
|
||||
}
|
||||
// select final adaptations
|
||||
if ($type === 'L' || $type === 'strtolower')
|
||||
{
|
||||
// replace white space with underscore
|
||||
$string = preg_replace('/\s+/', $spacer, $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+/', $spacer, $string);
|
||||
// return all upper
|
||||
return strtoupper($string);
|
||||
}
|
||||
elseif ($type === 'F' || $type === 'ucfirst')
|
||||
{
|
||||
// replace white space with underscore
|
||||
$string = preg_replace('/\s+/', $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 '';
|
||||
}
|
||||
|
||||
public static function transliterate($string)
|
||||
{
|
||||
// set tag only once
|
||||
if (!self::check(self::$langTag))
|
||||
{
|
||||
// get global value
|
||||
self::$langTag = ComponentHelper::getParams('com_componentbuilder')->get('language', 'en-GB');
|
||||
}
|
||||
|
||||
// Transliterate on the language requested
|
||||
$lang = Language::getInstance(self::$langTag);
|
||||
|
||||
return $lang->transliterate($string);
|
||||
}
|
||||
|
||||
public static function html($var, $charset = 'UTF-8', $shorten = false, $length = 40)
|
||||
{
|
||||
if (self::check($var))
|
||||
{
|
||||
$filter = new InputFilter();
|
||||
$string = $filter->clean(
|
||||
html_entity_decode(
|
||||
htmlentities(
|
||||
$var,
|
||||
ENT_COMPAT,
|
||||
$charset
|
||||
)
|
||||
),
|
||||
'HTML'
|
||||
);
|
||||
if ($shorten)
|
||||
{
|
||||
return self::shorten($string, $length);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
public static function numbers($string)
|
||||
{
|
||||
// set numbers array
|
||||
$numbers = array();
|
||||
|
||||
// first get all numbers
|
||||
preg_match_all('!\d+!', $string, $numbers);
|
||||
|
||||
// check if we have any numbers
|
||||
if (isset($numbers[0]) && ArrayHelper::check($numbers[0]))
|
||||
{
|
||||
foreach ($numbers[0] as $number)
|
||||
{
|
||||
$searchReplace[$number] = self::number((int)$number);
|
||||
}
|
||||
|
||||
// now replace numbers in string
|
||||
$string = str_replace(array_keys($searchReplace), array_values($searchReplace), $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
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @returns a string
|
||||
*/
|
||||
public static function random($size)
|
||||
{
|
||||
$bag = "abcefghijknopqrstuwxyzABCDDEFGHIJKLLMMNOPQRSTUVVWXYZabcddefghijkllmmnopqrstuvvwxyzABCEFGHIJKNOPQRSTUWXYZ";
|
||||
$key = array();
|
||||
$bagsize = strlen($bag) - 1;
|
||||
|
||||
for ($i = 0; $i < $size; $i++)
|
||||
{
|
||||
$get = rand(0, $bagsize);
|
||||
$key[] = $bag[$get];
|
||||
}
|
||||
|
||||
return implode($key);
|
||||
}
|
||||
|
||||
}
|
||||
|
1
libraries/jcb_powers/VDM.Joomla/src/Utilities/index.html
Normal file
1
libraries/jcb_powers/VDM.Joomla/src/Utilities/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
9
libraries/jcb_powers/htaccess.txt
Normal file
9
libraries/jcb_powers/htaccess.txt
Normal file
@ -0,0 +1,9 @@
|
||||
# Apache 2.4+
|
||||
<IfModule mod_authz_core.c>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
|
||||
# Apache 2.0-2.2
|
||||
<IfModule !mod_authz_core.c>
|
||||
Deny from all
|
||||
</IfModule>
|
1
libraries/jcb_powers/index.html
Normal file
1
libraries/jcb_powers/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
7
libraries/jcb_powers/web.config
Normal file
7
libraries/jcb_powers/web.config
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<system.web>
|
||||
<authorization>
|
||||
<deny users="*" />
|
||||
</authorization>
|
||||
</system.web>
|
||||
</configuration>
|
Reference in New Issue
Block a user