-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme.php
435 lines (344 loc) · 13.7 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<?php
/**
This is the StartBootstrap-Scrolling-Nav theme.
This file contains the theme class of the StartBootstrap-Scrolling-Nav
theme.
@package urlaube\startbootstrap-scrolling-nav
@version 0.7a4
@author Yahe <[email protected]>
@since 0.1a0
*/
// ===== DO NOT EDIT HERE =====
// prevent script from getting called directly
if (!defined("URLAUBE")) { die(""); }
class StartBootstrapScrollingNav extends BaseHandler implements Plugin, Theme {
// CONSTANTS
const NAME = "name";
const MANDATORY = null;
const OPTIONAL = [self::NAME => null];
const REGEX = "~^\/".
"(?P<name>[0-9A-Za-z\_\-\/]*)".
"$~";
const REGEXCSS = "~^\/startbootstrap\-scrolling\-nav\.css$~";
// ABSTRACT FUNCTIONS
protected static function getResult($metadata, &$cachable) {
$result = null;
// only proceed when this is the active theme
if (0 === strcasecmp(static::class, value(Main::class, THEMENAME))) {
// this result may be cached
$cachable = true;
$name = value($metadata, static::NAME);
$result = callcontent($name, true, false,
function ($content) {
// filter out all results that are located in sub-folder
if (0 === strpos(value($content, URI), value(Main::class, URI))) {
$uri = notrail(substr(value($content, URI), strlen(value(Main::class, URI))), US);
if (false !== strpos($uri, US)) {
$content = null;
}
}
return $content;
});
}
return $result;
}
protected static function prepareMetadata($metadata) {
$metadata->set(static::NAME, trail(lead(value($metadata, static::NAME), US), US));
return $metadata;
}
// overwrite the default behaviour
public static function getUri($metadata) {
$result = null;
// prepare metadata for sanitization
$metadata = preparecontent($metadata, static::OPTIONAL, static::MANDATORY);
if ($metadata instanceof Content) {
// sanitize metadata
$metadata = preparecontent(static::prepareMetadata($metadata), static::OPTIONAL, static::MANDATORY);
if ($metadata instanceof Content) {
// get the base URI
$result = value(Main::class, ROOTURI);
// append the mandatory URI parts
$result .= nolead(value($metadata, static::NAME), US);
}
}
return $result;
}
// INTERFACE FUNCTIONS
public static function getContentCss($metadata, &$pagecount) {
return null;
}
public static function getUriCss($metadata) {
return value(Main::class, ROOTURI)."startbootstrap-scrolling-nav.css";
}
public static function parseUriCss($uri) {
$result = null;
$metadata = preparecontent(parseuri($uri, static::REGEXCSS));
if ($metadata instanceof Content) {
$result = $metadata;
}
return $result;
}
// HELPER FUNCTIONS
protected static function configureCss() {
Themes::preset(CSS, "");
Themes::preset("dark_color", "#666");
Themes::preset("light_color", "#ccc");
}
protected static function configureTheme() {
// individual theme configuration
Themes::preset("copyright_html", null);
Themes::preset("logo_url", null);
// recommended theme configuration
Themes::preset(AUTHOR, static::getDefaultAuthor());
Themes::preset(CANONICAL, static::getDefaultCanonical());
Themes::preset(CHARSET, static::getDefaultCharset());
Themes::preset(COPYRIGHT, static::getDefaultCopyright());
Themes::preset(DESCRIPTION, static::getDefaultDescription());
Themes::preset(FAVICON, null);
Themes::preset(KEYWORDS, static::getDefaultKeywords());
Themes::preset(LANGUAGE, static::getDefaultLanguage());
Themes::preset(LOGO, null);
Themes::preset(MENU, null);
Themes::preset(PAGENAME, static::getDefaultPagename());
Themes::preset(SITENAME, t("Deine Webseite", static::class));
Themes::preset(SITESLOGAN, t("Dein Slogan", static::class));
Themes::preset(TIMEFORMAT, "d.m.Y");
Themes::preset(TITLE, static::getDefaultTitle());
}
protected static function getDefaultAuthor() {
$result = null;
// try to retrieve the first author
foreach (value(Main::class, CONTENT) as $content_item) {
if ($content_item->isset(AUTHOR)) {
$result = value($content_item, AUTHOR);
break;
}
}
return $result;
}
protected static function getDefaultCanonical() {
$result = null;
// do not set a canonical URI on error
if (ErrorHandler::class !== Handlers::getActive()) {
$result = value(Main::class, URI);
}
return $result;
}
protected static function getDefaultCharset() {
return strtolower(value(Main::class, CHARSET));
}
protected static function getDefaultCopyright() {
return "Copyright ©".SP.value(Themes::class, SITENAME).SP.date("Y");
}
protected static function getDefaultDescription() {
$result = null;
// get the first entry of the content entries
if (0 < count(value(Main::class, CONTENT))) {
if (value(Main::class, CONTENT)[0]->isset(CONTENT)) {
// remove all HTML tags and replace line breaks with spaces
$result = substr(strtr(strip_tags(value(value(Main::class, CONTENT)[0], CONTENT)),
["\r\n" => SP, "\n" => SP, "\r" => SP]),
0, 300);
}
}
return $result;
}
protected static function getDefaultKeywords() {
$result = null;
// retrieve all words from the titles
$words = [];
foreach (value(Main::class, CONTENT) as $content_item) {
if ($content_item->isset(TITLE)) {
$words = array_merge($words, explode(SP, value($content_item, TITLE)));
}
}
// filter all words that do not fit the scheme
for ($index = count($words)-1; $index >= 0; $index--) {
if (1 !== preg_match("~^[0-9A-Za-z\-]+$~", $words[$index])) {
unset($words[$index]);
}
}
$result = implode(DP.SP, $words);
return $result;
}
protected static function getDefaultLanguage() {
$result = strtolower(value(Main::class, LANGUAGE));
// only take the first part if the language is of the form "ab_xy"
if (1 === preg_match("~^([a-z]+)\_[a-z]+$~", $result, $matches)) {
if (2 === count($matches)) {
$result = $matches[1];
}
}
return $result;
}
protected static function getDefaultPagename() {
$result = null;
// convert the METADATA to a pagename
$metadata = value(Main::class, METADATA);
if ($metadata instanceof Content) {
switch (Handlers::getActive()) {
case ArchiveHandler::class:
if ((null !== value($metadata, ArchiveHandler::DAY)) ||
(null !== value($metadata, ArchiveHandler::MONTH)) ||
(null !== value($metadata, ArchiveHandler::YEAR))) {
$result = t("Archiv", StartBootstrapScrollingNav::class).COL.SP;
$parts = [];
if (null !== value($metadata, ArchiveHandler::DAY)) {
$parts[] .= t("Tag", StartBootstrapScrollingNav::class).SP.value($metadata, ArchiveHandler::DAY);
}
if (null !== value($metadata, ArchiveHandler::MONTH)) {
$parts[] .= t("Monat", StartBootstrapScrollingNav::class).SP.value($metadata, ArchiveHandler::MONTH);
}
if (null !== value($metadata, ArchiveHandler::YEAR)) {
$parts[] .= t("Jahr", StartBootstrapScrollingNav::class).SP.value($metadata, ArchiveHandler::YEAR);
}
$result .= implode(DP.SP, $parts);
}
break;
case AuthorHandler::class:
$result = t("Autor", StartBootstrapScrollingNav::class).COL.SP.value($metadata, AUTHOR);
break;
case CategoryHandler::class:
$result = t("Kategorie", StartBootstrapScrollingNav::class).COL.SP.value($metadata, CATEGORY);
break;
case SearchHandler::class:
$result = t("Suche", StartBootstrapScrollingNav::class).COL.SP.strtr(value($metadata, SEARCH), DOT, SP);
break;
}
}
return $result;
}
protected static function getDefaultTitle() {
$result = "";
// prepare the site title
if (null !== value(Themes::class, SITENAME)) {
$result = value(Themes::class, SITENAME);
}
if (null !== value(Themes::class, SITESLOGAN)) {
// only use separator if the result already contains text
if (0 < strlen($result)) {
$result = $result.SP."-".SP;
}
$result = $result.value(Themes::class, SITESLOGAN);
}
// prepare the page title
if (null !== value(Themes::class, PAGENAME)) {
// only use separator if the result already contains text
if (0 < strlen($result)) {
$result = SP."|".SP.$result;
}
$result = value(Themes::class, PAGENAME).$result;
} else {
// handle errors and pages
if ((ErrorHandler::class === Handlers::getActive()) ||
(PageHandler::class === Handlers::getActive())) {
// get the first entry of the content entries
if (0 < count(value(Main::class, CONTENT))) {
if (value(Main::class, CONTENT)[0]->isset(TITLE)) {
// only use separator if the result already contains text
if (0 < strlen($result)) {
$result = SP."|".SP.$result;
}
$result = value(value(Main::class, CONTENT)[0], TITLE).$result;
}
}
}
}
return $result;
}
// SOURCECODE HELPER FUNCTION
public static function cleanString($string) {
$result = $string;
if (is_string($result)) {
$result = preg_replace('@[^0-9a-z\-]@', '', strtolower($result));
}
return $result;
}
// RUNTIME FUNCTIONS
public static function css() {
$result = false;
// only proceed when this is the active theme
if (0 === strcasecmp(static::class, value(Main::class, THEMENAME))) {
$metadata = static::parseUriCss(relativeuri());
if (null !== $metadata) {
// check if the URI is correct
$fixed = static::getUriCss($metadata);
if (0 !== strcmp(value(Main::class, URI), $fixed)) {
relocate($fixed.querystring(), false, true);
} else {
// preset handler configuration
static::configureCss();
// generate the CSS file output
require_once(__DIR__.DS."startbootstrap-scrolling-nav.css.php");
}
// we handled this page
$result = true;
}
}
return $result;
}
public static function plugin($argument) {
$result = $argument;
// only proceed when this is the active theme
if (0 === strcasecmp(static::class, value(Main::class, THEMENAME))) {
$result = preparecontent($result, null, [Plugins::ENTITY]);
if (null !== $result) {
// make sure that we only handle arrays
if ($result instanceof Content) {
$result = [$result];
}
$unsupported = [ArchiveHandler::class,
AuthorHandler::class,
CategoryHandler::class,
FeedHandler::class,
PageHandler::class,
SearchHandler::class,
SitemapXmlHandler::class];
// iterate through the handlers and unset unsupported ones
foreach ($result as $key => $value) {
if (in_array(value($value, Plugins::ENTITY), $unsupported)) {
unset($result[$key]);
}
}
}
}
return $result;
}
public static function theme() {
$result = false;
// we do not handle empty content
$content = preparecontent(value(Main::class, CONTENT));
if (null !== $content) {
// make sure that we only handle arrays
if ($content instanceof Content) {
Main::set(CONTENT, [$content]);
}
// preset theme configuration
static::configureTheme();
// generate the head output
Plugins::run(BEFORE_HEAD);
require_once(__DIR__.DS."head.php");
Plugins::run(AFTER_HEAD);
// generate the body output
Plugins::run(BEFORE_BODY);
require_once(__DIR__.DS."body.php");
Plugins::run(AFTER_BODY);
// generate the footer output
Plugins::run(BEFORE_FOOTER);
require_once(__DIR__.DS."footer.php");
Plugins::run(AFTER_FOOTER);
// we handled this page
$result = true;
}
return $result;
}
}
// register handlers
Handlers::register(StartBootstrapScrollingNav::class, "css", StartBootstrapScrollingNav::REGEXCSS, [GET, POST], ADDSLASH);
Handlers::register(StartBootstrapScrollingNav::class, "run", StartBootstrapScrollingNav::REGEX, [GET, POST], USER);
// register plugin
Plugins::register(StartBootstrapScrollingNav::class, "plugin", FILTER_HANDLERS);
// register theme
Themes::register(StartBootstrapScrollingNav::class, "theme", StartBootstrapScrollingNav::class);
// register translation
Translate::register(__DIR__.DS."lang".DS, StartBootstrapScrollingNav::class);