diff options
| author | 2019-04-02 00:08:51 +0200 | |
|---|---|---|
| committer | 2019-04-02 00:08:51 +0200 | |
| commit | d9e246ecf763eb592f8246d4e9431a80599248e3 (patch) | |
| tree | 9148f8b9989a9addfae605fdddb2e9102cf047f1 | |
| parent | 0853cab2c46e2a38ce2f820a882dc0805be85ab8 (diff) | |
Shortcuts legacy (#2320)
Fix https://github.com/FreshRSS/FreshRSS/issues/2316
| -rwxr-xr-x | app/Controllers/configureController.php | 24 | ||||
| -rw-r--r-- | app/views/helpers/javascript_vars.phtml | 2 | ||||
| -rw-r--r-- | lib/lib_rss.php | 36 |
3 files changed, 42 insertions, 20 deletions
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index 9c3900f39..16dd82121 100755 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -166,30 +166,16 @@ class FreshRSS_configure_Controller extends Minz_ActionController { * tab and up. */ public function shortcutAction() { - $list_keys = array('a', 'b', 'backspace', 'c', 'd', 'delete', 'down', 'e', 'end', 'enter', - 'escape', 'f', 'g', 'h', 'home', 'i', 'insert', 'j', 'k', 'l', 'left', - 'm', 'n', 'o', 'p', 'page_down', 'page_up', 'q', 'r', 'return', 'right', - 's', 'space', 't', 'tab', 'u', 'up', 'v', 'w', 'x', 'y', - 'z', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', - 'f10', 'f11', 'f12', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'); - $this->view->list_keys = $list_keys; + $this->view->list_keys = SHORTCUT_KEYS; if (Minz_Request::isPost()) { - $shortcuts = Minz_Request::param('shortcuts'); - $shortcuts_ok = array(); - - foreach ($shortcuts as $key => $value) { - if (in_array($value, $list_keys)) { - $shortcuts_ok[$key] = $value; - } - } - - FreshRSS_Context::$user_conf->shortcuts = $shortcuts_ok; + FreshRSS_Context::$user_conf->shortcuts = validateShortcutList(Minz_Request::param('shortcuts')); FreshRSS_Context::$user_conf->save(); invalidateHttpCache(); - Minz_Request::good(_t('feedback.conf.shortcuts_updated'), - array('c' => 'configure', 'a' => 'shortcut')); + Minz_Request::good(_t('feedback.conf.shortcuts_updated'), array('c' => 'configure', 'a' => 'shortcut')); + } else { + FreshRSS_Context::$user_conf->shortcuts = validateShortcutList(FreshRSS_Context::$user_conf->shortcuts); } Minz_View::prependTitle(_t('conf.shortcut.title') . ' ยท '); diff --git a/app/views/helpers/javascript_vars.phtml b/app/views/helpers/javascript_vars.phtml index b62263ecf..52489c5c3 100644 --- a/app/views/helpers/javascript_vars.phtml +++ b/app/views/helpers/javascript_vars.phtml @@ -1,6 +1,6 @@ <?php $mark = FreshRSS_Context::$user_conf->mark_when; -$s = FreshRSS_Context::$user_conf->shortcuts; +$s = validateShortcutList(FreshRSS_Context::$user_conf->shortcuts); echo htmlspecialchars(json_encode(array( 'context' => array( 'anonymous' => !FreshRSS_Auth::hasAccess(), diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 3e0033a61..00b38254a 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -544,3 +544,39 @@ function base64url_decode($data) { function _i($icon, $url_only = false) { return FreshRSS_Themes::icon($icon, $url_only); } + + +const SHORTCUT_KEYS = array( + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', + 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'Backspace', 'Delete', + 'End', 'Enter', 'Escape', 'Home', 'Insert', 'PageDown', 'PageUp', 'Space', 'Tab', + ); + +function validateShortcutList($shortcuts) { + $legacy = array( + 'down' => 'ArrowDown', 'left' => 'ArrowLeft', 'page_down' => 'PageDown', 'page_up' => 'PageUp', + 'right' => 'ArrowRight', 'up' => 'ArrowUp', + ); + $upper = null; + $shortcuts_ok = array(); + + foreach ($shortcuts as $key => $value) { + if (in_array($value, SHORTCUT_KEYS)) { + $shortcuts_ok[$key] = $value; + } elseif (isset($legacy[$value])) { + $shortcuts_ok[$key] = $legacy[$value]; + } else { //Case-insensitive search + if ($upper === null) { + $upper = array_map('strtoupper', SHORTCUT_KEYS); + } + $i = array_search(strtoupper($value), $upper); + if ($i !== false) { + $shortcuts_ok[$key] = SHORTCUT_KEYS[$i]; + } + } + } + return $shortcuts_ok; +} |
