Skip to content

Commit 9621e72

Browse files
committed
Code cleanup and partial refactoring
No significant functional changes
1 parent 0942597 commit 9621e72

File tree

10 files changed

+1056
-966
lines changed

10 files changed

+1056
-966
lines changed

PicoAdmin/PicoAdmin.php

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ protected function handleAdminRequest()
108108
// show built-in landing page when no specific module was requested
109109
// landing page requires authentication, therefore non-authenticated users will end up on the login page
110110
$this->requestModule = 'landing';
111+
$this->requestAction = $this->requestPayload = '';
111112
$this->authenticationRequired = true;
112113
}
113114

@@ -269,6 +270,11 @@ protected function generateAuthToken($password)
269270
return $authToken;
270271
}
271272

273+
public function isAuthenticated()
274+
{
275+
return $this->authenticated;
276+
}
277+
272278
public function getAdminPageUrl($page, $queryData = null)
273279
{
274280
$page = $page ? $this->getPluginConfig('url') . '/' . $page : $this->getPluginConfig('url');

PicoAdmin/PicoContentAdmin.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function onAdminInitialized()
180180
// create new CSRF token
181181
$csrfTokenPayload = 'PicoContentAdmin|' . $this->admin->getPluginConfig('auth_token');
182182
$this->csrfToken = $this->session->generateSignedToken('PicoContentAdmin', $csrfTokenPayload);
183-
} elseif ($this->action !== 'fullPreview') {
183+
} elseif ($this->action !== 'navigation') {
184184
// check CSRF token
185185
$csrfTokenPayload = 'PicoContentAdmin|' . $this->admin->getPluginConfig('auth_token');
186186
$csrfToken = (isset($_POST['csrf_token']) && is_array($_POST['csrf_token'])) ? $_POST['csrf_token'] : array();
@@ -192,8 +192,8 @@ public function onAdminInitialized()
192192
}
193193

194194
// make sure that this is a JSON request
195-
if (!$this->admin->isJsonRequest()) {
196-
$this->action = 'error';
195+
if (($this->action !== 'fullPreview') && !$this->admin->isJsonRequest()) {
196+
$this->action = 'jsonError';
197197
}
198198
}
199199

