Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit 7344ae6

Browse files
committed
Outsourcing helper function
1 parent 8bdd25c commit 7344ae6

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

kirby-sri.php

+11-17
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,17 @@
1010
* @license MIT
1111
*/
1212

13-
if(!c::get('plugin.kirby-sri')) return;
13+
if (c::get('plugin.kirby-sri', false)) {
14+
// Loading SRI helper function
15+
require_once __DIR__ . DS . 'utility' . DS . 'helper.php';
1416

15-
// Helper function generating base64-encoded SRI hashes
16-
function sri_checksum($input) {
17-
$algorithm = c::get('plugin.kirby-sri.algorithm', 'sha512');
18-
$hash = hash($algorithm, $input, true);
19-
$hash_base64 = base64_encode($hash);
17+
// Loading core
18+
load([
19+
'kirby\\plugins\\sri\\css' => __DIR__ . DS . 'core' . DS . 'css.php',
20+
'kirby\\plugins\\sri\\js' => __DIR__ . DS . 'core' . DS . 'js.php'
21+
]);
2022

21-
return "$algorithm-$hash_base64";
23+
// Registering with Kirby's extension registry
24+
kirby()->set('component', 'css', 'Kirby\Plugins\\SRI\\CSS');
25+
kirby()->set('component', 'js', 'Kirby\Plugins\\SRI\\JS');
2226
}
23-
24-
// Loading core
25-
load([
26-
'kirby\\plugins\\sri\\css' => __DIR__ . DS . 'core' . DS . 'css.php',
27-
'kirby\\plugins\\sri\\js' => __DIR__ . DS . 'core' . DS . 'js.php'
28-
]);
29-
30-
// Registering with Kirby's extension registry
31-
kirby()->set('component', 'css', 'Kirby\Plugins\\SRI\\CSS');
32-
kirby()->set('component', 'js', 'Kirby\Plugins\\SRI\\JS');

utility/helper.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Kirby\Plugins\SRI;
4+
5+
use c;
6+
7+
// Helper function generating base64-encoded SRI hashes
8+
function sri_checksum($input)
9+
{
10+
$algorithm = c::get('plugin.kirby-sri.algorithm', 'sha512');
11+
$hash = hash($algorithm, $input, true);
12+
$hash_base64 = base64_encode($hash);
13+
14+
return "$algorithm-$hash_base64";
15+
}

0 commit comments

Comments
 (0)