-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecipebook.php
74 lines (63 loc) · 1.9 KB
/
recipebook.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace Grav\Plugin;
use Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
/**
* Class RecipebookPlugin
* @package Grav\Plugin
*/
class RecipebookPlugin extends Plugin
{
public $features = [
'blueprints' => 100,
];
public function onPluginsInitialized()
{
if ($this->isAdmin()) {
return;
}
$this->enable([
'onTwigInitialized' => ['onTwigInitialized', 0]
]);
}
/**
* @return array
*
* The getSubscribedEvents() gives the core a list of events
* that the plugin wants to listen to. The key of each
* array section is the event that the plugin listens to
* and the value (in the form of an array) contains the
* callable (or function) as well as the priority. The
* higher the number the higher the priority.
*/
public static function getSubscribedEvents(): array
{
return [
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0]
, 'onPluginsInitialized' => ['onPluginsInitialized', 0]
];
}
public function onTwigInitialized(Event $e)
{
$this->grav['twig']->twig()->addFilter(
new \Twig_SimpleFilter('vulgarize', [$this, 'vulgarizeString'])
);
}
public function vulgarizeString($string)
{
$search = array(
'1/2', '1/4', '3/4', '1/7', '1/9', '1/10', '1/3', '2/3', '1/5'
, '2/5', '3/5', '4/5', '1/6', '5/6', '1/8', '3/8', '5/8', '7/8'
);
$replace = array(
'½', '¼', '¾', '⅐', '⅑', '⅒', '⅓', '⅔', '⅕', '⅖', '⅗', '⅘'
, '⅙', '⅚', '⅛', '⅜', '⅝', '⅞'
);
return str_replace($search, $replace, $string);
}
public function onTwigTemplatePaths()
{
$twig = $this->grav['twig'];
$twig->twig_paths[] = __DIR__ . '/templates';
}
}