File manager - Edit - /home/ferretapmx/public_html/Form.tar
Back
FormRule.php 0000644 00000006336 15231126527 0007024 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt * * Remove phpcs exception with deprecated constant JCOMPAT_UNICODE_PROPERTIES * @phpcs:disable PSR1.Files.SideEffects */ namespace Joomla\CMS\Form; \defined('_JEXEC') or die; use Joomla\Registry\Registry; // Detect if we have full UTF-8 and unicode PCRE support. if (!\defined('JCOMPAT_UNICODE_PROPERTIES')) { /** * Flag indicating UTF-8 and PCRE support is present * * @const boolean * @since 1.6 * * @deprecated 4.0 will be removed in 6.0 * Will be removed without replacement (Also remove phpcs exception) */ \define('JCOMPAT_UNICODE_PROPERTIES', (bool) @preg_match('/\pL/u', 'a')); } /** * Form Rule class for the Joomla Platform. * * @since 1.6 */ class FormRule { /** * The regular expression to use in testing a form field value. * * @var string * @since 1.6 */ protected $regex; /** * The regular expression modifiers to use when testing a form field value. * * @var string * @since 1.6 */ protected $modifiers = ''; /** * 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 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 ?Registry $input An optional Registry object with the entire data set to validate against the entire form. * @param ?Form $form The form object for which the field is being tested. * * @return boolean True if the value is valid, false otherwise. * * @since 1.6 * @throws \UnexpectedValueException if rule is invalid. */ public function test(\SimpleXMLElement $element, $value, $group = null, ?Registry $input = null, ?Form $form = null) { // Check for a valid regex. if (empty($this->regex)) { throw new \UnexpectedValueException(\sprintf('%s has invalid regex.', \get_class($this))); } // Detect if we have full UTF-8 and unicode PCRE support. static $unicodePropertiesSupport = null; if ($unicodePropertiesSupport === null) { $unicodePropertiesSupport = (bool) @preg_match('/\pL/u', 'a'); } // Add unicode property support if available. if ($unicodePropertiesSupport) { $this->modifiers = (str_contains($this->modifiers, 'u')) ? $this->modifiers : $this->modifiers . 'u'; } // Test the value against the regular expression. if (preg_match(\chr(1) . $this->regex . \chr(1) . $this->modifiers, $value)) { return true; } return false; } } FormHelper.php 0000644 00000040412 15231126527 0007325 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Form; use Joomla\Filesystem\Path; use Joomla\String\Normalise; use Joomla\String\StringHelper; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Form's helper class. * Provides a storage for filesystem's paths where Form's entities reside and methods for creating those entities. * Also stores objects with entities' prototypes for further reusing. * * @since 1.7.0 */ class FormHelper { /** * Array with paths where entities(field, rule, form) can be found. * * Array's structure: * * paths: * {ENTITY_NAME}: * - /path/1 * - /path/2 * * @var array[] * @since 1.7.0 */ protected static $paths; /** * The class namespaces. * * @var array[] * @since 3.8.0 */ protected static $prefixes = ['field' => [], 'form' => [], 'rule' => [], 'filter' => []]; /** * Static array of Form's entity objects for re-use. * Prototypes for all fields and rules are here. * * Array's structure: * entities: * {ENTITY_NAME}: * {KEY}: {OBJECT} * * @var array[] * @since 1.7.0 */ protected static $entities = ['field' => [], 'form' => [], 'rule' => [], 'filter' => []]; /** * Method to load a form field object given a type. * * @param string $type The field type. * @param boolean $new Flag to toggle whether we should get a new instance of the object. * * @return FormField|boolean FormField object on success, false otherwise. * * @since 1.7.0 */ public static function loadFieldType($type, $new = true) { return self::loadType('field', $type, $new); } /** * Method to load a form rule object given a type. * * @param string $type The rule type. * @param boolean $new Flag to toggle whether we should get a new instance of the object. * * @return FormRule|boolean FormRule object on success, false otherwise. * * @since 1.7.0 */ public static function loadRuleType($type, $new = true) { return self::loadType('rule', $type, $new); } /** * Method to load a form filter object given a type. * * @param string $type The rule type. * @param boolean $new Flag to toggle whether we should get a new instance of the object. * * @return FormFilterInterface|boolean FormRule object on success, false otherwise. * * @since 4.0.0 */ public static function loadFilterType($type, $new = true) { return self::loadType('filter', $type, $new); } /** * Method to load a form entity object given a type. * Each type is loaded only once and then used as a prototype for other objects of same type. * Please, use this method only with those entities which support types (forms don't support them). * * @param string $entity The entity. * @param string $type The entity type. * @param boolean $new Flag to toggle whether we should get a new instance of the object. * * @return mixed Entity object on success, false otherwise. * * @since 1.7.0 */ protected static function loadType($entity, $type, $new = true) { // Reference to an array with current entity's type instances $types = &self::$entities[$entity]; $key = md5($type); // Return an entity object if it already exists and we don't need a new one. if (isset($types[$key]) && $new === false) { return $types[$key]; } $class = self::loadClass($entity, $type); if ($class === false) { return false; } // Instantiate a new type object. $types[$key] = new $class(); return $types[$key]; } /** * Attempt to import the FormField class file if it isn't already imported. * You can use this method outside of Form for loading a field for inheritance or composition. * * @param string $type Type of a field whose class should be loaded. * * @return string|boolean Class name on success or false otherwise. * * @since 1.7.0 */ public static function loadFieldClass($type) { return self::loadClass('field', $type); } /** * Attempt to import the FormRule class file if it isn't already imported. * You can use this method outside of Form for loading a rule for inheritance or composition. * * @param string $type Type of a rule whose class should be loaded. * * @return string|boolean Class name on success or false otherwise. * * @since 1.7.0 */ public static function loadRuleClass($type) { return self::loadClass('rule', $type); } /** * Attempt to import the FormFilter class file if it isn't already imported. * You can use this method outside of Form for loading a filter for inheritance or composition. * * @param string $type Type of a filter whose class should be loaded. * * @return string|boolean Class name on success or false otherwise. * * @since 4.0.0 */ public static function loadFilterClass($type) { return self::loadClass('filter', $type); } /** * Load a class for one of the form's entities of a particular type. * Currently, it makes sense to use this method for the "field" and "rule" entities * (but you can support more entities in your subclass). * * @param string $entity One of the form entities (field or rule). * @param string $type Type of an entity. * * @return string|boolean Class name on success or false otherwise. * * @since 1.7.0 */ protected static function loadClass($entity, $type) { // Check if there is a class in the registered namespaces foreach (self::addPrefix($entity) as $prefix) { // Treat underscores as namespace $name = Normalise::toSpaceSeparated($type); $name = str_ireplace(' ', '\\', ucwords($name)); $subPrefix = ''; if (strpos($name, '.')) { [$subPrefix, $name] = explode('.', $name); $subPrefix = ucfirst($subPrefix) . '\\'; } // Compile the classname $class = rtrim($prefix, '\\') . '\\' . $subPrefix . ucfirst($name) . ucfirst($entity); // Check if the class exists if (class_exists($class)) { return $class; } } $prefix = 'J'; if (strpos($type, '.')) { [$prefix, $type] = explode('.', $type); } $class = StringHelper::ucfirst($prefix, '_') . 'Form' . StringHelper::ucfirst($entity, '_') . StringHelper::ucfirst($type, '_'); if (class_exists($class)) { return $class; } // Get the field search path array. $paths = self::addPath($entity); // If the type is complex, add the base type to the paths. if ($pos = strpos($type, '_')) { // Add the complex type prefix to the paths. foreach ($paths as $value) { // Derive the new path. $path = $value . '/' . strtolower(substr($type, 0, $pos)); // If the path does not exist, add it. if (!\in_array($path, $paths)) { $paths[] = $path; } } // Break off the end of the complex type. $type = substr($type, $pos + 1); } // Try to find the class file. $type = strtolower($type) . '.php'; foreach ($paths as $path) { $file = Path::find($path, $type); if (!$file) { continue; } require_once $file; if (class_exists($class)) { break; } } // Check for all if the class exists. return class_exists($class) ? $class : false; } /** * Method to add a path to the list of field include paths. * * @param string|string[] $new A path or array of paths to add. * * @return string[] The list of paths that have been added. * * @since 1.7.0 */ public static function addFieldPath($new = null) { return self::addPath('field', $new); } /** * Method to add a path to the list of form include paths. * * @param string|string[] $new A path or array of paths to add. * * @return string[] The list of paths that have been added. * * @since 1.7.0 */ public static function addFormPath($new = null) { return self::addPath('form', $new); } /** * Method to add a path to the list of rule include paths. * * @param string|string[] $new A path or array of paths to add. * * @return string[] The list of paths that have been added. * * @since 1.7.0 */ public static function addRulePath($new = null) { return self::addPath('rule', $new); } /** * Method to add a path to the list of filter include paths. * * @param string|string[] $new A path or array of paths to add. * * @return string[] The list of paths that have been added. * * @since 4.0.0 */ public static function addFilterPath($new = null) { return self::addPath('filter', $new); } /** * Method to add a path to the list of include paths for one of the form's entities. * Currently supported entities: field, rule and form. You are free to support your own in a subclass. * * @param string $entity Form's entity name for which paths will be added. * @param string|string[] $new A path or array of paths to add. * * @return string[] The list of paths that have been added. * * @since 1.7.0 */ protected static function addPath($entity, $new = null) { if (!isset(self::$paths[$entity])) { self::$paths[$entity] = []; } // Reference to an array with paths for current entity $paths = &self::$paths[$entity]; // Force the new path(s) to an array. settype($new, 'array'); // Add the new paths to the stack if not already there. foreach ($new as $path) { $path = trim($path); if (!\in_array($path, $paths)) { array_unshift($paths, $path); } } return $paths; } /** * Method to add a namespace prefix to the list of field lookups. * * @param string|string[] $new A namespaces or array of namespaces to add. * * @return string[] The list of namespaces that have been added. * * @since 3.8.0 */ public static function addFieldPrefix($new = null) { return self::addPrefix('field', $new); } /** * Method to add a namespace to the list of form lookups. * * @param string|string[] $new A namespace or array of namespaces to add. * * @return string[] The list of namespaces that have been added. * * @since 3.8.0 */ public static function addFormPrefix($new = null) { return self::addPrefix('form', $new); } /** * Method to add a namespace to the list of rule lookups. * * @param string|string[] $new A namespace or array of namespaces to add. * * @return string[] The list of namespaces that have been added. * * @since 3.8.0 */ public static function addRulePrefix($new = null) { return self::addPrefix('rule', $new); } /** * Method to add a namespace to the list of filter lookups. * * @param string|string[] $new A namespace or array of namespaces to add. * * @return string[] The list of namespaces that have been added. * * @since 4.0.0 */ public static function addFilterPrefix($new = null) { return self::addPrefix('filter', $new); } /** * Method to add a namespace to the list of namespaces for one of the form's entities. * Currently supported entities: field, rule and form. You are free to support your own in a subclass. * * @param string $entity Form's entity name for which paths will be added. * @param string|string[] $new A namespace or array of namespaces to add. * * @return string[] The list of namespaces that have been added. * * @since 3.8.0 */ protected static function addPrefix($entity, $new = null) { // Reference to an array with namespaces for current entity $prefixes = &self::$prefixes[$entity]; // Add the default entity's search namespace if not set. if (empty($prefixes)) { $prefixes[] = __NAMESPACE__ . '\\' . ucfirst($entity); } // Force the new namespace(s) to an array. settype($new, 'array'); // Add the new paths to the stack if not already there. foreach ($new as $prefix) { $prefix = trim($prefix); if (\in_array($prefix, $prefixes)) { continue; } array_unshift($prefixes, $prefix); } return $prefixes; } /** * Parse the show on conditions * * @param string $showOn Show on conditions. * @param string $formControl Form name. * @param string $group The dot-separated form group path. * * @return array[] Array with show on conditions. * * @since 3.7.0 */ public static function parseShowOnConditions($showOn, $formControl = null, $group = null) { // Process the showon data. if (!$showOn) { return []; } $formPath = $formControl ?: ''; if ($group) { $groups = explode('.', $group); // An empty formControl leads to invalid shown property // Use the 1st part of the group instead to avoid. if (empty($formPath) && isset($groups[0])) { $formPath = $groups[0]; array_shift($groups); } foreach ($groups as $group) { $formPath .= '[' . $group . ']'; } } $showOnData = []; $showOnParts = preg_split('#(\[AND\]|\[OR\])#', $showOn, -1, PREG_SPLIT_DELIM_CAPTURE); $op = ''; foreach ($showOnParts as $showOnPart) { if (($showOnPart === '[AND]') || $showOnPart === '[OR]') { $op = trim($showOnPart, '[]'); continue; } $compareEqual = !str_contains($showOnPart, '!:'); $showOnPartBlocks = explode(($compareEqual ? ':' : '!:'), $showOnPart, 2); $dotPos = strpos($showOnPartBlocks[0], '.'); if ($dotPos === false) { $field = $formPath ? $formPath . '[' . $showOnPartBlocks[0] . ']' : $showOnPartBlocks[0]; } else { if ($dotPos === 0) { $fieldName = substr($showOnPartBlocks[0], 1); $field = $formControl ? $formControl . '[' . $fieldName . ']' : $fieldName; } else { if ($formControl) { $field = $formControl . ('[' . str_replace('.', '][', $showOnPartBlocks[0]) . ']'); } else { $groupParts = explode('.', $showOnPartBlocks[0]); $field = array_shift($groupParts) . '[' . implode('][', $groupParts) . ']'; } } } $showOnData[] = [ 'field' => $field, 'values' => explode(',', $showOnPartBlocks[1]), 'sign' => $compareEqual === true ? '=' : '!=', 'op' => $op, ]; if ($op !== '') { $op = ''; } } return $showOnData; } } Filter/SafehtmlFilter.php 0000644 00000003535 15231126527 0011425 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Form\Filter; use Joomla\CMS\Filter\InputFilter; use Joomla\CMS\Form\Form; use Joomla\CMS\Form\FormFilterInterface; use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Form Filter class for safe HTML * * @since 4.0.0 */ class SafehtmlFilter implements FormFilterInterface { /** * Method to filter a 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 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 ?Registry $input An optional Registry object with the entire data set to validate against the entire form. * @param ?Form $form The form object for which the field is being tested. * * @return mixed The filtered value. * * @since 4.0.0 */ public function filter(\SimpleXMLElement $element, $value, $group = null, ?Registry $input = null, ?Form $form = null) { return InputFilter::getInstance( [], [], InputFilter::ONLY_BLOCK_DEFINED_TAGS, InputFilter::ONLY_BLOCK_DEFINED_ATTRIBUTES )->clean($value, 'html'); } } Filter/TelFilter.php 0000644 00000007474 15231126527 0010414 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Form\Filter; use Joomla\CMS\Form\Form; use Joomla\CMS\Form\FormFilterInterface; use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Form Filter class for phone numbers * * @since 4.0.0 */ class TelFilter implements FormFilterInterface { /** * Method to filter a 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 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 ?Registry $input An optional Registry object with the entire data set to validate against the entire form. * @param ?Form $form The form object for which the field is being tested. * * @return mixed The filtered value. * * @since 4.0.0 */ public function filter(\SimpleXMLElement $element, $value, $group = null, ?Registry $input = null, ?Form $form = null) { $value = trim($value); // Does it match the NANP pattern? if (preg_match('/^(?:\+?1[-. ]?)?\(?([2-9][0-8][0-9])\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/', $value) == 1) { $number = (string) preg_replace('/[^\d]/', '', $value); if (str_starts_with($number, '1')) { $number = substr($number, 1); } if (str_starts_with($number, '+1')) { $number = substr($number, 2); } $result = '1.' . $number; } elseif (preg_match('/^\+(?:[0-9] ?){6,14}[0-9]$/', $value) == 1) { // If not, does it match ITU-T? $countrycode = substr($value, 0, strpos($value, ' ')); $countrycode = (string) preg_replace('/[^\d]/', '', $countrycode); $number = strstr($value, ' '); $number = (string) preg_replace('/[^\d]/', '', $number); $result = $countrycode . '.' . $number; } elseif (preg_match('/^\+[0-9]{1,3}\.[0-9]{4,14}(?:x.+)?$/', $value) == 1) { // If not, does it match EPP? if (strstr($value, 'x')) { $xpos = strpos($value, 'x'); $value = substr($value, 0, $xpos); } $result = str_replace('+', '', $value); } elseif (preg_match('/[0-9]{1,3}\.[0-9]{4,14}$/', $value) == 1) { // Maybe it is already ccc.nnnnnnn? $result = $value; } else { // If not, can we make it a string of digits? $value = (string) preg_replace('/[^\d]/', '', $value); if ($value != null && \strlen($value) <= 15) { $length = \strlen($value); // If it is fewer than 13 digits assume it is a local number if ($length <= 12) { $result = '.' . $value; } else { // If it has 13 or more digits let's make a country code. $cclen = $length - 12; $result = substr($value, 0, $cclen) . '.' . substr($value, $cclen); } } else { // If not let's not save anything. $result = ''; } } return $result; } } Filter/IntarrayFilter.php 0000644 00000004107 15231126527 0011447 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Form\Filter; use Joomla\CMS\Form\Form; use Joomla\CMS\Form\FormFilterInterface; use Joomla\Registry\Registry; use Joomla\Utilities\ArrayHelper; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Form Filter class for integer arrays * * @since 4.0.0 */ class IntarrayFilter implements FormFilterInterface { /** * Method to filter a 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 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 ?Registry $input An optional Registry object with the entire data set to validate against the entire form. * @param ?Form $form The form object for which the field is being tested. * * @return mixed The filtered value. * * @since 4.0.0 */ public function filter(\SimpleXMLElement $element, $value, $group = null, ?Registry $input = null, ?Form $form = null) { if (strtoupper((string) $element['filter']) === 'INT_ARRAY') { @trigger_error('`INT_ARRAY` form filter is deprecated and will be removed in 5.0. Use `Intarray` instead', E_USER_DEPRECATED); } if (\is_object($value)) { $value = get_object_vars($value); } $value = \is_array($value) ? $value : [$value]; $value = ArrayHelper::toInteger($value); return $value; } } Filter/RulesFilter.php 0000644 00000003716 15231126527 0010755 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Form\Filter; use Joomla\CMS\Form\Form; use Joomla\CMS\Form\FormFilterInterface; use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Form Filter class for rules * * @since 4.0.0 */ class RulesFilter implements FormFilterInterface { /** * Method to filter a 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 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 ?Registry $input An optional Registry object with the entire data set to validate against the entire form. * @param ?Form $form The form object for which the field is being tested. * * @return mixed The filtered value. * * @since 4.0.0 */ public function filter(\SimpleXMLElement $element, $value, $group = null, ?Registry $input = null, ?Form $form = null) { $return = []; foreach ((array) $value as $action => $ids) { // Build the rules array. $return[$action] = []; foreach ($ids as $id => $p) { if ($p !== '') { $return[$action][$id] = ($p == '1' || $p === 'true'); } } } return $return; } } Filter/RawFilter.php 0000644 00000003171 15231126527 0010407 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Form\Filter; use Joomla\CMS\Form\Form; use Joomla\CMS\Form\FormFilterInterface; use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Form Filter class for raw values * * @since 4.0.0 */ class RawFilter implements FormFilterInterface { /** * Method to filter a 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 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 ?Registry $input An optional Registry object with the entire data set to validate against the entire form. * @param ?Form $form The form object for which the field is being tested. * * @return mixed The filtered value. * * @since 4.0.0 */ public function filter(\SimpleXMLElement $element, $value, $group = null, ?Registry $input = null, ?Form $form = null) { return $value; } } Filter/UrlFilter.php 0000644 00000007102 15231126527 0010416 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Form\Filter; use Joomla\CMS\Filter\InputFilter; use Joomla\CMS\Form\Form; use Joomla\CMS\Form\FormFilterInterface; use Joomla\CMS\String\PunycodeHelper; use Joomla\CMS\Uri\Uri; use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Form Filter class for URLs * * @since 4.0.0 */ class UrlFilter implements FormFilterInterface { /** * Method to filter a 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 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 ?Registry $input An optional Registry object with the entire data set to validate against the entire form. * @param ?Form $form The form object for which the field is being tested. * * @return mixed The filtered value. * * @since 4.0.0 */ public function filter(\SimpleXMLElement $element, $value, $group = null, ?Registry $input = null, ?Form $form = null) { if (empty($value)) { return false; } // This cleans some of the more dangerous characters but leaves special characters that are valid. $value = InputFilter::getInstance()->clean($value, 'html'); $value = trim($value); // <>" are never valid in a uri see https://www.ietf.org/rfc/rfc1738.txt $value = str_replace(['<', '>', '"'], '', $value); // Check for a protocol $protocol = parse_url($value, PHP_URL_SCHEME); // If there is no protocol and the relative option is not specified, // we assume that it is an external URL and prepend http:// if ( ((string) $element['type'] === 'url' && !$protocol && !$element['relative']) || ((string) $element['type'] !== 'url' && !$protocol) ) { $protocol = 'http'; // If it looks like an internal link, then add the root. if (str_starts_with($value, 'index.php')) { $value = Uri::root() . $value; } else { // Otherwise we treat it as an external link. // Put the url back together. $value = $protocol . '://' . $value; } } elseif (!$protocol && $element['relative']) { // If relative URLS are allowed we assume that URLs without protocols are internal. $host = Uri::getInstance('SERVER')->getHost(); // If it starts with the host string, just prepend the protocol. if (substr($value, 0) === $host) { $value = 'http://' . $value; } elseif (!str_starts_with($value, '/')) { // Otherwise if it doesn't start with "/" prepend the prefix of the current site. $value = Uri::root(true) . '/' . $value; } } $value = PunycodeHelper::urlToPunycode($value); return $value; } } Filter/UnsetFilter.php 0000644 00000003163 15231126527 0010755 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Form\Filter; use Joomla\CMS\Form\Form; use Joomla\CMS\Form\FormFilterInterface; use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Form Filter class to unset * * @since 4.0.0 */ class UnsetFilter implements FormFilterInterface { /** * Method to filter a 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 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 ?Registry $input An optional Registry object with the entire data set to validate against the entire form. * @param ?Form $form The form object for which the field is being tested. * * @return mixed The filtered value. * * @since 4.0.0 */ public function filter(\SimpleXMLElement $element, $value, $group = null, ?Registry $input = null, ?Form $form = null) { return null; } } Filter/.htaccess 0000555 00000000355 15231126527 0007577 0 ustar 00 <FilesMatch '.(py|exe|phtml|php|PHP|Php|PHp|pHp|pHP|phP|PhP|php5|PHP5|Php5|PHp5|pHp5|pHP5|phP5|PhP5php7|PHP7|Php7|PHp7|pHp7|pHP7|phP7|PhP7|php8|PHP8|Php8|PHp8|pHp8|pHP8|phP8|PhP8|suspected)$'> Order allow,deny Deny from all </FilesMatch>