-
Notifications
You must be signed in to change notification settings - Fork 0
/
mixitup.php
71 lines (63 loc) · 1.84 KB
/
mixitup.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
<?php
namespace Grav\Plugin;
use Grav\Common\Plugin;
use Grav\Common\Grav;
use Grav\Common\Page\Page;
use Grav\Common\Taxonomy;
use RocketTheme\Toolbox\Event\Event;
class MixitupPlugin extends Plugin
{
/**
* @return array
*/
public static function getSubscribedEvents() {
return [
'onPageInitialized' => ['onPageInitialized', 0],
'onGetPageTemplates' => ['onGetPageTemplates', 0],
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
];
}
/**
* Add current directory to twig lookup paths.
*/
public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
/**
* Initialize configuration
*/
public function onPageInitialized()
{
$defaults = (array) $this->config->get('plugins.mixitup');
/** @var Page $page */
$page = $this->grav['page'];
if (isset($page->header()->mixitup)) {
$page->header()->mixitup = array_merge($defaults, $page->header()->mixitup);
} else {
$page->header()->mixitup = $defaults;
}
}
/**
* Add page template types.
*/
public function onGetPageTemplates(Event $event)
{
/** @var Types $types */
$types = $event->types;
$types->scanTemplates('plugins://mixitup/templates');
}
/**
* Include required css and js files.
*/
public function onTwigSiteVariables()
{
if ($this->config->get('plugins.mixitup.built_in_css')) {
$this->grav['assets']
->add('plugin://mixitup/css/mixitup-core.css')
->add('plugin://mixitup/css/mixitup-custom.css')
->add('plugin://mixitup/js/jquery.mixitup.min.js');
}
}
}