Skip to content

Commit

Permalink
Merge branch '3.0'
Browse files Browse the repository at this point in the history
* 3.0:
  Don't show the session countdown if the user is not logged in
  Fixed issue if no category image is stored
  Fixed layout
  Removed wrong toggle
  Added missing session countdown
  Fixed check on existing class
  Added reading time functionality
  • Loading branch information
thorsten committed Jan 6, 2020
2 parents f1fc467 + 07d2ed3 commit 71aeb56
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 140 deletions.
11 changes: 9 additions & 2 deletions phpmyfaq/admin/assets/scss/navs/_topbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
outline: none;
}
}
.navbar-text {
height: $topbar-base-height;
display: flex;
align-items: center;
padding: 0 0.75rem;
}
&:focus {
outline: none;
}
Expand Down Expand Up @@ -80,7 +86,7 @@
position: absolute;
bottom: 0;
right: 0;
border: .125rem solid $white;
border: 0.125rem solid $white;
}
}
.text-truncate {
Expand Down Expand Up @@ -111,7 +117,8 @@
}
}

.topbar.navbar-dark {}
.topbar.navbar-dark {
}

.topbar.navbar-light {
.navbar-nav {
Expand Down
113 changes: 78 additions & 35 deletions phpmyfaq/admin/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,62 @@
$adminHelper = new AdministrationHelper();
$adminHelper->setUser($user);

$secLevelEntries['user'] = $adminHelper->addMenuEntry('add_user+edit_user+delete_user', 'user',
'ad_menu_user_administration', $action);
$secLevelEntries['user'] = $adminHelper->addMenuEntry(
'add_user+edit_user+delete_user',
'user',
'ad_menu_user_administration',
$action
);
if ($faqConfig->get('security.permLevel') !== 'basic') {
$secLevelEntries['user'] .= $adminHelper->addMenuEntry('addgroup+editgroup+delgroup', 'group',
'ad_menu_group_administration', $action);
$secLevelEntries['user'] .= $adminHelper->addMenuEntry(
'addgroup+editgroup+delgroup',
'group',
'ad_menu_group_administration',
$action
);
}
if ($faqConfig->get('security.permLevel') === 'large') {
$secLevelEntries['user'] .= $adminHelper->addMenuEntry('add_section+edit_section+del_section', 'section',
'ad_menu_section_administration', $action);
$secLevelEntries['user'] .= $adminHelper->addMenuEntry(
'add_section+edit_section+del_section',
'section',
'ad_menu_section_administration',
$action
);
}
$secLevelEntries['content'] = $adminHelper->addMenuEntry('addcateg+editcateg+delcateg', 'category',
'ad_menu_categ_edit', $action);
$secLevelEntries['content'] = $adminHelper->addMenuEntry(
'addcateg+editcateg+delcateg',
'category',
'ad_menu_categ_edit',
$action
);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('add_faq', 'editentry', 'ad_entry_add', $action);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('edit_faq+delete_faq', 'view', 'ad_menu_entry_edit', $action);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('edit_faq+delete_faq', 'searchfaqs', 'ad_menu_searchfaqs',
$action);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
'edit_faq+delete_faq',
'searchfaqs',
'ad_menu_searchfaqs',
$action
);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('delcomment', 'comments', 'ad_menu_comments', $action);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('delquestion', 'question', 'ad_menu_open', $action);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('addglossary+editglossary+delglossary', 'glossary',
'ad_menu_glossary', $action);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('addnews+editnews+delnews', 'news', 'ad_menu_news_edit',
$action);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('addattachment+editattachment+delattachment', 'attachments',
'ad_menu_attachments', $action);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
'addglossary+editglossary+delglossary',
'glossary',
'ad_menu_glossary',
$action
);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
'addnews+editnews+delnews',
'news',
'ad_menu_news_edit',
$action
);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
'addattachment+editattachment+delattachment',
'attachments',
'ad_menu_attachments',
$action
);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('edit_faq', 'tags', 'ad_entry_tags', $action);

$secLevelEntries['statistics'] = $adminHelper->addMenuEntry('viewlog', 'statistics', 'ad_menu_stat', $action);
Expand All @@ -88,10 +120,18 @@

