2namespace Bitrix\Forum\BadWords;
5use Bitrix\Main\ArgumentException;
7use \Bitrix\Main\Localization\Loc;
8use Bitrix\Main\ORM\Data\Result;
9use Bitrix\Main\ORM\Event;
10use Bitrix\Main\ORM\Fields\BooleanField;
11use Bitrix\Main\ORM\Fields\IntegerField;
12use Bitrix\Main\ORM\Fields\StringField;
13use Bitrix\Main\ORM\Fields\TextField;
14use Bitrix\Main\ORM\Fields\EnumField;
15use \Bitrix\Main\ORM\Data\UpdateResult;
17Loc::loadMessages(__FILE__);
37 private static $dataById = [];
38 private const PATTERN_CREATE_METHOD_SIMPLE =
"WORDS";
39 private const PATTERN_CREATE_METHOD_TRANSLATE =
"TRNSL";
40 private const PATTERN_CREATE_METHOD_NONE =
"PTTRN";
44 return 'b_forum_filter';
50 (
new IntegerField(
"ID", [
"primary" =>
true,
"autocomplete" =>
true])),
51 (
new IntegerField(
"DICTIONARY_ID", [
"required" =>
true])),
53 (
new TextField(
"PATTERN", [
"required" =>
true])),
56 self::PATTERN_CREATE_METHOD_SIMPLE,
57 self::PATTERN_CREATE_METHOD_TRANSLATE,
58 self::PATTERN_CREATE_METHOD_NONE
60 "default_value" => self::PATTERN_CREATE_METHOD_TRANSLATE,
63 (
new StringField(
"REPLACEMENT", [
"size" => 255,
"default_value" =>
""])),
65 (
new BooleanField(
"USE_IT", [
"values" => [
"N",
"Y"],
"default_value" =>
"Y"])),
74 if (array_key_exists(
"PATTERN",
$data))
77 if (!
$res->isSuccess())
86 unset(self::$dataById[$primary[
"ID"]]);
97 $result->addError(
new Main\
Error(Loc::getMessage(
"FLT_ERR_BAD_PATTERN").
" [empty]",
"emptyPattern"));
99 else if (strpos(
$pattern,
"/") !== 0)
101 $result->addError(
new Main\
Error(Loc::getMessage(
"FLT_ERR_BAD_DELIMITER"),
"badDelimiter"));
103 else if (($modificators = substr(
$pattern, strrpos(
$pattern,
"/"))) && strpos($modificators,
"e") !==
false)
105 $result->addError(
new Main\
Error(Loc::getMessage(
"FLT_ERR_BAD_MODIFICATOR"),
"badModificator"));
111 preg_match(
$pattern,
"test string", $arTest);
113 catch (\Throwable $exception)
117 Loc::getMessage(
"FLT_ERR_BAD_PATTERN").
" ".$exception->getMessage(),
128 if (!array_key_exists($id, self::$dataById))
130 self::$dataById[$id] = self::getList([
132 "filter" => [
"ID" => $id],
138 return self::$dataById[$id];
144 use \Bitrix\Forum\Internals\EntityFabric;
145 use \Bitrix\Forum\Internals\EntityBaseMethods;
157 throw new \Bitrix\Main\ArgumentException(__CLASS__ .
" empty id.");
161 throw new \Bitrix\Main\ArgumentException(__CLASS__ .
" data with id is empty.");
176 Loc::getMessage(
"FLT_ERR_DICT_PATT_MISSED"),
180 else if (isset(
$fields[
"DICTIONARY_ID"]) && intval(
$fields[
"DICTIONARY_ID"]) <= 0)
183 Loc::getMessage(
"FLT_ERR_DICTIONARY_MISSED"),
187 else if (isset(
$fields[
"WORDS"]) &&
$fields[
"WORDS"] !== $this[
"WORDS"] ||
188 isset(
$fields[
"DICTIONARY_ID"]) &&
$fields[
"DICTIONARY_ID"] !== $this[
"DICTIONARY_ID"] ||
189 isset(
$fields[
"PATTERN_CREATE"]) &&
$fields[
"PATTERN_CREATE"] !== $this[
"PATTERN_CREATE"]
193 $fields[
"DICTIONARY_ID"] = isset(
$fields[
"DICTIONARY_ID"]) ?
$fields[
"DICTIONARY_ID"] : $this[
"DICTIONARY_ID"];
194 $fields[
"PATTERN_CREATE"] = isset(
$fields[
"PATTERN_CREATE"]) ?
$fields[
"PATTERN_CREATE"] : $this[
"PATTERN_CREATE"];
195 if (($wordEqual = FilterTable::getList([
198 "DICTIONARY_ID" =>
$fields[
"DICTIONARY_ID"],
202 ])->fetch()) && !empty($wordEqual))
205 Loc::getMessage(
"FLT_ALREADY_EXIST"),
209 else if (
$fields[
"PATTERN_CREATE"] ===
"PTTRN")
213 else if (
$fields[
"PATTERN_CREATE"] ===
"TRNSL")
215 $fields[
"PATTERN"] = Dictionary::getById(
$fields[
"DICTIONARY_ID"])->translitAndCreatePattern(
$fields[
"WORDS"]);
219 $fields[
"PATTERN_CREATE"] =
"WORDS";
226 $result = FilterTable::update($this->
id, $fields);
231 public function delete()
233 return FilterTable::delete($this->
id);
239 if ($this[
"PATTERN_CREATE"] ===
"PTTRN")
241 $fields[
"PATTERN"] = $this[
"WORDS"];
243 else if ($this[
"PATTERN_CREATE"] ===
"TRNSL")
245 $fields[
"PATTERN"] = Dictionary::getById($this[
"DICTIONARY_ID"])->translitAndCreatePattern($this[
"WORDS"]);
249 $fields[
"PATTERN_CREATE"] =
"WORDS";
250 $fields[
"PATTERN"] = Dictionary::getById($this[
"DICTIONARY_ID"])->createPattern($this[
"WORDS"]);
252 return FilterTable::update($this->
id,
$fields);
261 Loc::getMessage(
"FLT_ERR_DICT_PATT_MISSED"),
265 else if (intval(
$fields[
"DICTIONARY_ID"]) <= 0)
268 Loc::getMessage(
"FLT_ERR_DICTIONARY_MISSED"),
272 else if (($wordEqual = FilterTable::getList([
275 "DICTIONARY_ID" =>
$fields[
"DICTIONARY_ID"],
278 ])->fetch()) && !empty($wordEqual))
281 Loc::getMessage(
"FLT_ALREADY_EXIST"),
285 else if (
$fields[
"PATTERN_CREATE"] ===
"PTTRN")
289 else if (
$fields[
"PATTERN_CREATE"] ===
"TRNSL")
291 $fields[
"PATTERN"] = Dictionary::getById(
$fields[
"DICTIONARY_ID"])->translitAndCreatePattern(
$fields[
"WORDS"]);
295 $fields[
"PATTERN_CREATE"] =
"WORDS";
static add(array $fields)
static getDataById($id, $ttl=84600)
static checkPattern(string $pattern)
static checkFields(Result $result, $primary, array $data)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(!Loader::includeModule('sale')) $pattern