aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/front/controller/admin/ToolsController.php49
-rw-r--r--doc/md/Translations.md2
-rw-r--r--index.php18
-rw-r--r--tests/front/controller/admin/LogoutControllerTest.php2
-rw-r--r--tests/front/controller/admin/ToolsControllerTest.php73
-rw-r--r--tpl/default/page.header.html2
-rw-r--r--tpl/vintage/page.header.html4
7 files changed, 131 insertions, 19 deletions
diff --git a/application/front/controller/admin/ToolsController.php b/application/front/controller/admin/ToolsController.php
new file mode 100644
index 00000000..66db5ad9
--- /dev/null
+++ b/application/front/controller/admin/ToolsController.php
@@ -0,0 +1,49 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller\Admin;
6
7use Slim\Http\Request;
8use Slim\Http\Response;
9
10/**
11 * Class ToolsController
12 *
13 * Slim controller used to display the tools page.
14 */
15class ToolsController extends ShaarliAdminController
16{
17 public function index(Request $request, Response $response): Response
18 {
19 $data = [
20 'pageabsaddr' => index_url($this->container->environment),
21 'sslenabled' => is_https($this->container->environment),
22 ];
23
24 $this->executeHooks($data);
25
26 foreach ($data as $key => $value) {
27 $this->assignView($key, $value);
28 }
29
30 $this->assignView('pagetitle', t('Tools') .' - '. $this->container->conf->get('general.title', 'Shaarli'));
31
32 return $response->write($this->render('tools'));
33 }
34
35 /**
36 * @param mixed[] $data Variables passed to the template engine
37 *
38 * @return mixed[] Template data after active plugins render_picwall hook execution.
39 */
40 protected function executeHooks(array $data): array
41 {
42 $this->container->pluginManager->executeHooks(
43 'render_tools',
44 $data
45 );
46
47 return $data;
48 }
49}
diff --git a/doc/md/Translations.md b/doc/md/Translations.md
index e0e411bb..38878940 100644
--- a/doc/md/Translations.md
+++ b/doc/md/Translations.md
@@ -36,7 +36,7 @@ http://<replace_domain>/?do=addlink
36http://<replace_domain>/?do=changepasswd 36http://<replace_domain>/?do=changepasswd
37http://<replace_domain>/?do=changetag 37http://<replace_domain>/?do=changetag
38http://<replace_domain>/?do=configure 38http://<replace_domain>/?do=configure
39http://<replace_domain>/?do=tools 39http://<replace_domain>/tools
40http://<replace_domain>/daily 40http://<replace_domain>/daily
41http://<replace_domain>/?post 41http://<replace_domain>/?post
42http://<replace_domain>/?do=export 42http://<replace_domain>/?do=export
diff --git a/index.php b/index.php
index 4cd6d5f4..f4c8b391 100644
--- a/index.php
+++ b/index.php
@@ -501,18 +501,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
501 501
502 // -------- Display the Tools menu if requested (import/export/bookmarklet...) 502 // -------- Display the Tools menu if requested (import/export/bookmarklet...)
503 if ($targetPage == Router::$PAGE_TOOLS) { 503 if ($targetPage == Router::$PAGE_TOOLS) {
504 $data = [ 504 header('Location: ./tools');
505 'pageabsaddr' => index_url($_SERVER),
506 'sslenabled' => is_https($_SERVER),
507 ];
508 $pluginManager->executeHooks('render_tools', $data);
509
510 foreach ($data as $key => $value) {
511 $PAGE->assign($key, $value);
512 }
513
514 $PAGE->assign('pagetitle', t('Tools') .' - '. $conf->get('general.title', 'Shaarli'));
515 $PAGE->renderPage('tools');
516 exit; 505 exit;
517 } 506 }
518 507
@@ -557,10 +546,10 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
557 ); 546 );
558 547
559 // TODO: do not handle exceptions/errors in JS. 548 // TODO: do not handle exceptions/errors in JS.
560 echo '<script>alert("'. $e->getMessage() .'");document.location=\'./?do=tools\';</script>'; 549 echo '<script>alert("'. $e->getMessage() .'");document.location=\'./tools\';</script>';
561 exit; 550 exit;
562 } 551 }
563 echo '<script>alert("'. t('Your password has been changed') .'");document.location=\'./?do=tools\';</script>'; 552 echo '<script>alert("'. t('Your password has been changed') .'");document.location=\'./tools\';</script>';
564 exit; 553 exit;
565 } else { 554 } else {
566 // show the change password form. 555 // show the change password form.
@@ -1514,6 +1503,7 @@ $app->group('', function () {
1514 1503
1515 /* -- LOGGED IN -- */ 1504 /* -- LOGGED IN -- */
1516 $this->get('/logout', '\Shaarli\Front\Controller\Admin\LogoutController:index')->setName('logout'); 1505 $this->get('/logout', '\Shaarli\Front\Controller\Admin\LogoutController:index')->setName('logout');
1506 $this->get('/tools', '\Shaarli\Front\Controller\Admin\ToolsController:index')->setName('tools');
1517 1507
1518 $this 1508 $this
1519 ->get('/links-per-page', '\Shaarli\Front\Controller\Admin\SessionFilterController:linksPerPage') 1509 ->get('/links-per-page', '\Shaarli\Front\Controller\Admin\SessionFilterController:linksPerPage')
diff --git a/tests/front/controller/admin/LogoutControllerTest.php b/tests/front/controller/admin/LogoutControllerTest.php
index 239e39b2..ba681b16 100644
--- a/tests/front/controller/admin/LogoutControllerTest.php
+++ b/tests/front/controller/admin/LogoutControllerTest.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7/** Override PHP builtin setcookie function in the local namespace to mock it... more or less */ 7/** Override PHP builtin setcookie function in the local namespace to mock it... more or less */
8if (!function_exists('Shaarli\Front\Controller\setcookie')) { 8if (!function_exists('Shaarli\Front\Controller\Admin\setcookie')) {
9 function setcookie(string $name, string $value): void { 9 function setcookie(string $name, string $value): void {
10 $_COOKIE[$name] = $value; 10 $_COOKIE[$name] = $value;
11 } 11 }
diff --git a/tests/front/controller/admin/ToolsControllerTest.php b/tests/front/controller/admin/ToolsControllerTest.php
new file mode 100644
index 00000000..47c5746e
--- /dev/null
+++ b/tests/front/controller/admin/ToolsControllerTest.php
@@ -0,0 +1,73 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller\Admin;
6
7use PHPUnit\Framework\TestCase;
8use Slim\Http\Request;
9use Slim\Http\Response;
10
11class ToolsControllerTestControllerTest extends TestCase
12{
13 use FrontAdminControllerMockHelper;
14
15 /** @var ToolsController */
16 protected $controller;
17
18 public function setUp(): void
19 {
20 $this->createContainer();
21
22 $this->controller = new ToolsController($this->container);
23 }
24
25 public function testDefaultInvokeWithHttps(): void
26 {
27 $this->createValidContainerMockSet();
28
29 $request = $this->createMock(Request::class);
30 $response = new Response();
31
32 $this->container->environment = [
33 'SERVER_NAME' => 'shaarli',
34 'SERVER_PORT' => 443,
35 'HTTPS' => 'on',
36 ];
37
38 // Save RainTPL assigned variables
39 $assignedVariables = [];
40 $this->assignTemplateVars($assignedVariables);
41
42 $result = $this->controller->index($request, $response);
43
44 static::assertSame(200, $result->getStatusCode());
45 static::assertSame('tools', (string) $result->getBody());
46 static::assertSame('https://shaarli', $assignedVariables['pageabsaddr']);
47 static::assertTrue($assignedVariables['sslenabled']);
48 }
49
50 public function testDefaultInvokeWithoutHttps(): void
51 {
52 $this->createValidContainerMockSet();
53
54 $request = $this->createMock(Request::class);
55 $response = new Response();
56
57 $this->container->environment = [
58 'SERVER_NAME' => 'shaarli',
59 'SERVER_PORT' => 80,
60 ];
61
62 // Save RainTPL assigned variables
63 $assignedVariables = [];
64 $this->assignTemplateVars($assignedVariables);
65
66 $result = $this->controller->index($request, $response);
67
68 static::assertSame(200, $result->getStatusCode());
69 static::assertSame('tools', (string) $result->getBody());
70 static::assertSame('http://shaarli', $assignedVariables['pageabsaddr']);
71 static::assertFalse($assignedVariables['sslenabled']);
72 }
73}
diff --git a/tpl/default/page.header.html b/tpl/default/page.header.html
index 624367e4..ca7dc1bc 100644
--- a/tpl/default/page.header.html
+++ b/tpl/default/page.header.html
@@ -26,7 +26,7 @@
26 </a> 26 </a>
27 </li> 27 </li>
28 <li class="pure-menu-item" id="shaarli-menu-tools"> 28 <li class="pure-menu-item" id="shaarli-menu-tools">
29 <a href="./?do=tools" class="pure-menu-link">{'Tools'|t}</a> 29 <a href="./tools" class="pure-menu-link">{'Tools'|t}</a>
30 </li> 30 </li>
31 {/if} 31 {/if}
32 <li class="pure-menu-item" id="shaarli-menu-tags"> 32 <li class="pure-menu-item" id="shaarli-menu-tags">
diff --git a/tpl/vintage/page.header.html b/tpl/vintage/page.header.html
index 9268ced9..c265d6d0 100644
--- a/tpl/vintage/page.header.html
+++ b/tpl/vintage/page.header.html
@@ -19,10 +19,10 @@
19<li><a href="{$titleLink}" class="nomobile">Home</a></li> 19<li><a href="{$titleLink}" class="nomobile">Home</a></li>
20 {if="$is_logged_in"} 20 {if="$is_logged_in"}
21 <li><a href="./logout">Logout</a></li> 21 <li><a href="./logout">Logout</a></li>
22 <li><a href="?do=tools">Tools</a></li> 22 <li><a href="./tools">Tools</a></li>
23 <li><a href="?do=addlink">Add link</a></li> 23 <li><a href="?do=addlink">Add link</a></li>
24 {elseif="$openshaarli"} 24 {elseif="$openshaarli"}
25 <li><a href="./?do=tools">Tools</a></li> 25 <li><a href="./tools">Tools</a></li>
26 <li><a href="./?do=addlink">Add link</a></li> 26 <li><a href="./?do=addlink">Add link</a></li>
27 {else} 27 {else}
28 <li><a href="./login">Login</a></li> 28 <li><a href="./login">Login</a></li>