Fixed changelog direction so newest changes is listed at top of the file. Finished the init function of super powers. Adds rest function inside super power. Adds super powers to all templates. Updates many helper class methods to now use the utility classes. Adds the method to the component entry file (as-well). Moved most methods from the compiler fields class to powers. #955 Refactored many new builder classes from the registry class. Converted the Content class to two builder classes. Adds option to add additional templates to a module. Resolves #1002 by adding STRING instead of WORD. Ported the FOF encryption class into Powers. https://git.vdm.dev/joomla/fof Changed all CSS and JS to use instead of in compiler code. Adds option to turn jQuery off if UIKIT 3 is added. Adds option to auto write injection boilerplate code in Powers area. Adds option to auto write service provider boilerplate code in the Powers area. Improved the method and all banner locations to fetch from https://git.vdm.dev/joomla/jcb-external/ instead. Major stability improvements all over the new powers complier classes. New [base Registry class](https://git.vdm.dev/joomla/super-powers/src/branch/master/src/7e822c03-1b20-41d1-9427-f5b8d5836af7) has been created specially for JCB. Remember to update all plug-ins with this version update (use the package).
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* The Base64 Helper
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Base64Helper
|
||||
{
|
||||
/**
|
||||
* open base64 string if stored as base64 (in JCB)
|
||||
*
|
||||
* @param string|null $data The base64 string
|
||||
* @param string|null $key We store the string with that suffix :)
|
||||
* @param string|null $default The default switch
|
||||
*
|
||||
* @return string|null The opened string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function open(?string $data, ?string $key = '__.o0=base64=Oo.__', ?string $default = 'string'): ?string
|
||||
{
|
||||
// check that we have a string
|
||||
if (StringHelper::check($data))
|
||||
{
|
||||
// check if we have a key
|
||||
if (StringHelper::check($key))
|
||||
{
|
||||
if (strpos($data, $key) !== false)
|
||||
{
|
||||
return base64_decode(str_replace($key, '', $data));
|
||||
}
|
||||
}
|
||||
|
||||
// fallback to this, not perfect method
|
||||
if (base64_encode(base64_decode($data, true)) === $data)
|
||||
{
|
||||
return base64_decode($data);
|
||||
}
|
||||
}
|
||||
|
||||
// check if we should just return the string
|
||||
if ('string' === $default)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
@@ -132,7 +132,7 @@ abstract class FileHelper
|
||||
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');
|
||||
Factory::getApplication()->enqueueMessage('<h2>Curl Not Found!</h2><p>Please setup curl on your system, or the <b>Joomla Component</b> will not function correctly!</p>', 'Error');
|
||||
// load this notice only once
|
||||
self::$curlError = true;
|
||||
}
|
||||
|
187
libraries/jcb_powers/VDM.Joomla/src/Utilities/FormHelper.php
Normal file
187
libraries/jcb_powers/VDM.Joomla/src/Utilities/FormHelper.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
||||
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use Joomla\CMS\Form\FormHelper as JoomlaFormHelper;
|
||||
use Joomla\CMS\Form\FormField;
|
||||
|
||||
|
||||
/**
|
||||
* Form Helper
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class FormHelper
|
||||
{
|
||||
/**
|
||||
* get the field xml
|
||||
*
|
||||
* @param array $attributes The array of attributes
|
||||
* @param array $options The options to apply to the XML element
|
||||
*
|
||||
* @return \SimpleXMLElement|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function xml(array $attributes, ?array $options = null): ?\SimpleXMLElement
|
||||
{
|
||||
// make sure we have attributes and a type value
|
||||
if (ArrayHelper::check($attributes))
|
||||
{
|
||||
// start field xml
|
||||
$XML = new \SimpleXMLElement('<field/>');
|
||||
|
||||
// load the attributes
|
||||
self::attributes($XML, $attributes);
|
||||
|
||||
// check if we have options
|
||||
if (ArrayHelper::check($options))
|
||||
{
|
||||
// load the options
|
||||
self::options($XML, $options);
|
||||
}
|
||||
|
||||
// return the field xml
|
||||
return $XML;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlAppend
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param mixed $node A SimpleXMLElement node to append to the XML element reference,
|
||||
* or a stdClass object containing a comment attribute to be injected
|
||||
* before the XML node and a fieldXML attribute containing a SimpleXMLElement
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function append(\SimpleXMLElement &$xml, $node)
|
||||
{
|
||||
if (!$node)
|
||||
{
|
||||
// element was not returned
|
||||
return;
|
||||
}
|
||||
switch (get_class($node))
|
||||
{
|
||||
case 'stdClass':
|
||||
if (property_exists($node, 'comment'))
|
||||
{
|
||||
self::comment($xml, $node->comment);
|
||||
}
|
||||
if (property_exists($node, 'fieldXML'))
|
||||
{
|
||||
self::append($xml, $node->fieldXML);
|
||||
}
|
||||
break;
|
||||
case 'SimpleXMLElement':
|
||||
$domXML = \dom_import_simplexml($xml);
|
||||
$domNode = \dom_import_simplexml($node);
|
||||
$domXML->appendChild($domXML->ownerDocument->importNode($domNode, true));
|
||||
$xml = \simplexml_import_dom($domXML);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlComment
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param string $comment The comment to inject
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function comment(\SimpleXMLElement &$xml, string $comment)
|
||||
{
|
||||
$domXML = \dom_import_simplexml($xml);
|
||||
$domComment = new \DOMComment($comment);
|
||||
$nodeTarget = $domXML->ownerDocument->importNode($domComment, true);
|
||||
$domXML->appendChild($nodeTarget);
|
||||
$xml = \simplexml_import_dom($domXML);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlAddAttributes
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param array $attributes The attributes to apply to the XML element
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function attributes(\SimpleXMLElement &$xml, array $attributes = [])
|
||||
{
|
||||
foreach ($attributes as $key => $value)
|
||||
{
|
||||
$xml->addAttribute($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlAddOptions
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param array $options The options to apply to the XML element
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function options(\SimpleXMLElement &$xml, array $options = [])
|
||||
{
|
||||
foreach ($options as $key => $value)
|
||||
{
|
||||
$addOption = $xml->addChild('option');
|
||||
$addOption->addAttribute('value', $key);
|
||||
$addOption[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the field object
|
||||
*
|
||||
* @param array $attributes The array of attributes
|
||||
* @param string $default The default of the field
|
||||
* @param array $options The options to apply to the XML element
|
||||
*
|
||||
* @return FormField|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function field(array $attributes, string $default = '', ?array $options = null): ?FormField
|
||||
{
|
||||
// make sure we have attributes and a type value
|
||||
if (ArrayHelper::check($attributes) && isset($attributes['type']))
|
||||
{
|
||||
// get field type
|
||||
if (($field = JoomlaFormHelper::loadFieldType($attributes['type'], true)) === false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// get field xml
|
||||
$XML = self::xml($attributes, $options);
|
||||
|
||||
// setup the field
|
||||
$field->setup($XML, $default);
|
||||
|
||||
// return the field object
|
||||
return $field;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -27,48 +27,47 @@ abstract class MathHelper
|
||||
* @param int $val2 The second value
|
||||
* @param int $scale The scale value
|
||||
*
|
||||
* @return int
|
||||
* @return string|int|null|bool
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function bc($type, $val1, $val2, $scale = 0)
|
||||
{
|
||||
// build function name
|
||||
// Validate input
|
||||
if (!is_numeric($val1) || !is_numeric($val2))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Build function name
|
||||
$function = 'bc' . $type;
|
||||
// use the bcmath function if available
|
||||
if (function_exists($function))
|
||||
|
||||
// Use the bcmath function if available
|
||||
if (is_callable($function))
|
||||
{
|
||||
return $function($val1, $val2, $scale);
|
||||
}
|
||||
|
||||
// if function does not exist we use +-*/ operators (fallback - not ideal)
|
||||
switch ($type)
|
||||
{
|
||||
// Multiply two numbers
|
||||
case 'mul':
|
||||
return (string) round($val1 * $val2, $scale);
|
||||
break;
|
||||
// Divide of two numbers
|
||||
case 'div':
|
||||
if ($val2 == 0) return null; // Avoid division by zero
|
||||
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;
|
||||
$diff = round($val1 - $val2, $scale);
|
||||
return ($diff > 0) ? 1 : (($diff < 0) ? -1 : 0);
|
||||
}
|
||||
return false;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -25,47 +25,43 @@ abstract class NamespaceHelper
|
||||
/**
|
||||
* Making namespace safe
|
||||
*
|
||||
* @input string $string The you would like to make safe
|
||||
* @input bool $removeNumbers The switch to remove numbers
|
||||
* @param string $string The namespace string you would like to make safe
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @return string on success
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safe(string $string, bool $removeNumbers = true): string
|
||||
public static function safe(string $string): string
|
||||
{
|
||||
// 0nly continue if we have a string with length
|
||||
if (StringHelper::check($string))
|
||||
// Remove leading and trailing backslashes
|
||||
$string = trim($string, '\\');
|
||||
|
||||
// Split the string into namespace segments
|
||||
$segments = explode('\\', $string);
|
||||
|
||||
foreach ($segments as &$segment)
|
||||
{
|
||||
// make sure it has not numbers
|
||||
if ($removeNumbers)
|
||||
// Check if segment starts with a number
|
||||
if (preg_match("/^\d/", $segment))
|
||||
{
|
||||
$string = StringHelper::numbers($string);
|
||||
// Extract the starting number(s)
|
||||
preg_match("/^\d+/", $segment, $matches);
|
||||
|
||||
if (isset($matches[0]))
|
||||
{
|
||||
$numberWord = StringHelper::numbers($matches[0]);
|
||||
$segment = str_replace($matches[0], $numberWord, $segment);
|
||||
}
|
||||
}
|
||||
|
||||
// Transliterate string TODO: look again as this makes it lowercase
|
||||
// $string = StringHelper::transliterate($string);
|
||||
// $segment = StringHelper::transliterate($segment);
|
||||
|
||||
// first remove all [\] backslashes
|
||||
$string = str_replace('\\', '+', (string) $string);
|
||||
|
||||
// remove all and keep only characters and [\] backslashes inside of the string
|
||||
if ($removeNumbers)
|
||||
{
|
||||
$string = trim( preg_replace("/[^A-Za-z\+]/", '', $string), '+');
|
||||
}
|
||||
else
|
||||
{
|
||||
$string = trim( preg_replace("/[^A-Za-z0-9\+]/", '', $string), '+');
|
||||
}
|
||||
|
||||
// place the [\] backslashes back
|
||||
return trim( preg_replace("/\++/", '\\', $string));
|
||||
// Make sure segment only contains valid characters
|
||||
$segment = preg_replace("/[^A-Za-z0-9]/", '', $segment);
|
||||
}
|
||||
|
||||
// not a string
|
||||
return '';
|
||||
}
|
||||
|
||||
// Join the namespace segments back together
|
||||
return implode('\\', $segments);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user