diff --git a/src/Html/HtmlBuilder.php b/src/Html/HtmlBuilder.php index 5b7770cb3..86a4b1752 100644 --- a/src/Html/HtmlBuilder.php +++ b/src/Html/HtmlBuilder.php @@ -404,7 +404,7 @@ public function obfuscate($value) */ public static function strip($string, $allow = '') { - return htmlspecialchars_decode(strip_tags($string, $allow)); + return strip_tags(htmlspecialchars_decode($string), $allow); } /** diff --git a/src/Validation/ValidationServiceProvider.php b/src/Validation/ValidationServiceProvider.php index c100377ec..ee5be1c70 100644 --- a/src/Validation/ValidationServiceProvider.php +++ b/src/Validation/ValidationServiceProvider.php @@ -20,6 +20,11 @@ protected function registerValidationFactory() $validator->setPresenceVerifier($app['validation.presence']); } + // Replacers for custom rules in Validator class + $validator->replacer('unique_site', function ($message, $attribute, $rule, $parameters) { + return __('validation.unique', ['attribute' => $attribute]); + }); + return $validator; }); } diff --git a/src/Validation/Validator.php b/src/Validation/Validator.php index 5bba58180..27171f0f4 100644 --- a/src/Validation/Validator.php +++ b/src/Validation/Validator.php @@ -1,5 +1,7 @@ requireParameterCount(1, $parameters, 'unique_site'); + + [$connection, $table, $idColumn] = $this->parseTable($parameters[0]); + + // The second parameter position holds the name of the column that needs to + // be verified as unique. If this parameter isn't specified we will just + // assume that this column to be verified shares the attribute's name. + $column = $this->getQueryColumn($parameters, $attribute); + + $id = null; + + if (isset($parameters[2])) { + [$idColumn, $id] = $this->getUniqueIds($idColumn, $parameters); + + if (!is_null($id)) { + $id = stripslashes($id); + } + } + + // The presence verifier is responsible for counting rows within this store + // mechanism which might be a relational database or any other permanent + // data store like Redis, etc. We will use it to determine uniqueness. + $verifier = $this->getPresenceVerifier($connection); + + $extra = $this->getUniqueExtra($parameters); + + if ($this->currentRule instanceof Unique) { + $extra = array_merge($extra, $this->currentRule->queryCallbacks()); + } + + // Add the site extra + $extra['site_id'] = Site::getSiteIdFromContext(); + + return $verifier->getCount( + $table, $column, $value, $id, $idColumn, $extra + ) == 0; + } }