28 if(is_array($this->arList))
30 foreach($this->arList as $arCode)
32 if(!isset($codes[$arCode[
"CLASS_NAME"]]))
34 $codes[$arCode[
"CLASS_NAME"]] =
array();
36 $codes[$arCode[
"CLASS_NAME"]][] = $arCode;
41 if(isset($codes[$className]))
43 return $codes[$className];
55 $cleanUrl = mb_substr(
$url, $hostPos + mb_strlen(
$_SERVER[
"HTTP_HOST"]));
60 if(($qMarkPos = mb_strpos($cleanUrl,
"?")))
61 $cleanUrl = mb_substr($cleanUrl, 0, $qMarkPos);
70 if(!is_array($this->arList))
76 foreach ($this->arList as $arCode)
78 $codeUrl = $this->
CleanUrl($arCode[
"URL"]);
80 if(($codeUrl == mb_substr(
$url, 0, mb_strlen($codeUrl)) && $codeUrl) || (!$arCode[
"CLASS_NAME"] && (!$arCode[
"URL"] || $arCode[
"URL"] ==
"*")))
96 if(is_array($this->arList))
98 foreach($this->arList as $arCode)
100 $codes[$arCode[
"TITLE_OBJ"]] = $arCode[
"ID"];
105 if(isset($codes[$strTitleObj]))
107 return $codes[$strTitleObj];
125 if(preg_match(
"#<\\s*/*\\s*script(.*?)*>#i",
$arFields[
"CODE"]))
147 $arCond[
"CLASS_NAME"] =
$arFields[
"CLASS_NAME"];
165 $aMsg[] =
array(
"id"=>
"CLASS_NAME",
"text"=>
GetMessage(
"HK_CF_HK_CLASS_NAME"));
170 $aMsg[] =
array(
"id"=>
"CLASS_NAME",
"text"=>
GetMessage(
"HK_CF_HK_CLASS_NAME"));
190 if(!is_array($this->arList))
192 if(
$CACHE_MANAGER->Read($this->hkCacheTtl,
"b_hot_keys_code".LANGUAGE_ID))
194 $this->arList =
$CACHE_MANAGER->Get(
"b_hot_keys_code".LANGUAGE_ID);
199 while($arTemp =
$res->Fetch())
201 if(!$arTemp[
"IS_CUSTOM"])
203 if(isset($arTemp[
"NAME"]) && $arTemp[
"NAME"] !=
"-=AUTONAME=-")
204 $arTemp[
"NAME"] =
GetMessage($arTemp[
"NAME"]);
206 if(isset($arTemp[
"COMMENTS"]))
207 $arTemp[
"COMMENTS"] =
GetMessage($arTemp[
"COMMENTS"]);
210 $this->arList[$arTemp[
"ID"]] = $arTemp;
212 $CACHE_MANAGER->Set(
"b_hot_keys_code".LANGUAGE_ID, $this->arList);
233 $strSql =
"SELECT ID FROM b_hot_keys WHERE CODE_ID=".intval(
$ID);
236 while($arHK =
$res->Fetch())
239 $sql =
"DELETE FROM b_hot_keys_code WHERE ID=".intval(
$ID);
241 return $DB->Query($sql);
253 $strUpdate =
$DB->PrepareUpdate(
"b_hot_keys_code",
$arFields);
257 $strSql =
"UPDATE b_hot_keys_code SET ".$strUpdate.
" WHERE ID=".intval(
$ID);
258 if(!
$DB->Query($strSql))
273 return $DB->Add(
"b_hot_keys_code",
$arFields);
279 $arSqlSearch =
array();
284 if ((
string)
$val ==
'' ||
$val ==
"NOT_REF")
290 $arSqlSearch[] =
"C.ID=".intval(
$val);
306 $arSqlSearch[] =
"C.NAME IS NOT NULL AND C.NAME<>'-=AUTONAME=-'";
311 $ord = (mb_strtoupper(
$val) <>
"ASC"?
"DESC":
"ASC");
312 switch(mb_strtoupper(
$key))
315 $sOrder .=
", C.ID ".$ord;
318 $sOrder .=
", C.CLASS_NAME ".$ord;
321 $sOrder .=
", C.CODE ".$ord;
324 $sOrder .=
", C.NAME ".$ord;
327 $sOrder .=
", C.COMMENTS ".$ord;
330 $sOrder .=
", C.TITLE_OBJ ".$ord;
333 $sOrder .=
", C.URL ".$ord;
336 $sOrder .=
", C.IS_CUSTOM ".$ord;
341 $sOrder =
"NAME ASC";
343 $strSqlOrder =
" ORDER BY ".trim($sOrder,
", ");
432 private function __construct() { }
433 private function __clone() { }
437 if (!isset(self::$instance))
440 self::$instance =
new $c;
442 self::$optUse = COption::GetOptionString(
'main',
"use_hot_keys",
"Y") ==
"Y";
443 self::$ExpImpFileName =
"hk_export_" . (
$_SERVER[
'HTTP_HOST'] ??
'CLI') .
".srl";
446 self::$instance->LoadToCache();
450 return self::$instance;
457 if(is_array($this->arList) || !self::$optUse)
460 if(isset(\
Bitrix\Main\Application::getInstance()->getSession()[
"hasHotKeys"]) && !\
Bitrix\Main\Application::getInstance()->getSession()[
"hasHotKeys"])
464 $cacheId = static::getCacheId(
$uid);
476 while($arTemp =
$res->Fetch())
477 $this->arList[$arTemp[
"ID"]] = $arTemp;
480 if(is_array($this->arList))
496 if(!$setDef || !$setNoDef)
525 return "b_hot_keys" .
$userId . LANGUAGE_ID;
533 if(!is_array($this->arList))
536 foreach ($this->arList as $arHK)
537 if($arHK[
"CODE_ID"] == $codeID)
547 if(!is_array($this->arList))
550 foreach ($this->arList as $arHK)
551 if($arHK[
"ID"] == $hkID)
552 return $arHK[
"USER_ID"];
561 if(!is_array($arCode))
564 if (is_array($this->arList))
566 foreach ($this->arList as $arHK)
568 if($arCode[
"ID"] == $arHK[
"CODE_ID"])
570 $arCode[
"KEYS_STRING"] = $arHK[
"KEYS_STRING"];
571 $arCode[
"CODE_ID"] = $arHK[
"CODE_ID"];
572 $arCode[
"HK_ID"] = $arHK[
"ID"];
581 $arCode[
"KEYS_STRING"] =
"";
582 $arCode[
"CODE_ID"] = $arCode[
"ID"];
583 $arCode[
"HK_ID"] = 0;
594 $arCodes = self::$codes->GetCodeByClassName($className);
604 $arCode[
"CODE"] =
$code;
607 $arCode[
"NAME"] =
$name;
629 public function GetTitle($strTitleObj, $forHint =
false)
634 $codeID = self::$codes->GetIDByTitleObj($strTitleObj);
636 $space = ($forHint ?
" " :
" ");
639 return " (".$space.htmlspecialcharsbx($this->
ShowHKAsChar($arHK[
"KEYS_STRING"]), ENT_QUOTES).$space.
") ";
645 public function SetTitle($className, $forHint =
false)
650 $arCodes = self::$codes->GetCodeByClassName($className);
659 if(!$arCode[
"TITLE_OBJ"])
663 $space = ($forHint ?
" " :
" ");
668 $retHtml .=
"<script> var d = BX('".$arCode[
"TITLE_OBJ"].
"'); if (!d) d=BX.findChild(document, {attribute: {'name': '".$arCode[
"TITLE_OBJ"].
"'}}, true ); if(d) d.title+=' (".$space.Cutil::JSEscape($this->
ShowHKAsChar($arHK[
"KEYS_STRING"])).$space.
") ';</script>";
674 public function PrintJSExecs($execs, $controlName =
"", $scriptTags =
true, $checkHK =
false)
678 if(!is_array($execs))
681 $printName = ($controlName? $controlName.
"." :
"");
683 foreach ($execs as $arExec)
686 $code = $printName.CUtil::JSEscape($arExec[
"CODE"]);
690 $retStr .=
' BXHotKeys.Add("'.htmlspecialcharsbx($arExec[
"KEYS_STRING"]).
'", "'.
$code.
'", '.intval($arExec[
"CODE_ID"]).
", '".strip_tags(addslashes($arExec[
"NAME"]),
"<b>").
"', ".intval($arExec[
"HK_ID"]).
"); ";
694 $retStr =
' if(window.BXHotKeys!==undefined) { '.$retStr.
' } ';
697 $retStr =
'<script>'.$retStr.
'</script>';
715 $aMsg[] =
array(
"id"=>
"KEYS_STRING",
"text"=>
GetMessage(
"HK_CF_KEYS_STRING"));
720 $hotKeys =
$res->Fetch();
724 if($hotKeys[
"CODE_ID"] ==
$arFields[
"CODE_ID"] && $hotKeys[
"USER_ID"] ==
$arFields[
"USER_ID"] &&
$ID != $hotKeys[
"ID"])
725 $aMsg[] =
array(
"id"=>
"CODE_ID",
"text"=>
GetMessage(
"HK_CF_CODEUSER_UNIQ"));
731 $aMsg[] =
array(
"id"=>
"CODE_ID",
"text"=>
GetMessage(
"HK_CF_CODEUSER_UNIQ"));
737 $aMsg[] =
array(
"id"=>
"KEYS_STRING",
"text"=>
GetMessage(
"HK_CF_KEYS_STRING"));
754 $arSqlSearch =
array();
759 if ((
string)
$val ==
'' ||
$val ==
"NOT_REF")
767 $arSqlSearch[] =
$key.
"=".intval(
$val);
779 $ord = (mb_strtoupper(
$val) <>
"ASC"?
"DESC":
"ASC");
780 switch(mb_strtoupper(
$key))
783 $sOrder .=
", ID ".$ord;
786 $sOrder .=
", KEYS_STRING ".$ord;
789 $sOrder .=
", CODE_ID ".$ord;
792 $sOrder .=
", USER_ID ".$ord;
798 $strSqlOrder =
" ORDER BY ".trim($sOrder,
", ");
822 $arPrepFields =
array(
823 "KEYS_STRING" =>
$arFields[
"KEYS_STRING"],
824 "CODE_ID" => intval(
$arFields[
"CODE_ID"]),
825 "USER_ID" => intval(
$arFields[
"USER_ID"]),
828 $result =
$DB->Add(
"b_hot_keys", $arPrepFields);
830 unset(\
Bitrix\Main\Application::getInstance()->getSession()[
"hasHotKeys"]);
831 static::CleanCache();
843 $strUpdate =
$DB->PrepareUpdate(
"b_hot_keys",
$arFields);
847 $strSql =
"UPDATE b_hot_keys SET ".$strUpdate.
" WHERE ID=".intval(
$ID);
848 if(!
$DB->Query($strSql))
851 unset(\
Bitrix\Main\Application::getInstance()->getSession()[
"hasHotKeys"]);
852 static::CleanCache();
861 $sql =
"DELETE FROM b_hot_keys WHERE ID=".intval(
$ID);
864 unset(\
Bitrix\Main\Application::getInstance()->getSession()[
"hasHotKeys"]);
865 static::CleanCache();
867 return $res->AffectedRowsCount();
874 $sql =
'DELETE FROM b_hot_keys WHERE USER_ID = ' . intval($USER_ID);
877 static::CleanCache($USER_ID);
879 return $res->AffectedRowsCount();
886 $etime = microtime(1) + 1;
889 $res =
$DB->Query(
'SELECT MIN(USER_ID) MIN_USER_ID FROM b_hot_keys WHERE USER_ID > ' . intval($USER_ID));
890 $next_user =
$res->Fetch();
891 if (!$next_user || !$next_user[
'MIN_USER_ID'])
899 '=ID' => $next_user[
'MIN_USER_ID'],
906 $DB->Query(
'DELETE FROM b_hot_keys WHERE USER_ID = ' . $next_user[
'MIN_USER_ID']);
907 static::CleanCache($next_user[
'MIN_USER_ID']);
910 while (microtime(1) < $etime);
912 return 'CHotKeys::CleanUp(' . $next_user[
'MIN_USER_ID'] .
');';
920 $uid = intval($userID);
922 unset(\
Bitrix\Main\Application::getInstance()->getSession()[
"hasHotKeys"]);
924 $sql =
"DELETE FROM b_hot_keys WHERE USER_ID=".$uid;
925 $delRes =
$DB->Query($sql);
930 while($arHK = $listRes->Fetch())
932 $arPrepFields =
array(
933 "KEYS_STRING" => $arHK[
"KEYS_STRING"],
934 "CODE_ID" => $arHK[
"CODE_ID"],
938 $insRes =
$DB->Add(
"b_hot_keys",$arPrepFields);
944 return ($delRes && !$insErr);
952 $lastPlusPos = mb_strrpos($hotKeysString,
"+");
956 $charCode = mb_substr($hotKeysString, $lastPlusPos + 1, mb_strlen($hotKeysString));
957 $preChar = mb_substr($hotKeysString, 0, $lastPlusPos + 1);
958 if($charCode == 16 || $charCode == 17 || $charCode == 18)
959 return mb_substr($preChar, 0, mb_strlen($preChar) - 1);
963 $charCode = $hotKeysString;
967 if(intval($charCode)<256)
969 if(!($codeSymb = ($this->arServSymb[intval($charCode)] ?? 0)))
970 $codeSymb = chr($charCode);
974 $codeSymb = html_entity_decode(
"&#".$charCode.
";", ENT_NOQUOTES,
LANG_CHARSET);
977 return $preChar.$codeSymb;
982 $keyCode = str_replace(
array(
"ctrl",
"alt",
"shift",
"+"),
"", mb_strtolower($keysString));
983 return !(strcmp(intval($keyCode), $keyCode));
993 BXHotKeys.MesNotAssign = '".GetMessageJS(
"HK_NOT_ASSIGN").
"';
994 BXHotKeys.MesClToChange = '".
GetMessageJS(
"HK_CLICK_TO_CHANGE").
"';
999 BXHotKeys.MesSettings = '".
GetMessageJS(
"HK_SETTINGS").
"';
1000 BXHotKeys.MesDefault = '".
GetMessageJS(
"HK_DEFAULT").
"';
1002 BXHotKeys.MesDelConfirm = '".
GetMessageJS(
"HK_DEL_CONFIRM").
"';
1003 BXHotKeys.MesDefaultConfirm = '".
GetMessageJS(
"HK_DEFAULT_CONFIRM").
"';
1006 BXHotKeys.MesExpFalse = '".
GetMessageJS(
"HK_EXP_FALSE").
"';
1007 BXHotKeys.MesImpFalse = '".
GetMessageJS(
"HK_IMP_FALSE").
"';
1008 BXHotKeys.MesImpSuc = '".
GetMessageJS(
"HK_IMP_SUCCESS").
"';
1009 BXHotKeys.MesImpHeader = '".
GetMessageJS(
"HK_IMP_HEADER").
"';
1010 BXHotKeys.MesFileEmpty = '".
GetMessageJS(
"HK_FILENAME_EMPTY").
"';
1012 BXHotKeys.MesChooseFile = '".
GetMessageJS(
"HK_CHOOSE_FILE").
"';
1013 BXHotKeys.uid = ".
$USER->GetID().
";
1020 return self::$optUse;
1032 if(isset($arPanelButton[
"LINK"]))
1033 $hkCode =
"location.href='".$arPanelButton[
"LINK"].
"'";
1035 if(isset($arPanelButton[
"ACTION"]))
1036 $hkCode = $arPanelButton[
"ACTION"];
1038 if(isset($arPanelButton[
"ALT"]))
1039 $arPanelButton[
"ALT"] = $arPanelButton[
"ALT"].(isset($arPanelButton[
"HK_ID"])? $this->
GetTitle($arPanelButton[
"HK_ID"]):
"");
1041 if(isset($arPanelButton[
"TITLE"]))
1042 $arPanelButton[
"TITLE"] = $arPanelButton[
"TITLE"].(isset($arPanelButton[
"HK_ID"])? $this->
GetTitle($arPanelButton[
"HK_ID"]):
"");
1044 if(isset($arPanelButton[
"HK_ID"]))
1046 $name = str_replace(
array(
"#BR#",
" "),
array(
" ",
""), $arPanelButton[
"TEXT"]);
1050 $name = $parent.$name;
1052 elseif (isset($arPanelButton[
"MENU"]) && $arPanelButton[
"MENU"])
1054 $name =
"<b>".$name.
"</b>";
1061 if (isset($arPanelButton[
"MENU"]) && is_array($arPanelButton[
"MENU"]))
1063 foreach ($arPanelButton[
"MENU"] as &$menu)
1064 $retJS .= $this->
PrintTPButton($menu, $parent.
" ");
1073 CUserOptions::GetOption(
"hot_keys",
"user_defined",
"a") ===
"a"
1074 && CUserOptions::GetOption(
"hot_keys",
"user_defined",
"b") ===
"b"
1080 CUserOptions::SetOption(
"hot_keys",
"user_defined",
true);
1089 if(COption::GetOptionString(
"fileman",
"stickers_use_hotkeys",
"Y") !=
"Y")
1092 $strSql =
"SELECT ID FROM b_hot_keys WHERE USER_ID=0 AND ( CODE_ID=87 OR CODE_ID=88 OR CODE_ID=89)";
1097 $this->
Add (
array(
"KEYS_STRING"=>
"Ctrl+Shift+83",
"CODE_ID"=>87,
"USER_ID"=>0));
1098 $this->
Add (
array(
"KEYS_STRING"=>
"Ctrl+Shift+88",
"CODE_ID"=>88,
"USER_ID"=>0));
1099 $this->
Add (
array(
"KEYS_STRING"=>
"Ctrl+Shift+76",
"CODE_ID"=>89,
"USER_ID"=>0));
1102 return COption::SetOptionString(
"fileman",
"stickers_use_hotkeys",
"N");
1108 if(!
$GLOBALS[
"APPLICATION"]->PanelShowed)
1134 $res = self::$codes->GetByID($codeID);
1142 $exceptedUsers =
array();
1146 while($hotKey =
$res->Fetch())
1147 if($hotKey[
"KEYS_STRING"] == $keysString)
1148 $exceptedUsers[] = $hotKey[
"USER_ID"];
1151 if(!empty($exceptedUsers))
1152 if(in_array(0, $exceptedUsers))
1156 $strSql =
"SELECT DISTINCT USER_ID FROM b_hot_keys";
1161 while($hkUsers =
$res->Fetch())
1163 if(!empty($exceptedUsers))
1164 if(in_array($hkUsers[
'USER_ID'], $exceptedUsers))
1167 $this->
Add (
array(
"KEYS_STRING"=>$keysString,
"CODE_ID"=>$codeID,
"USER_ID"=>$hkUsers[
'USER_ID']));
1182 if(!is_array($this->arList) || empty($this->arList))
1185 $arForExport =
array();
1186 $tmpDir = CTempFile::GetDirectoryName();
1188 $tmpExportFile = $tmpDir.self::$ExpImpFileName;
1190 foreach ($this->arList as $arHK)
1192 $res = self::$codes->GetByID($arHK[
'CODE_ID']);
1193 $arTmpCode =
$res->Fetch();
1195 if(!is_array($arTmpCode) || empty($arTmpCode))
1199 'KEYS_STRING' => $arHK[
'KEYS_STRING'],
1200 'CLASS_NAME' => $arTmpCode[
'CLASS_NAME'],
1201 'NAME' => $arTmpCode[
'NAME'],
1202 'IS_CUSTOM' => $arTmpCode[
'IS_CUSTOM'],
1205 if($arTmpCode[
'IS_CUSTOM'])
1207 $arTmpLink[
'CODE'] = $arTmpCode[
'CODE'];
1208 $arTmpLink[
'COMMENTS'] = $arTmpCode[
'COMMENTS'];
1209 $arTmpLink[
'URL'] = $arTmpCode[
'URL'];
1212 $arForExport[] = $arTmpLink;
1215 $result = file_put_contents($tmpExportFile, serialize($arForExport));
1220 return $tmpExportFile;
1237 $arInput = unserialize(
$fileContent, [
'allowed_classes' =>
false]);
1239 if(!is_array($arInput) || empty($arInput))
1244 foreach ($arInput as $arHotKey)
1247 if(!isset($arHotKey[
'IS_CUSTOM']) || !isset($arHotKey[
'KEYS_STRING']) || !isset($arHotKey[
'NAME']) || !$this->
CheckKeysString($arHotKey[
'KEYS_STRING']))
1250 if($arHotKey[
'IS_CUSTOM'])
1252 if(!isset($arHotKey[
'CODE']))
1255 $resCodes = self::$codes->GetList(
array(),
array(
1256 'CLASS_NAME' => $arHotKey[
'CLASS_NAME'] ??
'',
1257 'NAME' => $arHotKey[
'NAME'],
1258 'CODE' => $arHotKey[
'CODE'],
1260 $arCode = $resCodes->Fetch();
1262 $codeID = $arCode[
'ID'] ?? self::$codes->Add(
array(
1263 'CLASS_NAME' => $arHotKey[
'CLASS_NAME'] ??
"",
1264 'CODE' => $arHotKey[
'CODE'],
1265 'NAME' => $arHotKey[
'NAME'],
1266 'COMMENTS' => $arHotKey[
'COMMENTS'] ??
"",
1267 'TITLE_OBJ' => $arHotKey[
'TITLE_OBJ'] ??
"",
1268 'URL' => $arHotKey[
'URL'] ??
"",
1269 'IS_CUSTOM' => $arHotKey[
'IS_CUSTOM'],
1274 $resCodes = self::$codes->GetList(
array(),
array(
1275 'CLASS_NAME' => $arHotKey[
'CLASS_NAME'] ??
'',
1276 'NAME' => $arHotKey[
'NAME'],
1278 $arCode = $resCodes->Fetch();
1280 if(isset($arCode[
'ID']))
1281 $codeID = $arCode[
'ID'];
1288 "CODE_ID" => $codeID,
1289 "USER_ID" => intval($userID),
1291 $arHK = $resHK->Fetch();
1296 $hkID = $arHK[
'ID'];
1298 "KEYS_STRING" => $arHotKey[
"KEYS_STRING"],
1299 "CODE_ID" => $codeID,
1300 "USER_ID" => intval($userID),
1306 "KEYS_STRING" => $arHotKey[
"KEYS_STRING"],
1307 "CODE_ID" => $codeID,
1308 "USER_ID" => intval($userID),
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getList(array $parameters=array())
static GetLangSwitcherArray()
CheckFields($arFields, $ID=false)
GetList($aSort=array(), $arFilter=array(), $showEmptyName=true)
GetCodeByClassName($className)
GetIDByTitleObj($strTitleObj)
CheckFields($arFields, $ID=false)
static getCacheId($userId=null)
static CleanUp($USER_ID=0)
PrintJSExecs($execs, $controlName="", $scriptTags=true, $checkHK=false)
GetList($aSort=array(), $arFilter=array())
GetTitle($strTitleObj, $forHint=false)
CheckKeysString($keysString)
PrintTPButton(&$arPanelButton, $parent="")
ShowHKAsChar($hotKeysString)
static CleanCache($userId=null)
static DeleteByUser($USER_ID)
SetTitle($className, $forHint=false)
AddDefaultKeyToAll($codeID, $keysString)
Import($fileName, $userID)
GetCodeByClassName($className, $name="", $code="")
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$_SERVER["DOCUMENT_ROOT"]
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
CheckSerializedData($str, $max_depth=200)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
GetMessageJS($name, $aReplace=false)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
$GLOBALS['_____370096793']