diff options
author | Minteck <contact@minteck.org> | 2022-04-21 14:37:44 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-04-21 14:37:44 +0200 |
commit | 958a68292191d8a4c9024ca2f1f658135ab6f704 (patch) | |
tree | 114779ef1b2deb7430e91e30f029e151816d5977 /includes/functions.php | |
parent | 7a7e357dcdd34e4a33a81eadc55548d579938f49 (diff) | |
download | ember-958a68292191d8a4c9024ca2f1f658135ab6f704.tar.gz ember-958a68292191d8a4c9024ca2f1f658135ab6f704.tar.bz2 ember-958a68292191d8a4c9024ca2f1f658135ab6f704.zip |
WIP projects page
Diffstat (limited to 'includes/functions.php')
-rw-r--r-- | includes/functions.php | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/includes/functions.php b/includes/functions.php index defa152..38dda54 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1,6 +1,6 @@ <?php -function version() { +function version(): string { if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/.version")) { return substr(trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/.version")), 0, 8); } else if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/.git/refs/heads/trunk")) { @@ -10,10 +10,53 @@ function version() { } } -function build() { +function build(): string { if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/.build")) { return substr(trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/.build")), 0, 8); } else { return "dev"; } -}
\ No newline at end of file +} + +function getLetters(string $project): string { + $words = explode(" ", preg_replace('/#+/m', "#", preg_replace('/[^a-z0-9 ]/m', "#", strtolower(trim(preg_replace('/[A-Z]/m', ' $0', $project)))))); + + $words = array_slice(array_filter($words, function ($v) { + return trim($v); + }), 0); + + return substr($words[0], 0, 1); +} + +function timeAgo($time): string { + if (!is_numeric($time)) { + $time = strtotime($time); + } + + $periods = array("second", "minute", "hour", "day", "week", "month", "year", "age"); + $lengths = array("60", "60", "24", "7", "4.35", "12", "100"); + + $now = time(); + + $difference = $now - $time; + if ($difference <= 10 && $difference >= 0) { + return $tense = 'just now'; + } elseif ($difference > 0) { + $tense = 'ago'; + } else { + $tense = 'later'; + } + + for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) { + $difference /= $lengths[$j]; + } + + $difference = round($difference); + + $period = $periods[$j] . ($difference >1 ? 's' :''); + return "{$difference} {$period} {$tense} "; +} + +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/Parsedown.php"; +global $Parsedown; +$Parsedown = new Parsedown();
\ No newline at end of file |