<?php

class sfFilterValidator extends sfValidator
{
	public static $filters = array(
		'@\b(cặc|cẶc|lồn|lỒn|buồi|buỒi|cứt|cỨt|fuck)\b@',
		'@[^\w|đ|Đ](đéo|đÉo|Đéo|ĐÉo|địt|đỊt|Địt|ĐỊt|ỉa|Ỉa|đụ|ĐỤ|Đụ|đỤ)[^\w]@',
	);
	public static $vnfilters = array(
		'@\b(kiem tien tren mang|kiem tien online|hack tien|hack tai khoan|duong vat|am ho)\b@',
		'@\b(dcm|dkm|vcl|vkl|cave|kak|may`|ma`y|bo may|me may|dit me|dit con me)\b@'
	);

	public function execute(&$value, &$error)
  {
    $error = $this->getParameterHolder()->get('filter_error');
		$content = strtolower($value);
		$content = str_replace('  ', ' ', $content);
    $content = ' '.$content.' ';
		foreach (self::$filters as $filter) {
			if (preg_match($filter, $content)) return false;
		}
		$vncontent = myUtility::vietDecode(myUtility::htmlToText($content));
		foreach (self::$vnfilters as $filter) {
			if (preg_match($filter, $vncontent)) return false;
		}
		return true;
	}

  public function initialize($context, $parameters = null)
  {
    parent::initialize($context);
    $this->getParameterHolder()->set('filter_error', 'Nội dung có từ ngữ không phù hợp');
    $this->getParameterHolder()->add($parameters);
    return true;
  }
}
