This repository has been archived by the owner on May 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
bootstrap.php
82 lines (70 loc) · 2.07 KB
/
bootstrap.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
<?php
/**
* Cockpit better slugs addon
*
* @author Paulo Gomes
* @package CockpitCMS-BetterSlugs
* @license MIT
*
* @source https://github.com/pauloamgomes/CockpitCMS-BetterSlugs
* @see { README.md } for usage info.
*/
$this->helpers['betterslugs'] = 'BetterSlugs\\Helper\\Utils';
$this->module('betterslugs')->extend([
'slugify' => function($name, $entry, $field, $isUpdate) {
$localize = $field['localize'] ?? FALSE;
$format = $field['options']['format'];
$fieldName = $field['name'];
// Only automate slug generation if field is empty.
if (empty($entry[$fieldName])) {
$slug = $this->app->helper('betterslugs')->generate($format, $name, $entry);
}
else {
$slug = $entry[$fieldName];
}
$slug = $this->app->helper('betterslugs')->getUnique($name, $slug, $fieldName, $entry['_id'] ?? NULL);
if ($localize) {
// Get enabled locales.
$locales = array_keys($this->app->retrieve('languages', []));
foreach ($locales as $locale) {
if ($locale === 'default') {
$locFieldName = $fieldName;
$lang = $this->app->config['i18n'];
}
else {
$locFieldName = "{$fieldName}_{$locale}";
$lang = $locale;
}
if (!array_key_exists($locFieldName, $entry)) {
continue;
}
if (empty($entry[$locFieldName])) {
$slug = $this->app->helper('betterslugs')->generate($format, $name, $entry, $lang);
}
else {
$slug = $entry[$locFieldName] ?? $entry[$fieldName] ?? '';
}
$entry[$locFieldName] = $slug;
}
}
else {
$entry[$fieldName] = $slug;
}
return $entry;
},
]);
// CLI includes.
if (COCKPIT_CLI) {
$this->path('#cli', __DIR__ . '/cli');
include_once __DIR__ . '/actions.php';
}
// Admin includes.
if (COCKPIT_ADMIN && !COCKPIT_API_REQUEST) {
include_once __DIR__ . '/admin.php';
include_once __DIR__ . '/actions.php';
}
// API includes.
if (COCKPIT_API_REQUEST) {
include_once __DIR__ . '/actions.php';
include_once __DIR__ . '/cockpitql.php';
}