first commit

This commit is contained in:
alazhar
2020-01-02 22:20:31 +07:00
commit 10eb3340ad
5753 changed files with 631345 additions and 0 deletions

View File

@ -0,0 +1,36 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleBoolean extends JFormRule
{
/**
* The regular expression to use in testing a form field value.
*
* @var string
* @since 11.1
*/
protected $regex = '^(?:[01]|true|false)$';
/**
* The regular expression modifiers to use when testing a form field value.
*
* @var string
* @since 11.1
*/
protected $modifiers = 'i';
}

View File

@ -0,0 +1,62 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.2
*/
class JFormRuleColor extends JFormRule
{
/**
* Method to test for a valid color in hexadecimal.
*
* @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.2
*/
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null)
{
$value = trim($value);
if (empty($value))
{
// A color field can't be empty
return true;
}
if ($value[0] != '#')
{
return false;
}
// Remove the leading # if present to validate the numeric part
$value = ltrim($value, '#');
// The value must be 6 or 3 characters long
if (!((strlen($value) == 6 || strlen($value) == 3) && ctype_xdigit($value)))
{
return false;
}
return true;
}
}

View File

@ -0,0 +1,128 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleEmail extends JFormRule
{
/**
* The regular expression to use in testing a form field value.
*
* @var string
* @since 11.1
* @see http://www.w3.org/TR/html-markup/input.email.html
*/
protected $regex = '^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$';
/**
* 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;
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleEquals extends JFormRule
{
/**
* Method to test if two values are equal. To use this rule, the form
* XML needs a validate attribute of equals and a field attribute
* that is equal to the field to test against.
*
* @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
* @throws InvalidArgumentException
* @throws UnexpectedValueException
*/
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null)
{
$field = (string) $element['field'];
// Check that a validation field is set.
if (!$field)
{
throw new UnexpectedValueException(sprintf('$field empty in %s::test', get_class($this)));
}
if (is_null($form))
{
throw new InvalidArgumentException(sprintf('The value for $form must not be null in %s', get_class($this)));
}
if (is_null($input))
{
throw new InvalidArgumentException(sprintf('The value for $input must not be null in %s', get_class($this)));
}
// Test the two values against each other.
if ($value == $input->get($field))
{
return true;
}
return false;
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,48 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
* Requires the value entered be one of the options in a field of type="list"
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleOptions extends JFormRule
{
/**
* Method to test the 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)
{
// Check each value and return true if we get a match
foreach ($element->option as $option)
{
if ($value == (string) $option->attributes()->value)
{
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,114 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleRules extends JFormRule
{
/**
* Method to test the 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)
{
// Get the possible field actions and the ones posted to validate them.
$fieldActions = self::getFieldActions($element);
$valueActions = self::getValueActions($value);
// Make sure that all posted actions are in the list of possible actions for the field.
foreach ($valueActions as $action)
{
if (!in_array($action, $fieldActions))
{
return false;
}
}
return true;
}
/**
* Method to get the list of permission action names from the form field value.
*
* @param mixed $value The form field value to validate.
*
* @return array A list of permission action names from the form field value.
*
* @since 11.1
*/
protected function getValueActions($value)
{
$actions = array();
// Iterate over the asset actions and add to the actions.
foreach ((array) $value as $name => $rules)
{
$actions[] = $name;
}
return $actions;
}
/**
* Method to get the list of possible permission action names for the form field.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the
* form field object.
*
* @return array A list of permission action names from the form field element definition.
*
* @since 11.1
*/
protected function getFieldActions(SimpleXMLElement $element)
{
$actions = array();
// Initialise some field attributes.
$section = $element['section'] ? (string) $element['section'] : '';
$component = $element['component'] ? (string) $element['component'] : '';
// Get the asset actions for the element.
$elActions = JAccess::getActions($component, $section);
// Iterate over the asset actions and add to the actions.
foreach ($elActions as $item)
{
$actions[] = $item->name;
}
// Iterate over the children and add to the actions.
foreach ($element->children() as $el)
{
if ($el->getName() == 'action')
{
$actions[] = (string) $el['name'];
}
}
return $actions;
}
}

View File

@ -0,0 +1,105 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleTel extends JFormRule
{
/**
* Method to test the url for a valid parts.
*
* @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;
}
/*
* @see http://www.nanpa.com/
* @see http://tools.ietf.org/html/rfc4933
* @see http://www.itu.int/rec/T-REC-E.164/en
*
* Regex by Steve Levithan
* @see http://blog.stevenlevithan.com/archives/validate-phone-number
* @note that valid ITU-T and EPP must begin with +.
*/
$regexarray = array('NANP' => '/^(?:\+?1[-. ]?)?\(?([2-9][0-8][0-9])\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/',
'ITU-T' => '/^\+(?:[0-9] ?){6,14}[0-9]$/', 'EPP' => '/^\+[0-9]{1,3}\.[0-9]{4,14}(?:x.+)?$/');
if (isset($element['plan']))
{
$plan = (string) $element['plan'];
if ($plan == 'northamerica' || $plan == 'us')
{
$plan = 'NANP';
}
elseif ($plan == 'International' || $plan == 'int' || $plan == 'missdn' || !$plan)
{
$plan = 'ITU-T';
}
elseif ($plan == 'IETF')
{
$plan = 'EPP';
}
$regex = $regexarray[$plan];
// Test the value against the regular expression.
if (preg_match($regex, $value) == false)
{
return false;
}
}
else
{
/*
* If the rule is set but no plan is selected just check that there are between
* 7 and 15 digits inclusive and no illegal characters (but common number separators
* are allowed).
*/
$cleanvalue = preg_replace('/[+. \-(\)]/', '', $value);
$regex = '/^[0-9]{7,15}?$/';
if (preg_match($regex, $cleanvalue) == true)
{
return true;
}
else
{
return false;
}
}
return true;
}
}

