1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jidaikobo\Kontiki\Controllers; |
4
|
|
|
|
5
|
|
|
use Slim\App; |
6
|
|
|
use Psr\Http\Message\ResponseInterface as Response; |
7
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request; |
8
|
|
|
use Slim\Views\PhpRenderer; |
9
|
|
|
|
10
|
|
|
class AdminController |
11
|
|
|
{ |
12
|
|
|
private PhpRenderer $view; |
13
|
|
|
|
14
|
|
|
public function __construct(PhpRenderer $view) |
15
|
|
|
{ |
16
|
|
|
$this->view = $view; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public static function registerRoutes(App $app): void |
20
|
|
|
{ |
21
|
|
|
$app->get('/admin.js', AdminController::class . ':serveJs'); |
22
|
|
|
$app->get('/admin.css', AdminController::class . ':serveCss'); |
23
|
|
|
$app->get('/favicon.ico', AdminController::class . ':serveFavicon'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Serve the requested JavaScript file. |
28
|
|
|
* |
29
|
|
|
* @return Response |
30
|
|
|
*/ |
31
|
|
|
public function serveJs(Request $request, Response $response): Response |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$content = $this->view->fetch( |
34
|
|
|
'js/admin.js.php', |
35
|
|
|
[ |
36
|
|
|
'publishing' => __('publishing'), |
37
|
|
|
'reserved' => __('reserved'), |
38
|
|
|
'expired' => __('expired'), |
39
|
|
|
'do_publish' => __('do_publish', 'publish'), |
40
|
|
|
'do_reserve' => __('do_reserve', 'reserve'), |
41
|
|
|
'do_save_as_pending' => __('do_save_as_pending', 'save as pending'), |
42
|
|
|
'do_save_as_draft' => __('do_save_as_draft', 'save as draft'), |
43
|
|
|
'published_url' => __('published_url'), |
44
|
|
|
'reserved_url' => __('reserved_url'), |
45
|
|
|
'banned_url' => __('banned_url'), |
46
|
|
|
'open_in_new_window' => __('open_in_new_window'), |
47
|
|
|
'open_sidebar' => __('open_sidebar'), |
48
|
|
|
'close_sidebar' => __('close_sidebar'), |
49
|
|
|
] |
50
|
|
|
); |
51
|
|
|
$response->getBody()->write($content); |
52
|
|
|
return $response->withHeader( |
53
|
|
|
'Content-Type', |
54
|
|
|
'application/javascript; charset=utf-8' |
55
|
|
|
)->withStatus(200); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Serve the requested CSS file. |
61
|
|
|
* |
62
|
|
|
* @return Response |
63
|
|
|
*/ |
64
|
|
|
public function serveCss(Request $request, Response $response): Response |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$content = $this->view->fetch( |
67
|
|
|
'css/admin.css.php', |
68
|
|
|
[ |
69
|
|
|
'color' => env('ADMIN_THEME_COLOR', '#ffffff'), |
70
|
|
|
'bgcolor' => env('ADMIN_THEME_BGCOLOR', '#343a40') |
71
|
|
|
] |
72
|
|
|
); |
73
|
|
|
$response->getBody()->write($content); |
74
|
|
|
return $response->withHeader( |
75
|
|
|
'Content-Type', |
76
|
|
|
'text/css; charset=utf-8' |
77
|
|
|
)->withStatus(200); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Serve the requested favicon file. |
82
|
|
|
* |
83
|
|
|
* @return Response |
84
|
|
|
*/ |
85
|
|
|
public function serveFavicon(Request $request, Response $response): Response |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$faviconPath = env('PROJECT_PATH', '') . '/src/views/images/favicon.ico'; |
88
|
|
|
$content = file_get_contents($faviconPath); |
89
|
|
|
$response->getBody()->write($content); |
90
|
|
|
return $response |
91
|
|
|
->withHeader('Content-Type', 'image/x-icon') |
92
|
|
|
->withHeader('Cache-Control', 'public, max-age=86400') |
93
|
|
|
->withStatus(200); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.