From 3b89cea776890ddb0b0204bc9b4516d1be8af2f9 Mon Sep 17 00:00:00 2001 From: eferdi Date: Thu, 5 Sep 2013 01:52:27 +0200 Subject: [PATCH] Add support for keyboard navigation with shortcuts --- picturelicious.sql | 1 + picturelicious/lib/users.php | 20 ++++++++++++++------ picturelicious/media/shortcuts.js.php | 17 +++++++++++++++++ picturelicious/templates/header.tpl.php | 1 + picturelicious/templates/profile.tpl.php | 8 +++++++- 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 picturelicious/media/shortcuts.js.php diff --git a/picturelicious.sql b/picturelicious.sql index 391eb3d..065160d 100644 --- a/picturelicious.sql +++ b/picturelicious.sql @@ -80,6 +80,7 @@ CREATE TABLE `pl_users` ( `images` int(11) NOT NULL default '0', `avatar` varchar(255) collate utf8_unicode_ci NOT NULL, `website` varchar(255) collate utf8_unicode_ci NOT NULL, + `activateShortcuts` tinyint(1) NOT NULL default '0', `email` varchar(255) collate utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/picturelicious/lib/users.php b/picturelicious/lib/users.php index 5d4e3e7..205661a 100644 --- a/picturelicious/lib/users.php +++ b/picturelicious/lib/users.php @@ -15,6 +15,7 @@ class User { public $id = 0; public $validationString = ''; public $admin = 0; + public $activateShortcuts = false; public $website = 0; public function __construct() { @@ -22,7 +23,7 @@ class User { public function validate( $id ) { $u = DB::getRow( - 'SELECT id, name, admin, website FROM '.TABLE_USERS.' WHERE valid = 0 AND remember = :1', + 'SELECT id, name, admin, website, activateShortcuts FROM '.TABLE_USERS.' WHERE valid = 0 AND remember = :1', $id ); @@ -38,7 +39,8 @@ class User { $_SESSION['name'] = $this->name = $u['name']; $_SESSION['admin'] = $this->admin = $u['admin']; $_SESSION['website'] = $this->website = $u['website']; - + $_SESSION['activateShortcuts'] = $this->activateShortcuts = $u['activateShortcuts']; + setcookie( Config::$rememberCookie, $id, time() + 3600 * 24 * 365, Config::$absolutePath ); if( Config::$vbbIntegration['enabled'] ) { @@ -78,7 +80,7 @@ class User { if( isset($_POST['login']) ) { // post login $u = DB::getRow( - 'SELECT id, name, admin, website FROM '.TABLE_USERS.' WHERE name = :1 AND pass = :2 and valid = 1', + 'SELECT id, name, admin, website, activateShortcuts FROM '.TABLE_USERS.' WHERE name = :1 AND pass = :2 and valid = 1', $_POST['name'], md5($_POST['pass']) ); if( !empty($u) ) { @@ -87,6 +89,7 @@ class User { $_SESSION['name'] = $this->name = $u['name']; $_SESSION['admin'] = $this->admin = $u['admin']; $_SESSION['website'] = $this->website = $u['website']; + $_SESSION['activateShortcuts'] = $this->activateShortcuts = $u['activateShortcuts']; if( !empty($_POST['remember']) ) { $r = md5(uniqid(rand())); @@ -111,12 +114,13 @@ class User { $this->name = $_SESSION['name']; $this->admin = $_SESSION['admin']; $this->website = $_SESSION['website']; + $this->activateShortcuts = $_SESSION['activateShortcuts']; } } else if( !empty($_COOKIE[Config::$rememberCookie]) ) { // remember cookie found $u = DB::getRow( - 'SELECT id, name, admin, website FROM '.TABLE_USERS.' WHERE remember = :1', + 'SELECT id, name, admin, website, activateShortcuts FROM '.TABLE_USERS.' WHERE remember = :1', $_COOKIE[Config::$rememberCookie] ); if( !empty($u) ) { @@ -125,7 +129,8 @@ class User { $_SESSION['id'] = $this->id = $u['id']; $_SESSION['name'] = $this->name = $u['name']; $_SESSION['admin'] = $this->admin = $u['admin']; - $_SESSION['website'] = $this->website = $u['website']; + $_SESSION['website'] = $this->website = $u['website']; + $_SESSION['activateShortcuts'] = $this->activateShortcuts = $u['activateShortcuts']; // refresh for another year setcookie( Config::$rememberCookie, $_COOKIE[Config::$rememberCookie], time() + 3600 * 24 * 365, Config::$absolutePath ); @@ -140,9 +145,11 @@ class User { } public function profile( $localFile, &$messages ) { - $upd = array( 'website' => $_POST['website'] ); + $upd = array( 'website' => $_POST['website'], + 'activateShortcuts' => $_POST['activateShortcuts']); $_SESSION['website'] = $_POST['website']; + $_SESSION['activateShortcuts'] = $_POST['activateShortcuts']; if( Config::$vbbIntegration['enabled'] ) { global $vbulletin; @@ -262,6 +269,7 @@ class User { 'score' => 0, 'images' => 0, 'website' => '', + 'activateShortcuts' => 0, 'avatar' => Config::$images['avatarsPath'].'default.png', 'remember' => $this->validationString, 'admin' => 0, diff --git a/picturelicious/media/shortcuts.js.php b/picturelicious/media/shortcuts.js.php new file mode 100644 index 0000000..f4377f1 --- /dev/null +++ b/picturelicious/media/shortcuts.js.php @@ -0,0 +1,17 @@ + + +document.onkeydown=function(e){ + var keyCode = e.keyCode || e.which; + var arrow = {left: 37, up: 38, right: 39, down: 40 }; + + switch(keyCode){ + case arrow.left: + document.getElementById('prevBar').click(); + break; + case arrow.right: + document.getElementById('nextBar').click(); + break; + } +} diff --git a/picturelicious/templates/header.tpl.php b/picturelicious/templates/header.tpl.php index 7af6875..1920dd4 100644 --- a/picturelicious/templates/header.tpl.php +++ b/picturelicious/templates/header.tpl.php @@ -5,6 +5,7 @@ + id && $user->activateShortcuts ){ ?> diff --git a/picturelicious/templates/profile.tpl.php b/picturelicious/templates/profile.tpl.php index 25f51a3..a7965fb 100644 --- a/picturelicious/templates/profile.tpl.php +++ b/picturelicious/templates/profile.tpl.php @@ -17,7 +17,7 @@
-
Passwort:
+
Password:
(leave empty, if you don't want to change it)
@@ -41,6 +41,12 @@
+ +
Navigation:
+
+ activateShortcuts == 1 ) { echo ' checked="checked"'; } ?> /> + +
Avatar: