forked from hibbitts-design/grav-theme-learn2-git-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlearn2-git-sync.php
121 lines (111 loc) · 3.02 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
<?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],
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
'onTNTSearchIndex' => ['onTNTSearchIndex', 0]
];
}
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;
}
}
?>