@@ -379,7 +379,7 @@ public function onPageRendering(Twig_Environment &$twig, array &$twigVariables,
379379
} elseif ($this->action === 'fullPreview') {
380380
// use frontend theme
381381
return;
382-
} elseif ($this->action === 'error') {
382+
} elseif ($this->action === 'jsonError') {
383383
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
384384
return;
385385
} elseif ($this->action === 'csrfError') {

PicoAdmin/content/info.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ Robots: noindex,nofollow
1717
to use to access the admin panel below and hit `Generate`:
1818

1919
<form action="" method="post">
20-
<input type="password" name="password" placeholder="Password" />
21-
<input type="submit" value="Generate" />
20+
<fieldset>
21+
<input type="password" name="password" placeholder="Password" />
22+
<input type="submit" value="Generate" />
23+
</fieldset>
2224
</form>
2325

2426
<div class="admin-auth-token" data-auth-token="%meta.admin_auth_token%" markdown="1">

PicoAdmin/content/login.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Robots: noindex,nofollow
55

66
## Pico Admin Login
77

8-
<form action="" method="post">
8+
<form action="?" method="post">
99
<fieldset>
1010
<input type="password" name="password" placeholder="Password" />
1111
<input type="submit" value="Login" />

PicoAdmin/theme/admin-content.twig

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
<script src="{{ admin_theme_url }}/js/admin-content.js" type="text/javascript"></script>
1212

1313
<script type="text/javascript">
14-
var picoContentAdmin = new PicoContentAdmin(picoAdmin, {{ csrf_token|json_encode }});
14+
var picoContentAdmin = new PicoContentAdmin(
15+
picoAdmin,
16+
{{ csrf_token|json_encode }},
17+
{% filter json_encode %}{1} | Pico Admin Panel | {{ site_title }}{% endfilter %}
18+
);
1519
picoContentAdmin.init({
16-
title: {% filter json_encode %}{1} | Pico Admin Panel | {{ site_title }}{% endfilter %},
1720
contentExt: {{ config.content_ext|json_encode }},
1821
yamlEditorOptions: utils.extend(
1922
{{ config.PicoAdmin.PicoContentAdmin.yamlEditor|json_encode }},
@@ -30,13 +33,10 @@
3033

3134
{% if admin_request.module == "content" %}
3235
<script type="text/javascript">
33-
if (!picoContentAdmin.restore()) {
34-
picoContentAdmin.takeOver(
35-
'{{ page_path|escape("js") }}',
36-
'{% if not rescue_mode %}{{ admin_request.action }}{% else %}rescue{% endif %}',
37-
'{{ page_title|escape("js") }}'
38-
);
39-
}
36+
picoAdmin.takeOver('content', '{{ page_path|escape("js") }}', [
37+
'{% if not rescue_mode %}{{ admin_request.action }}{% else %}rescue{% endif %}',
38+
'{{ page_title|escape("js") }}'
39+
]);
4040
</script>
4141
{% endif %}
4242
{% endblock %}

PicoAdmin/theme/css/admin.css

+26-3
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ header { border-right: 1px solid #ddd; }
103103
header > h1 {
104104
margin: 0;
105105
padding: 1rem;
106+
106107
white-space: pre;
107108
overflow: hidden;
108109
text-overflow: ellipsis;
110+
109111
background: #2EAE9B;
110112
color: #fff;
111113
}
@@ -183,8 +185,10 @@ footer a[href]:hover { color: #fff; }
183185
position: fixed;
184186
top: 0;
185187
left: 0;
188+
186189
width: 100%;
187190
height: 100%;
191+
188192
z-index: 100;
189193
background: #000;
190194
}
@@ -196,14 +200,19 @@ footer a[href]:hover { color: #fff; }
196200
top: 0;
197201
left: 0;
198202
right: 0;
203+
199204
width: 768px;
200205
max-width: 100%;
201206
margin: 0 auto;
202207
padding: 0 0.5em;
208+
203209
z-index: 200;
204210
opacity: 0.95;
205211
}
206-
#notification > .alert { border-top: 0 none; }
212+
#notification > .alert {
213+
border-top: 0 none;
214+
margin-bottom: 0;
215+
}
207216
#notification > .alert:last-child {
208217
border-bottom-left-radius: 0.3rem;
209218
border-bottom-right-radius: 0.3rem;
@@ -231,6 +240,7 @@ footer a[href]:hover { color: #fff; }
231240
align-items: center;
232241
background: #ccc;
233242
border: 1px solid #999;
243+
margin-bottom: 1em;
234244
}
235245
.alert.alert-info { background: #6cc; border-color: #399; }
236246
.alert.alert-success { background: #6c9; border-color: #396; }
@@ -256,13 +266,16 @@ footer a[href]:hover { color: #fff; }
256266
.alert > .button {
257267
align-self: flex-start;
258268
flex: 0 0 auto;
269+
259270
display: block;
260271
margin: 1rem;
261272
padding: 0.5em 1em;
273+
262274
color: #444;
263275
background: rgba(0, 0, 0, 0.15);
264276
border-radius: 0.3em;
265277
cursor: pointer;
278+
266279
-webkit-transition: background .2s ease-in;
267280
transition: background .2s ease-in;
268281
}
@@ -272,17 +285,21 @@ footer a[href]:hover { color: #fff; }
272285

273286
.alert > .dismiss {
274287
align-self: flex-start;
288+
275289
min-width: 2em;
276290
height: 2em;
277291
margin: 1rem;
278292
line-height: 2em;
293+
279294
font-size: 0.7rem;
280295
text-align: center;
281296
font-weight: bold;
297+
282298
color: rgba(0, 0, 0, 0.4);
283299
background: rgba(0, 0, 0, 0.15);
284300
border-radius: 0.3rem;
285301
cursor: default;
302+
286303
-webkit-transition: background .2s ease-in;
287304
transition: background .2s ease-in;
288305
}
@@ -407,10 +424,12 @@ footer a[href]:hover { color: #fff; }
407424
width: 2em;
408425
margin: 0;
409426
padding: 0.3em;
427+
410428
background: #eee;
411429
text-align: center;
412430
color: #444;
413431
cursor: pointer;
432+
414433
-webkit-transition: color .2s ease-in;
415434
transition: color .2s ease-in;
416435
}
@@ -493,13 +512,17 @@ footer a[href]:hover { color: #fff; }
493512
display: flex;
494513
flex-direction: column;
495514
justify-content: center;
515+
496516
width: 12em;
497517
height: 10em;
498-
border: 1px solid #ddd;
499-
border-radius: 0.5em;
500518
margin: 0.25em;
501519
padding: 1em;
520+
521+
border: 1px solid #ddd;
522+
border-radius: 0.5em;
523+
502524
cursor: pointer;
525+
503526
-webkit-transition: border-color .2s ease-in,
504527
box-shadow .2s ease-in;
505528
transition: border-color .2s ease-in,

0 commit comments

Comments
 (0)