This repository has been archived by the owner on Apr 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
61 lines (54 loc) · 2.6 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
<?php
function icon(string $icon, float $px = 15) {
return "<i class='bi bi-$icon' style='font-size:{$size}px'></i>";
}
function alert(string $text, string $type = "success", bool $showicon = True) {
$icon = "";
if ($showicon) {
if ($type == "danger") $icon = icon("x-circle");
else if ($type == "warning") $icon = icon("exclamation-circle");
else if ($type == "info") $icon = icon("info-circle");
else if ($type == "success") $icon = icon("check-circle");
}
return "<div class='alert alert-$type'>$icon $text</div>";
}
function getNotes(string $notesFile = "notes.json") {
$notes = [];
if (is_file($notesFile)) {
$notes = file_get_contents($notesFile);
$notes = json_decode($notes, True);
}
// Sort by descending array index/key
krsort($notes);
return $notes;
}
/* ────────────────────────────────────────────────────────────────────────── */
/* relativeTime */
/* ────────────────────────────────────────────────────────────────────────── */
function relativeTime(string $date) {
$date = new DateTime($date);
$now = new DateTime();
$diff = $now->diff($date);
if ($diff->y > 0) {
return $diff->format('%y years ago');
} elseif ($diff->m > 0) {
return $diff->format('%m months ago');
} elseif ($diff->d > 0) {
return $diff->format('%d days ago');
} elseif ($diff->h > 0) {
return $diff->format('%h hours ago');
} elseif ($diff->i > 0) {
return $diff->format('%i minutes ago');
} else {
return 'Just now';
}
}
/* ───────────────────────────────────────────────────────────────────── */
/* md (markdown) */
/* ───────────────────────────────────────────────────────────────────── */
# NOTE: No longer using this, using showdownjs instead.
// function md(string $text) {
// require_once("Michelf/Markdown.inc.php");
// return \Michelf\Markdown::defaultTransform($text);
// }
?>