forked from hibbitts-design/grav-theme-learn2-git-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
learn2-git-sync.php
139 lines (125 loc) · 3.78 KB
/
learn2-git-sync.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
namespace Grav\Theme;
use Grav\Common\Grav;
use Grav\Common\Theme;
use RocketTheme\Toolbox\Event\Event;
class Learn2GitSync extends Learn2
{
/**
* Initialize plugin and subsequent events
*
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onTwigInitialized' => ['onTwigInitialized', 0],
'onThemeInitialized' => ['onThemeInitialized', 0],
'onShortcodeHandlers' => ['onShortcodeHandlers', 0],
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
'onTNTSearchIndex' => ['onTNTSearchIndex', 0],
'registerNextGenEditorPlugin' => ['registerNextGenEditorPluginShortcodes', 0]
];
}
public function onShortcodeHandlers()
{
$this->grav['shortcode']->registerAllShortcodes('user://themes/learn2-git-sync/shortcodes');
}
public function registerNextGenEditorPluginShortcodes($event) {
$plugins = $event['plugins'];
$plugins['js'][] = 'user://themes/learn2-git-sync/nextgen-editor/shortcodes/googleslides.js';
$plugins['js'][] = 'user://themes/learn2-git-sync/nextgen-editor/shortcodes/h5p.js';
$plugins['js'][] = 'user://themes/learn2-git-sync/nextgen-editor/shortcodes/pdf.js';
$event['plugins'] = $plugins;
return $event;
}
public function onTwigSiteVariables()
{
if ($this->isAdmin() && ($this->grav['config']->get('plugins.shortcode-core.enabled'))) {
$this->grav['assets']->add('theme://editor-buttons/admin/js/shortcode-presentation.js');
}
}
public function onTNTSearchIndex(Event $e)
{
$fields = $e['fields'];
$page = $e['page'];
$taxonomy = $page->taxonomy();
if (isset($taxonomy['tag'])) {
$fields->tag = implode(",", $taxonomy['tag']);
}
}
public function onTwigInitialized() {
$sc = $this->grav['shortcode'];
$sc->getHandlers()->addAlias('version', 'lang');
}
/**
* Register events and route with Grav
*
* @return void
*/
public function onThemeInitialized()
{
/* Check if Admin-interface */
if (!$this->isAdmin()) {
$this->enable(
[
'onPageInitialized' => ['onPageInitialized', 0]
]
);
}
}
/**
* Get default category setting
*
* @return string
*/
public static function getdefaulttaxonomycategory()
{
$config = Grav::instance()['config'];
return $config->get('themes.' . $config->get('system.pages.theme'). '.default_taxonomy_category');
}
/**
* Handle CSS
*
* @return void
*/
public function onPageInitialized()
{
$assets = $this->grav['assets'];
$config = $this->config();
if (isset($config['style'])) {
$style = $config['style'];
if ($style == 'default') {
$style = 'theme';
}
$current = self::fileFinder(
$style,
'.css',
'theme://css/styles',
'theme://css'
);
$assets->addCss($current, 101);
}
}
/**
* Search for a file in multiple locations
*
* @param string $file Filename.
* @param string $ext File extension.
* @param array ...$locations List of paths.
*
* @return string
*/
public static function fileFinder($file, $ext, ...$locations)
{
$return = false;
foreach ($locations as $location) {
if (file_exists($location . '/' . $file . $ext)) {
$return = $location . '/' . $file . $ext;
break;
}
}
return $return;
}
}
?>