This repository has been archived by the owner on Jan 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
133 lines (121 loc) · 4.72 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
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
<?php
use Pagekit\Application as App;
use Spqr\Assets\Model\Asset;
return [
'name' => 'spqr/assets',
'type' => 'extension',
'main' => function ($app) {
},
'autoload' => [
'Spqr\\Assets\\' => 'src'
],
'routes' => [
'/assets' => [
'name' => '@assets',
'controller' => [
'Spqr\\Assets\\Controller\\AssetsController',
'Spqr\\Assets\\Controller\\AssetController'
]
],
'/api/assets' => [
'name' => '@assets/api',
'controller' => [
'Spqr\\Assets\\Controller\\AssetApiController'
]
]
],
'widgets' => [],
'menu' => [
'assets' => [
'label' => 'Assets',
'url' => '@assets/asset',
'active' => '@assets/asset*',
'icon' => 'spqr/assets:icon.svg'
],
'assets: asset' => [
'parent' => 'assets',
'label' => 'Assets',
'icon' => 'spqr/assets:icon.svg',
'url' => '@assets/asset',
'access' => 'assets: manage assets',
'active' => '@assets/asset*'
],
'assets: settings' => [
'parent' => 'assets',
'label' => 'Settings',
'url' => '@assets/settings',
'access' => 'assets: manage settings'
]
],
'permissions' => [
'assets: manage settings' => [
'title' => 'Manage settings'
],
'assets: manage assets' => [
'title' => 'Manage assets'
]
],
'settings' => '@assets/settings',
'resources' => [
'spqr/assets:' => ''
],
'config' => [
'caching' => true,
'items_per_page' => 20,
],
'events' => [
'boot' => function ($event, $app) {
},
'site' => function ($event, $app) {
$app->on('view.content', function ($event, $scripts) use ($app) {
$config = $this->config;
foreach ($assets = Asset::where(['status = ?'], [Asset::STATUS_PUBLISHED])->get() as $asset) {
if ((!$asset->nodes || in_array($app[ 'node' ]->id, $asset->nodes))) {
$lang = $asset->get('lang');
$type = $asset->get('type');
$execution = $asset->get('execution');
$slug = $asset->slug;
$options = [];
$dependencies = [];
if ($config[ 'caching' ] && $type != 'url') {
$hash =
substr(sha1($app->system()->config('secret') . date_format($asset->modified,
'd/m/Y H:i:s')), 0, 4);
$options[ 'version' ] = $hash;
}
if ($type == 'url') {
$content = $asset->get('url');
} elseif ($type == 'inline') {
$content = $asset->get('content');
$options = 'string';
} elseif ($type == 'file') {
$content = 'spqr/assets:assets/custom/' . $asset->get('filename');
} else {
$content = '';
}
if ($lang == 'js') {
if ($type == 'url' || $type == 'file') {
if ($execution == 'deferred') {
$options[ 'defer' ] = true;
}
if ($execution == 'async') {
$options[ 'async' ] = true;
}
if (!empty($asset->get('dependencies'))) {
foreach ($asset->get('dependencies') as $key => $dependency) {
if ($dependency === true) {
$dependencies[] = $key;
}
}
}
}
$app[ 'scripts' ]->add($slug, $content, $dependencies, $options);
} elseif ($lang == 'css') {
$app[ 'styles' ]->add($slug, $content, [], $options);
}
}
}
});
}
]
];