$secLevelEntries['config'] .= $adminHelper->addMenuEntry('editconfig', 'config', 'ad_menu_editconfig', $action);
$secLevelEntries['config'] .= $adminHelper->addMenuEntry('editconfig', 'system', 'ad_system_info', $action, false);
$secLevelEntries['config'] .= $adminHelper->addMenuEntry('editinstances+addinstances+delinstances', 'instances',
'ad_menu_instances', $action);
$secLevelEntries['config'] .= $adminHelper->addMenuEntry('editconfig', 'stopwordsconfig', 'ad_menu_stopwordsconfig',
$action);
$secLevelEntries['config'] .= $adminHelper->addMenuEntry(
'editinstances+addinstances+delinstances',
'instances',
'ad_menu_instances',
$action
);
$secLevelEntries['config'] .= $adminHelper->addMenuEntry(
'editconfig',
'stopwordsconfig',
'ad_menu_stopwordsconfig',
$action
);
$secLevelEntries['config'] .= $adminHelper->addMenuEntry('editconfig', 'meta', 'ad_menu_meta', $action);
if ($faqConfig->get('search.enableElasticsearch')) {
$secLevelEntries['config'] .= $adminHelper->addMenuEntry(
Expand Down Expand Up @@ -184,8 +224,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<title><?= $faqConfig->get('main.titleFAQ'); ?> - powered by
phpMyFAQ <?= $faqConfig->get('main.currentVersion'); ?></title>
<title><?= $faqConfig->get('main.titleFAQ'); ?> - powered by phpMyFAQ <?= System::getVersion() ?></title>
<base href="<?= $faqSystem->getSystemUri($faqConfig) ?>admin/">

<meta name="description" content="Only Chuck Norris can divide by zero.">
Expand Down Expand Up @@ -218,7 +257,8 @@
<div id="wrapper">

<!-- Sidebar -->
<?php if (isset($auth) && (count($user->perm->getAllUserRights($user->getUserId())) > 0 || $user->isSuperAdmin())): ?>
<?php if (isset($auth) && (count($user->perm->getAllUserRights($user->getUserId())) > 0 || $user->isSuperAdmin(
))): ?>
<ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">

<li>
Expand Down Expand Up @@ -337,18 +377,10 @@
<hr class="sidebar-divider d-none d-md-block">
</li>

<!-- Sidebar Toggler (Sidebar) -->
<li>
<div class="text-center d-none d-md-inline">
<button class="rounded-circle border-0" id="sidebarToggle"></button>
</div>
</li>

</ul>
<!-- End of Sidebar -->
<?php endif; ?>


<!-- Content Wrapper -->
<div id="content-wrapper" class="d-flex flex-column">

Expand Down Expand Up @@ -383,9 +415,18 @@
</div>
</li>

<div class="topbar-divider d-none d-sm-block"></div>
<?php if (isset($auth) && (count(
$user->perm->getAllUserRights($user->getUserId())
) > 0 || $user->isSuperAdmin())): ?>
<li class="nav-item">
<div class="navbar-text text-gray-600 small">
<i class="fa fa-clock-o fa-fw"></i> <?= $PMF_LANG['ad_session_expiration']; ?>:
<span id="sessioncounter" class="pl-2"><i aria-hidden="true" class="fa fa-spinner fa-spin"></i> Loading...</span>
</div>
</li>

<div class="topbar-divider d-none d-sm-block"></div>

<?php if (isset($auth) && count($user->perm->getAllUserRights($user->getUserId())) > 0): ?>
<li class="nav-item dropdown no-arrow">
<a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
Expand All @@ -395,8 +436,10 @@
<?php
if ($faqConfig->get('main.enableGravatarSupport')) {
$avatar = new Gravatar($faqConfig);
echo $avatar->getImage($user->getUserData('email'),
['size' => 24, 'class' => 'img-profile rounded-circle']);
echo $avatar->getImage(
$user->getUserData('email'),
['size' => 24, 'class' => 'img-profile rounded-circle']
);
} else {
echo '<i aria-hidden="true" class="fa fa-user"></i>';
}
Expand Down
61 changes: 30 additions & 31 deletions phpmyfaq/admin/session.keepalive.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* session expiration and to give him the contextual possibility for
* refreshing the session by clicking <OK>.
*
*
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
Expand Down Expand Up @@ -70,44 +68,45 @@
<meta name="application-name" content="phpMyFAQ <?= $faqConfig->get('main.currentVersion'); ?>">
<meta name="copyright" content="(c) 2001-2020 phpMyFAQ Team">
<meta name="publisher" content="phpMyFAQ Team">
<?php if (isset($user) && ($refreshTime > 0)) {
?>
<?php if (isset($user) && ($refreshTime > 0)) { ?>
<script>

function _PMFSessionTimeoutWarning() {
if (window.confirm('<?php printf($PMF_LANG['ad_session_expiring'], PMF_AUTH_TIMEOUT_WARNING);
?>')) {
const sessionTimeoutWarning = () => {
if (window.confirm('<?php printf($PMF_LANG['ad_session_expiring'], PMF_AUTH_TIMEOUT_WARNING); ?>')) {
location.href = location.href;
}
}
}
};

function _PMFSessionTimeoutClock(topRef, expire) {
expire.setSeconds(expire.getSeconds() - 1);
if (expire.getFullYear() < 2009) {
const sessionTimeoutClock = (topRef, sessionStart, expire) => {
expire.setSeconds(expire.getSeconds() - 1);
const duration = expire - sessionStart;

if (expire.getFullYear() < 2020) {
parent.location.search = '?action=logout';
return;
}
}

if (topRef) {
topRef.innerHTML = new Date(duration).toISOString().substr(11, 8);
}
};

if (topRef) {
topRef.innerHTML = ('' + expire).match(/\d\d:\d\d:\d\d/);
}
}
window.onload = () => {
const expire = new Date();
const sessionStart = new Date();
expire.setSeconds(<?= PMF_AUTH_TIMEOUT ?> * 60);

window.onload = function() {
var expire = new Date();
expire.setSeconds(<?= PMF_AUTH_TIMEOUT ?> * 60);
var topRef = top.document.getElementById('sessioncounter');
const topRef = top.document.getElementById('sessioncounter');

window.setTimeout(_PMFSessionTimeoutWarning, <?= $refreshTime ?> * 1000);
window.setInterval(
function() {
_PMFSessionTimeoutClock(topRef, expire);
window.setTimeout(sessionTimeoutWarning, <?= $refreshTime ?> * 1000);
window.setInterval(
() => {
sessionTimeoutClock(topRef, sessionStart, expire);
},
1000
);
}
</script>
<?php } ?>
1000,
);
};
</script>
<?php } ?>
</head>
<body>

Expand Down
6 changes: 6 additions & 0 deletions phpmyfaq/assets/src/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@
*/

import 'cookieconsent';
import { calculateReadingTime } from './reading-time';

const faqBody = document.querySelector('.pmf-faq-body');
if (faqBody !== null) {
calculateReadingTime();
}
28 changes: 28 additions & 0 deletions phpmyfaq/assets/src/reading-time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Simple function to calculate the reading time
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
*
* @package phpMyFAQ
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @copyright 2020 phpMyFAQ Team
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2020-01-05
*/

export const calculateReadingTime = () => {
const wordsPerMinute = 200;
const answer = document.getElementsByClassName('pmf-faq-body');
let result;

let textLength = answer[0].innerText.split(' ').length;
if (textLength > 0) {
let value = Math.ceil(textLength / wordsPerMinute);
result = `~${value} min`;
}

document.getElementById('pmf-reading-time-minutes').innerText = result;
};
1 change: 1 addition & 0 deletions phpmyfaq/assets/themes/default/scss/_faq.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
padding: 0.5em;
margin-bottom: 1em;

.pmf-faq-reading-time,
.pmf-faq-author,
.pmf-faq-date,
.pmf-faq-comments,
Expand Down
4 changes: 4 additions & 0 deletions phpmyfaq/assets/themes/default/templates/faq.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
</div>
<h2>{{ question }}</h2>
<div class="pmf-faq-meta clearfix">
<div class="pmf-faq-reading-time">
<i aria-hidden="true" class="fa fa-clock-o"></i>
<span class="data" id="pmf-reading-time-minutes">~ 0 min</span>
</div>
<div class="pmf-faq-author">
<i aria-hidden="true" class="fa fa-user"></i>
<span class="data" rel="author">{{ faqAuthor }}</span>
Expand Down
30 changes: 18 additions & 12 deletions phpmyfaq/assets/themes/default/templates/password.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
<section class="col-12">
<h1>
{{ pageHeader }}
</h1>

<form id="formValues" action="#" method="post" accept-charset="utf-8">
<div class="control-group">
<label class="form-control-label">{{ msgUsername }}</label>
<div class="controls">
<input type="text" name="username" required="required" autofocus="autofocus" />
<div class="form-group row">
<label class="col-3 form-control-label" for="username">{{ msgUsername }}</label>
<div class="col-9">
<input class="form-control" type="text" name="username" id="username" required autofocus />
</div>
</div>

<div class="control-group">
<label class="form-control-label">{{ msgEmail }}</label>
<div class="controls">
<input type="email" name="email" required="required" />
<div class="form-group row">
<label class="col-3 form-control-label" for="email">{{ msgEmail }}</label>
<div class="col-9">
<input class="form-control" type="email" name="email" id="email" required />
</div>
</div>

<div class="form-actions">
<button class="btn btn-primary" type="submit" id="changepassword">
{{ msgSubmit }}
</button>
<div class="form-group row">
<div class="col-sm-12 text-right">
<button class="btn btn-primary" type="submit" id="changepassword">
{{ msgSubmit }}
</button>
</div>
</div>
</form>

Expand Down

0 comments on commit 71aeb56

Please sign in to comment.