-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.php
249 lines (227 loc) · 6.98 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
use Concrete\Core\Multilingual\Page\Section\Section;
use Concrete\Core\Support\Facade\Application;
use Xanweb\Helper\Arr;
use Xanweb\Helper\Path;
use Xanweb\Helper\Str;
if (!function_exists('c5app')) {
/**
* Resolve the given type from the container.
*
* @param string|null $abstract
* @param array $parameters
*
* @return mixed
*/
function c5app(?string $abstract = null, array $parameters = [])
{
$app = Application::getFacadeApplication();
if ($abstract === null) {
return $app;
}
return $app->make($abstract, $parameters);
}
}
if (!function_exists('strip_spaces')) {
/**
* Remove all spaces from the given string.
*
* @param string $string
*
* @return string
*/
function strip_spaces(string $string): string
{
return Str::stripSpaces($string);
}
}
if (!function_exists('remove_accents')) {
/**
* Replace special chars with normal ones.
*
* @param string $string with accents
*
* @return string
*/
function remove_accents(string $string): string
{
return Str::removeAccents($string);
}
}
if (!function_exists('absolute_path')) {
/**
* Get absolute path from relative.
*
* @param string $relativePath relative path
*
* @return string
*/
function absolute_path(string $relativePath): string
{
return Path::getAbsolutePath($relativePath);
}
}
if (!function_exists('is_absolute_path')) {
/**
* Check if path is absolute.
*
* @param string $path
*
* @return bool
*/
function is_absolute_path(string $path): bool
{
return Path::isAbsolutePath($path);
}
}
if (!function_exists('theme_path')) {
/**
* Get theme relative path.
*
* @return string
*/
function theme_path(): string
{
static $themePath;
if (!$themePath) {
$themePath = PageTheme::getSiteTheme()->getThemeURL();
}
return $themePath;
}
}
if (!function_exists('active_language')) {
/**
* Get Active Contextual Language en|de...
*
* @return string
*/
function active_language(): string
{
return Localization::activeLanguage();
}
}
if (!function_exists('active_locale')) {
/**
* Get Active Contextual Locale en_US|de_DE...
*
* @return string
*/
function active_locale(): string
{
return Localization::activeLocale();
}
}
if (!function_exists('current_language')) {
/**
* Get Active Site Language en|de...
*
* @return string
*/
function current_language(): string
{
return \current(\explode('_', current_locale()));
}
}
if (!function_exists('current_locale')) {
/**
* Get Current Page Locale.
*
* @return string
*/
function current_locale(): string
{
$section = Section::getCurrentSection();
$locale = is_object($section) ? $section->getLocale() : null;
return $locale ?? Localization::activeLocale();
}
}
if (!function_exists('getRandomItemByInterval')) {
/**
* Get random item that its position is between zero and the maximal value (ItemsCount).
*
* @param $timeBase
* @param $array
*
* @return mixed
*/
function getRandomItemByInterval($timeBase, $array)
{
$randomIndexPos = (((int) $timeBase) % count($array));
return $array[$randomIndexPos];
}
}
if (!function_exists('c5_date_format_custom')) {
/**
* An Alias of \Concrete\Core\Localization\Service\Date::formatCustom().
*
* Render a date/time as a localized string, by specifying a custom format.
*
* @param string $format The custom format (see http://www.php.net/manual/en/function.date.php for applicable formats)
* @param mixed $value The date/time representation (one of the values accepted by toDateTime)
* @param string $toTimezone The timezone to set. Special values are:<ul>
* <li>'system' for the current system timezone</li>
* <li>'user' (default) for the user's timezone</li>
* <li>'app' for the app's timezone</li>
* <li>Other values: one of the PHP supported time zones (see http://us1.php.net/manual/en/timezones.php )</li>
* </ul>
* @param string $fromTimezone The original timezone of $value (useful only if $value is a string like '2000-12-31 23:59'); it accepts the same values as $toTimezone
*
* @return string Returns an empty string if $value couldn't be parsed, the localized string otherwise
*/
function c5_date_format_custom($format, $value = 'now', $toTimezone = 'user', $fromTimezone = 'system')
{
return c5app('date')->formatCustom($format, $value, $toTimezone, $fromTimezone);
}
}
if (!function_exists('c5_date_format')) {
/**
* An Alias of \Concrete\Core\Localization\Service\Date::formatDate().
*
* Render the date part of a date/time as a localized string.
*
* @param mixed $value $The date/time representation (one of the values accepted by toDateTime)
* @param string $format the format name; it can be 'full' (eg 'EEEE, MMMM d, y' - 'Wednesday, August 20, 2014'), 'long' (eg 'MMMM d, y' - 'August 20, 2014'), 'medium' (eg 'MMM d, y' - 'August 20, 2014') or 'short' (eg 'M/d/yy' - '8/20/14'),
* or a skeleton pattern prefixed by '~', e.g. '~yMd'.
* You can also append a caret ('^') or an asterisk ('*') to $width. If so, special day names may be used (like 'Today', 'Yesterday', 'Tomorrow' with '^' and 'today', 'yesterday', 'tomorrow' width '*') instead of the date.
* @param string $toTimezone The timezone to set. Special values are:<ul>
* <li>'system' for the current system timezone</li>
* <li>'user' (default) for the user's timezone</li>
* <li>'app' for the app's timezone</li>
* <li>Other values: one of the PHP supported time zones (see http://us1.php.net/manual/en/timezones.php )</li>
* </ul>
*
* @return string Returns an empty string if $value couldn't be parsed, the localized string otherwise
*/
function c5_date_format($value = 'now', $format = 'short', $toTimezone = 'user')
{
return c5app('date')->formatDate($value, $format, $toTimezone);
}
}
if (!function_exists('in_array_all')) {
/**
* Verify that all needles are in haystack array.
*
* @param array $needles
* @param array $haystack
*
* @return bool
*/
function in_array_all(array $needles, array $haystack): bool
{
return Arr::inArrayAll($needles, $haystack);
}
}
if (!function_exists('in_array_any')) {
/**
* Verify that at least one of needles is in haystack array.
*
* @param array $needles
* @param array $haystack
*
* @return bool
*/
function in_array_any(array $needles, array $haystack): bool
{
return Arr::inArrayAny($needles, $haystack);
}
}