1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
hot_keys.php
См. документацию.
1<?php
8
10
12{
13 protected $arList;
14 protected $hkCacheTtl = 3600;
15
16 public function GetByID($ID)
17 {
18 return $this->GetList(array(), array("ID" => $ID));
19 }
20
21 public function GetCodeByClassName($className)
22 {
23 static $codes = null;
24 if($codes === null)
25 {
26 $this->LoadToCache();
27 $codes = array();
28 if(is_array($this->arList))
29 {
30 foreach($this->arList as $arCode)
31 {
32 if(!isset($codes[$arCode["CLASS_NAME"]]))
33 {
34 $codes[$arCode["CLASS_NAME"]] = array();
35 }
36 $codes[$arCode["CLASS_NAME"]][] = $arCode;
37 }
38 }
39 }
40
41 if(isset($codes[$className]))
42 {
43 return $codes[$className];
44 }
45
46 return false;
47 }
48
49 protected function CleanUrl($url)
50 {
51 $url = (string)$url;
52
53 //removes host & proto from url
54 if(($hostPos = mb_strpos($url, $_SERVER["HTTP_HOST"])))
55 $cleanUrl = mb_substr($url, $hostPos + mb_strlen($_SERVER["HTTP_HOST"]));
56 else
57 $cleanUrl = $url;
58
59 //removes all after "?"
60 if(($qMarkPos = mb_strpos($cleanUrl, "?")))
61 $cleanUrl = mb_substr($cleanUrl, 0, $qMarkPos);
62
63 return $cleanUrl;
64 }
65
66 public function GetByUrl($url)
67 {
68 $this->LoadToCache();
69
70 if(!is_array($this->arList))
71 return false;
72
73 $url = $this->CleanUrl($url);
74
75 $arRet = false;
76 foreach ($this->arList as $arCode)
77 {
78 $codeUrl = $this->CleanUrl($arCode["URL"]);
79
80 if(($codeUrl == mb_substr($url, 0, mb_strlen($codeUrl)) && $codeUrl) || (!$arCode["CLASS_NAME"] && (!$arCode["URL"] || $arCode["URL"] == "*")))
81 $arRet[] = $arCode;
82 }
83
84 return $arRet;
85 }
86
87 public function GetIDByTitleObj($strTitleObj)
88 {
89 static $codes = null;
90 if($strTitleObj)
91 {
92 if($codes === null)
93 {
94 $this->LoadToCache();
95 $codes = array();
96 if(is_array($this->arList))
97 {
98 foreach($this->arList as $arCode)
99 {
100 $codes[$arCode["TITLE_OBJ"]] = $arCode["ID"];
101 }
102 }
103 }
104
105 if(isset($codes[$strTitleObj]))
106 {
107 return $codes[$strTitleObj];
108 }
109 }
110
111 return false;
112 }
113
114 protected function CheckFields($arFields, $ID = false)
115 {
116 global $APPLICATION;
117
118 $aMsg = array();
119
120 if(isset($arFields["CODE"]))
121 {
122 if(!$arFields["CODE"])
123 $aMsg[] = array("id"=>"CODE", "text"=>GetMessage("HK_CF_CODE"));
124
125 if(preg_match("#<\\s*/*\\s*script(.*?)*>#i", $arFields["CODE"]))
126 $aMsg[] = array("id"=>"CODE", "text"=>GetMessage("HK_CF_SCRIPT"));
127 }
128
129 if(isset($arFields["NAME"]))
130 if(!$arFields["NAME"])
131 $aMsg[] = array("id"=>"NAME", "text"=>GetMessage("HK_CF_NAME"));
132
133 //if ADD
134 if(!$ID)
135 {
136 if(!isset($arFields["CODE"]))
137 $aMsg[] = array("id"=>"CODE", "text"=>GetMessage("HK_CF_CODE"));
138
139 if(!isset($arFields["NAME"]))
140 $aMsg[] = array("id"=>"NAME", "text"=>GetMessage("HK_CF_NAME"));
141
142 }
143
144 $arCond = array();
145
146 if(isset($arFields["CLASS_NAME"]))
147 $arCond["CLASS_NAME"] = $arFields["CLASS_NAME"];
148
149 if(isset($arFields['NAME']))
150 $arCond['NAME'] = $arFields['NAME'];
151
152 if(isset($arFields["CODE"]))
153 $arCond["CODE"] = $arFields["CODE"];
154
155 if(!empty($arCond))
156 {
157 $res = $this->GetList(array(), $arCond);
158 $code = $res->Fetch();
159
160 if($code)
161 {
162 if($ID)
163 {
164 if($code['ID'] != $ID)
165 $aMsg[] = array("id"=>"CLASS_NAME", "text"=>GetMessage("HK_CF_HK_CLASS_NAME"));
166
167 }
168 else
169 {
170 $aMsg[] = array("id"=>"CLASS_NAME", "text"=>GetMessage("HK_CF_HK_CLASS_NAME"));
171 }
172 }
173 }
174
175 if(!empty($aMsg))
176 {
177 $e = new CAdminException($aMsg);
178 $APPLICATION->ThrowException($e);
179 return false;
180 }
181
182
183 return true;
184 }
185
186 protected function LoadToCache()
187 {
188 global $CACHE_MANAGER;
189
190 if(!is_array($this->arList))
191 {
192 if($CACHE_MANAGER->Read($this->hkCacheTtl, "b_hot_keys_code".LANGUAGE_ID))
193 {
194 $this->arList = $CACHE_MANAGER->Get("b_hot_keys_code".LANGUAGE_ID);
195 }
196 else
197 {
198 $res = $this->GetList();
199 while($arTemp = $res->Fetch())
200 {
201 if(!$arTemp["IS_CUSTOM"])
202 {
203 if(isset($arTemp["NAME"]) && $arTemp["NAME"] != "-=AUTONAME=-")
204 $arTemp["NAME"] = GetMessage($arTemp["NAME"]);
205
206 if(isset($arTemp["COMMENTS"]))
207 $arTemp["COMMENTS"] = GetMessage($arTemp["COMMENTS"]);
208 }
209
210 $this->arList[$arTemp["ID"]] = $arTemp;
211 }
212 $CACHE_MANAGER->Set("b_hot_keys_code".LANGUAGE_ID, $this->arList);
213 }
214 }
215 }
216
217 protected function CleanCache()
218 {
219 global $CACHE_MANAGER;
221
222 foreach($arLangs as $adminLang)
223 $CACHE_MANAGER->Clean("b_hot_keys_code".$adminLang["LID"]);
224
225 }
226
227 public function Delete($ID)
228 {
229 global $DB;
230
231 $this->CleanCache();
232
233 $strSql = "SELECT ID FROM b_hot_keys WHERE CODE_ID=".intval($ID);
234 $res = $DB->Query($strSql);
235
236 while($arHK = $res->Fetch())
237 CHotKeys::GetInstance()->Delete($arHK["ID"]);
238
239 $sql = "DELETE FROM b_hot_keys_code WHERE ID=".intval($ID);
240
241 return $DB->Query($sql);
242 }
243
244 public function Update($ID, $arFields)
245 {
246 if(!$this->CheckFields($arFields, $ID))
247 return false;
248
249 global $DB;
250
251 $this->CleanCache();
252
253 $strUpdate = $DB->PrepareUpdate("b_hot_keys_code", $arFields);
254
255 if($strUpdate != "")
256 {
257 $strSql = "UPDATE b_hot_keys_code SET ".$strUpdate." WHERE ID=".intval($ID); //." AND IS_CUSTOM <> 0"
258 if(!$DB->Query($strSql))
259 return false;
260 }
261 return true;
262 }
263
264 public function Add($arFields)
265 {
266 if(!$this->CheckFields($arFields))
267 return false;
268
269 global $DB;
270
271 $this->CleanCache();
272
273 return $DB->Add("b_hot_keys_code", $arFields);
274 }
275
276 public function GetList($aSort = array(), $arFilter = array(), $showEmptyName = true)
277 {
278 global $DB;
279 $arSqlSearch = array();
280 if (is_array($arFilter))
281 {
282 foreach ($arFilter as $key => $val)
283 {
284 if ((string)$val == '' || $val == "NOT_REF")
285 continue;
286 $key = mb_strtoupper($key);
287 switch($key)
288 {
289 case "ID":
290 $arSqlSearch[] = "C.ID=".intval($val);
291 break;
292 case "CLASS_NAME":
293 case "CODE":
294 case "NAME":
295 case "COMMENTS":
296 case "TITLE_OBJ":
297 case "URL":
298 case "IS_CUSTOM":
299 $arSqlSearch[] = GetFilterQuery("C.".$key, $val);
300 break;
301 }
302 }
303 }
304
305 if(!$showEmptyName)
306 $arSqlSearch[] = "C.NAME IS NOT NULL AND C.NAME<>'-=AUTONAME=-'";
307
308 $sOrder = "";
309 foreach($aSort as $key => $val)
310 {
311 $ord = (mb_strtoupper($val) <> "ASC"? "DESC":"ASC");
312 switch(mb_strtoupper($key))
313 {
314 case "ID":
315 $sOrder .= ", C.ID ".$ord;
316 break;
317 case "CLASS_NAME":
318 $sOrder .= ", C.CLASS_NAME ".$ord;
319 break;
320 case "CODE":
321 $sOrder .= ", C.CODE ".$ord;
322 break;
323 case "NAME":
324 $sOrder .= ", C.NAME ".$ord;
325 break;
326 case "COMMENTS":
327 $sOrder .= ", C.COMMENTS ".$ord;
328 break;
329 case "TITLE_OBJ":
330 $sOrder .= ", C.TITLE_OBJ ".$ord;
331 break;
332 case "URL":
333 $sOrder .= ", C.URL ".$ord;
334 break;
335 case "IS_CUSTOM":
336 $sOrder .= ", C.IS_CUSTOM ".$ord;
337 break;
338 }
339 }
340 if ($sOrder == '')
341 $sOrder = "NAME ASC";
342
343 $strSqlOrder = " ORDER BY ".trim($sOrder, ", ");
344 $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
345 $strSql = "
346 SELECT
347 C.*
348 FROM
349 b_hot_keys_code C
350 WHERE
351 ".$strSqlSearch."
352 ".$strSqlOrder;
353
354 $res = $DB->Query($strSql);
355 return $res;
356 }
357}
358
360{
362 protected static $codes;
364 protected static $instance;
365 protected static $optUse; //Global settings option
366 protected $hkCacheTtl = 3600;
367 protected $arList; //For Cache //private
368 protected $arServSymb = array(
369 8 => "Back Space",
370 9 => "Tab",
371 13 => "Enter",
372 16 => "Shift",
373 17 => "Ctrl",
374 18 => "Alt",
375 19 => "Pause",
376 20 => "Caps Lock",
377 27 => "ESC",
378 32 => "Space bar",
379 33 => "Page Up",
380 34 => "Page Down",
381 35 => "End",
382 36 => "Home",
383 37 => "Left",
384 38 => "Up",
385 39 => "Right",
386 40 => "Down",
387 45 => "Insert",
388 46 => "Delete",
389 96 => "0 (ext)",
390 97 => "1 (ext)",
391 98 => "2 (ext)",
392 99 => "3 (ext)",
393 100 => "4 (ext)",
394 101 => "5 (ext)",
395 102 => "6 (ext)",
396 105 => "9 (ext)",
397 106 => "* (ext)",
398 107 => "+ (ext)",
399 104 => "8 (ext)",
400 103 => "7 (ext)",
401 110 => ". (ext)",
402 111 => "/ (ext)",
403 112 => "F1",
404 113 => "F2",
405 114 => "F3",
406 115 => "F4",
407 116 => "F5",
408 117 => "F6",
409 118 => "F7",
410 119 => "F8",
411 120 => "F9",
412 121 => "F10",
413 122 => "F11",
414 123 => "F12",
415 144 => "Num Lock",
416 186 => ";",
417 188 => ",",
418 190 => ".",
419 191 => "/",
420 192 => "`",
421 219 => "[",
422 220 => "|",
423 221 => "]",
424 222 => "'",
425 189 => "-",
426 187 => "+",
427 145 => "Scrol Lock",
428 );
429
430 public static $ExpImpFileName;
431
432 private function __construct() { }
433 private function __clone() { }
434
435 public static function GetInstance()
436 {
437 if (!isset(self::$instance))
438 {
439 $c = __CLASS__;
440 self::$instance = new $c;
441 self::$codes = new CHotKeysCode;
442 self::$optUse = COption::GetOptionString('main', "use_hot_keys", "Y") == "Y";
443 self::$ExpImpFileName = "hk_export_" . ($_SERVER['HTTP_HOST'] ?? 'CLI') . ".srl";
444 if(self::$optUse)
445 {
446 self::$instance->LoadToCache();
447 }
448 }
449
450 return self::$instance;
451 }
452
453 protected function LoadToCache()
454 {
455 global $USER, $CACHE_MANAGER;
456
457 if(is_array($this->arList) || !self::$optUse)
458 return false;
459
460 if(isset(\Bitrix\Main\Application::getInstance()->getSession()["hasHotKeys"]) && !\Bitrix\Main\Application::getInstance()->getSession()["hasHotKeys"])
461 return false;
462
463 $uid = $USER->GetID();
464 $cacheId = static::getCacheId($uid);
465
466 if($CACHE_MANAGER->Read($this->hkCacheTtl, $cacheId))
467 {
468 $this->arList = $CACHE_MANAGER->Get($cacheId);
469 }
470 else
471 {
472 $res = $this->GetList(array(), array("USER_ID"=>$uid));
473
474 $this->CheckStickers();
475
476 while($arTemp = $res->Fetch())
477 $this->arList[$arTemp["ID"]] = $arTemp;
478 }
479
480 if(is_array($this->arList))
481 {
482 $CACHE_MANAGER->Set($cacheId, $this->arList);
483 \Bitrix\Main\Application::getInstance()->getSession()["hasHotKeys"] = true;
484 }
485 else //for the first user's login let's try to set default keys
486 {
487 if(!$this->IsDefaultOpt())
488 {
489 \Bitrix\Main\Application::getInstance()->getSession()["hasHotKeys"] = false;
490 return false;
491 }
492
493 $setDef = $this->SetDefault($uid);
494 $setNoDef = $this->SetNotDefaultOpt();
495
496 if(!$setDef || !$setNoDef)
497 {
498 \Bitrix\Main\Application::getInstance()->getSession()["hasHotKeys"] = false;
499 return false;
500 }
501
502 return $this->LoadToCache();
503 }
504
505 return true;
506 }
507
508 protected static function CleanCache($userId = null)
509 {
510 global $CACHE_MANAGER;
511
512 $CACHE_MANAGER->Clean(static::getCacheId($userId));
513
514 return true;
515 }
516
517 protected static function getCacheId($userId = null)
518 {
519 global $USER;
520
521 if ($userId === null)
522 {
523 $userId = $USER->GetID();
524 }
525 return "b_hot_keys" . $userId . LANGUAGE_ID;
526 }
527
528 protected function GetByCodeID($codeID)
529 {
530 if(!$codeID)
531 return false;
532
533 if(!is_array($this->arList))
534 return false;
535
536 foreach ($this->arList as $arHK)
537 if($arHK["CODE_ID"] == $codeID)
538 return $arHK;
539
540 return false;
541 }
542
543 public function GetUIDbyHID($hkID) //user id by hot-key id
544 {
545 $this->LoadToCache();
546
547 if(!is_array($this->arList))
548 return false;
549
550 foreach ($this->arList as $arHK)
551 if($arHK["ID"] == $hkID)
552 return $arHK["USER_ID"];
553
554 return false;
555 }
556
557 protected function GlueSelfToCode(&$arCode)
558 {
559 $found = false;
560
561 if(!is_array($arCode)) //|| !is_array($this->arList)
562 return false;
563
564 if (is_array($this->arList))
565 {
566 foreach ($this->arList as $arHK)
567 {
568 if($arCode["ID"] == $arHK["CODE_ID"])
569 {
570 $arCode["KEYS_STRING"] = $arHK["KEYS_STRING"];
571 $arCode["CODE_ID"] = $arHK["CODE_ID"];
572 $arCode["HK_ID"] = $arHK["ID"];
573 $found = true;
574 break;
575 }
576 }
577 }
578
579 if(!$found)
580 {
581 $arCode["KEYS_STRING"] = "";
582 $arCode["CODE_ID"] = $arCode["ID"];
583 $arCode["HK_ID"] = 0;
584 }
585
586 return $found;
587 }
588
589 public function GetCodeByClassName($className, $name = "", $code = "")
590 {
591 if(!self::$optUse)
592 return false;
593
594 $arCodes = self::$codes->GetCodeByClassName($className);
595
596 if(!is_array($arCodes))
597 return false;
598
599 foreach ($arCodes as &$arCode)
600 {
601 $this->GlueSelfToCode($arCode);
602
603 if($code) //TODO: work only for single code in each class
604 $arCode["CODE"] = $code;
605
606 if($name)
607 $arCode["NAME"] = $name;
608 }
609
610 return $arCodes;
611 }
612
613 public function GetCodeByUrl($url)
614 {
615 if(!self::$optUse)
616 return false;
617
618 $arCodes = self::$codes->GetByUrl($url);
619
620 if(!is_array($arCodes))
621 return false;
622
623 foreach ($arCodes as &$arCode)
624 $this->GlueSelfToCode($arCode);
625
626 return $arCodes;
627 }
628
629 public function GetTitle($strTitleObj, $forHint = false)
630 {
631 if(!self::$optUse)
632 return false;
633
634 $codeID = self::$codes->GetIDByTitleObj($strTitleObj);
635 $arHK = $this->GetByCodeID($codeID);
636 $space = ($forHint ? "&nbsp;" : " ");
637
638 if(is_array($arHK))
639 return " (".$space.htmlspecialcharsbx($this->ShowHKAsChar($arHK["KEYS_STRING"]), ENT_QUOTES).$space.") ";
640
641 return "";
642 }
643
644 //if obj has unique id = b_hot-keys_code.TITLE_OBJ
645 public function SetTitle($className, $forHint = false)
646 {
647 if(!self::$optUse)
648 return false;
649
650 $arCodes = self::$codes->GetCodeByClassName($className);
651
652 if(!is_array($arCodes))
653 return false;
654
655 $retHtml = "";
656
657 foreach ($arCodes as $arCode)
658 {
659 if(!$arCode["TITLE_OBJ"])
660 continue;
661
662 $arHK = $this->GetByCodeID($arCode["ID"]);
663 $space = ($forHint ? "&nbsp;" : " ");
664
665 if(!is_array($arHK))
666 continue;
667
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>";
669 }
670
671 return $retHtml;
672 }
673
674 public function PrintJSExecs($execs, $controlName = "", $scriptTags = true, $checkHK = false)
675 {
676 $retStr = "";
677
678 if(!is_array($execs))
679 return false;
680
681 $printName = ($controlName? $controlName."." : "");
682
683 foreach ($execs as $arExec)
684 {
685 if($arExec["CODE"])
686 $code = $printName.CUtil::JSEscape($arExec["CODE"]);
687 else
688 $code = "";
689
690 $retStr .= ' BXHotKeys.Add("'.htmlspecialcharsbx($arExec["KEYS_STRING"]).'", "'.$code.'", '.intval($arExec["CODE_ID"]).", '".strip_tags(addslashes($arExec["NAME"]),"<b>")."', ".intval($arExec["HK_ID"])."); ";
691 }
692
693 if($checkHK)
694 $retStr = ' if(window.BXHotKeys!==undefined) { '.$retStr.' } ';
695
696 if($scriptTags)
697 $retStr = '<script>'.$retStr.'</script>';
698
699 return $retStr;
700 }
701
702 //On Error Throws exception+message and return false
703 protected function CheckFields($arFields, $ID = false)
704 {
705 global $APPLICATION;
706
707 $aMsg = array();
708
709 if(isset($arFields["CODE_ID"]))
710 if(!$arFields["CODE_ID"])
711 $aMsg[] = array("id"=>"CODE_ID", "text"=>GetMessage("HK_CF_CODE_ID"));
712
713 if(isset($arFields["KEYS_STRING"]))
714 if(!$arFields["KEYS_STRING"] || !$this->CheckKeysString($arFields["KEYS_STRING"]))
715 $aMsg[] = array("id"=>"KEYS_STRING", "text"=>GetMessage("HK_CF_KEYS_STRING"));
716
717
718 //USER_ID+CODE_ID must be unique
719 $res = $this->GetList(array(), array("CODE_ID"=>$arFields["CODE_ID"], "USER_ID"=>$arFields["USER_ID"]));
720 $hotKeys = $res->Fetch();
721 if($ID)
722 {
723 if($hotKeys)
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"));
726
727 }
728 else
729 {
730 if($hotKeys)
731 $aMsg[] = array("id"=>"CODE_ID", "text"=>GetMessage("HK_CF_CODEUSER_UNIQ"));
732
733 if(!isset($arFields["CODE_ID"]))
734 $aMsg[] = array("id"=>"CODE_ID", "text"=>GetMessage("HK_CF_CODE_ID"));
735
736 if(!isset($arFields["KEYS_STRING"]))
737 $aMsg[] = array("id"=>"KEYS_STRING", "text"=>GetMessage("HK_CF_KEYS_STRING"));
738 }
739
740
741 if(!empty($aMsg))
742 {
743 $e = new CAdminException($aMsg);
744 $APPLICATION->ThrowException($e);
745 return false;
746 }
747
748 return true;
749 }
750
751 public function GetList($aSort = array(), $arFilter = array())
752 {
753 global $DB;
754 $arSqlSearch = array();
755 if (is_array($arFilter))
756 {
757 foreach ($arFilter as $key => $val)
758 {
759 if ((string)$val == '' || $val == "NOT_REF")
760 continue;
761 $key = mb_strtoupper($key);
762 switch($key)
763 {
764 case "ID":
765 case "CODE_ID":
766 case "USER_ID":
767 $arSqlSearch[] = $key."=".intval($val);
768 break;
769 case "KEYS_STRING":
770 $arSqlSearch[] = GetFilterQuery("KEYS_STRING", $val);
771 break;
772 }
773 }
774 }
775
776 $sOrder = "";
777 foreach($aSort as $key => $val)
778 {
779 $ord = (mb_strtoupper($val) <> "ASC"? "DESC":"ASC");
780 switch(mb_strtoupper($key))
781 {
782 case "ID":
783 $sOrder .= ", ID ".$ord;
784 break;
785 case "KEYS_STRING":
786 $sOrder .= ", KEYS_STRING ".$ord;
787 break;
788 case "CODE_ID":
789 $sOrder .= ", CODE_ID ".$ord;
790 break;
791 case "USER_ID":
792 $sOrder .= ", USER_ID ".$ord;
793 break;
794 }
795 }
796
797 if ($sOrder <> '')
798 $strSqlOrder = " ORDER BY ".trim($sOrder, ", ");
799 else
800 $strSqlOrder = "";
801
802 $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
803 $strSql = "
804 SELECT
805 *
806 FROM
807 b_hot_keys
808 WHERE
809 ".$strSqlSearch."
810 ".$strSqlOrder;
811 $res = $DB->Query($strSql);
812 return $res;
813 }
814
815 public function Add($arFields)
816 {
817 if(!$this->CheckFields($arFields))
818 return false;
819
820 global $DB;
821
822 $arPrepFields = array(
823 "KEYS_STRING" => $arFields["KEYS_STRING"],
824 "CODE_ID" => intval($arFields["CODE_ID"]),
825 "USER_ID" => intval($arFields["USER_ID"]),
826 );
827
828 $result = $DB->Add("b_hot_keys", $arPrepFields);
829
830 unset(\Bitrix\Main\Application::getInstance()->getSession()["hasHotKeys"]);
831 static::CleanCache();
832
833 return $result;
834 }
835
836 public function Update($ID, $arFields)
837 {
838 if(!$this->CheckFields($arFields, $ID))
839 return false;
840
841 global $DB;
842
843 $strUpdate = $DB->PrepareUpdate("b_hot_keys", $arFields);
844
845 if($strUpdate != "")
846 {
847 $strSql = "UPDATE b_hot_keys SET ".$strUpdate." WHERE ID=".intval($ID);
848 if(!$DB->Query($strSql))
849 return false;
850
851 unset(\Bitrix\Main\Application::getInstance()->getSession()["hasHotKeys"]);
852 static::CleanCache();
853 }
854 return true;
855 }
856
857 public function Delete($ID)
858 {
859 global $DB;
860
861 $sql = "DELETE FROM b_hot_keys WHERE ID=".intval($ID);
862 $res = $DB->Query($sql);
863
864 unset(\Bitrix\Main\Application::getInstance()->getSession()["hasHotKeys"]);
865 static::CleanCache();
866
867 return $res->AffectedRowsCount();
868 }
869
870 public static function DeleteByUser($USER_ID)
871 {
872 global $DB;
873
874 $sql = 'DELETE FROM b_hot_keys WHERE USER_ID = ' . intval($USER_ID);
875 $res = $DB->Query($sql);
876
877 static::CleanCache($USER_ID);
878
879 return $res->AffectedRowsCount();
880 }
881
882 public static function CleanUp($USER_ID = 0)
883 {
884 global $DB;
885
886 $etime = microtime(1) + 1; //1 sec
887 do
888 {
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'])
892 {
893 return '';
894 }
895
897 [
898 'filter' => [
899 '=ID' => $next_user['MIN_USER_ID'],
900 ],
901 'select' => ['ID'],
902 ]
903 );
904 if (!$res->fetch())
905 {
906 $DB->Query('DELETE FROM b_hot_keys WHERE USER_ID = ' . $next_user['MIN_USER_ID']);
907 static::CleanCache($next_user['MIN_USER_ID']);
908 }
909 }
910 while (microtime(1) < $etime);
911
912 return 'CHotKeys::CleanUp(' . $next_user['MIN_USER_ID'] . ');';
913 }
914
915 //sets (copy) keys_strings from user with id=0 to userID
916 public function SetDefault($userID)
917 {
918 global $DB;
919
920 $uid = intval($userID);
921
922 unset(\Bitrix\Main\Application::getInstance()->getSession()["hasHotKeys"]);
923
924 $sql = "DELETE FROM b_hot_keys WHERE USER_ID=".$uid;
925 $delRes = $DB->Query($sql);
926
927 $listRes = $this->GetList(array(), array("USER_ID"=>"0"));
928
929 $insErr = false;
930 while($arHK = $listRes->Fetch())
931 {
932 $arPrepFields = array(
933 "KEYS_STRING" => $arHK["KEYS_STRING"],
934 "CODE_ID" => $arHK["CODE_ID"],
935 "USER_ID" => $uid,
936 );
937
938 $insRes = $DB->Add("b_hot_keys",$arPrepFields);
939
940 if(!$insRes)
941 $insErr = true;
942 }
943
944 return ($delRes && !$insErr);
945 }
946
947 public function ShowHKAsChar($hotKeysString)
948 {
949 if(!$this->CheckKeysString($hotKeysString))
950 return GetMessage("HK_WRONG_KS");
951
952 $lastPlusPos = mb_strrpos($hotKeysString, "+");
953
954 if($lastPlusPos)
955 {
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);
960 }
961 else
962 {
963 $charCode = $hotKeysString;
964 $preChar = "";
965 }
966
967 if(intval($charCode)<256)
968 {
969 if(!($codeSymb = ($this->arServSymb[intval($charCode)] ?? 0)))
970 $codeSymb = chr($charCode);
971 }
972 else
973 {
974 $codeSymb = html_entity_decode("&#".$charCode.";", ENT_NOQUOTES,LANG_CHARSET);
975 }
976
977 return $preChar.$codeSymb;
978 }
979
980 protected function CheckKeysString($keysString)
981 {
982 $keyCode = str_replace(array("ctrl", "alt", "shift", "+"), "", mb_strtolower($keysString));
983 return !(strcmp(intval($keyCode), $keyCode));
984 }
985
986 public function PrintPhpToJSVars()
987 {
988 if(!self::$optUse)
989 return false;
990
991 global $USER;
992 $htmlOut = "<script>
993 BXHotKeys.MesNotAssign = '".GetMessageJS("HK_NOT_ASSIGN")."';
994 BXHotKeys.MesClToChange = '".GetMessageJS("HK_CLICK_TO_CHANGE")."';
995 BXHotKeys.MesClean = '".GetMessageJS("HK_CLEAN")."';
996 BXHotKeys.MesBusy = '".GetMessageJS("HK_BUSY")."';
997 BXHotKeys.MesClose = '".GetMessageJS("HK_CLOSE")."';
998 BXHotKeys.MesSave = '".GetMessageJS("HK_SAVE")."';
999 BXHotKeys.MesSettings = '".GetMessageJS("HK_SETTINGS")."';
1000 BXHotKeys.MesDefault = '".GetMessageJS("HK_DEFAULT")."';
1001 BXHotKeys.MesDelAll = '".GetMessageJS("HK_DELALL")."';
1002 BXHotKeys.MesDelConfirm = '".GetMessageJS("HK_DEL_CONFIRM")."';
1003 BXHotKeys.MesDefaultConfirm = '".GetMessageJS("HK_DEFAULT_CONFIRM")."';
1004 BXHotKeys.MesExport = '".GetMessageJS("HK_EXPORT")."';
1005 BXHotKeys.MesImport = '".GetMessageJS("HK_IMPORT")."';
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")."';
1011 BXHotKeys.MesDelete = '".GetMessageJS("HK_DELETE")."';
1012 BXHotKeys.MesChooseFile = '".GetMessageJS("HK_CHOOSE_FILE")."';
1013 BXHotKeys.uid = ".$USER->GetID().";
1014 </script>";
1015 return $htmlOut;
1016 }
1017
1018 public function IsActive()
1019 {
1020 return self::$optUse;
1021 }
1022
1023 // Top panel buttons
1024 public function PrintTPButton(&$arPanelButton, $parent = "")
1025 {
1026 if(!self::$optUse)
1027 return false;
1028
1029 $retJS = "";
1030 $hkCode = "";
1031
1032 if(isset($arPanelButton["LINK"]))
1033 $hkCode = "location.href='".$arPanelButton["LINK"]."'";
1034
1035 if(isset($arPanelButton["ACTION"]))
1036 $hkCode = $arPanelButton["ACTION"];
1037
1038 if(isset($arPanelButton["ALT"]))
1039 $arPanelButton["ALT"] = $arPanelButton["ALT"].(isset($arPanelButton["HK_ID"])? $this->GetTitle($arPanelButton["HK_ID"]): "");
1040
1041 if(isset($arPanelButton["TITLE"]))
1042 $arPanelButton["TITLE"] = $arPanelButton["TITLE"].(isset($arPanelButton["HK_ID"])? $this->GetTitle($arPanelButton["HK_ID"]): "");
1043
1044 if(isset($arPanelButton["HK_ID"]))
1045 {
1046 $name = str_replace(array("#BR#", "&nbsp;"), array(" ", ""), $arPanelButton["TEXT"]);
1047
1048 if ($parent != "")
1049 {
1050 $name = $parent.$name;
1051 }
1052 elseif (isset($arPanelButton["MENU"]) && $arPanelButton["MENU"])
1053 {
1054 $name = "<b>".$name."</b>";
1055 }
1056
1057 $Execs = $this->GetCodeByClassName($arPanelButton["HK_ID"], $name, $hkCode);
1058 $retJS .= $this->PrintJSExecs($Execs);
1059 }
1060
1061 if (isset($arPanelButton["MENU"]) && is_array($arPanelButton["MENU"]))
1062 {
1063 foreach ($arPanelButton["MENU"] as &$menu)
1064 $retJS .= $this->PrintTPButton($menu, $parent."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
1065 }
1066
1067 return $retJS;
1068 }
1069
1070 protected function IsDefaultOpt()
1071 {
1072 return
1073 CUserOptions::GetOption("hot_keys", "user_defined", "a") === "a"
1074 && CUserOptions::GetOption("hot_keys", "user_defined", "b") === "b"
1075 ;
1076 }
1077
1078 protected function SetNotDefaultOpt()
1079 {
1080 CUserOptions::SetOption("hot_keys", "user_defined", true);
1081 return true;
1082 }
1083
1084 //for old stickers hotkeys compability
1085 protected function CheckStickers()
1086 {
1087 global $DB;
1088
1089 if(COption::GetOptionString("fileman", "stickers_use_hotkeys", "Y") != "Y")
1090 return false;
1091
1092 $strSql = "SELECT ID FROM b_hot_keys WHERE USER_ID=0 AND ( CODE_ID=87 OR CODE_ID=88 OR CODE_ID=89)";
1093 $res = $DB->Query($strSql);
1094
1095 if(!$res->Fetch())
1096 {
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));
1100 }
1101
1102 return COption::SetOptionString("fileman", "stickers_use_hotkeys", "N");
1103 }
1104
1105 public function PrintGlobalUrlVar()
1106 {
1107
1108 if(!$GLOBALS["APPLICATION"]->PanelShowed)
1109 return "";
1110
1111 $Execs = $this->GetCodeByClassName("Global");
1112 $out = $this->PrintJSExecs($Execs);
1113
1114 $Execs = $this->GetCodeByUrl($_SERVER["REQUEST_URI"]);
1115 $out .= $this->PrintJSExecs($Execs);
1116
1117 $out .= $this->PrintPhpToJSVars();
1118
1119 return $out;
1120 }
1121
1130 public function AddDefaultKeyToAll($codeID, $keysString)
1131 {
1132 global $DB;
1133
1134 $res = self::$codes->GetByID($codeID);
1135
1136 if(!$res->Fetch())
1137 return false;
1138
1139 if(!$this->CheckKeysString($keysString))
1140 return false;
1141
1142 $exceptedUsers = array();
1143 $res = $this->GetList();
1144
1145 //user can alredy using this hot-keys combination
1146 while($hotKey = $res->Fetch())
1147 if($hotKey["KEYS_STRING"] == $keysString)
1148 $exceptedUsers[] = $hotKey["USER_ID"];
1149
1150 //we could alredy attempted to add this keys
1151 if(!empty($exceptedUsers))
1152 if(in_array(0, $exceptedUsers))
1153 return false;
1154
1155 //all users wich using hot-keys
1156 $strSql = "SELECT DISTINCT USER_ID FROM b_hot_keys";
1157 $res = $DB->Query($strSql);
1158
1159 $added = 0;
1160
1161 while($hkUsers = $res->Fetch())
1162 {
1163 if(!empty($exceptedUsers))
1164 if(in_array($hkUsers['USER_ID'], $exceptedUsers))
1165 continue;
1166
1167 $this->Add (array("KEYS_STRING"=>$keysString, "CODE_ID"=>$codeID, "USER_ID"=>$hkUsers['USER_ID']));
1168 $added++;
1169 }
1170
1171 return $added;
1172 }
1173
1178 public function Export()
1179 {
1180 $this->LoadToCache();
1181
1182 if(!is_array($this->arList) || empty($this->arList))
1183 return false;
1184
1185 $arForExport = array();
1186 $tmpDir = CTempFile::GetDirectoryName();
1187 CheckDirPath($tmpDir);
1188 $tmpExportFile = $tmpDir.self::$ExpImpFileName;
1189
1190 foreach ($this->arList as $arHK)
1191 {
1192 $res = self::$codes->GetByID($arHK['CODE_ID']);
1193 $arTmpCode = $res->Fetch();
1194
1195 if(!is_array($arTmpCode) || empty($arTmpCode))
1196 continue;
1197
1198 $arTmpLink = array(
1199 'KEYS_STRING' => $arHK['KEYS_STRING'],
1200 'CLASS_NAME' => $arTmpCode['CLASS_NAME'],
1201 'NAME' => $arTmpCode['NAME'],
1202 'IS_CUSTOM' => $arTmpCode['IS_CUSTOM'],
1203 );
1204
1205 if($arTmpCode['IS_CUSTOM'])
1206 {
1207 $arTmpLink['CODE'] = $arTmpCode['CODE'];
1208 $arTmpLink['COMMENTS'] = $arTmpCode['COMMENTS'];
1209 $arTmpLink['URL'] = $arTmpCode['URL'];
1210 }
1211
1212 $arForExport[] = $arTmpLink;
1213 }
1214
1215 $result = file_put_contents($tmpExportFile, serialize($arForExport));
1216
1217 if($result === false)
1218 return false;
1219
1220 return $tmpExportFile;
1221 }
1222
1228 public function Import($fileName, $userID)
1229 {
1230 $fileContent = file_get_contents($fileName);
1231
1232 if(!$fileContent)
1233 return false;
1234
1235 $arInput = null;
1237 $arInput = unserialize($fileContent, ['allowed_classes' => false]);
1238
1239 if(!is_array($arInput) || empty($arInput))
1240 return false;
1241
1242 $added = 0;
1243
1244 foreach ($arInput as $arHotKey)
1245 {
1246 $codeID = false;
1247 if(!isset($arHotKey['IS_CUSTOM']) || !isset($arHotKey['KEYS_STRING']) || !isset($arHotKey['NAME']) || !$this->CheckKeysString($arHotKey['KEYS_STRING']))
1248 continue;
1249 //if custom code
1250 if($arHotKey['IS_CUSTOM'])
1251 {
1252 if(!isset($arHotKey['CODE']))
1253 continue;
1254
1255 $resCodes = self::$codes->GetList(array(), array(
1256 'CLASS_NAME' => $arHotKey['CLASS_NAME'] ?? '',
1257 'NAME' => $arHotKey['NAME'],
1258 'CODE' => $arHotKey['CODE'],
1259 ));
1260 $arCode = $resCodes->Fetch();
1261 //if same code alredy exist
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'],
1270 ));
1271 }
1272 else //if system code
1273 {
1274 $resCodes = self::$codes->GetList(array(), array(
1275 'CLASS_NAME' => $arHotKey['CLASS_NAME'] ?? '',
1276 'NAME' => $arHotKey['NAME'],
1277 ));
1278 $arCode = $resCodes->Fetch();
1279
1280 if(isset($arCode['ID']))
1281 $codeID = $arCode['ID'];
1282 }
1283
1284 if(!$codeID)
1285 continue;
1286
1287 $resHK = $this->GetList(array(), array(
1288 "CODE_ID" => $codeID,
1289 "USER_ID" => intval($userID),
1290 ));
1291 $arHK = $resHK->Fetch();
1292
1293 //if this code alredy binding to some keys for this user
1294 if($arHK)
1295 {
1296 $hkID = $arHK['ID'];
1297 $this->Update( $hkID, array(
1298 "KEYS_STRING" => $arHotKey["KEYS_STRING"],
1299 "CODE_ID" => $codeID,
1300 "USER_ID" => intval($userID),
1301 ));
1302 }
1303 else
1304 {
1305 $hkID = $this->Add( array(
1306 "KEYS_STRING" => $arHotKey["KEYS_STRING"],
1307 "CODE_ID" => $codeID,
1308 "USER_ID" => intval($userID),
1309 ));
1310 }
1311
1312 if($hkID)
1313 $added++;
1314 }
1315
1316 return $added;
1317 }
1318}
global $APPLICATION
Определения include.php:80
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getInstance()
Определения application.php:98
static getList(array $parameters=array())
Определения datamanager.php:431
static GetLangSwitcherArray()
Определения language.php:308
Определения hot_keys.php:12
Delete($ID)
Определения hot_keys.php:227
CheckFields($arFields, $ID=false)
Определения hot_keys.php:114
CleanUrl($url)
Определения hot_keys.php:49
GetByID($ID)
Определения hot_keys.php:16
GetList($aSort=array(), $arFilter=array(), $showEmptyName=true)
Определения hot_keys.php:276
CleanCache()
Определения hot_keys.php:217
LoadToCache()
Определения hot_keys.php:186
GetCodeByClassName($className)
Определения hot_keys.php:21
GetByUrl($url)
Определения hot_keys.php:66
GetIDByTitleObj($strTitleObj)
Определения hot_keys.php:87
$arList
Определения hot_keys.php:13
$hkCacheTtl
Определения hot_keys.php:14
Add($arFields)
Определения hot_keys.php:264
Update($ID, $arFields)
Определения hot_keys.php:244
Определения hot_keys.php:360
Delete($ID)
Определения hot_keys.php:857
CheckFields($arFields, $ID=false)
Определения hot_keys.php:703
GetCodeByUrl($url)
Определения hot_keys.php:613
static $optUse
Определения hot_keys.php:365
static getCacheId($userId=null)
Определения hot_keys.php:517
SetDefault($userID)
Определения hot_keys.php:916
static CleanUp($USER_ID=0)
Определения hot_keys.php:882
GetUIDbyHID($hkID)
Определения hot_keys.php:543
static GetInstance()
Определения hot_keys.php:435
SetNotDefaultOpt()
Определения hot_keys.php:1078
PrintPhpToJSVars()
Определения hot_keys.php:986
PrintJSExecs($execs, $controlName="", $scriptTags=true, $checkHK=false)
Определения hot_keys.php:674
LoadToCache()
Определения hot_keys.php:453
GlueSelfToCode(&$arCode)
Определения hot_keys.php:557
static $ExpImpFileName
Определения hot_keys.php:430
GetList($aSort=array(), $arFilter=array())
Определения hot_keys.php:751
Export()
Определения hot_keys.php:1178
static $codes
Определения hot_keys.php:362
GetTitle($strTitleObj, $forHint=false)
Определения hot_keys.php:629
PrintGlobalUrlVar()
Определения hot_keys.php:1105
CheckKeysString($keysString)
Определения hot_keys.php:980
CheckStickers()
Определения hot_keys.php:1085
PrintTPButton(&$arPanelButton, $parent="")
Определения hot_keys.php:1024
ShowHKAsChar($hotKeysString)
Определения hot_keys.php:947
static CleanCache($userId=null)
Определения hot_keys.php:508
static DeleteByUser($USER_ID)
Определения hot_keys.php:870
SetTitle($className, $forHint=false)
Определения hot_keys.php:645
AddDefaultKeyToAll($codeID, $keysString)
Определения hot_keys.php:1130
Import($fileName, $userID)
Определения hot_keys.php:1228
GetByCodeID($codeID)
Определения hot_keys.php:528
$arList
Определения hot_keys.php:367
static $instance
Определения hot_keys.php:364
$hkCacheTtl
Определения hot_keys.php:366
IsDefaultOpt()
Определения hot_keys.php:1070
Add($arFields)
Определения hot_keys.php:815
GetCodeByClassName($className, $name="", $code="")
Определения hot_keys.php:589
$arServSymb
Определения hot_keys.php:368
IsActive()
Определения hot_keys.php:1018
Update($ID, $arFields)
Определения hot_keys.php:836
global $CACHE_MANAGER
Определения clear_component_cache.php:7
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$fileContent
Определения file_property.php:47
$res
Определения filter_act.php:7
GetFilterSqlSearch($arSqlSearch=array(), $FilterLogic="FILTER_logic")
Определения filter_tools.php:397
GetFilterQuery($field, $val, $procent="Y", $ex_sep=array(), $clob="N", $div_fields="Y", $clob_upper="N")
Определения filter_tools.php:383
$result
Определения get_property_values.php:14
if($ajaxMode) $ID
Определения get_user.php:27
$uid
Определения hot_keys_act.php:8
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
const LANG_CHARSET
Определения include.php:65
$arCodes
Определения options.php:154
CheckSerializedData($str, $max_depth=200)
Определения tools.php:4949
CheckDirPath($path)
Определения tools.php:2707
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
GetMessageJS($name, $aReplace=false)
Определения tools.php:3392
$name
Определения menu_edit.php:35
$arLangs
Определения prolog_auth_admin.php:31
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$fileName
Определения quickway.php:305
if(empty($signedUserToken)) $key
Определения quickway.php:257
$val
Определения options.php:1793
$GLOBALS['_____370096793']
Определения update_client.php:1
$arFilter
Определения user_search.php:106
$url
Определения iframe.php:7