diff --git a/README.md b/README.md index 88a9b8b6c..e951e6ed0 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will safe you lots of time and money. A real must have! -You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.7.0) with **ALL** its features and **ALL** concepts totally open-source and free! +You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.7.1) with **ALL** its features and **ALL** concepts totally open-source and free! > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -126,14 +126,14 @@ Component Builder is mapped as a component in itself on my local development env + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](http://joomlacomponentbuilder.com) + *First Build*: 30th April, 2015 -+ *Last Build*: 24th March, 2018 -+ *Version*: 2.7.0 ++ *Last Build*: 27th March, 2018 ++ *Version*: 2.7.1 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **186317** -+ *Field count*: **994** -+ *File count*: **1173** -+ *Folder count*: **189** ++ *Line count*: **190902** ++ *Field count*: **1007** ++ *File count*: **1196** ++ *Folder count*: **193** > This **component** was build with a Joomla [Automated Component Builder](http://joomlacomponentbuilder.com). > Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) diff --git a/admin/README.txt b/admin/README.txt index 88a9b8b6c..e951e6ed0 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will safe you lots of time and money. A real must have! -You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.7.0) with **ALL** its features and **ALL** concepts totally open-source and free! +You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.7.1) with **ALL** its features and **ALL** concepts totally open-source and free! > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -126,14 +126,14 @@ Component Builder is mapped as a component in itself on my local development env + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](http://joomlacomponentbuilder.com) + *First Build*: 30th April, 2015 -+ *Last Build*: 24th March, 2018 -+ *Version*: 2.7.0 ++ *Last Build*: 27th March, 2018 ++ *Version*: 2.7.1 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **186317** -+ *Field count*: **994** -+ *File count*: **1173** -+ *Folder count*: **189** ++ *Line count*: **190902** ++ *Field count*: **1007** ++ *File count*: **1196** ++ *Folder count*: **193** > This **component** was build with a Joomla [Automated Component Builder](http://joomlacomponentbuilder.com). > Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) diff --git a/admin/access.xml b/admin/access.xml index a4f8040d9..1e03fea0e 100644 --- a/admin/access.xml +++ b/admin/access.xml @@ -212,15 +212,16 @@ + + - @@ -358,6 +359,18 @@ + + + + + + + + + + + +
@@ -455,6 +468,15 @@
+
+ + + + + + + +
diff --git a/admin/assets/css/validation_rule.css b/admin/assets/css/validation_rule.css new file mode 100644 index 000000000..eea5d6f4b --- /dev/null +++ b/admin/assets/css/validation_rule.css @@ -0,0 +1,27 @@ +/*--------------------------------------------------------------------------------------------------------| www.vdm.io |------/ + __ __ _ _____ _ _ __ __ _ _ _ + \ \ / / | | | __ \ | | | | | \/ | | | | | | | + \ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | ___| |_| |__ ___ __| | + \ \/ / _` / __| __| | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| '_ \ / _ \ / _` | + \ / (_| \__ \ |_ | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_ | | | | __/ |_| | | | (_) | (_| | + \/ \__,_|___/\__| |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__| |_| |_|\___|\__|_| |_|\___/ \__,_| + | | + |_| +/-------------------------------------------------------------------------------------------------------------------------------/ + + @version 2.7.x + @created 30th April, 2015 + @package Component Builder + @subpackage validation_rule.css + @author Llewellyn van der Merwe + @github Joomla Component Builder + @copyright Copyright (C) 2015. All Rights Reserved + @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + + Builds Complex Joomla Components + +/-----------------------------------------------------------------------------------------------------------------------------*/ + +/* CSS Document */ + + diff --git a/admin/assets/css/validation_rules.css b/admin/assets/css/validation_rules.css new file mode 100644 index 000000000..f91e4a23d --- /dev/null +++ b/admin/assets/css/validation_rules.css @@ -0,0 +1,27 @@ +/*--------------------------------------------------------------------------------------------------------| www.vdm.io |------/ + __ __ _ _____ _ _ __ __ _ _ _ + \ \ / / | | | __ \ | | | | | \/ | | | | | | | + \ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | ___| |_| |__ ___ __| | + \ \/ / _` / __| __| | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| '_ \ / _ \ / _` | + \ / (_| \__ \ |_ | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_ | | | | __/ |_| | | | (_) | (_| | + \/ \__,_|___/\__| |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__| |_| |_|\___|\__|_| |_|\___/ \__,_| + | | + |_| +/-------------------------------------------------------------------------------------------------------------------------------/ + + @version 2.7.x + @created 30th April, 2015 + @package Component Builder + @subpackage validation_rules.css + @author Llewellyn van der Merwe + @github Joomla Component Builder + @copyright Copyright (C) 2015. All Rights Reserved + @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + + Builds Complex Joomla Components + +/-----------------------------------------------------------------------------------------------------------------------------*/ + +/* CSS Document */ + + diff --git a/admin/assets/images/icons/getsnippets.png b/admin/assets/images/icons/get_snippets.png similarity index 100% rename from admin/assets/images/icons/getsnippets.png rename to admin/assets/images/icons/get_snippets.png diff --git a/admin/assets/images/icons/help_document_add.png b/admin/assets/images/icons/help_document_add.png deleted file mode 100644 index 52889e109..000000000 Binary files a/admin/assets/images/icons/help_document_add.png and /dev/null differ diff --git a/admin/assets/images/icons/validation_rules.png b/admin/assets/images/icons/validation_rules.png new file mode 100644 index 000000000..2969d2cae Binary files /dev/null and b/admin/assets/images/icons/validation_rules.png differ diff --git a/admin/compiler/joomla_3/JFormRule.php b/admin/compiler/joomla_3/JFormRule.php index 9009436ca..5458a0e94 100644 --- a/admin/compiler/joomla_3/JFormRule.php +++ b/admin/compiler/joomla_3/JFormRule.php @@ -26,22 +26,17 @@ defined('_JEXEC') or die('Restricted access'); ?> ###BOM### -// No direct access to this file -defined('_JEXEC') or die('Restricted access'); +namespace Joomla\CMS\Form\Rule; + +defined('JPATH_PLATFORM') or die; + +use Joomla\CMS\Form\Form; +use Joomla\CMS\Form\FormRule; +use Joomla\Registry\Registry; -// import Joomla formrule library -jimport('joomla.form.formrule'); /** - * Form Rule class for the Joomla Framework. + * Form Rule (###Name###) class for the Joomla Platform. */ -class JFormRule###Name### extends JFormRule -{ - /** - * The regular expression. - * - * @access protected - * @var string - * @since 2.5 - */ - protected $regex = '^[^_]+$'; +class JFormRule###Name### extends FormRule +{###VALIDATION_RULE_METHODS### } diff --git a/admin/controller.php b/admin/controller.php index 8a041d7e1..a85e2b6d1 100644 --- a/admin/controller.php +++ b/admin/controller.php @@ -117,6 +117,7 @@ class ComponentbuilderController extends JControllerLegacy 'custom_code' => 'custom_codes', 'library' => 'libraries', 'snippet' => 'snippets', + 'validation_rule' => 'validation_rules', 'field' => 'fields', 'fieldtype' => 'fieldtypes', 'language_translation' => 'language_translations', diff --git a/admin/controllers/ajax.json.php b/admin/controllers/ajax.json.php index c52ef1b82..64e91ff4c 100644 --- a/admin/controllers/ajax.json.php +++ b/admin/controllers/ajax.json.php @@ -60,6 +60,9 @@ class ComponentbuilderControllerAjax extends JControllerLegacy $this->registerTask('getDynamicValues', 'ajax'); $this->registerTask('checkFunctionName', 'ajax'); $this->registerTask('usedin', 'ajax'); + $this->registerTask('getExistingValidationRuleCode', 'ajax'); + $this->registerTask('getValidationRulesTable', 'ajax'); + $this->registerTask('checkRuleName', 'ajax'); $this->registerTask('fieldOptions', 'ajax'); $this->registerTask('snippetDetails', 'ajax'); $this->registerTask('setSnippetGithub', 'ajax'); @@ -771,6 +774,121 @@ class ComponentbuilderControllerAjax extends JControllerLegacy } } break; + case 'getExistingValidationRuleCode': + try + { + $returnRaw = $jinput->get('raw', false, 'BOOLEAN'); + $nameValue = $jinput->get('name', NULL, 'WORD'); + if($nameValue && $user->id != 0) + { + $result = $this->getModel('ajax')->getExistingValidationRuleCode($nameValue); + } + else + { + $result = false; + } + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback . "(".json_encode($result).");"; + } + elseif($returnRaw) + { + echo json_encode($result); + } + else + { + echo "(".json_encode($result).");"; + } + } + catch(Exception $e) + { + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback."(".json_encode($e).");"; + } + else + { + echo "(".json_encode($e).");"; + } + } + break; + case 'getValidationRulesTable': + try + { + $returnRaw = $jinput->get('raw', false, 'BOOLEAN'); + $idValue = $jinput->get('id', NULL, 'INT'); + if($idValue && $user->id != 0) + { + $result = $this->getModel('ajax')->getValidationRulesTable($idValue); + } + else + { + $result = false; + } + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback . "(".json_encode($result).");"; + } + elseif($returnRaw) + { + echo json_encode($result); + } + else + { + echo "(".json_encode($result).");"; + } + } + catch(Exception $e) + { + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback."(".json_encode($e).");"; + } + else + { + echo "(".json_encode($e).");"; + } + } + break; + case 'checkRuleName': + try + { + $returnRaw = $jinput->get('raw', false, 'BOOLEAN'); + $nameValue = $jinput->get('name', NULL, 'STRING'); + $idValue = $jinput->get('id', NULL, 'INT'); + if($nameValue && $idValue && $user->id != 0) + { + $result = $this->getModel('ajax')->checkRuleName($nameValue, $idValue); + } + else + { + $result = false; + } + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback . "(".json_encode($result).");"; + } + elseif($returnRaw) + { + echo json_encode($result); + } + else + { + echo "(".json_encode($result).");"; + } + } + catch(Exception $e) + { + if($callback = $jinput->get('callback', null, 'CMD')) + { + echo $callback."(".json_encode($e).");"; + } + else + { + echo "(".json_encode($e).");"; + } + } + break; case 'fieldOptions': try { diff --git a/admin/controllers/validation_rule.php b/admin/controllers/validation_rule.php new file mode 100644 index 000000000..457bbeb79 --- /dev/null +++ b/admin/controllers/validation_rule.php @@ -0,0 +1,326 @@ + + @github Joomla Component Builder + @copyright Copyright (C) 2015. All Rights Reserved + @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + + Builds Complex Joomla Components + +/-----------------------------------------------------------------------------------------------------------------------------*/ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +// import Joomla controllerform library +jimport('joomla.application.component.controllerform'); + +/** + * Validation_rule Controller + */ +class ComponentbuilderControllerValidation_rule extends JControllerForm +{ + /** + * Current or most recently performed task. + * + * @var string + * @since 12.2 + * @note Replaces _task. + */ + protected $task; + + public function __construct($config = array()) + { + $this->view_list = 'Validation_rules'; // safeguard for setting the return view listing to the main view. + parent::__construct($config); + } + + /** + * Method override to check if you can add a new record. + * + * @param array $data An array of input data. + * + * @return boolean + * + * @since 1.6 + */ + protected function allowAdd($data = array()) + { + // Access check. + $access = JFactory::getUser()->authorise('validation_rule.access', 'com_componentbuilder'); + if (!$access) + { + return false; + } + // In the absense of better information, revert to the component permissions. + return JFactory::getUser()->authorise('validation_rule.create', $this->option); + } + + /** + * Method override to check if you can edit an existing record. + * + * @param array $data An array of input data. + * @param string $key The name of the key for the primary key. + * + * @return boolean + * + * @since 1.6 + */ + protected function allowEdit($data = array(), $key = 'id') + { + // get user object. + $user = JFactory::getUser(); + // get record id. + $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + + + // Access check. + $access = ($user->authorise('validation_rule.access', 'com_componentbuilder.validation_rule.' . (int) $recordId) && $user->authorise('validation_rule.access', 'com_componentbuilder')); + if (!$access) + { + return false; + } + + if ($recordId) + { + // The record has been set. Check the record permissions. + $permission = $user->authorise('validation_rule.edit', 'com_componentbuilder.validation_rule.' . (int) $recordId); + if (!$permission) + { + if ($user->authorise('validation_rule.edit.own', 'com_componentbuilder.validation_rule.' . $recordId)) + { + // Now test the owner is the user. + $ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0; + if (empty($ownerId)) + { + // Need to do a lookup from the model. + $record = $this->getModel()->getItem($recordId); + + if (empty($record)) + { + return false; + } + $ownerId = $record->created_by; + } + + // If the owner matches 'me' then allow. + if ($ownerId == $user->id) + { + if ($user->authorise('validation_rule.edit.own', 'com_componentbuilder')) + { + return true; + } + } + } + return false; + } + } + // Since there is no permission, revert to the component permissions. + return $user->authorise('validation_rule.edit', $this->option); + } + + /** + * Gets the URL arguments to append to an item redirect. + * + * @param integer $recordId The primary key id for the item. + * @param string $urlVar The name of the URL variable for the id. + * + * @return string The arguments to append to the redirect URL. + * + * @since 12.2 + */ + protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') + { + $tmpl = $this->input->get('tmpl'); + $layout = $this->input->get('layout', 'edit', 'string'); + + $ref = $this->input->get('ref', 0, 'string'); + $refid = $this->input->get('refid', 0, 'int'); + + // Setup redirect info. + + $append = ''; + + if ($refid) + { + $append .= '&ref='.(string)$ref.'&refid='.(int)$refid; + } + elseif ($ref) + { + $append .= '&ref='.(string)$ref; + } + + if ($tmpl) + { + $append .= '&tmpl=' . $tmpl; + } + + if ($layout) + { + $append .= '&layout=' . $layout; + } + + if ($recordId) + { + $append .= '&' . $urlVar . '=' . $recordId; + } + + return $append; + } + + /** + * Method to run batch operations. + * + * @param object $model The model. + * + * @return boolean True if successful, false otherwise and internal error is set. + * + * @since 2.5 + */ + public function batch($model = null) + { + JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + + // Set the model + $model = $this->getModel('Validation_rule', '', array()); + + // Preset the redirect + $this->setRedirect(JRoute::_('index.php?option=com_componentbuilder&view=validation_rules' . $this->getRedirectToListAppend(), false)); + + return parent::batch($model); + } + + /** + * Method to cancel an edit. + * + * @param string $key The name of the primary key of the URL variable. + * + * @return boolean True if access level checks pass, false otherwise. + * + * @since 12.2 + */ + public function cancel($key = null) + { + // get the referal details + $this->ref = $this->input->get('ref', 0, 'word'); + $this->refid = $this->input->get('refid', 0, 'int'); + + $cancel = parent::cancel($key); + + if ($cancel) + { + if ($this->refid) + { + $redirect = '&view='.(string)$this->ref.'&layout=edit&id='.(int)$this->refid; + + // Redirect to the item screen. + $this->setRedirect( + JRoute::_( + 'index.php?option=' . $this->option . $redirect, false + ) + ); + } + elseif ($this->ref) + { + $redirect = '&view='.(string)$this->ref; + + // Redirect to the list screen. + $this->setRedirect( + JRoute::_( + 'index.php?option=' . $this->option . $redirect, false + ) + ); + } + } + else + { + // Redirect to the items screen. + $this->setRedirect( + JRoute::_( + 'index.php?option=' . $this->option . '&view=' . $this->view_list, false + ) + ); + } + return $cancel; + } + + /** + * Method to save a record. + * + * @param string $key The name of the primary key of the URL variable. + * @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions). + * + * @return boolean True if successful, false otherwise. + * + * @since 12.2 + */ + public function save($key = null, $urlVar = null) + { + // get the referal details + $this->ref = $this->input->get('ref', 0, 'word'); + $this->refid = $this->input->get('refid', 0, 'int'); + + if ($this->ref || $this->refid) + { + // to make sure the item is checkedin on redirect + $this->task = 'save'; + } + + $saved = parent::save($key, $urlVar); + + if ($this->refid && $saved) + { + $redirect = '&view='.(string)$this->ref.'&layout=edit&id='.(int)$this->refid; + + // Redirect to the item screen. + $this->setRedirect( + JRoute::_( + 'index.php?option=' . $this->option . $redirect, false + ) + ); + } + elseif ($this->ref && $saved) + { + $redirect = '&view='.(string)$this->ref; + + // Redirect to the list screen. + $this->setRedirect( + JRoute::_( + 'index.php?option=' . $this->option . $redirect, false + ) + ); + } + return $saved; + } + + /** + * Function that allows child controller access to model data + * after the data has been saved. + * + * @param JModel &$model The data model object. + * @param array $validData The validated data. + * + * @return void + * + * @since 11.1 + */ + protected function postSaveHook(JModelLegacy $model, $validData = array()) + { + return; + } + +} diff --git a/admin/controllers/validation_rules.php b/admin/controllers/validation_rules.php new file mode 100644 index 000000000..868d1971f --- /dev/null +++ b/admin/controllers/validation_rules.php @@ -0,0 +1,111 @@ + + @github Joomla Component Builder + @copyright Copyright (C) 2015. All Rights Reserved + @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + + Builds Complex Joomla Components + +/-----------------------------------------------------------------------------------------------------------------------------*/ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +// import Joomla controlleradmin library +jimport('joomla.application.component.controlleradmin'); + +/** + * Validation_rules Controller + */ +class ComponentbuilderControllerValidation_rules extends JControllerAdmin +{ + protected $text_prefix = 'COM_COMPONENTBUILDER_VALIDATION_RULES'; + /** + * Proxy for getModel. + * @since 2.5 + */ + public function getModel($name = 'Validation_rule', $prefix = 'ComponentbuilderModel', $config = array()) + { + $model = parent::getModel($name, $prefix, array('ignore_request' => true)); + + return $model; + } + + public function exportData() + { + // Check for request forgeries + JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); + // check if export is allowed for this user. + $user = JFactory::getUser(); + if ($user->authorise('validation_rule.export', 'com_componentbuilder') && $user->authorise('core.export', 'com_componentbuilder')) + { + // Get the input + $input = JFactory::getApplication()->input; + $pks = $input->post->get('cid', array(), 'array'); + // Sanitize the input + JArrayHelper::toInteger($pks); + // Get the model + $model = $this->getModel('Validation_rules'); + // get the data to export + $data = $model->getExportData($pks); + if (ComponentbuilderHelper::checkArray($data)) + { + // now set the data to the spreadsheet + $date = JFactory::getDate(); + ComponentbuilderHelper::xls($data,'Validation_rules_'.$date->format('jS_F_Y'),'Validation rules exported ('.$date->format('jS F, Y').')','validation rules'); + } + } + // Redirect to the list screen with error. + $message = JText::_('COM_COMPONENTBUILDER_EXPORT_FAILED'); + $this->setRedirect(JRoute::_('index.php?option=com_componentbuilder&view=validation_rules', false), $message, 'error'); + return; + } + + + public function importData() + { + // Check for request forgeries + JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); + // check if import is allowed for this user. + $user = JFactory::getUser(); + if ($user->authorise('validation_rule.import', 'com_componentbuilder') && $user->authorise('core.import', 'com_componentbuilder')) + { + // Get the import model + $model = $this->getModel('Validation_rules'); + // get the headers to import + $headers = $model->getExImPortHeaders(); + if (ComponentbuilderHelper::checkObject($headers)) + { + // Load headers to session. + $session = JFactory::getSession(); + $headers = json_encode($headers); + $session->set('validation_rule_VDM_IMPORTHEADERS', $headers); + $session->set('backto_VDM_IMPORT', 'validation_rules'); + $session->set('dataType_VDM_IMPORTINTO', 'validation_rule'); + // Redirect to import view. + $message = JText::_('COM_COMPONENTBUILDER_IMPORT_SELECT_FILE_FOR_VALIDATION_RULES'); + $this->setRedirect(JRoute::_('index.php?option=com_componentbuilder&view=import', false), $message); + return; + } + } + // Redirect to the list screen with error. + $message = JText::_('COM_COMPONENTBUILDER_IMPORT_FAILED'); + $this->setRedirect(JRoute::_('index.php?option=com_componentbuilder&view=validation_rules', false), $message, 'error'); + return; + } +} diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index 272312b1d..fe2615b9c 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -414,6 +414,13 @@ class Get */ public $sqlTweak = array(); + /** + * The validation rules that should be added + * + * @var array + */ + public $validationRules = array(); + /** * The admin views data array * @@ -2082,6 +2089,37 @@ class Get // load the values form params $field->xml = $this->setDynamicValues(json_decode($field->xml)); + + // check if we have validate (validation rule set) + $validationRule = ComponentbuilderHelper::getBetween($field->xml, 'validate="', '"'); + if (ComponentbuilderHelper::checkString($validationRule)) + { + // make sure it is lowercase + $validationRule = ComponentbuilderHelper::safeString($validationRule); + // make sure it is not already set + if (!isset($this->validationRules[$validationRule])) + { + // get joomla core validation names + if ($coreValidationRules = ComponentbuilderHelper::getExistingValidationRuleNames(true)) + { + // make sure this rule is not a core validation rule + if (!in_array($validationRule, $coreValidationRules)) + { + // get the class methods for this rule if it exists + if ($this->validationRules[$validationRule] = ComponentbuilderHelper::getVar('validation_rule', $validationRule, 'name','php')) + { + // open and set the validation rule + $this->validationRules[$validationRule] = $this->setDynamicValues(base64_decode($this->validationRules[$validationRule])); + } + else + { + // set the notice that this validation rule is custom and was not found + + } + } + } + } + } // load the type values form type params $field->properties = (isset($field->properties) && ComponentbuilderHelper::checkJson($field->properties)) ? json_decode($field->properties, true) : null; diff --git a/admin/helpers/compiler/c_Fields.php b/admin/helpers/compiler/c_Fields.php index ba18df700..e532a7dbf 100644 --- a/admin/helpers/compiler/c_Fields.php +++ b/admin/helpers/compiler/c_Fields.php @@ -2083,6 +2083,15 @@ class Fields extends Structure // get the actual field name $xmlValue = $this->setPlaceholders($name, $placeholders); } + elseif ($property['name'] === 'validate') + { + // check if we have validate (validation rule set) + $xmlValue = ComponentbuilderHelper::getBetween($field['settings']->xml, 'validate="', '"'); + if (ComponentbuilderHelper::checkString($xmlValue)) + { + $xmlValue = ComponentbuilderHelper::safeString($xmlValue); + } + } elseif ($property['name'] === 'extension' || $property['name'] === 'directory' || $property['name'] === 'formsource') { $xmlValue = ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"'); @@ -2290,6 +2299,16 @@ class Fields extends Structure { $fieldAttributes['display'] = $display; } + // make sure validation is set if found (even it not part of field properties) + if (!isset($fieldAttributes['validate'])) + { + // check if we have validate (validation rule set) + $validationRule = ComponentbuilderHelper::getBetween($field['settings']->xml, 'validate="', '"'); + if (ComponentbuilderHelper::checkString($validationRule)) + { + $fieldAttributes['validate'] = ComponentbuilderHelper::safeString($validationRule); + } + } } } return $fieldAttributes; diff --git a/admin/helpers/compiler/f_Infusion.php b/admin/helpers/compiler/f_Infusion.php index 576b0aad6..706092265 100644 --- a/admin/helpers/compiler/f_Infusion.php +++ b/admin/helpers/compiler/f_Infusion.php @@ -815,6 +815,21 @@ class Infusion extends Interpretation // set the module $this->fileContentDynamic['ajax']['###AJAX_SITE_MODEL_METHODS###'] = $this->setAjaxModelMethods('site'); } + + // build the validation rules + if (isset($this->validationRules) && ComponentbuilderHelper::checkArray($this->validationRules)) + { + foreach ($this->validationRules as $rule => $_php) + { + // setup rule file + $target = array('admin' => 'a_rule_zi'); + $this->buildDynamique($target, 'rule', $rule); + // set the JFormRule Name + $this->fileContentDynamic['a_rule_zi_'.$rule]['###Name###'] = ucfirst($rule); + // set the JFormRule PHP + $this->fileContentDynamic['a_rule_zi_'.$rule]['###VALIDATION_RULE_METHODS###'] = PHP_EOL . $_php; + } + } // run the second run if needed if (isset($this->secondRunAdmin) && ComponentbuilderHelper::checkArray($this->secondRunAdmin)) diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index e845bcddb..040f3f76b 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -157,6 +157,60 @@ abstract class ComponentbuilderHelper } return $object; } + + /* + * Get the Array of Existing Validation Rule Names + * + * @return array + */ + public static function getExistingValidationRuleNames($lowercase = false) + { + if (!$items = self::get('_existing_validation_rules_VDM', null)) + { + // load the file class + jimport('joomla.filesystem.file'); + jimport('joomla.filesystem.folder'); + // set the path to the form validation rules + $path = JPATH_LIBRARIES . '/src/Form/Rule'; + // check if the path exist + if (!JFolder::exists($path)) + { + return false; + } + // we must first store the current working directory + $joomla = getcwd(); + // go to that folder + chdir($path); + // load all the files in this path + $items = JFolder::files('.', '\.php', true, true); + // change back to Joomla working directory + chdir($joomla); + // make sure we have an array + if (!self::checkArray($items)) + { + return false; + } + // remove the Rule.php from the name + $items = array_map( function ($name) { + return str_replace(array('./','Rule.php'), '', $name); + }, $items); + // store the names for next run + self::set('_existing_validation_rules_VDM', json_encode($items)); + } + // make sure it is no longer json + if (self::checkJson($items)) + { + $items = json_decode($items, true); + } + // check if the names should be all lowercase + if ($lowercase) + { + $items = array_map( function($item) { + return strtolower($item); + }, $items); + } + return $items; + } public static function getDynamicScripts($type, $fieldName = false) { @@ -1626,10 +1680,13 @@ abstract class ComponentbuilderHelper { $result = $db->loadObject(); $properties = json_decode($result->properties,true); - $field = array('values' => " '