Adds some PHP 8 ready changes to compiler classes. Adds Server and Crypt classes.
This commit is contained in:
@ -0,0 +1,233 @@
|
||||
<?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\Componentbuilder\Abstraction;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Table;
|
||||
|
||||
|
||||
/**
|
||||
* Our base Model
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Model
|
||||
{
|
||||
/**
|
||||
* Last ID
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $last;
|
||||
|
||||
/**
|
||||
* Search Table
|
||||
*
|
||||
* @var Table
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Table $table;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Table $table The search table object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Table $table)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the value
|
||||
* Example: $this->value(value, 'value_key', 'table_name');
|
||||
*
|
||||
* @param mixed $value The value to model
|
||||
* @param string $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract public function value($value, string $field, ?string $table = null);
|
||||
|
||||
/**
|
||||
* Model the values of an item
|
||||
* Example: $this->item('table_name', Object);
|
||||
*
|
||||
* @param object $item The item object
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(object $item, ?string $table = null): ?object
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
// field counter
|
||||
$field_number = 0;
|
||||
|
||||
// check if this is a valid table
|
||||
if (($fields = $this->getTableFields($table)) !== null)
|
||||
{
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
// model a value if it exists
|
||||
if(isset($item->{$field}))
|
||||
{
|
||||
$item->{$field} = $this->value($item->{$field}, $field, $table);
|
||||
|
||||
if ($this->validate($item->{$field}))
|
||||
{
|
||||
$field_number++;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($item->{$field});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// all items must have more than one field or its empty (1 = id)
|
||||
if ($field_number > 1)
|
||||
{
|
||||
return $item;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the values of multiple items
|
||||
* Example: $this->items(Array, 'table_name');
|
||||
*
|
||||
* @param array|null $items The array of item objects
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(?array $items = null, ?string $table = null): ?array
|
||||
{
|
||||
// check if this is a valid table
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
foreach ($items as $id => &$item)
|
||||
{
|
||||
// model the item
|
||||
if (($item = $this->item($item, $table)) !== null)
|
||||
{
|
||||
// add the last ID
|
||||
$this->last[$table] = $item->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($items[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last modeled ID
|
||||
* Example: $this->last('table_name');
|
||||
*
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function last(?string $table = null): ?int
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if ($table && isset($this->last[$table]))
|
||||
{
|
||||
return $this->last[$table];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the values (basic, override in child class)
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param string|null $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function validate(&$value, ?string $field = null, ?string $table = null): bool
|
||||
{
|
||||
// check values
|
||||
if (StringHelper::check($value) || ArrayHelper::check($value, true))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// remove empty values
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table's fields
|
||||
*
|
||||
* @param string $table The table
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTableFields(string $table): ?array
|
||||
{
|
||||
return $this->table->fields($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract protected function getTable(): string;
|
||||
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ class Gui implements GuiInterface
|
||||
if (is_array($query) && count($query) >= 3)
|
||||
{
|
||||
// cleanup the newlines around the code
|
||||
$code = trim(str_replace($first_line, '', $code), PHP_EOL)
|
||||
$code = trim(str_replace($first_line, '', (string) $code), PHP_EOL)
|
||||
. PHP_EOL;
|
||||
// set the ID
|
||||
$id = (int) $query[2];
|
||||
@ -243,14 +243,9 @@ class Gui implements GuiInterface
|
||||
protected function check(string &$code): bool
|
||||
{
|
||||
// check for customcode placeholders
|
||||
if (strpos($code, '$$$$') !== false)
|
||||
{
|
||||
// we do not add GUI wrapper placeholder to code
|
||||
// that already has any customcode placeholders
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
// we do not add GUI wrapper placeholder to code
|
||||
// that already has any customcode placeholders
|
||||
return strpos($code, '$$$$') === false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class Hash
|
||||
public function set(string $script): string
|
||||
{
|
||||
// check if we should hash a string
|
||||
if (\strpos($script, 'HASH' . 'STRING((((') !== false)
|
||||
if (strpos($script, 'HASH' . 'STRING((((') !== false)
|
||||
{
|
||||
// get the strings
|
||||
$values = GetHelper::allBetween(
|
||||
@ -67,14 +67,14 @@ class Hash
|
||||
foreach ($values as $value)
|
||||
{
|
||||
$locker['HASH' . 'STRING((((' . $value . '))))']
|
||||
= \md5($value);
|
||||
= md5((string) $value);
|
||||
}
|
||||
|
||||
// update the script
|
||||
return $this->placeholder->update($script, $locker);
|
||||
}
|
||||
// check if we should hash a file
|
||||
if (\strpos($script, 'HASH' . 'FILE((((') !== false)
|
||||
if (strpos($script, 'HASH' . 'FILE((((') !== false)
|
||||
{
|
||||
// get the strings
|
||||
$values = GetHelper::allBetween(
|
||||
@ -89,7 +89,7 @@ class Hash
|
||||
{
|
||||
// now we hash the file content
|
||||
$locker['HASH' . 'FILE((((' . $path . '))))']
|
||||
= \md5($value);
|
||||
= md5((string) $value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -69,8 +69,8 @@ class LockBase implements LockBaseInterface
|
||||
$locker['LOCK'.'BASE64((((' . $value . '))))']
|
||||
= "base64_decode( preg_replace('/\s+/', ''," .
|
||||
PHP_EOL . Indent::_(2) . "'" .
|
||||
\wordwrap(
|
||||
\base64_encode($value), 64, PHP_EOL . Indent::_(2), true
|
||||
wordwrap(
|
||||
base64_encode((string) $value), 64, PHP_EOL . Indent::_(2), true
|
||||
) .
|
||||
"'))";
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ class InstallScript implements GetScriptInterface
|
||||
else
|
||||
{
|
||||
// get the flight key
|
||||
$flight = str_replace('php_', '', $method);
|
||||
$flight = str_replace('php_', '', (string) $method);
|
||||
// load the script to our bucket
|
||||
$this->{$flight . 'Bucket'}[$type][] = $extension->{$method . '_' . $type};
|
||||
// show that the method is active
|
||||
|
@ -102,8 +102,8 @@ class Customcode
|
||||
= true;
|
||||
}
|
||||
|
||||
if (strpos($field->javascript_view_footer, "token") !== false
|
||||
|| strpos($field->javascript_view_footer, "task=ajax") !== false)
|
||||
if (strpos((string) $field->javascript_view_footer, "token") !== false
|
||||
|| strpos((string) $field->javascript_view_footer, "task=ajax") !== false)
|
||||
{
|
||||
if (!isset($this->dispenser->hub['token']))
|
||||
{
|
||||
@ -182,8 +182,8 @@ class Customcode
|
||||
{
|
||||
$field->javascript_views_footer_decoded = true;
|
||||
}
|
||||
if (strpos($field->javascript_views_footer, "token") !== false
|
||||
|| strpos($field->javascript_views_footer, "task=ajax") !== false)
|
||||
if (strpos((string) $field->javascript_views_footer, "token") !== false
|
||||
|| strpos((string) $field->javascript_views_footer, "task=ajax") !== false)
|
||||
{
|
||||
if (!isset($this->dispenser->hub['token']))
|
||||
{
|
||||
|
@ -196,7 +196,7 @@ class Data
|
||||
$field->type = $field->fieldtype;
|
||||
|
||||
// load the values form params
|
||||
$field->xml = $this->customcode->update(json_decode($field->xml));
|
||||
$field->xml = $this->customcode->update(json_decode((string) $field->xml));
|
||||
|
||||
// check if we have validate (validation rule and set it if found)
|
||||
$this->validation->set($id, $field->xml);
|
||||
@ -204,7 +204,7 @@ class Data
|
||||
// load the type values form type params
|
||||
$field->properties = (isset($field->properties)
|
||||
&& JsonHelper::check($field->properties))
|
||||
? json_decode($field->properties, true) : null;
|
||||
? json_decode((string) $field->properties, true) : null;
|
||||
if (ArrayHelper::check($field->properties))
|
||||
{
|
||||
$field->properties = array_values($field->properties);
|
||||
@ -243,13 +243,13 @@ class Data
|
||||
))
|
||||
{
|
||||
$field->initiator_save_key = md5(
|
||||
$field->initiator_on_save_model
|
||||
(string) $field->initiator_on_save_model
|
||||
);
|
||||
$field->initiator_save = explode(
|
||||
PHP_EOL, $this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$field->initiator_on_save_model
|
||||
(string) $field->initiator_on_save_model
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -260,13 +260,13 @@ class Data
|
||||
))
|
||||
{
|
||||
$field->initiator_get_key = md5(
|
||||
$field->initiator_on_get_model
|
||||
(string) $field->initiator_on_get_model
|
||||
);
|
||||
$field->initiator_get = explode(
|
||||
PHP_EOL, $this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$field->initiator_on_get_model
|
||||
(string) $field->initiator_on_get_model
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -276,14 +276,14 @@ class Data
|
||||
$field->model_field['save'] = explode(
|
||||
PHP_EOL, $this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode($field->on_save_model_field)
|
||||
base64_decode((string) $field->on_save_model_field)
|
||||
)
|
||||
)
|
||||
);
|
||||
$field->model_field['get'] = explode(
|
||||
PHP_EOL, $this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode($field->on_get_model_field)
|
||||
base64_decode((string) $field->on_get_model_field)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -88,7 +88,7 @@ class CoreValidation implements CoreValidationInterface
|
||||
}
|
||||
|
||||
// remove the Rule.php from the name
|
||||
$this->rules = array_map( function ($name) {
|
||||
$this->rules = array_map( function ($name): string {
|
||||
return str_replace(array('./','Rule.php'), '', $name);
|
||||
}, $rules);
|
||||
}
|
||||
@ -99,7 +99,7 @@ class CoreValidation implements CoreValidationInterface
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
{
|
||||
return array_map( function($item) {
|
||||
return array_map( function($item): string {
|
||||
return strtolower($item);
|
||||
}, $this->rules);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class TypeName
|
||||
))
|
||||
{
|
||||
// search for own custom fields
|
||||
if (strpos($field['settings']->type_name, '@') !== false)
|
||||
if (strpos((string) $field['settings']->type_name, '@') !== false)
|
||||
{
|
||||
// set own custom field
|
||||
$field['settings']->own_custom = $field['settings']->type_name;
|
||||
@ -66,8 +66,8 @@ class TypeName
|
||||
);
|
||||
|
||||
// if custom (we must use the xml value)
|
||||
if (strtolower($type_name) === 'custom'
|
||||
|| strtolower($type_name) === 'customuser')
|
||||
if (strtolower((string) $type_name) === 'custom'
|
||||
|| strtolower((string) $type_name) === 'customuser')
|
||||
{
|
||||
$type = TypeHelper::safe(
|
||||
GetHelper::between(
|
||||
|
@ -133,7 +133,7 @@ class Validation
|
||||
$this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$php_code
|
||||
(string) $php_code
|
||||
)
|
||||
)
|
||||
),
|
||||
|
@ -166,7 +166,7 @@ class History implements HistoryInterface
|
||||
// check the note
|
||||
if (JsonHelper::check($object->version_note))
|
||||
{
|
||||
$version_note = json_decode($object->version_note, true);
|
||||
$version_note = json_decode((string) $object->version_note, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -183,7 +183,7 @@ class History implements HistoryInterface
|
||||
)) !== false)
|
||||
{
|
||||
// last version that was used to build/compile
|
||||
$this->tmp = json_decode($object->version_data);
|
||||
$this->tmp = json_decode((string) $object->version_data);
|
||||
// remove it from this component
|
||||
unset($version_note['component'][$key]);
|
||||
}
|
||||
|
@ -104,13 +104,8 @@ class Extractor
|
||||
{
|
||||
// get targets to search for
|
||||
$lang_string_targets = array_filter(
|
||||
$this->config->lang_string_targets, function ($get) use ($content) {
|
||||
if (strpos($content, $get) !== false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
$this->config->lang_string_targets, function ($get) use ($content): bool {
|
||||
return strpos($content, $get) !== false;
|
||||
}
|
||||
);
|
||||
// check if we should continue
|
||||
|
@ -100,12 +100,7 @@ class Placeholder implements PlaceholderInterface
|
||||
*/
|
||||
public function exist(string $key): bool
|
||||
{
|
||||
if (isset($this->active[$key]) || $this->exist_($key) || $this->exist_h($key))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return isset($this->active[$key]) || $this->exist_($key) || $this->exist_h($key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -193,11 +188,7 @@ class Placeholder implements PlaceholderInterface
|
||||
*/
|
||||
public function exist_(string $key): bool
|
||||
{
|
||||
if (isset($this->active[Placefix::_($key)]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return isset($this->active[Placefix::_($key)]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -274,11 +265,7 @@ class Placeholder implements PlaceholderInterface
|
||||
*/
|
||||
public function exist_h(string $key): bool
|
||||
{
|
||||
if (isset($this->active[Placefix::_h($key)]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return isset($this->active[Placefix::_h($key)]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -401,7 +388,7 @@ class Placeholder implements PlaceholderInterface
|
||||
elseif (2 == $action) // <-- check if data string has placeholders
|
||||
{
|
||||
$replace = false;
|
||||
foreach ($placeholder as $key => $val)
|
||||
foreach (array_keys($placeholder) as $key)
|
||||
{
|
||||
if (strpos($data, $key) !== false)
|
||||
{
|
||||
@ -410,7 +397,7 @@ class Placeholder implements PlaceholderInterface
|
||||
}
|
||||
}
|
||||
// only replace if the data has these placeholder values
|
||||
if ($replace === true)
|
||||
if ($replace)
|
||||
{
|
||||
return str_replace(
|
||||
array_keys($placeholder), array_values($placeholder), $data
|
||||
@ -420,7 +407,7 @@ class Placeholder implements PlaceholderInterface
|
||||
elseif (3 == $action) // <-- remove placeholders not in data string
|
||||
{
|
||||
$replace = $placeholder;
|
||||
foreach ($replace as $key => $val)
|
||||
foreach (array_keys($replace) as $key)
|
||||
{
|
||||
if (strpos($data, $key) === false)
|
||||
{
|
||||
|
@ -99,7 +99,7 @@ class Reverse
|
||||
{
|
||||
// get local code if set
|
||||
if ($id > 0 && $code = base64_decode(
|
||||
GetHelper::var($table, $id, 'id', $field)
|
||||
(string) GetHelper::var($table, $id, 'id', $field)
|
||||
))
|
||||
{
|
||||
$string = $this->setReverse(
|
||||
@ -124,13 +124,9 @@ class Reverse
|
||||
{
|
||||
// get targets to search for
|
||||
$lang_string_targets = array_filter(
|
||||
$this->config->lang_string_targets, function ($get) use ($string) {
|
||||
if (strpos($string, $get) !== false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
$this->config->lang_string_targets,
|
||||
function ($get) use ($string) : bool {
|
||||
return strpos($string, $get) !== false;
|
||||
}
|
||||
);
|
||||
// check if we should continue
|
||||
|
@ -297,7 +297,7 @@ class Power implements PowerInterface
|
||||
$this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$this->active[$guid]->licensing_template
|
||||
(string) $this->active[$guid]->licensing_template
|
||||
)
|
||||
)
|
||||
),
|
||||
@ -321,7 +321,7 @@ class Power implements PowerInterface
|
||||
$this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$this->active[$guid]->head
|
||||
(string) $this->active[$guid]->head
|
||||
)
|
||||
)
|
||||
),
|
||||
@ -351,7 +351,7 @@ class Power implements PowerInterface
|
||||
$this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$this->active[$guid]->main_class_code
|
||||
(string) $this->active[$guid]->main_class_code
|
||||
)
|
||||
)
|
||||
),
|
||||
@ -391,10 +391,10 @@ class Power implements PowerInterface
|
||||
*
|
||||
* @param string $guid The global unique id of the power
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function setNamespace(string $guid)
|
||||
protected function setNamespace(string $guid): bool
|
||||
{
|
||||
// set namespace
|
||||
$this->active[$guid]->namespace = $this->placeholder->update_(
|
||||
@ -407,7 +407,7 @@ class Power implements PowerInterface
|
||||
// we raise an error message
|
||||
$this->app->enqueueMessage(
|
||||
Text::sprintf('COM_COMPONENTBUILDER_HTHREES_NAMESPACE_ERROR_SHTHREEPYOU_MUST_ATLEAST_HAVE_TWO_SECTIONS_IN_YOUR_NAMESPACE_YOU_JUST_HAVE_ONE_THIS_IS_AN_UNACCEPTABLE_ACTION_PLEASE_SEE_A_HREFS_PSRFOURA_FOR_MORE_INFOPPTHIS_S_WAS_THEREFORE_REMOVED_A_HREFSCLICK_HEREA_TO_FIX_THIS_ISSUEP',
|
||||
ucfirst($this->active[$guid]->type), $this->active[$guid]->name, $this->active[$guid]->namespace,
|
||||
ucfirst((string) $this->active[$guid]->type), $this->active[$guid]->name, $this->active[$guid]->namespace,
|
||||
'"https://www.php-fig.org/psr/psr-4/" target="_blank"', $this->active[$guid]->type,
|
||||
$this->fixUrl),
|
||||
'Error'
|
||||
@ -429,7 +429,7 @@ class Power implements PowerInterface
|
||||
// we raise an error message
|
||||
$this->app->enqueueMessage(
|
||||
Text::sprintf('COM_COMPONENTBUILDER_HTHREES_NAMESPACE_ERROR_SHTHREEPYOU_MUST_ATLEAST_HAVE_TWO_SECTIONS_IN_YOUR_NAMESPACE_YOU_JUST_HAVE_ONE_S_THIS_IS_AN_UNACCEPTABLE_ACTION_PLEASE_SEE_A_HREFS_PSRFOURA_FOR_MORE_INFOPPTHIS_S_WAS_THEREFORE_REMOVED_A_HREFSCLICK_HEREA_TO_FIX_THIS_ISSUEP',
|
||||
ucfirst($this->active[$guid]->type), $this->active[$guid]->name, $this->active[$guid]->namespace,
|
||||
ucfirst((string) $this->active[$guid]->type), $this->active[$guid]->name, $this->active[$guid]->namespace,
|
||||
'"https://www.php-fig.org/psr/psr-4/" target="_blank"', $this->active[$guid]->type,
|
||||
$this->fixUrl),
|
||||
'Error'
|
||||
@ -472,7 +472,7 @@ class Power implements PowerInterface
|
||||
// we raise an error message
|
||||
$this->app->enqueueMessage(
|
||||
Text::sprintf('COM_COMPONENTBUILDER_PS_NAMING_MISMATCH_ERROR_SPPTHE_S_NAME_IS_BSB_AND_THE_ENDING_FILE_NAME_IN_THE_NAMESPACE_IS_BSB_THIS_IS_BAD_CONVENTION_PLEASE_SEE_A_HREFS_PSRFOURA_FOR_MORE_INFOPPA_HREFSCLICK_HEREA_TO_FIX_THIS_ISSUEP',
|
||||
ucfirst($this->active[$guid]->type), $this->active[$guid]->name, $this->active[$guid]->type, $this->active[$guid]->class_name, $this->active[$guid]->file_name,
|
||||
ucfirst((string) $this->active[$guid]->type), $this->active[$guid]->name, $this->active[$guid]->type, $this->active[$guid]->class_name, $this->active[$guid]->file_name,
|
||||
'"https://www.php-fig.org/psr/psr-4/" target="_blank"',
|
||||
$this->fixUrl),
|
||||
'Error'
|
||||
@ -533,20 +533,13 @@ class Power implements PowerInterface
|
||||
$this->active[$guid]->use_selection = (isset($this->active[$guid]->use_selection)
|
||||
&& JsonHelper::check(
|
||||
$this->active[$guid]->use_selection
|
||||
)) ? json_decode($this->active[$guid]->use_selection, true) : null;
|
||||
)) ? json_decode((string) $this->active[$guid]->use_selection, true) : null;
|
||||
|
||||
if ($this->active[$guid]->use_selection)
|
||||
{
|
||||
$use = array_values(array_map(function ($u) use(&$as) {
|
||||
// track the AS options
|
||||
if (empty($u['as']))
|
||||
{
|
||||
$as[$u['use']] = 'default';
|
||||
}
|
||||
else
|
||||
{
|
||||
$as[$u['use']] = (string) $u['as'];
|
||||
}
|
||||
$as[$u['use']] = empty($u['as']) ? 'default' : (string) $u['as'];
|
||||
// return the guid
|
||||
return $u['use'];
|
||||
}, $this->active[$guid]->use_selection));
|
||||
@ -567,7 +560,7 @@ class Power implements PowerInterface
|
||||
$this->active[$guid]->load_selection = (isset($this->active[$guid]->load_selection)
|
||||
&& JsonHelper::check(
|
||||
$this->active[$guid]->load_selection
|
||||
)) ? json_decode($this->active[$guid]->load_selection, true) : null;
|
||||
)) ? json_decode((string) $this->active[$guid]->load_selection, true) : null;
|
||||
|
||||
if ($this->active[$guid]->load_selection)
|
||||
{
|
||||
@ -594,7 +587,7 @@ class Power implements PowerInterface
|
||||
$_composer = (isset($this->active[$guid]->composer)
|
||||
&& JsonHelper::check(
|
||||
$this->active[$guid]->composer
|
||||
)) ? json_decode($this->active[$guid]->composer, true) : null;
|
||||
)) ? json_decode((string) $this->active[$guid]->composer, true) : null;
|
||||
|
||||
unset($this->active[$guid]->composer);
|
||||
|
||||
@ -602,46 +595,44 @@ class Power implements PowerInterface
|
||||
{
|
||||
foreach ($_composer as $composer)
|
||||
{
|
||||
if (isset($composer['access_point']) && StringHelper::check($composer['access_point']))
|
||||
if (isset($composer['access_point']) && StringHelper::check($composer['access_point']) &&
|
||||
isset($composer['namespace']) && ArrayHelper::check($composer['namespace']))
|
||||
{
|
||||
if (isset($composer['namespace']) && ArrayHelper::check($composer['namespace']))
|
||||
foreach ($composer['namespace'] as $_namespace)
|
||||
{
|
||||
foreach ($composer['namespace'] as $_namespace)
|
||||
// make sure we have a valid namespace
|
||||
if (isset($_namespace['use']) && StringHelper::check($_namespace['use']) &&
|
||||
strpos((string) $_namespace['use'], '\\') !== false)
|
||||
{
|
||||
// make sure we have a valid namespace
|
||||
if (isset($_namespace['use']) && StringHelper::check($_namespace['use']) &&
|
||||
strpos($_namespace['use'], '\\') !== false)
|
||||
// add the namespace to this access point
|
||||
$as = 'default';
|
||||
if (strpos((string) $_namespace['use'], ' as ') !== false)
|
||||
{
|
||||
// add the namespace to this access point
|
||||
$as = 'default';
|
||||
if (strpos($_namespace['use'], ' as ') !== false)
|
||||
$namespace_as = explode(' as ', (string) $_namespace['use']);
|
||||
// make sure the AS value is set
|
||||
if (count($namespace_as) == 2)
|
||||
{
|
||||
$namespace_as = explode(' as ', $_namespace['use']);
|
||||
// make sure the AS value is set
|
||||
if (count($namespace_as) == 2)
|
||||
{
|
||||
$as = trim(trim($namespace_as[1], ';'));
|
||||
}
|
||||
$namespace = $this->getCleanNamespace($namespace_as[0], false);
|
||||
$as = trim(trim($namespace_as[1], ';'));
|
||||
}
|
||||
else
|
||||
{
|
||||
// trim possible use or ; added to the namespace
|
||||
$namespace = $this->getCleanNamespace($_namespace['use'], false);
|
||||
}
|
||||
|
||||
// check if still valid
|
||||
if (!StringHelper::check($namespace))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// add to the header of the class
|
||||
$this->addToHeader($guid, $this->getUseNamespace($namespace, $as));
|
||||
|
||||
// add composer namespaces for autoloader
|
||||
$this->composer[$namespace] = $composer['access_point'];
|
||||
$namespace = $this->getCleanNamespace($namespace_as[0], false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// trim possible use or ; added to the namespace
|
||||
$namespace = $this->getCleanNamespace($_namespace['use'], false);
|
||||
}
|
||||
|
||||
// check if still valid
|
||||
if (!StringHelper::check($namespace))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// add to the header of the class
|
||||
$this->addToHeader($guid, $this->getUseNamespace($namespace, $as));
|
||||
|
||||
// add composer namespaces for autoloader
|
||||
$this->composer[$namespace] = $composer['access_point'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -667,7 +658,7 @@ class Power implements PowerInterface
|
||||
$this->active[$guid]->implements = (isset($this->active[$guid]->implements)
|
||||
&& JsonHelper::check(
|
||||
$this->active[$guid]->implements
|
||||
)) ? json_decode($this->active[$guid]->implements, true) : null;
|
||||
)) ? json_decode((string) $this->active[$guid]->implements, true) : null;
|
||||
|
||||
if ($this->active[$guid]->implements)
|
||||
{
|
||||
@ -820,7 +811,7 @@ class Power implements PowerInterface
|
||||
{
|
||||
// check if it is already added manually
|
||||
if (isset($this->active[$guid]->head) &&
|
||||
strpos($this->active[$guid]->head, $string) === false)
|
||||
strpos((string) $this->active[$guid]->head, $string) === false)
|
||||
{
|
||||
$this->active[$guid]->head .= $string . PHP_EOL;
|
||||
}
|
||||
|
@ -166,10 +166,10 @@ class Infusion
|
||||
if (StringHelper::check($power->description))
|
||||
{
|
||||
// check if this is escaped
|
||||
if (strpos($power->description, '/*') === false)
|
||||
if (strpos((string) $power->description, '/*') === false)
|
||||
{
|
||||
// make this description escaped
|
||||
$power->description = '/**' . PHP_EOL . ' * ' . implode(PHP_EOL . ' * ', explode(PHP_EOL, $power->description)) . PHP_EOL . ' */';
|
||||
$power->description = '/**' . PHP_EOL . ' * ' . implode(PHP_EOL . ' * ', explode(PHP_EOL, (string) $power->description)) . PHP_EOL . ' */';
|
||||
}
|
||||
$code[] = PHP_EOL . $power->description;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class Registry extends BaseRegistry
|
||||
// convert all array to []
|
||||
$array = preg_split("/\r\n|\n|\r/", $data);
|
||||
$array = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [NULL, ']$1', ' => ['], $array);
|
||||
$data = join(PHP_EOL, array_filter(["["] + $array));
|
||||
$data = implode(PHP_EOL, array_filter(["["] + $array));
|
||||
|
||||
// add needed indentation to the last ]
|
||||
$data = preg_replace("/^(\])/m", Indent::_($default) . '$1', $data);
|
||||
@ -88,7 +88,7 @@ class Registry extends BaseRegistry
|
||||
// update each found space (group) with one indentation
|
||||
foreach (range(1, 11) as $space)
|
||||
{
|
||||
if (strlen($matches[$space]) > 0)
|
||||
if (strlen((string) $matches[$space]) > 0)
|
||||
{
|
||||
$indent .= Indent::_(1);
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
<?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\Componentbuilder\Compiler\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Database\Load;
|
||||
use VDM\Joomla\Componentbuilder\Database\Insert;
|
||||
|
||||
|
||||
/**
|
||||
* Database Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Database implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(Load::class, 'Load')
|
||||
->share('Load', [$this, 'getLoad'], true);
|
||||
|
||||
$container->alias(Insert::class, 'Insert')
|
||||
->share('Insert', [$this, 'getInsert'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Core Load Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Load
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getLoad(Container $container): Load
|
||||
{
|
||||
return new Load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Core Insert Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Insert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getInsert(Container $container): Insert
|
||||
{
|
||||
return new Insert();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
<?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\Componentbuilder\Compiler\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Server\Model\Load as ServerLoad;
|
||||
|
||||
|
||||
/**
|
||||
* Model Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Model implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(ServerLoad::class, 'Model.Server.Load')
|
||||
->share('Model.Server.Load', [$this, 'getServerLoad'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server Model Server Loader class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return ServerLoad
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getServerLoad(Container $container): ServerLoad
|
||||
{
|
||||
return new ServerLoad(
|
||||
$container->get('Crypt'),
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,9 +51,9 @@ abstract class Path
|
||||
}
|
||||
}
|
||||
// if just a string
|
||||
elseif (StringHelper::check($values) && strpos($values, '\\') !== false)
|
||||
elseif (StringHelper::check($values) && strpos((string) $values, '\\') !== false)
|
||||
{
|
||||
$values = str_replace('\\', '/', $values);
|
||||
$values = str_replace('\\', '/', (string) $values);
|
||||
}
|
||||
}
|
||||
|
||||
|
153
libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Crypt.php
Normal file
153
libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Crypt.php
Normal file
@ -0,0 +1,153 @@
|
||||
<?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\Componentbuilder;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Crypt\FOF;
|
||||
use VDM\Joomla\Componentbuilder\Crypt\Password;
|
||||
|
||||
|
||||
/**
|
||||
* Crypto Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Crypt
|
||||
{
|
||||
/**
|
||||
* The Crypt AES FOF class
|
||||
* replacement class
|
||||
*
|
||||
* @var FOF
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected FOF $fof;
|
||||
|
||||
/**
|
||||
* The Password class
|
||||
*
|
||||
* @var Password
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Password $password;
|
||||
|
||||
/**
|
||||
* Active encryption options
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $options = ['basic' => true, 'medium' => true];
|
||||
|
||||
/**
|
||||
* Active passwords
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $passwords = ['basic' => null, 'medium' => null];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param FOF $fof The FOF class
|
||||
* @param Password $password The Password class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(FOF $fof, Password $password)
|
||||
{
|
||||
$this->fof = $fof;
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt a string as needed
|
||||
*
|
||||
* @param string $string The string to encrypt
|
||||
* @param string $method The encryption method to use
|
||||
* @param string|null $default The default password
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function encrypt(string $string, string $method,
|
||||
?string $default = null): string
|
||||
{
|
||||
if (($password = $this->getPassword($method, $default)) !== null)
|
||||
{
|
||||
return $this->fof->encrypt($string, $password);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt a string as needed
|
||||
*
|
||||
* @param string $string The string to decrypt
|
||||
* @param string $method The encryption method to use
|
||||
* @param string|null $default The default password
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function decrypt(string $string, string $method,
|
||||
?string $default = null): string
|
||||
{
|
||||
if (($password = $this->getPassword($method, $default)) !== null)
|
||||
{
|
||||
return $this->fof->decrypt($string, $password);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a decryption method exist and is supported
|
||||
*
|
||||
* @param string $method The encryption method to find
|
||||
*
|
||||
* @return bool true it it exist
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function exist(string $method): bool
|
||||
{
|
||||
return $this->options[$method] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the password
|
||||
*
|
||||
* @param string $method The encryption method to find
|
||||
* @param string|null $default The default password
|
||||
*
|
||||
* @return string|null the password or null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function getPassword(string $method, ?string $default = null): ?string
|
||||
{
|
||||
if ($this->exist($method))
|
||||
{
|
||||
if (empty($this->passwords[$method]))
|
||||
{
|
||||
$this->passwords[$method] = $this->password->get($method, $default);
|
||||
}
|
||||
|
||||
return $this->passwords[$method];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,204 @@
|
||||
<?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\Componentbuilder\Crypt;
|
||||
|
||||
|
||||
use phpseclib3\Crypt\AES;
|
||||
use VDM\Joomla\Componentbuilder\Crypt\Random;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\Cryptinterface;
|
||||
|
||||
|
||||
/**
|
||||
* Replacement Class for FOFEncryptAes
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class FOF implements Cryptinterface
|
||||
{
|
||||
/**
|
||||
* The Aes class
|
||||
*
|
||||
* @var AES
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected AES $aes;
|
||||
|
||||
/**
|
||||
* The Random class
|
||||
*
|
||||
* @var Random
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Random $random;
|
||||
|
||||
/**
|
||||
* The block size
|
||||
*
|
||||
* @var int
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected int $size = 128;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param AES $aes The Aes class
|
||||
* @param Random $random The Random class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(AES $aes, Random $random)
|
||||
{
|
||||
$this->aes = $aes;
|
||||
$this->random = $random;
|
||||
|
||||
// we set the length once
|
||||
$this->aes->setKeyLength($this->size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt a string as needed
|
||||
*
|
||||
* @param string $string The string to encrypt
|
||||
* @param string $key The encryption key
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function encrypt(string $string, string $key): string
|
||||
{
|
||||
// we get the IV length
|
||||
$iv_length = (int) $this->aes->getBlockLength() >> 3;
|
||||
|
||||
// get the IV value
|
||||
$iv = $this->random::string($iv_length);
|
||||
// Load the IV
|
||||
$this->aes->setIV($iv);
|
||||
|
||||
// load the key
|
||||
$this->aes->setKey($this->getExpandedKey($key, $iv_length, $iv));
|
||||
|
||||
// encrypt the string, and base 64 encode the result
|
||||
return base64_encode($iv . $this->aes->encrypt($string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt a string as needed
|
||||
*
|
||||
* @param string $string The string to decrypt
|
||||
* @param string $key The decryption key
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function decrypt(string $string, string $key): string
|
||||
{
|
||||
// we get the IV length
|
||||
$iv_length = (int) $this->aes->getBlockLength() >> 3;
|
||||
|
||||
// remove base 64 encoding
|
||||
$string = base64_decode($string);
|
||||
|
||||
// get the IV
|
||||
$iv = substr($string, 0, $iv_length);
|
||||
// remove the IV
|
||||
$string = substr($string, $iv_length);
|
||||
|
||||
// set the key
|
||||
$this->aes->setKey($this->getExpandedKey($key, $iv_length, $iv));
|
||||
|
||||
// set the IV
|
||||
$this->aes->setIV($iv);
|
||||
|
||||
return $this->aes->decrypt($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function taken from FOFEncryptAes
|
||||
* changed a little but basically the same
|
||||
* to ensure we get the same passwords (not ideal)
|
||||
* we should use `$this->aes->setPassword(...)` instead
|
||||
* but can't for backwards compatibility issues with already encrypted string
|
||||
*
|
||||
* @param string $key The key to expand
|
||||
* @param int $blockSize The size of the block
|
||||
* @param string $iv The IV used
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getExpandedKey(string $key, int $blockSize, string $iv): string
|
||||
{
|
||||
$pass_length = strlen($key);
|
||||
|
||||
if (function_exists('mb_strlen'))
|
||||
{
|
||||
$pass_length = mb_strlen($key, 'ASCII');
|
||||
}
|
||||
|
||||
if ($pass_length != $blockSize)
|
||||
{
|
||||
$iterations = 1000;
|
||||
$salt = $this->resizeKey($iv, 16);
|
||||
$key = hash_pbkdf2('sha256', $key, $salt, $iterations, $blockSize, true);
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function taken from FOFEncryptAes
|
||||
* changed a little but basically the same
|
||||
* to ensure we get the same passwords (not ideal)
|
||||
* we should use `$this->aes->setPassword(...)` instead
|
||||
* but can't for backwards compatibility issues with already encrypted string
|
||||
*
|
||||
* @param string $key The key to resize
|
||||
* @param int $size The size of the block
|
||||
*
|
||||
* @return string|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function resizeKey(string $key, int $size): ?string
|
||||
{
|
||||
if (empty($key))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$key_length = strlen($key);
|
||||
|
||||
if (function_exists('mb_strlen'))
|
||||
{
|
||||
$key_length = mb_strlen($key, 'ASCII');
|
||||
}
|
||||
|
||||
if ($key_length == $size)
|
||||
{
|
||||
return $key;
|
||||
}
|
||||
|
||||
if ($key_length > $size)
|
||||
{
|
||||
if (function_exists('mb_substr'))
|
||||
{
|
||||
return mb_substr($key, 0, $size, 'ASCII');
|
||||
}
|
||||
|
||||
return substr($key, 0, $size);
|
||||
}
|
||||
|
||||
return $key . str_repeat("\0", ($size - $key_length));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
<?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\Componentbuilder\Crypt;
|
||||
|
||||
|
||||
use phpseclib3\Crypt\PublicKeyLoader;
|
||||
|
||||
|
||||
/**
|
||||
* KeyLoader Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class KeyLoader extends PublicKeyLoader
|
||||
{
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
<?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\Componentbuilder\Crypt;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
|
||||
|
||||
/**
|
||||
* Password Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Password
|
||||
{
|
||||
/**
|
||||
* Get the type of password
|
||||
* Example: $this->get('basic', 'default-password');
|
||||
*
|
||||
* @param string $type The value of password to get
|
||||
* @param string|null $default The default password if the type is not found
|
||||
*
|
||||
* @return string|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $type, ?string $default = null): ?string
|
||||
{
|
||||
if (($password = Helper::_('getCryptKey', [$type, $default])) !== null)
|
||||
{
|
||||
return $password;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
<?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\Componentbuilder\Crypt;
|
||||
|
||||
|
||||
use phpseclib3\Crypt\Random as CryptRandom;
|
||||
|
||||
|
||||
/**
|
||||
* Random Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Random extends CryptRandom
|
||||
{
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@ -194,14 +194,7 @@ class Insert extends Database implements InsertInterface
|
||||
// load only what is part of the columns set
|
||||
foreach ($columns as $key)
|
||||
{
|
||||
if (isset($value->{$key}))
|
||||
{
|
||||
$row[] = $this->quote($value->{$key});
|
||||
}
|
||||
else
|
||||
{
|
||||
$row[] = '';
|
||||
}
|
||||
$row[] = isset($value->{$key}) ? $this->quote($value->{$key}) : '';
|
||||
}
|
||||
|
||||
// add to query
|
||||
|
@ -0,0 +1,43 @@
|
||||
<?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\Componentbuilder\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* The Crypt Interface
|
||||
*/
|
||||
interface Cryptinterface
|
||||
{
|
||||
/**
|
||||
* Encrypt a string as needed
|
||||
*
|
||||
* @param string $string The string to encrypt
|
||||
* @param string $key The encryption key
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function encrypt(string $string, string $key): string;
|
||||
|
||||
/**
|
||||
* Decrypt a string as needed
|
||||
*
|
||||
* @param string $string The string to decrypt
|
||||
* @param string $key The decryption key
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function decrypt(string $string, string $key): string;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
<?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\Componentbuilder\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Model Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface ModelInterface
|
||||
{
|
||||
/**
|
||||
* Model the value
|
||||
* Example: $this->value(value, 'value_key', 'table_name');
|
||||
*
|
||||
* @param mixed $value The value to model
|
||||
* @param string $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function value($value, string $field, ?string $table = null);
|
||||
|
||||
/**
|
||||
* Model the values of an item
|
||||
* Example: $this->item(Object, 'table_name');
|
||||
*
|
||||
* @param object $item The item object
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(object $item, ?string $table = null): ?object;
|
||||
|
||||
/**
|
||||
* Model the values of multiple items
|
||||
* Example: $this->items(Array, 'table_name');
|
||||
*
|
||||
* @param array|null $items The array of item objects
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(?array $items = null, ?string $table = null): ?array;
|
||||
|
||||
/**
|
||||
* Get last modeled ID
|
||||
* Example: $this->last('table_name');
|
||||
*
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function last(?string $table = null): ?int;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
<?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\Componentbuilder\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* The Core Server Interface
|
||||
*/
|
||||
interface Serverinterface
|
||||
{
|
||||
/**
|
||||
* set the server details
|
||||
*
|
||||
* @param object $details The server details
|
||||
*
|
||||
* @return self
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function set(object $details);
|
||||
|
||||
/**
|
||||
* move a file to server with the FTP client
|
||||
*
|
||||
* @param string $localPath The full local path to the file
|
||||
* @param string $fileName The file name
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function move(string $localPath, string $fileName): bool;
|
||||
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ class Insert
|
||||
$success = true;
|
||||
foreach ($items as $item)
|
||||
{
|
||||
if ($this->item($item, $table) !== true)
|
||||
if (!$this->item($item, $table))
|
||||
{
|
||||
$success = false;
|
||||
break;
|
||||
|
@ -117,7 +117,7 @@ abstract class Engine
|
||||
protected function lineCounter()
|
||||
{
|
||||
// we count every line we search
|
||||
$this->config->line_counter = $this->config->line_counter + 1;
|
||||
$this->config->line_counter += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,8 +404,8 @@ class Agent
|
||||
'&match_case=' . (int) $this->config->match_case .
|
||||
'&whole_word=' . (int) $this->config->whole_word .
|
||||
'®ex_search=' . (int) $this->config->regex_search .
|
||||
'&search_value=' . (string) urlencode($this->config->search_value) .
|
||||
'&replace_value=' . (string) urlencode($this->config->replace_value)));
|
||||
'&search_value=' . (string) urlencode((string) $this->config->search_value) .
|
||||
'&replace_value=' . (string) urlencode((string) $this->config->replace_value)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,51 +167,39 @@ class Search implements SearchInterface
|
||||
// forth layer
|
||||
foreach ($ro as $k => $r)
|
||||
{
|
||||
if (StringHelper::check($r))
|
||||
if (StringHelper::check($r) && ($_found = $this->string($r)) !== null)
|
||||
{
|
||||
if (($_found = $this->string($r)) !== null)
|
||||
foreach ($_found as $_n => $_f)
|
||||
{
|
||||
foreach ($_found as $_n => $_f)
|
||||
{
|
||||
$found[$keys . '.' . $key . '.' . $ke . '.' . $k . '.' . $_n] = $_f;
|
||||
}
|
||||
$found[$keys . '.' . $key . '.' . $ke . '.' . $k . '.' . $_n] = $_f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (StringHelper::check($ro))
|
||||
elseif (StringHelper::check($ro) && ($_found = $this->string($ro)) !== null)
|
||||
{
|
||||
if (($_found = $this->string($ro)) !== null)
|
||||
foreach ($_found as $_n => $_f)
|
||||
{
|
||||
foreach ($_found as $_n => $_f)
|
||||
{
|
||||
$found[$keys. '.' . $key . '.' . $ke . '.' . $_n] = $_f;
|
||||
}
|
||||
$found[$keys. '.' . $key . '.' . $ke . '.' . $_n] = $_f;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
elseif (StringHelper::check($row))
|
||||
elseif (StringHelper::check($row) && ($_found = $this->string($row)) !== null)
|
||||
{
|
||||
if (($_found = $this->string($row)) !== null)
|
||||
foreach ($_found as $_n => $_f)
|
||||
{
|
||||
foreach ($_found as $_n => $_f)
|
||||
{
|
||||
$found[$keys. '.' . $key . '.' . $_n] = $_f;
|
||||
}
|
||||
$found[$keys. '.' . $key . '.' . $_n] = $_f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (StringHelper::check($rows))
|
||||
elseif (StringHelper::check($rows) && ($_found = $this->string($rows)) !== null)
|
||||
{
|
||||
if (($_found = $this->string($rows)) !== null)
|
||||
foreach ($_found as $_n => $_f)
|
||||
{
|
||||
foreach ($_found as $_n => $_f)
|
||||
{
|
||||
$found[$keys. '.' . $_n] = $_f;
|
||||
}
|
||||
$found[$keys. '.' . $_n] = $_f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -308,7 +296,7 @@ class Search implements SearchInterface
|
||||
protected function fieldCounter()
|
||||
{
|
||||
// we count every field we search
|
||||
$this->config->field_counter = $this->config->field_counter + 1;
|
||||
$this->config->field_counter += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,9 +83,9 @@ class Update
|
||||
// the possibility of updating sub-forms in sub-forms
|
||||
if (ArrayHelper::check($value))
|
||||
{
|
||||
if (strpos($line, '.') !== false)
|
||||
if (strpos((string) $line, '.') !== false)
|
||||
{
|
||||
$line = explode('.', $line);
|
||||
$line = explode('.', (string) $line);
|
||||
}
|
||||
// first layer
|
||||
foreach ($value as $keys => &$rows)
|
||||
|
@ -173,7 +173,7 @@ class Insert implements InsertInterface
|
||||
$success = true;
|
||||
foreach ($items as $item)
|
||||
{
|
||||
if ($this->item($item, $table) !== true)
|
||||
if (!$this->item($item, $table))
|
||||
{
|
||||
$success = false;
|
||||
break;
|
||||
|
@ -75,7 +75,7 @@ class Insert extends Model implements ModelInterface
|
||||
switch($store)
|
||||
{
|
||||
case 'base64':
|
||||
$value = base64_encode($value);
|
||||
$value = base64_encode((string) $value);
|
||||
break;
|
||||
case 'json':
|
||||
$value = json_encode($value, JSON_FORCE_OBJECT);
|
||||
|
@ -77,13 +77,13 @@ class Load extends Model implements ModelInterface
|
||||
switch($store)
|
||||
{
|
||||
case 'base64':
|
||||
$value = base64_decode($value);
|
||||
$value = base64_decode((string) $value);
|
||||
break;
|
||||
case 'json':
|
||||
// check if there is a json string
|
||||
if (JsonHelper::check($value))
|
||||
{
|
||||
$value = json_decode($value, true);
|
||||
$value = json_decode((string) $value, true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
147
libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Server.php
Normal file
147
libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Server.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?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\Componentbuilder;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory as JoomlaFactory;
|
||||
use Joomla\CMS\User\User;
|
||||
use VDM\Joomla\Componentbuilder\Server\Load;
|
||||
use VDM\Joomla\Componentbuilder\Server\Ftp;
|
||||
use VDM\Joomla\Componentbuilder\Server\Sftp;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Server Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Server
|
||||
{
|
||||
/**
|
||||
* The Loader
|
||||
*
|
||||
* @var Load
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The Ftp object
|
||||
*
|
||||
* @var Ftp
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Ftp $ftp;
|
||||
|
||||
/**
|
||||
* The Sftp object
|
||||
*
|
||||
* @var Sftp
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Sftp $sftp;
|
||||
|
||||
/**
|
||||
* Current User object
|
||||
*
|
||||
* @var User
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected User $user;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The server details loader object.
|
||||
* @param Ftp $ftp The server ftp object.
|
||||
* @param Sftp $sftp The server sftp object.
|
||||
* @param User|null $user The user object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Load $load, Ftp $ftp, Sftp $sftp, ?User $user = null)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->ftp = $ftp;
|
||||
$this->sftp = $sftp;
|
||||
$this->user = $user ?: JoomlaFactory::getUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move File to Server
|
||||
*
|
||||
* @param int $id The server local id to use
|
||||
* @param string $localPath The local path to the file
|
||||
* @param string $fileName The actual file name
|
||||
* @param int|null $protocol The protocol to use (if set)
|
||||
* @param string $permission The permission validation area
|
||||
*
|
||||
* @return bool true on success
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function move(int $id, string $localPath, string $fileName,
|
||||
?int $protocol = null, string $permission = 'core.export'): bool
|
||||
{
|
||||
// get the server
|
||||
if ($this->user->authorise($permission, 'com_componentbuilder') &&
|
||||
(
|
||||
(
|
||||
is_numeric($protocol) &&
|
||||
($protocol == 1 || $protocol == 2)
|
||||
) || (
|
||||
($protocol = $this->load->value($id, 'protocol')) !== null &&
|
||||
($protocol == 1 || $protocol == 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
// use the FTP protocol
|
||||
if (1 == $protocol)
|
||||
{
|
||||
$protocol = 'ftp';
|
||||
$fields = [
|
||||
'name',
|
||||
'signature'
|
||||
];
|
||||
}
|
||||
// use the SFTP protocol
|
||||
else
|
||||
{
|
||||
$protocol = 'sftp';
|
||||
$fields = [
|
||||
'name',
|
||||
'authentication',
|
||||
'username',
|
||||
'host',
|
||||
'password',
|
||||
'path',
|
||||
'port',
|
||||
'private',
|
||||
'private_key',
|
||||
'secret'
|
||||
];
|
||||
}
|
||||
|
||||
// get the details
|
||||
if (StringHelper::check($protocol) && ($details = $this->load->item($id, $fields)) !== null)
|
||||
{
|
||||
// now move the file
|
||||
return $this->{$protocol}->set($details)->move($localPath, $fileName);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,139 @@
|
||||
<?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\Componentbuilder\Server;
|
||||
|
||||
|
||||
use Joomla\CMS\Client\FtpClient;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\Serverinterface;
|
||||
|
||||
|
||||
/**
|
||||
* Ftp Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Ftp implements Serverinterface
|
||||
{
|
||||
/**
|
||||
* The client object
|
||||
*
|
||||
* @var FtpClient
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected FtpClient $client;
|
||||
|
||||
/**
|
||||
* The server details
|
||||
*
|
||||
* @var object
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected object $details;
|
||||
|
||||
/**
|
||||
* set the server details
|
||||
*
|
||||
* @param object $details The server details
|
||||
*
|
||||
* @return Ftp
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function set(object $details): Ftp
|
||||
{
|
||||
// set the details
|
||||
$this->details = $details;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* move a file to server with the FTP client
|
||||
*
|
||||
* @param string $localPath The full local path to the file
|
||||
* @param string $fileName The file name
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function move(string $localPath, string $fileName): bool
|
||||
{
|
||||
if ($this->connected())
|
||||
{
|
||||
return $this->client->store($localPath, $fileName);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure we are connected
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function connected(): bool
|
||||
{
|
||||
// check if we have a connection
|
||||
return ($this->client instanceof FtpClient && $this->client->isConnected()) ||
|
||||
($this->client = $this->getClient()) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the FtpClient object
|
||||
*
|
||||
* @return FtpClient|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function getClient(): ?FtpClient
|
||||
{
|
||||
// make sure we have a string and it is not default or empty
|
||||
if (StringHelper::check($this->details->signature))
|
||||
{
|
||||
// turn into variables
|
||||
parse_str((string) $this->details->signature);
|
||||
// set options
|
||||
if (isset($options) && ArrayHelper::check($options))
|
||||
{
|
||||
foreach ($options as $o__p0t1on => $vAln3)
|
||||
{
|
||||
if ('timeout' === $o__p0t1on)
|
||||
{
|
||||
$options[$o__p0t1on] = (int) $vAln3;
|
||||
}
|
||||
if ('type' === $o__p0t1on)
|
||||
{
|
||||
$options[$o__p0t1on] = (string) $vAln3;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$options = array();
|
||||
}
|
||||
// get ftp object
|
||||
if (isset($host) && $host != 'HOSTNAME' &&
|
||||
isset($port) && $port != 'PORT_INT' &&
|
||||
isset($username) && $username != 'user@name.com' &&
|
||||
isset($password) && $password != 'password')
|
||||
{
|
||||
// this is a singleton
|
||||
return FtpClient::getInstance($host, $port, $options, $username, $password);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,122 @@
|
||||
<?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\Componentbuilder\Server;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Database\Load as Database;
|
||||
use VDM\Joomla\Componentbuilder\Server\Model\Load as Model;
|
||||
|
||||
|
||||
/**
|
||||
* Server Load Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Load
|
||||
{
|
||||
/**
|
||||
* Database Load
|
||||
*
|
||||
* @var Database
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Database $db;
|
||||
|
||||
/**
|
||||
* Model Class
|
||||
*
|
||||
* @var Model
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Model $model;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Database|null $db The database object.
|
||||
* @param Model|null $model The core crypt object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Database $db = null, ?Model $model = null)
|
||||
{
|
||||
$this->db = $db ?: Factory::_('Load');
|
||||
$this->model = $model ?: Factory::_('Model.Server.Load');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value from a given server
|
||||
* Example: $this->value(23, 'protocol');
|
||||
*
|
||||
* @param int $id The item ID
|
||||
* @param string $field The table field
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function value(int $id, string $field): ?object
|
||||
{
|
||||
if ($id > 0 && ($value = $this->db->value(
|
||||
$this->setDatabaseFields([$field]), ['a' => 'server'], ['a.id' => $id]
|
||||
)) !== null)
|
||||
{
|
||||
return $this->model->value($value, $field, 'server');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get values from a given server
|
||||
* Example: $this->item(23, ['name', 'of', 'fields']);
|
||||
*
|
||||
* @param int $id The item ID
|
||||
* @param array $fields The table fields
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(int $id, array $fields): ?object
|
||||
{
|
||||
if ($id > 0 && ($item = $this->db->item(
|
||||
$this->setDatabaseFields($fields), ['a' => 'server'], ['a.id' => $id]
|
||||
)) !== null)
|
||||
{
|
||||
return $this->model->item($item, 'server');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Fields ready to use in database call
|
||||
*
|
||||
* @param array $fields The table
|
||||
* @param string $key The table key to which the fields belong
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function setDatabaseFields(array $fields, string $key = 'a'): array
|
||||
{
|
||||
$bucket = [];
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
$bucket[$key . '.' . $field] = $field;
|
||||
}
|
||||
|
||||
return $bucket;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,135 @@
|
||||
<?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\Componentbuilder\Server\Model;
|
||||
|
||||
|
||||
use Joomla\Registry\Registry;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Crypt;
|
||||
use VDM\Joomla\Componentbuilder\Table;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\ModelInterface;
|
||||
use VDM\Joomla\Componentbuilder\Abstraction\Model;
|
||||
|
||||
|
||||
/**
|
||||
* Server Model Load Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Load extends Model implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* Decryption Class
|
||||
*
|
||||
* @var Crypt
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Crypt $crypt;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Crypt|null $crypt The core crypt object.
|
||||
* @param Table|null $table The search table object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Crypt $crypt = null, ?Table $table = null)
|
||||
{
|
||||
parent::__construct($table ?? Factory::_('Table'));
|
||||
|
||||
$this->crypt = $crypt ?: Factory::_('Crypt');
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the value
|
||||
* Example: $this->value(value, 'value_key', 'table_name');
|
||||
*
|
||||
* @param mixed $value The value to model
|
||||
* @param string $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function value($value, string $field, ?string $table = null)
|
||||
{
|
||||
// load the table
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if (StringHelper::check($value) && ($store = $this->table->get($table, $field, 'store')) !== null)
|
||||
{
|
||||
// open the value based on the store method
|
||||
switch($store)
|
||||
{
|
||||
case 'basic_encryption':
|
||||
$value = $this->crypt->decrypt($value, 'basic');
|
||||
break;
|
||||
case 'medium_encryption':
|
||||
$value = $this->crypt->decrypt($value, 'medium');
|
||||
break;
|
||||
case 'base64':
|
||||
$value = base64_decode((string) $value);
|
||||
break;
|
||||
case 'json':
|
||||
// check if there is a json string
|
||||
if (JsonHelper::check($value))
|
||||
{
|
||||
$registry = new Registry;
|
||||
$registry->loadString($value);
|
||||
$value = $registry->toArray();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ($this->crypt->exist($store))
|
||||
{
|
||||
$value = $this->crypt->decrypt($value, $store);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the values (basic, override in child class)
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param string|null $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function validate(&$value, ?string $field = null, ?string $table = null): bool
|
||||
{
|
||||
// remove none
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTable(): string
|
||||
{
|
||||
return 'server';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@ -0,0 +1,185 @@
|
||||
<?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\Componentbuilder\Server;
|
||||
|
||||
|
||||
use phpseclib3\Net\SFTP as SftpClient;
|
||||
use VDM\Joomla\Componentbuilder\Crypt\KeyLoader;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\FileHelper;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\Serverinterface;
|
||||
|
||||
|
||||
/**
|
||||
* Sftp Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Sftp implements Serverinterface
|
||||
{
|
||||
/**
|
||||
* The KeyLoader
|
||||
*
|
||||
* @var KeyLoader
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected KeyLoader $key;
|
||||
|
||||
/**
|
||||
* The client object
|
||||
*
|
||||
* @var SftpClient
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected SftpClient $client;
|
||||
|
||||
/**
|
||||
* The server details
|
||||
*
|
||||
* @var object
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected object $details;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param KeyLoader $key The key loader object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(KeyLoader $key)
|
||||
{
|
||||
$this->key = $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the server details
|
||||
*
|
||||
* @param object $details The server details
|
||||
*
|
||||
* @return Sftp
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function set(object $details): Sftp
|
||||
{
|
||||
// set the details
|
||||
$this->details = $details;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* move a file to server with the FTP client
|
||||
*
|
||||
* @param string $localPath The full local path to the file
|
||||
* @param string $fileName The file name
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function move(string $localPath, string $fileName): bool
|
||||
{
|
||||
if ($this->connected() &&
|
||||
($data = FileHelper::getContent($localPath, null)) !== null)
|
||||
{
|
||||
// get the remote path
|
||||
$path = '';
|
||||
if (isset($this->details->path) &&
|
||||
StringHelper::check($this->details->path) &&
|
||||
$this->details->path !== '/')
|
||||
{
|
||||
$path = '/' . trim((string) $this->details->path, '/');
|
||||
}
|
||||
|
||||
return $this->client->put($path . '/' . $fileName, $data);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the SftpClient object
|
||||
*
|
||||
* @return SftpClient|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function getClient(): ?SftpClient
|
||||
{
|
||||
// make sure we have a host value set
|
||||
if (isset($this->details->host) && StringHelper::check($this->details->host) &&
|
||||
isset($this->details->username) && StringHelper::check($this->details->username))
|
||||
{
|
||||
// insure the port is set
|
||||
$port = (isset($this->details->port) && is_numeric($this->details->port) && $this->details->port > 0)
|
||||
? (int) $this->details->port : 22;
|
||||
|
||||
// open the connection
|
||||
$sftp = new SftpClient($this->details->host, $port);
|
||||
|
||||
// set the passphrase if it exist
|
||||
$passphrase = $this->details->secret ?? null;
|
||||
|
||||
// set the password if it exist
|
||||
$password = $this->details->password ?? null;
|
||||
|
||||
// now login based on authentication type
|
||||
$key = null;
|
||||
switch($this->details->authentication)
|
||||
{
|
||||
case 1: // password
|
||||
$key = $this->details->password ?? null;
|
||||
$password = null;
|
||||
break;
|
||||
case 2: // private key file
|
||||
case 3: // both password and private key file
|
||||
if (isset($this->details->private) && StringHelper::check($this->details->private) &&
|
||||
($private_key = FileHelper::getContent($this->details->private, null)) !== null)
|
||||
{
|
||||
$key = $this->key::load($private_key, $passphrase);
|
||||
}
|
||||
break;
|
||||
case 4: // private key field
|
||||
case 5: // both password and private key field
|
||||
if (isset($this->details->private_key) && StringHelper::check($this->details->private_key))
|
||||
{
|
||||
$key = $this->key::load($this->details->private_key, $passphrase);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// login
|
||||
if ((!empty($key) && !empty($password) && $sftp->login($this->details->username, $key, $password)) ||
|
||||
(!empty($key) && $sftp->login($this->details->username, $key)))
|
||||
{
|
||||
return $sftp;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure we are connected
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function connected(): bool
|
||||
{
|
||||
// check if we have a connection
|
||||
return ($this->client instanceof SftpClient && ($this->client->isConnected() || $this->client->ping())) ||
|
||||
($this->client = $this->getClient()) !== null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@ -20,6 +20,8 @@ use phpseclib3\Crypt\DES;
|
||||
use VDM\Joomla\Componentbuilder\Crypt as Crypto;
|
||||
use VDM\Joomla\Componentbuilder\Crypt\KeyLoader;
|
||||
use VDM\Joomla\Componentbuilder\Crypt\Random;
|
||||
use VDM\Joomla\Componentbuilder\Crypt\Password;
|
||||
use VDM\Joomla\Componentbuilder\Crypt\FOF;
|
||||
|
||||
|
||||
/**
|
||||
@ -45,6 +47,12 @@ class Crypt implements ServiceProviderInterface
|
||||
$container->alias(Random::class, 'Crypt.Random')
|
||||
->share('Crypt.Random', [$this, 'getRandom'], true);
|
||||
|
||||
$container->alias(Password::class, 'Crypt.Password')
|
||||
->share('Crypt.Password', [$this, 'getPassword'], true);
|
||||
|
||||
$container->alias(FOF::class, 'Crypt.FOF')
|
||||
->share('Crypt.FOF', [$this, 'getFOF'], true);
|
||||
|
||||
$container->alias(KeyLoader::class, 'Crypt.Key')
|
||||
->share('Crypt.Key', [$this, 'getKeyLoader'], true);
|
||||
|
||||
@ -93,7 +101,23 @@ class Crypt implements ServiceProviderInterface
|
||||
*/
|
||||
public function getCrypt(Container $container): Crypto
|
||||
{
|
||||
return new Crypto();
|
||||
return new Crypto(
|
||||
$container->get('Crypt.FOF'),
|
||||
$container->get('Crypt.Password')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Password class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Password
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getPassword(Container $container): Password
|
||||
{
|
||||
return new Password();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,6 +133,22 @@ class Crypt implements ServiceProviderInterface
|
||||
return new Random();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the FOF AES Cyper with CBC mode
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return FOF
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getFOF(Container $container): FOF
|
||||
{
|
||||
return new FOF(
|
||||
$container->get('Crypt.AES.CBC'),
|
||||
$container->get('Crypt.Random')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the KeyLoader class
|
||||
*
|
||||
|
@ -0,0 +1,114 @@
|
||||
<?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\Componentbuilder\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Server as Client;
|
||||
use VDM\Joomla\Componentbuilder\Server\Load;
|
||||
use VDM\Joomla\Componentbuilder\Server\Ftp;
|
||||
use VDM\Joomla\Componentbuilder\Server\Sftp;
|
||||
|
||||
|
||||
/**
|
||||
* Server Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Server implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(Client::class, 'Server')
|
||||
->share('Server', [$this, 'getServer'], true);
|
||||
|
||||
$container->alias(Load::class, 'Server.Load')
|
||||
->share('Server.Load', [$this, 'getServerLoad'], true);
|
||||
|
||||
$container->alias(Ftp::class, 'Server.FTP')
|
||||
->share('Server.FTP', [$this, 'getServerFtp'], true);
|
||||
$container->alias(Sftp::class, 'Server.SFTP')
|
||||
->share('Server.SFTP', [$this, 'getServerSftp'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server Client class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Client
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getServer(Container $container): Client
|
||||
{
|
||||
return new Client(
|
||||
$container->get('Server.Load'),
|
||||
$container->get('Server.FTP'),
|
||||
$container->get('Server.SFTP')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server Load class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Load
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getServerLoad(Container $container): Load
|
||||
{
|
||||
return new Load(
|
||||
$container->get('Load'),
|
||||
$container->get('Model.Server.Load')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server Ftp class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Ftp
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getServerFtp(Container $container): Ftp
|
||||
{
|
||||
return new Ftp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server Sftp class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Sftp
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getServerSftp(Container $container): Sftp
|
||||
{
|
||||
return new Sftp(
|
||||
$container->get('Crypt.Key')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ abstract class ArrayHelper
|
||||
*
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public static function intersect($a_array, $b_array)
|
||||
public static function intersect($a_array, $b_array): bool
|
||||
{
|
||||
// flip the second array
|
||||
$b_array = array_flip($b_array);
|
||||
|
@ -30,7 +30,7 @@ abstract class Helper
|
||||
* @var string
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static $option;
|
||||
public static string $option;
|
||||
|
||||
/**
|
||||
* The component params list cache
|
||||
@ -38,19 +38,18 @@ abstract class Helper
|
||||
* @var Registry[]
|
||||
* @since 3.0.11
|
||||
*/
|
||||
protected static $params = array();
|
||||
protected static array $params = [];
|
||||
|
||||
/**
|
||||
* Gets the parameter object for the component
|
||||
*
|
||||
* @param string $option The option 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($option = null): Registry
|
||||
public static function getParams(?string $option = null): Registry
|
||||
{
|
||||
// check that we have an option
|
||||
if (empty($option))
|
||||
@ -73,10 +72,9 @@ abstract class Helper
|
||||
* @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($default = 'empty'): ?string
|
||||
public static function getOption(string $default = 'empty'): ?string
|
||||
{
|
||||
if (empty(self::$option))
|
||||
{
|
||||
@ -95,14 +93,13 @@ abstract class Helper
|
||||
/**
|
||||
* Gets the component code name
|
||||
*
|
||||
* @param string $option The option for the component.
|
||||
* @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($option = null, $default = null): ?string
|
||||
public static function getCode(?string $option = null, ?string $default = null): ?string
|
||||
{
|
||||
// check that we have an option
|
||||
if (empty($option))
|
||||
@ -128,7 +125,7 @@ abstract class Helper
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function get($option = null, $default = null): ?string
|
||||
public static function get(string $option = null, string $default = null): ?string
|
||||
{
|
||||
// check that we have an option
|
||||
// and get the code name from it
|
||||
@ -149,25 +146,43 @@ abstract class Helper
|
||||
/**
|
||||
* Check if the helper class of this component has a method
|
||||
*
|
||||
* @param String $method The method name to search for
|
||||
* @param String $option The option for the component.
|
||||
* @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($method, $option = null)
|
||||
public static function methodExists(string $method, string $option = null): bool
|
||||
{
|
||||
// get the helper class
|
||||
if (($helper = self::get($option, false)) !== false)
|
||||
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))
|
||||
{
|
||||
if (method_exists($helper, $method))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// we know this is bad...
|
||||
// so we need to move these
|
||||
// functions to their own classes
|
||||
return call_user_func_array([$helper, $method], $arguments);
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,12 +39,12 @@ abstract class GuidHelper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function get($trim = true)
|
||||
public static function get(bool $trim = true): string
|
||||
{
|
||||
// Windows
|
||||
if (function_exists('com_create_guid') === true)
|
||||
if (function_exists('com_create_guid'))
|
||||
{
|
||||
if ($trim === true)
|
||||
if ($trim)
|
||||
{
|
||||
return trim(com_create_guid(), '{}');
|
||||
}
|
||||
@ -56,7 +56,7 @@ abstract class GuidHelper
|
||||
$rbrace = $trim ? "" : chr(125); // "}"
|
||||
|
||||
// OSX/Linux
|
||||
if (function_exists('openssl_random_pseudo_bytes') === true)
|
||||
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
|
||||
@ -82,7 +82,7 @@ abstract class GuidHelper
|
||||
* Validate the Globally Unique Identifier ( and check if table already has this identifier)
|
||||
*
|
||||
* @param string $guid
|
||||
* @param string $table
|
||||
* @param string|null $table
|
||||
* @param int $id
|
||||
* @param string|null $component
|
||||
*
|
||||
@ -90,7 +90,7 @@ abstract class GuidHelper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function valid($guid, $table = null, $id = 0, $component = null)
|
||||
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))
|
||||
@ -135,56 +135,53 @@ abstract class GuidHelper
|
||||
*
|
||||
* @param string $guid
|
||||
* @param string $table
|
||||
* @param string/array $what
|
||||
* @param string|array $what
|
||||
* @param string|null $component
|
||||
*
|
||||
* @return mix
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function item($guid, $table, $what = 'a.id', $component = null)
|
||||
public static function item($guid, $table, $what = 'a.id', ?string $component = null)
|
||||
{
|
||||
// check if we have a string
|
||||
if (self::validate($guid))
|
||||
// check if table already has this identifier
|
||||
if (self::validate($guid) && StringHelper::check($table))
|
||||
{
|
||||
// check if table already has this identifier
|
||||
if (StringHelper::check($table))
|
||||
// check that we have the component code name
|
||||
if (!is_string($component))
|
||||
{
|
||||
// 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);
|
||||
$component = (string) Helper::getCode();
|
||||
}
|
||||
// Get the database object and a new query object.
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
if (ArrayHelper::check($what))
|
||||
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.*')
|
||||
{
|
||||
$query->select($db->quoteName($what));
|
||||
return $db->loadObject();
|
||||
}
|
||||
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 $db->loadResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ abstract class JsonHelper
|
||||
{
|
||||
if (StringHelper::check($string))
|
||||
{
|
||||
json_decode($string);
|
||||
json_decode((string) $string);
|
||||
return (json_last_error() === JSON_ERROR_NONE);
|
||||
}
|
||||
|
||||
@ -52,14 +52,14 @@ abstract class JsonHelper
|
||||
{
|
||||
// do some table foot work
|
||||
$external = false;
|
||||
if (strpos($table, '#__') !== false)
|
||||
if (is_string($table) && strpos((string) $table, '#__') !== false)
|
||||
{
|
||||
$external = true;
|
||||
$table = str_replace('#__', '', $table);
|
||||
$table = str_replace('#__', '', (string) $table);
|
||||
}
|
||||
|
||||
// check if string is JSON
|
||||
$result = json_decode($value, true);
|
||||
$result = json_decode((string) $value, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE)
|
||||
{
|
||||
// is JSON
|
||||
@ -92,7 +92,7 @@ abstract class JsonHelper
|
||||
}
|
||||
return (string) implode($separator, $result);
|
||||
}
|
||||
return (string) json_decode($value);
|
||||
return (string) json_decode((string) $value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
@ -34,13 +34,13 @@ abstract class ClassfunctionHelper
|
||||
public static function safe($name)
|
||||
{
|
||||
// remove numbers if the first character is a number
|
||||
if (is_numeric(substr($name, 0, 1)))
|
||||
if (is_numeric(substr((string) $name, 0, 1)))
|
||||
{
|
||||
$name = StringHelper::numbers($name);
|
||||
}
|
||||
|
||||
// remove all spaces and strange characters
|
||||
return trim(preg_replace("/[^A-Za-z0-9_-]/", '', $name));
|
||||
return trim(preg_replace("/[^A-Za-z0-9_-]/", '', (string) $name));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -57,13 +57,13 @@ abstract class FieldHelper
|
||||
if (StringHelper::check($string))
|
||||
{
|
||||
// check that the first character is not a number
|
||||
if (is_numeric(substr($string, 0, 1)))
|
||||
if (is_numeric(substr((string)$string, 0, 1)))
|
||||
{
|
||||
$string = StringHelper::numbers($string);
|
||||
}
|
||||
|
||||
// remove all other strange characters
|
||||
$string = trim($string);
|
||||
$string = trim((string) $string);
|
||||
$string = preg_replace('/'.$spacer.'+/', ' ', $string);
|
||||
$string = preg_replace('/\s+/', ' ', $string);
|
||||
|
||||
@ -71,10 +71,10 @@ abstract class FieldHelper
|
||||
$string = StringHelper::transliterate($string);
|
||||
|
||||
// remove all and keep only characters and numbers
|
||||
$string = preg_replace("/[^A-Za-z0-9 ]/", '', $string);
|
||||
$string = preg_replace("/[^A-Za-z0-9 ]/", '', (string) $string);
|
||||
|
||||
// replace white space with underscore (SAFEST OPTION)
|
||||
$string = preg_replace('/\s+/', $spacer, $string);
|
||||
$string = preg_replace('/\s+/', (string) $spacer, $string);
|
||||
|
||||
// return all caps
|
||||
if ($allcap)
|
||||
|
@ -32,7 +32,7 @@ abstract class NamespaceHelper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safe(string $string, bool $removeNumbers = true)
|
||||
public static function safe(string $string, bool $removeNumbers = true): string
|
||||
{
|
||||
// 0nly continue if we have a string with length
|
||||
if (StringHelper::check($string))
|
||||
@ -47,7 +47,7 @@ abstract class NamespaceHelper
|
||||
// $string = StringHelper::transliterate($string);
|
||||
|
||||
// first remove all [\] backslashes
|
||||
$string = str_replace('\\', '+', $string);
|
||||
$string = str_replace('\\', '+', (string) $string);
|
||||
|
||||
// remove all and keep only characters and [\] backslashes inside of the string
|
||||
if ($removeNumbers)
|
||||
|
@ -29,7 +29,7 @@ abstract class PluginHelper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeFolderName($codeName, $group)
|
||||
public static function safeFolderName(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
@ -52,7 +52,7 @@ abstract class PluginHelper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeClassName($codeName, $group)
|
||||
public static function safeClassName(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
@ -75,7 +75,7 @@ abstract class PluginHelper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeInstallClassName($codeName, $group)
|
||||
public static function safeInstallClassName(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
@ -98,7 +98,7 @@ abstract class PluginHelper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeLangPrefix($codeName, $group)
|
||||
public static function safeLangPrefix(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
|
@ -65,7 +65,7 @@ abstract class TypeHelper
|
||||
$string = StringHelper::transliterate($string);
|
||||
|
||||
// remove all and keep only characters and numbers and point (TODO just one point)
|
||||
$string = trim(preg_replace("/[^A-Za-z0-9\.]/", '', $string));
|
||||
$string = trim(preg_replace("/[^A-Za-z0-9\.]/", '', (string) $string));
|
||||
|
||||
// best is to return lower (for all string equality in compiler)
|
||||
return strtolower($string);
|
||||
|
@ -44,12 +44,7 @@ abstract class StringHelper
|
||||
*/
|
||||
public static function check($string): bool
|
||||
{
|
||||
if (is_string($string) && strlen($string) > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return is_string($string) && strlen($string) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,8 +60,8 @@ abstract class StringHelper
|
||||
{
|
||||
if (self::check($string))
|
||||
{
|
||||
$initial = strlen($string);
|
||||
$words = preg_split('/([\s\n\r]+)/', $string, null, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$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;
|
||||
@ -82,12 +77,12 @@ abstract class StringHelper
|
||||
|
||||
$newString = implode(array_slice($words, 0, $last_word));
|
||||
$final = strlen($newString);
|
||||
if ($initial != $final && $addTip)
|
||||
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)
|
||||
elseif ($initial !== $final && !$addTip)
|
||||
{
|
||||
return trim($newString) . '...';
|
||||
}
|
||||
@ -118,7 +113,7 @@ abstract class StringHelper
|
||||
if ($type === 'filename')
|
||||
{
|
||||
// make sure VDM is not in the string
|
||||
$string = str_replace('VDM', 'vDm', $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
|
||||
@ -131,7 +126,7 @@ abstract class StringHelper
|
||||
return preg_replace('/\s+/', ' ', $string);
|
||||
}
|
||||
// remove all other characters
|
||||
$string = trim($string);
|
||||
$string = trim((string) $string);
|
||||
$string = preg_replace('/'.$spacer.'+/', ' ', $string);
|
||||
$string = preg_replace('/\s+/', ' ', $string);
|
||||
// Transliterate string
|
||||
@ -150,7 +145,7 @@ abstract class StringHelper
|
||||
if ($type === 'L' || $type === 'strtolower')
|
||||
{
|
||||
// replace white space with underscore
|
||||
$string = preg_replace('/\s+/', $spacer, $string);
|
||||
$string = preg_replace('/\s+/', (string) $spacer, $string);
|
||||
// default is to return lower
|
||||
return strtolower($string);
|
||||
}
|
||||
@ -177,14 +172,14 @@ abstract class StringHelper
|
||||
elseif ($type === 'U' || $type === 'strtoupper')
|
||||
{
|
||||
// replace white space with underscore
|
||||
$string = preg_replace('/\s+/', $spacer, $string);
|
||||
$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+/', $spacer, $string);
|
||||
$string = preg_replace('/\s+/', (string) $spacer, $string);
|
||||
// return with first character to upper
|
||||
return ucfirst(strtolower($string));
|
||||
}
|
||||
@ -245,7 +240,7 @@ abstract class StringHelper
|
||||
$string = $filter->clean(
|
||||
html_entity_decode(
|
||||
htmlentities(
|
||||
$var,
|
||||
(string) $var,
|
||||
ENT_COMPAT,
|
||||
$charset
|
||||
)
|
||||
@ -276,21 +271,22 @@ abstract class StringHelper
|
||||
public static function numbers($string)
|
||||
{
|
||||
// set numbers array
|
||||
$numbers = array();
|
||||
$numbers = [];
|
||||
$search_replace= [];
|
||||
|
||||
// first get all numbers
|
||||
preg_match_all('!\d+!', $string, $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)
|
||||
{
|
||||
$searchReplace[$number] = self::number((int)$number);
|
||||
$search_replace[$number] = self::number((int)$number);
|
||||
}
|
||||
|
||||
// now replace numbers in string
|
||||
$string = str_replace(array_keys($searchReplace), array_values($searchReplace), $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);
|
||||
@ -400,7 +396,7 @@ abstract class StringHelper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function random($size)
|
||||
public static function random($size): string
|
||||
{
|
||||
$bag = "abcefghijknopqrstuwxyzABCDDEFGHIJKLLMMNOPQRSTUVVWXYZabcddefghijkllmmnopqrstuvvwxyzABCEFGHIJKNOPQRSTUWXYZ";
|
||||
$key = array();
|
||||
|
@ -2589,7 +2589,11 @@ abstract class SymmetricKey
|
||||
|
||||
$length = ord($text[strlen($text) - 1]);
|
||||
|
||||
if (!$length || $length > $this->block_size) {
|
||||
if (!$length) {
|
||||
// temp fix for FOFEncryptAes conversions
|
||||
// Added by Llewellyn van der Merwe <joomla@vdm.io>
|
||||
return rtrim($text, "\0");
|
||||
} elseif ($length > $this->block_size) {
|
||||
throw new BadDecryptionException("The ciphertext has an invalid padding length ($length) compared to the block size ({$this->block_size})");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user