public function testSetMatchRule()
 {
     $c = new ae_CommentfilterModel();
     $c->setMatchRule('/^this is regex\\./i');
     $this->assertEquals($c->getMatchRule(), '/^this is regex\\./i');
     $c->setMatchRule(';^This too is regex\\.$;');
     $this->assertEquals($c->getMatchRule(), ';^This too is regex\\.$;');
     $this->setExpectedException('Exception');
     $c->setMatchRule('not regex');
 }
Example #2
0
/**
 * Create the comment filter.
 * @return {int} ID of the comment filter.
 */
function createCommentfilter()
{
    if (!isset($_POST['cf-name'], $_POST['cf-target'], $_POST['cf-match'], $_POST['cf-action'], $_POST['submit'])) {
        header('Location: ../admin.php?error=missing_data_for_cofilter');
        exit;
    }
    $cf = new ae_CommentfilterModel();
    if (isset($_POST['edit-id'])) {
        $cf->setId($_POST['edit-id']);
    }
    $cf->setName($_POST['cf-name']);
    $cf->setMatchTarget($_POST['cf-target']);
    try {
        $cf->setMatchRule($_POST['cf-match']);
    } catch (Exception $exc) {
        header('Location: ../admin.php?area=settings&cofilter&error=invalid_regex');
        exit;
    }
    $cf->setAction($_POST['cf-action']);
    $cf->setStatus(isset($_POST['cf-status']) ? $_POST['cf-status'] : ae_CommentfilterModel::STATUS_ACTIVE);
    $cf->save();
    return $cf->getId();
}