Release of v5.0.0-alpha8
Add power path override option on component level. Fix the sql build feature. #1032.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,232 @@
|
||||
<?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\Field;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Dispenser;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Customcode
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Customcode
|
||||
{
|
||||
/**
|
||||
* Tracking the update of fields per/view
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $views;
|
||||
|
||||
/**
|
||||
* Compiler Customcode Dispenser
|
||||
*
|
||||
* @var Dispenser
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Dispenser $dispenser;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Dispenser|null $dispenser The compiler customcode dispenser object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Dispenser $dispenser = null)
|
||||
{
|
||||
$this->dispenser = $dispenser ?: Compiler::_('Customcode.Dispenser');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update field customcode
|
||||
*
|
||||
* @param int $id The field id
|
||||
* @param object $field The field object
|
||||
* @param string|null $singleViewName The view edit or single name
|
||||
* @param string|null $listViewName The view list name
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function update(int $id, object &$field, $singleViewName = null, $listViewName = null)
|
||||
{
|
||||
// check if we should load scripts for single view
|
||||
if ($singleViewName && StringHelper::check($singleViewName)
|
||||
&& !isset($this->views[$singleViewName][$id]))
|
||||
{
|
||||
// add_javascript_view_footer
|
||||
if ($field->add_javascript_view_footer == 1
|
||||
&& StringHelper::check(
|
||||
$field->javascript_view_footer
|
||||
))
|
||||
{
|
||||
$convert__ = true;
|
||||
if (isset($field->javascript_view_footer_decoded)
|
||||
&& $field->javascript_view_footer_decoded)
|
||||
{
|
||||
$convert__ = false;
|
||||
}
|
||||
$this->dispenser->set(
|
||||
$field->javascript_view_footer,
|
||||
'view_footer',
|
||||
$singleViewName,
|
||||
null,
|
||||
array(
|
||||
'table' => 'field',
|
||||
'id' => (int) $id,
|
||||
'field' => 'javascript_view_footer',
|
||||
'type' => 'js',
|
||||
'prefix' => PHP_EOL),
|
||||
$convert__,
|
||||
$convert__,
|
||||
true
|
||||
);
|
||||
if (!isset($field->javascript_view_footer_decoded))
|
||||
{
|
||||
$field->javascript_view_footer_decoded
|
||||
= true;
|
||||
}
|
||||
|
||||
if (strpos((string) $field->javascript_view_footer, "token") !== false
|
||||
|| strpos((string) $field->javascript_view_footer, "task=ajax") !== false)
|
||||
{
|
||||
if (!isset($this->dispenser->hub['token']))
|
||||
{
|
||||
$this->dispenser->hub['token'] = [];
|
||||
}
|
||||
if (!isset($this->dispenser->hub['token'][$singleViewName])
|
||||
|| !$this->dispenser->hub['token'][$singleViewName])
|
||||
{
|
||||
$this->dispenser->hub['token'][$singleViewName]
|
||||
= true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add_css_view
|
||||
if ($field->add_css_view == 1)
|
||||
{
|
||||
$convert__ = true;
|
||||
if (isset($field->css_view_decoded)
|
||||
&& $field->css_view_decoded)
|
||||
{
|
||||
$convert__ = false;
|
||||
}
|
||||
$this->dispenser->set(
|
||||
$field->css_view,
|
||||
'css_view',
|
||||
$singleViewName,
|
||||
null,
|
||||
array('prefix' => PHP_EOL),
|
||||
$convert__,
|
||||
$convert__,
|
||||
true
|
||||
);
|
||||
if (!isset($field->css_view_decoded))
|
||||
{
|
||||
$field->css_view_decoded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// add this only once to single view.
|
||||
$this->views[$singleViewName][$id] = true;
|
||||
}
|
||||
|
||||
// check if we should load scripts for list views
|
||||
if ($listViewName && StringHelper::check($listViewName)
|
||||
&& !isset($this->views[$listViewName][$id]))
|
||||
{
|
||||
// add_javascript_views_footer
|
||||
if ($field->add_javascript_views_footer == 1
|
||||
&& StringHelper::check(
|
||||
$field->javascript_views_footer
|
||||
))
|
||||
{
|
||||
$convert__ = true;
|
||||
if (isset($field->javascript_views_footer_decoded)
|
||||
&& $field->javascript_views_footer_decoded)
|
||||
{
|
||||
$convert__ = false;
|
||||
}
|
||||
$this->dispenser->set(
|
||||
$field->javascript_views_footer,
|
||||
'views_footer',
|
||||
$singleViewName,
|
||||
null,
|
||||
array(
|
||||
'table' => 'field',
|
||||
'id' => (int) $id,
|
||||
'field' => 'javascript_views_footer',
|
||||
'type' => 'js',
|
||||
'prefix' => PHP_EOL),
|
||||
$convert__,
|
||||
$convert__,
|
||||
true
|
||||
);
|
||||
if (!isset($field->javascript_views_footer_decoded))
|
||||
{
|
||||
$field->javascript_views_footer_decoded = true;
|
||||
}
|
||||
if (strpos((string) $field->javascript_views_footer, "token") !== false
|
||||
|| strpos((string) $field->javascript_views_footer, "task=ajax") !== false)
|
||||
{
|
||||
if (!isset($this->dispenser->hub['token']))
|
||||
{
|
||||
$this->dispenser->hub['token'] = [];
|
||||
}
|
||||
if (!isset($this->dispenser->hub['token'][$listViewName])
|
||||
|| !$this->dispenser->hub['token'][$listViewName])
|
||||
{
|
||||
$this->dispenser->hub['token'][$listViewName]
|
||||
= true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add_css_views
|
||||
if ($field->add_css_views == 1)
|
||||
{
|
||||
$convert__ = true;
|
||||
if (isset($field->css_views_decoded)
|
||||
&& $field->css_views_decoded)
|
||||
{
|
||||
$convert__ = false;
|
||||
}
|
||||
$this->dispenser->set(
|
||||
$field->css_views,
|
||||
'css_views',
|
||||
$singleViewName,
|
||||
null,
|
||||
array('prefix' => PHP_EOL),
|
||||
$convert__,
|
||||
$convert__,
|
||||
true
|
||||
);
|
||||
if (!isset($field->css_views_decoded))
|
||||
{
|
||||
$field->css_views_decoded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// add this only once to list view.
|
||||
$this->views[$listViewName][$id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,319 @@
|
||||
<?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\Field;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface as Event;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HistoryInterface as History;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\Customcode as FieldCustomcode;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\Rule;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Data
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Data
|
||||
{
|
||||
/**
|
||||
* Compiler Fields
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $fields;
|
||||
|
||||
/**
|
||||
* The Config Class.
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The EventInterface Class.
|
||||
*
|
||||
* @var Event
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Event $event;
|
||||
|
||||
/**
|
||||
* The HistoryInterface Class.
|
||||
*
|
||||
* @var History
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected History $history;
|
||||
|
||||
/**
|
||||
* The Placeholder Class.
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* The Customcode Class.
|
||||
*
|
||||
* @var Customcode
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Customcode $customcode;
|
||||
|
||||
/**
|
||||
* The Customcode Class.
|
||||
*
|
||||
* @var FieldCustomcode
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected FieldCustomcode $fieldcustomcode;
|
||||
|
||||
/**
|
||||
* The Rule Class.
|
||||
*
|
||||
* @var Rule
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Rule $rule;
|
||||
|
||||
/**
|
||||
* The database class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Config $config The Config Class.
|
||||
* @param Event $event The EventInterface Class.
|
||||
* @param History $history The HistoryInterface Class.
|
||||
* @param Placeholder $placeholder The Placeholder Class.
|
||||
* @param Customcode $customcode The Customcode Class.
|
||||
* @param FieldCustomcode $fieldcustomcode The Customcode Class.
|
||||
* @param Rule $rule The Rule Class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Config $config, Event $event, History $history,
|
||||
Placeholder $placeholder, Customcode $customcode,
|
||||
FieldCustomcode $fieldcustomcode, Rule $rule)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->event = $event;
|
||||
$this->history = $history;
|
||||
$this->placeholder = $placeholder;
|
||||
$this->customcode = $customcode;
|
||||
$this->fieldcustomcode = $fieldcustomcode;
|
||||
$this->rule = $rule;
|
||||
$this->db = Factory::getDbo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Field Data
|
||||
*
|
||||
* @param int $id The field ID
|
||||
* @param string|null $singleViewName The view edit or single name
|
||||
* @param string|null $listViewName The view list name
|
||||
*
|
||||
* @return object|null The field data
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(int $id, ?string $singleViewName = null, ?string $listViewName = null): ?object
|
||||
{
|
||||
if ($id > 0 && !isset($this->fields[$id]))
|
||||
{
|
||||
// Create a new query object.
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// Select all the values in the field
|
||||
$query->select('a.*');
|
||||
$query->select(
|
||||
$this->db->quoteName(
|
||||
array('c.name', 'c.properties'),
|
||||
array('type_name', 'properties')
|
||||
)
|
||||
);
|
||||
$query->from('#__componentbuilder_field AS a');
|
||||
$query->join(
|
||||
'LEFT',
|
||||
$this->db->quoteName('#__componentbuilder_fieldtype', 'c')
|
||||
. ' ON (' . $this->db->quoteName('a.fieldtype') . ' = '
|
||||
. $this->db->quoteName('c.id') . ')'
|
||||
);
|
||||
$query->where(
|
||||
$this->db->quoteName('a.id') . ' = ' . $this->db->quote($id)
|
||||
);
|
||||
|
||||
// Trigger Event: jcb_ce_onBeforeQueryFieldData
|
||||
$this->event->trigger(
|
||||
'jcb_ce_onBeforeQueryFieldData', [&$id, &$query, &$this->db]
|
||||
);
|
||||
|
||||
// Reset the query using our newly populated query object.
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
|
||||
$field = $this->db->loadObject();
|
||||
|
||||
// Trigger Event: jcb_ce_onBeforeModelFieldData
|
||||
$this->event->trigger(
|
||||
'jcb_ce_onBeforeModelFieldData', [&$field]
|
||||
);
|
||||
|
||||
// adding a fix for the changed name of type to fieldtype
|
||||
$field->type = $field->fieldtype;
|
||||
|
||||
// load the values form params
|
||||
$field->xml = $this->customcode->update(json_decode((string) $field->xml));
|
||||
|
||||
// check if we have validate (validation rule and set it if found)
|
||||
$this->rule->set($id, $field->xml);
|
||||
|
||||
// load the type values form type params
|
||||
$field->properties = (isset($field->properties)
|
||||
&& JsonHelper::check($field->properties))
|
||||
? json_decode((string) $field->properties, true) : null;
|
||||
if (ArrayHelper::check($field->properties))
|
||||
{
|
||||
$field->properties = array_values($field->properties);
|
||||
}
|
||||
|
||||
// check if we have WHMCS encryption
|
||||
if (4 == $field->store
|
||||
&& !$this->config->whmcs_encryption)
|
||||
{
|
||||
$this->config->whmcs_encryption = true;
|
||||
}
|
||||
// check if we have basic encryption
|
||||
elseif (3 == $field->store
|
||||
&& !$this->config->basic_encryption)
|
||||
{
|
||||
$this->config->basic_encryption = true;
|
||||
}
|
||||
// check if we have better encryption
|
||||
elseif (5 == $field->store
|
||||
&& $this->config->medium_encryption)
|
||||
{
|
||||
$this->config->medium_encryption = true;
|
||||
}
|
||||
// check if we have better encryption
|
||||
elseif (6 == $field->store
|
||||
&& StringHelper::check(
|
||||
$field->on_get_model_field
|
||||
)
|
||||
&& StringHelper::check(
|
||||
$field->on_save_model_field
|
||||
))
|
||||
{
|
||||
// add only if string lenght found
|
||||
if (StringHelper::check(
|
||||
$field->initiator_on_save_model
|
||||
))
|
||||
{
|
||||
$field->initiator_save_key = md5(
|
||||
(string) $field->initiator_on_save_model
|
||||
);
|
||||
$field->initiator_save = explode(
|
||||
PHP_EOL, $this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
(string) $field->initiator_on_save_model
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (StringHelper::check(
|
||||
$field->initiator_on_save_model
|
||||
))
|
||||
{
|
||||
$field->initiator_get_key = md5(
|
||||
(string) $field->initiator_on_get_model
|
||||
);
|
||||
$field->initiator_get = explode(
|
||||
PHP_EOL, $this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
(string) $field->initiator_on_get_model
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
// set the field modelling
|
||||
$field->model_field['save'] = explode(
|
||||
PHP_EOL, $this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode((string) $field->on_save_model_field)
|
||||
)
|
||||
)
|
||||
);
|
||||
$field->model_field['get'] = explode(
|
||||
PHP_EOL, $this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode((string) $field->on_get_model_field)
|
||||
)
|
||||
)
|
||||
);
|
||||
// remove the original values
|
||||
unset(
|
||||
$field->on_save_model_field,
|
||||
$field->on_get_model_field,
|
||||
$field->initiator_on_save_model,
|
||||
$field->initiator_on_get_model
|
||||
);
|
||||
}
|
||||
|
||||
// get the last used version
|
||||
$field->history = $this->history->get('field', $id);
|
||||
|
||||
// Trigger Event: jcb_ce_onAfterModelFieldData
|
||||
$this->event->trigger(
|
||||
'jcb_ce_onAfterModelFieldData', [&$field]
|
||||
);
|
||||
|
||||
$this->fields[$id] = $field;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if ($id > 0 && isset($this->fields[$id]))
|
||||
{
|
||||
// update the customcode of the field
|
||||
$this->fieldcustomcode->update($id, $this->fields[$id], $singleViewName, $listViewName);
|
||||
|
||||
// return the field
|
||||
return $this->fields[$id];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,121 @@
|
||||
<?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\Field;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Builder\Lists;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Registry;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Database Name
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class DatabaseName
|
||||
{
|
||||
/**
|
||||
* The Lists Class.
|
||||
*
|
||||
* @var Lists
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Lists $lists;
|
||||
|
||||
/**
|
||||
* The Registry Class.
|
||||
*
|
||||
* @var Registry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Registry $registry;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Lists $lists The Lists Class.
|
||||
* @param Registry $registry The Registry Class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Lists $lists, Registry $registry)
|
||||
{
|
||||
$this->lists = $lists;
|
||||
$this->registry = $registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the field database name and AS prefix
|
||||
*
|
||||
* @param string $nameListCode The list view name
|
||||
* @param int $fieldId The field ID
|
||||
* @param string $targetArea The area being targeted
|
||||
*
|
||||
* @return string|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $nameListCode, int $fieldId, string $targetArea = 'builder.list'): ?string
|
||||
{
|
||||
if ($targetArea === 'builder.list')
|
||||
{
|
||||
if (($fields = $this->lists->get($nameListCode)) === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
elseif (($fields = $this->registry->get("${targetArea}.${nameListCode}")) === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($fieldId < 0)
|
||||
{
|
||||
switch ($fieldId)
|
||||
{
|
||||
case -1:
|
||||
return 'a.id';
|
||||
case -2:
|
||||
return 'a.ordering';
|
||||
case -3:
|
||||
return 'a.published';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
if ($field['id'] == $fieldId)
|
||||
{
|
||||
// now check if this is a category
|
||||
if ($field['type'] === 'category')
|
||||
{
|
||||
return 'c.title';
|
||||
}
|
||||
// set the custom code
|
||||
elseif (ArrayHelper::check(
|
||||
$field['custom']
|
||||
))
|
||||
{
|
||||
return $field['custom']['db'] . "."
|
||||
. $field['custom']['text'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'a.' . $field['code'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,191 @@
|
||||
<?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\Field;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Groups
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class Groups
|
||||
{
|
||||
/**
|
||||
* Field Grouping https://docs.joomla.org/Form_field
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $groups = [
|
||||
'default' => [
|
||||
'accesslevel', 'cachehandler', 'calendar', 'captcha', 'category', 'checkbox', 'checkboxes', 'chromestyle',
|
||||
'color', 'combo', 'componentlayout', 'contentlanguage', 'contenttype', 'databaseconnection', 'components',
|
||||
'editor', 'editors', 'email', 'file', 'file', 'filelist', 'folderlist', 'groupedlist', 'headertag', 'helpsite', 'hidden', 'imagelist',
|
||||
'integer', 'language', 'list', 'media', 'menu', 'modal_menu', 'menuitem', 'meter', 'modulelayout', 'moduleorder', 'moduleposition',
|
||||
'moduletag', 'note', 'number', 'password', 'plugins', 'predefinedlist', 'radio', 'range', 'repeatable', 'rules',
|
||||
'sessionhandler', 'spacer', 'sql', 'subform', 'tag', 'tel', 'templatestyle', 'text', 'textarea', 'timezone', 'url', 'user', 'usergroup'
|
||||
],
|
||||
'plain' => [
|
||||
'cachehandler', 'calendar', 'checkbox', 'chromestyle', 'color', 'componentlayout', 'contenttype', 'editor', 'editors', 'captcha',
|
||||
'email', 'file', 'headertag', 'helpsite', 'hidden', 'integer', 'language', 'media', 'menu', 'modal_menu', 'menuitem', 'meter', 'modulelayout', 'templatestyle',
|
||||
'moduleorder', 'moduletag', 'number', 'password', 'range', 'rules', 'tag', 'tel', 'text', 'textarea', 'timezone', 'url', 'user', 'usergroup'
|
||||
],
|
||||
'option' => [
|
||||
'accesslevel', 'category', 'checkboxes', 'combo', 'contentlanguage', 'databaseconnection', 'components',
|
||||
'filelist', 'folderlist', 'imagelist', 'list', 'plugins', 'predefinedlist', 'radio', 'sessionhandler', 'sql', 'groupedlist'
|
||||
],
|
||||
'text' => [
|
||||
'calendar', 'color', 'editor', 'email', 'number', 'password', 'range', 'tel', 'text', 'textarea', 'url'
|
||||
],
|
||||
'list' => [
|
||||
'checkbox', 'checkboxes', 'list', 'radio', 'groupedlist', 'combo'
|
||||
],
|
||||
'dynamic' => [
|
||||
'category', 'file', 'filelist', 'folderlist', 'headertag', 'imagelist', 'integer', 'media', 'meter', 'rules', 'tag', 'timezone', 'user'
|
||||
],
|
||||
'spacer' => [
|
||||
'note', 'spacer'
|
||||
],
|
||||
'special' => [
|
||||
'contentlanguage', 'moduleposition', 'plugin', 'repeatable', 'subform'
|
||||
],
|
||||
'search' => [
|
||||
'editor', 'email', 'tel', 'text', 'textarea', 'url', 'subform'
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* Database object to query local DB
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = Factory::getDbo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Field Checker
|
||||
*
|
||||
* @param string $type The field type
|
||||
* @param string $option The field grouping
|
||||
*
|
||||
* @return bool if the field was found
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function check(string $type, string $option = 'default'): bool
|
||||
{
|
||||
// now check
|
||||
if (isset($this->groups[$option]) && in_array($type, $this->groups[$option]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the field types id -> name of a group or groups
|
||||
*
|
||||
* @param array $groups The groups
|
||||
*
|
||||
* @return array|null ids of the spacer field types
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function types(array $groups = []): ?array
|
||||
{
|
||||
// make sure we have a group
|
||||
if (($ids = $this->typesIds($groups)) !== null)
|
||||
{
|
||||
// Create a new query object.
|
||||
$query = $this->db->getQuery(true);
|
||||
$query->select($this->db->quoteName(array('id', 'name')));
|
||||
$query->from($this->db->quoteName('#__componentbuilder_fieldtype'));
|
||||
$query->where($this->db->quoteName('published') . ' = 1');
|
||||
$query->where($this->db->quoteName('id') . ' IN (' . implode(',',$ids) . ')');
|
||||
|
||||
// Reset the query using our newly populated query object.
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
return $this->db->loadAssocList('id', 'name');
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the field types IDs of a group or groups
|
||||
*
|
||||
* @param array $groups The groups
|
||||
*
|
||||
* @return array|null ids of the spacer field types
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function typesIds(array $groups = []): ?array
|
||||
{
|
||||
// make sure we have a group
|
||||
if (ArrayHelper::check($groups))
|
||||
{
|
||||
$merge_groups = [];
|
||||
foreach ($groups as $group)
|
||||
{
|
||||
if (isset($this->groups[$group]))
|
||||
{
|
||||
$merge_groups[] = $this->groups[$group];
|
||||
}
|
||||
}
|
||||
|
||||
// make sure we have these types of groups
|
||||
if (ArrayHelper::check($merge_groups))
|
||||
{
|
||||
// get the database object to use quote
|
||||
return GetHelper::vars(
|
||||
'fieldtype',
|
||||
(array) array_map(function($name) {
|
||||
return $this->db->quote(ucfirst($name));
|
||||
}, ArrayHelper::merge($merge_groups)),
|
||||
'name',
|
||||
'id'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the spacer IDs
|
||||
*
|
||||
* @return array|null ids of the spacer field types
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function spacerIds(): ?array
|
||||
{
|
||||
return $this->typesIds(['spacer']);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,129 @@
|
||||
<?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\Field\JoomlaFive;
|
||||
|
||||
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreFieldInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Core Joomla Fields
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class CoreField implements CoreFieldInterface
|
||||
{
|
||||
/**
|
||||
* Local Core Joomla Fields
|
||||
*
|
||||
* @var array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $fields = [];
|
||||
|
||||
/**
|
||||
* Local Core Joomla Fields Path
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $paths = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// set the path to the form validation fields
|
||||
$this->paths[] = JPATH_LIBRARIES . '/src/Form/Field';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Array of Existing Validation Field Names
|
||||
*
|
||||
* @param bool $lowercase Switch to set fields lowercase
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(bool $lowercase = false): array
|
||||
{
|
||||
if ($this->fields === [])
|
||||
{
|
||||
// check if the path exist
|
||||
foreach ($this->paths as $path)
|
||||
{
|
||||
$this->set($path);
|
||||
}
|
||||
}
|
||||
|
||||
// return fields if found
|
||||
if ($this->fields !== [])
|
||||
{
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
{
|
||||
return array_map(
|
||||
fn($item): string => strtolower((string) $item),
|
||||
$this->fields
|
||||
);
|
||||
}
|
||||
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
// return empty array
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fields found in a path
|
||||
*
|
||||
* @param string $path The path to load fields from
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function set(string $path): void
|
||||
{
|
||||
// Check if the path exists
|
||||
if (!Folder::exists($path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load all PHP files in this path
|
||||
$fields = Folder::files($path, '\.php$', true, true);
|
||||
|
||||
// Process the files to extract field names
|
||||
$processedFields = array_map(function ($name) {
|
||||
$fileName = basename($name);
|
||||
|
||||
// Remove 'Field.php' if it exists or just '.php' otherwise
|
||||
if (substr($fileName, -9) === 'Field.php')
|
||||
{
|
||||
return str_replace('Field.php', '', $fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return str_replace('.php', '', $fileName);
|
||||
}
|
||||
}, $fields);
|
||||
|
||||
// Merge with existing fields and remove duplicates
|
||||
$this->fields = array_unique(array_merge($processedFields, $this->fields));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,125 @@
|
||||
<?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\Field\JoomlaFive;
|
||||
|
||||
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreRuleInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Core Joomla Field Rules
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class CoreRule implements CoreRuleInterface
|
||||
{
|
||||
/**
|
||||
* Local Core Joomla Rules
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $rules = [];
|
||||
|
||||
/**
|
||||
* Local Core Joomla Rules Path
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected string $path;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// set the path to the form validation rules
|
||||
$this->path = JPATH_LIBRARIES . '/src/Form/Rule';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Array of Existing Validation Rule Names
|
||||
*
|
||||
* @param bool $lowercase Switch to set rules lowercase
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(bool $lowercase = false): array
|
||||
{
|
||||
if ($this->rules === [])
|
||||
{
|
||||
$this->set($this->path);
|
||||
}
|
||||
|
||||
// return rules if found
|
||||
if ($this->rules !== [])
|
||||
{
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
{
|
||||
return array_map(
|
||||
fn($item): string => strtolower((string) $item),
|
||||
$this->rules
|
||||
);
|
||||
}
|
||||
|
||||
return $this->rules;
|
||||
}
|
||||
|
||||
// return empty array
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rules found in a path
|
||||
*
|
||||
* @param string $path The path to load rules from
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function set(string $path): void
|
||||
{
|
||||
// Check if the path exists
|
||||
if (!Folder::exists($path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load all PHP files in this path
|
||||
$rules = Folder::files($path, '\.php$', true, true);
|
||||
|
||||
// Process the files to extract rule names
|
||||
$processedRules = array_map(function ($name) {
|
||||
$fileName = basename($name);
|
||||
|
||||
// Remove 'Rule.php' if it exists or just '.php' otherwise
|
||||
if (substr($fileName, -8) === 'Rule.php')
|
||||
{
|
||||
return str_replace('Rule.php', '', $fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return str_replace('.php', '', $fileName);
|
||||
}
|
||||
}, $rules);
|
||||
|
||||
// Merge with existing rules and remove duplicates
|
||||
$this->rules = array_unique(array_merge($processedRules, $this->rules));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,345 @@
|
||||
<?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\Field\JoomlaFive;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Creator\Permission;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\InputButtonInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Input Button
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class InputButton implements InputButtonInterface
|
||||
{
|
||||
/**
|
||||
* The Config Class.
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The Placeholder Class.
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* The Permission Class.
|
||||
*
|
||||
* @var Permission
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Permission $permission;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Config $config The Config Class.
|
||||
* @param Placeholder $placeholder The Placeholder Class.
|
||||
* @param Permission $permission The Permission Class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Config $config, Placeholder $placeholder,
|
||||
Permission $permission)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->placeholder = $placeholder;
|
||||
$this->permission = $permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Add Button To List Field Input (getInput tweak)
|
||||
*
|
||||
* @param array $fieldData The field custom data
|
||||
*
|
||||
* @return string of getInput class on success empty string otherwise
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(array $fieldData): string
|
||||
{
|
||||
// make sure hte view values are set
|
||||
if (isset($fieldData['add_button'])
|
||||
&& ($fieldData['add_button'] === 'true'
|
||||
|| 1 == $fieldData['add_button'])
|
||||
&& isset($fieldData['view'])
|
||||
&& isset($fieldData['views'])
|
||||
&& StringHelper::check($fieldData['view'])
|
||||
&& StringHelper::check($fieldData['views']))
|
||||
{
|
||||
// set local component
|
||||
$local_component = "com_" . $this->config->component_code_name;
|
||||
// check that the component value is set
|
||||
if (!isset($fieldData['component'])
|
||||
|| !StringHelper::check(
|
||||
$fieldData['component']
|
||||
))
|
||||
{
|
||||
$fieldData['component'] = $local_component;
|
||||
}
|
||||
// check that the component has the com_ value in it
|
||||
if (strpos((string) $fieldData['component'], 'com_') === false
|
||||
|| strpos((string) $fieldData['component'], '=') !== false)
|
||||
{
|
||||
$fieldData['component'] = "com_" . $fieldData['component'];
|
||||
}
|
||||
// make sure the component is update if # # # or [ [ [ component placeholder is used
|
||||
if (strpos((string) $fieldData['component'], (string) Placefix::h()) !== false
|
||||
|| strpos((string) $fieldData['component'], (string) Placefix::b()) !== false) // should not be needed... but
|
||||
{
|
||||
$fieldData['component'] = $this->placeholder->update_(
|
||||
$fieldData['component']
|
||||
);
|
||||
}
|
||||
// get core permissions
|
||||
$coreLoad = false;
|
||||
// add ref tags
|
||||
$refLoad = true;
|
||||
// fall back on the field component
|
||||
$component = $fieldData['component'];
|
||||
// check if we should add ref tags (since it only works well on local views)
|
||||
if ($local_component !== $component)
|
||||
{
|
||||
// do not add ref tags
|
||||
$refLoad = false;
|
||||
}
|
||||
// start building the add buttons/s
|
||||
$addButton = array();
|
||||
$addButton[] = PHP_EOL . PHP_EOL . Indent::_(1) . "/**";
|
||||
$addButton[] = Indent::_(1) . " * Override to add new button";
|
||||
$addButton[] = Indent::_(1) . " *";
|
||||
$addButton[] = Indent::_(1)
|
||||
. " * @return string The field input markup.";
|
||||
$addButton[] = Indent::_(1) . " *";
|
||||
$addButton[] = Indent::_(1) . " * @since 3.2";
|
||||
$addButton[] = Indent::_(1) . " */";
|
||||
$addButton[] = Indent::_(1) . "protected function getInput()";
|
||||
$addButton[] = Indent::_(1) . "{";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " see if we should add buttons";
|
||||
$addButton[] = Indent::_(2)
|
||||
. "\$set_button = \$this->getAttribute('button');";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get html";
|
||||
$addButton[] = Indent::_(2) . "\$html = parent::getInput();";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " if true set button";
|
||||
$addButton[] = Indent::_(2) . "if (\$set_button === 'true')";
|
||||
$addButton[] = Indent::_(2) . "{";
|
||||
$addButton[] = Indent::_(3) . "\$button = array();";
|
||||
$addButton[] = Indent::_(3) . "\$script = array();";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_code_name = \$this->getAttribute('name');";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the input from url";
|
||||
$addButton[] = Indent::_(3) . "\$app = Factory::getApplication();";
|
||||
$addButton[] = Indent::_(3) . "\$jinput = \$app->input;";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the view name & id";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$values = \$jinput->getArray(array(";
|
||||
$addButton[] = Indent::_(4) . "'id' => 'int',";
|
||||
$addButton[] = Indent::_(4) . "'view' => 'word'";
|
||||
$addButton[] = Indent::_(3) . "));";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " check if new item";
|
||||
$addButton[] = Indent::_(3) . "\$ref = '';";
|
||||
$addButton[] = Indent::_(3) . "\$refJ = '';";
|
||||
if ($refLoad)
|
||||
{
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (!is_null(\$values['id']) && strlen(\$values['view']))";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only load referral if not new item.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&ref=' . \$values['view'] . '&refid=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&ref=' . \$values['view'] . '&refid=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_uri = (string) \Joomla\CMS\Uri\Uri::getInstance();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_return = urlencode(base64_encode(\$_uri));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " load return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref .= '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ .= '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
}
|
||||
else
|
||||
{
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (!is_null(\$values['id']) && strlen(\$values['view']))";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only load field details if not new item.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&field=' . \$values['view'] . '&field_id=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&field=' . \$values['view'] . '&field_id=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_uri = (string) \Joomla\CMS\Uri\Uri::getInstance();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_return = urlencode(base64_encode(\$_uri));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " load return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
}
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get button label";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = trim(\$button_code_name);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace('/_+/', ' ', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace('/\s+/', ' ', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace(\"/[^A-Za-z ]/\", '', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = ucfirst(strtolower(\$button_label));";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get user object";
|
||||
$addButton[] = Indent::_(3) . "\$user = Factory::getApplication()->getIdentity();";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only add if user allowed to create " . $fieldData['view'];
|
||||
// check if the item has permissions.
|
||||
$addButton[] = Indent::_(3) . "if (\$user->authorise('"
|
||||
. $this->permission->getGlobal($fieldData['view'], 'core.create')
|
||||
. "', '" . $component . "') && \$app->isClient('administrator')) // TODO for now only in admin area.";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build Create button";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$button[] = '<a id=\"'.\$button_code_name.'Create\" class=\"btn btn-small btn-success hasTooltip\" title=\"'.Text:"
|
||||
. ":sprintf('" . $this->config->lang_prefix
|
||||
. "_CREATE_NEW_S', \$button_label).'\" style=\"border-radius: 0px 4px 4px 0px;\"";
|
||||
$addButton[] = Indent::_(5) . "href=\"index.php?option="
|
||||
. $fieldData['component'] . "&view=" . $fieldData['view']
|
||||
. "&layout=edit'.\$ref.'\" >";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "<span class=\"icon-new icon-white\"></span></a>';";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only add if user allowed to edit " . $fieldData['view'];
|
||||
// check if the item has permissions.
|
||||
$addButton[] = Indent::_(3) . "if (\$user->authorise('"
|
||||
. $this->permission->getGlobal($fieldData['view'], 'core.edit')
|
||||
. "', '" . $component . "') && \$app->isClient('administrator')) // TODO for now only in admin area.";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build edit button";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$button[] = '<a id=\"'.\$button_code_name.'Edit\" class=\"btn btn-small btn-outline-success button-select hasTooltip\" title=\"'.Text:"
|
||||
. ":sprintf('" . $this->config->lang_prefix
|
||||
. "_EDIT_S', \$button_label).'\" style=\"display: none; border-radius: 0px 4px 4px 0px;\" href=\"#\" >";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "<span class=\"icon-edit\"></span></a>';";
|
||||
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build script";
|
||||
$addButton[] = Indent::_(4) . "\$script[] = \"";
|
||||
$addButton[] = Indent::_(5) . "document.addEventListener('DOMContentLoaded', function() {";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "document.getElementById('jform_\".\$button_code_name.\"').addEventListener('change', function(e) {";
|
||||
$addButton[] = Indent::_(7) . "e.preventDefault();";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "let \".\$button_code_name.\"Value = this.value;";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "\".\$button_code_name.\"Button(\".\$button_code_name.\"Value);";
|
||||
$addButton[] = Indent::_(6) . "});";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "let \".\$button_code_name.\"Value = document.getElementById('jform_\".\$button_code_name.\"').value;";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "\".\$button_code_name.\"Button(\".\$button_code_name.\"Value);";
|
||||
$addButton[] = Indent::_(5) . "});";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "function \".\$button_code_name.\"Button(value) {";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "var createButton = document.getElementById('\".\$button_code_name.\"Create');";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "var editButton = document.getElementById('\".\$button_code_name.\"Edit');";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "if (value > 0) {"; // TODO not ideal since value may not be an (int)
|
||||
$addButton[] = Indent::_(7) . "// hide the create button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "createButton.style.display = 'none';";
|
||||
$addButton[] = Indent::_(7) . "// show edit button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "editButton.style.display = 'block';";
|
||||
$addButton[] = Indent::_(7) . "let url = 'index.php?option="
|
||||
. $fieldData['component'] . "&view=" . $fieldData['views']
|
||||
. "&task=" . $fieldData['view']
|
||||
. ".edit&id='+value+'\".\$refJ.\"';"; // TODO this value may not be the ID
|
||||
$addButton[] = Indent::_(7)
|
||||
. "editButton.setAttribute('href', url);";
|
||||
$addButton[] = Indent::_(6) . "} else {";
|
||||
$addButton[] = Indent::_(7) . "// show the create button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "createButton.style.display = 'block';";
|
||||
$addButton[] = Indent::_(7) . "// hide edit button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "editButton.style.display = 'none';";
|
||||
$addButton[] = Indent::_(6) . "}";
|
||||
$addButton[] = Indent::_(5) . "}\";";
|
||||
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " check if button was created for " . $fieldData['view']
|
||||
. " field.";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (is_array(\$button) && count(\$button) > 0)";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " Load the needed script.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$document = Factory::getApplication()->getDocument();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$document->addScriptDeclaration(implode(' ',\$script));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " return the button attached to input field.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "return '<div class=\"input-group\">' .\$html . implode('',\$button).'</div>';";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(2) . "}";
|
||||
$addButton[] = Indent::_(2) . "return \$html;";
|
||||
$addButton[] = Indent::_(1) . "}";
|
||||
|
||||
return implode(PHP_EOL, $addButton);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -0,0 +1,129 @@
|
||||
<?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\Field\JoomlaFour;
|
||||
|
||||
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreFieldInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Core Joomla Fields
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class CoreField implements CoreFieldInterface
|
||||
{
|
||||
/**
|
||||
* Local Core Joomla Fields
|
||||
*
|
||||
* @var array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $fields = [];
|
||||
|
||||
/**
|
||||
* Local Core Joomla Fields Path
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $paths = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// set the path to the form validation fields
|
||||
$this->paths[] = JPATH_LIBRARIES . '/src/Form/Field';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Array of Existing Validation Field Names
|
||||
*
|
||||
* @param bool $lowercase Switch to set fields lowercase
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(bool $lowercase = false): array
|
||||
{
|
||||
if ($this->fields === [])
|
||||
{
|
||||
// check if the path exist
|
||||
foreach ($this->paths as $path)
|
||||
{
|
||||
$this->set($path);
|
||||
}
|
||||
}
|
||||
|
||||
// return fields if found
|
||||
if ($this->fields !== [])
|
||||
{
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
{
|
||||
return array_map(
|
||||
fn($item): string => strtolower((string) $item),
|
||||
$this->fields
|
||||
);
|
||||
}
|
||||
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
// return empty array
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fields found in a path
|
||||
*
|
||||
* @param string $path The path to load fields from
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function set(string $path): void
|
||||
{
|
||||
// Check if the path exists
|
||||
if (!Folder::exists($path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load all PHP files in this path
|
||||
$fields = Folder::files($path, '\.php$', true, true);
|
||||
|
||||
// Process the files to extract field names
|
||||
$processedFields = array_map(function ($name) {
|
||||
$fileName = basename($name);
|
||||
|
||||
// Remove 'Field.php' if it exists or just '.php' otherwise
|
||||
if (substr($fileName, -9) === 'Field.php')
|
||||
{
|
||||
return str_replace('Field.php', '', $fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return str_replace('.php', '', $fileName);
|
||||
}
|
||||
}, $fields);
|
||||
|
||||
// Merge with existing fields and remove duplicates
|
||||
$this->fields = array_unique(array_merge($processedFields, $this->fields));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,125 @@
|
||||
<?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\Field\JoomlaFour;
|
||||
|
||||
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreRuleInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Core Joomla Field Rules
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class CoreRule implements CoreRuleInterface
|
||||
{
|
||||
/**
|
||||
* Local Core Joomla Rules
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $rules = [];
|
||||
|
||||
/**
|
||||
* Local Core Joomla Rules Path
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected string $path;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// set the path to the form validation rules
|
||||
$this->path = JPATH_LIBRARIES . '/src/Form/Rule';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Array of Existing Validation Rule Names
|
||||
*
|
||||
* @param bool $lowercase Switch to set rules lowercase
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(bool $lowercase = false): array
|
||||
{
|
||||
if ($this->rules === [])
|
||||
{
|
||||
$this->set($this->path);
|
||||
}
|
||||
|
||||
// return rules if found
|
||||
if ($this->rules !== [])
|
||||
{
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
{
|
||||
return array_map(
|
||||
fn($item): string => strtolower((string) $item),
|
||||
$this->rules
|
||||
);
|
||||
}
|
||||
|
||||
return $this->rules;
|
||||
}
|
||||
|
||||
// return empty array
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rules found in a path
|
||||
*
|
||||
* @param string $path The path to load rules from
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function set(string $path): void
|
||||
{
|
||||
// Check if the path exists
|
||||
if (!Folder::exists($path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load all PHP files in this path
|
||||
$rules = Folder::files($path, '\.php$', true, true);
|
||||
|
||||
// Process the files to extract rule names
|
||||
$processedRules = array_map(function ($name) {
|
||||
$fileName = basename($name);
|
||||
|
||||
// Remove 'Rule.php' if it exists or just '.php' otherwise
|
||||
if (substr($fileName, -8) === 'Rule.php')
|
||||
{
|
||||
return str_replace('Rule.php', '', $fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return str_replace('.php', '', $fileName);
|
||||
}
|
||||
}, $rules);
|
||||
|
||||
// Merge with existing rules and remove duplicates
|
||||
$this->rules = array_unique(array_merge($processedRules, $this->rules));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,345 @@
|
||||
<?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\Field\JoomlaFour;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Creator\Permission;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\InputButtonInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Input Button
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class InputButton implements InputButtonInterface
|
||||
{
|
||||
/**
|
||||
* The Config Class.
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The Placeholder Class.
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* The Permission Class.
|
||||
*
|
||||
* @var Permission
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Permission $permission;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Config $config The Config Class.
|
||||
* @param Placeholder $placeholder The Placeholder Class.
|
||||
* @param Permission $permission The Permission Class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Config $config, Placeholder $placeholder,
|
||||
Permission $permission)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->placeholder = $placeholder;
|
||||
$this->permission = $permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Add Button To List Field Input (getInput tweak)
|
||||
*
|
||||
* @param array $fieldData The field custom data
|
||||
*
|
||||
* @return string of getInput class on success empty string otherwise
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(array $fieldData): string
|
||||
{
|
||||
// make sure hte view values are set
|
||||
if (isset($fieldData['add_button'])
|
||||
&& ($fieldData['add_button'] === 'true'
|
||||
|| 1 == $fieldData['add_button'])
|
||||
&& isset($fieldData['view'])
|
||||
&& isset($fieldData['views'])
|
||||
&& StringHelper::check($fieldData['view'])
|
||||
&& StringHelper::check($fieldData['views']))
|
||||
{
|
||||
// set local component
|
||||
$local_component = "com_" . $this->config->component_code_name;
|
||||
// check that the component value is set
|
||||
if (!isset($fieldData['component'])
|
||||
|| !StringHelper::check(
|
||||
$fieldData['component']
|
||||
))
|
||||
{
|
||||
$fieldData['component'] = $local_component;
|
||||
}
|
||||
// check that the component has the com_ value in it
|
||||
if (strpos((string) $fieldData['component'], 'com_') === false
|
||||
|| strpos((string) $fieldData['component'], '=') !== false)
|
||||
{
|
||||
$fieldData['component'] = "com_" . $fieldData['component'];
|
||||
}
|
||||
// make sure the component is update if # # # or [ [ [ component placeholder is used
|
||||
if (strpos((string) $fieldData['component'], (string) Placefix::h()) !== false
|
||||
|| strpos((string) $fieldData['component'], (string) Placefix::b()) !== false) // should not be needed... but
|
||||
{
|
||||
$fieldData['component'] = $this->placeholder->update_(
|
||||
$fieldData['component']
|
||||
);
|
||||
}
|
||||
// get core permissions
|
||||
$coreLoad = false;
|
||||
// add ref tags
|
||||
$refLoad = true;
|
||||
// fall back on the field component
|
||||
$component = $fieldData['component'];
|
||||
// check if we should add ref tags (since it only works well on local views)
|
||||
if ($local_component !== $component)
|
||||
{
|
||||
// do not add ref tags
|
||||
$refLoad = false;
|
||||
}
|
||||
// start building the add buttons/s
|
||||
$addButton = array();
|
||||
$addButton[] = PHP_EOL . PHP_EOL . Indent::_(1) . "/**";
|
||||
$addButton[] = Indent::_(1) . " * Override to add new button";
|
||||
$addButton[] = Indent::_(1) . " *";
|
||||
$addButton[] = Indent::_(1)
|
||||
. " * @return string The field input markup.";
|
||||
$addButton[] = Indent::_(1) . " *";
|
||||
$addButton[] = Indent::_(1) . " * @since 3.2";
|
||||
$addButton[] = Indent::_(1) . " */";
|
||||
$addButton[] = Indent::_(1) . "protected function getInput()";
|
||||
$addButton[] = Indent::_(1) . "{";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " see if we should add buttons";
|
||||
$addButton[] = Indent::_(2)
|
||||
. "\$set_button = \$this->getAttribute('button');";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get html";
|
||||
$addButton[] = Indent::_(2) . "\$html = parent::getInput();";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " if true set button";
|
||||
$addButton[] = Indent::_(2) . "if (\$set_button === 'true')";
|
||||
$addButton[] = Indent::_(2) . "{";
|
||||
$addButton[] = Indent::_(3) . "\$button = array();";
|
||||
$addButton[] = Indent::_(3) . "\$script = array();";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_code_name = \$this->getAttribute('name');";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the input from url";
|
||||
$addButton[] = Indent::_(3) . "\$app = Factory::getApplication();";
|
||||
$addButton[] = Indent::_(3) . "\$jinput = \$app->input;";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the view name & id";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$values = \$jinput->getArray(array(";
|
||||
$addButton[] = Indent::_(4) . "'id' => 'int',";
|
||||
$addButton[] = Indent::_(4) . "'view' => 'word'";
|
||||
$addButton[] = Indent::_(3) . "));";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " check if new item";
|
||||
$addButton[] = Indent::_(3) . "\$ref = '';";
|
||||
$addButton[] = Indent::_(3) . "\$refJ = '';";
|
||||
if ($refLoad)
|
||||
{
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (!is_null(\$values['id']) && strlen(\$values['view']))";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only load referral if not new item.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&ref=' . \$values['view'] . '&refid=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&ref=' . \$values['view'] . '&refid=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_uri = (string) \Joomla\CMS\Uri\Uri::getInstance();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_return = urlencode(base64_encode(\$_uri));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " load return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref .= '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ .= '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
}
|
||||
else
|
||||
{
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (!is_null(\$values['id']) && strlen(\$values['view']))";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only load field details if not new item.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&field=' . \$values['view'] . '&field_id=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&field=' . \$values['view'] . '&field_id=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_uri = (string) \Joomla\CMS\Uri\Uri::getInstance();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_return = urlencode(base64_encode(\$_uri));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " load return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
}
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get button label";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = trim(\$button_code_name);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace('/_+/', ' ', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace('/\s+/', ' ', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace(\"/[^A-Za-z ]/\", '', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = ucfirst(strtolower(\$button_label));";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get user object";
|
||||
$addButton[] = Indent::_(3) . "\$user = Factory::getApplication()->getIdentity();";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only add if user allowed to create " . $fieldData['view'];
|
||||
// check if the item has permissions.
|
||||
$addButton[] = Indent::_(3) . "if (\$user->authorise('"
|
||||
. $this->permission->getGlobal($fieldData['view'], 'core.create')
|
||||
. "', '" . $component . "') && \$app->isClient('administrator')) // TODO for now only in admin area.";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build Create button";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$button[] = '<a id=\"'.\$button_code_name.'Create\" class=\"btn btn-small btn-success hasTooltip\" title=\"'.Text:"
|
||||
. ":sprintf('" . $this->config->lang_prefix
|
||||
. "_CREATE_NEW_S', \$button_label).'\" style=\"border-radius: 0px 4px 4px 0px;\"";
|
||||
$addButton[] = Indent::_(5) . "href=\"index.php?option="
|
||||
. $fieldData['component'] . "&view=" . $fieldData['view']
|
||||
. "&layout=edit'.\$ref.'\" >";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "<span class=\"icon-new icon-white\"></span></a>';";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only add if user allowed to edit " . $fieldData['view'];
|
||||
// check if the item has permissions.
|
||||
$addButton[] = Indent::_(3) . "if (\$user->authorise('"
|
||||
. $this->permission->getGlobal($fieldData['view'], 'core.edit')
|
||||
. "', '" . $component . "') && \$app->isClient('administrator')) // TODO for now only in admin area.";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build edit button";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$button[] = '<a id=\"'.\$button_code_name.'Edit\" class=\"btn btn-small btn-outline-success button-select hasTooltip\" title=\"'.Text:"
|
||||
. ":sprintf('" . $this->config->lang_prefix
|
||||
. "_EDIT_S', \$button_label).'\" style=\"display: none; border-radius: 0px 4px 4px 0px;\" href=\"#\" >";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "<span class=\"icon-edit\"></span></a>';";
|
||||
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build script";
|
||||
$addButton[] = Indent::_(4) . "\$script[] = \"";
|
||||
$addButton[] = Indent::_(5) . "document.addEventListener('DOMContentLoaded', function() {";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "document.getElementById('jform_\".\$button_code_name.\"').addEventListener('change', function(e) {";
|
||||
$addButton[] = Indent::_(7) . "e.preventDefault();";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "let \".\$button_code_name.\"Value = this.value;";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "\".\$button_code_name.\"Button(\".\$button_code_name.\"Value);";
|
||||
$addButton[] = Indent::_(6) . "});";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "let \".\$button_code_name.\"Value = document.getElementById('jform_\".\$button_code_name.\"').value;";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "\".\$button_code_name.\"Button(\".\$button_code_name.\"Value);";
|
||||
$addButton[] = Indent::_(5) . "});";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "function \".\$button_code_name.\"Button(value) {";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "var createButton = document.getElementById('\".\$button_code_name.\"Create');";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "var editButton = document.getElementById('\".\$button_code_name.\"Edit');";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "if (value > 0) {"; // TODO not ideal since value may not be an (int)
|
||||
$addButton[] = Indent::_(7) . "// hide the create button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "createButton.style.display = 'none';";
|
||||
$addButton[] = Indent::_(7) . "// show edit button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "editButton.style.display = 'block';";
|
||||
$addButton[] = Indent::_(7) . "let url = 'index.php?option="
|
||||
. $fieldData['component'] . "&view=" . $fieldData['views']
|
||||
. "&task=" . $fieldData['view']
|
||||
. ".edit&id='+value+'\".\$refJ.\"';"; // TODO this value may not be the ID
|
||||
$addButton[] = Indent::_(7)
|
||||
. "editButton.setAttribute('href', url);";
|
||||
$addButton[] = Indent::_(6) . "} else {";
|
||||
$addButton[] = Indent::_(7) . "// show the create button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "createButton.style.display = 'block';";
|
||||
$addButton[] = Indent::_(7) . "// hide edit button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "editButton.style.display = 'none';";
|
||||
$addButton[] = Indent::_(6) . "}";
|
||||
$addButton[] = Indent::_(5) . "}\";";
|
||||
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " check if button was created for " . $fieldData['view']
|
||||
. " field.";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (is_array(\$button) && count(\$button) > 0)";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " Load the needed script.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$document = Factory::getApplication()->getDocument();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$document->addScriptDeclaration(implode(' ',\$script));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " return the button attached to input field.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "return '<div class=\"input-group\">' .\$html . implode('',\$button).'</div>';";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(2) . "}";
|
||||
$addButton[] = Indent::_(2) . "return \$html;";
|
||||
$addButton[] = Indent::_(1) . "}";
|
||||
|
||||
return implode(PHP_EOL, $addButton);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -0,0 +1,130 @@
|
||||
<?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\Field\JoomlaThree;
|
||||
|
||||
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreFieldInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Core Joomla Fields
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class CoreField implements CoreFieldInterface
|
||||
{
|
||||
/**
|
||||
* Local Core Joomla Fields
|
||||
*
|
||||
* @var array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $fields = [];
|
||||
|
||||
/**
|
||||
* Local Core Joomla Fields Path
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $paths = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// set the path to the form validation fields
|
||||
$this->paths[] = JPATH_LIBRARIES . '/src/Form/Field';
|
||||
$this->paths[] = JPATH_LIBRARIES . '/joomla/form/fields';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Array of Existing Validation Field Names
|
||||
*
|
||||
* @param bool $lowercase Switch to set fields lowercase
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(bool $lowercase = false): array
|
||||
{
|
||||
if ($this->fields === [])
|
||||
{
|
||||
// check if the path exist
|
||||
foreach ($this->paths as $path)
|
||||
{
|
||||
$this->set($path);
|
||||
}
|
||||
}
|
||||
|
||||
// return fields if found
|
||||
if ($this->fields !== [])
|
||||
{
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
{
|
||||
return array_map(
|
||||
fn($item): string => strtolower((string) $item),
|
||||
$this->fields
|
||||
);
|
||||
}
|
||||
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
// return empty array
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fields found in a path
|
||||
*
|
||||
* @param string $path The path to load fields from
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function set(string $path): void
|
||||
{
|
||||
// Check if the path exists
|
||||
if (!Folder::exists($path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load all PHP files in this path
|
||||
$fields = Folder::files($path, '\.php$', true, true);
|
||||
|
||||
// Process the files to extract field names
|
||||
$processedFields = array_map(function ($name) {
|
||||
$fileName = basename($name);
|
||||
|
||||
// Remove 'Field.php' if it exists or just '.php' otherwise
|
||||
if (substr($fileName, -9) === 'Field.php')
|
||||
{
|
||||
return str_replace('Field.php', '', $fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return str_replace('.php', '', $fileName);
|
||||
}
|
||||
}, $fields);
|
||||
|
||||
// Merge with existing fields and remove duplicates
|
||||
$this->fields = array_unique(array_merge($processedFields, $this->fields));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,125 @@
|
||||
<?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\Field\JoomlaThree;
|
||||
|
||||
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreRuleInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Core Joomla Field Rules
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class CoreRule implements CoreRuleInterface
|
||||
{
|
||||
/**
|
||||
* Local Core Joomla Rules
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $rules = [];
|
||||
|
||||
/**
|
||||
* Local Core Joomla Rules Path
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected string $path;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// set the path to the form validation rules
|
||||
$this->path = JPATH_LIBRARIES . '/src/Form/Rule';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Array of Existing Validation Rule Names
|
||||
*
|
||||
* @param bool $lowercase Switch to set rules lowercase
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(bool $lowercase = false): array
|
||||
{
|
||||
if ($this->rules === [])
|
||||
{
|
||||
$this->set($this->path);
|
||||
}
|
||||
|
||||
// return rules if found
|
||||
if ($this->rules !== [])
|
||||
{
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
{
|
||||
return array_map(
|
||||
fn($item): string => strtolower((string) $item),
|
||||
$this->rules
|
||||
);
|
||||
}
|
||||
|
||||
return $this->rules;
|
||||
}
|
||||
|
||||
// return empty array
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rules found in a path
|
||||
*
|
||||
* @param string $path The path to load rules from
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
private function set(string $path): void
|
||||
{
|
||||
// Check if the path exists
|
||||
if (!Folder::exists($path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load all PHP files in this path
|
||||
$rules = Folder::files($path, '\.php$', true, true);
|
||||
|
||||
// Process the files to extract rule names
|
||||
$processedRules = array_map(function ($name) {
|
||||
$fileName = basename($name);
|
||||
|
||||
// Remove 'Rule.php' if it exists or just '.php' otherwise
|
||||
if (substr($fileName, -8) === 'Rule.php')
|
||||
{
|
||||
return str_replace('Rule.php', '', $fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return str_replace('.php', '', $fileName);
|
||||
}
|
||||
}, $rules);
|
||||
|
||||
// Merge with existing rules and remove duplicates
|
||||
$this->rules = array_unique(array_merge($processedRules, $this->rules));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,339 @@
|
||||
<?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\Field\JoomlaThree;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Creator\Permission;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\InputButtonInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Input Button
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class InputButton implements InputButtonInterface
|
||||
{
|
||||
/**
|
||||
* The Config Class.
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The Placeholder Class.
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* The Permission Class.
|
||||
*
|
||||
* @var Permission
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Permission $permission;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Config $config The Config Class.
|
||||
* @param Placeholder $placeholder The Placeholder Class.
|
||||
* @param Permission $permission The Permission Class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Config $config, Placeholder $placeholder,
|
||||
Permission $permission)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->placeholder = $placeholder;
|
||||
$this->permission = $permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Add Button To List Field Input (getInput tweak)
|
||||
*
|
||||
* @param array $fieldData The field custom data
|
||||
*
|
||||
* @return string of getInput class on success empty string otherwise
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(array $fieldData): string
|
||||
{
|
||||
// make sure hte view values are set
|
||||
if (isset($fieldData['add_button'])
|
||||
&& ($fieldData['add_button'] === 'true'
|
||||
|| 1 == $fieldData['add_button'])
|
||||
&& isset($fieldData['view'])
|
||||
&& isset($fieldData['views'])
|
||||
&& StringHelper::check($fieldData['view'])
|
||||
&& StringHelper::check($fieldData['views']))
|
||||
{
|
||||
// set local component
|
||||
$local_component = "com_" . $this->config->component_code_name;
|
||||
// check that the component value is set
|
||||
if (!isset($fieldData['component'])
|
||||
|| !StringHelper::check(
|
||||
$fieldData['component']
|
||||
))
|
||||
{
|
||||
$fieldData['component'] = $local_component;
|
||||
}
|
||||
// check that the component has the com_ value in it
|
||||
if (strpos((string) $fieldData['component'], 'com_') === false
|
||||
|| strpos((string) $fieldData['component'], '=') !== false)
|
||||
{
|
||||
$fieldData['component'] = "com_" . $fieldData['component'];
|
||||
}
|
||||
// make sure the component is update if # # # or [ [ [ component placeholder is used
|
||||
if (strpos((string) $fieldData['component'], (string) Placefix::h()) !== false
|
||||
|| strpos((string) $fieldData['component'], (string) Placefix::b()) !== false) // should not be needed... but
|
||||
{
|
||||
$fieldData['component'] = $this->placeholder->update_(
|
||||
$fieldData['component']
|
||||
);
|
||||
}
|
||||
// get core permissions
|
||||
$coreLoad = false;
|
||||
// add ref tags
|
||||
$refLoad = true;
|
||||
// fall back on the field component
|
||||
$component = $fieldData['component'];
|
||||
// check if we should add ref tags (since it only works well on local views)
|
||||
if ($local_component !== $component)
|
||||
{
|
||||
// do not add ref tags
|
||||
$refLoad = false;
|
||||
}
|
||||
// start building the add buttons/s
|
||||
$addButton = array();
|
||||
$addButton[] = PHP_EOL . PHP_EOL . Indent::_(1) . "/**";
|
||||
$addButton[] = Indent::_(1) . " * Override to add new button";
|
||||
$addButton[] = Indent::_(1) . " *";
|
||||
$addButton[] = Indent::_(1)
|
||||
. " * @return string The field input markup.";
|
||||
$addButton[] = Indent::_(1) . " *";
|
||||
$addButton[] = Indent::_(1) . " * @since 3.2";
|
||||
$addButton[] = Indent::_(1) . " */";
|
||||
$addButton[] = Indent::_(1) . "protected function getInput()";
|
||||
$addButton[] = Indent::_(1) . "{";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " see if we should add buttons";
|
||||
$addButton[] = Indent::_(2)
|
||||
. "\$set_button = \$this->getAttribute('button');";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get html";
|
||||
$addButton[] = Indent::_(2) . "\$html = parent::getInput();";
|
||||
$addButton[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
||||
. " if true set button";
|
||||
$addButton[] = Indent::_(2) . "if (\$set_button === 'true')";
|
||||
$addButton[] = Indent::_(2) . "{";
|
||||
$addButton[] = Indent::_(3) . "\$button = array();";
|
||||
$addButton[] = Indent::_(3) . "\$script = array();";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_code_name = \$this->getAttribute('name');";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the input from url";
|
||||
$addButton[] = Indent::_(3) . "\$app = Factory::getApplication();";
|
||||
$addButton[] = Indent::_(3) . "\$jinput = \$app->input;";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the view name & id";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$values = \$jinput->getArray(array(";
|
||||
$addButton[] = Indent::_(4) . "'id' => 'int',";
|
||||
$addButton[] = Indent::_(4) . "'view' => 'word'";
|
||||
$addButton[] = Indent::_(3) . "));";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " check if new item";
|
||||
$addButton[] = Indent::_(3) . "\$ref = '';";
|
||||
$addButton[] = Indent::_(3) . "\$refJ = '';";
|
||||
if ($refLoad)
|
||||
{
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (!is_null(\$values['id']) && strlen(\$values['view']))";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only load referral if not new item.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&ref=' . \$values['view'] . '&refid=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&ref=' . \$values['view'] . '&refid=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_uri = (string) \Joomla\CMS\Uri\Uri::getInstance();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_return = urlencode(base64_encode(\$_uri));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " load return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref .= '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ .= '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
}
|
||||
else
|
||||
{
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (!is_null(\$values['id']) && strlen(\$values['view']))";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only load field details if not new item.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&field=' . \$values['view'] . '&field_id=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&field=' . \$values['view'] . '&field_id=' . \$values['id'];";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get the return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_uri = (string) \Joomla\CMS\Uri\Uri::getInstance();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$_return = urlencode(base64_encode(\$_uri));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " load return value.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$ref = '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$refJ = '&return=' . \$_return;";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
}
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get button label";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = trim(\$button_code_name);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace('/_+/', ' ', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace('/\s+/', ' ', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = preg_replace(\"/[^A-Za-z ]/\", '', \$button_label);";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "\$button_label = ucfirst(strtolower(\$button_label));";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " get user object";
|
||||
$addButton[] = Indent::_(3) . "\$user = Factory::getUser();";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only add if user allowed to create " . $fieldData['view'];
|
||||
// check if the item has permissions.
|
||||
$addButton[] = Indent::_(3) . "if (\$user->authorise('"
|
||||
. $this->permission->getGlobal($fieldData['view'], 'core.create')
|
||||
. "', '" . $component . "') && \$app->isClient('administrator')) // TODO for now only in admin area.";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build Create button";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$button[] = '<a id=\"'.\$button_code_name.'Create\" class=\"btn btn-small btn-success hasTooltip\" title=\"'.Text:"
|
||||
. ":sprintf('" . $this->config->lang_prefix
|
||||
. "_CREATE_NEW_S', \$button_label).'\" style=\"border-radius: 0px 4px 4px 0px; padding: 4px 4px 4px 7px;\"";
|
||||
$addButton[] = Indent::_(5) . "href=\"index.php?option="
|
||||
. $fieldData['component'] . "&view=" . $fieldData['view']
|
||||
. "&layout=edit'.\$ref.'\" >";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "<span class=\"icon-new icon-white\"></span></a>';";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " only add if user allowed to edit " . $fieldData['view'];
|
||||
// check if the item has permissions.
|
||||
$addButton[] = Indent::_(3) . "if (\$user->authorise('"
|
||||
. $this->permission->getGlobal($fieldData['view'], 'core.edit')
|
||||
. "', '" . $component . "') && \$app->isClient('administrator')) // TODO for now only in admin area.";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build edit button";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$button[] = '<a id=\"'.\$button_code_name.'Edit\" class=\"btn btn-small hasTooltip\" title=\"'.Text:"
|
||||
. ":sprintf('" . $this->config->lang_prefix
|
||||
. "_EDIT_S', \$button_label).'\" style=\"display: none; padding: 3px 4px 4px 7px;\" href=\"#\" >";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "<span class=\"icon-edit\"></span></a>';";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " build script";
|
||||
$addButton[] = Indent::_(4) . "\$script[] = \"";
|
||||
$addButton[] = Indent::_(5) . "jQuery(document).ready(function() {";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "jQuery('#adminForm').on('change', '#jform_\".\$button_code_name.\"',function (e) {";
|
||||
$addButton[] = Indent::_(7) . "e.preventDefault();";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "var \".\$button_code_name.\"Value = jQuery('#jform_\".\$button_code_name.\"').val();";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "\".\$button_code_name.\"Button(\".\$button_code_name.\"Value);";
|
||||
$addButton[] = Indent::_(6) . "});";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "var \".\$button_code_name.\"Value = jQuery('#jform_\".\$button_code_name.\"').val();";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "\".\$button_code_name.\"Button(\".\$button_code_name.\"Value);";
|
||||
$addButton[] = Indent::_(5) . "});";
|
||||
$addButton[] = Indent::_(5)
|
||||
. "function \".\$button_code_name.\"Button(value) {";
|
||||
$addButton[] = Indent::_(6)
|
||||
. "if (value > 0) {"; // TODO not ideal since value may not be an (int)
|
||||
$addButton[] = Indent::_(7) . "// hide the create button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "jQuery('#\".\$button_code_name.\"Create').hide();";
|
||||
$addButton[] = Indent::_(7) . "// show edit button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "jQuery('#\".\$button_code_name.\"Edit').show();";
|
||||
$addButton[] = Indent::_(7) . "var url = 'index.php?option="
|
||||
. $fieldData['component'] . "&view=" . $fieldData['views']
|
||||
. "&task=" . $fieldData['view']
|
||||
. ".edit&id='+value+'\".\$refJ.\"';"; // TODO this value may not be the ID
|
||||
$addButton[] = Indent::_(7)
|
||||
. "jQuery('#\".\$button_code_name.\"Edit').attr('href', url);";
|
||||
$addButton[] = Indent::_(6) . "} else {";
|
||||
$addButton[] = Indent::_(7) . "// show the create button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "jQuery('#\".\$button_code_name.\"Create').show();";
|
||||
$addButton[] = Indent::_(7) . "// hide edit button";
|
||||
$addButton[] = Indent::_(7)
|
||||
. "jQuery('#\".\$button_code_name.\"Edit').hide();";
|
||||
$addButton[] = Indent::_(6) . "}";
|
||||
$addButton[] = Indent::_(5) . "}\";";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(3) . "//" . Line::_(__Line__, __Class__)
|
||||
. " check if button was created for " . $fieldData['view']
|
||||
. " field.";
|
||||
$addButton[] = Indent::_(3)
|
||||
. "if (is_array(\$button) && count(\$button) > 0)";
|
||||
$addButton[] = Indent::_(3) . "{";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " Load the needed script.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$document = Factory::getDocument();";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "\$document->addScriptDeclaration(implode(' ',\$script));";
|
||||
$addButton[] = Indent::_(4) . "//" . Line::_(__Line__, __Class__)
|
||||
. " return the button attached to input field.";
|
||||
$addButton[] = Indent::_(4)
|
||||
. "return '<div class=\"input-append\">' .\$html . implode('',\$button).'</div>';";
|
||||
$addButton[] = Indent::_(3) . "}";
|
||||
$addButton[] = Indent::_(2) . "}";
|
||||
$addButton[] = Indent::_(2) . "return \$html;";
|
||||
$addButton[] = Indent::_(1) . "}";
|
||||
|
||||
return implode(PHP_EOL, $addButton);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -0,0 +1,228 @@
|
||||
<?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\Field;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\String\TypeHelper;
|
||||
use VDM\Joomla\Utilities\String\FieldHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\UniqueName;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Builder\CategoryOtherName;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Name
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Name
|
||||
{
|
||||
/**
|
||||
* Unique Field Names
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $unique;
|
||||
|
||||
/**
|
||||
* The Placeholder Class.
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* The UniqueName Class.
|
||||
*
|
||||
* @var UniqueName
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected UniqueName $uniquename;
|
||||
|
||||
/**
|
||||
* The CategoryOtherName Class.
|
||||
*
|
||||
* @var CategoryOtherName
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected CategoryOtherName $categoryothername;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Placeholder $placeholder The Placeholder Class.
|
||||
* @param UniqueName $uniquename The UniqueName Class.
|
||||
* @param CategoryOtherName $categoryothername The CategoryOtherName Class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Placeholder $placeholder, UniqueName $uniquename,
|
||||
CategoryOtherName $categoryothername)
|
||||
{
|
||||
$this->placeholder = $placeholder;
|
||||
$this->uniquename = $uniquename;
|
||||
$this->categoryothername = $categoryothername;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field's actual name
|
||||
*
|
||||
* @param array $field The field array
|
||||
* @param string|null $listViewName The list view name
|
||||
* @param string $amicably The peaceful resolve (for fields in subforms in same view :)
|
||||
*
|
||||
* @return string Success returns field name
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(array &$field, ?string $listViewName = null, string $amicably = ''): string
|
||||
{
|
||||
// return the unique name if already set
|
||||
if ($listViewName && StringHelper::check($listViewName) && isset($field['hash'])
|
||||
&& isset($this->unique[$listViewName . $amicably . $field['hash']]))
|
||||
{
|
||||
return $this->unique[$listViewName . $amicably . $field['hash']];
|
||||
}
|
||||
|
||||
// always make sure we have a field name and type
|
||||
if (!isset($field['settings']) || !isset($field['settings']->type_name)
|
||||
|| !isset($field['settings']->name))
|
||||
{
|
||||
return 'error';
|
||||
}
|
||||
|
||||
// set the type name
|
||||
$type_name = TypeHelper::safe(
|
||||
$field['settings']->type_name
|
||||
);
|
||||
|
||||
// set the name of the field
|
||||
$name = FieldHelper::safe($field['settings']->name);
|
||||
|
||||
// check that we have the properties
|
||||
if (ArrayHelper::check($field['settings']->properties))
|
||||
{
|
||||
foreach ($field['settings']->properties as $property)
|
||||
{
|
||||
if ($property['name'] === 'name')
|
||||
{
|
||||
// if category then name must be catid (only one per view)
|
||||
if ($type_name === 'category')
|
||||
{
|
||||
// quick check if this is a category linked to view page
|
||||
$requeSt_id = GetHelper::between(
|
||||
$field['settings']->xml, 'name="', '"'
|
||||
);
|
||||
if (strpos($requeSt_id, '_request_id') !== false
|
||||
|| strpos($requeSt_id, '_request_catid') !== false)
|
||||
{
|
||||
// keep it then, don't change
|
||||
$name = $this->placeholder->update_(
|
||||
$requeSt_id
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$name = 'catid';
|
||||
}
|
||||
|
||||
// if list view name is set
|
||||
if (StringHelper::check($listViewName))
|
||||
{
|
||||
// check if we should use another Text Name as this views name
|
||||
$otherName = $this->placeholder->update_(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'othername="', '"'
|
||||
)
|
||||
);
|
||||
$otherViews = $this->placeholder->update_(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'views="', '"'
|
||||
)
|
||||
);
|
||||
$otherView = $this->placeholder->update_(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'view="', '"'
|
||||
)
|
||||
);
|
||||
|
||||
// This is to link other view category
|
||||
if (StringHelper::check($otherName)
|
||||
&& StringHelper::check($otherViews)
|
||||
&& StringHelper::check($otherView))
|
||||
{
|
||||
// set other category details
|
||||
$this->categoryothername->set($listViewName, [
|
||||
'name' => FieldHelper::safe(
|
||||
$otherName
|
||||
),
|
||||
'views' => StringHelper::safe(
|
||||
$otherViews
|
||||
),
|
||||
'view' => StringHelper::safe(
|
||||
$otherView
|
||||
)
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if tag is set then enable all tag options for this view (only one per view)
|
||||
elseif ($type_name === 'tag')
|
||||
{
|
||||
$name = 'tags';
|
||||
}
|
||||
// if the field is set as alias it must be called alias
|
||||
elseif (isset($field['alias']) && $field['alias'])
|
||||
{
|
||||
$name = 'alias';
|
||||
}
|
||||
else
|
||||
{
|
||||
// get value from xml
|
||||
$xml = FieldHelper::safe(
|
||||
$this->placeholder->update_(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'name="', '"'
|
||||
)
|
||||
)
|
||||
);
|
||||
// check if a value was found
|
||||
if (StringHelper::check($xml))
|
||||
{
|
||||
$name = $xml;
|
||||
}
|
||||
}
|
||||
// exit foreach loop
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return the value unique
|
||||
if (StringHelper::check($listViewName) && isset($field['hash']))
|
||||
{
|
||||
$this->unique[$listViewName . $amicably . $field['hash']]
|
||||
= $this->uniquename->get($name, $listViewName . $amicably);
|
||||
|
||||
// now return the unique name
|
||||
return $this->unique[$listViewName . $amicably . $field['hash']];
|
||||
}
|
||||
|
||||
// fall back to global
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,166 @@
|
||||
<?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\Field;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Registry;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Gui;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreRuleInterface as CoreRule;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Rules
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Rule
|
||||
{
|
||||
/**
|
||||
* The Registry Class.
|
||||
*
|
||||
* @var Registry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Registry $registry;
|
||||
|
||||
/**
|
||||
* The Customcode Class.
|
||||
*
|
||||
* @var Customcode
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Customcode $customcode;
|
||||
|
||||
/**
|
||||
* The Gui Class.
|
||||
*
|
||||
* @var Gui
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Gui $gui;
|
||||
|
||||
/**
|
||||
* The Placeholder Class.
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* The CoreRuleInterface Class.
|
||||
*
|
||||
* @var CoreRule
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected CoreRule $corerule;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Registry $registry The Registry Class.
|
||||
* @param Customcode $customcode The Customcode Class.
|
||||
* @param Gui $gui The Gui Class.
|
||||
* @param Placeholder $placeholder The Placeholder Class.
|
||||
* @param CoreRule $corerule The CoreRuleInterface Class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Registry $registry, Customcode $customcode, Gui $gui,
|
||||
Placeholder $placeholder, CoreRule $corerule)
|
||||
{
|
||||
$this->registry = $registry;
|
||||
$this->customcode = $customcode;
|
||||
$this->gui = $gui;
|
||||
$this->placeholder = $placeholder;
|
||||
$this->corerule = $corerule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the validation rule
|
||||
*
|
||||
* @param int $id The field id
|
||||
* @param string $field The field string
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function set(int $id, string $field)
|
||||
{
|
||||
// check if we have validate (validation rule set)
|
||||
$validation_rule = GetHelper::between(
|
||||
$field, 'validate="', '"'
|
||||
);
|
||||
|
||||
if (StringHelper::check($validation_rule))
|
||||
{
|
||||
// make sure it is lowercase
|
||||
$validation_rule = StringHelper::safe(
|
||||
$validation_rule
|
||||
);
|
||||
|
||||
// link this field to this validation (don't move this down)
|
||||
$this->registry->set("validation.linked.${id}", $validation_rule);
|
||||
|
||||
// make sure it is not already set
|
||||
if ($this->registry->get("validation.rules.${validation_rule}") === null)
|
||||
{
|
||||
// get joomla core validation names and make sure this rule is not a core validation rule
|
||||
if (!in_array($validation_rule, (array) $this->corerule->get(true)))
|
||||
{
|
||||
// get the class methods for this rule if it exists
|
||||
if (($php_code = GetHelper::var(
|
||||
'validation_rule', $validation_rule, 'name', 'php'
|
||||
)) !== false)
|
||||
{
|
||||
// open and set the validation rule
|
||||
$this->registry->set("validation.rules.${validation_rule}",
|
||||
$this->gui->set(
|
||||
$this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
(string) $php_code
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'table' => 'validation_rule',
|
||||
'field' => 'php',
|
||||
'id' => GetHelper::var(
|
||||
'validation_rule',
|
||||
$validation_rule, 'name', 'id'
|
||||
),
|
||||
'type' => 'php'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO set the notice that this validation rule is custom and was not found
|
||||
$this->registry->remove("validation.linked.${id}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// remove link (we only want custom validations linked)
|
||||
$this->registry->remove("validation.linked.${id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,123 @@
|
||||
<?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\Field;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
use VDM\Joomla\Utilities\String\TypeHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Type Name
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class TypeName
|
||||
{
|
||||
/**
|
||||
* Get the field's actual type
|
||||
*
|
||||
* @param array $field The field object
|
||||
*
|
||||
* @return string Success returns field type
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(array &$field): string
|
||||
{
|
||||
// check if we have done this already
|
||||
if (isset($field['type_name']))
|
||||
{
|
||||
return $field['type_name'];
|
||||
}
|
||||
|
||||
// check that we have the properties
|
||||
if (isset($field['settings'])
|
||||
&& ObjectHelper::check($field['settings'])
|
||||
&& isset($field['settings']->properties)
|
||||
&& ArrayHelper::check($field['settings']->properties))
|
||||
{
|
||||
// search for own custom fields
|
||||
if (strpos((string) $field['settings']->type_name, '@') !== false)
|
||||
{
|
||||
// set own custom field
|
||||
$field['settings']->own_custom = $field['settings']->type_name;
|
||||
$field['settings']->type_name = 'Custom';
|
||||
}
|
||||
|
||||
// set the type name
|
||||
$type_name = TypeHelper::safe(
|
||||
$field['settings']->type_name
|
||||
);
|
||||
|
||||
// if custom (we must use the xml value)
|
||||
if (strtolower((string) $type_name) === 'custom'
|
||||
|| strtolower((string) $type_name) === 'customuser')
|
||||
{
|
||||
$type = TypeHelper::safe(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'type="', '"'
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// loop over properties looking for the type value
|
||||
foreach ($field['settings']->properties as $property)
|
||||
{
|
||||
if ($property['name']
|
||||
=== 'type') // type field is never adjustable (unless custom)
|
||||
{
|
||||
// force the default value
|
||||
if (isset($property['example'])
|
||||
&& StringHelper::check(
|
||||
$property['example']
|
||||
))
|
||||
{
|
||||
$type = TypeHelper::safe(
|
||||
$property['example']
|
||||
);
|
||||
}
|
||||
// fall back on the xml settings (not ideal)
|
||||
else
|
||||
{
|
||||
$type = TypeHelper::safe(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'type="', '"'
|
||||
)
|
||||
);
|
||||
}
|
||||
// exit foreach loop
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// check if the value is set
|
||||
if (isset($type) && StringHelper::check($type))
|
||||
{
|
||||
return $type;
|
||||
}
|
||||
// fallback on type name set in name field (not ideal)
|
||||
else
|
||||
{
|
||||
return $type_name;
|
||||
}
|
||||
}
|
||||
|
||||
// fall back to text
|
||||
return 'text';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,112 @@
|
||||
<?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\Field;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Utilities\String\FieldHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Registry;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Unique Name
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class UniqueName
|
||||
{
|
||||
/**
|
||||
* The compiler registry
|
||||
*
|
||||
* @var Registry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Registry $registry;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Registry|null $registry The compiler registry object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Registry $registry = null)
|
||||
{
|
||||
$this->registry = $registry ?: Compiler::_('Registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many times the same field is used per view
|
||||
*
|
||||
* @param string $name The name of the field
|
||||
* @param string $view The name of the view
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function set(string $name, string $view)
|
||||
{
|
||||
if (($number = $this->registry->get("unique.names.${view}.counter.${name}")) === null)
|
||||
{
|
||||
$this->registry->set("unique.names.${view}.counter.${name}", 1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// count how many times the field is used
|
||||
$this->registry->set("unique.names.${view}.counter.${name}", ++$number);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Naming each field with an unique name
|
||||
*
|
||||
* @param string $name The name of the field
|
||||
* @param string $view The name of the view
|
||||
*
|
||||
* @return string the name
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $name, string $view): string
|
||||
{
|
||||
// only increment if the field name is used multiple times
|
||||
if ($this->registry->get("unique.names.${view}.counter.${name}") > 1)
|
||||
{
|
||||
$counter = 1;
|
||||
// set the unique name
|
||||
$unique_name = FieldHelper::safe(
|
||||
$name . '_' . $counter
|
||||
);
|
||||
|
||||
while ($this->registry->get("unique.names.${view}.names.${unique_name}") !== null)
|
||||
{
|
||||
// increment the number
|
||||
$counter++;
|
||||
// try again
|
||||
$unique_name = FieldHelper::safe(
|
||||
$name . '_' . $counter
|
||||
);
|
||||
}
|
||||
|
||||
// set the new name number
|
||||
$this->registry->set("unique.names.${view}.names.${unique_name}", $counter);
|
||||
|
||||
// return the unique name
|
||||
return $unique_name;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
Reference in New Issue
Block a user