/** * Method to test the email address and optionally check for uniqueness. * * @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. * * @since 11.1 */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { // If the field is empty and not required, the field is valid. $required = (string) $element['required'] == 'true' || (string) $element['required'] == 'required'; if (!$required && empty($value)) { return true; } // Test the value against the regular expression. if (!parent::test($element, $value, $group, $input, $form)) { return false; } // Check if we should test for uniqueness. $unique = (string) $element['unique'] == 'true' || (string) $element['unique'] == 'unique'; if ($unique) { // Get the database object and a new query object. $db = JFactory::getDBO(); $query = $db->getQuery(true); // Build the query. $query->select('COUNT(*)'); $query->from('#__users'); $query->where('email = ' . $db->quote($value)); // Get the extra field check attribute. $userId = $form instanceof JForm ? $form->getValue('id') : ''; $query->where($db->quoteName('id') . ' <> ' . (int) $userId); // Set and query the database. $db->setQuery($query); $duplicate = (bool) $db->loadResult(); if ($duplicate) { return false; } } return true; }
public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, JForm $form = null) { if ($value == null or $value == '') { return true; } return parent::test($element, $value, $group, $input, $form); }
/** * @param SimpleXMLElement $element The JXmlElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { if (is_object($value)) { $error = false; foreach ($value->name as $name) { if (!parent::test($element, $name, $group, $input, $form) and $name != '') { $error = true; } } if ($error) { // Change to RuntimeException when Joomla! 2.5 no longer supported as JException (deprecated) and will be removed from Joomla return new JException(JText::_('COM_COMPONENTARCHITECT_COMPONENT_WIZARD_ERROR_INVALID_OBJECTS'), 1, E_WARNING); } else { return true; } } if (is_array($value)) { $value = $value['name']; } if (!parent::test($element, $value, $group, $input, $form)) { return false; } else { return true; } }
public function test(&$element, $value, $group = null, &$input = null, &$form = null) { if ($value == null or $value == '') { return true; } return parent::test($element, $value, $group, $input, $form); }
/** * @param SimpleXMLElement $element The JXmlElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { if (!parent::test($element, $value, $group, $input, $form)) { return false; } else { //[%%START_CUSTOM_CODE%%] if ($input->get('component_object_id') != 0) { $db = JFactory::getDBO(); $query = $db->getQuery(true); // Build the query. $query->select('COUNT(*)'); $query->from('#__componentarchitect_fields'); $query->where('code_name = ' . $db->quote($value)); $query->where('component_object_id = ' . $db->quote($input->get('component_object_id'))); $query->where('id != ' . $db->quote($input->get('id'))); try { // Set and query the database. $db->setQuery($query); $duplicate = (bool) $db->loadResult(); $title = $db->loadResult(); } catch (RuntimeException $e) { throw new RuntimeException(JText::sprintf('COM_COMPONENTARCHITECT_ERROR_DATABASE_FATAL', $e->getMessage())); } if ($duplicate) { // Change to RuntimeException when Joomla! 2.5 no longer supported as JException (deprecated) and will be removed from Joomla return new JException(JText::_('COM_COMPONENTARCHITECT_FIELDS_FIELD_CODE_NAME_ERROR_DUPLICATE'), 1, E_WARNING); } } //[%%END_CUSTOM_CODE%%] return true; } }
/** * @param SimpleXMLElement $element The JXmlElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { if (!parent::test($element, $value, $group, $input, $form)) { return false; } else { return true; } }
/** * Method to test the email address and optionally check for uniqueness. * * @param object $element The JXMLElement object representing the <field /> tag for the * form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array * container for the field. For example if the field has name="foo" * and the group value is set to "bar" then the full field name * would end up being "bar[foo]". * @param object $input An optional JRegistry object with the entire data set to validate * against the entire form. * @param object $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. * @since 1.0 */ public function test(&$element, $value, $group = null, &$input = null, &$form = null) { // If the field is empty and not required, the field is valid. $required = (string) $element['required'] == 'true' || (string) $element['required'] == 'required'; if (!$required && empty($value)) { return true; } // Test the value against the regular expression. if (!parent::test($element, $value, $group, $input, $form)) { return false; } // Check if we should test for uniqueness. $unique = (string) $element['unique'] == 'true' || (string) $element['unique'] == 'unique'; if ($unique) { // Get the database object and a new query object. $db = JFactory::getDBO(); $query = $db->getQuery(true); // Build the query. $query->select('COUNT(*)'); $query->from('#__newsletter_subscribers'); $query->where('email = ' . $db->quote($value)); // Get the extra field check attribute. $userId = $form instanceof JForm ? $form->getValue('subscriber_id') : ''; $query->where($db->nameQuote('subscriber_id') . ' <> ' . (int) $userId); // Set and query the database. $db->setQuery($query); $duplicate = (bool) $db->loadResult(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseWarning(500, $db->getErrorMsg()); } if ($duplicate) { return false; } // Build the query. $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__users AS u'); $query->join('left', '#__newsletter_subscribers AS s ON u.id = s.user_id'); $query->where('u.email = ' . $db->quote($value)); $query->where('(subscriber_id <> ' . (int) $userId . ' OR subscriber_id IS NULL)'); // Set and query the database. $db->setQuery($query); $duplicate = (bool) $db->loadResult(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseWarning(500, $db->getErrorMsg()); } if ($duplicate) { return false; } } return true; }
/** * Method to test the email address and optionally check for uniqueness. * * @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. * * @since 11.1 */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { // If the field is empty and not required, the field is valid. $required = (string) $element['required'] == 'true' || (string) $element['required'] == 'required'; if (!$required && empty($value)) { return true; } // If the tld attribute is present, change the regular expression to require at least 2 characters for it. $tld = (string) $element['tld'] == 'tld' || (string) $element['tld'] == 'required'; if ($tld) { $this->regex = '^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]{2,})$'; } // Determine if the multiple attribute is present $multiple = (string) $element['multiple'] == 'true' || (string) $element['multiple'] == 'multiple'; if ($multiple) { $values = explode(',', $value); } if (!$multiple) { // Handle idn e-mail addresses by converting to punycode. $value = JStringPunycode::emailToPunycode($value); // Test the value against the regular expression. if (!parent::test($element, $value, $group, $input, $form)) { return false; } } else { foreach ($values as $value) { // Handle idn e-mail addresses by converting to punycode. $value = JStringPunycode::emailToPunycode($value); // Test the value against the regular expression. if (!parent::test($element, $value, $group, $input, $form)) { return false; } } } // Check if we should test for uniqueness. This only can be used if multiple is not true $unique = (string) $element['unique'] == 'true' || (string) $element['unique'] == 'unique'; if ($unique && !$multiple) { // Get the database object and a new query object. $db = JFactory::getDbo(); $query = $db->getQuery(true); // Build the query. $query->select('COUNT(*)')->from('#__users')->where('email = ' . $db->quote($value)); // Get the extra field check attribute. $userId = $form instanceof JForm ? $form->getValue('id') : ''; $query->where($db->quoteName('id') . ' <> ' . (int) $userId); // Set and query the database. $db->setQuery($query); $duplicate = (bool) $db->loadResult(); if ($duplicate) { return false; } } return true; }
/** * Method to test list of email and name separated with | and each pair in new line * Example: biuro@perfect-web.pl|Perfect-Web * support@perfect-web.pl|Support * * @param object $element The JXMLElement object representing the <field /> tag for the * form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array * container for the field. For example if the field has name="foo" * and the group value is set to "bar" then the full field name * would end up being "bar[foo]". * @param object $input An optional JRegistry object with the entire data set to validate * against the entire form. * @param object $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. * * @since 11.1 * @throws JException on invalid rule. */ public function test(&$element, $value, $group = null, &$input = null, &$form = null) { // If the field is empty and not required, the field is valid. $required = (string) $element['required'] == 'true' || (string) $element['required'] == 'required'; if (!$required && empty($value)) { return true; } // Test the value against the regular expression. if (!parent::test($element, $value, $group, $input, $form)) { return false; } return true; }
/** * @param SimpleXMLElement $element The JXmlElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { if (!parent::test($element, $value, $group, $input, $form)) { return false; } else { //[%%START_CUSTOM_CODE%%] if ($value == '1' and $input->get('order', '0') == '1') { // Change to RuntimeException when Joomla! 2.5 no longer supported as JException (deprecated) and will be removed from Joomla return new JException(JText::_('COM_COMPONENTARCHITECT_FIELDS_FIELD_MULTIPLE_ERROR_CANNOT_BE_ORDER'), 1, E_WARNING); } //[%%END_CUSTOM_CODE%%] return true; } }
/** * @param SimpleXMLElement $element The JXmlElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { if (!parent::test($element, $value, $group, $input, $form)) { return false; } else { //[%%START_CUSTOM_CODE%%] if ($value != '' and ($value[0] != "'" or $value[strlen($value) - 1] != "'")) { // Change to RuntimeException when Joomla! 2.5 no longer supported as JException (deprecated) and will be removed from Joomla return new JException(JText::_('COM_COMPONENTARCHITECT_FIELDTYPES_FIELD_MYSQL_DEFAULT_DEFAULT_ERROR_NOT_IN_QUOTES'), 1, E_WARNING); } //[%%END_CUSTOM_CODE%%] return true; } }
/** * @param SimpleXMLElement $element The JXmlElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { if (!parent::test($element, $value, $group, $input, $form)) { return false; } else { //[%%START_CUSTOM_CODE%%] if ($input->get('generate_admin') == '0' and $value == '1') { // Change to RuntimeException when Joomla! 2.5 no longer supported as JException (deprecated) and will be removed from Joomla return new JException(JText::_('COM_COMPONENTARCHITECT_COMPONENTS_FIELD_GENERATE_ADMIN_VIEWS_ERROR_ADMIN_NOT_SET'), 1, E_WARNING); } //[%%END_CUSTOM_CODE%%] return true; } }
/** * @param SimpleXMLElement $element The JXmlElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { if (!parent::test($element, $value, $group, $input, $form)) { return false; } else { //[%%START_CUSTOM_CODE%%] $joomla_features = (array) $input->get('joomla_features'); if ($joomla_features['include_description'] == '0' and $value == '1') { // Change to RuntimeException when Joomla! 2.5 no longer supported as JException (deprecated) and will be removed from Joomla return new JException(JText::_('COM_COMPONENTARCHITECT_COMPONENTS_FIELD_INCLUDE_INTRO_ERROR_DESCRIPTION_NOT_SET'), 1, E_WARNING); } //[%%END_CUSTOM_CODE%%] return true; } }
/** * @param SimpleXMLElement $element The JXmlElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { if (!parent::test($element, $value, $group, $input, $form)) { return false; } else { //[%%START_CUSTOM_CODE%%] $joomla_parts = (array) $input->get('joomla_parts'); if ($joomla_parts['generate_plugins'] == '0' and $value == '1') { // Change to RuntimeException when Joomla! 2.5 no longer supported as JException (deprecated) and will be removed from Joomla return new JException(JText::_('COM_COMPONENTARCHITECT_COMPONENTOBJECTS_FIELD_GENERATE_PLUGINS_EMAILCLOAK_ERROR_PLUGINS_NOT_SET'), 1, E_WARNING); } //[%%END_CUSTOM_CODE%%] return true; } }
/** * @param SimpleXMLElement $element The JXmlElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { if (!parent::test($element, $value, $group, $input, $form)) { return false; } else { //[%%START_CUSTOM_CODE%%] $joomla_features = (array) $input->get('joomla_features'); if ($input->get('component_id') > 0 and ($value == '' or $joomla_features['include_description'] == '')) { $db = JFactory::getDBO(); $query = $db->getQuery(true); // Build the query. $query->select('joomla_features'); $query->from('#__componentarchitect_components'); $query->where('id = ' . $db->quote($input->get('component_id'))); // Set and query the database. $db->setQuery($query); $component_joomla_features = $db->loadResult(); $registry = new JRegistry(); $registry->loadString($component_joomla_features); $component_joomla_features = $registry->toArray(); $registry = null; //release memory // If values are blank use the Joomla! feature from the component if ($value == '') { $include_intro = $component_joomla_features['include_intro']; } else { $include_intro = $value; } if ($joomla_features['include_description'] == '') { $include_description = $component_joomla_features['include_description']; } else { $include_description = $joomla_features['include_description']; } if ($include_description == '0' and $include_intro == '1') { // Change to RuntimeException when Joomla! 2.5 no longer supported as JException (deprecated) and will be removed from Joomla return new JException(JText::_('COM_COMPONENTARCHITECT_COMPONENTOBJECTS_FIELD_INCLUDE_INTRO_ERROR_DESCRIPTION_NOT_SET'), 1, E_WARNING); } } else { if ($joomla_features['include_description'] == '0' and $value == '1') { // Change to RuntimeException when Joomla! 2.5 no longer supported as JException (deprecated) and will be removed from Joomla return new JException(JText::_('COM_COMPONENTARCHITECT_COMPONENTOBJECTS_FIELD_INCLUDE_INTRO_ERROR_DESCRIPTION_NOT_SET'), 1, E_WARNING); } } //[%%END_CUSTOM_CODE%%] return true; } }
/** * @param SimpleXMLElement $element The JXmlElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { if (!parent::test($element, $value, $group, $input, $form)) { return false; } else { //[%%START_CUSTOM_CODE%%] $file_name = $_FILES['jform']['name']['categories_icon_16px']; if ($file_name != '') { $file_name_parts = explode('.', $file_name); $file_type = $file_name_parts[count($file_name_parts) - 1]; if ($file_type != 'png') { // Change to RuntimeException when Joomla! 2.5 no longer supported as JException (deprecated) and will be removed from Joomla return new JException(JText::_('COM_COMPONENTARCHITECT_COMPONENTS_FIELD_CATEGORIES_ICON_16PX_ERROR_NOT_PNG'), 1, E_WARNING); } } //[%%END_CUSTOM_CODE%%] return true; } }
/** * Method to test if an e-mail address is unique. * * @param object $field A reference to the form field. * @param mixed $values The values to test for validiaty. * @return mixed JException on invalid rule, true if the value is valid, false otherwise. * @since 1.6 */ public function test(&$field, &$values) { $return = false; $name = (string) $field->attributes()->name; $check = (string) $field->attributes()->unique == 'true' || (string) $field->attributes()->unique == 'unique'; // If the field is empty and not required, the field is valid. if ((string) $field->attributes()->required != 'true') { // Get the data for the field. $value = array_key_exists($name, $values) ? $values[$name] : null; // If the data is empty, return valid. if ($value == null) { return true; } } // Check if we should test for uniqueness. if ($check) { $key = (string) $field->attributes()->field; $value = isset($values[$key]) ? $values[$key] : 0; // Check the rule. if (!$key) { return new JException('Invalid Form Rule :: ' . get_class($this)); } // Check if the username is unique. $db =& JFactory::getDbo(); $db->setQuery('SELECT count(*) FROM `#__users`' . ' WHERE `email` = ' . $db->Quote($values[$name]) . ' AND ' . $db->nameQuote($key) . ' != ' . $db->Quote($value)); $duplicate = (bool) $db->loadResult(); // Check for a database error. if ($db->getErrorNum()) { return new JException('Database Error :: ' . $db->getErrorMsg()); } // Test the value against the regular expression. if (parent::test($field, $values) && !$duplicate) { $return = true; } } else { // Test the value against the regular expression. if (parent::test($field, $values)) { $return = true; } } return $return; }
public function test(&$element, $value, $group = null, &$input = null, &$form = null) { return false; return parent::test($element, $value, $group, $input, $form); }
/** * Method to test the field value. * * @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * @param JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form. * @param JForm $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. * * @since 11.1 */ public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null) { // Test the value against the regular expression. return parent::test($element, $value, $group, $input, $form); }