-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme.php
236 lines (181 loc) · 6.41 KB
/
theme.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
namespace Grav\Theme;
use Grav\Common\Plugin;
use Grav\Common\Theme;
use Grav\Plugin\Admin\Admin;
use Gantry\Framework\Gantry;
use Gantry\Framework\Theme as GantryTheme;
use Grav\Common\Grav;
use RocketTheme\Toolbox\Event\Event;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
class Neocatema extends Theme
{
public $gantry = '5.4.37';
/**
* @var GantryTheme
*/
protected $theme;
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onAdminMenu' => ['onAdminMenu', 0],
'onBuildPagesInitialized' => ['propertiesPrepare',0],
'onGetPageBlueprints' => ['onGetPageBlueprints', 0],
'onGetPageTemplates' => ['onGetPageTemplates', 0],
'onOutputGenerated' => ['onOutputGenerated', 0],
'onThemeInitialized' => ['onThemeInitialized', 0],
'onTwigExtensions' => ['onTwigExtensions', 0],
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
];
}
public function getgantry_outline() {
$gantry = Gantry::instance();
$array = $gantry['outlines']->all()->toArray();
return $array;
}
public function propertiesPrepare()
{
require_once(__DIR__.'/php/ncc-util.php');
$cores = ncc_filedir(__DIR__.'/js/core/','*.js');
$modules = ncc_filedir(__DIR__.'/js/modules/','*.js');
$str = "/* to recompile this file, clear your grav cache\n";
$str .= " => ". __DIR__;
$str .= "\n*/\n";
foreach ($cores as $m) {
//$str .= "/* = ".$m['file'] ." */";
$str .= ncc_compact( file_get_contents($m['rfile']) );
}
foreach ($modules as $m) {
//$str .= "/* = ".$m['file'] ." */";
$str .= "\n/*- ".$m['base']." -*/\n";
$str .= ncc_compact( file_get_contents($m['rfile']) );
}
file_put_contents(__DIR__.'/js/module.min.js',$str);
}
public function onAdminMenu()
{
$theme_name = $this->name;
$this->grav['assets']->add("user://themes/$theme_name/admin/css/poko.css",1);
$this->grav['assets']->add("user://themes/$theme_name/js/core/w3color.js");
$this->grav['assets']->add("user://themes/$theme_name/admin/js/poko.js");
}
public function webcheck() {
$array=[];
$barray=[];
$array[] = "<tr><td>DOCUMENT_ROOT</td><td><input type='text' value='". $_SERVER['DOCUMENT_ROOT']. "' ></td></tr>";
$array[] = "<tr><td>GRAV_ROOT</td><td><input type='text' value='". GRAV_ROOT ."' ></td></tr>";
$array[] = "<tr><td>DIR</td><td><input type='text' value='". __DIR__ ."' ></td></tr>";
return "<table class='ncc_enviro'>".join("",$array)."</table>";
}
public function onThemeInitialized()
{
if (defined('GRAV_CLI') && GRAV_CLI) {
return;
}
$locator = $this->grav['locator'];
$path = $locator('theme://');
$name = $this->name;
if (!class_exists('\Gantry5\Loader')) {
if ($this->isAdmin()) {
$messages = $this->grav['messages'];
$messages->add('Please enable Gantry 5 plugin in order to use current theme!', 'error');
return;
} else {
throw new \LogicException('Please install and enable Gantry 5 Framework plugin!');
}
}
// Setup Gantry 5 Framework or throw exception.
\Gantry5\Loader::setup();
// Get Gantry instance.
$gantry = Gantry::instance();
// Set the theme path from Grav variable.
$gantry['theme.path'] = $path;
$gantry['theme.name'] = $name;
// Define the template.
require $locator('theme://includes/theme.php');
require_once(__DIR__.'/php/ncc-util.php');
/* check and create the workspace's path */
create_ifnotexists($locator('user://').'/workspace/templates');
create_ifnotexists($locator('user://').'/workspace/blueprints');
create_ifnotexists($locator('user://').'/workspace/css');
create_ifnotexists($locator('user://').'/workspace/scss');
create_ifnotexists($locator('user://').'/workspace/js');
create_ifnotexists($locator('user://').'/workspace/assets');
/* touch the needed files */
create_ifnotexists($locator('user://').'/workspace/js/script.js','touch');
create_ifnotexists($locator('user://').'/workspace/css/grav.css','touch');
/* copy file from theme/skeleton */
create_ifnotexists($locator('user://').'/workspace/scss/grav.scss',
'copy',__DIR__.'/skel/workspace/scss/grav.scss');
create_ifnotexists($locator('user://').'/workspace/scss/gantry.scss',
'copy',__DIR__.'/skel/workspace/scss/gantry.scss');
create_ifnotexists($locator('user://').'/workspace/scss/_custom.scss',
'copy',__DIR__.'/skel/workspace/scss/_custom.scss');
create_ifnotexists($locator('user://').'/workspace/scss-watch.sh',
'copy',__DIR__.'/skel/workspace/scss-watch.sh');
/* for particles */
// create_ifnotexists($locator('user://')."/data/gantry5/themes/$name/particles");
// Define Gantry services.
$gantry['theme'] = function ($c) {
return new \Gantry\Theme\Neoca($c['theme.path'], $c['theme.name']);
};
}
public function onTwigSiteVariables()
{
$locator = $this->grav['locator'];
$adminCookieSuffix = '-admin';
$this->adminCookie = session_name() . $adminCookieSuffix;
$this->config->set('buf',[]);
/* Provide {{ config.gas }} */
if (isset($_COOKIE[$this->adminCookie]) === true) {
$this->config->set('gas.admin',true);
}
}
public function onTwigExtensions()
{
require_once(__DIR__.'/php/ncc-TwigExtension.php');
$this->grav['twig']->twig->addExtension(new nccTwigExtension());
}
public function onTwigTemplatePaths()
{
$locator = $this->grav['locator'];
$this->grav['twig']->twig_paths[] = $locator('user://workspace/templates');
}
public function onGetPageTemplates(Event $event)
{
$types = $event->types;
$types->scanTemplates('user://workspace/templates');
}
public function onGetPageBlueprints(Event $event)
{
$types = $event->types;
$types->scanBlueprints('user://workspace/blueprints');
}
public function onOutputGenerated()
{
require_once(__DIR__.'/php/ncc-util.php');
if (! $this->isAdmin()) {
if (isset($this->config['theme']['tidy_output'])) {
$this->grav->output = ncc_tidyup($this->grav->output."");
}
if (isset($this->config['plugins']['neocaprima']['static_path'])) {
/* require neocaprima plugins */
$tdir = GRAV_ROOT.'/'. $this->config['plugins']['neocaprima']['static_path'];
ncc_generate_staticpages(
$this->grav->output,
$tdir.$this->grav['uri']->path(),
__DIR__."/skel",
$tdir,
$this->config['plugins']['neocaprima']['static_path'],
$this->config['plugins']['neocaprima']['rewrite'],
$this->grav['assets']['js_pipeline'],
$this->grav['assets']['css_pipeline']
);
}
}
}
}