This repository has been archived by the owner on Jan 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.php
163 lines (140 loc) · 5.41 KB
/
config.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
<?php
use \attitude\Elements\HTTPException;
use \attitude\Elements\DependencyContainer;
use \attitude\Elements\Boot_Element;
use \attitude\Elements\Request_Element;
use \attitude\FlatYAMLDB\ContentDB_Element;
use \attitude\FlatYAMLDB\TranslationsDB_Element;
use \attitude\Mustache\DataPreprocessor_Component;
use \attitude\Mustache\AtomicLoader_FilesystemLoader;
use \attitude\Mustache\AtomicLoader_MacawLoader;
use \attitude\Mustache\AtomicLoader_AssetsConcatenator;
// Identify language attributes for data translations
DependencyContainer::set('global::languageRegex', '/^(?:[a-z]{2}|[a-z]{2}_[A-Z]{2})$/');
// Content database
// Yaml file source
DependencyContainer::set('global::contentDBFile', APP_ROOT_DIR.'/db/content.yaml');
// Set by what attribute to query DB
DependencyContainer::set(
'global::contentDBIndexes',
array(
'_id',
'_collection',
'_type',
'code',
'default',
'name',
'published',
'route',
'subtitle',
'tags',
'title',
)
);
// To use cache set false, to refresh on each load set true (e.g. for debugging)
DependencyContainer::set('global::contentDBNocache', false);
// Translations database
DependencyContainer::set('global::translationsDBFile', APP_ROOT_DIR.'/db/translations.yaml');
DependencyContainer::set('global::translationsDBIndexes', array());
DependencyContainer::set('global::translationsDBNocache', false);
// Money setup
// @TODO: use current language to provide settings
DependencyContainer::set('money::currency_prefix', false);
DependencyContainer::set('money::dec_point', ',');
// Set expanders
DependencyContainer::set('global::dataExpanders', array(
'link' => function($args) {
return DependencyContainer::get('global::db')->expanderLink($args);
},
'href' => function($args) {
return DependencyContainer::get('global::db')->expanderHref($args);
},
'title' => function($args) {
return DependencyContainer::get('global::db')->expanderTitle($args);
},
'query' => function($args) {
return DependencyContainer::get('global::db')->expanderQuery($args);
},
'content' => function($args) {
if (!isset($args[0])) {
throw new HTTPException(500, 'content() expander expects sequential array: `content(): [content_id_1, content_id_2, ...]');
}
$results = array();
foreach ((array) $args as $_args) {
$_args = array('_id' => $_args);
$_args['_type'] = 'content';
try {
$results[] = DependencyContainer::get('global::db')->expanderQuery($_args);
} catch (HTTPException $e) {}
}
return $results;
},
'copyrightYear' => function ($args) {
$Y = date('Y');
if (isset($args['since']) && $Y > $args['since']) {
return $Y;
}
return false;
}
));
// Set pluralisation logic for Slovak (and Czech also)
// English rules is used by default
DependencyContainer::set('global::language.pluralRules.skSelect', function($n) {
// Change 1,25 to 1.25 which is understood correctly as float
if (is_string($n)) {
$n = str_replace(',','.',$n);
}
if (intval($n) != $n) {
return TranslationsDB_Element::FRACTION;
}
if ($n == 1) {
return TranslationsDB_Element::ONE;
}
if ($n == ($n | 0) && $n >= 2 && $n <= 4) {
return TranslationsDB_Element::FEW;
}
return TranslationsDB_Element::OTHER;
});
// Czech has same rules
DependencyContainer::set('global::language.pluralRules.csSelect', DependencyContainer::get('global::language.pluralRules.skSelect'));
// Templating
$loader_args = array(
'publicDir' => WWW_ROOT_DIR,
'publicURL' => 'http'. (isset($_SERVER['SCHEME']) && $_SERVER['SCHEME']==='HTTPS' ? 's' : '').'://'.$_SERVER['HTTP_HOST'].'/',
'assets' => AtomicLoader_FilesystemLoader::getAssetDefaults()
);
// Cache path
DependencyContainer::set('global::mustacheCachePath', ROOT_DIR.'/cache/mustache');
DependencyContainer::set(
'global::mustacheViews',
new \Mustache_Loader_CascadingLoader(array(
new AtomicLoader_FilesystemLoader(WWW_ROOT_DIR.'/templates/views', $loader_args),
new AtomicLoader_MacawLoader(WWW_ROOT_DIR.'/macaw/templates/views', $loader_args)
))
);
DependencyContainer::set(
'global::mustachePartials',
new \Mustache_Loader_CascadingLoader(array(
new AtomicLoader_FilesystemLoader(WWW_ROOT_DIR.'/templates', $loader_args),
new AtomicLoader_MacawLoader(WWW_ROOT_DIR.'/macaw/templates', $loader_args)
))
);
// More Mustache helpers
DependencyContainer::set('global::markdownParser', new \Parsedown());
DependencyContainer::set('global::mustacheHelpers', array(
'markdown' => function($str) {
return DependencyContainer::get('global::markdownParser')->parse($str);
},
'csslinebreaks' => function($str) {
$lines = explode('<br>', preg_replace('/<br.*?\/?>/', '<br>', $str));
foreach ($lines as $i => &$line) {
$line = '<span class="csslinebreak csslinebreak--'.($i+1).'">'.$line.'</span>';
}
return implode('', $lines);
}
));
// Assets concatenation
$concatenation_args = $loader_args;
$concatenation_args['publicStaticDir'] = ASSETS_ROOT_DIR;
$concatenation_args['publicStaticURL'] = ASSETS_URL;
DependencyContainer::set('global::assetsConcantenator', new AtomicLoader_AssetsConcatenator(WWW_ROOT_DIR, $concatenation_args));