Skip to content

Commit

Permalink
Merge pull request #727 from Flyspray/accesskeyhelp
Browse files Browse the repository at this point in the history
detect basic browser and platform at session start
  • Loading branch information
peterdd committed Jul 29, 2019
2 parents 9045676 + 72b77a3 commit f2aba30
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 37 deletions.
44 changes: 30 additions & 14 deletions includes/class.flyspray.php
Expand Up @@ -993,21 +993,37 @@ public static function setCookie($name, $val, $time = null, $path=null, $domain=
* @version 1.0
* @notes smile intented
*/
public static function startSession()
{
global $conf;
if (defined('IN_FEED') || php_sapi_name() === 'cli') {
return;
}
public static function startSession()
{
global $conf;
if (defined('IN_FEED') || php_sapi_name() === 'cli') {
return;
}

$url = parse_url($GLOBALS['baseurl']);
session_name('flyspray');
session_set_cookie_params(0,$url['path'],'', (isset($conf['general']['securecookies'])? $conf['general']['securecookies']:false), TRUE);
session_start();
if(!isset($_SESSION['csrftoken'])){
$_SESSION['csrftoken']=rand(); # lets start with one anti csrf token secret for the session and see if it's simplicity is good enough (I hope together with enforced Content Security Policies)
}
}
$url = parse_url($GLOBALS['baseurl']);
session_name('flyspray');
session_set_cookie_params(0,$url['path'],'', (isset($conf['general']['securecookies'])? $conf['general']['securecookies']:false), TRUE);
session_start();
if(!isset($_SESSION['csrftoken'])){
$_SESSION['csrftoken']=rand(); # lets start with one anti csrf token secret for the session and see if it's simplicity is good enough (I hope together with enforced Content Security Policies)
}

/**
* For the access key help: differences of browser and operating system combinations.
* As it is relative expensive and very slow below PHP 7.1.1:
* only do that once per user session and
* only on newer php versions and
* only if a browscap file is installed.
* lite_php_browscap.ini from browscap.org should be sufficient.
* (below 1ms on a linux with php7.3 in virtualbox on old laptop)
*/
if (!isset($_SESSION['ua']) && version_compare(PHP_VERSION, '7.1.1') >= 0 && ini_get('browscap')){
$ua = get_browser(null, true);
$_SESSION['ua'] = array();
$_SESSION['ua']['platform'] = $ua['platform'];
$_SESSION['ua']['browser'] = $ua['browser'];
}
}

/**
* Compares two tasks and returns an array of differences
Expand Down
47 changes: 26 additions & 21 deletions themes/CleanFS/templates/shortcuts.tpl
@@ -1,19 +1,24 @@
<?php
/*
TODO: show only or at least highlight the section that is matching the current view.
TODO: a fast platform and browser detection of user agent string to dynamically adapt accesskey help,
see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/accesskey
if ($is_mac) {
$accesskey='<kbd>CTRL</kbd> + <kbd>ALT</kbd>';
} elseif ($is_firefox) {
$accesskey='<kbd>ALT</kbd> + <kbd>SHIFT</kbd>';
# TODO: show only or at least highlight the section that is matching the current view.

# following decisions based on:
# https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/accesskey
# https://en.wikipedia.org/wiki/Access_key#Access_in_different_browsers
if (isset($_SESSION['ua'])) {
if ($_SESSION['ua']['platform'] == 'MacOSX') {
# all Browsers on Apple Macs
$modifier='<kbd>Ctrl</kbd> + <kbd>⌥ Opt</kbd>';
} elseif ($_SESSION['ua']['browser'] == 'Firefox') {
# Firefox on Windows and Linux
$modifier='<kbd>Alt</kbd> + <kbd>⇧ Shift</kbd>';
} else {
# all others
$modifier='<kbd>Alt</kbd>';
}
} else {
$accesskey='<kbd>ALT</kbd>';
# fallback
$modifier='<kbd>Alt</kbd> + <kbd>⇧ Shift</kbd>';
}
*/

$accesskey='<kbd>CTRL</kbd> + <kbd>ALT</kbd>';

?>
<input type="checkbox" id="s_shortcuts" />
<label for="s_shortcuts" id="shortcutlabel"><i class="fa fa-keyboard-o"></i> <?= eL('keyboardshortcuts') ?></label>
Expand All @@ -23,10 +28,10 @@ $accesskey='<kbd>CTRL</kbd> + <kbd>ALT</kbd>';
<h3><?= eL('availablekeybshortcuts') ?></h3>
<h4></h4>
<ul>
<li><?= $accesskey ?> + <kbd>l</kbd> <?= eL('logindialoglogout') ?></li>
<li><?= $accesskey ?> + <kbd>a</kbd> <?= eL('addnewtask') ?></li>
<li><?= $accesskey ?> + <kbd>m</kbd> <?= eL('mysearch') ?></li>
<li><?= $accesskey ?> + <kbd>t</kbd> <?= eL('focustaskidsearch') ?></li>
<li><?= $modifier ?> + <kbd>l</kbd> <?= eL('logindialoglogout') ?></li>
<li><?= $modifier ?> + <kbd>a</kbd> <?= eL('addnewtask') ?></li>
<li><?= $modifier ?> + <kbd>m</kbd> <?= eL('mysearch') ?></li>
<li><?= $modifier ?> + <kbd>t</kbd> <?= eL('focustaskidsearch') ?></li>
</ul>
<h4><?= eL('tasklist') ?></h4>
<ul>
Expand All @@ -38,12 +43,12 @@ $accesskey='<kbd>CTRL</kbd> + <kbd>ALT</kbd>';
<ul>
<li><kbd>n</kbd> <?= eL('nexttask') ?></li>
<li><kbd>p</kbd> <?= eL('previoustask') ?></li>
<li><?= $accesskey ?> + <kbd>e</kbd> <kbd>ENTER</kbd> <?= eL('edittask') ?></li>
<li><?= $accesskey ?> + <kbd>w</kbd> <?= eL('watchtask') ?></li>
<li><?= $accesskey ?> + <kbd>y</kbd> <?= eL('closetask') ?></li>
<li><?= $modifier ?> + <kbd>e</kbd> <kbd>↵ Enter</kbd> <?= eL('edittask') ?></li>
<li><?= $modifier ?> + <kbd>w</kbd> <?= eL('watchtask') ?></li>
<li><?= $modifier ?> + <kbd>y</kbd> <?= eL('closetask') ?></li>
</ul>
<h4><?= eL('taskediting') ?></h4>
<ul>
<li><?= $accesskey ?> + <kbd>s</kbd> <?= eL('savetask') ?></li>
<li><?= $modifier ?> + <kbd>s</kbd> <?= eL('savetask') ?></li>
</ul>
</div>
4 changes: 2 additions & 2 deletions themes/CleanFS/theme.css
Expand Up @@ -654,8 +654,8 @@ table.inline td {border:1px solid #ccc; padding:4px;}
margin-top:-260px;
max-height:540px;
left:50%;
width:300px;
margin-left:-150px;
width:360px;
margin-left:-180px;
box-sizing:border-box;
}
#shortcutsmodal {
Expand Down

0 comments on commit f2aba30

Please sign in to comment.