-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·52 lines (52 loc) · 1.69 KB
/
index.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
<?php
Kirby::plugin('studioscholz/slug-to-id', [
'routes' => function ($kirby) {
return [
[
'pattern' => 'slug-to-id',
'method' => 'GET',
'action' => function () {
$base = kirby()->root('site');
// Include languages
$languageFiles = glob($base . '/languages' . '/*.php');
$languages = array();
foreach ($languageFiles as $language) {
$languages[] = include $language;
}
$currentLanguage = kirby()->language();
// Define data
$data = [];
// Merge pages
$allPages = kirby()->site()->index();
// Translate
foreach($allPages as $entry) {
foreach($languages as $language) {
$parents = $entry->parents()->flip();
$slug = '/';
// Add language code
$slug .= $language['code'] != $currentLanguage ? $language['code'] : '';
// Add slash for language code
if($language['code'] != $currentLanguage && $entry->slug($language['code']) != 'index') {
$slug .= '/';
}
// Add all parents’ slugs
foreach($parents as $parent) {
$slug .= $parent->slug($language['code']) . '/';
}
// Add page slug
if($entry->slug($language['code']) != 'index') {
$slug .= $entry->slug($language['code']);
}
// Add entry
$data[$language['code']][$slug] = $entry->id();
}
}
return [
'status' => 'ok',
'data' => $data
];
}
]
];
}
]);