View File

@ -0,0 +1,98 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleUrl extends JFormRule
{
/**
* Method to test an external url for a valid parts.
*
* @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
* @link http://www.w3.org/Addressing/URL/url-spec.txt
* @see Jstring
*/
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;
}
$urlParts = JString::parse_url($value);
// See http://www.w3.org/Addressing/URL/url-spec.txt
// Use the full list or optionally specify a list of permitted schemes.
if ($element['schemes'] == '')
{
$scheme = array('http', 'https', 'ftp', 'ftps', 'gopher', 'mailto', 'news', 'prospero', 'telnet', 'rlogin', 'tn3270', 'wais', 'url',
'mid', 'cid', 'nntp', 'tel', 'urn', 'ldap', 'file', 'fax', 'modem', 'git');
}
else
{
$scheme = explode(',', $element['schemes']);
}
/*
* This rule is only for full URLs with schemes because parse_url does not parse
* accurately without a scheme.
* @see http://php.net/manual/en/function.parse-url.php
*/
if ($urlParts && !array_key_exists('scheme', $urlParts))
{
return false;
}
$urlScheme = (string) $urlParts['scheme'];
$urlScheme = strtolower($urlScheme);
if (in_array($urlScheme, $scheme) == false)
{
return false;
}
// For some schemes here must be two slashes.
if (($urlScheme == 'http' || $urlScheme == 'https' || $urlScheme == 'ftp' || $urlScheme == 'sftp' || $urlScheme == 'gopher'
|| $urlScheme == 'wais' || $urlScheme == 'gopher' || $urlScheme == 'prospero' || $urlScheme == 'telnet' || $urlScheme == 'git')
&& ((substr($value, strlen($urlScheme), 3)) !== '://'))
{
return false;
}
// The best we can do for the rest is make sure that the strings are valid UTF-8
// and the port is an integer.
if (array_key_exists('host', $urlParts) && !JString::valid((string) $urlParts['host']))
{
return false;
}
if (array_key_exists('port', $urlParts) && !is_int((int) $urlParts['port']))
{
return false;
}
if (array_key_exists('path', $urlParts) && !JString::valid((string) $urlParts['path']))
{
return false;
}
return true;
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleUsername extends JFormRule
{
/**
* Method to test the username 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)
{
// 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('username = ' . $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;
}
}