Skip to content

Commit

Permalink
Merge branch 'release-1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
BytewaveMLP committed Mar 30, 2017
2 parents b9facf6 + 7828099 commit 5cf5e87
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# sleeti
A proof-of-concept port of eeti.me to Slim 3

# Version 1.0.2
# Version 1.1

## To-do list
All upcoming and completed features, bugfixes, etc are listed [on the Trello board](https://trello.com/b/e5rzo48n/sleeti). Suggestions should be submitted through Github issues.
Expand Down
30 changes: 30 additions & 0 deletions app/Middleware/ActiveRouteMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* This file is part of sleeti.
* Copyright (C) 2016 Eliot Partridge
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Sleeti\Middleware;

class ActiveRouteMiddleware extends Middleware {
public function __invoke($request, $response, $next) {
$this->container->view->addExtension(new \Sleeti\Twig\Extensions\BootstrapActiveExtension($request));

$response = $next($request, $response);
return $response;
}
}
81 changes: 81 additions & 0 deletions app/Twig/Extensions/BootstrapActiveExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/**
* This file is part of sleeti.
* Copyright (C) 2016 Eliot Partridge
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Sleeti\Twig\Extensions;

class BootstrapActiveExtension extends \Twig_Extension {
protected $request;

public function __construct($request) {
$this->request = $request;
}

public function getFunctions() {
return [
new \Twig_SimpleFunction('active_route', [$this, 'isActiveRoute']),
new \Twig_SimpleFunction('active_route_one_of', [$this, 'isActiveRouteOneOf']),
new \Twig_SimpleFunction('active_group', [$this, 'isActiveRouteInGruop']),
new \Twig_SimpleFunction('active_group_one_of', [$this, 'isActiveRouteInGroups']),
];
}

public function isActiveRoute(string $name) {
$route = $this->request->getAttribute('route');

if (!$route) return;

if ($route->getName() == $name) {
return 'active';
}
}

public function isActiveRouteOneOf(array $names) {
foreach ($names as $name) {
if ($this->isActiveRoute($name)) {
return 'active';
}
}
}

public function isActiveRouteInGruop(string $group) {
$route = $this->request->getAttribute('route');

if (!$route) return;

$routeName = $route->getName();

$routeParts = explode('.', $routeName);
$groupParts = explode('.', $group);

foreach ($groupParts as $i => $part) {
if ($routeParts[$i] !== $part) return;
}

return 'active';
}

public function isActiveRouteInGroups(array $groups) {
foreach ($groups as $group) {
if ($this->isActiveRouteInGruop($group)) {
return 'active';
}
}
}
}
2 changes: 2 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
// Load the config
$settings['settings'] = json_decode(file_get_contents(__DIR__ . '/../config/config.json'), true);

$settings['settings']['determineRouteBeforeAppMiddleware'] = true;

// Load up Slim...
$app = new \Slim\App($settings);

Expand Down
1 change: 1 addition & 0 deletions bootstrap/globalmiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
$app->add(new \Sleeti\Middleware\OldInputMiddleware($container));
$app->add(new \Sleeti\Middleware\RememberMeMiddleware($container));
$app->add(new \Sleeti\Middleware\SessionCanaryMiddleware($container));
$app->add(new \Sleeti\Middleware\ActiveRouteMiddleware($container));
16 changes: 8 additions & 8 deletions resources/views/templates/partials/admin/acp/navigation.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

<div class="col-md-2">
<ul class="nav nav-pills nav-stacked">
<li role="presentation"><a href="{{ path_for('admin.acp.home') }}"><span aria-hidden="true" class="fa fa-home fa-fw"></span> ACP Home</a></li>
<li role="presentation"><a href="{{ path_for('admin.acp.database') }}"><span aria-hidden="true" class="fa fa-database fa-fw"></span> Database Settings</a></li>
<li role="presentation"><a href="{{ path_for('admin.acp.site') }}"><span aria-hidden="true" class="fa fa-pencil-square-o fa-fw"></span> Site Settings</a></li>
<li role="presentation"><a href="{{ path_for('admin.acp.password') }}"><span aria-hidden="true" class="fa fa-asterisk fa-fw"></span> Password Settings</a></li>
<li role="presentation"><a href="{{ path_for('admin.acp.errors') }}"><span aria-hidden="true" class="fa fa-exclamation-triangle fa-fw"></span> Error Settings</a></li>
<li role="presentation"><a href="{{ path_for('admin.acp.recaptcha') }}"><span aria-hidden="true" class="fa fa-check-square fa-fw"></span> reCAPTCHA Settings</a></li>
<li role="presentation"><a href="{{ path_for('admin.acp.log') }}"><span aria-hidden="true" class="fa fa-file-text-o fa-fw"></span> Log Settings</a></li>
<li role="presentation"><a href="{{ path_for('admin.acp.cache') }}"><span aria-hidden="true" class="fa fa-files-o fa-fw"></span> Cache Settings</a></li>
<li role="presentation" class="{{ active_route('admin.acp.home') }}"><a href="{{ path_for('admin.acp.home') }}"><span aria-hidden="true" class="fa fa-home fa-fw"></span> ACP Home</a></li>
<li role="presentation" class="{{ active_route('admin.acp.database') }}"><a href="{{ path_for('admin.acp.database') }}"><span aria-hidden="true" class="fa fa-database fa-fw"></span> Database Settings</a></li>
<li role="presentation" class="{{ active_route('admin.acp.site') }}"><a href="{{ path_for('admin.acp.site') }}"><span aria-hidden="true" class="fa fa-pencil-square-o fa-fw"></span> Site Settings</a></li>
<li role="presentation" class="{{ active_route('admin.acp.password') }}"><a href="{{ path_for('admin.acp.password') }}"><span aria-hidden="true" class="fa fa-asterisk fa-fw"></span> Password Settings</a></li>
<li role="presentation" class="{{ active_route('admin.acp.errors') }}"><a href="{{ path_for('admin.acp.errors') }}"><span aria-hidden="true" class="fa fa-exclamation-triangle fa-fw"></span> Error Settings</a></li>
<li role="presentation" class="{{ active_route('admin.acp.recaptcha') }}"><a href="{{ path_for('admin.acp.recaptcha') }}"><span aria-hidden="true" class="fa fa-check-square fa-fw"></span> reCAPTCHA Settings</a></li>
<li role="presentation" class="{{ active_route('admin.acp.log') }}"><a href="{{ path_for('admin.acp.log') }}"><span aria-hidden="true" class="fa fa-file-text-o fa-fw"></span> Log Settings</a></li>
<li role="presentation" class="{{ active_route('admin.acp.cache') }}"><a href="{{ path_for('admin.acp.cache') }}"><span aria-hidden="true" class="fa fa-files-o fa-fw"></span> Cache Settings</a></li>
</ul>
</div>
4 changes: 2 additions & 2 deletions resources/views/templates/partials/mod/mcp/navigation.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

<div class="col-md-2">
<ul class="nav nav-pills nav-stacked">
<li role="presentation"><a href="{{ path_for('mod.mcp.home') }}"><span aria-hidden="true" class="fa fa-home fa-fw"></span> MCP Home</a></li>
<li role="presentation"><a href="{{ path_for('mod.mcp.files') }}"><span aria-hidden="true" class="fa fa-files-o fa-fw"></span> All Files</a></li>
<li role="presentation" class="{{ active_route('mod.mcp.home') }}"><a href="{{ path_for('mod.mcp.home') }}"><span aria-hidden="true" class="fa fa-home fa-fw"></span> MCP Home</a></li>
<li role="presentation" class=" {{ active_route('mod.mcp.files') }} "><a href="{{ path_for('mod.mcp.files') }}"><span aria-hidden="true" class="fa fa-files-o fa-fw"></span> All Files</a></li>
</ul>
</div>
22 changes: 11 additions & 11 deletions resources/views/templates/partials/navigation.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="{{ path_for('home') }}">Home</a></li>
<li><a href="{{ path_for('community') }}">Community</a></li>
<li class="dropdown">
<li class="{{ active_route('home') }}"><a href="{{ path_for('home') }}">Home</a></li>
<li class="{{ active_route('community') }}"><a href="{{ path_for('community') }}">Community</a></li>
<li class="dropdown {{ active_group('file.upload') }}">
<a href="#" class="dropdown-toggle" id="uploaddropdown" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Upload <span class="caret"></span></a>
<ul class="dropdown-menu" aria-labelledby="uploaddropdown">
<li><a href="{{ path_for('file.upload') }}">File</a></li>
<li><a href="{{ path_for('file.upload.paste') }}">Paste</a></li>
<li><a href="{{ path_for('file.upload.sharex') }}">ShareX</a></li>
<li><a href="{{ path_for('file.upload.bash') }}">Bash + cURL</a></li>
<li class="{{ active_route('file.upload') }}"><a href="{{ path_for('file.upload') }}">File</a></li>
<li class="{{ active_route('file.upload.paste') }}"><a href="{{ path_for('file.upload.paste') }}">Paste</a></li>
<li class="{{ active_route('file.upload.sharex') }}"><a href="{{ path_for('file.upload.sharex') }}">ShareX</a></li>
<li class="{{ active_route('file.upload.bash') }}"><a href="{{ path_for('file.upload.bash') }}">Bash + cURL</a></li>
</ul>
</li>
{% if auth.check %}
{% if auth.user.isModerator() %}
<li class="dropdown">
<li class="dropdown {{ active_group_one_of(['mod.mcp', 'admin.acp']) }}">
<a href="#" class="dropdown-toggle" id="controldropdown" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Control Panels <span class="caret"></span></a>
<ul class="dropdown-menu" aria-labelledby="controldropdown">
<li><a href="{{ path_for('mod.mcp.home') }}">Moderator Control Panel</a></li>
Expand All @@ -56,7 +56,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</ul>
<ul class="nav navbar-nav navbar-right">
{% if auth.check %}
<li class="dropdown">
<li class="dropdown {{ active_group_one_of(['user.profile', 'auth']) }}">
<a href="#" class="dropdown-toggle" id="userdropdown" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ auth.user.username }} {% if auth.user.name %}({{ auth.user.name }}){% endif %}<span class="caret"></span></a>
<ul class="dropdown-menu" aria-labelledby="userdropdown">
<li><a href="{{ path_for('user.profile', {'id': auth.user.id}) }}">View profile</a></li>
Expand All @@ -68,8 +68,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</ul>
</li>
{% else %}
<li><a href="{{ path_for('auth.signup') }}">Sign up</a></li>
<li><a href="{{ path_for('auth.signin') }}">Sign in</a></li>
<li class="{{ active_route('auth.signup') }}"><a href="{{ path_for('auth.signup') }}">Sign up</a></li>
<li class="{{ active_route('auth.signin') }}"><a href="{{ path_for('auth.signin') }}">Sign in</a></li>
{% endif %}
</ul>
</div>
Expand Down

0 comments on commit 5cf5e87

Please sign in to comment.