/
functions.php
executable file
·73 lines (57 loc) · 1.7 KB
/
functions.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
<?php
require get_theme_root() . '/' . get_template() . '/vendor/autoload.php';
use App\Http\Lumberjack;
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
// Create the Application Container
$app = require_once('bootstrap/app.php');
// Bootstrap Lumberjack from the Container
$lumberjack = $app->make(Lumberjack::class);
$lumberjack->bootstrap();
if (! function_exists('get_field')) {
return;
}
// Import our routes file
require_once('routes.php');
// Set global params in the Timber context
add_filter('timber_context', [$lumberjack, 'addToContext']);
function humanDateRanges($start, $end)
{
$startTime = strtotime($start);
$endTime = strtotime($end);
$divider = '-';
if (date('Y', $startTime) != date('Y', $endTime)) {
// diff years
$start = date('F j, Y', $startTime);
$end = date('F j, Y', $endTime);
} else {
// same years
$start = date('jS F', $startTime);
$end = date('jS F Y', $endTime);
// same months
if (date('m', $startTime) == date('m', $endTime)) {
$start = date('jS', $startTime);
// same days
if (date('d', $startTime) == date('d', $endTime)) {
return date('jS F Y', $startTime);
}
}
}
return sprintf(
'%s %s %s',
$start,
$divider,
$end
);
}
function generateRandomString($length = 10)
{
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}