Файл: DESURE-dcms-f12de01ac63e/sys/plugins/classes/is_valid.class.php
Строк: 209
<?php
/**
* Проверка валидности различных данных
*/
abstract class is_valid {
/**
* Проверка на соответствие WMID
* @param string $wmid
* @return boolean
*/
static function wmid($wmid) {
if (preg_match("#^[0-9]{12}$#", $wmid))
return true;
}
/**
* Проверка на соответствие логину skype
* @param string $skype
* @return boolean
*/
static function skype($skype) {
if (preg_match("#^[a-z][a-z0-9_-.]{5,31}$#ui", $skype))
return true;
}
static function telnumber($login) {
if (preg_match('#^+?([0-9]+)$#', $login, $m)) {
return '+' . $m[1];
}
return $login;
}
/**
* Проверяет на возможность использования строки в качестве ника
* @param string $nick
* @return boolean
*/
static function nick($nick) {
// проверка на длину логина и возможные символы
if (!preg_match("#^[a-zа-яё][a-zа-яё0-9-_ ]{2,31}$#ui", $nick)) {
return false;
}
// запрещаем использовать ряд логинов (которые могут ввести в оману новичков)
if (preg_match("#(bot|DCMS|deleted|moder|system|бот|модер|систем)#ui", $nick)) {
return false;
}
// запрещаем одновременное использование кирилицы и латинского алфавита
if (preg_match("#[a-z]+#ui", $nick) && preg_match("#[а-яё]+#ui", $nick)) {
return false;
}
// пробелы вначале или конце ника недопустимы
if (preg_match("#(^ )|( $)#ui", $nick)) {
return false;
}
return true;
}
/**
* Проверка на соответствие email
* @param string $mail
* @return boolean
*/
static function mail($mail) {
if (preg_match('#^[a-z0-9-._]+@([a-z0-9-_]+.)+([a-z0-9]{2,4}).?$#ui', $mail))
return true;
}
/**
* Проверяет на соответствие паролю
* @param string $pass
* @return boolean
*/
static function password($pass) {
if (preg_match("#^[a-zа-яё0-9-_ ]{6,32}$#ui", $pass)) {
return true;
}
}
/**
* Проверка ника на подозрительность
* @param string $str
* @return boolean
*/
static function suspicion($str) {
// три и более согласных подряд
if (preg_match('#[БВГДЖЗКЛМНПРСТФХЦЧШЩBCDFGHJKLMNPQRSTVXZ]{4,}#ui', $str, $m)) {
return $m[0];
}
// повторение одного символа или выражения более 3-х раз подряд
if (preg_match('#([[:alpha:]]+)1{2,}#ui', $str)) {
return $m[0];
}
return false;
}
/**
* Проверка на мат
* @staticvar array $pretext
* @staticvar array $badwords
* @staticvar array $re_trans
* @staticvar array $trans
* @param string $s
* @param int $delta
* @param string $continue
* @return string|boolean
*/
static function mat($s, $delta = 3, $continue = "xe2x80xa6") {
static $pretext = array(
'[уyоo]_? (?=[еёeхx])',
'[вvbсc]_? (?=[хпбмгжxpmgj])',
'[вvbсc]_?[ъь]_? (?=[еёe])',
'ё_? (?=[бb])',
'[вvb]_?[ыi]_?',
'[зz3]_?[аa]_?',
'[нnh]_?[аaеeиi]_?',
'[вvb]_?[сc]_? (?=[хпбмгжxpmgj])',
'[оo]_?[тtбb]_? (?=[хпбмгжxpmgj])',
'[оo]_?[тtбb]_?[ъь]_? (?=[еёe])',
'[иiвvb]_?[зz3]_? (?=[хпбмгжxpmgj])',
'[иiвvb]_?[зz3]_?[ъь]_? (?=[еёe])',
'[иi]_?[сc]_? (?=[хпбмгжxpmgj])',
'[пpдdg]_?[оo]_? (?> [бb]_? (?=[хпбмгжxpmgj])
| [бb]_? [ъь]_? (?=[еёe])
| [зz3]_? [аa] _?
)?',
'[пp]_?[рr]_?[оoиi]_?',
'[зz3]_?[лl]_?[оo]_?',
'[нnh]_?[аa]_?[дdg]_? (?=[хпбмгжxpmgj])',
'[нnh]_?[аa]_?[дdg]_?[ъь]_? (?=[еёe])',
'[пp]_?[оo]_?[дdg]_? (?=[хпбмгжxpmgj])',
'[пp]_?[оo]_?[дdg]_?[ъь]_? (?=[еёe])',
'[рr]_?[аa]_?[зz3сc]_? (?=[хпбмгжxpmgj])',
'[рr]_?[аa]_?[зz3сc]_?[ъь]_? (?=[еёe])',
'[вvb]_?[оo]_?[зz3сc]_? (?=[хпбмгжxpmgj])',
'[вvb]_?[оo]_?[зz3сc]_?[ъь]_? (?=[еёe])',
'[нnh]_?[еe]_?[дdg]_?[оo]_?',
'[пp]_?[еe]_?[рr]_?[еe]_?',
'[oо]_?[дdg]_?[нnh]_?[оo]_?',
'[кk]_?[oо]_?[нnh]_?[оo]_?',
'[мm]_?[уy]_?[дdg]_?[оoаa]_?',
'[oо]_?[сc]_?[тt]_?[оo]_?',
'[дdg]_?[уy]_?[рpr]_?[оoаa]_?',
'[хx]_?[уy]_?[дdg]_?[оoаa]_?',
'[мm]_?[нnh]_?[оo]_?[гg]_?[оo]_?',
'[мm]_?[оo]_?[рpr]_?[дdg]_?[оoаa]_?',
'[мm]_?[оo]_?[зz3]_?[гg]_?[оoаa]_?',
'[дdg]_?[оo]_?[лl]_?[бb6]_?[оoаa]_?',
);
static $badwords = array(
'(?<=[_d]) {RE_PRETEXT}?
[hхx]_?[уyu]_?[йiеeёяюju] #хуй, хуя, хую, хуем, хуёвый
#исключения:
(?<! _hue(?=_) #HUE -- цветовая палитра
| _hue(?=so_) #hueso -- испанское слово
| _хуе(?=дин) #Хуедин -- город в Румынии
)',
'(?<=[_d]) {RE_PRETEXT}?
[пp]_?[иi]_?[зz3]_?[дd]_?[:vowel:]',
'(?<=[_d]) {RE_PRETEXT}?
[eеё]_? (?<!не[её]_) [бb6]_?(?: [уyиi]_ #ебу, еби
| [ыиiоoaаеeёуy]_?[:consonant:] #ебут, ебать, ебись, ебёт, поеботина, выебываться, ёбарь
| [лl][оoаaыиi] #ебло, ебла, ебливая, еблись, еблысь
| [нn]_?[уy] #ёбнул, ёбнутый
| [кk]_?[аa] #взъёбка
)',
'(?<=[_d]) {RE_PRETEXT}
(?<=[^_d][^_d]|[^_d]_[^_d]_) [eеё]_?[бb6] (?:_|_?[аa]_?[^_d])',
'(?<=[_d]) {RE_PRETEXT}?
[бb6]_?[лl]_?(?:я|ya)(?: _ #бля
| _?[тд] #блять, бляди
)',
'(?<=[_d]) [пp]_?[иieе]_?[дdg]_?[eеaаoо]_?[rpр]',
'(?<=[_d]) [мm]_?[уy]_?[дdg]_?[аa]',
'(?<=[_d]) [zж]_?h?_?[оo]_?[pп]_?[aаyуыiеeoо]',
'(?<=[_d]) [мm]_?[аa]_?[нnh]_?[дdg]_?[aаyуыiеeoо](?<! манда(?=[лн])|манде(?=ль ))',
'(?<=[_d]) [гg]_?[оo]_?[вvb]_?[нnh]_?[оoаaяеeyу]',
'(?<=[_d]) f_?u_?[cс]_?k',
);
static $re_trans = array(
'_' => 'x20',
'[:vowel:]' => '[аеиоуыэюяёaeioyu]',
'[:consonant:]' => '[^аеиоуыэюяёaeioyux20d]',
);
$re_badwords = str_replace('{RE_PRETEXT}', '(?>' . implode('|', $pretext) . ')', '~' . implode('|', $badwords) . '~sxu');
$re_badwords = strtr($re_badwords, $re_trans);
$s = self::strip_tags_smart($s, null, true, array('comment', 'style', 'map', 'frameset', 'object', 'applet'));
$s = self::utf8_html_entity_decode($s, $is_htmlspecialchars = true);
$s = self::utf8_convert_case($s, CASE_LOWER);
static $trans = array(
"xc2xad" => '',
"xccx81" => '',
'/\' => 'л',
'/|' => 'л',
"xd0xb5xd0xb5" => "xd0xb5xd1x91",
);
$s = strtr($s, $trans);
preg_match_all('/(?> xd0[xb0-xbf]|xd1[x80-x8fx91] #[а-я]
| [a-zd]+
)+
/sx', $s, $m);
$s = ' ' . implode(' ', $m[0]) . ' ';
$s = preg_replace('/( [xd0xd1][x80-xbf] #оптимизированное [а-я]
| [a-zd]
) \1+
/sx', '$1', $s);
if (preg_match($re_badwords, $s, $m, PREG_OFFSET_CAPTURE)) {
list($word, $offset) = $m[0];
$s1 = substr($s, 0, $offset);
$s2 = substr($s, $offset + strlen($word));
$delta = intval($delta);
if ($delta < 1 || $delta > 10)
$delta = 3;
preg_match('/ (?> x20 (?>[xd0xd1][x80-xbf]|[a-zd]+)+ ){1,' . $delta . '}
x20?
$/sx', $s1, $m1);
preg_match('/^ (?>[xd0xd1][x80-xbf]|[a-zd]+)* #окончание
x20?
(?> (?>[xd0xd1][x80-xbf]|[a-zd]+)+ x20 ){1,' . $delta . '}
/sx', $s2, $m2);
$fragment = (ltrim(@$m1[0]) !== ltrim($s1) ? $continue : '') .
trim(@$m1[0] . '[' . trim($word) . ']' . @$m2[0]) .
(rtrim(@$m2[0]) !== rtrim($s2) ? $continue : '');
return $fragment;
}
return false;
}
static function utf8_html_entity_decode($s, $is_htmlspecialchars = false) {
if (strlen($s) < 4 || ($pos = strpos($s, '&') === false) || strpos($s, ';', $pos) === false)
return $s;
$table = array(
' ' => "xc2xa0",
'¡' => "xc2xa1",
'¢' => "xc2xa2",
'£' => "xc2xa3",
'¤' => "xc2xa4",
'¥' => "xc2xa5",
'¦' => "xc2xa6",
'§' => "xc2xa7",
'¨' => "xc2xa8",
'©' => "xc2xa9",
'ª' => "xc2xaa",
'«' => "xc2xab",
'¬' => "xc2xac",
'­' => "xc2xad",
'®' => "xc2xae",
'¯' => "xc2xaf",
'°' => "xc2xb0",
'±' => "xc2xb1",
'²' => "xc2xb2",
'³' => "xc2xb3",
'´' => "xc2xb4",
'µ' => "xc2xb5",
'¶' => "xc2xb6",
'·' => "xc2xb7",
'¸' => "xc2xb8",
'¹' => "xc2xb9",
'º' => "xc2xba",
'»' => "xc2xbb",
'¼' => "xc2xbc",
'½' => "xc2xbd",
'¾' => "xc2xbe",
'¿' => "xc2xbf",
'À' => "xc3x80",
'Á' => "xc3x81",
'Â' => "xc3x82",
'Ã' => "xc3x83",
'Ä' => "xc3x84",
'Å' => "xc3x85",
'Æ' => "xc3x86",
'Ç' => "xc3x87",
'È' => "xc3x88",
'É' => "xc3x89",
'Ê' => "xc3x8a",
'Ë' => "xc3x8b",
'Ì' => "xc3x8c",
'Í' => "xc3x8d",
'Î' => "xc3x8e",
'Ï' => "xc3x8f",
'Ð' => "xc3x90",
'Ñ' => "xc3x91",
'Ò' => "xc3x92",
'Ó' => "xc3x93",
'Ô' => "xc3x94",
'Õ' => "xc3x95",
'Ö' => "xc3x96",
'×' => "xc3x97",
'Ø' => "xc3x98",
'Ù' => "xc3x99",
'Ú' => "xc3x9a",
'Û' => "xc3x9b",
'Ü' => "xc3x9c",
'Ý' => "xc3x9d",
'Þ' => "xc3x9e",
'ß' => "xc3x9f",
'à' => "xc3xa0",
'á' => "xc3xa1",
'â' => "xc3xa2",
'ã' => "xc3xa3",
'ä' => "xc3xa4",
'å' => "xc3xa5",
'æ' => "xc3xa6",
'ç' => "xc3xa7",
'è' => "xc3xa8",
'é' => "xc3xa9",
'ê' => "xc3xaa",
'ë' => "xc3xab",
'ì' => "xc3xac",
'í' => "xc3xad",
'î' => "xc3xae",
'ï' => "xc3xaf",
'ð' => "xc3xb0",
'ñ' => "xc3xb1",
'ò' => "xc3xb2",
'ó' => "xc3xb3",
'ô' => "xc3xb4",
'õ' => "xc3xb5",
'ö' => "xc3xb6",
'÷' => "xc3xb7",
'ø' => "xc3xb8",
'ù' => "xc3xb9",
'ú' => "xc3xba",
'û' => "xc3xbb",
'ü' => "xc3xbc",
'ý' => "xc3xbd",
'þ' => "xc3xbe",
'ÿ' => "xc3xbf",
'ƒ' => "xc6x92",
'Α' => "xcex91",
'Β' => "xcex92",
'Γ' => "xcex93",
'Δ' => "xcex94",
'Ε' => "xcex95",
'Ζ' => "xcex96",
'Η' => "xcex97",
'Θ' => "xcex98",
'Ι' => "xcex99",
'Κ' => "xcex9a",
'Λ' => "xcex9b",
'Μ' => "xcex9c",
'Ν' => "xcex9d",
'Ξ' => "xcex9e",
'Ο' => "xcex9f",
'Π' => "xcexa0",
'Ρ' => "xcexa1",
'Σ' => "xcexa3",
'Τ' => "xcexa4",
'Υ' => "xcexa5",
'Φ' => "xcexa6",
'Χ' => "xcexa7",
'Ψ' => "xcexa8",
'Ω' => "xcexa9",
'α' => "xcexb1",
'β' => "xcexb2",
'γ' => "xcexb3",
'δ' => "xcexb4",
'ε' => "xcexb5",
'ζ' => "xcexb6",
'η' => "xcexb7",
'θ' => "xcexb8",
'ι' => "xcexb9",
'κ' => "xcexba",
'λ' => "xcexbb",
'μ' => "xcexbc",
'ν' => "xcexbd",
'ξ' => "xcexbe",
'ο' => "xcexbf",
'π' => "xcfx80",
'ρ' => "xcfx81",
'ς' => "xcfx82",
'σ' => "xcfx83",
'τ' => "xcfx84",
'υ' => "xcfx85",
'φ' => "xcfx86",
'χ' => "xcfx87",
'ψ' => "xcfx88",
'ω' => "xcfx89",
'ϑ' => "xcfx91",
'ϒ' => "xcfx92",
'ϖ' => "xcfx96",
'•' => "xe2x80xa2",
'…' => "xe2x80xa6",
'′' => "xe2x80xb2",
'″' => "xe2x80xb3",
'‾' => "xe2x80xbe",
'⁄' => "xe2x81x84",
'℘' => "xe2x84x98",
'ℑ' => "xe2x84x91",
'ℜ' => "xe2x84x9c",
'™' => "xe2x84xa2",
'ℵ' => "xe2x84xb5",
'←' => "xe2x86x90",
'↑' => "xe2x86x91",
'→' => "xe2x86x92",
'↓' => "xe2x86x93",
'↔' => "xe2x86x94",
'↵' => "xe2x86xb5",
'⇐' => "xe2x87x90",
'⇑' => "xe2x87x91",
'⇒' => "xe2x87x92",
'⇓' => "xe2x87x93",
'⇔' => "xe2x87x94",
'∀' => "xe2x88x80",
'∂' => "xe2x88x82",
'∃' => "xe2x88x83",
'∅' => "xe2x88x85",
'∇' => "xe2x88x87",
'∈' => "xe2x88x88",
'∉' => "xe2x88x89",
'∋' => "xe2x88x8b",
'∏' => "xe2x88x8f",
'∑' => "xe2x88x91",
'−' => "xe2x88x92",
'∗' => "xe2x88x97",
'√' => "xe2x88x9a",
'∝' => "xe2x88x9d",
'∞' => "xe2x88x9e",
'∠' => "xe2x88xa0",
'∧' => "xe2x88xa7",
'∨' => "xe2x88xa8",
'∩' => "xe2x88xa9",
'∪' => "xe2x88xaa",
'∫' => "xe2x88xab",
'∴' => "xe2x88xb4",
'∼' => "xe2x88xbc",
'≅' => "xe2x89x85",
'≈' => "xe2x89x88",
'≠' => "xe2x89xa0",
'≡' => "xe2x89xa1",
'≤' => "xe2x89xa4",
'≥' => "xe2x89xa5",
'⊂' => "xe2x8ax82",
'⊃' => "xe2x8ax83",
'⊄' => "xe2x8ax84",
'⊆' => "xe2x8ax86",
'⊇' => "xe2x8ax87",
'⊕' => "xe2x8ax95",
'⊗' => "xe2x8ax97",
'⊥' => "xe2x8axa5",
'⋅' => "xe2x8bx85",
'⌈' => "xe2x8cx88",
'⌉' => "xe2x8cx89",
'⌊' => "xe2x8cx8a",
'⌋' => "xe2x8cx8b",
'⟨' => "xe2x8cxa9",
'⟩' => "xe2x8cxaa",
'◊' => "xe2x97x8a",
'♠' => "xe2x99xa0",
'♣' => "xe2x99xa3",
'♥' => "xe2x99xa5",
'♦' => "xe2x99xa6",
'Œ' => "xc5x92",
'œ' => "xc5x93",
'Š' => "xc5xa0",
'š' => "xc5xa1",
'Ÿ' => "xc5xb8",
'ˆ' => "xcbx86",
'˜' => "xcbx9c",
' ' => "xe2x80x82",
' ' => "xe2x80x83",
' ' => "xe2x80x89",
'‌' => "xe2x80x8c",
'‍' => "xe2x80x8d",
'‎' => "xe2x80x8e",
'‏' => "xe2x80x8f",
'–' => "xe2x80x93",
'—' => "xe2x80x94",
'‘' => "xe2x80x98",
'’' => "xe2x80x99",
'‚' => "xe2x80x9a",
'“' => "xe2x80x9c",
'”' => "xe2x80x9d",
'„' => "xe2x80x9e",
'†' => "xe2x80xa0",
'‡' => "xe2x80xa1",
'‰' => "xe2x80xb0",
'‹' => "xe2x80xb9",
'›' => "xe2x80xba",
'€' => "xe2x82xac",
);
$htmlspecialchars = array(
'"' => "x22",
'&' => "x26",
'<' => "x3c",
'>' => "x3e",
);
if ($is_htmlspecialchars)
$table += $htmlspecialchars;
preg_match_all('/&[a-zA-Z]+d*;/s', $s, $m, null, $pos);
foreach (array_unique($m[0]) as $entity) {
if (array_key_exists($entity, $table))
$s = str_replace($entity, $table[$entity], $s);
}
if (($pos = strpos($s, '&#')) !== false) {
$htmlspecialchars_flip = array_flip($htmlspecialchars);
$s = preg_replace(
'/&#((x)[da-fA-F]{2,4}|d{1,4});/se', '(array_key_exists($a = pack("C", $d = ("$2") ? hexdec("$1") : "$1"), $htmlspecialchars_flip) && ! $is_htmlspecialchars) ?
$htmlspecialchars_flip[$a] :
iconv("UCS-2BE", "UTF-8", pack("n", $d))', $s, - 1, $pos);
}
return $s;
}
static function utf8_convert_case($s, $mode) {
static $trans = array(
"x41" => "x61",
"x42" => "x62",
"x43" => "x63",
"x44" => "x64",
"x45" => "x65",
"x46" => "x66",
"x47" => "x67",
"x48" => "x68",
"x49" => "x69",
"x4a" => "x6a",
"x4b" => "x6b",
"x4c" => "x6c",
"x4d" => "x6d",
"x4e" => "x6e",
"x4f" => "x6f",
"x50" => "x70",
"x51" => "x71",
"x52" => "x72",
"x53" => "x73",
"x54" => "x74",
"x55" => "x75",
"x57" => "x77",
"x56" => "x76",
"x58" => "x78",
"x59" => "x79",
"x5a" => "x7a",
"xd0x81" => "xd1x91",
"xd0x90" => "xd0xb0",
"xd0x91" => "xd0xb1",
"xd0x92" => "xd0xb2",
"xd0x93" => "xd0xb3",
"xd0x94" => "xd0xb4",
"xd0x95" => "xd0xb5",
"xd0x96" => "xd0xb6",
"xd0x97" => "xd0xb7",
"xd0x98" => "xd0xb8",
"xd0x99" => "xd0xb9",
"xd0x9a" => "xd0xba",
"xd0x9b" => "xd0xbb",
"xd0x9c" => "xd0xbc",
"xd0x9d" => "xd0xbd",
"xd0x9e" => "xd0xbe",
"xd0x9f" => "xd0xbf",
"xd0xa0" => "xd1x80",
"xd0xa1" => "xd1x81",
"xd0xa2" => "xd1x82",
"xd0xa3" => "xd1x83",
"xd0xa4" => "xd1x84",
"xd0xa5" => "xd1x85",
"xd0xa6" => "xd1x86",
"xd0xa7" => "xd1x87",
"xd0xa8" => "xd1x88",
"xd0xa9" => "xd1x89",
"xd0xaa" => "xd1x8a",
"xd0xab" => "xd1x8b",
"xd0xac" => "xd1x8c",
"xd0xad" => "xd1x8d",
"xd0xae" => "xd1x8e",
"xd0xaf" => "xd1x8f",
"xd2x96" => "xd2x97",
"xd2xa2" => "xd2xa3",
"xd2xae" => "xd2xaf",
"xd2xba" => "xd2xbb",
"xd3x98" => "xd3x99",
"xd3xa8" => "xd3xa9",
"xd2x90" => "xd2x91",
"xd0x84" => "xd1x94",
"xd0x86" => "xd1x96",
"xd0x87" => "xd1x97",
"xd0x8e" => "xd1x9e",
"xc3x84" => "xc3xa4",
"xc3x87" => "xc3xa7",
"xc3x91" => "xc3xb1",
"xc3x96" => "xc3xb6",
"xc3x9c" => "xc3xbc",
"xc4x9e" => "xc4x9f",
"xc4xb0" => "xc4xb1",
"xc5x9e" => "xc5x9f",
"xc4x8c" => "xc4x8d",
"xc4x86" => "xc4x87",
"xc4x90" => "xc4x91",
"xc5xa0" => "xc5xa1",
"xc5xbd" => "xc5xbe",
"xc3x80" => "xc3xa0",
"xc3x82" => "xc3xa2",
"xc3x86" => "xc3xa6",
"xc3x88" => "xc3xa8",
"xc3x89" => "xc3xa9",
"xc3x8a" => "xc3xaa",
"xc3x8b" => "xc3xab",
"xc3x8e" => "xc3xae",
"xc3x8f" => "xc3xaf",
"xc3x94" => "xc3xb4",
"xc5x92" => "xc5x93",
"xc3x99" => "xc3xb9",
"xc3x9b" => "xc3xbb",
"xc5xb8" => "xc3xbf",
);
if ($mode == CASE_UPPER) {
if (function_exists('mb_strtoupper'))
return mb_strtoupper($s, 'utf-8');
if (preg_match('/^[x00-x7e]*$/', $s))
return strtoupper($s);
strtr($s, array_flip($trans));
} elseif ($mode == CASE_LOWER) {
if (function_exists('mb_strtolower'))
return mb_strtolower($s, 'utf-8');
if (preg_match('/^[x00-x7e]*$/', $s))
return strtolower($s);
strtr($s, $trans);
} else {
trigger_error('Parameter 2 should be a constant of CASE_LOWER or CASE_UPPER!', E_USER_WARNING);
return $s;
}
return $s;
}
static function strip_tags_smart($s, array $allowable_tags = null, $is_format_spaces = false, array $pair_tags = array('script', 'style', 'map', 'iframe', 'frameset', 'object', 'applet', 'comment', 'button'), array $para_tags = array('p', 'td', 'th', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'form', 'title')
) {
static $_callback_type = false;
static $_allowable_tags = array();
static $_para_tags = array();
static $re_attrs_fast_safe = '(?> (?>[x20rnt]+|xc2xa0)+ #пробельные символы (д.б. обязательно)
(?>
#правильные атрибуты
[^>"']+
| (?<=[=x20rnt]|xc2xa0) "[^"]*"
| (?<=[=x20rnt]|xc2xa0) '[^']*'
#разбитые атрибуты
| [^>]+
)*
)?';
if (is_array($s) && $_callback_type === 'strip_tags') {
$tag = strtolower($s[1]);
if ($_allowable_tags &&
(array_key_exists($tag, $_allowable_tags) || array_key_exists('<' . trim(strtolower($s[0]), '< />') . '>', $_allowable_tags))
)
return $s[0];
if ($tag == 'br')
return "rn";
if ($_para_tags && array_key_exists($tag, $_para_tags))
return "rnrn";
return '';
}
if (($pos = strpos($s, '<') === false) || strpos($s, '>', $pos) === false) {
return $s;
}
$re_tags = '/<[/!]? ([a-zA-Z][a-zA-Zd]* (?>:[a-zA-Z][a-zA-Zd]*)?)' . $re_attrs_fast_safe . '/?>/sx';
$patterns = array(
'/<([?%]) .*? \1>/sx',
'/<![CDATA[ .*? ]]>/sx',
'/<!--.*?-->/s',
'/<! (?>--)?
[
(?> [^]"']+ | "[^"]*" | '[^']*' )*
]
(?>--)?
>/sx',
);
if ($pair_tags) {
foreach ($pair_tags as $k => $v)
$pair_tags[$k] = preg_quote($v, '/');
$patterns[] = '/<((?i:' . implode('|', $pair_tags) . '))' . $re_attrs_fast_safe . '> .*? </(?i:\1)' . $re_attrs_fast_safe . '>/sx';
}
$i = 0;
$max = 99;
while ($i < $max) {
$s2 = preg_replace($patterns, '', $s);
if ($i == 0) {
$is_html = ($s2 != $s || preg_match($re_tags, $s2));
if ($is_html) {
$s2 = strtr($s2, "x09x0ax0cx0d", ' ');
if ($allowable_tags)
$_allowable_tags = array_flip($allowable_tags);
if ($para_tags)
$_para_tags = array_flip($para_tags);
}
}
if ($is_html) {
$_callback_type = 'strip_tags';
$s2 = preg_replace_callback($re_tags, array(__CLASS__, 'strip_tags_smart'), $s2);
$_callback_type = false;
}
if ($s === $s2)
break;
$s = $s2;
$i++;
}
if ($i >= $max)
$s = strip_tags($s);
if ($is_format_spaces || $is_html) {
$s = preg_replace('/x20x20+/s', ' ', trim($s));
$s = str_replace(array("rnx20", "x20rn"), "rn", $s);
$s = preg_replace('/rn[rn]+/s', "rnrn", $s);
}
return $s;
}
}