--- /dev/null
+<?php
+
+declare(strict_types=1);
+
+namespace Shaarli\Front\Controller\Admin;
+
+use Slim\Http\Request;
+use Slim\Http\Response;
+
+/**
+ * Class ToolsController
+ *
+ * Slim controller used to display the tools page.
+ */
+class ToolsController extends ShaarliAdminController
+{
+ public function index(Request $request, Response $response): Response
+ {
+ $data = [
+ 'pageabsaddr' => index_url($this->container->environment),
+ 'sslenabled' => is_https($this->container->environment),
+ ];
+
+ $this->executeHooks($data);
+
+ foreach ($data as $key => $value) {
+ $this->assignView($key, $value);
+ }
+
+ $this->assignView('pagetitle', t('Tools') .' - '. $this->container->conf->get('general.title', 'Shaarli'));
+
+ return $response->write($this->render('tools'));
+ }
+
+ /**
+ * @param mixed[] $data Variables passed to the template engine
+ *
+ * @return mixed[] Template data after active plugins render_picwall hook execution.
+ */
+ protected function executeHooks(array $data): array
+ {
+ $this->container->pluginManager->executeHooks(
+ 'render_tools',
+ $data
+ );
+
+ return $data;
+ }
+}
http://<replace_domain>/?do=changepasswd
http://<replace_domain>/?do=changetag
http://<replace_domain>/?do=configure
-http://<replace_domain>/?do=tools
+http://<replace_domain>/tools
http://<replace_domain>/daily
http://<replace_domain>/?post
http://<replace_domain>/?do=export
// -------- Display the Tools menu if requested (import/export/bookmarklet...)
if ($targetPage == Router::$PAGE_TOOLS) {
- $data = [
- 'pageabsaddr' => index_url($_SERVER),
- 'sslenabled' => is_https($_SERVER),
- ];
- $pluginManager->executeHooks('render_tools', $data);
-
- foreach ($data as $key => $value) {
- $PAGE->assign($key, $value);
- }
-
- $PAGE->assign('pagetitle', t('Tools') .' - '. $conf->get('general.title', 'Shaarli'));
- $PAGE->renderPage('tools');
+ header('Location: ./tools');
exit;
}
);
// TODO: do not handle exceptions/errors in JS.
- echo '<script>alert("'. $e->getMessage() .'");document.location=\'./?do=tools\';</script>';
+ echo '<script>alert("'. $e->getMessage() .'");document.location=\'./tools\';</script>';
exit;
}
- echo '<script>alert("'. t('Your password has been changed') .'");document.location=\'./?do=tools\';</script>';
+ echo '<script>alert("'. t('Your password has been changed') .'");document.location=\'./tools\';</script>';
exit;
} else {
// show the change password form.
/* -- LOGGED IN -- */
$this->get('/logout', '\Shaarli\Front\Controller\Admin\LogoutController:index')->setName('logout');
+ $this->get('/tools', '\Shaarli\Front\Controller\Admin\ToolsController:index')->setName('tools');
$this
->get('/links-per-page', '\Shaarli\Front\Controller\Admin\SessionFilterController:linksPerPage')
namespace Shaarli\Front\Controller\Admin;
/** Override PHP builtin setcookie function in the local namespace to mock it... more or less */
-if (!function_exists('Shaarli\Front\Controller\setcookie')) {
+if (!function_exists('Shaarli\Front\Controller\Admin\setcookie')) {
function setcookie(string $name, string $value): void {
$_COOKIE[$name] = $value;
}
--- /dev/null
+<?php
+
+declare(strict_types=1);
+
+namespace Shaarli\Front\Controller\Admin;
+
+use PHPUnit\Framework\TestCase;
+use Slim\Http\Request;
+use Slim\Http\Response;
+
+class ToolsControllerTestControllerTest extends TestCase
+{
+ use FrontAdminControllerMockHelper;
+
+ /** @var ToolsController */
+ protected $controller;
+
+ public function setUp(): void
+ {
+ $this->createContainer();
+
+ $this->controller = new ToolsController($this->container);
+ }
+
+ public function testDefaultInvokeWithHttps(): void
+ {
+ $this->createValidContainerMockSet();
+
+ $request = $this->createMock(Request::class);
+ $response = new Response();
+
+ $this->container->environment = [
+ 'SERVER_NAME' => 'shaarli',
+ 'SERVER_PORT' => 443,
+ 'HTTPS' => 'on',
+ ];
+
+ // Save RainTPL assigned variables
+ $assignedVariables = [];
+ $this->assignTemplateVars($assignedVariables);
+
+ $result = $this->controller->index($request, $response);
+
+ static::assertSame(200, $result->getStatusCode());
+ static::assertSame('tools', (string) $result->getBody());
+ static::assertSame('https://shaarli', $assignedVariables['pageabsaddr']);
+ static::assertTrue($assignedVariables['sslenabled']);
+ }
+
+ public function testDefaultInvokeWithoutHttps(): void
+ {
+ $this->createValidContainerMockSet();
+
+ $request = $this->createMock(Request::class);
+ $response = new Response();
+
+ $this->container->environment = [
+ 'SERVER_NAME' => 'shaarli',
+ 'SERVER_PORT' => 80,
+ ];
+
+ // Save RainTPL assigned variables
+ $assignedVariables = [];
+ $this->assignTemplateVars($assignedVariables);
+
+ $result = $this->controller->index($request, $response);
+
+ static::assertSame(200, $result->getStatusCode());
+ static::assertSame('tools', (string) $result->getBody());
+ static::assertSame('http://shaarli', $assignedVariables['pageabsaddr']);
+ static::assertFalse($assignedVariables['sslenabled']);
+ }
+}
</a>
</li>
<li class="pure-menu-item" id="shaarli-menu-tools">
- <a href="./?do=tools" class="pure-menu-link">{'Tools'|t}</a>
+ <a href="./tools" class="pure-menu-link">{'Tools'|t}</a>
</li>
{/if}
<li class="pure-menu-item" id="shaarli-menu-tags">
<li><a href="{$titleLink}" class="nomobile">Home</a></li>
{if="$is_logged_in"}
<li><a href="./logout">Logout</a></li>
- <li><a href="?do=tools">Tools</a></li>
+ <li><a href="./tools">Tools</a></li>
<li><a href="?do=addlink">Add link</a></li>
{elseif="$openshaarli"}
- <li><a href="./?do=tools">Tools</a></li>
+ <li><a href="./tools">Tools</a></li>
<li><a href="./?do=addlink">Add link</a></li>
{else}
<li><a href="./login">Login</a></li>