68 use \Bitrix\Forum\Internals\EntityFabric;
69 use \Bitrix\Forum\Internals\EntityBaseMethods;
78 private const NOT_WORD =
"\s.,;:!?\#\-\*\|\[\]\(\)";
83 $this->data = DictionaryTable::getById($this->
id)->fetch();
85 if ($languageId ===
null)
87 $languageId = LANGUAGE_ID;
89 $this->translitId = Main\Config\Option::get(
"forum",
"FILTER_DICT_T",
"", $languageId);
92 public function delete()
94 $result = DictionaryTable::delete($this->
id);
95 if ($result->isSuccess())
98 if ($this->data[
"TYPE"] ==
"T")
99 $DB->Query(
"DELETE FROM b_forum_letter WHERE DICTIONARY_ID=".$this->
id);
101 $DB->Query(
"DELETE FROM b_forum_filter WHERE DICTIONARY_ID=".$this->
id);
105 private function getTranslitDictionary($multiLetter =
true) : array
107 static $letters =
null;
108 if (is_null($letters))
111 "singleLetter" => [],
114 $dbRes = LetterTable::getList([
116 "filter" => [
"DICTIONARY_ID" => $this->translitId],
122 while ($lett = $dbRes->fetch())
127 $arrRepl = explode(
",", $lett[
"REPLACEMENT"]);
129 for ($ii = 0; $ii < count($arrRepl); $ii++)
131 $arrRepl[$ii] = trim($arrRepl[$ii]);
132 if (mb_strlen($lett[
"LETTER"]) == 1)
134 if (mb_strlen($arrRepl[$ii]) == 1)
136 $arrRes[$ii] = $arrRepl[$ii].
"+";
138 else if (mb_strpos($arrRepl[$ii],
"(") === 0 && mb_substr($arrRepl[$ii], -1, 1) ==
")")
140 $arrRes[$ii] = $arrRepl[$ii].
"+";
142 else if (mb_strpos($arrRepl[$ii],
"(") === 0 && mb_substr($arrRepl[$ii], -2, 1) ==
")")
144 $arrRes[$ii] = $arrRepl[$ii];
146 else if (mb_strlen($arrRepl[$ii]) > 1)
148 $arrRes[$ii] =
"[".$arrRepl[$ii].
"]+";
155 else if ($arrRepl[$ii] <>
'')
157 $arrRes[$ii] = $arrRepl[$ii];
161 if (mb_strlen($lett[
"LETTER"]) == 1)
167 $letters[
"singleLetter"][$lett[
"LETTER"]] =
"(".implode(
"|", $arrRes).
")";
171 $letters[
"multiLetter"][
"/".preg_quote($lett[
"LETTER"]).
"/is".BX_UTF_PCRE_MODIFIER] =
"(".implode(
"|", $arrRes).
")";
174 $letters[
"singleLetter"][
"*"] =
"[^".self::NOT_WORD.
"]*";
175 $letters[
"singleLetter"][
"+"] =
"[^".self::NOT_WORD.
"]+";
176 $letters[
"singleLetter"][
"?"] =
".?";
178 return ($multiLetter ===
true ? $letters[
"multiLetter"] : $letters[
"singleLetter"]);
184 $letters = $this->getTranslitDictionary(
true);
185 $word = preg_replace(array_keys($letters), array_values($letters), mb_strtolower(trim($word)));
188 $letters = $this->getTranslitDictionary(
false);
189 $replace = array_flip(array_keys($letters));
191 $length = strlen(count($replace));
192 $replace1 = array_map(
function ($number) use ($length) {
193 $number = str_pad($number, $length,
"0", STR_PAD_LEFT);
194 return "\017x$number";}, $replace);
196 $word = str_replace(array_keys($replace), array_values($replace1), $word);
197 $word = preg_quote($word);
198 $word = str_replace(array_values($replace1), array_values($letters), $word);
200 $word =
"/(?<=[".self::NOT_WORD.
"])(".$word.
")(?=[".self::NOT_WORD.
"])/is".BX_UTF_PCRE_MODIFIER;
207 $res =
"/(?<=[".self::NOT_WORD.
"])(".preg_quote($word).
")(?=[".self::NOT_WORD.
"])/is".BX_UTF_PCRE_MODIFIER;
static loadMessages($file)