init.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. class Hotkeys_Ru extends Plugin {
  3. private $host;
  4. function about() {
  5. return array(1.0,
  6. "Mirrors English hotkey map into Russian keyboard layout",
  7. "fox");
  8. }
  9. function init($host) {
  10. $this->host = $host;
  11. $host->add_hook($host::HOOK_HOTKEY_MAP, $this);
  12. }
  13. private function mb_strtr($str, $from, $to) {
  14. $keys = [];
  15. $values = [];
  16. if (!is_array($from)) {
  17. preg_match_all('/./u', $from, $keys);
  18. preg_match_all('/./u', $to, $values);
  19. $mapping = array_combine($keys[0], $values[0]);
  20. } else {
  21. $mapping = $from;
  22. }
  23. return strtr($str, $mapping);
  24. }
  25. function hook_hotkey_map($hotkeys) {
  26. $local_map = [];
  27. foreach ($hotkeys as $k => $v) {
  28. if (strpos($k, "(") === FALSE) {
  29. $local_k = $this->mb_strtr($k, "`[email protected]#$%^&qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:\"|ZXCVBNM<>?",
  30. "ёЁ!\"№;%:?йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭ/ЯЧСМИТЬБЮ,");
  31. if ($local_k != $k)
  32. $local_map[$local_k] = $v;
  33. }
  34. }
  35. return array_merge($hotkeys, $local_map);
  36. }
  37. function api_version() {
  38. return 2;
  39. }
  40. }