-
Notifications
You must be signed in to change notification settings - Fork 0
/
acronym.php
54 lines (44 loc) · 1.43 KB
/
acronym.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Grav\Plugin;
use Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
class AcronymPlugin extends Plugin
{
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onPageContentRaw' => ['onPageContentRaw', 0]
];
}
public function onPageContentRaw(Event $event)
{
// Defined acronyms
$acronyms = $this->config->get('plugins.acronym.acronyms', array());
$page = $event['page'];
$config = $this->mergeConfig($page);
$enabled = $config->get('enabled');
// Check that page processes markdown
$enabled = $enabled && $page->process()['markdown'];
// Check that markdown extra is enabled
if (isset($page->header()->markdown) &&
array_key_exists('extra', $page->header()->markdown)) {
$enabled = $enabled && $page->header()->markdown['extra'];
} else {
$enabled = $enabled && $this->config->get('system.pages.markdown.extra');
}
if ($enabled && (count($acronyms) > 0)) {
// Get initial content
$raw = $page->getRawContent();
$raw .= "\n\n";
// Append acronyms to page
foreach ($acronyms as $key => $value) {
$raw .= "*[${key}]: ${value}\n";
}
// Put content back in
$page->setRawContent($raw);
}
}
}