Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sanitizer.php
1<?php
9
11use Bitrix\Fileman;
12
18{
27 public static function sanitizeHtml($html, $previousHtml = '', User $user = null)
28 {
29 $html = self::cleanHtml($html);
30 return self::removePhp($html, $previousHtml, $user);
31 }
32
39 public static function cleanHtml($html)
40 {
41 if (!$html || !is_string($html))
42 {
43 return null;
44 }
45
46 $html = preg_replace('/<(script|iframe)(.*?)>(.*?)(<\\/\\1.*?>)/is', '', $html);
47 if (Loader::includeModule('fileman'))
48 {
49 $html = Fileman\Block\Content\SliceConverter::sanitize($html);
50 }
51
52 return $html;
53 }
54
61 public static function fixReplacedStyles($html)
62 {
63 return str_replace(
64 [
65 '<st yle ', '<st yle ',
66 ' st yle="',' st yle="',
67 ' st yle=\'',' st yle=\'',
68 ],
69 [
70 '<style ', '<style ',
71 ' style="',' style="',
72 ' style=\'',' style=\'',
73 ],
74 $html
75 );
76 }
77
84 public static function fixTemplateStyles($html)
85 {
86 $html = str_replace('<body class="">{}', '<body class="">', $html);
87 $html = str_replace('</style>{}', '</style>', $html);
88
89 if (!$html)
90 {
91 return $html;
92 }
93
94 $html = preg_replace('/<st yle.*?>(.*?)<\/style>/is', '</style>', $html);
95 $html = preg_replace('/<\/style>([\s]*?)<\/style>/is', '</style>', $html);
96
97 return $html;
98 }
99
107 public static function removePhp($string = '', $previousString, User $user = null)
108 {
109 $user = $user ?: User::current();
110 Loader::includeModule('fileman');
111 return Fileman\Block\EditorMail::removePhpFromHtml(
112 $string,
113 $previousString,
114 $user->canEditPhp(),
115 $user->canUseLpa()
116 );
117 }
118}
static removePhp($string='', $previousString, User $user=null)
static sanitizeHtml($html, $previousHtml='', User $user=null)
Definition sanitizer.php:27