if ($ex = $APPLICATION->GetException()) { $APPLICATION->ThrowException($ex->GetString()); } else { $APPLICATION->ThrowException(GetMessage("FLTR_NOT_SAVE")); } } $bVarsFromForm = true; $sDocTitle = $ID > 0 ? str_replace("#ID#", $ID, GetMessage("FLTR_EDIT")) : GetMessage("FLTR_NEW"); $APPLICATION->SetTitle($sDocTitle); require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php"; /*******************************************************************/ $str_LETTER = ""; $str_REPLACEMENT = ""; $str_DICTIONARY_ID = $DICTIONARY_ID; if ($ID > 0) { $db_res = CFilterLetter::GetList(array(), array("ID" => $ID)); $db_res->ExtractFields("str_", False); } if ($bVarsFromForm) { $DB->InitTableVarsForEdit("b_forum_letter", "", "str_"); } $aMenu = array(array("TEXT" => GetMessage("FLTR_LIST"), "LINK" => "/bitrix/admin/forum_letter.php?DICTIONARY_ID=" . $DICTIONARY_ID . "&lang=" . LANG, "ICON" => "btn_list")); if ($ID > 0 && $forumPermWrite) { $aMenu[] = array("SEPARATOR" => "Y"); $aMenu[] = array("TEXT" => GetMessage("FLTR_NEW"), "LINK" => "/bitrix/admin/forum_dictionary_edit.php?DICTIONARY_ID=" . $DICTIONARY_ID . "&lang=" . LANG, "ICON" => "btn_new"); $aMenu[] = array("TEXT" => GetMessage("FLTR_DEL"), "LINK" => "javascript:if(confirm('" . GetMessage("FLTR_DEL_CONFIRM") . "')) window.location='/bitrix/admin/forum_letter.php?DICTIONARY_ID=" . $DICTIONARY_ID . "&lang=" . LANG . "&action=delete&ID[]=" . $ID . "&" . bitrix_sessid_get() . "';", "ICON" => "btn_delete"); } $context = new CAdminContextMenu($aMenu); $context->Show(); if ($err = $APPLICATION->GetException()) { CAdminMessage::ShowMessage($err->GetString());
public static function CreatePattern($pattern = "", $DICTIONARY_ID = 0) { $res = ""; $NotWord = "\\s.,;:!?\\#\\-\\*\\|\\[\\]\\(\\)"; $word_separator = "[" . $NotWord . "]"; $pattern = strtolower(trim($pattern)); $DICTIONARY_ID = intval($DICTIONARY_ID); if (strlen($pattern) <= 0) { return false; } if ($DICTIONARY_ID == 0) { $DICTIONARY_ID = COption::GetOptionString("forum", "FILTER_DICT_T", '', LANGUAGE_ID); } elseif ($DICTIONARY_ID < 0) { $DICTIONARY_ID = 0; } $lettPatt = array(); $lettersPatt = array(); $letters = CFilterLetter::GetList(array(), array("DICTIONARY_ID" => $DICTIONARY_ID)); while ($lett = $letters->Fetch()) { $space = false; $arrRes = array(); $arrRepl = array(); $arrRepl = explode(",", $lett["REPLACEMENT"]); // create letters. for ($ii = 0; $ii < count($arrRepl); $ii++) { $arrRepl[$ii] = trim($arrRepl[$ii]); if (strLen($lett["LETTER"]) == 1) { if (strLen($arrRepl[$ii]) == 1) { $arrRes[$ii] = $arrRepl[$ii] . "+"; } elseif (substr($arrRepl[$ii], 0, 1) == "(" && (substr($arrRepl[$ii], -1, 1) == ")" || substr($arrRepl[$ii], -2, 1) == ")")) { if (substr($arrRepl[$ii], -1, 1) == ")") { $arrRes[$ii] = $arrRepl[$ii] . "+"; } else { $arrRes[$ii] = $arrRepl[$ii]; } } elseif (strLen($arrRepl[$ii]) > 1) { $arrRes[$ii] = "[" . $arrRepl[$ii] . "]+"; } else { $space = true; } } else { if (strLen($arrRepl[$ii]) > 0) { $arrRes[$ii] = $arrRepl[$ii]; } } } if (strLen($lett["LETTER"]) == 1) { if ($space) { $arrRes[] = ""; } // $lettPatt[$lett["LETTER"]] = str_replace("+", "*", $lettPatt[$lett["LETTER"]]); $lettPatt[$lett["LETTER"]] = implode("|", $arrRes); } else { $lettersPatt["/" . preg_quote($lett["LETTER"]) . "/is" . BX_UTF_PCRE_MODIFIER] = "(" . implode("|", $arrRes) . ")"; } } // letters foreach ($lettersPatt as $key => $val) { $pattern = preg_replace($key . BX_UTF_PCRE_MODIFIER, $val, $pattern); } for ($ii = 0; $ii < strLen($pattern); $ii++) { $sPattern = substr($pattern, $ii, 1); if (is_set($lettPatt, substr($pattern, $ii, 1))) { $res .= "(" . $lettPatt[substr($pattern, $ii, 1)] . ")"; } else { $ord = ord(substr($pattern, $ii, 1)); if (48 > $ord || (64 > $ord and $ord > 57) || (97 > $ord and $ord > 90) || (127 > $ord and $ord > 122)) { if ($ord == 42) { $res .= "[^" . $NotWord . "]*"; } elseif ($ord == 43) { $res .= "[^" . $NotWord . "]+"; } elseif ($ord == 63) { $res .= ".?"; } else { $res .= substr($pattern, $ii, 1); } } else { $res .= substr($pattern, $ii, 1) . "+"; } } $res .= $separator; } $res = "/(?<=" . $word_separator . ")(" . $res . ")(?=" . $word_separator . ")/is" . BX_UTF_PCRE_MODIFIER; return $res; }
} if (check_bitrix_sessid() && CFilterUnquotableWords::FilterPerm()) { foreach ($arID as $ID) { if (strlen($ID) <= 0) { continue; } $ID = intval($ID); switch ($_REQUEST['action']) { case "delete": CFilterLetter::Delete($ID); break; } } } } $rsData = CFilterLetter::GetList(array($by => $order), $arFilter); $rsData = new CAdminResult($rsData, $sTableID); $rsData->NavStart(); $lAdmin->NavText($rsData->GetNavPrint(GetMessage("FLT_LETTERS"))); $lAdmin->AddHeaders(array(array("id" => "ID", "content" => "ID", "sort" => "ID", "default" => true), array("id" => "LETTER", "content" => GetMessage("FLT_LETTER"), "sort" => "LETTER", "default" => true), array("id" => "REPLACEMENT", "content" => GetMessage("FLT_REPLACE"), "sort" => "REPLACEMENT", "default" => true))); /*******************************************************************/ while ($arData = $rsData->NavNext(true, "t_")) { $row =& $lAdmin->AddRow($t_ID, $arData); if (!CFilterUnquotableWords::FilterPerm()) { $row->bReadOnly = True; } $row->AddViewField("ID", $t_ID); $row->AddInputField("LETTER", array("size" => "35")); $row->AddInputField("REPLACEMENT", array("size" => "150")); // $row->AddViewField("DICTIONARY_ID", $DICTIONARY_ID); }