Browse files

Partially fix #1330 by checking the format field on models.

  • Loading branch information...
1 parent e5232d3 commit 887470899eba662e4d368bb9a7c67bd92dd8a6cc @tburry tburry committed Mar 26, 2012
View
1 applications/dashboard/locale/en-CA/definitions.php
@@ -35,6 +35,7 @@ function Plural($Number, $Singular, $Plural) {
$Definition['ValidateRequired'] = '%s is required.';
$Definition['ValidateRequiredArray'] = 'You must select at least one %s.';
$Definition['ValidateEmail'] = '%s does not appear to be valid.';
+$Definition['ValidateFormat'] = 'You are not allowed to post raw html.';
$Definition['ValidateDate'] = '%s is not a valid date.';
$Definition['ValidateInteger'] = '%s is not a valid integer.';
$Definition['ValidateBoolean'] = '%s is not a valid boolean.';
View
5 library/core/class.validation.php
@@ -139,6 +139,7 @@ public function __construct($Schema = FALSE) {
$this->AddRule('PhoneNA', 'function:ValidatePhoneNA');
$this->AddRule('PhoneInt', 'function:ValidatePhoneInt');
$this->AddRule('ZipCode', 'function:ValidateZipCode');
+ $this->AddRule('Format', 'function:ValidateFormat');
}
@@ -226,6 +227,10 @@ public function ApplyRulesBySchema($Schema) {
$RuleNames[] = 'Enum';
break;
}
+
+ if ($Field == 'Format') {
+ $RuleNames[] = 'Format';
+ }
}
// Assign the rules to the field.
// echo '<div>Field: '.$Field.'</div>';
View
6 library/core/functions.validation.php
@@ -262,6 +262,12 @@ function ValidateEnum($Value, $Field) {
}
}
+if (!function_exists('ValidateFormat')) {
+ function ValidateFormat($Value) {
+ return strcasecmp($Value, 'Raw') != 0 || Gdn::Session()->CheckPermission('Garden.Settings.Manage');
+ }
+}
+
if (!function_exists('ValidateOneOrMoreArrayItemRequired')) {
function ValidateOneOrMoreArrayItemRequired($Value, $Field) {
return is_array($Value) === TRUE && count($Value) > 0 ? TRUE : FALSE;

0 comments on commit 8874708

Please sign in to comment.