function testProfanityFilter()
 {
     /* these test will no longer work, as we are dealing with random replacements
        
        $this->assertEquals(ProfanityFilter::filterHTML("<div>what <a href='foobar'>the</a> f**k?</div>"), "<div>what <a href='foobar'>the</a> #&@!*?</div>");
        $this->assertEquals(ProfanityFilter::filterHTML("what the f**k?"), "what the #&@!*?");
        $this->assertEquals(ProfanityFilter::filterHTML("---cusstest1---"), "---cusstest1-filtered---");
        */
     $profaneHTML = "<div>what <a href='foobar'>the</a> f**k?</div> brainfuck should be safe... what about assingement? Will it be filtered as ass?\n        Let's see about F**K or Ass";
     $filtered = ProfanityFilter::filterHTML($profaneHTML);
     // count profanity in original and filtered
     $cnt_prof = 0;
     $cnt_filt = 0;
     foreach (PA::$config->profanity as $i => $w) {
         $regexp = "/\\b" . $w . "\\b/i";
         $cnt_prof += preg_match_all($regexp, $profaneHTML, $m);
         $cnt_filt += preg_match_all($regexp, $filtered, $m);
     }
     echo "{$cnt_prof} profane words in input\n{$cnt_filt} in filtered output\n";
     echo "{$profaneHTML} \n------\n{$filtered}\n";
     $this->assertEquals($cnt_filt, 0, "expected 0 profane words, got {$cnt_filt}\n");
 }
Пример #2
0
function _filter($html, $truncate = NULL, $params = NULL)
{
    require_once PA::$path . "/ext/InputSanitizer/InputSanitizer.php";
    $defaults = NULL;
    // bleep out cuss words
    $defaults->filter_profanity = TRUE;
    // strip most html
    $defaults->passthrough_html = FALSE;
    // and break longish strings
    $defaults->wbr = 15;
    // minimal HTML formating
    $defaults->taglist = array('ul', 'li', 'p', 'br', 'b', 'strong', 'em', 'i');
    $defaults->collapseWhitespace = TRUE;
    foreach ($defaults as $k => $v) {
        if (empty($params->{$k})) {
            $params->{$k} = $v;
        }
    }
    $sDom = new InputSanitizer(@$params->taglist, @$params->attrlist);
    $sDom->wbr = @$params->wbr;
    // break long strings every 15 chars
    $sDom->htmlAllowedEverywhere = TRUE;
    $sDom->passthrough = @$params->passthrough_html;
    $sDom->collapseWhitespace = $params->collapseWhitespace;
    $filered_drop = array();
    foreach ($sDom->dropWithChildren as $i => $tag) {
        if (!in_array($tag, $params->taglist)) {
            $filered_drop[] = $tag;
        }
    }
    $sDom->dropWithChildren = $filered_drop;
    $html = $sDom->process($html, $truncate);
    if (@$params->filter_profanity) {
        require_once PA::$path . "/api/Validation/ProfanityFilter.php";
        $html = ProfanityFilter::filterHTML($html);
    }
    return $html;
}
function _out($html)
{
    return ProfanityFilter::filterHTML($html);
}