77use SilverStripe \Core \Config \Configurable ;
88use SilverStripe \Core \Injector \Injectable ;
99use SilverStripe \Core \XssSanitiser ;
10+ use SilverStripe \Dev \Deprecation ;
1011use SilverStripe \View \Parsers \HTMLValue ;
1112use stdClass ;
1213
@@ -34,12 +35,22 @@ class HTMLEditorSanitiser
3435 */
3536 private static $ link_rel_value = 'noopener noreferrer ' ;
3637
37- /** @var stdClass - $element => $rule hash for whitelist element rules where the element name isn't a pattern */
38+ /**
39+ * @var stdClass - $element => $rule hash for whitelist element rules where the element name isn't a pattern
40+ * @deprecated 5.4.0 Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet
41+ */
3842 protected $ elements = [];
39- /** @var stdClass - Sequential list of whitelist element rules where the element name is a pattern */
43+
44+ /**
45+ * @var stdClass - Sequential list of whitelist element rules where the element name is a pattern
46+ * @deprecated 5.4.0 Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet
47+ */
4048 protected $ elementPatterns = [];
4149
42- /** @var stdClass - The list of attributes that apply to all further whitelisted elements added */
50+ /**
51+ * @var stdClass - The list of attributes that apply to all further whitelisted elements added
52+ * @deprecated 5.4.0 Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet
53+ */
4354 protected $ globalAttributes = [];
4455
4556 /**
@@ -68,9 +79,14 @@ public function __construct(HTMLEditorConfig $config)
6879 *
6980 * @param $str - The TinyMCE pattern
7081 * @return string - The equivalent regex
82+ * @deprecated 5.4.0 Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet::patternToRegex()
7183 */
7284 protected function patternToRegex ($ str )
7385 {
86+ Deprecation::noticeWithNoReplacment (
87+ '5.4.0 ' ,
88+ 'Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet::patternToRegex() '
89+ );
7490 return '/^ ' . preg_replace ('/([?+*])/ ' , '.$1 ' , $ str ?? '' ) . '$/ ' ;
7591 }
7692
@@ -81,9 +97,14 @@ protected function patternToRegex($str)
8197 * Logic based heavily on javascript version from tiny_mce_src.js
8298 *
8399 * @param string $validElements - The valid_elements or extended_valid_elements string to add to the whitelist
100+ * @deprecated 5.4.0 Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet
84101 */
85102 protected function addValidElements ($ validElements )
86103 {
104+ Deprecation::noticeWithNoReplacment (
105+ '5.4.0 ' ,
106+ 'Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet '
107+ );
87108 $ elementRuleRegExp = '/^([#+\-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/ ' ;
88109 $ attrRuleRegExp = '/^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/ ' ;
89110 $ hasPatternsRegExp = '/[*?+]/ ' ;
@@ -186,9 +207,14 @@ protected function addValidElements($validElements)
186207 * Given an element tag, return the rule structure for that element
187208 * @param string $tag The element tag
188209 * @return stdClass The element rule
210+ * @deprecated 5.4.0 Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet::getRuleForElement()
189211 */
190212 protected function getRuleForElement ($ tag )
191213 {
214+ Deprecation::noticeWithNoReplacment (
215+ '5.4.0 ' ,
216+ 'Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet::getRuleForElement() '
217+ );
192218 if (isset ($ this ->elements [$ tag ])) {
193219 return $ this ->elements [$ tag ];
194220 }
@@ -206,9 +232,14 @@ protected function getRuleForElement($tag)
206232 * @param object $elementRule
207233 * @param string $name The attribute name
208234 * @return stdClass The attribute rule
235+ * @deprecated 5.4.0 Will be replaced with logic in SilverStripe\Forms\HTMLEditor\HTMLEditorElementRule
209236 */
210237 protected function getRuleForAttribute ($ elementRule , $ name )
211238 {
239+ Deprecation::noticeWithNoReplacment (
240+ '5.4.0 ' ,
241+ 'Will be replaced with logic in SilverStripe\Forms\HTMLEditor\HTMLEditorElementRule '
242+ );
212243 if (isset ($ elementRule ->attributes [$ name ])) {
213244 return $ elementRule ->attributes [$ name ];
214245 }
@@ -225,9 +256,14 @@ protected function getRuleForAttribute($elementRule, $name)
225256 * @param DOMElement $element The element to check
226257 * @param stdClass $rule The rule to check against
227258 * @return bool True if the element passes (and so can be kept), false if it fails (and so needs stripping)
259+ * @deprecated 5.4.0 Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet::isElementAllowed()
228260 */
229261 protected function elementMatchesRule ($ element , $ rule = null )
230262 {
263+ Deprecation::noticeWithNoReplacment (
264+ '5.4.0 ' ,
265+ 'Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet::isElementAllowed() '
266+ );
231267 // If the rule doesn't exist at all, the element isn't allowed
232268 if (!$ rule ) {
233269 return false ;
@@ -263,9 +299,14 @@ protected function elementMatchesRule($element, $rule = null)
263299 * @param DOMAttr $attr - the attribute to check
264300 * @param stdClass $rule - the rule to check against
265301 * @return bool - true if the attribute passes (and so can be kept), false if it fails (and so needs stripping)
302+ * @deprecated 5.4.0 Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorElementRule::isAttributeAllowed()
266303 */
267304 protected function attributeMatchesRule ($ attr , $ rule = null )
268305 {
306+ Deprecation::noticeWithNoReplacment (
307+ '5.4.0 ' ,
308+ 'Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorElementRule::isAttributeAllowed() '
309+ );
269310 // If the rule doesn't exist at all, the attribute isn't allowed
270311 if (!$ rule ) {
271312 return false ;
0 commit comments