diff --git a/administrator/components/com_banners/models/forms/banner.xml b/administrator/components/com_banners/models/forms/banner.xml index 4734a899b3d8c..f24d7fcda9691 100644 --- a/administrator/components/com_banners/models/forms/banner.xml +++ b/administrator/components/com_banners/models/forms/banner.xml @@ -339,6 +339,7 @@ directory="banners" hide_none="1" size="40" + validate="filePath" /> diff --git a/administrator/components/com_contact/models/forms/contact.xml b/administrator/components/com_contact/models/forms/contact.xml index 2040978d1dc89..cf304d9a2fa82 100644 --- a/administrator/components/com_contact/models/forms/contact.xml +++ b/administrator/components/com_contact/models/forms/contact.xml @@ -253,6 +253,7 @@ label="COM_CONTACT_FIELD_ICONS_ADDRESS_LABEL" description="COM_CONTACT_FIELD_ICONS_ADDRESS_DESC" hide_none="1" + validate="filepath" /> @@ -311,6 +317,7 @@ label="COM_CONTACT_FIELD_PARAMS_IMAGE_LABEL" description="COM_CONTACT_FIELD_PARAMS_IMAGE_DESC" hide_none="1" + validate="filepath" /> - + diff --git a/libraries/src/Form/Rule/FilePathRule.php b/libraries/src/Form/Rule/FilePathRule.php new file mode 100644 index 0000000000000..1d9a9d76fd437 --- /dev/null +++ b/libraries/src/Form/Rule/FilePathRule.php @@ -0,0 +1,73 @@ +` 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 __DEPLOY_VERSION__ + */ + public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null) + { + $value = trim($value); + + // 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; + } + + // Append the root path + $value = JPATH_ROOT . '/' . $value; + + try + { + $path = Path::check($value); + } + catch (\Exception $e) + { + // When there is an exception in the check method this is not valid + return false; + } + + // Check whether this is a valid file + if (is_file($path)) + { + return true; + } + + return false; + } +} diff --git a/modules/mod_custom/mod_custom.xml b/modules/mod_custom/mod_custom.xml index f766c29ffb9e9..f241495300cad 100644 --- a/modules/mod_custom/mod_custom.xml +++ b/modules/mod_custom/mod_custom.xml @@ -43,6 +43,7 @@ type="media" label="MOD_CUSTOM_FIELD_BACKGROUNDIMAGE_LABEL" description="MOD_BACKGROUNDIMAGE_FIELD_LOGO_DESC" + validate="filePath" />
diff --git a/templates/beez3/templateDetails.xml b/templates/beez3/templateDetails.xml index c15c405ea8ff2..47a374b2f7577 100644 --- a/templates/beez3/templateDetails.xml +++ b/templates/beez3/templateDetails.xml @@ -81,6 +81,7 @@ type="media" label="TPL_BEEZ3_FIELD_LOGO_LABEL" description="TPL_BEEZ3_FIELD_LOGO_DESC" + validate="filePath" />