-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
97 lines (83 loc) · 3.05 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
<?php
/*
* Bear CMS addon for Bear Framework
* https://bearcms.com/
* Copyright (c) Amplilabs Ltd.
* Free to use under the MIT license.
*/
use BearFramework\App;
use BearCMS\Internal;
$app = App::get();
$context = $app->contexts->get(__DIR__);
$context->classes
->add('BearCMS', 'classes/BearCMS.php')
->add('BearCMS\*', 'classes/BearCMS/*.php');
$context->assets
->addDir('assets');
$app->assets
->addDir('appdata://bearcms/files/themeimage/')
->addDir('appdata://bearcms/files/elementstyleimage/')
->addDir('appdata://bearcms/files/canvasstyleimage/')
->addDir('appdata://bearcms/files/blog/')
->addDir('appdata://bearcms/files/video/')
->addDir('appdata://bearcms/files/videoposter/')
->addDir('appdata://bearcms/files/image/')
->addDir('appdata://bearcms/files/imagegallery/')
->addDir('appdata://bearcms/files/icon/')
->addDir('appdata://bearcms/files/page/')
->addDir('appdata://bearcms/files/font/')
->addDir('appdata://.temp/bearcms/files/themeimage/')
->addDir('appdata://.temp/bearcms/files/elementstyleimage/')
->addDir('appdata://.temp/bearcms/files/canvasstyleimage/')
->addDir('appdata://.temp/bearcms/export/');
$app->localization
->addDictionary('en', function () use ($context) {
return include $context->dir . '/locales/en.php';
})
->addDictionary('bg', function () use ($context) {
return include $context->dir . '/locales/bg.php';
})
->addDictionary('ru', function () use ($context) {
return include $context->dir . '/locales/ru.php';
});
$app->shortcuts
->add('bearCMS', function () {
return new BearCMS();
});
BearCMS\Internal2::initialize();
if ($app->request->method === 'GET' && (string)$app->request->path !== '/robots.txt') {
if (strpos($app->request->path, $app->assets->pathPrefix) !== 0) {
$cacheBundlePath = $app->request->path->get();
Internal\Data::loadCacheBundle($cacheBundlePath);
$app
->addEventListener('sendResponse', function () use ($cacheBundlePath) {
Internal\Data::saveCacheBundle($cacheBundlePath);
});
}
}
$app->data
->addEventListener('itemChange', function (\BearFramework\App\Data\ItemChangeEventDetails $details) use (&$app) {
$key = $details->key;
Internal\Data::onDataChanged($key);
$prefixes = [
'bearcms/pages/page/',
'bearcms/blog/post/'
];
foreach ($prefixes as $prefix) {
if (strpos($key, $prefix) === 0) {
$dataBundleID = 'bearcmsdataprefix-' . $prefix;
if ($app->data->exists($key)) {
$app->dataBundle->addItem($dataBundleID, $key);
} else {
$app->dataBundle->removeItem($dataBundleID, $key);
}
break;
}
}
});
$app
->addEventListener('sendResponse', function () use ($app) {
if (Internal\Data::$hasContentChange) {
$app->bearCMS->dispatchEvent('internalChangeData');
}
});