├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml ├── src └── ObsceneCensorRus.php └── tests ├── Cp1251Test.php ├── FalsePositiveTest.php ├── FilterTest.php ├── PositiveTest.php └── TodoTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | composer.lock 3 | vendor 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | php: 3 | - 5.6 4 | - 5.5 5 | - 5.4 6 | - 5.3 7 | 8 | 9 | script: 10 | - phpunit --configuration phpunit.xml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Vea Rooftop 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | php-obscene-censor-rus 2 | ====================== 3 | [![Build Status](https://travis-ci.org/vearutop/php-obscene-censor-rus.png?branch=master)](https://travis-ci.org/vearutop/php-obscene-censor-rus) [![Total Downloads](https://poser.pugx.org/vearutop/php-obscene-censor-rus/downloads)](https://packagist.org/packages/vearutop/php-obscene-censor-rus) 4 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fvearutop%2Fphp-obscene-censor-rus.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fvearutop%2Fphp-obscene-censor-rus?ref=badge_shield) 5 | 6 | Класс для фильтрации нецензурных выражений (матов). 7 | 8 | Анализ на основе регулярных выражений с списком исключений, совместим с UTF8. 9 | 10 | Использование: 11 | 12 | ```php 13 | $text = 'Да пошел ты нахуй и в пиzdu huesos, ушлепок ебаный, ебать мой вялый хуй! 14 | Мой дед ветеран твоего деда педрилу ебал :( Хуячечки'; 15 | 16 | ObsceneCensorRus::filterText($text); 17 | 18 | echo $text; 19 | //Да пошел ты ***** и в ***** ******, ушлепок ******, ***** мой вялый ***! 20 | //Мой дед ветеран твоего деда ******* **** :( ******** 21 | ``` 22 | 23 | ```php 24 | $text = ObsceneCensorRus::getFiltered($text); 25 | ``` 26 | 27 | ```php 28 | var_dump(ObsceneCensorRus::isAllowed($text)); 29 | // false 30 | ``` 31 | 32 | Вторым параметром можно указать кодировку если она отличается от UTF8 33 | ```php 34 | ObsceneCensorRus::getFiltered('кто прочитает тот лол', 'CP1251') 35 | ``` 36 | 37 | Установка: 38 | ``` 39 | composer require vearutop/php-obscene-censor-rus 40 | ``` 41 | 42 | Тесты: 43 | ``` 44 | php phpunit.phar ./tests 45 | ``` 46 | 47 | 48 | Цензура, антимат, матерщинные слова, фильтр мата, обсценная лексика, нецензурная брань, треугольные сиськи. 49 | 50 | 51 | ## License 52 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fvearutop%2Fphp-obscene-censor-rus.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fvearutop%2Fphp-obscene-censor-rus?ref=badge_large) -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vearutop/php-obscene-censor-rus", 3 | "type": "library", 4 | "description": "Класс для фильтрации нецензурных выражений (матов).", 5 | "keywords": ["censor", "антимат", "цензура", "хуй", "модерация"], 6 | "homepage": "https://github.com/vearutop/php-obscene-censor-rus/", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Viacheslav Poturaev", 11 | "email": "vearutop@gmail.com", 12 | "homepage": "https://github.com/vearutop" 13 | } 14 | ], 15 | "require": { 16 | "php": ">=5.3.0" 17 | }, 18 | "autoload": { 19 | "psr-4": {"Wkhooy\\": "src/"} 20 | }, 21 | "require-dev": { 22 | "phpunit/phpunit": "^4.0" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ./tests 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/ObsceneCensorRus.php: -------------------------------------------------------------------------------- 1 | 0) { 188 | for ($i = 0; $i < $c; $i++) { 189 | $word = $m[1][$i]; 190 | $word = mb_strtolower($word, $utf8); 191 | 192 | foreach (self::$exceptions as $x) { 193 | if (mb_strpos($word, $x) !== false) { 194 | if (is_array(self::$logEx)) { 195 | $t = &self::$logEx[$m[1][$i]]; 196 | ++$t; 197 | } 198 | $word = false; 199 | unset($m[1][$i]); 200 | break; 201 | } 202 | } 203 | 204 | if ($word) { 205 | $m[1][$i] = str_replace(array(' ', ',', ';', '.', '!', '-', '?', "\t", "\n"), '', $m[1][$i]); 206 | } 207 | } 208 | 209 | $m[1] = array_unique($m[1]); 210 | 211 | //var_dump($m[1]); 212 | $asterisks = array(); 213 | foreach ($m[1] as $word) { 214 | if (is_array(self::$log)) { 215 | $t = &self::$log[$word]; 216 | ++$t; 217 | } 218 | $asterisks []= str_repeat('*', mb_strlen($word, $utf8)); 219 | } 220 | 221 | $text = str_replace($m[1], $asterisks, $text); 222 | 223 | if ($charset !== $utf8) { 224 | $text = iconv($utf8, $charset, $text); 225 | } 226 | 227 | return true; 228 | } else { 229 | if ($charset !== $utf8) { 230 | $text = iconv($utf8, $charset, $text); 231 | } 232 | 233 | return false; 234 | } 235 | } 236 | 237 | } 238 | -------------------------------------------------------------------------------- /tests/Cp1251Test.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vearutop/php-obscene-censor-rus/ff0baca1aa0c4caba875773115f50d8252487b31/tests/Cp1251Test.php -------------------------------------------------------------------------------- /tests/FalsePositiveTest.php: -------------------------------------------------------------------------------- 1 | assertSame('феерический *******', ObsceneCensorRus::getFiltered('феерический долбоеб')); 10 | $this->assertSame('12 ноября', ObsceneCensorRus::getFiltered('12 ноября')); 11 | $this->assertTrue(ObsceneCensorRus::isAllowed('dying')); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/FilterTest.php: -------------------------------------------------------------------------------- 1 | assertSame($expected, ObsceneCensorRus::getFiltered($test)); 18 | } 19 | 20 | 21 | public function testText() { 22 | $test = 'Да пошел ты нахуй и в пиzdu huesos, ушлепок ебаный, ебать мой вялый хуй! 23 | Мой дед ветеран твоего деда педрилу ебал :( Хуячечки'; 24 | ObsceneCensorRus::filterText($test); 25 | 26 | $this->assertSame('Да пошел ты ***** и в ***** ******, ушлепок ******, ***** мой вялый ***! 27 | Мой дед ветеран твоего деда ******* **** :( ********', $test); 28 | } 29 | 30 | 31 | public function testLog() { 32 | ObsceneCensorRus::$log = array(); 33 | ObsceneCensorRus::$logEx = array(); 34 | 35 | ObsceneCensorRus::getFiltered('ебанушка'); 36 | ObsceneCensorRus::getFiltered('йоба'); 37 | ObsceneCensorRus::getFiltered('педик'); 38 | ObsceneCensorRus::getFiltered('транквилизатор'); 39 | ObsceneCensorRus::getFiltered('Йебать'); 40 | ObsceneCensorRus::getFiltered('3 рубля'); 41 | ObsceneCensorRus::getFiltered('дайте хлеба в ноябре'); 42 | 43 | 44 | $this->assertSame(array( 45 | 'ебанушка' => 1, 46 | 'йоба' => 1, 47 | 'педик' => 1, 48 | 'Йебать' => 1, 49 | ), 50 | ObsceneCensorRus::$log); 51 | 52 | 53 | $this->assertSame(array( 54 | 'рубля' => 1, 55 | 'ноябре' => 1, 56 | ), 57 | ObsceneCensorRus::$logEx); 58 | 59 | 60 | ObsceneCensorRus::$log = null; 61 | ObsceneCensorRus::$logEx = null; 62 | } 63 | 64 | 65 | 66 | public function testAllowed() { 67 | $this->assertTrue(ObsceneCensorRus::isAllowed('Ан нет. Готовит снова рок Последний жесткий свой урок.')); 68 | $this->assertFalse(ObsceneCensorRus::isAllowed('Итак, пиздец приходит дяде. Навек прощайте, водка, бляди…')); 69 | } 70 | 71 | 72 | 73 | } -------------------------------------------------------------------------------- /tests/PositiveTest.php: -------------------------------------------------------------------------------- 1 | assertSame('******', ObsceneCensorRus::getFiltered('ПиЗдЮк')); 10 | $this->assertSame('*****', ObsceneCensorRus::getFiltered('сучка')); 11 | 12 | $this->assertSame('DHIWE ******', ObsceneCensorRus::getFiltered('DHIWE E6AHOE')); 13 | $this->assertSame('********', ObsceneCensorRus::getFiltered('ибанушка')); 14 | 15 | $this->assertSame('*****', ObsceneCensorRus::getFiltered('huilo')); 16 | $this->assertSame('*****', ObsceneCensorRus::getFiltered('пидор')); 17 | $this->assertSame('*****', ObsceneCensorRus::getFiltered('педик')); 18 | $this->assertSame('*********', ObsceneCensorRus::getFiltered('пидарасит')); 19 | $this->assertSame('**********', ObsceneCensorRus::getFiltered('мандавошка')); 20 | $this->assertSame('*********** творог', ObsceneCensorRus::getFiltered('подзалупный творог')); 21 | } 22 | } -------------------------------------------------------------------------------- /tests/TodoTest.php: -------------------------------------------------------------------------------- 1 | assertSame('сучила', ObsceneCensorRus::getFiltered('сучила')); 10 | } 11 | } --------------------------------------------------------------------------------